diff --git a/M2/Macaulay2/m2/matrix.m2 b/M2/Macaulay2/m2/matrix.m2 index 66ec39c5a3..fbe2059657 100644 --- a/M2/Macaulay2/m2/matrix.m2 +++ b/M2/Macaulay2/m2/matrix.m2 @@ -625,11 +625,28 @@ isSubquotient(Module,Module) := (M,N) -> ( relations N % relations M == 0 ) +----------------------------------------------------------------------------- +-- inducedMap +----------------------------------------------------------------------------- + inducedMap = method ( Options => { Verify => true, Degree => null }) +-- TODO: hookify this, so people can add more application specific induced maps +inducedMap(Module, Module) := Matrix => opts -> (M, N) -> ( + if ambient M =!= ambient N then error "inducedMap: expected modules with same ambient free module"; + -- e.g. avoid a gb computation for inducedMap(M, image basis(d, M)) + if N.cache.?Monomials and M === target N.cache.Monomials + then map(M, N, N.cache.Monomials, Degree => opts.Degree) + else inducedMap(M, N, id_(ambient N), opts)) +inducedMap(Module, Nothing, Matrix) := Matrix => opts -> (M, N, f) -> ( + B := image f; + -- e.g. avoid a gb computation for inducedMap(image f, , f) + if M === target B.cache.Monomials + then map(M, source B.cache.Monomials, B.cache.Monomials, Degree => opts.Degree) + else inducedMap(M, source f, f, opts)) inducedMap(Module,Module,Matrix) := Matrix => opts -> (N',M',f) -> ( N := target f; M := source f; @@ -651,7 +668,6 @@ inducedMap(Module,Module,Matrix) := Matrix => opts -> (N',M',f) -> ( if not isWellDefined f' then error "inducedMap: expected matrix to induce a well-defined map"; ); f') -inducedMap(Module,Nothing,Matrix) := o -> (M,N,f) -> inducedMap(M,source f, f,o) inducedMap(Nothing,Module,Matrix) := o -> (M,N,f) -> inducedMap(target f,N, f,o) inducedMap(Nothing,Nothing,Matrix) := o -> (M,N,f) -> inducedMap(target f,source f, f,o) @@ -665,10 +681,6 @@ addHook((inducedMap, Module, Module, Matrix), Strategy => Default, (opts, N', M' f' = map(N',M',f',Degree => if opts.Degree === null then degree f else opts.Degree); (f', g, gbN', gbM))) -inducedMap(Module,Module) := Matrix => o -> (M,N) -> ( - if ambient M =!= ambient N then error "inducedMap: expected modules with same ambient free module"; - inducedMap(M,N,id_(ambient N),o)) - -- TODO: deprecate this in favor of isWellDefined inducesWellDefinedMap = method(TypicalValue => Boolean) inducesWellDefinedMap(Module,Module,Matrix) := (M,N,f) -> ( @@ -685,6 +697,8 @@ inducesWellDefinedMap(Module,Nothing,Matrix) := (M,N,f) -> inducesWellDefinedMap inducesWellDefinedMap(Nothing,Module,Matrix) := (M,N,f) -> inducesWellDefinedMap(target f,N,f) inducesWellDefinedMap(Nothing,Nothing,Matrix) := (M,N,f) -> true +----------------------------------------------------------------------------- + vars Ring := Matrix => R -> ( g := generators R; if R.?vars then R.vars else R.vars =