17

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.

matheorem
  • 17,132
  • 8
  • 45
  • 115
Anixx
  • 3,585
  • 1
  • 20
  • 32

2 Answers2

20

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_] := System`Times[x, y]
End[];

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

rm -rf
  • 88,781
  • 21
  • 293
  • 472
  • Will it simplify complex expressions? – Anixx May 21 '12 at 02: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 May 21 '12 at 02:38
  • @Anixx: why not try it out yourself? BTW: you didn't mention if associativity is a property of your algebra... – J. M.'s missing motivation May 21 '12 at 02:39
  • I wonder whether it will derive associativity ans distributivity laws itself. – Anixx May 21 '12 at 02:41
  • the tables I provided are enough for such derivation. – Anixx May 21 '12 at 02:42
  • I want it do derive all the properties of the new algebra for itself, just taking the tables of addition and multiplication as the input. – Anixx May 21 '12 at 02:43
  • @Anixx: okay then... Function[{a, b, c}, a\[CirclePlus](b\[CirclePlus]c) == (a\[CirclePlus]b)\[CirclePlus]c] @@@ Apply[Join, Permutations /@ Tuples[{0, 1, Infinity}, 3]] – J. M.'s missing motivation May 21 '12 at 02:47
  • Also, Function[{a, b, c}, a\[CircleTimes](b\[CirclePlus]c) == (a\[CircleTimes]b)\[CirclePlus](a\[CircleTimes]c)] @@@ Apply[Join, Permutations /@ Tuples[{0, 1, Infinity}, 3]] – J. M.'s missing motivation May 21 '12 at 02:49
  • But can it automatically simplify the expressions with unknown variables? For example, simplify $(a\otimes b)\oplus (a\otimes c)$ to $a\otimes (b\oplus c)$? – Anixx May 21 '12 at 05:58
  • @Anixx: Commutativity should already be accounted for by the line SetAttributes[#,Orderless]&/@{plus,times};. To account for associativity as well, you can change Orderless to {Flat,Orderless} in that line. I don't think there's an attribute for distributivity, though. – celtschk May 21 '12 at 14:30
11

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}
*)
celtschk
  • 19,133
  • 1
  • 51
  • 106
  • 3
    If one takes this route, symbols like \[ScriptZero] and \[ScriptOne] might be useful. – J. M.'s missing motivation 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