Skip to content

Commit 859bf07

Browse files
committed
remove try in promote part 2
1 parent 5c5dae8 commit 859bf07

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

M2/Macaulay2/m2/classes.m2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ancestors = T -> unique join({T}, while (T = parent T) =!= Thing list T, {Thing
99
ancestors' = T -> unique join({T}, while (T = class T) =!= Type list T, {Type})
1010

1111
-- TODO: make this TT toString X later?
12-
synonym = X -> if X.?synonym then X.synonym else "object of class " | toString X
12+
synonym = X -> lookup(symbol synonym,X) -- X.synonym ?? "object of class " | toString X
1313
-- TODO: find a more permanent solution
1414
plurals = new MutableHashTable from {
1515
"body" => "bodies",
@@ -22,7 +22,7 @@ pluralize = s -> demark_" " append(
2222
drop(ws := separate_" " s, -1),
2323
if plurals#?(last ws)
2424
then plurals#(last ws) else last ws | "s")
25-
pluralsynonym = T -> if T.?synonym then pluralize T.synonym else "objects of class " | toString T
25+
pluralsynonym = T -> pluralize lookup(symbol synonym,T) -- pluralize T.synonym ?? "objects of class " | toString T
2626

2727
Time.synonym = "timing result"
2828
Boolean.synonym = "Boolean value"

M2/Macaulay2/m2/matrix.m2

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33

44
needs "modules.m2"
55

6+
notsamering := (X,Y) -> (
7+
if X === Y then error("expected ",pluralsynonym X, " for the same ring")
8+
else error("expected ",synonym X," and ",synonym Y," for the same ring"))
9+
samering = (M,N) -> if ring M === ring N then (M,N) else notsamering(class M,class N)
10+
nottosamering := (X,Y) -> (
11+
if X === Y then error("expected ",pluralsynonym X, " for compatible rings")
12+
else error("expected ",synonym X," and ",synonym Y," for compatible rings"))
13+
tosamering = (M,N) -> (
14+
R := ring M; S := ring N;
15+
if R =!= S then (
16+
if isPromotable(R,S) then (promote(M,S),N)
17+
else if isPromotable(S,R) then (M,promote(N,R))
18+
else nottosamering(class M,class N)
19+
)
20+
else (M,N))
21+
622
oops := R -> error (
723
if degreeLength R === 1
824
then "expected degree to be an integer or list of integers of length 1"
@@ -75,24 +91,15 @@ reduce = (tar,rawF) -> (
7591

7692
addHook(ReduceHooks, Strategy => Default, (tar, rawF) -> rawF % raw gb presentation tar)
7793

78-
toSameRing = (m,n) -> (
79-
R := ring m; S := ring n;
80-
if R =!= S then (
81-
if isPromotable(R,S) then (promote(m,S),n)
82-
else if isPromotable(S,R) then (m,promote(n,R))
83-
else error "expected compatible rings"
84-
)
85-
else (m,n))
86-
8794
InfiniteNumber * Matrix := (r,m) -> (map(target m, source m, matrix(r*(entries m))))
8895
Matrix * InfiniteNumber := (m,r) -> r*m
8996
Number * Matrix :=
9097
RingElement * Matrix := (r,m) -> (
91-
(r,m) = toSameRing(r,m);
98+
(r,m) = tosamering(r,m);
9299
map(target m, source m, reduce(target m, raw r * raw m)))
93100
Matrix * Number :=
94101
Matrix * RingElement := (m,r) -> (
95-
(r,m) = toSameRing(r,m);
102+
(r,m) = tosamering(r,m);
96103
map(target m, source m, reduce(target m, raw m * raw r)))
97104
Matrix / Number :=
98105
Matrix / RingElement := (m,r) -> m * (1/r)
@@ -129,7 +136,7 @@ Matrix == ZZ := (m,i) -> if i === 0 then rawIsZero m.RawMatrix else m - i == 0
129136

130137
Matrix + Matrix := Matrix => (
131138
(f,g) -> map(target f, source f, reduce(target f, raw f + raw g))
132-
) @@ toSameRing
139+
) @@ tosamering
133140
Matrix + RingElement :=
134141
Matrix + Number := (f,r) -> if r == 0 then f else f + r*id_(target f)
135142
RingElement + Matrix :=
@@ -139,7 +146,7 @@ Number + Vector := RingElement + Vector := (r,v) -> vector(r + matrix v)
139146

140147
Matrix - Matrix := Matrix => (
141148
(f,g) -> map(target f, source f, reduce(target f, raw f - raw g))
142-
) @@ toSameRing
149+
) @@ tosamering
143150
Matrix - RingElement :=
144151
Matrix - Number := (f,r) -> if r == 0 then f else f - r*id_(target f)
145152
RingElement - Matrix :=
@@ -177,7 +184,7 @@ Matrix * Matrix := Matrix => (m,n) -> (
177184
q,
178185
Degree => degree m + if m.?RingMap then m.RingMap.cache.DegreeMap degree n else degree n))
179186
else (
180-
(m,n) = toSameRing(m,n);
187+
(m,n) = tosamering(m,n);
181188
M = target m;
182189
P := source m;
183190
N = source n;
@@ -510,7 +517,7 @@ bothFree := (f,g) -> (
510517
or not isFreeModule source g or not isFreeModule target g then error "expected a homomorphism between free modules"
511518
else (f,g))
512519

513-
diff(Matrix, Matrix) := Matrix => ( (f,g) -> map(ring f, rawMatrixDiff(f.RawMatrix, g.RawMatrix)) ) @@ bothFree @@ toSameRing
520+
diff(Matrix, Matrix) := Matrix => ( (f,g) -> map(ring f, rawMatrixDiff(f.RawMatrix, g.RawMatrix)) ) @@ bothFree @@ tosamering
514521
diff(RingElement, RingElement) := RingElement => (f,g) -> (diff(matrix{{f}},matrix{{g}}))_(0,0)
515522
diff(Matrix, RingElement) := (m,f) -> diff(m,matrix{{f}})
516523
diff(RingElement, Matrix) := (f,m) -> diff(matrix{{f}},m)
@@ -520,7 +527,7 @@ diff(Vector, Vector) := (v,w) -> diff(matrix{v}, transpose matrix{w})
520527
diff(Matrix, Vector) := (m,w) -> diff(m,transpose matrix {w})
521528
diff(Vector, Matrix) := (v,m) -> diff(matrix {v}, m)
522529

523-
contract(Matrix, Matrix) := Matrix => ( (f,g) -> map(ring f, rawMatrixContract(f.RawMatrix, g.RawMatrix)) ) @@ bothFree @@ toSameRing
530+
contract(Matrix, Matrix) := Matrix => ( (f,g) -> map(ring f, rawMatrixContract(f.RawMatrix, g.RawMatrix)) ) @@ bothFree @@ tosamering
524531
contract(RingElement, RingElement) := RingElement => (f,g) -> (contract(matrix{{f}},matrix{{g}}))_(0,0)
525532
contract(Matrix, RingElement) := (m,f) -> contract(m,matrix{{f}})
526533
contract(RingElement, Matrix) := (f,m) -> contract(matrix{{f}},m)
@@ -538,8 +545,8 @@ contract(Number, Matrix) := (f,m) -> contract(matrix{{f}},m)
538545
contract(Vector, Number) := (v,f) -> (contract(matrix{v},matrix{{f}}))_0
539546
contract(Number, Vector) := (f,v) -> contract(matrix{{f}},transpose matrix{v})
540547

541-
diff'(Matrix, Matrix) := Matrix => ((m,n) -> ( flip(dual target n, target m) * diff(n,m) * flip(source m, dual source n) )) @@ bothFree @@ toSameRing
542-
contract'(Matrix, Matrix) := Matrix => ((m,n) -> ( flip(dual target n, target m) * contract(n,m) * flip(source m, dual source n) )) @@ bothFree @@ toSameRing
548+
diff'(Matrix, Matrix) := Matrix => ((m,n) -> ( flip(dual target n, target m) * diff(n,m) * flip(source m, dual source n) )) @@ bothFree @@ tosamering
549+
contract'(Matrix, Matrix) := Matrix => ((m,n) -> ( flip(dual target n, target m) * contract(n,m) * flip(source m, dual source n) )) @@ bothFree @@ tosamering
543550

544551
jacobian = method()
545552
jacobian Matrix := Matrix => (m) -> diff(transpose vars ring m, m)

M2/Macaulay2/m2/matrix1.m2

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ needs "quotient.m2"
66

77
-----------------------------------------------------------------------------
88

9-
notsamering := (X,Y) -> (
10-
if X === Y then error("expected ",pluralsynonym X, " for the same ring")
11-
else error("expected ",X.synonym," and ",Y.synonym," for the same ring"))
12-
nottosamering := (X,Y) -> (
13-
if X === Y then error("expected ",pluralsynonym X, " for compatible rings")
14-
else error("expected ",X.synonym," and ",Y.synonym," for compatible rings"))
15-
samering = (M,N) -> if ring M === ring N then (M,N) else notsamering(class M,class N)
16-
tosamering := (M,N) -> if ring M === ring N then (M,N) else ( -- need merging with toSameRing in matrix.m2
17-
z := try 0_(ring M) + 0_(ring N) else nottosamering(class M,class N);
18-
(promote(M,ring z),promote(N,ring z)))
19-
209
module Ring := Module => (cacheValue symbol module)(R -> R^1)
2110

2211
matrix(RingFamily,List) := Matrix => opts -> (R,m) -> matrix(default R, m, opts)
@@ -382,7 +371,7 @@ tensor(Matrix, Matrix) := Matrix => {} >> opts -> ((f, g) -> (
382371
map(target f ** target g,
383372
source f ** source g,
384373
map(R, f.RawMatrix ** g.RawMatrix),
385-
Degree => degree f + degree g))) @@ toSameRing
374+
Degree => degree f + degree g))) @@ tosamering
386375

387376
Matrix ** Module := Matrix => (f, M) -> tensor(f, id_M)
388377
Module ** Matrix := Matrix => (M, f) -> tensor(id_M, f)

0 commit comments

Comments
 (0)