有限环Z[ω]/(m+nω)的结构分析(Lua版本)

Eisenstein整数环Z[ω]之模m+nω的剩余类环Z[ω]/(m+nω)是m^2+n^2-mn阶有限环。
https://www.doc88.com/p-901238501777.html
素理想的情形:
Z[ω]/(1-ω)={0,1,2}是F_3,这是Z[ω]的剩余类环中唯一的一个对合环。

root@ubuntu:/home/cpptest/lua# ./luatest EisensteinIntegers.lua
z1=9+11ω
z2=56+3ω
z1+z2=65+14ω
z1-z2=-47+8ω
z1*z2=471+610ω
z1/z2=0+0ω
true 9+11ω 0+0ω
(7+5ω,18+5ω)= 1+1ω
(112+ω,-57+79ω)= 1+0ω
0,1,3,4,7,9,12,13,16,19,21,25,27,28,31,36,37,39,43,48,49,52,57,61,63,64,67,73,75,76,79,81,84,91,93,97,100,103,108,109,111,112,117,121,124,127,129,133,139,144,147,148,151,156,157,163,169,171,172,175,181,183,189,192,193,196,199,
3
Z[ω]/(1-ω)={0,1,2}:
[R3Add]
1 2 3
2 3 1
3 1 2
[R3Mul]
1 1 1
1 2 3
1 3 2

function eAdd(z1,z2)
local z3 = {}
z3[1]=z1[1]+z2[1]
z3[2]=z1[2]+z2[2]
return z3
end

function eSub(z1,z2)
local z3 = {}
z3[1]=z1[1]-z2[1]
z3[2]=z1[2]-z2[2]
return z3
end

function eMul(z1,z2)
local z3 = {}
z3[1]=z1[1]*z2[1]-z1[2]*z2[2]
z3[2]=z1[1]*z2[2]+z1[2]*z2[1]-z1[2]*z2[2]
return z3
end

function eStr(z)
local s
if z[2]>=0 then
s=z[1].."+"..z[2].."ω"
else
s=z[1]..z[2].."ω"
end
return s
end

--a+bω和a+bω^2的范数都为(a+bω)(a+bω^2)=a^2-ab+b^2
function eNorm(z)
return (z[1]*z[1]-z[1]*z[2]+z[2]*z[2])
end

function gNorm(z)
return (z[1]*z[1]+z[2]*z[2])
end

--a+bω=a-b-bω^2的共轭为a+bω^2=a+b(-1-ω)=a-b-bω
function eConj(z)
local fz = {}
fz[1]=z[1]-z[2]
fz[2]=-z[2]
return fz
end

--定义:设a,b∈M,若存在ε使b=ε(·)a,则称b是a的相伴数,记作b~a。
--a+bω的6个相伴元:a+bω,-a-bω,-b+(a-b)ω,b+(b-a)ω,(b-a)-aω,(a-b)+aω,范数都是a^2-ab+b^2
--艾森斯坦整数有六个单位数(N(ξ)=1):±1,±ω,±ω2,
function eIsAssociatedNumber(z1,z2)
local E={{-1,0},{1,0},{0,1},{0,-1},{-1,-1},{1,1}}
for k,v in ipairs(E) do
local b=eMul(v, z1)
if b[1]==z2[1] and b[2]==z2[2] then
return true
end
end
return false
end

function ocdiv(a,b,c,d)
local e,f,p,q,s,w;
p=a*c;
q=-b*d;
s=(a+b)*(c-d);
w=c*c+d*d;
if(w+1.0==1.0)then
e=1.0e+35*a/math.abs(a)
f=1.0e+35*b/math.abs(b)
else
e=(p-q)/w
f=(s-p-q)/w
end
return e,f
end

function ediv(a,b,c,d)
local e,f
w=c*c+d*d-c*d
if(w+1.0==1.0)then
e=1.0e+35*a/math.abs(a)
f=1.0e+35*b/math.abs(b)
else
e=(a*c+b*d)/w
f=(b*d+b*c-a*d)/w
end
return e,f
end

--转化为复数域上的点
function e2g(a,b)
local x=a-0.5*b
local y=0.866025*b
return x,y
end

function eDis(z1,z2)
local x1,y1=z1[1],z1[2]
local x2,y2=z2[1],z2[2]
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)
end

--找出最小值序号及最小值
function minimum(a)
local mi=1
local m=a[mi]
for i,val in ipairs(a) do
if val < m then
mi = i
m = val
end
end
return m, mi
end

--最接近复数域上点的艾森斯坦整数
function Eis(x,y)
local a=x+0.57735*y
local b=1.1547*y
local z={}
local a1=math.floor(a+0.5)
local a2=a1-1
local b1=math.floor(b+0.5)
local b2=b1-1
local drr={eDis({a1,b1},{a,b}),eDis({a1,b2},{a,b}),eDis({a2,b1},{a,b}),eDis({a2,b2},{a,b})}
local m,mi=minimum(drr)
if mi==1 then
z[1]=a1
z[2]=b1
elseif mi==2 then
z[1]=a1
z[2]=b2
elseif mi==3 then
z[1]=a2
z[2]=b1
elseif mi==4 then
z[1]=a2
z[2]=b2
end
return z
end

function eDiv(z1,z2)
local c={}
local c1,c2
local x1,y1=e2g(z1[1],z1[2])
local x2,y2=e2g(z2[1],z2[2])
local x3,y3=ocdiv(x1,y1,x2,y2)
c=Eis(x3,y3)
return c
end

function gStr(z)
local s
if z[2]>=0 then
s=z[1].."+"..z[2].."i"
else
s=z[1]..z[2].."i"
end
return s
end

function edivide(z1,z2)
local q=eDiv(z1,z2)
local r=eSub(z1,eMul(q,z2))
local bRet=(r[1]==0 and r[2]==0)
return bRet,q,r
end

function eMod(z1,z2)
local q=eDiv(z1,z2)
local r=eSub(z1,eMul(q,z2))
return r
end

function eGcd(z1,z2)
local x = z1
local y = z2
if(eNorm(z1)<eNorm(z2))then
x = z2
y = z1
end
while (y[1]~=0 or y[2]~=0) do
local ret,q,r=edivide(x,y)
--print(ret,eStr(q),eStr(r),eStr(x),eStr(y))
x = y
y = r
end
return x
end

local z1={9,11}
local z2={56,3}
local z3=eAdd(z1,z2)
local z4=eSub(z1,z2)
local z5=eMul(z1,z2)
local z6=eDiv(z1,z2)--距离z1/z2最近的艾森斯坦整数
io.write("z1=",eStr(z1),"\n","z2=",eStr(z2),"\n")
io.write("z1+z2=",eStr(z3),"\n")
io.write("z1-z2=",eStr(z4),"\n")
io.write("z1*z2=",eStr(z5),"\n")
io.write("z1/z2=",eStr(z6),"\n")
local ret,q,r=edivide({471,610},{56,3})
print(ret,eStr(q),eStr(r))
local z7a=eGcd({7,5},{18,5})
print("(7+5ω,18+5ω)=",eStr(z7a))
local z8a=eGcd({112,1},{-57,79})
print("(112+ω,-57+79ω)=",eStr(z8a))

function get_key(value, tbl)
for k,v in ipairs(tbl) do
if v == value then
return k
end
end
return -1
end

function geneN(n)
local gN={}
for m=0,n,1 do
for n=0,n,1 do
local mn=m*m+n*n-m*n
local k=get_key(mn, gN)
if k==-1 then
table.insert(gN,mn)
end
end
end
table.sort(gN , function(a , b)
return a < b
end)
for k,v in pairs(gN) do
io.write(v, ",")
end
io.write("\n")
end

--小于等于N的所有范数
function geneMaxN(N)
local gN={}
local N1=N
for m=0,N1,1 do
for n=0,N1,1 do
local mn=m*m+n*n-m*n
local k=get_key(mn, gN)
if k==-1 and mn<=N then
table.insert(gN,mn)
end
end
end
table.sort(gN , function(a , b)
return a < b
end)
for k,v in pairs(gN) do
io.write(v, ",")
end
io.write("\n")
end
--geneN(10)
geneMaxN(200)
print(eNorm({1,-1}))

local function get_len(tb)
local len = 0
for k,v in pairs(tb) do
len= len+1
end
return len
end

function is_equal(a, b)
local na=get_len(a)
local nb=get_len(b)
if(na~=nb) then
return false
end
for i=1,na,1 do
if a[i] ~= b[i] then
return false
end
end
return true
end

function get_key2(value, tbl)
for k,v in ipairs(tbl) do
if is_equal(v, value) then
return k
end
end
return -1
end

function printTable(G,z,Func)
local nR=get_len(G)
local rG={}
for i=1,nR,1 do
local r=eMod(G[i],z)
table.insert(rG,r)
end
for i=1,nR,1 do
for j=1,nR,1 do
local ij=eMod(Func(rG[i],rG[j]),z)
local IJ=get_key2(ij,rG)
io.write(IJ, " ")
end
io.write("\n")
end
end

local R3={{0,0},{1,0},{2,0}}
print("Z[ω]/(1-ω)={0,1,2}:")
print("[R3Add]")
printTable(R3,{1,-1},eAdd)
print("[R3Mul]")
printTable(R3,{1,-1},eMul)

上一篇:从iQOO Z1看vivo越来越强大的5G势能


下一篇:Hidden Markov Model (HMM) 详细推导及思路分析