-
Notifications
You must be signed in to change notification settings - Fork 231
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
Promote #3494
base: development
Are you sure you want to change the base?
Promote #3494
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,7 +225,40 @@ commonEngineRingInitializations = (F) -> ( | |
*- | ||
) | ||
|
||
----------------------------------------------------------------------------- | ||
------------------------------------------------------------------------------ | ||
-- TODO improve this, or deprecate promote/lift(List,R,S) | ||
defaultDegMap := (R,S) -> ( | ||
n:=degreeLength S-degreeLength R; | ||
if n==0 then identity | ||
else if n<0 then d -> take(d,degreeLength S) | ||
else d -> d|toList(n:0) | ||
) | ||
|
||
-- automate promote | ||
setupPromote = method() | ||
setupPromote (Function,Ring,Ring,Function) := (f,R,S,degmap) -> ( | ||
promote(R,S) := (a,S) -> f a; | ||
promote(List,R,S) := (m,R,S) -> apply(m,degmap); | ||
-- promote(Matrix,R,S) := | ||
-- promote(MutableMatrix,R,S) := -- doesn't work, cf https://github.com/Macaulay2/M2/issues/2192 | ||
Comment on lines
+242
to
+243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused about these commented lines. Don't you have these exact methods implemented two lines below? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but not as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would it be? That wouldn't even work because |
||
promote(Module,R,S) := (M,R1,S1) -> S ** M; | ||
promote(Matrix,R,S) := (m,R,S) -> map(promote(target m,S),promote(source m,S),applyTable(entries m,x->promote(x,S))); | ||
promote(MutableMatrix,R,S) := (m,R,S) -> mutableMatrix applyTable(entries m,x->promote(x,S)); | ||
) | ||
setupPromote (Function,Ring,Ring) := (f,R,S) -> setupPromote(f,R,S,defaultDegMap(R,S)); | ||
|
||
-- automate (to some extent) lift | ||
setupLift = method() | ||
setupLift (Function,Ring,Ring,Function) := (f,R,S,degmap) -> ( | ||
lift(R,S) := opts -> (a,S) -> if opts.Verify then f a else try f a; | ||
lift(List,R,S) := opts -> (m,R,S) -> apply(m,degmap); | ||
lift(Module,R,S) := opts -> (M,R,S) -> S ** M; | ||
lift(Matrix,R,S) := opts -> (m,R,S) -> map(lift(target m,S),lift(source m,S),applyTable(entries m,x->lift(x,S))); | ||
lift(MutableMatrix,R,S) := opts -> (m,R,S) -> mutableMatrix applyTable(entries m,x->lift(x,S)); | ||
Comment on lines
+253
to
+257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good question. |
||
) | ||
setupLift (Function,Ring,Ring) := (f,R,S) -> setupLift(f,R,S,defaultDegMap(R,S)); | ||
|
||
----------------------------------------------------------------------------- | ||
reduce := (r,s) -> ( | ||
z := syz( matrix{{r,s}}, SyzygyLimit => 1 ); | ||
a := z_(1,0); | ||
|
@@ -329,6 +362,10 @@ 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 ( | ||
setupPromote(a->fraction(promote(numerator a,R),promote(denominator a,R)),S.frac,F); | ||
setupLift(a->fraction(lift(numerator a,S),lift(denominator a,S)),F,S.frac); | ||
)); | ||
F) | ||
|
||
-- methods for all ring elements | ||
|
@@ -466,6 +503,8 @@ swap = (x,y) -> (y,x) | |
promoterightexact = swap @@ promoteleftexact @@ swap | ||
promoterightinexact = swap @@ promoteleftinexact @@ swap | ||
|
||
isPromotable = (R,S) -> lookup(promote,R,S) =!= null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be defined next to |
||
|
||
divmod := R -> (f,g) -> ( | ||
(q,r) := rawDivMod(raw f, raw g); | ||
(new R from q, new R from r)) | ||
|
@@ -474,10 +513,10 @@ quotientRemainder(RingElement,RingElement) := (f,g) -> ( | |
S := ring g; | ||
m := quotientRemainder(R,S) := ( | ||
if R === S then divmod R | ||
else if isMember(R,S.baseRings) then ( | ||
else if isPromotable(R,S) then ( | ||
(x,y) -> divmod(promote(x,S), y) | ||
) | ||
else if isMember(S,R.baseRings) then ( | ||
else if isPromotable(S,R) then ( | ||
(x,y) -> divmod(x, promote(y,R)) | ||
) | ||
else error "expected pair to have a method for quotientRemainder" | ||
|
@@ -500,10 +539,10 @@ RingElement % RingElement := RingElement => (f,g) -> ( | |
if R === S then ( | ||
(x,y) -> new R from raw x % raw y | ||
) | ||
else if isMember(R,S.baseRings) then ( | ||
else if isPromotable(R,S) then ( | ||
(x,y) -> promote(x,S) % y | ||
) | ||
else if isMember(S,R.baseRings) then ( | ||
else if isPromotable(S,R) then ( | ||
(x,y) -> x % promote(y,R) | ||
) | ||
else error "expected pair to have a method for '%'" | ||
|
@@ -523,10 +562,10 @@ RingElement // RingElement := RingElement => (f,g) -> ( | |
if R === S then ( | ||
(x,y) -> new R from raw x // raw y | ||
) | ||
else if isMember(R,S.baseRings) then ( | ||
else if isPromotable(R,S) then ( | ||
(x,y) -> promote(x,S) // y | ||
) | ||
else if isMember(S,R.baseRings) then ( | ||
else if isPromotable(S,R) then ( | ||
(x,y) -> x // promote(y,R) | ||
) | ||
else error "expected pair to have a method for '//'" | ||
|
@@ -544,10 +583,10 @@ RingElement - RingElement := RingElement => (f,g) -> ( | |
if R === S then ( | ||
(x,y) -> new R from raw x - raw y | ||
) | ||
else if isMember(R,S.baseRings) then ( | ||
else if isPromotable(R,S) then ( | ||
(x,y) -> promote(x,S) - y | ||
) | ||
else if isMember(S,R.baseRings) then ( | ||
else if isPromotable(S,R) then ( | ||
(x,y) -> x - promote(y,R) | ||
) | ||
else error "expected pair to have a method for '-'" | ||
|
@@ -565,10 +604,10 @@ RingElement * RingElement := RingElement => (f,g) -> ( | |
if R === S then ( | ||
(x,y) -> new R from raw x * raw y | ||
) | ||
else if isMember(R,S.baseRings) then ( | ||
else if isPromotable(R,S) then ( | ||
(x,y) -> promote(x,S) * y | ||
) | ||
else if isMember(S,R.baseRings) then ( | ||
else if isPromotable(S,R) then ( | ||
(x,y) -> x * promote(y,R) | ||
) | ||
else error "expected pair to have a method for '*'" | ||
|
@@ -586,10 +625,10 @@ RingElement + RingElement := RingElement => (f,g) -> ( | |
if R === S then ( | ||
(x,y) -> new R from raw x + raw y | ||
) | ||
else if isMember(R,S.baseRings) then ( | ||
else if isPromotable(R,S) then ( | ||
(x,y) -> promote(x,S) + y | ||
) | ||
else if isMember(S,R.baseRings) then ( | ||
else if isPromotable(S,R) then ( | ||
(x,y) -> x + promote(y,R) | ||
) | ||
else error "expected pair to have a method for '+'" | ||
|
@@ -611,10 +650,10 @@ RingElement == RingElement := (f,g) -> ( | |
if R === S then ( | ||
(x,y) -> raw x === raw y | ||
) | ||
else if isMember(R,S.baseRings) then ( | ||
else if isPromotable(R,S) then ( | ||
(x,y) -> promote(x,S) == y | ||
) | ||
else if isMember(S,R.baseRings) then ( | ||
else if isPromotable(S,R) then ( | ||
(x,y) -> x == promote(y,R) | ||
) | ||
else error "expected pair to have a method for '=='" | ||
|
@@ -630,10 +669,10 @@ RingElement / RingElement := RingElement => (f,g) -> ( | |
frac R; | ||
(r,s) -> fraction (r,s) | ||
) | ||
else if isMember(R,S.baseRings) then ( | ||
else if isPromotable(R,S) then ( | ||
(x,y) -> promote(x,S) / y | ||
) | ||
else if isMember(S,R.baseRings) then ( | ||
else if isPromotable(S,R) then ( | ||
(x,y) -> x / promote(y,R) | ||
) | ||
else error "expected pair to have a method for '/'" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,7 +281,7 @@ char QuotientRing := (stashValue symbol char) ((S) -> ( | |
g := generators gb relns; | ||
if g == 0 then return char ring g; | ||
m := g_(0,0); | ||
if liftable(m,ZZ) then lift(m,ZZ) else 0)) | ||
lift(m,ZZ,Verify=>false) ?? 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I understand the motivation in this change. I like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in general I would agree with you but here's a pretty clear-cut case where we're basically calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually a little confused about what's happening in this code, but sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a second thought, basically any time someone calls isLiftable, a potential call to lift is on the horizon, no? |
||
|
||
singularLocus = method() | ||
singularLocus(Ring) := QuotientRing => (R) -> ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,6 @@ needs "mutablemat.m2" | |
-- should do something about the degree map here | ||
degmap0 := n -> ( d := toList ( n : 0 ); e -> d ) | ||
|
||
workable = f -> try (f(); true) else false | ||
|
||
----------------------------------------------------------------------------- | ||
-- RingMap type declarations and basic methods | ||
----------------------------------------------------------------------------- | ||
|
@@ -85,7 +83,7 @@ map(Ring, Ring, Matrix) := RingMap => opts -> (R, S, m) -> ( | |
" into a degree of length ", toString degreeLength R); | ||
opts.DegreeMap | ||
) | ||
else if workable (() -> promote({},S,R)) then (d -> first promote({d},S,R)) | ||
else if (pr:=lookup(promote,List,S,R)) =!= null then (d -> first pr({d},S,R)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, I didn't know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the record I fixed this line because it could create infinite loops. It pretty much never occurred before because there were few There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would be in favor of deprecating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe just |
||
else if degreeLength R === degreeLength S then identity | ||
else if degreeLength S === 0 or degreeLength R === 0 then degmap0 degreeLength R | ||
else ( | ||
|
@@ -125,7 +123,7 @@ map(Ring, Ring, Matrix) := RingMap => opts -> (R, S, m) -> ( | |
else if r < n then error ("encountered values for ", toString r, " variables, but expected ", toString n) | ||
else if r == n then ( | ||
if numgens A > 0 then ( | ||
if A === R or isMember(A, R.baseRings) then ( | ||
if A === R or isPromotable(A, R) then ( | ||
-- we can promote | ||
mE = mE | promote(vars A, R); | ||
if instance(A,GaloisField) and A.rawGaloisField then ( | ||
|
@@ -569,6 +567,18 @@ map(Module,Module,RingMap,List) := Matrix => o -> (M,N,p,f) -> map(M,N,p,map(M,r | |
map(Module,Nothing,RingMap,List) := Matrix => o -> (M,N,p,f) -> map(M,N,p,map(M,,f),o) | ||
map(Module,RingMap) := Matrix => o -> (M,p) -> map(M,,p,map(M,cover M,1),o) | ||
|
||
-- | ||
setupPromote (RingMap,Ring,Ring,Function) := lookup(setupPromote,Function,Ring,Ring,Function) | ||
setupPromote (RingMap,Ring,Ring) := (f,R,S) -> setupPromote(f,R,S,f.cache.DegreeMap) | ||
-- note that promote(Module,R,S) := (M,R,S) -> f ** M would make more sense, but promote only works with free modules anyway | ||
setupPromote RingMap := f -> setupPromote(f,source f,target f) | ||
setupPromote (Ring,Ring) := (R,S) -> setupPromote map(S,R) | ||
|
||
setupLift (RingMap,Ring,Ring) := (f,R,S) -> -- f is a partial inverse to the promote map | ||
setupLift( a -> ( b := f a; if promote(b,R) == a then b else error "cannot lift" ), R,S,f.cache.DegreeMap); | ||
|
||
setupLift RingMap := f -> setupLift(f,source f,target f) | ||
|
||
-- Local Variables: | ||
-- compile-command: "make -C $M2BUILDDIR/Macaulay2/m2 " | ||
-- End: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hash changed again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a pain, we should set up the emacs stuff differently so it doesn't occur...