MathGroup Archive 2003

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

Search the Archive

RE: constant -> constant

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41963] RE: [mg41945] constant -> constant
  • From: "David Park" <djmp at earthlink.net>
  • Date: Wed, 11 Jun 2003 13:17:58 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Carlos,

It is not a bug. I think it is correct behavior. Having set b to a value you
can't expect it to behave like a symbol without a value.

a = b = 0;

a /. b -> 1 // Trace
{{a, 0}, {{b, 0}, 0 -> 1, 0 -> 1}, 0 /. 0 -> 1, 1}

a was zero, but then you told Mathematica to changes 0's to 1's. Mathematica
evaluates the lhs of rules before applying them. When you preserve b as a
symbol by using HoldPattern, you do get 0 as a result.

a /. HoldPattern[b] -> 1 // Trace
{{a, 0}, {HoldPattern[b] -> 1, HoldPattern[b] -> 1},
  0 /. HoldPattern[b] -> 1, 0}

If you expect to use a symbol for symbolic manipulation don't Set it to a
value. Use rules in the first place for value substitution, or use it as a
parameter in a function definition.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


From: Carlos Felippa [mailto:carlos at colorado.edu]
To: mathgroup at smc.vnet.net


I traced a bug in a large program to an unexpected
substitution.  This gives the idea:

a=b=0; Print [a/.b->1];

1

Is this correct behavior and, is there a way to guard
against this happening?


  • Prev by Date: Re: InverseFunction[]
  • Next by Date: Re: Gamma distribution
  • Previous by thread: RE: constant -> constant
  • Next by thread: Mathematica doesn't start??