Skip to content

Commit

Permalink
Preserve source when using Number/RingElement +/- Matrix
Browse files Browse the repository at this point in the history
Previously, if the number/ring element appeared first, then the result
was a matrix whose source *and* target was the target of the original
matrix
  • Loading branch information
d-torrance committed Dec 9, 2024
1 parent 21a5b78 commit 216da0a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions M2/Macaulay2/m2/matrix.m2
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,20 @@ Matrix == ZZ := (m,i) -> if i === 0 then rawIsZero m.RawMatrix else m - i == 0
Matrix + Matrix := Matrix => (
(f,g) -> map(target f, source f, reduce(target f, raw f + raw g))
) @@ toSameRing
Matrix + RingElement := (f,r) -> if r == 0 then f else f + r*id_(target f)
RingElement + Matrix := (r,f) -> if r == 0 then f else r*id_(target f) + f
Number + Matrix := (i,f) -> if i === 0 then f else i*id_(target f) + f
Matrix + Number := (f,i) -> if i === 0 then f else f + i*id_(target f)
Matrix + RingElement :=
Matrix + Number := (f,r) -> if r == 0 then f else f + r*id_(target f)
RingElement + Matrix :=
Number + Matrix := (r,f) -> f + r
Vector + Number := Vector + RingElement := (v,r) -> vector(matrix v + r)
Number + Vector := RingElement + Vector := (r,v) -> vector(r + matrix v)

Matrix - Matrix := Matrix => (
(f,g) -> map(target f, source f, reduce(target f, raw f - raw g))
) @@ toSameRing
Matrix - RingElement := (f,r) -> if r == 0 then f else f - r*id_(target f)
RingElement - Matrix := (r,f) -> if r == 0 then -f else r*id_(target f) - f
Number - Matrix := (i,f) -> if i === 0 then -f else i*id_(target f) - f
Matrix - Number := (f,i) -> if i === 0 then f else f - i*id_(target f)
Matrix - RingElement :=
Matrix - Number := (f,r) -> if r == 0 then f else f - r*id_(target f)
RingElement - Matrix :=
Number - Matrix := (r,f) -> -f + r
Vector - Number := Vector - RingElement := (v,r) -> vector(matrix v - r)
Number - Vector := RingElement - Vector := (r,v) -> vector(r - matrix v)

Expand Down

0 comments on commit 216da0a

Please sign in to comment.