Fraction congruence mod n
fraccon(t,b,n)
Func
@top,bot,num
@returns x=t/b mod n
@or i if x doesn't exist
Local i
For i,1,n-1
If mod(b*i,n)=t Then
Return i
EndIf
EndFor
Return i
EndFunc
Order of m mod n under multiplication
order(m,n)
Func
@m,n
Local i
For i,1,n
If mod(m^i,n)=1 Then
Return i
EndIf
EndFor
Return ∞
EndFunc
Pivot on a matrix entry
pivot(a,pr,pc)
Func
@matrix,prow,pcol
Local r
mRow(1/(a[pr,pc]),a,pr)→a
For r,1,rowDim(a)
If r≠pr Then
mRowAdd(-a[r,pc],a,pr,r)→a
EndIf
EndFor
Return a
EndFunc
Group of units mod n (U-group for n)
ugroup(n)
Func
@m,n
Local x,y,i,j
seq(int(1/gcd(x,n))*x,
x,1,n-1)→y
@pick out non 0 terms
1→j
For i,1,dim(y)
If y[i]>0 Then
y[i]→y[j]
j+1→j
EndIf
EndFor
Return left(y,j-1)
EndFunc
Cayley table for a U-group
cayley(l,n)
Func
@list,n
Local c,d,m
newMat(dim(l),dim(l))→m
For c,1,dim(l)
For d,l,dim(l)
mod(l[c]*l[d],n)→m[c,d]
EndFor
EndFor
Return m
EndFunc