GAP code to get Multiplication Table.

628 Views Asked by At

I have a finite set $S=\{0,1,2,\ldots,n-1\}$ and binary operation $\star$ on $S$ defined by

$$x\star y= \left\{ \begin{array}{l l l} \frac{3(x+y)}{2} ~~\text{modulo} ~~n& \qquad \mbox{if $x$ and $y$ are odd.}\\ x-y ~~\text{modulo} ~~n & \qquad \text{if $x+y$ is odd.}\\ x\cdot y ~~\text{modulo} ~~n & \qquad \text{if $x$ and $y$ are even.}\\ \end{array} \right.$$

I want to write GAP code to get Multiplication Table.

1

There are 1 best solutions below

0
On BEST ANSWER

It largely writes itself. First we define $\star$ as a function:

f:=function(x,y,n)
  if(x mod 2=1 and y mod 2=1) then
    return (3*(x+y)/2) mod n;
  elif((x+y) mod 2=1) then
    return (x-y) mod n;
  else
    return (x*y) mod n;
  fi;
end;;

We pick an $n$-value:

n:=10;;

Then the multiplication table can be computed using

M:=List([0..n-1],x->List([0..n-1],y->f(x,y,n)));

One warning about M though: GAP indices start at $1$ so M[1][1] returns the value of $0 \star 0$, etc.