       Simulating the behaviour of Plus and Times.

• To: mathgroup at smc.vnet.net
• Subject: [mg75858] Simulating the behaviour of Plus and Times.
• From: Szabolcs <szhorvat at gmail.com>
• Date: Sat, 12 May 2007 03:03:17 -0400 (EDT)
• Organization: University of Bergen

```Is it possible to define two functions whose behaviour is the same as
that of Plus, Times and Minus in circumstances similar to the ones
illustrated below?

In:= 1+2
Out= 3

In:= a + a
Out= 2 a

In:= 3a + 5a
Out= 8 a

In:= x a + y a
Out= a x + a y

In:= 3(a+b) + 2(a+b)
Out= 5 (a+b)

In:= 0a
Out= 0

In:= a-a
Out= 0

Could someone show me how to define two such functions, plus and times,
that operate on integers represented as num[someNumber]? Example:

In := plus[times[num, plus[a, b]], times[plus[a, b], num]]
Out = times[num, plus[a, b]]

In := plus[times[num[-1], a], a]
Out = num

```

• Prev by Date: Coordinate conversion with Grad
• Next by Date: Shadows in Mathematica 6
• Previous by thread: Re: Coordinate conversion with Grad
• Next by thread: Shadows in Mathematica 6