# How to define a non-standard algebra in Mathematica?

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.

• 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. Commented May 21, 2012 at 2:31
• A related discussion of custom notation for an operator algebra: Having the derivative be an operator
– Jens
Commented May 21, 2012 at 15:30

Here's a way to do it:

Begin["NonStandardAlgebra"];
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_] := SystemTimes[x, y]
End[];


A couple of examples:

NonStandardAlgebratimes[Infinity, 0]
(* 1 *)

NonStandardAlgebraplus[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_] := NonStandardAlgebraplus[x, y]
CircleTimes[x_, y_] := NonStandardAlgebratimes[x, y]


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

• Will it simplify complex expressions? Commented May 21, 2012 at 2:37
• 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.
– rm -rf
Commented May 21, 2012 at 2:38
• @Anixx: why not try it out yourself? BTW: you didn't mention if associativity is a property of your algebra... Commented May 21, 2012 at 2:39
• I wonder whether it will derive associativity ans distributivity laws itself. Commented May 21, 2012 at 2:41
• the tables I provided are enough for such derivation. Commented May 21, 2012 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}
*)

• If one takes this route, symbols like \[ScriptZero] and \[ScriptOne] might be useful. Commented May 21, 2012 at 11:04
• In both methods the computer does not derive distributivity and associativity itself, Commented May 21, 2012 at 13:18
• @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? Commented May 21, 2012 at 14:25