       Re: Re: Redefining the minus operator

• To: mathgroup at smc.vnet.net
• Subject: [mg52655] Re: [mg52046] Re: Redefining the minus operator
• From: Ben Kovitz <bkovitz at acm.org>
• Date: Tue, 7 Dec 2004 04:09:42 -0500 (EST)
• References: <cmkkn6\$j99\$1@smc.vnet.net> <200411080813.DAA07948@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On Nov 8, 2004, at 12:13 AM, David Bailey wrote:

> I would be interested to know what you want to do with this code - as
> there may be better ways to solve your problem.

You saved me from getting into what looks like a very prickly place in
Mathematica.

Here's what I'm trying to do:  derive theorems mechanically in
Mathematica.  I'd like to be able to take, say, a trig theorem and a
few arithmetic theorems (like a + a == 2a), and see what other theorems
those generate.  Hopefully I could also make a visualization of the
graph of logical implication and equivalence relations.

For this purpose, I need to turn off *all* of Mathematica's
simplification code, and invoke just the pattern-matching code.  I'd
also like the results to look nice, but you've shown me that it's far
simpler to just define a PLUS function and not even bother trying to
talk Mathematica out of its normal interpretation of +.

I'm thinking of making an ever-growing list of theorems and just taking
Cases or another pattern-matching function on it.  A potential problem
with this is just that it could get slow.  I don't think DispatchTable
would be of much use, since the list produced is static, and my list of
theorems will grow and grow.

Any thoughts?  Is there some undocumented function for making a hash
table that's capable of growing?

Ben Kovitz
Humboldt State University

> Ben Kovitz wrote:
>> Is there a way in Mathematica to redefine the minus sign to stand for
>> a
>>
>> For example, I'd like to be able to do something like this:
>>
>> In:= Subtract[a_, b_] := MINUS[a, b]
>>
>> In:= FullForm[x - y]
>> Out:= MINUS[x, y]
>>
>> In:= 1 - 0
>> Out:= MINUS[1, 0]
>
> This is definitely an unwise thing to do unless it is just for interest
> or you have a very specialised application in mind. However, the first
> thing to realise is that you don't want to redefine Plus - that is too
> late in the translation process and also extremely disruptive to the
> rest of Mathematica. What you need to do is add extra definitions to
> MakeExpression to change the translation from BoxForm. The following
> code is designed to work in StandardForm:
>
> restructure[{a_}] := a;
> restructure[{a_, "+", b_, c___}] :=
> restructure[{RowBox[{"PLUS", "[", a, ",", b, "]"}], c}];
> restructure[{a_, "-", b_, c___}] :=
>           restructure[{RowBox[{"MINUS", "[", a, ",", b, "]"}], c}];
> restructure[{"+", b_, c___}] :=
> restructure[{RowBox[{"PLUS", "[", b, "]"}], c}];
> restructure[{ "-", b_, c___}] :=
> restructure[{RowBox[{"MINUS", "[", b, "]"}], c}];
>
> MakeExpression[RowBox[s : {___, "+" | "-", ___}],
>          StandardForm] := MakeExpression[restructure[s], StandardForm]
>
> Notice that this code will also translate +a into PLUS[a] and -a into
> MINUS[a]. Also 1+2 is translated into PLUS[1,2]
>
> I would be interested to know what you want to do with this code - as
> there may be better ways to solve your problem.
>
> Please note that this is a rather unusual piece of code, so TEST IT
> WELL
> before you rely on it.
>
> David Bailey
>

```

• Prev by Date: Re: web Mathematica /tomcat request
• Next by Date: Re: Algebraic simplification and speed
• Previous by thread: Re: Algebraic simplification and speed
• Next by thread: Re: Redefining the minus operator