From d2cb646119a632e2100baeed337b07b134fa7007 Mon Sep 17 00:00:00 2001 From: kalmar Date: Wed, 12 Jul 2017 21:11:50 +0200 Subject: [PATCH] use additive group for objects involving Rings --- src/DirectProducts.jl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/DirectProducts.jl b/src/DirectProducts.jl index 4e6b7a5..1ff2ef9 100644 --- a/src/DirectProducts.jl +++ b/src/DirectProducts.jl @@ -152,9 +152,13 @@ end ############################################################################### function direct_mult(g::DirectProductGroupElem, h::DirectProductGroupElem) - parent(g) == parent(h) || throw("Can't multiply elements from different groups: $g, $h") - G = parent(g) - return G([op(a,b) for (op,a,b) in zip(G.operations, g.elts, h.elts)]) + G = parent(g) + # G == parent(h) || throw("Can't multiply elements from different groups: $G, $parent(h)") + if isa(first(G.factors), Ring) + return G(.+(g.elts,h.elts)) + else + return G(.*(g.elts,h.elts)) + end end doc""" @@ -179,7 +183,11 @@ doc""" # TODO: dirty hack around `+` operation function inv(g::DirectProductGroupElem) G = parent(g) - return G([(op == (*) ? inv(elt): -elt) for (op,elt) in zip(G.operations, g.elts)]) + if isa(first(G.factors), Ring) + return DirectProductGroupElem([-a for a in g.elts]) + else + return DirectProductGroupElem([inv(a) for a in g.elts]) + end end ###############################################################################