diff --git a/M2/Macaulay2/m2/enginering.m2 b/M2/Macaulay2/m2/enginering.m2 index 5164cf7ce17..5dfce521e74 100644 --- a/M2/Macaulay2/m2/enginering.m2 +++ b/M2/Macaulay2/m2/enginering.m2 @@ -329,9 +329,13 @@ frac EngineRing := R -> if isField R then R else if R.?frac then R.frac else ( if R.?indexSymbols then F.indexSymbols = applyValues(R.indexSymbols, r -> promote(r,F)); if R.?indexStrings then F.indexStrings = applyValues(R.indexStrings, r -> promote(r,F)); if R.?numallvars then F.numallvars=R.numallvars; - scan(R.baseRings, S -> if S.?frac and not isPromotable(S.frac,F) then - promote(S.frac,F) := (a,F) -> fraction(promote(numerator a,R),promote(denominator a,R)) - ); + scan(R.baseRings, S -> if S.?frac and not isPromotable(S.frac,F) then ( + promote(S.frac,F) := (a,F) -> fraction(promote(numerator a,R),promote(denominator a,R)); + promote(List,S.frac,F) := (m,G,F) -> apply(m, d -> splice ( d | toList(degreeLength F-#d:0) )); -- TODO check + promote(Module,S.frac,F) := (M,G,F) -> F ** M; + promote(Matrix,S.frac,F) := (m,G,F) -> map(promote(target m,F),promote(source m,F),applyTable(entries m,x->promote(x,F))); + promote(MutableMatrix,S.frac,F) := (m,G,F) -> mutableMatrix applyTable(entries m,x->promote(x,F)); + )); F) -- methods for all ring elements diff --git a/M2/Macaulay2/m2/exports.m2 b/M2/Macaulay2/m2/exports.m2 index 2d9febd66ec..f9a22921c91 100644 --- a/M2/Macaulay2/m2/exports.m2 +++ b/M2/Macaulay2/m2/exports.m2 @@ -1028,6 +1028,7 @@ export { "projectiveHilbertPolynomial", "programPaths", "promote", + "promoteFromMap", "protect", "prune", "pruningMap", diff --git a/M2/Macaulay2/m2/matrix.m2 b/M2/Macaulay2/m2/matrix.m2 index 66ec39c5a35..27be32811e4 100644 --- a/M2/Macaulay2/m2/matrix.m2 +++ b/M2/Macaulay2/m2/matrix.m2 @@ -166,9 +166,9 @@ Matrix * Matrix := Matrix => (m,n) -> ( else ( R := ring m; S := ring target n; - if R =!= S then ( - try m = m ** S else - try n = n ** R else + if R =!= S then ( -- use toSameRing? + try m = promote(m,S) else + try n = promote(n,R) else error "maps over incompatible rings"; ); M = target m; diff --git a/M2/Macaulay2/m2/newring.m2 b/M2/Macaulay2/m2/newring.m2 index af59bf8b464..4e313936cc8 100644 --- a/M2/Macaulay2/m2/newring.m2 +++ b/M2/Macaulay2/m2/newring.m2 @@ -11,6 +11,18 @@ needs "matrix2.m2" -- for lift -- new polynomial ring or quotient ring from old -- ---------------------------------- +-- automate promotion +promoteFromMap = method() +promoteFromMap (Ring,Ring,RingMap) := (R,S,f) -> ( + promote(R,S) := (a,S1) -> f a; + promote(Matrix,R,S) := + promote(MutableMatrix,R,S) := -- doesn't work, cf https://github.com/Macaulay2/M2/issues/2192 + promote(Module,R,S) := (M,R1,S1) -> f M; -- TODO rethink carefully +-- promote(List,R,S) := (L,R1,S1) -> f\L; -- TODO put back!!!!!!!!!! + ) +promoteFromMap (Ring,Ring) := (R,S) -> promoteFromMap(R,S,map(S,R)) + + -- TODO: rewrite this to be easier to manage with degree group nothing := symbol nothing newRing = method( Options => applyValues(monoidDefaults, x -> nothing), TypicalValue => Ring ) @@ -77,7 +89,11 @@ tensor(QuotientRing, QuotientRing) := monoidTensorDefaults >> optns -> (R, S) fg := substitute(f,(vars AB)_{0 .. m-1}) | substitute(g,(vars AB)_{m .. m+n-1}); -- forceGB fg; -- if the monomial order chosen doesn't restrict, then this -- is an error!! MES - AB/image fg) + RS := AB/image fg; + promoteFromMap(R,RS,map(RS,R,(vars AB)_{0 .. m-1})); + promoteFromMap(S,RS,map(RS,S,(vars AB)_{m .. m+n-1})); + RS + ) ------------------------- -- Graph of a ring map -- diff --git a/M2/Macaulay2/packages/CotangentSchubert/cotangent.m2 b/M2/Macaulay2/packages/CotangentSchubert/cotangent.m2 index 7de27ab1719..68f335df80a 100644 --- a/M2/Macaulay2/packages/CotangentSchubert/cotangent.m2 +++ b/M2/Macaulay2/packages/CotangentSchubert/cotangent.m2 @@ -61,18 +61,6 @@ expandElem := (P,vrs,els) -> ( sub(C,ring first els) * product(#vrs, i -> (els#i)^(ee#i)) + expandElem(Q,vrs,els) ) --- automate promotion -promoteFromMap = method() -promoteFromMap (Ring,Ring,RingMap) := (R,S,f) -> ( - promote(R,S) := (a,S1) -> f a; - promote(Matrix,R,S) := - promote(MutableMatrix,R,S) := -- doesn't work, cf https://github.com/Macaulay2/M2/issues/2192 - promote(Module,R,S) := (M,R1,S1) -> f M; --- promote(List,R,S) := (L,R1,S1) -> f\L; -- TODO put back!!!!!!!!!! - S.baseRings = prepend(R,S.baseRings); -- temporary -- until promotability test improved in enginering.m2 - ) -promoteFromMap (Ring,Ring) := (R,S) -> promoteFromMap(R,S,map(S,R)) - tautoClass = method(Dispatch=>{Thing,Thing,Type},Options=>true); -- "Chern classes" -- renamed tautoClass to avoid confusion with motivic classes zeroSection = method(Dispatch=>{Type},Options=>true) -- note the {} dualZeroSection = method(Dispatch=>{Type},Options=>true) -- note the {}