I need examples of binary operations for real numbers that are
- associative and commutative
- associative but not commutative
The examples are for a programming class and need to be rather simple. Thus the operations have to work on real numbers and not on sets or matrices (which I would have to explain to the audience). The Fibonacci numbers would be a good counterexample.
The obvious choice for 1. would be multiplication and addition, but I would like to have another example to improve understanding.
Important is also that I need to be able to chain the operations. So the associative and commutative property should not only hold (or not hold) to a OPERATION b
but also to a OPERATION b OPERATION c OPERATION d ...
. For example
$a\ MEAN\ b := \frac{a + b}{2}$
is associative and commutative for only $a$ and $b $, but not for $a\ MEAN\ b\ MEAN\ c\ MEAN\ d$.
Best Answer
(1) associative and commutative. Beyond ordinary addition and multiplication you could take a binary operation $x*y$ defined by:
$x*y=x+y+1$ (or any other constant eg $x*y=x+y+2$). Similarly, you could take $x*y=2xy$ or $x*y=3xy$ or $x*y=-xy$ etc.
Another idea would be $x*y=\max(x,y)$ or $x*y=\min(x,y)$.
(2) associative but not commutative. You could define a binary operation $x*y$ as:
$x*y=y$ or $x*y=x$ or $x*y=y+1$ or $x*y=x-2$ etc.
A more complicated example is $x*y$ has the integer part of $x$ and the fractional part of $y$, eg $2.331*3.156=2.156$ or $-3.256*1.235=-3.235$
Any examples for (2) are inevitably going to be artificial. I cannot think of any operations on the reals in common use which are associative but not commutative.