Commit 0118ba90 authored by Weng's avatar Weng
Browse files

Upload New File

parent 424ebd89
%% Cell type:markdown id: tags:
# Ein chinesisches Orakel und zyklische Matrizen über $\mathbb{Z}/2\mathbb{Z}$
%% Cell type:markdown id: tags:
Notebook zum gleichnamigen Artikel
enthält Untersuchungen der auftretenden Matrizen, erlaubt Verallgemeinerung der Zaubertricks in P. Diaconis, R. Graham, Magical Mathematics, Princeton University Press (2012), DOI: 10.1515/978-1-400-83938-4
%% Cell type:markdown id: tags:
## Der ursprüngliche Zaubertrick
%% Cell type:code id: tags:
``` sage
MS = MatrixSpace(GF(2),14)
M14=MS([[1,1,0,1,0,0,0,0,0,0,0,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0,0],[0,0,1,1,0,1,0,0,0,0,0,0,0,0],[0,0,0,1,1,0,1,0,0,0,0,0,0,0],
[0,0,0,0,1,1,0,1,0,0,0,0,0,0],[0,0,0,0,0,1,1,0,1,0,0,0,0,0],[0,0,0,0,0,0,1,1,0,1,0,0,0,0],[0,0,0,0,0,0,0,1,1,0,1,0,0,0],
[0,0,0,0,0,0,0,0,1,1,0,1,0,0],[0,0,0,0,0,0,0,0,0,1,1,0,1,0],[0,0,0,0,0,0,0,0,0,0,1,1,0,1],[1,0,0,0,0,0,0,0,0,0,0,1,1,0],
[0,1,0,0,0,0,0,0,0,0,0,0,1,1],[1,0,1,0,0,0,0,0,0,0,0,0,0,1]])
```
%% Cell type:markdown id: tags:
Die letzten drei Zeilen sind linear abhängig:
%% Cell type:code id: tags:
``` sage
print(M14[11]+M14[0]+M14[1]+M14[2]+M14[4]+M14[7]+M14[8]+M14[9])
print(M14[12]+M14[1]+M14[2]+M14[3]+M14[5]+M14[8]+M14[9]+M14[10])
print(M14[13]+M14[2]+M14[3]+M14[4]+M14[6]+M14[9]+M14[10]+M14[11])
```
%%%% Output: stream
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
%% Cell type:code id: tags:
``` sage
kernel=M14.right_kernel()
kernel
```
%%%% Output: execute_result
Vector space of degree 14 and dimension 3 over Finite Field of size 2
Basis matrix:
[1 0 0 1 0 1 1 1 0 0 1 0 1 1]
[0 1 0 1 1 1 0 0 1 0 1 1 1 0]
[0 0 1 0 1 1 1 0 0 1 0 1 1 1]
%% Cell type:markdown id: tags:
## Verallgemeinerung
%% Cell type:markdown id: tags:
Die folgende Funktion erlaubt die Konstruktion der Matrix $M$ für beliebige Muster.
%% Cell type:code id: tags:
``` sage
def konstruiereGscamMatrix(n,pattern):
MS = MatrixSpace(GF(2),n)
m=copy(MS.zero_matrix())
k=len(pattern)
for i in range(0,n):
for j in range(0,len(pattern)):
if (i+j<n):
m[i,i+j]=pattern[j]
else:
k=(i+j)%n
m[i,k]=pattern[j]
return m
```
%% Cell type:markdown id: tags:
Ein Beispiel:
%% Cell type:code id: tags:
``` sage
M21=konstruiereGscamMatrix(21,[1,1,0,1])
M21.right_kernel()#gibt die Basis des Vektorraums der Vektoren v an mit M21*v=0
```
%%%% Output: execute_result
Vector space of degree 21 and dimension 3 over Finite Field of size 2
Basis matrix:
[1 0 0 1 0 1 1 1 0 0 1 0 1 1 1 0 0 1 0 1 1]
[0 1 0 1 1 1 0 0 1 0 1 1 1 0 0 1 0 1 1 1 0]
[0 0 1 0 1 1 1 0 0 1 0 1 1 1 0 0 1 0 1 1 1]
%% Cell type:markdown id: tags:
Hilfsfunktionen, um alle Muster der Länge $k$ aufzuzählen, die von der Form $m=[1,\tilde{m},1]$ mit $\tilde{m}\in \{0,1\}^{k-2}$ beliebig ist:
%% Cell type:code id: tags:
``` sage
import math as m
import numpy as np
def binary(number,total):
#konvertiert eine Zahl zu einer Binärzahl von rechts nach links
bits = int(m.log(total,2))
N = number
b_num = np.zeros(bits)
for i in np.arange(bits):
if( N/((2)**(bits-i-1)) >= 1 ):
b_num[i] = 1
N = N - 2 ** (bits-i-1)
B = []
for j in np.arange(len(b_num)):
B.append(int(b_num[j]))
return B
def detListePattern(k):
t=2^(k-2)
liste=[]
for i in range(0,t):
l1=binary(i,t)
l1.append(1)
l1.insert(0,1)
liste.append(l1)
return liste
```
%% Cell type:markdown id: tags:
Für alle Muster $m$ der Länge $k=3$ und $k+1\le n\le 52$ wird das Tupel $(n, Rang(M_n^m))$ ausgegeben. (bzw. nach Code-Anpassung für $k=4,5,6$.
%% Cell type:code id: tags:
``` sage
k=3 #oder k=4,5,6
liste=detListePattern(k)
for pattern in liste:
print("Muster")
print(pattern)
print("(n,Rang(M))")
liste=[]
for i in range(k+1,53):
liste.append([i,rank(konstruiereGscamMatrix(i,pattern))])
print(liste)
```
%%%% Output: stream
Muster
[1, 0, 1]
(n,Rang(M))
[[4, 2], [5, 4], [6, 4], [7, 6], [8, 6], [9, 8], [10, 8], [11, 10], [12, 10], [13, 12], [14, 12], [15, 14], [16, 14], [17, 16], [18, 16], [19, 18], [20, 18], [21, 20], [22, 20], [23, 22], [24, 22], [25, 24], [26, 24], [27, 26], [28, 26], [29, 28], [30, 28], [31, 30], [32, 30], [33, 32], [34, 32], [35, 34], [36, 34], [37, 36], [38, 36], [39, 38], [40, 38], [41, 40], [42, 40], [43, 42], [44, 42], [45, 44], [46, 44], [47, 46], [48, 46], [49, 48], [50, 48], [51, 50], [52, 50]]
Muster
[1, 1, 1]
(n,Rang(M))
[[4, 4], [5, 5], [6, 4], [7, 7], [8, 8], [9, 7], [10, 10], [11, 11], [12, 10], [13, 13], [14, 14], [15, 13], [16, 16], [17, 17], [18, 16], [19, 19], [20, 20], [21, 19], [22, 22], [23, 23], [24, 22], [25, 25], [26, 26], [27, 25], [28, 28], [29, 29], [30, 28], [31, 31], [32, 32], [33, 31], [34, 34], [35, 35], [36, 34], [37, 37], [38, 38], [39, 37], [40, 40], [41, 41], [42, 40], [43, 43], [44, 44], [45, 43], [46, 46], [47, 47], [48, 46], [49, 49], [50, 50], [51, 49], [52, 52]]
%% Cell type:markdown id: tags:
Die nächste Funktion bestimmt für ein vorgegebenes Muster und eine vorgegebene Dimension $n$ (=Kartenanzahl) das assoziierte Polynom.
%% Cell type:code id: tags:
``` sage
def liefereAssoziiertesPolynom(n,pattern):
R.<x> = PolynomialRing(GF(2))
pol=1
for i in range(1,len(pattern)):
pol=pol+pattern[i]*x^(n-i)
return pol
```
%% Cell type:code id: tags:
``` sage
liefereAssoziiertesPolynom(14,[1,1,0,1])
```
%%%% Output: execute_result
x^13 + x^11 + 1
%% Cell type:markdown id: tags:
Damit lässt sich noch auf andere Weise der Rang der Matrix $M_n^m$ ermitteln.
%% Cell type:code id: tags:
``` sage
def bestimmeRang(n,pattern):
R.<x> = PolynomialRing(GF(2))
g=gcd(liefereAssoziiertesPolynom(n,pattern),x^n-1)
return n-g.degree()
```
%% Cell type:markdown id: tags:
Und schließlich bestimmen wir noch eine Basis des Kerns:
%% Cell type:code id: tags:
``` sage
#MS = MatrixSpace(GF(2),n)
def createShiftList(n):
lst = []
for i in range(n-1):
lst.append(0)
lst.append(1)
return(lst)
def ermittleKern(n,pattern):
R.<x> = PolynomialRing(GF(2))
#bestimme Dimension des Kerns
g=gcd(liefereAssoziiertesPolynom(n,pattern),x^n-1)
k=g.degree()
h=R((x^n-1)/g)
list_h=h.list()
for i in range(len(list_h),n):
list_h.append(0)
k=g.degree()
if (k==0): return []
VS = VectorSpace(GF(2),n)
t1=VS(list_h)
list_kern=[t1]
shift=matrix.circulant(vector(GF(2),createShiftList(n),sparse=True))
t=t1
for i in range(1,k):
t=shift*t
list_kern.append(t)
return list_kern
```
%% Cell type:code id: tags:
``` sage
ermittleKern(14,[1,1,0,1])
```
%%%% Output: execute_result
[(1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0),
(0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0),
(0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1)]
%% Cell type:markdown id: tags:
Die nächste Funktion bringt den Kern der Matrix $M_n^m$ noch auf die Form, dass die ersten $k$ Spalten ($k$=Dimension des Kerns) die Einheitsmatrix darstellen.
%% Cell type:code id: tags:
``` sage
def transformiereKern(list_kern):
k=len(list_kern)
for i in range(0,k-1):
for j in range(i+1,k):
if (list_kern[i][j]==1):
list_kern[i]=list_kern[i]+list_kern[j]
return list_kern
```
%% Cell type:code id: tags:
``` sage
transformiereKern(ermittleKern(14,[1,1,0,1]))
```
%%%% Output: execute_result
[(1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1),
(0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0),
(0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1)]
%% Cell type:markdown id: tags:
## Beispiel 1: das Muster m=$[1,1,0,0,1]$
%% Cell type:code id: tags:
``` sage
mat=konstruiereGscamMatrix(15,[1,1,0,0,1])
```
%% Cell type:code id: tags:
``` sage
mat.right_kernel()
```
%%%% Output: execute_result
Vector space of degree 15 and dimension 4 over Finite Field of size 2
Basis matrix:
[1 0 0 0 1 0 0 1 1 0 1 0 1 1 1]
[0 1 0 0 1 1 0 1 0 1 1 1 1 0 0]
[0 0 1 0 0 1 1 0 1 0 1 1 1 1 0]
[0 0 0 1 0 0 1 1 0 1 0 1 1 1 1]
%% Cell type:code id: tags:
``` sage
transformiereKern(ermittleKern(15,[1,1,0,0,1]))
```
%%%% Output: execute_result
[(1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1),
(0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0),
(0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0),
(0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1)]
%% Cell type:markdown id: tags:
## Beispiel 2: das Muster $m=[1,1,\ldots,1]$ mit $k$ Einsen
%% Cell type:code id: tags:
``` sage
mat=konstruiereGscamMatrix(15,[1,1,1,1,1])
```
%% Cell type:code id: tags:
``` sage
mat.right_kernel()
```
%%%% Output: execute_result
Vector space of degree 15 and dimension 4 over Finite Field of size 2
Basis matrix:
[1 0 0 0 1 1 0 0 0 1 1 0 0 0 1]
[0 1 0 0 1 0 1 0 0 1 0 1 0 0 1]
[0 0 1 0 1 0 0 1 0 1 0 0 1 0 1]
[0 0 0 1 1 0 0 0 1 1 0 0 0 1 1]
%% Cell type:code id: tags:
``` sage
transformiereKern(ermittleKern(15,[1,1,1,1,1]))
```
%%%% Output: execute_result
[(1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1),
(0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1),
(0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1),
(0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1)]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment