From cff53280ecb4b978b971b6840d9290711657cd07 Mon Sep 17 00:00:00 2001 From: zhan jiang Date: Wed, 20 May 2020 17:55:44 -0400 Subject: [PATCH 1/4] Added new option 'Variable' to conwayPolynomial; map between GaloisFields fixed --- M2/Macaulay2/packages/ConwayPolynomials.m2 | 34 +++++++++++++--------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/M2/Macaulay2/packages/ConwayPolynomials.m2 b/M2/Macaulay2/packages/ConwayPolynomials.m2 index 3942b4609be..08920069ec2 100644 --- a/M2/Macaulay2/packages/ConwayPolynomials.m2 +++ b/M2/Macaulay2/packages/ConwayPolynomials.m2 @@ -10,24 +10,28 @@ newPackage( Headline => "a database of Conway polynomials" ) -- the data comes libflint -export "conwayPolynomial" +export { + "conwayPolynomial", + -- options to set the variable to use + "Variable" + } rawConwayPolynomial := value Core#"private dictionary"#"rawConwayPolynomial" getCP := (p,n) -> rawConwayPolynomial (p,n,false) -Ap := memoize(p -> (ZZ/p)(monoid [getSymbol "a"])) +Ap := memoize((p, a) -> (ZZ/p)(monoid [a])) fix := (p,n,co,a) -> sum(#co, i -> co#i * a^i) -conwayPolynomial = method() -conwayPolynomial(ZZ,ZZ) := (p,n) -> ( +conwayPolynomial = method(Options=>{Variable=>getSymbol "a"}) +conwayPolynomial(ZZ,ZZ) := opts -> (p,n) -> ( cp := getCP(p,n); - if cp != {} then fix(p,n,cp,(Ap p)_0)) -conwayPolynomial ZZ := q -> ( + if cp != {} then fix(p,n,cp,(Ap(p, opts.Variable))_0)) +conwayPolynomial ZZ := opts -> q -> ( factors := factor q; if #factors =!= 1 or factors#0#0 === -1 then error "expected a power of a prime"; - conwayPolynomial(factors#0#0,factors#0#1)) + conwayPolynomial(factors#0#0,factors#0#1,opts)) addHook(GaloisField,FindOne,(p,n,a) -> ( cp := getCP(p,n); if cp != {} then break fix(p,n,cp,a))) -isConway := (F) -> (gens ideal ambient F)_(0,0) == sub(conwayPolynomial(F.char,F.degree),ambient ambient F) +isConway := (F) -> (gens ideal ambient F)_(0,0) == sub(conwayPolynomial(F.char,F.degree, Variable=>F_0),ambient ambient F) map(GaloisField,GaloisField) := RingMap => o -> (K,F) -> ( p := char F; n := K.degree; @@ -71,9 +75,10 @@ document { Key => {conwayPolynomial, (conwayPolynomial,ZZ,ZZ), (conwayPolynomial,ZZ)}, Headline => "provide a Conway polynomial", SYNOPSIS ( - Usage => "conwayPolynomial q", + Usage => "conwayPolynomial(q,Variable=>a)", Inputs => { - "q" => ZZ => {"a power of a prime number"} + "q" => ZZ => {"a power of a prime number"}, + "a" => Symbol => {"an optional input, the symbol served as variable, default a"} }, Outputs => { {"a Conway polynomial whose roots generate a field with q elements"} @@ -83,16 +88,17 @@ document { /// ), SYNOPSIS ( - Usage => "conwayPolynomial(p,n)", + Usage => "conwayPolynomial(p,n,Variable=>a)", Inputs => { "p" => ZZ => {"a prime number"}, - "n" => ZZ + "n" => ZZ, + "a" => Symbol => {"an optional input, the symbol served as variable, default a"} }, Outputs => { - {"a Conway polynomial whose roots generate a field with p^n elements"} + {"a Conway polynomial whose roots generate a field with ", TEX "p^n", " elements"} }, EXAMPLE lines /// - conwayPolynomial(2,20) + conwayPolynomial(2,20,Variable=>"b") /// ) } From 6442b9fc990caea5b8fda0e4cb9cfc31737419c3 Mon Sep 17 00:00:00 2001 From: zhan jiang Date: Wed, 20 May 2020 20:14:55 -0400 Subject: [PATCH 2/4] updated as requested --- M2/Macaulay2/packages/ConwayPolynomials.m2 | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/M2/Macaulay2/packages/ConwayPolynomials.m2 b/M2/Macaulay2/packages/ConwayPolynomials.m2 index 08920069ec2..691ba9d7942 100644 --- a/M2/Macaulay2/packages/ConwayPolynomials.m2 +++ b/M2/Macaulay2/packages/ConwayPolynomials.m2 @@ -10,19 +10,17 @@ newPackage( Headline => "a database of Conway polynomials" ) -- the data comes libflint -export { - "conwayPolynomial", - -- options to set the variable to use - "Variable" - } +export "conwayPolynomial" rawConwayPolynomial := value Core#"private dictionary"#"rawConwayPolynomial" getCP := (p,n) -> rawConwayPolynomial (p,n,false) Ap := memoize((p, a) -> (ZZ/p)(monoid [a])) fix := (p,n,co,a) -> sum(#co, i -> co#i * a^i) -conwayPolynomial = method(Options=>{Variable=>getSymbol "a"}) +conwayPolynomial = method(Options=>{Variable=>null}) conwayPolynomial(ZZ,ZZ) := opts -> (p,n) -> ( cp := getCP(p,n); - if cp != {} then fix(p,n,cp,(Ap(p, opts.Variable))_0)) + var := opts.Variable; + var = if var === null then getSymbol "a" else baseName var; + if cp != {} then fix(p,n,cp,(Ap(p, var))_0)) conwayPolynomial ZZ := opts -> q -> ( factors := factor q; if #factors =!= 1 or factors#0#0 === -1 @@ -102,6 +100,22 @@ document { /// ) } + +--TEST /// -- check isConway +--K = GF(8,Variable=>z); +--assert(isConway(K)); +--/// + +TEST /// -- check map(GaloisField,GaloisField) +K = GF(8,Variable=>a); +L = GF(64,Variable=>b); +middleK = GF(8); +middleL = GF(64); +f1 = map(middleK,K,{middleK_0}); +f3 = map(L,middleL,{L_0}); +f2 = map(middleL,middleK); +assert(f3 * f2 * f1 === map(L, K)); +/// -- Local Variables: -- compile-command: "make -C $M2BUILDDIR/Macaulay2/packages PACKAGES=ConwayPolynomials RemakePackages=true RerunExamples=true IgnoreExampleErrors=false RemakeAllDocumentation=true" From 0698551d69279c13507513f3529fd42a205694e1 Mon Sep 17 00:00:00 2001 From: zhan jiang Date: Wed, 20 May 2020 20:15:30 -0400 Subject: [PATCH 3/4] extra test deleted --- M2/Macaulay2/packages/ConwayPolynomials.m2 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/M2/Macaulay2/packages/ConwayPolynomials.m2 b/M2/Macaulay2/packages/ConwayPolynomials.m2 index 691ba9d7942..891c7faa8e7 100644 --- a/M2/Macaulay2/packages/ConwayPolynomials.m2 +++ b/M2/Macaulay2/packages/ConwayPolynomials.m2 @@ -100,11 +100,6 @@ document { /// ) } - ---TEST /// -- check isConway ---K = GF(8,Variable=>z); ---assert(isConway(K)); ---/// TEST /// -- check map(GaloisField,GaloisField) K = GF(8,Variable=>a); From 23d4c2ede031ae75b48f115abe7cebe9a0f3c782 Mon Sep 17 00:00:00 2001 From: zhan jiang Date: Wed, 20 May 2020 21:17:39 -0400 Subject: [PATCH 4/4] removed getSymbol because monoid implicitly uses it --- M2/Macaulay2/packages/ConwayPolynomials.m2 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/M2/Macaulay2/packages/ConwayPolynomials.m2 b/M2/Macaulay2/packages/ConwayPolynomials.m2 index 891c7faa8e7..001824d3ab4 100644 --- a/M2/Macaulay2/packages/ConwayPolynomials.m2 +++ b/M2/Macaulay2/packages/ConwayPolynomials.m2 @@ -15,12 +15,10 @@ rawConwayPolynomial := value Core#"private dictionary"#"rawConwayPolynomial" getCP := (p,n) -> rawConwayPolynomial (p,n,false) Ap := memoize((p, a) -> (ZZ/p)(monoid [a])) fix := (p,n,co,a) -> sum(#co, i -> co#i * a^i) -conwayPolynomial = method(Options=>{Variable=>null}) +conwayPolynomial = method(Options=>{Variable=>"a"}) conwayPolynomial(ZZ,ZZ) := opts -> (p,n) -> ( cp := getCP(p,n); - var := opts.Variable; - var = if var === null then getSymbol "a" else baseName var; - if cp != {} then fix(p,n,cp,(Ap(p, var))_0)) + if cp != {} then fix(p,n,cp,(Ap(p, opts.Variable))_0)) conwayPolynomial ZZ := opts -> q -> ( factors := factor q; if #factors =!= 1 or factors#0#0 === -1