Re: Use of Mathematica with Rule-based Equation Derivations

• To: mathgroup at smc.vnet.net
• Subject: [mg61943] Re: [mg61914] Use of Mathematica with Rule-based Equation Derivations
• From: "Mark Morrissey" <mmorriss at gcn.ou.edu>
• Date: Sat, 5 Nov 2005 01:52:41 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Thank you Andrzej and others - I'll give your suggestions a try.  I used a
'double-stuck' character for 'E' since I know it means the exponential.

Thanks again - Mark

Mark Morrissey
Associate Professor
Meteorology
University of Oklahoma
EVAC
3201 Marshall Ave.
Norman, OK 73072
405 447-8412

-----Original Message-----
From: Andrzej Kozlowski [mailto:akoz at mimuw.edu.pl]
To: mathgroup at smc.vnet.net
Subject: [mg61943] Re: [mg61914] Use of Mathematica with Rule-based Equation
Derivations

On 4 Nov 2005, at 19:11, mmorriss at gcn.ou.edu wrote:

> Hi All - I'm a many-year user of mathematica, but have always had one
> particular problem with it that I may have just simply missed reading
>
> Mathematica Version: 5.2
>
> Problem: I would like to develop a set of re-rewite rules to apply
> to the
> Expected Value operator.  For example:
>
> E[a x] = a E[x]  a -> constant, x -> variable
> E[b + f[x]] = b + E[f[x]] , etc.
>
> The issue is how does one using Mathematica distinguish a 'constant
> variable (i.e. a and b)' from a variable 'variable' (i.e. 'x')? The
> of a, b and x is 'Symbol' and neither a, b nor x contain a number so I
> can't use a_?NumberQ to identify it as a constant.
>
> This actually goes to the wider question of how does one use
> Mathematica
> for symbolic derviations where numbers are not actually substituted
> in the
> derviation?
>
> E.g. E[a + E[b x]] /. Rule2
>    out= a + b E[x] etc.
>
> Thanks all - Mark Morrissey
> University of Oklahoma
>
>

First of all, it is not a good idea to use a protected symbol (E) in
this way. But concerning your question: there is no reason why you
shouldn't use NumberQ or NumericQ in the way you indicated.

First define the rule exactly in the way you said you could not:

Expectation[b_?NumericQ* x_]:=b*Expectation[x]

Now set:

NumericQ[a]=True;

Now you get

Expectation[a x]

a Expectation[x]

and of course as a bonus you automatically get:

Expectation[3 x]

3 Expectation[x]

This gives me a chance to offer a puzzle (for which I offer no prize)
for those who like this sort of things. Note that

NumericQ[a]

True

but where is this information stored by Mathematica? It can't be a
DownValue for NumericQ, since NumericQ has the Attribute Protected
and I did not unprotect it. And indeed:

DownValues[NumericQ]

{}

Or, we could try to give a an UpValue:

Expectation[b_?NumericQ* x_]:=b*Expectation[x]

a/:NumericQ[a]=True;

NumericQ[a]

True

Expectation[a x]

a Expectation(x)

Everything works fine yet:

UpValues[a]

{}

So now again the puzzle: where is this information stored?

Note also that NumberQ behaves quite differently. In fact you can't
set NumberQ[a]=True without first unprotecting NumberQ. On the other
hand if you use an UpValue to make a into a "number"

a/:NumberQ[a]=True;

then as expected:

UpValues[a]

{HoldPattern[NumberQ[a]] :> True}

Well, any guesses?

Andrzej Kozlowski

P.S. All the above with Mathematica 5.1 but I expect it;s the same in
5.2

```

• Prev by Date: Re: Use of Mathematica with Rule-based Equation Derivations
• Next by Date: MathML->SymbolicXML->MathML
• Previous by thread: Re: Use of Mathematica with Rule-based Equation Derivations
• Next by thread: Re: Use of Mathematica with Rule-based Equation Derivations