Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted fixes #3509

Merged
merged 6 commits into from
Oct 7, 2024
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
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/actors.d
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export (lhs:Expr) * (rhs:Expr) : Expr := (
is null do buildErrorPacket(EngineError("monomial ideal multiplication failed"))
)
else binarymethod(lhs,rhs,StarS))
is x:RawMatrixCell do ( -- # typical value: symbol *, RawMatrix, RawRingElement, RawRingElement
is x:RawMatrixCell do ( -- # typical value: symbol *, RawMatrix, RawRingElement, RawMatrix
when rhs
is y:RawRingElementCell do (
when x.p*y.p
Expand Down
1 change: 0 additions & 1 deletion M2/Macaulay2/d/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export LocalQuote := {+Operator:Token, rhs:Token, local:void};
export Binary := {+lhs:ParseTree, Operator:Token, rhs:ParseTree};
export Unary := {+Operator:Token, rhs:ParseTree};
export Postfix:= {+lhs:ParseTree, Operator:Token};
export ArrayParseTree := array(ParseTree);
export Parentheses := {+ left:Token, contents:ParseTree, right:Token };
export EmptyParentheses := {+ left:Token, right:Token };
export dummy := {+position:Position};
Expand Down
24 changes: 0 additions & 24 deletions M2/Macaulay2/d/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -273,30 +273,6 @@ matcher(left:string):string := (
);
""
);
export varexprlist := {
list:array(ParseTree),
size:int
};
export newvarexprlist(i:int):varexprlist := varexprlist(
new array(ParseTree) len i do provide dummyTree,
0);
needatleast(i:int,v:varexprlist):void := (
if length(v.list) < i then (
v.list = new array(ParseTree) len 2*i do (
foreach e in v.list do provide e;
while true do provide dummyTree;
);
);
);
export (v:varexprlist) << (e:ParseTree) : varexprlist := (
needatleast(v.size + 1,v);
v.list.(v.size) = e;
v.size = v.size + 1;
v
);
export toexprlist(v:varexprlist):ArrayParseTree := (
new array(ParseTree) len v.size do foreach e in v.list do provide e
);
export unaryparen(left:Token,file:TokenFile,prec:int,obeylines:bool):ParseTree := (
rightparen := matcher(left.word.name);
if rightparen == peektoken(file,false).word.name
Expand Down
8 changes: 0 additions & 8 deletions M2/Macaulay2/m2/modules.m2
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,6 @@ isSubset(Module, Module) := (M, N) -> (

-----------------------------------------------------------------------------

-- the key for issub hooks under GlobalHookStore
protect ContainmentHooks
issub = (f, g) -> f === g or ring f === ring g and tryHooks(ContainmentHooks, (f, g),
-- This is used by isSubset and for checking equality of ideals and modules.
-- Specialized strategies may be added as hooks, for instance for local rings.
-- TODO: how can do better in the homogeneous case?
(f, g) -> -1 === rawGBContains(raw gb g, raw f))

-- used for sorting a list of modules
Module ? Module := (M, N) -> if rank M != rank N then rank M ? rank N else degrees M ? degrees N

Expand Down
2 changes: 1 addition & 1 deletion M2/Macaulay2/m2/monideal.m2
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ monomialIdeal Sequence := v -> monomialIdeal toList v
monomialIdeal RingElement := v -> monomialIdeal {v}

MonomialIdeal#1 = I -> monomialIdeal 1_(ring I)
MonomialIdeal ^ ZZ := MonomialIdeal => (I, n) -> monomialIdeal (ideal I)^n
MonomialIdeal ^ ZZ := MonomialIdeal => BinaryPowerMethod
MonomialIdeal ^ Array := MonomialIdeal => (I, e) -> monomialIdeal (ideal I)^e

MonomialIdeal + MonomialIdeal := MonomialIdeal => ((I, J) -> newMonomialIdeal(ring I, raw I + raw J)) @@ samering
Expand Down
2 changes: 2 additions & 0 deletions M2/Macaulay2/m2/monoids.m2
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ degree MonoidElement := m -> (
baseName MonoidElement := m -> if #(s := rawSparseListFormMonomial raw m) == 1 and s#0#1 == 1
then (class m).generatorSymbols#(s#0#0) else error "expected a generator"

promote(IndexedVariable, RingElement) := RingElement => (m, R) -> promote(value m, R)
promote(MonoidElement, RingElement) := RingElement => (m, R) -> (
k := coefficientRing first flattenRing R;
-- TODO: audit this code
Expand All @@ -89,6 +90,7 @@ promote(MonoidElement, RingElement) := RingElement => (m, R) -> (
then new R from rawTerm(R.RawRing, raw 1_k, m.RawMonomial)
else "expected monomial from same ring")

lift(IndexedVariable, MonoidElement) := MonoidElement => (m, M) -> lift(value m, M)
lift(RingElement, MonoidElement) := MonoidElement => (m, M) -> (
k := coefficientRing first flattenRing(R := ring m);
if instance(m, monoid k)
Expand Down
23 changes: 11 additions & 12 deletions M2/Macaulay2/packages/Macaulay2Doc/ov_language.m2
Original file line number Diff line number Diff line change
Expand Up @@ -606,18 +606,17 @@ document {
},
SeeAlso => {"if", "then"}
}
document { Key => "catch",
Headline => "catch a thrown exception", SeeAlso => {"throw"},
Usage => "catch c",
Outputs => {{"the value obtained by evaluating the code ", TT "c", ", or, if a ", TO "throw", " was executed during the evaluation of ", TT "c", ",
the argument given to ", TO "throw", "."}},
EXAMPLE lines ///
catch scan(0..10, i -> if i == 5 then throw 18 else print i)
///}
document { Key => "throw",
Headline => "throw an exception", SeeAlso => {"catch"},
Usage => "throw x",
Consequences => {{"the flow of control is passed to the surrounding ", TO "catch", ", and ", TT "x", " is returned as its value"}},
document {
Key => {"throw", "catch"},
Headline => "throw and catch exceptions",
Copy link
Member

Choose a reason for hiding this comment

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

Is "exception" the right term to use here? This makes it seem like these are used for dealing with errors.

Copy link
Member Author

@mahrud mahrud Oct 7, 2024

Choose a reason for hiding this comment

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

An exception doesn't have to be an error, you catch exceptions so they don't become errors (you can then choose to still signal an error in a perhaps more graceful way, but you can also just do something else instead to deal with the exception). Also the previous titles were "throw an exception" and "catch a thrown exception".

Copy link
Member

Choose a reason for hiding this comment

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

Works for me!

Usage => "catch c\nthrow x",
Outputs => {{
TT "catch", " returns the value obtained by evaluating the code ", TT "c",
", or, if a ", TT "throw", " was executed during the evaluation of ", TT "c",
", the argument given to ", TT "throw", "."}},
Consequences => {{
TT "throw", " passes the flow of control to the surrounding ", TT "catch",
", and ", TT "x", " is returned as its value"}},
EXAMPLE lines ///
catch scan(0..10, i -> if i == 5 then throw 18 else print i)
///}
Expand Down
13 changes: 9 additions & 4 deletions M2/Macaulay2/tests/normal/monideal4.m2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ I = monomialIdeal(a^3,b^2*c,a*c*d)
J = saturate(I,a)
J1 = monomialIdeal(1_R)
assert(J == monomialIdeal(1_R))
end
-- Local Variables:
-- compile-command: "make -C $M2BUILDDIR/Macaulay2/packages/Macaulay2Doc/test monideal4.out"
-- End:

R = QQ[x_1..x_10]
I = monomialIdeal vars R
(t, J) = toSequence elapsedTiming I^6;
assert(t < 1 and instance(J, MonomialIdeal) and numgens J == 5005)
(t, K) = toSequence elapsedTiming saturate J;
assert(t < 1 and instance(K, MonomialIdeal) and K == 1)
(t, L) = toSequence elapsedTiming radical J;
assert(t < 1 and instance(L, MonomialIdeal) and L == I)
Loading