Пусть F [q ^ p] - конечный циклический набор c полиномов, где q - простое число, а p - целое число больше 0. Каждый элемент в F [q ^ p] будет полиномом вверх до степени (p-1) в (mod q).
Пример: F [2 ^ 2] = {0,1, x, 1 + x}
Пример: F [3 ^ 4] = {0,1,2,0 + х, 1 + х, 2 + х, 0 + х ^ 2,1 + х ^ 2,2 + х ^ 2, х + х ^ 2,1 + х + х ^ 2,2 + х + х ^ 2,2x + х ^ 2,1 + 2й + х ^ 2,2 + 2й + х ^ 2,0 + 2й ^ 2,1 + 2й ^ 2,2 + 2е ^ 2, х + 2x ^ 2,1 + х + 2x ^ 2,2 + х + 2x ^ 2,2x + 2x ^ 2,1 + 2x + 2x ^ 2,2 + 2x + 2x ^ 2, ... , 2 + 2x + 2x ^ 2 + 2x ^ 3}
Таким образом, в F [q, p] будет q ^ p элементов.
Предположим, что у нас есть генератор тета, где тета ^ k, где k = 0,1,2, ..., q ^ p-1, будет генерировать весь конечный цикл c множество F [q ^ p].
Давайте рассмотрим более сложный пример выше F [3 ^ 4]. Как я могу построить алгоритм, который может генерировать шаблон, такой как этот для F [3 ^ 4], для любого F [q ^ p]?
(0) (1) (2) (x) (1+x) ... (2+2x+2x^2+2x^3)
(0)+theta^(0+i) (1)+theta^(0+i) (2)+theta^(0+i) (x)+theta^(0+i) (1+x)+theta^(0+i) ... (2+2x+2x^2+2x^3)+theta^(0+i)
(0)+theta^(1+i) (1)+theta^(1+i) (2)+theta^(1+i) (x)+theta^(1+i) (1+x)+theta^(1+i) ... (2+2x+2x^2+2x^3)+theta^(1+i)
(0)+theta^(2+i) (1)+theta^(2+i) (2)+theta^(2+i) (x)+theta^(2+i) (1+x)+theta^(2+i) ... (2+2x+2x^2+2x^3)+theta^(2+i)
...
(0)+theta^(q-2+i) (1)+theta^(q-2+i) (2)+theta^(q-2+i) (x)+theta^(q-2+i) (1+x)+theta^(q-2+i) ... (2+2x+2x^2+2x^3)+theta^(q-2+i)
Заметим, что i = 1 ,. .., q-1, но для того, чтобы заставить это работать, давайте установим i = 1.
Сложная часть этой проблемы состоит в том, что вышеупомянутые элементы должны оставаться в (mod q), оставаясь при этом остающимися меньше, чем степень р.
Пример: (из пятого столбца, вторая строка выше) Предположим, что тета равен 0 + x. 1 + theta ^ 4 = 1 + x ^ 4, но x ^ 4 не входит в набор F [q ^ p], поскольку он выше степени (p-1) = 3. Итак, мы используем полиномиальное длинное деление, чтобы показать, что если мы разделим неприводимый многочлен x ^ 4 + x ^ 3 + x ^ 2 + 2x + 2 на x ^ 4, чтобы получить x ^ 3 + x ^ 2 + 2x + 2. (Неприводимый полином можно вычислить с помощью первой функции в моем коде ниже.)
Вот то, с чем я работал до сих пор, но я не добился большого прогресса.
library("polynom")
gf <- function(q,p){
### First we need to create an irreducible polynomial of degree p
poly <- polynomial(coef=c(floor(runif(p,min=0,max=q)),1)) #This generates the first polynomial of degree p with coefficients ranging between the integer values of 0,1,...,q
for(i in 1:(q^5*p)){ #we generate/check our polynomial a sufficient amount of times to ensure that we get an irreducible polynomial
poly.x <- as.function(poly) #we coerce the generated polynomial into a function
for(j in 0:q){ #we check if the generated polynomial is irreducible
if(poly.x(j) %% q == 0){ #if we find that a polynomial is reducible, then we generate a new polynomial
poly <- polynomial(coef=c(floor(runif(p,min=0,max=q)),1)) #...and go through the loop again
}
}
}
### Now, we need to construct the cyclic group F[x] given the irreducible polynomial "poly"
F <- matrix(ncol=p,nrow=q^p) #initialize the vector F
### Constructs an F[x], where each row contains the coefficients of the polynomial
F <- as.matrix(expand.grid(lapply(1:p, function(i) 1:q-1L)))
### We need to solve for x^p using the irreducible polynomial above
### https://rosettacode.org/wiki/Polynomial_long_division#R
polylongdiv <- function(n,d) {
gd <- length(d)
pv <- vector("numeric", length(n))
pv[1:gd] <- d
if ( length(n) >= gd ) {
q <- c()
while ( length(n) >= gd ) {
q <- c(q, n[1]/pv[1])
n <- n - pv * (n[1]/pv[1])
n <- n[2:length(n)]
pv <- pv[1:(length(pv)-1)]
}
list(q=q, r=n)
} else {
list(q=c(0), r=n)
}
}
### Now we need to check for a generator
for(i in (q+1):(q^p/2)){ #we can skip the first 1:q, since those are constants, and we don't need to calculate the second half of the set
posgen <- F[i,]
}
### Now we construct the orthogonal mate Latin Square, which must be a List, since it's a 3-dimensional matrix
gen <- c(0,1)
LS <- list()
i <- 1 #this will change later
for(i in 1:(q^p)){ #this is working well
LS[[i]] <- F[i,]%%q
}
for(k in (q^p+1):q^(2*p)){ #this gives the correct dimensions
for(i in 1:q^p){ #this is where things are getting weird
for(j in 0:(q-2)){
LS[[k]] <- (F[i,] + gen^(j+sub))%%q
}
}
}
list(poly.x=poly.x,poly=poly,F=F,posgen=posgen,LS=LS)
}