Skip to content

Commit

Permalink
incorporated the new augmented ??= operator in Core
Browse files Browse the repository at this point in the history
  • Loading branch information
mahrud committed Oct 15, 2024
1 parent 57f45a0 commit c07017e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
7 changes: 2 additions & 5 deletions M2/Macaulay2/m2/computations.m2
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,11 @@ new Computation from HashTable := (C, T) -> new C from { Result => null }
-- if there is a compatible computation stored in T.cache,
-- returns the computation container, otherwise creates the entry:
-- Context => Computation
-- TODO: look for other compatible contexts as well
fetchComputation = method(Options => true)
fetchComputation(Type, HashTable, Context) := Computation => true >> opts -> (C, T, context) -> fetchComputation(C, T, T, context)
fetchComputation(Type, HashTable, Sequence, Context) :=
fetchComputation(Type, HashTable, HashTable, Context) := Computation => true >> opts -> (C, T, X, context) -> (
-- TODO: look for other compatible contexts as well
-- TODO: use https://github.com/Macaulay2/M2/issues/1596 when it is implemented
if T.cache#?context then T.cache#context
else T.cache#context = new C from X)
fetchComputation(Type, HashTable, HashTable, Context) := Computation => true >> opts -> (C, T, X, context) -> T.cache#context ??= new C from X

-----------------------------------------------------------------------------
-- isComputationDone
Expand Down
6 changes: 3 additions & 3 deletions M2/Macaulay2/m2/gb.m2
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ degreeToHeft = (R, d) -> (
gb = method(TypicalValue => GroebnerBasis, Options => gbDefaults)
gb Ideal := GroebnerBasis => opts -> I -> gb (module I, opts)
gb Module := GroebnerBasis => opts -> M -> (
if M.?relations then (
if not M.cache#?"full gens" then M.cache#"full gens" = generators M | relations M;
gb(M.cache#"full gens", opts, SyzygyRows => numgens source generators M))
if M.?relations then gb(
M.cache#"full gens" ??= generators M | relations M, opts,
SyzygyRows => numgens source generators M)
else gb(generators M, opts))
gb Matrix := GroebnerBasis => opts -> m -> (
checkArgGB m;
Expand Down
4 changes: 1 addition & 3 deletions M2/Macaulay2/m2/matrix2.m2
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ addHook((quotient, Matrix, Matrix), Strategy => "Reflexive", (opts, f, g) -> if
f' := matrix f;
g' := matrix g;
G := (
if g.cache#?"gb for quotient"
then g.cache#"gb for quotient"
else g.cache#"gb for quotient" = (
g.cache#"gb for quotient" ??= (
if M.?relations
then gb(g' | relations M, ChangeMatrix => true, SyzygyRows => rank source g')
else gb(g', ChangeMatrix => true)));
Expand Down
4 changes: 2 additions & 2 deletions M2/Macaulay2/m2/modules2.m2
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Module _ ZZ := Vector => (M,i) -> (
new target p from {p})
-----------------------------------------------------------------------------
-- TODO: is caching here wise? There are 2^(#comps) many possibilities
Module ^ Array := Matrix => (M,w) -> if M.cache#?(symbol ^,w) then M.cache#(symbol ^,w) else M.cache#(symbol ^,w) = (
Module ^ Array := Matrix => (M,w) -> M.cache#(symbol ^, w) ??= (
-- we don't splice any more because natural indices include pairs (i,j).
w = toList w;
if not M.cache.?components then error "expected a direct sum module";
Expand All @@ -304,7 +304,7 @@ Module ^ Array := Matrix => (M,w) -> if M.cache#?(symbol ^,w) then M.cache#(symb
if oldw =!= null then newcomps = apply(oldw,newcomps,(i,M) -> i => M); -- warning: duplicate entries in oldw will lead to inaccessible components
map(directSum newcomps, M, (cover M)^(splice apply(w, i -> v#i))))

Module _ Array := Matrix => (M,w) -> if M.cache#?(symbol _,w) then M.cache#(symbol _,w) else M.cache#(symbol _,w) = (
Module _ Array := Matrix => (M,w) -> M.cache#(symbol _, w) ??= (
-- we don't splice any more because natural indices include pairs (i,j).
w = toList w;
if not M.cache.?components then error "expected a direct sum module";
Expand Down
15 changes: 6 additions & 9 deletions M2/Macaulay2/m2/multilin.m2
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ symmetricAlgebra Module := Ring => opts -> (cacheValue (symmetricAlgebra => opts
S.Module = M;
S))

symmetricAlgebra(Ring, Ring, Matrix) := RingMap => o -> (T, S, f) -> (
if f.cache#?(key := (symmetricAlgebra, T, S, f)) then f.cache#key else f.cache#key = (
symmetricAlgebra(Ring, Ring, Matrix) := RingMap => o -> (T, S, f) -> f.cache#(symmetricAlgebra, T, S, f) ??= (
p := map(T, S, vars T * promote(cover f, T));
if f.cache.?inverse then p.cache.inverse = (
map(S, T, vars S * promote(cover inverse f, S)));
p))
p)
symmetricAlgebra Matrix := RingMap => o -> f -> symmetricAlgebra(symmetricAlgebra target f, symmetricAlgebra source f, f)
symmetricAlgebra(Nothing, Nothing, Matrix) := RingMap => o -> (T, S, f) -> symmetricAlgebra(symmetricAlgebra target f, symmetricAlgebra source f, f)
symmetricAlgebra(Nothing, Ring, Matrix) := RingMap => o -> (T, S, f) -> symmetricAlgebra(symmetricAlgebra target f, S, f)
Expand All @@ -72,21 +71,19 @@ symmetricAlgebra(Ring, Nothing, Matrix) := RingMap => o -> (T, S, f) -> symme
-----------------------------------------------------------------------------

symmetricPower = method()
symmetricPower(ZZ, Module) := Module => (p, M) -> (
if M.cache#?(key := (symmetricPower, p)) then M.cache#key else M.cache#key = (
symmetricPower(ZZ, Module) := Module => (p, M) -> M.cache#(symmetricPower, p) ??= (
R := ring M;
if p < 0 then R^0 else
if p === 0 then R^1 else
if p === 1 then M else
if isFreeModule M then new Module from (R, rawSymmetricPower(p, raw M))
else coimage basis(p, symmetricAlgebra M,
SourceRing => ring M, Degree => {p, degreeLength R:0})
))
)
symmetricPower(ZZ, Matrix) := Matrix => (i, m) -> map(ring m, rawSymmetricPower(i, raw m))

exteriorPower = method(Options => { Strategy => null })
exteriorPower(ZZ, Module) := Module => opts -> (p, M) -> (
if M.cache#?(exteriorPower, p) then M.cache#(exteriorPower, p) else M.cache#(exteriorPower, p) = (
exteriorPower(ZZ, Module) := Module => opts -> (p, M) -> M.cache#(exteriorPower, p) ??= (
R := ring M;
if p < 0 then R^0 else
if p === 0 then R^1 else
Expand All @@ -99,7 +96,7 @@ exteriorPower(ZZ, Module) := Module => opts -> (p, M) -> (
h1 := m ** id_Fp1;
h2 := wedgeProduct(1,p-1,F);
cokernel(h2 * h1))
))
)

exteriorPower(ZZ, Matrix) := Matrix => opts -> (p, m) -> (
R := ring m;
Expand Down

0 comments on commit c07017e

Please sign in to comment.