MathGroup Archive 2005

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

Search the Archive

Re: Related quastions. Question 2


Hello Kazimir,
you want to automatically thread over Equal.
There is a small pitfall, you can not thread over Set, otherwise
equation = .. ==  ..
will not work.
Well, this can be done be redefining Equal like e.g.:

Unprotect[Equal];
f_[x1___, Equal[y1_, y2___], x2___] ^:= Equal[f[x1, y1, x2], f[x1, 
y2,x2]] /; f =!= Set

This defines an UpValue for Equal that threads any operator except Set 
over Equal.
Here is a (silly?) example:

eq= x == (a+b)^2
eq - (a^2+2 a b + b^2) gives -a^2-2*a*b-b^2+x ==-a^2-2*a*b-b^2+(a+b)^2
eq - (a^2+2 a b + b^2) //Expand  gives -a^2-2*a*b-b^2+x == 0

Sincerely, Daniel

Kazimir wrote:
> Dear Bob,
> 
> you gave the example 
> 
> Print["Equation to solve for x"]
> a x + b == c
> Print["Subtract b from each side"]
> # - b & /@ %%
> Print["Divide each side by a"]
> #/a & /@ %%
> 
> It works but i do not like very much expressions with  %%, as I should
> not insert more lines before it or I have to modify this symbol. I
> would like to start with
> 
> expr= (a x + b == c)
> 
> and then make a transform like expr1 =  expr - b. It clearly does not
> work. Could you advise me a mathematical operartion over expression
> which would return a x == c - b .
> 
> The best thing I found was 
> expr = (a x + b == c)
> Distribute[#1 - b &@expr, Equal]
> however, it does not work in all cases that I need.
> 
> Vlad
> 


  • Prev by Date: Re: Complex Oddity
  • Next by Date: Re: using Scripts with GUIKit (bug?)
  • Previous by thread: Re: Related quastions. Question 2
  • Next by thread: Re: Related quastions. Question 2