Re: Differencing two equations

*To*: mathgroup at smc.vnet.net*Subject*: [mg131484] Re: Differencing two equations*From*: Bob Hanlon <hanlonr357 at gmail.com>*Date*: Mon, 5 Aug 2013 23:08:50 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: l-mathgroup@wolfram.com*Delivered-to*: mathgroup-outx@smc.vnet.net*Delivered-to*: mathgroup-newsendx@smc.vnet.net*References*: <20130210082414.C3A5F6937@smc.vnet.net>

If you want to ensure that the inputs are equalities (and of the same length) just include the constraints in the function definition. equationOperate::usage = "equationOperate[equation1, equation2, operation] performs a listable operation (e.g., Plus, Subtract, Times, Divide) on the input equations. For example, equationOperate[a == b, c == d, Subtract] produces the equation a - c == b - d"; equationOperate[eqn1_Equal, eqn2_Equal, op_] := Equal @@ op @@ List @@@ {eqn1, eqn2} /; Length[eqn1] == Length[eqn2]; SetAttributes[f, Listable] equationOperate[a == r, b == s, #] & /@ {Subtract, Plus, Times, Divide, Power, Power[#2, #1] &, f} {a - b == r - s, a + b == r + s, a*b == r*s, a/b == r/s, a^b == r^s, b^a == s^r, f[a, b] == f[r, s]} equationOperate[a == r == x, b == s == y, #] & /@ {Subtract, Plus, Times, Divide, Power, Power[#2, #1] &, f} {a - b == r - s == x - y, a + b == r + s == x + y, a*b == r*s == x*y, a/b == r/s == x/y, a^b == r^s == x^y, b^a == s^r == y^x, f[a, b] == f[r, s] == f[x, y]} Bob Hanlon On Mon, Aug 5, 2013 at 6:04 AM, David Bailey <dave at removedbailey.co.uk>wrote: > On 11/02/2013 09:36, Murray Eisenberg wrote:> Yeah, Mathematica > stubbornly refuses t > > > >> I'm brand new to Mathematica, so I apologize for the naive questions... > >> > >> I'm trying to figure out how to difference two equations. Basically > if I have: > >> a==r > >> b==s > >> > >> I'd like to get: > >> a-b == r-s > >> > >> What I'm getting is more like (a==r) - (b==s). I'm not sure how > that's a useful result, but is there a function to do what I'm looking for? > >> > >> A quick search of the archives seem to bring up ways of doing this > from using transformation rules to swap heads to unlocking the Equals > operator and hacking its behavior. I'd like to avoid doing that kind of > rewiring for a simple operation, and I'd like to keep the syntax clean. > >> > >> The Core Language documentation makes a big point of how everything > is basically a list with different heads. In this case, what I'm trying > to do would work if it were treated as a list ({a,b}-{r,s} returns > {a-b,r-s}) but doesn't work under Equal. > >> > >> Thanks for any suggestions. > > > > I think it helps to manipulate algebraic expressions in a way that makes > it easy to understand when you come back to a notebook sometime later! > So my approach would be to define a function to subtract equations, so > that it is pretty obvious what is going on! > > In[16]:= subtract[a1_ == a2_, b1_ == b2_] := (a1 - b1) == (a2 - b2) > > In[17]:= subtract[x + 3 y == 6, x - y == 2] > > Out[17]= 4 y == 4 > > This also has the advantage that if you accidentally supply an argument > that is not an equality, you will not get a misleading answer! > > A slightly more general function might take a third argument that would > act as a multiplier of the second equality: > > In[20]:= combine[a1_ == a2_, b1_ == b2_, > k_] := (a1 + k b1) == (a2 + k b2) > > In[21]:= combine[x + 3 y == 6, x - y == 2, -1] > > Out[21]= 4 y == 4 > > In[23]:= combine[x + 3 y == 6, x - y == 2, 3] // Simplify > > Out[23]= x == 3 > > (You could also include the Simplify as part of your combine function) > > David Bailey > http://www.dbaileyconsultancy.co.uk > > >

**Corrupted files**

**Re: Differencing two equations**

**Re: Differencing two equations**

**Re: Differencing two equations**