Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion M2/Macaulay2/d/actors4.d
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,24 @@ 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))
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;
Expand Down
27 changes: 13 additions & 14 deletions M2/Macaulay2/d/gmp.d
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ export min(x:ulong,y:ulong):ulong := if x<y then x else y;

export max(x:ulong,y:ulong):ulong := if x<y then y else x;



isPositive0(x:ZZ) ::= 1 == Ccode(int, "mpz_sgn(", x, ")");
isZero0 (x:ZZ) ::= 0 == Ccode(int, "mpz_sgn(", x, ")");
isNegative0(x:ZZ) ::= -1 == Ccode(int, "mpz_sgn(", x, ")");
export sign(x:ZZ):int := Ccode(int, "mpz_sgn(", x, ")");
isPositive0(x:ZZ) ::= 1 == sign(x);
isZero0 (x:ZZ) ::= 0 == sign(x);
isNegative0(x:ZZ) ::= -1 == sign(x);

export isPositive(x:ZZ):bool := isPositive0(x);

Expand Down Expand Up @@ -645,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);
Expand Down Expand Up @@ -856,10 +856,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, ")");
Expand Down Expand Up @@ -2576,9 +2577,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

Expand Down
8 changes: 4 additions & 4 deletions M2/Macaulay2/d/gmp1.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions M2/Macaulay2/m2/exports.m2
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ export {
"showStructure",
"showTex",
"showUserStructure",
"sign",
"sin",
"singularLocus",
"sinh",
Expand Down
4 changes: 4 additions & 0 deletions M2/Macaulay2/m2/integers.m2
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> (
Expand Down
12 changes: 6 additions & 6 deletions M2/Macaulay2/packages/BettiCharacters.m2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

///

Expand Down Expand Up @@ -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
3 changes: 0 additions & 3 deletions M2/Macaulay2/packages/GradedLieAlgebras.m2
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export {
"mbRing",
"minimalModel",
"normalForm",
"sign",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed it from here, but several places in the documentation link to sign, which now goes to an irrelevant node in Macaulay2Doc.

"Signs",
"weight",
"VectorSpace",
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions M2/Macaulay2/packages/GradedLieAlgebras/doc.m2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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$).


Expand Down Expand Up @@ -249,7 +249,7 @@ doc ///
SeeAlso
lieDerivation
"isWellDefined(ZZ,LieDerivation)"
sign
(sign, LieDerivation)
"Homomorphisms and derivations"
///

Expand Down Expand Up @@ -717,7 +717,7 @@ Outputs
L: LieAlgebra
SeeAlso
lieAlgebra
sign
(sign, LieElement)
"Second Lie algebra tutorial"
Description
Text
Expand All @@ -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
Expand All @@ -743,7 +743,7 @@ Headline
name for an optional argument for lieAlgebra
SeeAlso
lieAlgebra
sign
(sign, LieElement)
"Second Lie algebra tutorial"
Description
Text
Expand Down Expand Up @@ -2171,7 +2171,7 @@ Description
(ext_1+2 ext_0) ext_2
SeeAlso
ExtAlgebra
sign
(sign, ExtElement)
weight

///
Expand Down
3 changes: 1 addition & 2 deletions M2/Macaulay2/packages/GradedLieAlgebras/doc2.m2
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -983,7 +983,6 @@ document {
}
document {
Key => {
sign,
(sign,LieElement),
(sign,ExtElement),
(sign,LieDerivation)
Expand Down
2 changes: 1 addition & 1 deletion M2/Macaulay2/packages/GradedLieAlgebras/tut2.m2
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
1 change: 1 addition & 0 deletions M2/Macaulay2/packages/Macaulay2Doc/functions.m2
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 29 additions & 0 deletions M2/Macaulay2/packages/Macaulay2Doc/functions/sign-doc.m2
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
doc ///
Key
sign
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a shared symbol, then it should be documented similar to other shared symbols, with links to nodes in other packages that enhance it.

(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)"
///
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Node
:Special functions
integrate
abs
sign
floor
(floor, Number)
ceiling
Expand Down
10 changes: 0 additions & 10 deletions M2/Macaulay2/packages/Parametrization.m2
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions M2/Macaulay2/packages/Permanents.m2
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -79,7 +79,7 @@ ryser Matrix := (M) -> (
prod=prod*s#i;
);

permanent = permanent+sign*prod;
permanent = permanent+sgn*prod;
);

permanent
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -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
Expand Down
Loading