17
$\begingroup$

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.

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

2 Answers 2

20
$\begingroup$

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

$\endgroup$
10
  • $\begingroup$ Will it simplify complex expressions? $\endgroup$
    – Anixx
    Commented May 21, 2012 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
    Commented May 21, 2012 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$ Commented May 21, 2012 at 2:39
  • $\begingroup$ I wonder whether it will derive associativity ans distributivity laws itself. $\endgroup$
    – Anixx
    Commented May 21, 2012 at 2:41
  • $\begingroup$ the tables I provided are enough for such derivation. $\endgroup$
    – Anixx
    Commented May 21, 2012 at 2:42
11
$\begingroup$

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}
*)
$\endgroup$
3
  • 3
    $\begingroup$ If one takes this route, symbols like \[ScriptZero] and \[ScriptOne] might be useful. $\endgroup$ Commented May 21, 2012 at 11:04
  • $\begingroup$ In both methods the computer does not derive distributivity and associativity itself, $\endgroup$
    – Anixx
    Commented May 21, 2012 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
    Commented May 21, 2012 at 14:25

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