MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: assuming certain properties about variables

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111421] Re: assuming certain properties about variables
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Sun, 1 Aug 2010 04:54:47 -0400 (EDT)

Hi Benjamin,

You can use UpValues to accomplish your goal:

In[1]:=
Clear[f];
f[x_?Positive] = x

Out[2]= x

In[3]:=
Clear[t];
t /: Positive[t] = True

Out[4]= True

In[5]:= f[t]

Out[5]= t

You can look up the definition and properties of UpValues in the
documentation.
The assignment operator used above is called TagSet, you may also want to
look at UpSet, which is a bit more narrow (specifically for defining
UpValues).

Regards,
Leonid


On Sat, Jul 31, 2010 at 10:40 AM, Benjamin Hell <hell at 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.
>
>


  • Prev by Date: Re: assuming certain properties about variables
  • Next by Date: Re: Packages designed for use in player pro
  • Previous by thread: Re: assuming certain properties about variables
  • Next by thread: Re: assuming certain properties about variables