From c5288db69de04f36879463f2f019c13db8658c90 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 19 Jan 2025 15:30:10 -0500 Subject: [PATCH 1/9] Rename "sign" -> "signbit" in d directory More descriptive since it gives the value of the sign *bit* and wraps mpfr_signbit. Clears the way for us to use "sign" for wrapping various *_sgn functions from GMP and MPFR. Also simplify remove unused sign(RRi). --- M2/Macaulay2/d/actors4.d | 2 +- M2/Macaulay2/d/gmp.d | 4 +--- M2/Macaulay2/d/gmp1.d | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/M2/Macaulay2/d/actors4.d b/M2/Macaulay2/d/actors4.d index 93402ef6c79..157a983d495 100644 --- a/M2/Macaulay2/d/actors4.d +++ b/M2/Macaulay2/d/actors4.d @@ -99,7 +99,7 @@ setupfun("setGroupID",setpgidfun); absfun(e:Expr):Expr := ( when e is i:ZZcell do toExpr(abs(i.v)) - is x:RRcell do toExpr(if sign(x.v) then -x.v else x.v) + is x:RRcell do toExpr(if signbit(x.v) then -x.v else x.v) is x:RRicell do toExpr(abs(x.v)) is x:CCcell do toExpr(abs(x.v)) is r:QQcell do toExpr(abs(r.v)) diff --git a/M2/Macaulay2/d/gmp.d b/M2/Macaulay2/d/gmp.d index 0d01acfec81..70fc3140485 100644 --- a/M2/Macaulay2/d/gmp.d +++ b/M2/Macaulay2/d/gmp.d @@ -2576,9 +2576,7 @@ export yn(n:long,x:RR):RR := ( Ccode( void, "mpfr_yn(", z, ",",n,",", x, ", MPFR_RNDN)" ); moveToRRandclear(z)); -export sign(x:RR):bool := 0 != Ccode(int,"mpfr_signbit(",x,")"); - -export sign(x:RRi):bool := 0 != Ccode(int,"mpfi_is_neg(",x,")"); +export signbit(x:RR):bool := 0 != Ccode(int,"mpfr_signbit(",x,")"); -- complex transcendental functions diff --git a/M2/Macaulay2/d/gmp1.d b/M2/Macaulay2/d/gmp1.d index ee9a6745c5e..cb4bdb5d351 100644 --- a/M2/Macaulay2/d/gmp1.d +++ b/M2/Macaulay2/d/gmp1.d @@ -70,7 +70,7 @@ export format( sep:string, -- separator between mantissa and exponent x:RR -- the number to format ) : array(string) := ( -- return: ("-","132.456") or ("","123.456") - ng := sign(x); + ng := signbit(x); if isinf(x) then return array(string)(if ng then "-" else "","infinity"); if isnan(x) then return array(string)(if ng then "-" else "","NotANumber"); meaningful := int(floor(precision(x) / log2ten)) + 1; @@ -171,9 +171,9 @@ tostringRRipointer = tostringRRi; export toExternalString(x:RR):string := ( - if isinf(x) then return if x < 0 then "-infinity" else "infinity"; - if isnan(x) then return if sign(x) then "-NotANumber" else "NotANumber"; - ng := sign(x); + ng := signbit(x); + if isinf(x) then return if ng then "-infinity" else "infinity"; + if isnan(x) then return if ng then "-NotANumber" else "NotANumber"; if ng then x = -x; ex := long(0); s := getstr(ex, base, 0, x); From a420af2bddb4db99925857e03ea7c4e8deb8e751 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 19 Jan 2025 15:44:04 -0500 Subject: [PATCH 2/9] Add sign(ZZ) to d directory (wraps mpz_sgn) --- M2/Macaulay2/d/gmp.d | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/M2/Macaulay2/d/gmp.d b/M2/Macaulay2/d/gmp.d index 70fc3140485..af92aab7650 100644 --- a/M2/Macaulay2/d/gmp.d +++ b/M2/Macaulay2/d/gmp.d @@ -92,11 +92,10 @@ export min(x:ulong,y:ulong):ulong := if x Date: Sun, 19 Jan 2025 15:47:56 -0500 Subject: [PATCH 3/9] Add sign(RR) to d directory (wraps mpfr_sgn) --- M2/Macaulay2/d/gmp.d | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/M2/Macaulay2/d/gmp.d b/M2/Macaulay2/d/gmp.d index af92aab7650..256ad93fe07 100644 --- a/M2/Macaulay2/d/gmp.d +++ b/M2/Macaulay2/d/gmp.d @@ -855,10 +855,11 @@ export realPart(z:CC):RR := z.re; export imaginaryPart(z:CC):RR := z.im; -- warning: these routines just check the sign bit, and don't verify finiteness! -isPositive0(x:RR) ::= 1 == Ccode(int, "mpfr_sgn(", x, ")"); -isNegative0(x:RR) ::= -1 == Ccode(int, "mpfr_sgn(", x, ")"); -isZero0 (x:RR) ::= 0 == Ccode(int, "mpfr_sgn(", x, ")"); - +export sign(x:RR):int := Ccode(int, "mpfr_sgn(", x, ")"); +isPositive0(x:RR) ::= 1 == sign(x); +isNegative0(x:RR) ::= -1 == sign(x); +isZero0 (x:RR) ::= 0 == sign(x); + isPositive0(x:RRi) ::= 0 < Ccode(int, "mpfi_is_strictly_pos(", x, ")"); isNegative0(x:RRi) ::= 0 < Ccode(int, "mpfi_is_strictly_neg(", x, ")"); isZero0 (x:RRi) ::= 0 < Ccode(int, "mpfi_is_zero(", x, ")"); From d8ada8b476bd3fe9565eab2b7c7c590e4d1f1f78 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 19 Jan 2025 15:50:33 -0500 Subject: [PATCH 4/9] Add sign(QQ) to d directory (wraps mpq_sgn) --- M2/Macaulay2/d/gmp.d | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/M2/Macaulay2/d/gmp.d b/M2/Macaulay2/d/gmp.d index 256ad93fe07..552255b7fcc 100644 --- a/M2/Macaulay2/d/gmp.d +++ b/M2/Macaulay2/d/gmp.d @@ -644,8 +644,9 @@ export denominatorRef(x:QQmutable) ::= Ccode( ZZmutable, "mpq_denref(", x, ")") export hash(x:QQ):hash_t := hash(numeratorRef(x))+1299841*hash(denominatorRef(x)); -isZero0 (x:QQ):bool := 0 == Ccode(int, "mpq_sgn(",x,")"); -isNegative0(x:QQ):bool := -1 == Ccode(int, "mpq_sgn(",x,")"); +export sign(x:QQ):int := Ccode(int, "mpq_sgn(",x,")"); +isZero0 (x:QQ):bool := 0 == sign(x); +isNegative0(x:QQ):bool := -1 == sign(x); export isZero (x:QQ):bool := isZero0(x); export isNegative(x:QQ):bool := isNegative0(x); From af34bf3fe3a80d86ba397c7fdc87d6e2f38bce87 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 19 Jan 2025 15:55:46 -0500 Subject: [PATCH 5/9] Make interpreter "sign" functions available at top level --- M2/Macaulay2/d/actors4.d | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/M2/Macaulay2/d/actors4.d b/M2/Macaulay2/d/actors4.d index 157a983d495..88138e2e120 100644 --- a/M2/Macaulay2/d/actors4.d +++ b/M2/Macaulay2/d/actors4.d @@ -106,6 +106,17 @@ absfun(e:Expr):Expr := ( else WrongArg("a number, real or complex")); setupfun("abs0",absfun); +sign(e:Expr):Expr := ( + when e + is x:ZZcell do toExpr(sign(x.v)) + is x:QQcell do toExpr(sign(x.v)) + is x:RRcell do toExpr(sign(x.v)) + is x:CCcell do ( + if isZero(x.v) then toExpr(toCC(0, 0, precision(x.v))) + else toExpr(x.v / abs(x.v))) + else WrongArg("a number, real or complex")); +setupfun("sign0", sign); + select(a:Sequence,f:Expr):Expr := ( b := new array(bool) len length(a) do provide false; found := 0; From e7433d627fd137b5008d1ec802aec0d89b3b35d2 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 19 Jan 2025 15:59:25 -0500 Subject: [PATCH 6/9] Add top-level "sign" method --- M2/Macaulay2/m2/exports.m2 | 1 + M2/Macaulay2/m2/integers.m2 | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/M2/Macaulay2/m2/exports.m2 b/M2/Macaulay2/m2/exports.m2 index 72f7184cc7f..b0a8e63d6c1 100644 --- a/M2/Macaulay2/m2/exports.m2 +++ b/M2/Macaulay2/m2/exports.m2 @@ -1137,6 +1137,7 @@ export { "showStructure", "showTex", "showUserStructure", + "sign", "sin", "singularLocus", "sinh", diff --git a/M2/Macaulay2/m2/integers.m2 b/M2/Macaulay2/m2/integers.m2 index 1cb1eeb4a00..e014afbc673 100644 --- a/M2/Macaulay2/m2/integers.m2 +++ b/M2/Macaulay2/m2/integers.m2 @@ -57,6 +57,10 @@ abs = method() abs ZZ := abs RR := abs RRi := abs CC := abs QQ := abs0 abs Constant := abs @@ numeric +sign = method() +sign Number := sign0 +sign Constant := sign @@ numeric + lcm = method(Binary => true) installMethod(lcm, () -> 1) lcm(ZZ,ZZ) := (f,g) -> ( From c03d1ea326cdac4bb0c26306291b67f79c2c3755 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 19 Jan 2025 16:16:32 -0500 Subject: [PATCH 7/9] Remove conflicts in packages now that "sign" is in Core Either remove now-redundant methods or rename "sign" variables to "sgn". --- M2/Macaulay2/packages/BettiCharacters.m2 | 12 ++++++------ M2/Macaulay2/packages/GradedLieAlgebras.m2 | 3 --- M2/Macaulay2/packages/GradedLieAlgebras/doc.m2 | 14 +++++++------- M2/Macaulay2/packages/GradedLieAlgebras/doc2.m2 | 3 +-- M2/Macaulay2/packages/GradedLieAlgebras/tut2.m2 | 2 +- M2/Macaulay2/packages/Parametrization.m2 | 10 ---------- M2/Macaulay2/packages/Permanents.m2 | 12 ++++++------ M2/Macaulay2/packages/Permutations.m2 | 4 +--- M2/Macaulay2/packages/Permutations/docs.m2 | 11 +++++------ M2/Macaulay2/packages/RealRoots.m2 | 11 ----------- M2/Macaulay2/packages/Resultants.m2 | 4 ++-- M2/Macaulay2/packages/SchurComplexes.m2 | 4 ++-- M2/Macaulay2/packages/SpechtModule.m2 | 14 +++++++------- 13 files changed, 38 insertions(+), 66 deletions(-) diff --git a/M2/Macaulay2/packages/BettiCharacters.m2 b/M2/Macaulay2/packages/BettiCharacters.m2 index 1d1ffccc0c0..1d6d2b1d339 100644 --- a/M2/Macaulay2/packages/BettiCharacters.m2 +++ b/M2/Macaulay2/packages/BettiCharacters.m2 @@ -1120,9 +1120,9 @@ Node the sign character just constructed: the result is the same as the character of the resolution. Example - sign = character(R,15,hashTable {(0,{7}) => + sgn = character(R,15,hashTable {(0,{7}) => matrix{{1,-1,-1,1,-1,1,-1,1,1,-1,1,-1,1,-1,1}}}) - dual(c,id_QQ)[-5] ** sign === c + dual(c,id_QQ)[-5] ** sgn === c Text The second argument in the @TT "dual"@ command is the restriction of complex conjugation to the field of @@ -2840,8 +2840,8 @@ Node observed by tensoring with the character of the sign representation concentrated in degree 3. Example - sign = character(R,3, hashTable { (0,{3}) => matrix{{1,-1,1}} }) - dual(a,{1,2,3}) ** sign === a + sgn = character(R,3, hashTable { (0,{3}) => matrix{{1,-1,1}} }) + dual(a,{1,2,3}) ** sgn === a /// @@ -3062,10 +3062,10 @@ K = freeResolution ideal vars R S4 = symmetricGroupActors(R) A = action(K,S4) c = character A -sign = character(R,5, hashTable { (-4,{-4}) => matrix{{-1,1,1,-1,1}} }) +sgn = character(R,5, hashTable { (-4,{-4}) => matrix{{-1,1,1,-1,1}} }) -- check duality of representations in Koszul complex -- which is true up to a twist by a sign representation -assert(dual(c,id_QQ) == c ** sign) +assert(dual(c,id_QQ) == c ** sgn) /// end diff --git a/M2/Macaulay2/packages/GradedLieAlgebras.m2 b/M2/Macaulay2/packages/GradedLieAlgebras.m2 index 1611b97c8a9..d863f4006cd 100644 --- a/M2/Macaulay2/packages/GradedLieAlgebras.m2 +++ b/M2/Macaulay2/packages/GradedLieAlgebras.m2 @@ -72,7 +72,6 @@ export { "mbRing", "minimalModel", "normalForm", - "sign", "Signs", "weight", "VectorSpace", @@ -2464,8 +2463,6 @@ isignlocal(BasicList,LieAlgebra):=(x,L)-> -- the sign of an element -- in the Ext-algebra - -sign=method() sign(LieElement) := (x)->( L:=class x; -- xx:=normalForm(x); diff --git a/M2/Macaulay2/packages/GradedLieAlgebras/doc.m2 b/M2/Macaulay2/packages/GradedLieAlgebras/doc.m2 index 4d55d7c52e1..8043e106258 100644 --- a/M2/Macaulay2/packages/GradedLieAlgebras/doc.m2 +++ b/M2/Macaulay2/packages/GradedLieAlgebras/doc.m2 @@ -53,7 +53,7 @@ doc /// {\mathbb Z}^n\times {\mathbb Z}/2{\mathbb Z}$, where the first component is called the @TO degree@, and the last component - is called the @TO sign@, which is 0 or 1 and have effect + is called the @TO2{(sign, LieElement), "sign"}@, which is 0 or 1 and have effect on the axioms, see below. The list of components of the grading except the sign is called the @TO weight@, and the last component of the @@ -72,7 +72,7 @@ doc /// which are specified by @TO [lieAlgebra,Signs]@. The sign of a homogeneous element can be obtained by the function - @TO sign@. In the axioms + @TO (sign, LieElement)@. In the axioms below the sign of an element $a$ is written sign($a$). @@ -249,7 +249,7 @@ doc /// SeeAlso lieDerivation "isWellDefined(ZZ,LieDerivation)" - sign + (sign, LieDerivation) "Homomorphisms and derivations" /// @@ -717,7 +717,7 @@ Outputs L: LieAlgebra SeeAlso lieAlgebra - sign + (sign, LieElement) "Second Lie algebra tutorial" Description Text @@ -727,7 +727,7 @@ Description then all generators will be odd. The default value is that all generators are even. The signs affect the axioms of a Lie superalgebra, see @TO LieAlgebra@. - Use @TO sign@ to + Use @TO (sign, LieElement)@ to compute the sign of an arbitrary homogeneous Lie expression. Example @@ -743,7 +743,7 @@ Headline name for an optional argument for lieAlgebra SeeAlso lieAlgebra - sign + (sign, LieElement) "Second Lie algebra tutorial" Description Text @@ -2171,7 +2171,7 @@ Description (ext_1+2 ext_0) ext_2 SeeAlso ExtAlgebra - sign + (sign, ExtElement) weight /// diff --git a/M2/Macaulay2/packages/GradedLieAlgebras/doc2.m2 b/M2/Macaulay2/packages/GradedLieAlgebras/doc2.m2 index 171a7229bde..e79b04c8e9a 100644 --- a/M2/Macaulay2/packages/GradedLieAlgebras/doc2.m2 +++ b/M2/Macaulay2/packages/GradedLieAlgebras/doc2.m2 @@ -392,7 +392,7 @@ Headline => be thought of as arbitrary. The weight of a derivation $d$ is the weight of $d$ as a graded map and may also be obtained as ", TT "d#weight.", -SeeAlso => {"firstDegree(LieElement)","sign","degreeLength"}, +SeeAlso => {"firstDegree(LieElement)",(sign, LieElement),"degreeLength"}, SYNOPSIS { Usage => "w=weight(x)", @@ -983,7 +983,6 @@ document { } document { Key => { - sign, (sign,LieElement), (sign,ExtElement), (sign,LieDerivation) diff --git a/M2/Macaulay2/packages/GradedLieAlgebras/tut2.m2 b/M2/Macaulay2/packages/GradedLieAlgebras/tut2.m2 index 2d1b4c5a9bc..c79c2eddc24 100644 --- a/M2/Macaulay2/packages/GradedLieAlgebras/tut2.m2 +++ b/M2/Macaulay2/packages/GradedLieAlgebras/tut2.m2 @@ -82,7 +82,7 @@ doc /// defines the signs of all the generators to be 1. The signs affect the axioms of a Lie superalgebra, see @TO LieAlgebra@. - Use @TO sign@ to + Use @TO (sign, LieElement)@ to compute the sign of an arbitrary homogeneous Lie expression. diff --git a/M2/Macaulay2/packages/Parametrization.m2 b/M2/Macaulay2/packages/Parametrization.m2 index 3ca3dc2ec81..fb634806311 100644 --- a/M2/Macaulay2/packages/Parametrization.m2 +++ b/M2/Macaulay2/packages/Parametrization.m2 @@ -702,16 +702,6 @@ return(rslt); --p=rtpt(1180943,-14640196896); --p_(0,0)^2+1180943*p_(0,1)^2-14640196896*p_(0,2)^2 -sign=method() -sign(ZZ):=(n)->( -if n>0 then return(1); -if n<0 then return(-1); -0) -sign(QQ):=(n)->( -if n>0 then return(1); -if n<0 then return(-1); -0) - -- Jval(ZZ,ZZ,ZZ) -- computes the index of the argument diff --git a/M2/Macaulay2/packages/Permanents.m2 b/M2/Macaulay2/packages/Permanents.m2 index cc9d47a47f9..d1fa6908f59 100644 --- a/M2/Macaulay2/packages/Permanents.m2 +++ b/M2/Macaulay2/packages/Permanents.m2 @@ -50,7 +50,7 @@ ryser Matrix := (M) -> ( for i from 1 to n-1 do(del = append(del,0););--delta is of length n --take the initial product corresponding to delta all +1's - sign:=1; + sgn:=1; prod:=1; for i from 0 to n-1 do( prod=prod*s#i; @@ -60,7 +60,7 @@ ryser Matrix := (M) -> ( curIndex:=0;--which position in the gray code changed curVal:=0;--what is the new value in the changed position of the gray code for count from 2 to 2^n do(--start at 2 because we already took the initial product corresponding to delta consisting of all 1's - sign=(-1)*sign; + sgn=(-1)*sgn; --increment delta flag:=1; for k from 0 to n-1 when flag==1 do( @@ -79,7 +79,7 @@ ryser Matrix := (M) -> ( prod=prod*s#i; ); - permanent = permanent+sign*prod; + permanent = permanent+sgn*prod; ); permanent @@ -117,7 +117,7 @@ glynn Matrix := (M) -> ( for i from 1 to n-2 do(del = append(del,0););--delta is of length n-1 because first position is always positive, so we don't consider it in the gray code --take the initial product corresponding to delta all +1's - sign:=1; + sgn:=1; prod:=1; for i from 0 to n-1 do( prod=prod*s#i; @@ -127,7 +127,7 @@ glynn Matrix := (M) -> ( curIndex:=0;--which position in the gray code changed curVal:=0;--what is the new value in the changed position of the gray code for count from 2 to 2^(n-1) do(--start at 2 because we already took the initial product corresponding to delta consisting of all 1's - sign=(-1)*sign; + sgn=(-1)*sgn; --increment delta flag:=1; for k from 0 to n-2 when flag==1 do( @@ -146,7 +146,7 @@ glynn Matrix := (M) -> ( prod=prod*s#i; ); - perm = perm+sign*prod; + perm = perm+sgn*prod; ); --need to divide in Glynn's formula diff --git a/M2/Macaulay2/packages/Permutations.m2 b/M2/Macaulay2/packages/Permutations.m2 index 1caab5f06d9..d073a2a12e4 100644 --- a/M2/Macaulay2/packages/Permutations.m2 +++ b/M2/Macaulay2/packages/Permutations.m2 @@ -33,7 +33,6 @@ export { "isCDG", "foataBijection", "ord", - "sign", "isEven", "isOdd", "isDerangement", @@ -327,7 +326,6 @@ ord Permutation := ZZ => w -> ( -- see https://en.wikipedia.org/wiki/Parity_of_a_permutation for different ways -- to compute the sign or parity of a permutation -sign = method() sign Permutation := ZZ => w -> ( if even(#w - #(cycleDecomposition w)) then 1 else -1 ) @@ -377,4 +375,4 @@ installPackage "Permutations" restart needsPackage "Permutations" elapsedTime check "Permutations" -viewHelp "Permutations" \ No newline at end of file +viewHelp "Permutations" diff --git a/M2/Macaulay2/packages/Permutations/docs.m2 b/M2/Macaulay2/packages/Permutations/docs.m2 index 12337bc924b..141335cefd9 100644 --- a/M2/Macaulay2/packages/Permutations/docs.m2 +++ b/M2/Macaulay2/packages/Permutations/docs.m2 @@ -321,7 +321,7 @@ doc /// records trim saliances - sign + (sign, Permutation) (matrix, Permutation) /// @@ -1209,13 +1209,13 @@ doc /// Text A permutation $p$ is {\em even} if it can be written as a product of an even number of transpositions. Equivalently, a permutation is even if its - @TO sign@ is $1$. + @TO2 {(sign, Permutation), "sign"}@ is $1$. Example p = permutation {3,1,2,5,4} isEven p SeeAlso isOdd - sign + (sign, Permutation) /// -- isOdd @@ -1235,13 +1235,13 @@ doc /// Text A permutation $p$ is {\em odd} if it can be written as a product of an odd number of transpositions. Equivalently, a permutation is odd if its - @TO sign@ is $-1$. + @TO2 {(sign, Permutation), "sign"}@ is $-1$. Example p = permutation {3,1,2,5,4} isOdd p SeeAlso isEven - sign + (sign, Permutation) /// -- isWellDefined @@ -1425,7 +1425,6 @@ doc /// -- sign doc /// Key - sign (sign, Permutation) Headline computes the sign of a permutation diff --git a/M2/Macaulay2/packages/RealRoots.m2 b/M2/Macaulay2/packages/RealRoots.m2 index 8df8d2b6cf1..16177171f15 100644 --- a/M2/Macaulay2/packages/RealRoots.m2 +++ b/M2/Macaulay2/packages/RealRoots.m2 @@ -91,17 +91,6 @@ isArtinian (Ring) := Boolean => S->( dim S === 0 ) - ---Computes the sign of a real number -sign = method() -for A in {ZZ,QQ} do -sign (A) := ZZ => n->( - if n < 0 then -1 - else if n == 0 then 0 - else if n > 0 then 1 - ) - - --Computes the sign of a real univariate polynomial at a given real number signAt = method() for A in {ZZ,QQ} do diff --git a/M2/Macaulay2/packages/Resultants.m2 b/M2/Macaulay2/packages/Resultants.m2 index ad46e2d08e2..36677d3e801 100644 --- a/M2/Macaulay2/packages/Resultants.m2 +++ b/M2/Macaulay2/packages/Resultants.m2 @@ -384,14 +384,14 @@ detectGrassmannian (QuotientRing) := (G) -> ( duality = method(TypicalValue => RingMap); -- p. 94 [Gelfand, Kapranov, Zelevinsky - Discriminants, resultants, and multidimensional determinants, 1994] -sign = (permutation) -> sub(product(subsets(0..#permutation-1,2),I->(permutation_(I_1)-permutation_(I_0))/(I_1-I_0)),ZZ); -- thanks to Nivaldo Medeiros +sgn = (permutation) -> sub(product(subsets(0..#permutation-1,2),I->(permutation_(I_1)-permutation_(I_0))/(I_1-I_0)),ZZ); -- thanks to Nivaldo Medeiros tosequence = (L) -> if #L != 1 then toSequence L else L_0; duality(PolynomialRing) := (R) -> ( -- returns the map R:=G(k,P^n) ---> G(n-k-1,P^n*) (k,n,KK,p) := detectGrassmannian R; G := ambient Grass(k,n,KK,Variable=>p); G' := ambient Grass(n-k-1,n,KK,Variable=>p); - L := for U in subsets(set(0..n),n-k) list sign( (sort toList(set(0..n)-U)) | sort toList U) * (p_(tosequence sort toList(set(0..n)-U)))_G; + L := for U in subsets(set(0..n),n-k) list sgn( (sort toList(set(0..n)-U)) | sort toList U) * (p_(tosequence sort toList(set(0..n)-U)))_G; return(map(R,G,vars R) * map(G,G',L)); ); diff --git a/M2/Macaulay2/packages/SchurComplexes.m2 b/M2/Macaulay2/packages/SchurComplexes.m2 index 2a3a25e7eb8..ed36026c30a 100644 --- a/M2/Macaulay2/packages/SchurComplexes.m2 +++ b/M2/Macaulay2/packages/SchurComplexes.m2 @@ -251,7 +251,7 @@ homologicalDegree(HashTable,List,List) := (T,evengen,oddgen) -> sum for b in key ------Straightening algorithm --Inputs: U= List, V= permutation represented as a list. Outputs: sign of the induced permutation on the unmarked elements of U. -sign = (U,V)-> ( +sgn = (U,V)-> ( n:=#U; answer:=1; for i from 0 to n-2 do ( @@ -288,7 +288,7 @@ shuffle = (T, vio, downCol2, lambdaprime) -> ( indicesofL:=toList (0..(#L-1)); subsetsofLofsizetruncatedcol1:=subsets(indicesofL,#truncatedcol1); pairs1:=apply(subsetsofLofsizetruncatedcol1, x-> (x, indicesofL-(set x))); - signs:=apply(pairs1, x-> sign(L,join(x))); + signs:=apply(pairs1, x-> sgn(L,join(x))); outputlist:={}; dividedContributions := for i from 0 to (#pairs1-1) list ( dividedContribution := 1; --contribution from divided power multiplication diff --git a/M2/Macaulay2/packages/SpechtModule.m2 b/M2/Macaulay2/packages/SpechtModule.m2 index 4004c8bed4f..559a2621ade 100644 --- a/M2/Macaulay2/packages/SpechtModule.m2 +++ b/M2/Macaulay2/packages/SpechtModule.m2 @@ -912,8 +912,8 @@ garnirElement(YoungTableau,ZZ,ZZ,ZZ):= (tableau,coef,a,b)-> ( for j from a+1 to conju#b do ( newTableau_(j-1,b) = AB#(comb#j); ); - sign:=sortColumnsTableau(newTableau); - spechtModuleElement (newTableau, (coef) *sign*permutationSign(conjugacyClass(comb))) + sgn:=sortColumnsTableau(newTableau); + spechtModuleElement (newTableau, (coef) *sgn*permutationSign(conjugacyClass(comb))) )); ); @@ -941,9 +941,9 @@ sortColumnsTableau SpechtModuleElement := element -> y := youngTableau(element#partition,t); coef := element#values#t; remove(element#values,t); - sign:= sortColumnsTableau(y); - if(element#values#?(entries y)) then element#values#(entries y) = element#values#(entries y)+sign*coef - else element#values#(entries y) = coef*sign; + sgn:= sortColumnsTableau(y); + if(element#values#?(entries y)) then element#values#(entries y) = element#values#(entries y)+sgn*coef + else element#values#(entries y) = coef*sgn; ) ); ) @@ -1193,14 +1193,14 @@ higherSpechtPolynomial(YoungTableau, YoungTableau, PolynomialRing) := o-> (S,T,R rowPermutations := rowPermutationTableaux indexTableau S; ans = spechtPolynomial(T,R,AsExpression =>o.AsExpression)*sum(rowPermutations, tab -> product apply (numcols S, i-> ( - (sortedList,sign) := sortList(tab_i); + (sortedList,sgn) := sortList(tab_i); sortedList = sortedList - toList (0..(#(tab_i)-1)); sortedList = reverse sortedList; firstZero := position(sortedList,i->i==0); lastNonZero:= 0; if (firstZero === null) then lastNonZero = #sortedList-1 else lastNonZero = firstZero -1; partition:= new Partition from sortedList_{0..lastNonZero}; - sign*schurPolynomial(T_i,partition,R,AsExpression => o.AsExpression) + sgn*schurPolynomial(T_i,partition,R,AsExpression => o.AsExpression) ))) ); ans From 08fa32592ecd4cc856fdd601ee8a6b3e0ad06fd7 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 19 Jan 2025 16:22:07 -0500 Subject: [PATCH 8/9] Document "sign" --- .../packages/Macaulay2Doc/functions.m2 | 1 + .../Macaulay2Doc/functions/sign-doc.m2 | 29 +++++++++++++++++++ .../Macaulay2Doc/ov_analytic_functions.m2 | 1 + 3 files changed, 31 insertions(+) create mode 100644 M2/Macaulay2/packages/Macaulay2Doc/functions/sign-doc.m2 diff --git a/M2/Macaulay2/packages/Macaulay2Doc/functions.m2 b/M2/Macaulay2/packages/Macaulay2Doc/functions.m2 index 53dd45f3988..42e51a2d58b 100644 --- a/M2/Macaulay2/packages/Macaulay2Doc/functions.m2 +++ b/M2/Macaulay2/packages/Macaulay2Doc/functions.m2 @@ -247,6 +247,7 @@ load "./functions/setRandomSeed-doc.m2" load "./functions/setupLift-doc.m2" load "./functions/setupPromote-doc.m2" load "./functions/show-doc.m2" +load "./functions/sign-doc.m2" load "./functions/sin-doc.m2" load "./functions/sinh-doc.m2" load "./functions/smithNormalForm-doc.m2" diff --git a/M2/Macaulay2/packages/Macaulay2Doc/functions/sign-doc.m2 b/M2/Macaulay2/packages/Macaulay2Doc/functions/sign-doc.m2 new file mode 100644 index 00000000000..4419f085769 --- /dev/null +++ b/M2/Macaulay2/packages/Macaulay2Doc/functions/sign-doc.m2 @@ -0,0 +1,29 @@ +doc /// + Key + sign + (sign, Number) + (sign, Constant) + Headline + sign (signum) function + Usage + sign x + Inputs + x:Number + Outputs + :{ZZ,CC} + Description + Text + When @VAR "x"@ is real, then this returns 1 if it is positive, -1 if it + is negative, and 0 if it is zero. + Example + sign 5 + sign (-3) + sign 0 + Text + If @VAR "x"@ is complex and nonzero, then this returns $x/|x|$. + Example + sign(-7*ii) + SeeAlso + "GradedLieAlgebras::sign(LieElement)" + "Permutations::sign(Permutation)" +/// diff --git a/M2/Macaulay2/packages/Macaulay2Doc/ov_analytic_functions.m2 b/M2/Macaulay2/packages/Macaulay2Doc/ov_analytic_functions.m2 index 1ea6073664f..9436a8f7197 100644 --- a/M2/Macaulay2/packages/Macaulay2Doc/ov_analytic_functions.m2 +++ b/M2/Macaulay2/packages/Macaulay2Doc/ov_analytic_functions.m2 @@ -20,6 +20,7 @@ Node :Special functions integrate abs + sign floor (floor, Number) ceiling From 7ee829e212bc99ce7564369558b7999782d6718b Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 19 Jan 2025 16:23:35 -0500 Subject: [PATCH 9/9] Add tests for "sign" --- M2/Macaulay2/tests/normal/numbers.m2 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/M2/Macaulay2/tests/normal/numbers.m2 b/M2/Macaulay2/tests/normal/numbers.m2 index 30d5276a8ae..5a6f85d463e 100644 --- a/M2/Macaulay2/tests/normal/numbers.m2 +++ b/M2/Macaulay2/tests/normal/numbers.m2 @@ -1086,6 +1086,12 @@ assert( rawFareyApproximation(numeric pi, 10) == 22/7 ) assert( rawFareyApproximation(numeric pi, 200) == 355/113 ) assert( rawFareyApproximation(-pi, 10) == -22/7 ) +assert( sign 5 == 1 ) +assert( sign pi == 1 ) +assert( sign 0/1 == 0 ) +assert( sign(-3) == -1 ) +assert( sign(-5 * ii) == -ii ) + -- Local Variables: -- compile-command: "make -C $M2BUILDDIR/Macaulay2/packages/Macaulay2Doc/test numbers.out" -- End: