[Date Index]
[Thread Index]
[Author Index]
Re: Problems with easy simplifications
*To*: mathgroup at smc.vnet.net
*Subject*: [mg54152] Re: Problems with easy simplifications
*From*: Curt Fischer <tentrillion at gmail.NOSPAM.com>
*Date*: Sat, 12 Feb 2005 01:57:00 -0500 (EST)
*References*: <cuhsm1$9j1$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Antonio González wrote:
> I have found some weird behaviors of Mathematica (5.0) related to the
> simplifications of easy expressions.
>
> Take, for instance the function
>
> H[x_, a_, b_] = If[x < a, a + b, a - b]
>
> If I try now to evaluate
>
> H[x,0,0]
>
> the result
>
> If[x < 0, 0 + 0, 0 - 0]
what result were you expecting? What is the bug? You have not supplied
a value for x that Mathematica could use to test whether or not x<a or
not.
In[1]:=
h[x_,a_,b_]=If[x<a,a+b,a-b]
Out[1]=
If[x<a,a+b,a-b]
In[2]:=
h[1,2,3]
Out[2]=
5
In[3]:=
h[3,1,2]
Out[3]=
-1
>
> (the values of a and b are irrelevat, a similar result is obtained, for
> instance, with a=1, b= 2, or any integer, real or complex values). I
> cannot force (at least in a simple way) Mathematica to make the addition
> or the substraction. The action of Simplify or FullSimplify leaves the
> expression unchanged while a Map of Simplify
>
> MapAll[Simplify, H[x, 0, 0]]
>
> produces
>
> If[x < 0,
> Simplify[Simplify[0] + Simplify[0]], Simplify[Simplify[
> 0] + Simplify[Simplify[-1] Simplify[0]]]]
>
> Something even worse happens if a use values already defined. For instance
>
> c = 0; d = 0; H[x_] = If[x < c, c + d, c - d]
>
> produces
>
> If[x < 0, c + d, c - d]
>
> In this case, the addition is not necessary.
>
> c = 0; d = 0; H[x_] = If[x < c, c, d]
>
> leads to
>
> If[x < 0, c, d]
If you don't want your definition for H[x_] to be evaluated _right
away_, before substituting the definitions for other variables, you
should use the delayed assignment operator :=.
In[3]:=
c=0;d=0;
In[4]:=
g[x_]:=If[x<c,c+d,c-d]
In[5]:=
g[1]
Out[5]=
0
>
> Similar problems arise using the function Which.
>
> Any explanation or help with this malfunction would be welcome.
Read the Help Browser.
--
Curt Fischer
Prev by Date:
**Re: Problems with easy simplifications**
Next by Date:
**Re: Problems with easy simplifications**
Previous by thread:
**Re: Problems with easy simplifications**
Next by thread:
**Re: Problems with easy simplifications**
| |