I want to define an algebra, where there are three elements: 0, 1 and $\infty$ and two operations, addition and multiplication defined, both commutative:

$$\begin{align*} 0+0&=0\\ 0+1&=1\\ 0+\infty&=\infty\\ 1+1&=1\\ 1+\infty&=\infty\\ \infty+\infty&=\infty\\ 0\times0&=0\\ 1\times0&=0\\ 1\times1&=1\\ 0\times\infty&=1\\ 1\times\infty&=\infty\\ \infty\times\infty&=\infty \end{align*}$$

I want Mathematica to simplify expressions in this system.

  • 3
    $\begingroup$ You might want to look into using CirclePlus[] and CircleTimes[] for defining your special operations, as it's usually not a good idea to modify Plus[] and Times[] willy-nilly. $\endgroup$ – J. M. will be back soon May 21 '12 at 2:31
  • $\begingroup$ A related discussion of custom notation for an operator algebra: Having the derivative be an operator $\endgroup$ – Jens May 21 '12 at 15:30

Here's a way to do it:

ClearAll /@ {plus, times};
SetAttributes[#, Orderless] & /@ {plus, times};
plus[x : 0 | 1, y : 0 | 1] := Unitize[x + y]
plus[Infinity, x : 0 | 1 | Infinity] := Infinity
times[0, Infinity] := 1
times[x_, y_] := System`Times[x, y]

A couple of examples:

NonStandardAlgebra`times[Infinity, 0]
(* 1 *)

NonStandardAlgebra`plus[1, 1]
(* 1 *)

To make the usage convenient, you can utilize an unused symbol. Here, I map these to CirclePlus and CircleTimes respectively as:

CirclePlus[x_, y_] := NonStandardAlgebra`plus[x, y]
CircleTimes[x_, y_] := NonStandardAlgebra`times[x, y]

Here's your entire algebra (the bottom line is the output):

enter image description here

  • $\begingroup$ Will it simplify complex expressions? $\endgroup$ – Anixx May 21 '12 at 2:37
  • $\begingroup$ what sort of expressions do you have in mind? Have you tried it with your expressions? You should add such info to the question before posting. $\endgroup$ – rm -rf May 21 '12 at 2:38
  • $\begingroup$ @Anixx: why not try it out yourself? BTW: you didn't mention if associativity is a property of your algebra... $\endgroup$ – J. M. will be back soon May 21 '12 at 2:39
  • $\begingroup$ I wonder whether it will derive associativity ans distributivity laws itself. $\endgroup$ – Anixx May 21 '12 at 2:41
  • $\begingroup$ the tables I provided are enough for such derivation. $\endgroup$ – Anixx May 21 '12 at 2:42

Since your addition and multiplication have the usual properties (associativity, commutativity, distributivity), another option is to use normal plus and times, but different symbols, e.g. zero, one and inf for your elements. Then you can write:

zero + x_ ^= x;
inf + x_ ^= inf;
one + one ^= one;
zero * zero ^= zero;
zero * inf ^= one;
one * x_ ^= x;
one * inf ^= inf;
inf * inf ^= inf;

Then you have

{zero + zero, one + zero, zero + inf, one + inf, inf + inf, zero * zero,
 one * zero, one * one, zero * inf, one * inf, inf * inf}
==> {zero, one, inf, inf, inf, zero, zero, one, one, inf, inf}
  • 2
    $\begingroup$ If one takes this route, symbols like \[ScriptZero] and \[ScriptOne] might be useful. $\endgroup$ – J. M. will be back soon May 21 '12 at 11:04
  • $\begingroup$ In both methods the computer does not derive distributivity and associativity itself, $\endgroup$ – Anixx May 21 '12 at 13:18
  • $\begingroup$ @Anixx: I just tried with my method (a+b)*one == a*one+b*one //Simplify and got True as expected. And associativity should be automatic due to Plus and Times having attribute Flat. The same is true for commutativity and Orderless. Do you have a concrete example that fails? $\endgroup$ – celtschk May 21 '12 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.