@@ -94,13 +94,14 @@ function CyclicCode(q::Int, n::Int, cosets::Vector{Vector{Int}})
9494 H, G_stand, H_stand, P, missing )
9595end
9696
97+ # TODO should define this instead over a residue ring such that n is already defined?
9798"""
98- CyclicCode(n::Int, g::FqPolyRingElem)
99+ CyclicCode(n::Int, g::Union{fpPolyRingElem, FqPolyRingElem} )
99100
100101Return the length `n` cyclic code generated by the polynomial `g`.
101102"""
102- function CyclicCode (n:: Int , g:: FqPolyRingElem )
103- n <= 1 && throw (DomainError (" Invalid parameters passed to CyclicCode constructor: n = $n ." ))
103+ function CyclicCode (n:: Int , g:: Union{fpPolyRingElem, FqPolyRingElem} )
104+ is_positive (n) || throw (DomainError (" Invalid parameters passed to CyclicCode constructor: n = $n ." ))
104105 R = parent (g)
105106 flag, h = divides (gen (R)^ n - 1 , g)
106107 flag || throw (ArgumentError (" Given polynomial does not divide x^$n - 1." ))
@@ -119,13 +120,19 @@ function CyclicCode(n::Int, g::FqPolyRingElem)
119120 β = α^ (div (q^ deg - 1 , n))
120121 ord_E = Int (order (E))
121122 R_E, y = polynomial_ring (E, :y )
122- g_E = R_E ([E (i) for i in collect (coefficients (g))])
123+ if t == 1 && typeof (g) == fpPolyRingElem
124+ g_E = R_E (E .(lift .(Ref (ZZ), collect (coefficients (g)))))
125+ else
126+ g_E = R_E ([E (i) for i in collect (coefficients (g))])
127+ end
123128 # _, h = divides(gen(R_E)^n - 1, g_E)
124129
130+ # TODO doesn't work for large fields
125131 dic = Dict {FqFieldElem, Int} ()
126132 for i in 0 : ord_E - 1
127133 dic[β^ i] = i
128134 end
135+
129136 cosets = defining_set (sort! ([dic[rt] for rt in roots (g_E)]), q, n, false )
130137 def_set = sort! (reduce (vcat, cosets))
131138 k = n - length (def_set)
@@ -145,7 +152,7 @@ function CyclicCode(n::Int, g::FqPolyRingElem)
145152 iszero (G * tr_H) || error (" Generator and parity check matrices are not transpose orthogonal." )
146153
147154 if t == 1
148- F = GF (p)
155+ F = Oscar . Nemo . Native . GF (p)
149156 G = change_base_ring (F, G)
150157 H = change_base_ring (F, H)
151158 G_stand = change_base_ring (F, G_stand)
@@ -378,6 +385,29 @@ Return the cyclic code whose roots are the quadratic residues of `q`, `n`.
378385"""
379386QuadraticResidueCode (q:: Int , n:: Int ) = CyclicCode (q, n, [quadratic_residues (q, n)])
380387
388+ """
389+ FireCode(p::Union{fpPolyRingElem, FqPolyRingElem}, l::Int)
390+
391+ Return the fire code with generator polynomial `(x^(2l - 1) + 1) * p`.
392+ """
393+ function FireCode (p:: Union{fpPolyRingElem, FqPolyRingElem} , l:: Int )
394+ # F = base_ring(p)
395+ # Int(order(F)) == 2 || throw(ArgumentError("Fire codes are only defined over `GF(2)`."))
396+ Oscar. is_irreducible (p) || throw (ArgumentError (" The polynomial `p` must be irreducible over `GF(2)`." ))
397+ m = degree (p)
398+ x = gen (parent (p))
399+ 1 ≤ l ≤ m || throw (DomainError (l, " This construction requires 1 ≤ l ≤ degree(p)." ))
400+ isone (gcd (p, x^ (2 l - 1 ) + 1 )) || throw (ArgumentError (" This construction requires `gcd(p, x^(2l - 1) + 1) = 1`." ))
401+ g = (x^ (2 l - 1 ) + 1 ) * p
402+
403+ n = - 1
404+ for i in 1 : 3000
405+ flag, _ = divides (x^ i - 1 , g)
406+ flag && (n = i; break )
407+ end
408+ n == - 1 && error (" Unable to find the period of the generator polynomial in 3000 iterations." )
409+ return CyclicCode (n, g)
410+ end
381411# TODO : cyclic code constructors from zeros and nonzeros
382412
383413# ############################
@@ -487,52 +517,6 @@ BCH_bound(C::AbstractCyclicCode) = C.δ
487517# """
488518# HT_bound(C::AbstractCyclicCode) = C.HT
489519
490- """
491- is_narrow_sense(C::AbstractBCHCode)
492-
493- Return `true` if the BCH code is narrowsense.
494- """
495- is_narrowsense (C:: AbstractBCHCode ) = iszero (C. b) # should we define this as b = 1 instead?
496-
497- """
498- is_reversible(C::AbstractCyclicCode)
499-
500- Return `true` if the cyclic code is reversible.
501- """
502- is_reversible (C:: AbstractCyclicCode ) = [C. n - i for i in C. def_set] ⊆ C. def_set
503-
504- """
505- is_degenerate(C::AbstractCyclicCode)
506-
507- Return `true` if the cyclic code is degenerate.
508-
509- # Notes
510- * A cyclic code is degenerate if the parity-check polynomial divides `x^r - 1` for
511- some `r` less than the length of the code.
512- """
513- function is_degenerate (C:: AbstractCyclicCode )
514- x = gen (C. R)
515- for r in 1 : C. n - 1
516- flag, _ = divides (x^ r - 1 , C. h)
517- flag && return true
518- end
519- return false
520- end
521-
522- """
523- is_primitive(C::AbstractBCHCode)
524-
525- Return `true` if the BCH code is primitive.
526- """
527- is_primitive (C:: AbstractBCHCode ) = C. n == Int (order (C. F)) - 1
528-
529- """
530- is_antiprimitive(C::AbstractBCHCode)
531-
532- Return `true` if the BCH code is antiprimitive.
533- """
534- is_antiprimitive (C:: AbstractBCHCode ) = C. n == Int (order (C. F)) + 1
535-
536520# ############################
537521 # setter functions
538522# ############################
@@ -814,6 +798,52 @@ function +(C1::AbstractCyclicCode, C2::AbstractCyclicCode)
814798 end
815799end
816800
801+ """
802+ is_narrow_sense(C::AbstractBCHCode)
803+
804+ Return `true` if the BCH code is narrowsense.
805+ """
806+ is_narrowsense (C:: AbstractBCHCode ) = iszero (C. b) # should we define this as b = 1 instead?
807+
808+ """
809+ is_reversible(C::AbstractCyclicCode)
810+
811+ Return `true` if the cyclic code is reversible.
812+ """
813+ is_reversible (C:: AbstractCyclicCode ) = [C. n - i for i in C. def_set] ⊆ C. def_set
814+
815+ """
816+ is_degenerate(C::AbstractCyclicCode)
817+
818+ Return `true` if the cyclic code is degenerate.
819+
820+ # Notes
821+ * A cyclic code is degenerate if the parity-check polynomial divides `x^r - 1` for
822+ some `r` less than the length of the code.
823+ """
824+ function is_degenerate (C:: AbstractCyclicCode )
825+ x = gen (C. R)
826+ for r in 1 : C. n - 1
827+ flag, _ = divides (x^ r - 1 , C. h)
828+ flag && return true
829+ end
830+ return false
831+ end
832+
833+ """
834+ is_primitive(C::AbstractBCHCode)
835+
836+ Return `true` if the BCH code is primitive.
837+ """
838+ is_primitive (C:: AbstractBCHCode ) = C. n == Int (order (C. F)) - 1
839+
840+ """
841+ is_antiprimitive(C::AbstractBCHCode)
842+
843+ Return `true` if the BCH code is antiprimitive.
844+ """
845+ is_antiprimitive (C:: AbstractBCHCode ) = C. n == Int (order (C. F)) + 1
846+
817847# "Schur products of linear codes: a study of parameters"
818848# Diego Mirandola
819849# """
0 commit comments