diff --git a/Valuations/Valuations.m2 b/Valuations/Valuations.m2 index 47080b5..a3389c5 100644 --- a/Valuations/Valuations.m2 +++ b/Valuations/Valuations.m2 @@ -13,14 +13,11 @@ newPackage("Valuations", DebuggingMode => false, HomePage => "https://github.com/Macaulay2/Workshop-2023-Minneapolis/tree/valuations", Configuration => {}, - PackageExports => {"LocalRings", "SubalgebraBases", "InvariantRing"} - ) - --- importFrom_"LocalRings" {"LocalRing"} --- importFrom_LocalRings {"LocalRing"} --- importFrom_SubalgebraBases {"Subring"} + --PackageExports => {"LocalRings", "SubalgebraBases", "InvariantRing", "Tropical", "gfanInterface", "Binomials"} + PackageExports => {"LocalRings", "SubalgebraBases", "InvariantRing", "gfanInterface", "Binomials"} + ) ------ MOVE TO SubalgebraBases -> Subring +----- Possibly move to other packages ring Subring := A -> ambient A ring RingOfInvariants := A -> ambient A ring LocalRing := A -> A @@ -35,6 +32,7 @@ export{"valuation", "getMExponent", "domain", "codomain", +-- "valM", "OrderedQQn", "OrderedQQVector", "orderedQQn" @@ -188,12 +186,12 @@ padicValuation ZZ := p -> ( valuation func ) --- Leading Term Valuation (max convention) +-- Leading Term Valuation leadTermValuation = method() leadTermValuation PolynomialRing := R -> ( monOrder := (options R).MonomialOrder; orderedMod := orderedQQn(R); - valFunc := f -> (print f;print describe f;if f == 0 then infinity else monomialToOrderedQQVector(leadTerm f, orderedMod)); + valFunc := f -> (if f == 0 then infinity else monomialToOrderedQQVector(leadTerm f, orderedMod)); internalValuation(valFunc, R, orderedMod) ) @@ -204,7 +202,7 @@ lowestTermValuation PolynomialRing := R -> ( orderedMod := orderedQQn(R); valFunc := f -> ( if f == 0_R then infinity - else monomialToOrderedQQVector((sort flatten entries monomials f)_0, orderedMod) + else (-1)*monomialToOrderedQQVector((sort flatten entries monomials f)_0, orderedMod) ); internalValuation(valFunc, R, orderedMod) ) @@ -232,6 +230,96 @@ localRingValuation LocalRing := R -> ( valuation(func, R, ZZ) ) +-------------------------------------------------------------------------------- +-------------------------------- example77 Valuation --------------------------- +-------------------------------------------------------------------------------- +-* +primeConesOfIdeal = I -> ( + F:=tropicalVariety(I, IsHomogeneous=>true,Prime=>true); + r:=rays(F); + c:=maxCones(F); + cns := for i in c list(r_i); + inCns := for c in cns list (flatten entries( c * transpose matrix{toList(numColumns(c) : 1)})); + L:= for i from 0 to #cns-1 list (J = gfanBuchberger(I, "w" => -1*(inCns#i)); + H := gfanInitialForms(J, -1*(inCns#i), "ideal" =>true); + K := H_1; + if binomialIsPrime(ideal(K)) then cns#i); + delete(null,L) + ) + +-- given a set of rays of a 2D cone, +-- get two interior points of the cone that span it (as a vector space) +coneToMatrix = coneRays -> ( + independentConeRays := getMaxIndependent(coneRays); + coeffs := matrix for i from 1 to numcols independentConeRays list for j from 1 to numcols independentConeRays list if i == j then 2 else 1; + print(coeffs); + print(independentConeRays); + coeffs*(transpose independentConeRays) + ) + +-- get a maximal set of independent columns of a matrix +getMaxIndependent = M -> ( + -- compute the pivot columns to obtain a maximal linearly independent subset of columns of M + R := reducedRowEchelonForm(sub(M, QQ)); + P := for i from 1 to rank M list min (for j from 1 to numcols M list if R_(i-1,j-1) != 0 then j-1 else numcols M); + M_P + ) + +-- scale the rows of a list of matrices +-- using a positive vector of the lineality space of a tropical +-- variety f +positivity = (f, matL) -> ( + l := transpose linealitySpace(f); + finalScaledMats := {}; + matList := for i from 0 to #matL-1 list entries matL_i; + for i from 0 to #matList-1 do ( + scaledRows = {}; + for j from 0 to #(matList_i)-1 do ( + coeff := -1*floor(min apply(#(matList_i)_j, k -> (((matList_i)_j)_k)/(flatten entries l)_k)); + scaledRows = append(scaledRows, (1/gcd(flatten entries (coeff*l + matrix{(matList_i)_j})))*(coeff*l + matrix{(matList_i)_j})); + ); + mat := scaledRows_0; + for i from 1 to #scaledRows-1 do mat = mat || scaledRows_i; + finalScaledMats = append(finalScaledMats, mat); + ); + finalScaledMats + ) + +-- TODO need to generalize! +coneToValuation = (coneRays, I) -> ( + F := tropicalVariety(I, IsHomogeneous=>true,Prime=>true); + M := coneToMatrix(coneRays); + scaledM := (positivity(F, {M}))/(i -> sub(i, ZZ)); + T := QQ[e_1, e_2, e_3, y, MonomialOrder=>{Weights=>((entries scaledM_0)_0), Weights=>((entries scaledM_0)_1)}]; + val := leadTermValuation(T); + orderedM := orderedQQn(2, {Lex}); + func := (f -> ( + valf := val(sub(f, T)); + if valf == infinity then infinity else ( + (gens orderedM)*(scaledM_0)*(valf) + ) + ) + ); + valuation(func, S, orderedM) + ) + +-- TODO need to generalize! +-- construct the new valuation by taking min +valM = (T, valMTwiddle) -> ( + valMfunc = (g) -> ( + R := QQ[x_1, x_2, x_3, e_1, e_2, e_3, y, MonomialOrder => Eliminate 3]; + I := ideal{x_1 + x_2 + x_3 - e_1, x_1*x_2 + x_1*x_3 + x_2*x_3 - e_2, x_1*x_2*x_3 - e_3, (x_1 - x_2)*(x_1 - x_3)*(x_2 - x_3) - y}; + f := e_1^2*e_2^2 - 4*e_2^3 - 4*e_3*e_1^3 + 18*e_1*e_2*e_3 - 27*e_3^2 - y^2; + S := valMTwiddle#"domain"; + m := map(S, R, matrix{{0,0,0}} | matrix {gens S}); + gTwiddle := m (sub(g, R) % I); + maxTwiddle := gTwiddle % ideal(sub(f, S)); + use T; -- something above changes the user's ring (what could it be?) let's assume it was T + valMTwiddle(maxTwiddle) + ); + valuation(valMfunc, T, valMTwiddle#"codomain") + ) +*- -------------------------------------------------------------------------------- -------------------------------- Documentation --------------------------------- -------------------------------------------------------------------------------- @@ -242,7 +330,7 @@ doc /// Key "trivialValuation" Headline - Constructs the trivial valuation + The trivial valuation Usage v = trivialValuation Outputs @@ -250,7 +338,7 @@ doc /// the trivial valuation Description Text - A function to construct the trivial valuation, returning infinity when the valuation input is zero and returning zero otherwise. + This valuation returns zero for all nonzero inputs. Example v = trivialValuation; v (-13) @@ -259,6 +347,11 @@ doc /// v 0 SeeAlso valuation + Valuation + leadTermValuation + lowestTermValuation + localRingValuation + padicValuation /// @@ -267,7 +360,7 @@ doc /// padicValuation (padicValuation, ZZ) Headline - Construct a p-adic valuation + The p-adic valuation Usage v = padicValuation(p) Inputs @@ -278,7 +371,8 @@ doc /// p-adic valuation using prime p Description Text - A function to construct the p-adic valuation, returning the number of times that p divides the numerator minus the number of times it divides the denominator. + This valuation returns the number of times that $p$ divides the numerator + minus the number of times that $p$ divides the denominator. Example v = padicValuation 7; v 98 @@ -287,6 +381,11 @@ doc /// v (-42) SeeAlso valuation + Valuation + leadTermValuation + lowestTermValuation + localRingValuation + "trivialValuation" /// doc /// @@ -294,75 +393,100 @@ doc /// lowestTermValuation (lowestTermValuation, PolynomialRing) Headline - The valuation which returns the lowest term of an element of an ordered ring + The valuation defined by lowest terms Usage v = lowestTermValuation Inputs R:PolynomialRing + the ring whose term order is used to define the valuation Outputs v:Valuation - the lowest term valuation + the lowest term valuation Description Text - This valuation returns the lowest (trailing) term of a polynomial with respect to the ring's term order. - The valuation returns a value in an ordered module. For more details see @TO "Ordered modules"@. + This valuation returns the exponent vector of the + lowest (trailing) term of a polynomial with respect to the ring's term order. + This valuation returns the exponent vector of the + lead term of a polynomial with respect to the ring's term order. + The valuation returns vectors in an @TT "ordered $\\QQ$-module"@, + which respects the monomial order of the + @TO "PolynomialRing"@. For more details see @TO "Ordered modules"@. Example R = QQ[a,b,c, MonomialOrder => Lex]; vR = lowestTermValuation R; f = 13*a^2*b + a*c^3; + g = 5*a^2*c + b^3; vR f + vR f < vR g S = QQ[a,b,c, MonomialOrder => RevLex, Global => false]; vS = lowestTermValuation S; f = 13*a^2*b + a*c^3; + g = 5*a^2*c + b^3; vS f + vS f < vS g SeeAlso valuation + Valuation + leadTermValuation + localRingValuation + padicValuation + "trivialValuation" /// doc /// Key valuation (valuation, Function) - (valuation, Function, Ring, Ring) - (valuation, Function, Ring, Subring) - (valuation, Function, Ring, LocalRing) - (valuation, Function, Ring, RingOfInvariants) - (valuation, Function, Subring, Ring) - (valuation, Function, Subring, Subring) - (valuation, Function, Subring, LocalRing) - (valuation, Function, Subring, RingOfInvariants) - (valuation, Function, LocalRing, Ring) - (valuation, Function, LocalRing, Subring) - (valuation, Function, LocalRing, LocalRing) - (valuation, Function, LocalRing, RingOfInvariants) - (valuation, Function, RingOfInvariants, Ring) - (valuation, Function, RingOfInvariants, Subring) - (valuation, Function, RingOfInvariants, LocalRing) - (valuation, Function, RingOfInvariants, RingOfInvariants) + (valuation, Function, Ring, Ring) + (valuation, Function, Ring, Subring) + (valuation, Function, Ring, LocalRing) + (valuation, Function, Ring, RingOfInvariants) + (valuation, Function, Subring, Ring) + (valuation, Function, Subring, Subring) + (valuation, Function, Subring, LocalRing) + (valuation, Function, Subring, RingOfInvariants) + (valuation, Function, LocalRing, Ring) + (valuation, Function, LocalRing, Subring) + (valuation, Function, LocalRing, LocalRing) + (valuation, Function, LocalRing, RingOfInvariants) + (valuation, Function, RingOfInvariants, Ring) + (valuation, Function, RingOfInvariants, Subring) + (valuation, Function, RingOfInvariants, LocalRing) + (valuation, Function, RingOfInvariants, RingOfInvariants) Headline - Constructs a user defined valuation object + User-defined valuation object Usage v = valuation(f) v = valuation(f, S, T) Inputs f:Function + the valuation function. S:{Ring,LocalRing,Subring} + the domain T:{Ring,LocalRing,Subring} + the codomain Outputs v:Valuation - user defined valuation function + user-defined valuation function Description Text - A function to construct a user defined valuation function. + Construct a user defined valuation function. + User-defined functions are not checked for satisfying the + properties of a valuation. + It is not necessary to specify a domain or codomain, but + if they are provided, then the input is checked to + be in the domain (or promotable to the domain). + For common use cases, it is suggested to use the + provided valuations. Example v = valuation(x -> if x == 0 then infinity else 0) v = valuation(x -> if x == 0 then infinity else 0, ZZ, ZZ) SeeAlso lowestTermValuation - padicValuation - "trivialValuation" - leadTermValuation - localRingValuation + padicValuation + "trivialValuation" + leadTermValuation + localRingValuation /// doc /// @@ -370,19 +494,22 @@ doc /// leadTermValuation (leadTermValuation, PolynomialRing) Headline - The valuation which returns the exponent of the lead term of an element of an ordered ring + The valuation defined by leading terms Usage v = leadTermValuation R Inputs R:PolynomialRing + the ring whose term order is used to define the valuation Outputs v:Valuation - the lead term valuation - Description + the lead term valuation + Description Text - This valuation returns the exponent vector of the lead term of a polynomial with respect to the ring's term order. - The valuation returns vectors in an \textit{ordered $\QQ$-module}, which respects the monomial order of the - given @TO "PolynomialRing"@. For more details see @TO "Ordered modules"@. + This valuation returns the exponent vector of the + lead term of a polynomial with respect to the ring's term order. + The valuation returns vectors in an @TT "ordered $\\QQ$-module"@, + which respects the monomial order of the + @TO "PolynomialRing"@. For more details see @TO "Ordered modules"@. Example R = QQ[a,b,c, MonomialOrder => Lex]; v = leadTermValuation R; @@ -390,9 +517,14 @@ doc /// g = 5*a^2*c + b^3; v f v g - v f > v g - SeeAlso - valuation + v f < v g + SeeAlso + valuation + Valuation + localRingValuation + lowestTermValuation + padicValuation + "trivialValuation" /// doc /// @@ -400,29 +532,34 @@ doc /// localRingValuation (localRingValuation, LocalRing) Headline - Construct a local ring valuation given a local ring. + The valuation defined by a local ring. Usage v = localRingValuation(R) Inputs R:LocalRing - a local ring + the ring whose maximal ideal determines the order Outputs v:Valuation local ring valuation using a local ring R Description Text - A function to construct a local ring valuation. This function returns the largest power of the maximal ideal - of R that contains the input of the valuation. + This valuation returns the largest power of the maximal ideal + of R that contains the input to the valuation. Example R = QQ[x,y]; - I = ideal(x,y); - S = R_I - localVal = localRingValuation(S) - localVal(1 + x + y) - localVal(x^4 + x^2*y^2 + x^7 + y^3) - localVal(x^2 + x*y + y^2) + I = ideal(x,y); + S = R_I + localVal = localRingValuation(S) + localVal(1 + x + y) + localVal(x^4 + x^2*y^2 + x^7 + y^3) + localVal(x^2 + x*y + y^2) SeeAlso valuation + Valuation + leadTermValuation + lowestTermValuation + padicValuation + "trivialValuation" /// doc /// @@ -434,32 +571,53 @@ doc /// Text A valuation is a function $v:R\rightarrow G\cup\{\infty\}$ where $R$ is a ring and $G$ is a linearly ordered group with - the following properties: $v(ab)=v(a)+v(b)$, - $v(a+b)\geq\min\{v(a),v(b)\}$, and $v(a)=\infty$ iff $a=0$. - As implemented in @TT "Macaulay2"@, a valuation acts like @ofClass Function@, - perhaps with extra information. + the following properties: + Text + @UL {{"$v(ab)=v(a)+v(b)$,"}, + {"$v(a+b)\\geq\\min\\{v(a),v(b)\\}$, and"}, + {"$v(a)=\\infty$ iff $a=0$."}}@ + Text + The @TT "Valuations"@ package provides uniform constructions of + common valuations and user-defined valuations. + A valuation acts like @ofClass Function@, + but contains extra information. Example pval = padicValuation 3; pval(54) + pval(2) R = QQ[x,y]; leadval = leadTermValuation R; leadval(x^3+3*x^3*y^2+2*y^4) lowestval = lowestTermValuation R; lowestval(x^3+3*x^3*y^2+2*y^4) - pval(0) + lowestval(0) /// doc /// Key - Valuation + Valuation Headline - The type of all valuations + The type of all valuations Description - Text - @TT "Valuation"@ is a type that contains the data needed - to evaluate a valuation. + Text + @TT "Valuation"@ is a type that contains the data needed + to evaluate a @TT "valuation"@. + A valuation is a function $v:R\rightarrow G\cup\{\infty\}$ + where $R$ is a ring and $G$ is a linearly ordered group with + the following properties: + Text + @UL {{"$v(ab)=v(a)+v(b)$,"}, + {"$v(a+b)\\geq\\min\\{v(a),v(b)\\}$, and"}, + {"$v(a)=\\infty$ iff $a=0$."}}@ + Text + This package provides common valuations and user-defined valuations. SeeAlso - valuation + valuation + leadTermValuation + lowestTermValuation + localRingValuation + padicValuation + "trivialValuation" /// doc /// @@ -492,9 +650,77 @@ doc /// lowestTermValuation OrderedQQn orderedQQn +/// + +-* +doc /// + Key + "valM" + Headline + Add headline! + Description + Text + Add description! + Example + R = QQ[x_1, x_2, x_3]; + + A = subring { + x_1 + x_2 + x_3, + x_1*x_2 + x_1*x_3 + x_2*x_3, + x_1*x_2*x_3, + (x_1 - x_2)*(x_1 - x_3)*(x_2 - x_3) + }; + + S = QQ[e_1, e_2, e_3, y]; + + presMap = map(R, S, gens A); + I = ker presMap + + -- The primes cones of the tropical variety: + C = primeConesOfIdeal I + + -- turn them into weights: + flatten (C/coneToMatrix/(i -> positivity(tropicalVariety I, {i}))) + -- create weight valuations on the polynomial ring S + v0 = coneToValuation(C#0, I); + v1 = coneToValuation(C#1, I); + v2 = coneToValuation(C#2, I); + use S; + + v0(e_1^2 + e_2*e_3 - y^3) -- lead term from e_1^2 + v1(e_1^2 + e_2*e_3 - y^3) -- lead term from y^3 + v2(e_1^2 + e_2*e_3 - y^3) -- lead term from e_2*e_3 + + + -- create the induced valuation on the subring A + vA0 = valM(R, v0); + vA1 = valM(R, v1); + vA2 = valM(R, v2); + use R; + + vA0(x_1^2 + x_2^2 + x_3^2) + vA1(x_1^2 + x_2^2 + x_3^2) + vA2(x_1^2 + x_2^2 + x_3^2) + + vA0((x_1^2 - x_2^2)*(x_1^2 - x_3^2)*(x_2^2 - x_3^2)) + vA1((x_1^2 - x_2^2)*(x_1^2 - x_3^2)*(x_2^2 - x_3^2)) + vA2((x_1^2 - x_2^2)*(x_1^2 - x_3^2)*(x_2^2 - x_3^2)) + + vA0(0_R) + + -- Note, for elements not in A, the valuation returns nonsense + -- because the valuation does not come from a weight valuation + -- on R + vA0(x_2) + vA0(x_2^2) + vA0(x_2^3) + SeeAlso + /// +*- + doc /// Key OrderedQQn @@ -686,12 +912,12 @@ assert(val (7/9) == 1) TEST/// R = QQ[x,y] val = leadTermValuation(R) -assert(val(x) < val(y^2)) +assert(val(x) > val(y^2)) /// TEST/// R = QQ[x,y, MonomialOrder=>Lex] val = leadTermValuation(R) -assert(val(x) > val(y^2)) +assert(val(x) < val(y^2)) /// -- Lowest Term Valuation tests