3
3
4
4
needs " modules.m2"
5
5
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
+
6
22
oops := R -> error (
7
23
if degreeLength R === 1
8
24
then " expected degree to be an integer or list of integers of length 1"
@@ -75,24 +91,15 @@ reduce = (tar,rawF) -> (
75
91
76
92
addHook (ReduceHooks, Strategy => Default , (tar, rawF) -> rawF % raw gb presentation tar)
77
93
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
-
87
94
InfiniteNumber * Matrix := (r,m) -> (map (target m, source m, matrix (r* (entries m))))
88
95
Matrix * InfiniteNumber := (m,r) -> r* m
89
96
Number * Matrix :=
90
97
RingElement * Matrix := (r,m) -> (
91
- (r,m) = toSameRing (r,m);
98
+ (r,m) = tosamering (r,m);
92
99
map (target m, source m, reduce(target m, raw r * raw m)))
93
100
Matrix * Number :=
94
101
Matrix * RingElement := (m,r) -> (
95
- (r,m) = toSameRing (r,m);
102
+ (r,m) = tosamering (r,m);
96
103
map (target m, source m, reduce(target m, raw m * raw r)))
97
104
Matrix / Number :=
98
105
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
129
136
130
137
Matrix + Matrix := Matrix => (
131
138
(f,g) -> map (target f, source f, reduce(target f, raw f + raw g))
132
- ) @@ toSameRing
139
+ ) @@ tosamering
133
140
Matrix + RingElement :=
134
141
Matrix + Number := (f,r) -> if r == 0 then f else f + r* id_(target f)
135
142
RingElement + Matrix :=
@@ -139,7 +146,7 @@ Number + Vector := RingElement + Vector := (r,v) -> vector(r + matrix v)
139
146
140
147
Matrix - Matrix := Matrix => (
141
148
(f,g) -> map (target f, source f, reduce(target f, raw f - raw g))
142
- ) @@ toSameRing
149
+ ) @@ tosamering
143
150
Matrix - RingElement :=
144
151
Matrix - Number := (f,r) -> if r == 0 then f else f - r* id_(target f)
145
152
RingElement - Matrix :=
@@ -177,7 +184,7 @@ Matrix * Matrix := Matrix => (m,n) -> (
177
184
q,
178
185
Degree => degree m + if m.?RingMap then m.RingMap .cache .DegreeMap degree n else degree n))
179
186
else (
180
- (m,n) = toSameRing (m,n);
187
+ (m,n) = tosamering (m,n);
181
188
M = target m;
182
189
P := source m;
183
190
N = source n;
@@ -510,7 +517,7 @@ bothFree := (f,g) -> (
510
517
or not isFreeModule source g or not isFreeModule target g then error " expected a homomorphism between free modules"
511
518
else (f,g))
512
519
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
514
521
diff (RingElement , RingElement ) := RingElement => (f,g) -> (diff (matrix {{f}},matrix {{g}}))_(0,0)
515
522
diff (Matrix , RingElement ) := (m,f) -> diff (m,matrix {{f}})
516
523
diff (RingElement , Matrix ) := (f,m) -> diff (matrix {{f}},m)
@@ -520,7 +527,7 @@ diff(Vector, Vector) := (v,w) -> diff(matrix{v}, transpose matrix{w})
520
527
diff (Matrix , Vector ) := (m,w) -> diff (m,transpose matrix {w})
521
528
diff (Vector , Matrix ) := (v,m) -> diff (matrix {v}, m)
522
529
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
524
531
contract (RingElement , RingElement ) := RingElement => (f,g) -> (contract (matrix {{f}},matrix {{g}}))_(0,0)
525
532
contract (Matrix , RingElement ) := (m,f) -> contract (m,matrix {{f}})
526
533
contract (RingElement , Matrix ) := (f,m) -> contract (matrix {{f}},m)
@@ -538,8 +545,8 @@ contract(Number, Matrix) := (f,m) -> contract(matrix{{f}},m)
538
545
contract (Vector , Number ) := (v,f) -> (contract (matrix {v},matrix {{f}}))_0
539
546
contract (Number , Vector ) := (f,v) -> contract (matrix {{f}},transpose matrix {v})
540
547
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
543
550
544
551
jacobian = method ()
545
552
jacobian Matrix := Matrix => (m) -> diff (transpose vars ring m, m)
0 commit comments