Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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. – J. M. May 21 '12 at 2:31
A related discussion of custom notation for an operator algebra: Having the derivative be an operator – Jens May 21 '12 at 15:30
up vote 18 down vote accepted

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

share|improve this answer
Will it simplify complex expressions? – Anixx May 21 '12 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. – R. M. May 21 '12 at 2:38
@Anixx: why not try it out yourself? BTW: you didn't mention if associativity is a property of your algebra... – J. M. May 21 '12 at 2:39
I wonder whether it will derive associativity ans distributivity laws itself. – Anixx May 21 '12 at 2:41
the tables I provided are enough for such derivation. – 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}
share|improve this answer
If one takes this route, symbols like \[ScriptZero] and \[ScriptOne] might be useful. – J. M. May 21 '12 at 11:04
In both methods the computer does not derive distributivity and associativity itself, – Anixx May 21 '12 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? – celtschk May 21 '12 at 14:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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