From: Christoph Lhotka on
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.
>>
>


From: Bob Hanlon on
t /: Positive[t] = True;

f[x_?Positive] = x;

f /@ {-2, 0, 2, t}

{f[-2], f[0], 2, t}


Bob Hanlon

---- Bill Rowe <readnews(a)sbcglobal.net> wrote:

=============
On 7/31/10 at 2:40 AM, hell(a)exoneon.de (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?

Basically, you can't unless you assign a positive value to t.

The pattern _?PositiveQ only matches positive numbers. A
variable with no assigned values will not match this pattern. If
you want your function to evaluate to a symbolic expression
given variables with no assigned values as arguments, you cannot
use a pattern that places restrictions on the arguments those
variables are used for. Such restrictive patterns will always
fail to match a variable with no assigned values. Consequently,
Mathematica will always return the function unevaluated.


From: Murray Eisenberg on
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 , 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(a)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

From: Derivator on
On 31 jul, 08:40, Benjamin Hell <h...(a)exoneon.de> wrote:
> Hi,
> 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.
>
> Thanks in advance.

I am not sure what you mean. Nevertheless, with
t/:Positive[t]=True;
you tell Mathematica t is positive. So, the input
{f[s],f[t]}
yields now
{f[s],t}

L.L.



From: Christoph Lhotka on
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 ...

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 , 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