Re: assuming certain properties about variables

*To*: mathgroup at smc.vnet.net*Subject*: [mg111622] Re: assuming certain properties about variables*From*: "Christoph Lhotka" <christoph.lhotka at univie.ac.at>*Date*: Sat, 7 Aug 2010 06:22:47 -0400 (EDT)

Hello, Sorry for my late reply. The reason is, that I found your message in the MathGroup archive, but never recieved it by mail. In addition it puzzles me, why you were not able to find my post, since it is present in the archive [mg111465]... Regarding your comment, I repeat, how I would use the symbol $Assumptions to define the function f to work for t without setting the upvalue to it: f[t_] := If[MemberQ[{$Assumptions}, t > 0], t, -t] Assuming[t > 0, f[t]] which will return t, if t is assumed to be positive and -t otherwise. The draw back is, that one also has to give a return value if t is not greater than 0. Best regards, Christoph PS: Could you please verify, that you see my message in the MathGroup? Thank you in advance. I don't see what $Assumptions has to do with the situation at hand, since using $Assumptions = t>0 does not change the result of leaving f[t] unevaluated; nor does either of Assuming[t>0, f[t]] Simplify[f[t], t>0] The only really workable thing I've seen posted in response to the O.P.'s query -- sorry, I cannot find any previous posting by you to MathGroup on this subject -- is Leonid Shifrin's [mg111421], using UpValues: t /: Positive[t] = True And I guess that, except for employing user-defined heads to create new types of objects, that's the closest one can come to declaring types of variables. Or am I missing something? On 8/2/2010 4:26 AM, Christoph Lhotka wrote: > hello, > > there is the symbol $Assumptions exactly for this purpose (please see my > previous response for a working definition of f, such that it will > return t, whenever it is assumed to be positive)... > > best, > > christoph > > On 01/08/2010 10:57, Murray Eisenberg wrote: >> But once you put the restriction on the argument of f, you've told >> Mathematica not to carry out the evaluation of f unless the input >> supplied is actually positive. >> >> If now t is just a symbol, then it is not positive (and not negative, >> either) -- it's just a symbol. So why would you expect to be able to >> tell Mathematica that it's positive? In general, Mathematica variables >> don't really have types. >> >> If it's just the particular symbol t that you want to supply to f, then >> you could do this (I'm changing your function definition for clarity) -- >> not that you probably want SetDelayed (:=) instead of Set (=): >> >> f[x_?Positive] := x^2 >> f[t] = t^2; >> >> f[3] >> 9 >> f[t] >> t^2 >> t = -5; >> f[t] >> f[-5] >> >> f >> >> >> On 7/31/2010 2:40 AM, Benjamin Hell wrote: >>> let's say I have defined the following function: >>> f[x_?Positive] = x >>> Now I want to evaluate f with a variable t: >>> f[t] >>> As mathematica knows nothing about t, the output is f[t] instead of t. >>> >>> How can I tell mathematica, that t should be a positive number so that >>> Positive[t] evaluates true and then f[t] evaluates to t? >>> Of course this is just an example, which should present what I would >>> like to know. > -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305