From c3fda804a6fcf28f17a22223ee7d3e03ca9674c0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Mar 2026 08:10:25 +0000 Subject: [PATCH 1/3] Implement SA.promote_with_map for TypedPolynomials types Adds StarAlgebras as a dependency and implements promote_with_map for Variable, Monomial, Term, and Polynomial so that SA.promote_bases works when polynomials have different variable sets. https://claude.ai/code/session_01XSQkPA1sAWYPuKmRs3GEhd --- Project.toml | 2 ++ src/TypedPolynomials.jl | 1 + src/sa.jl | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/sa.jl diff --git a/Project.toml b/Project.toml index f61a4c4..422e8fb 100644 --- a/Project.toml +++ b/Project.toml @@ -11,10 +11,12 @@ MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" +StarAlgebras = "0c0c59c1-dc5f-42e9-9a8b-b5dc384a6cd1" [compat] MacroTools = "0.5" MultivariatePolynomials = "0.5.8" MutableArithmetics = "1" Reexport = "1" +StarAlgebras = "0.3" julia = "1.10" diff --git a/src/TypedPolynomials.jl b/src/TypedPolynomials.jl index 79eb06e..a7706fe 100644 --- a/src/TypedPolynomials.jl +++ b/src/TypedPolynomials.jl @@ -36,5 +36,6 @@ include("conversion.jl") include("promotion.jl") include("call.jl") include("macros.jl") +include("sa.jl") end # module diff --git a/src/sa.jl b/src/sa.jl new file mode 100644 index 0000000..a84f92a --- /dev/null +++ b/src/sa.jl @@ -0,0 +1,41 @@ +import StarAlgebras as SA + +function SA.promote_with_map( + m::Monomial{V,N}, + all_vars::Tuple{Vararg{Variable}}, + map::MP.ExponentMap, +) where {V,N} + new_exps = map(m.exponents) + M = length(all_vars) + new_mono = Monomial{all_vars,M}(new_exps) + return new_mono, map +end + +function SA.promote_with_map( + v::Variable, + all_vars::Tuple{Vararg{Variable}}, + map::MP.ExponentMap, +) + return SA.promote_with_map(Monomial(v), all_vars, map) +end + +function SA.promote_with_map( + t::MP.Term{C,<:Monomial}, + all_vars::Tuple{Vararg{Variable}}, + map::MP.ExponentMap, +) where {C} + new_mono, _ = SA.promote_with_map(monomial(t), all_vars, map) + return MP.Term(coefficient(t), new_mono), map +end + +function SA.promote_with_map( + p::MP.Polynomial{C,<:MP.Term{C,<:Monomial}}, + all_vars::Tuple{Vararg{Variable}}, + map::MP.ExponentMap, +) where {C} + new_terms = [begin + new_mono, _ = SA.promote_with_map(monomial(t), all_vars, map) + MP.Term(coefficient(t), new_mono) + end for t in terms(p)] + return polynomial(new_terms), map +end From 120b003d7ceab7d77b7afcf01e39271259674e9a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Mar 2026 08:13:34 +0000 Subject: [PATCH 2/3] Remove promote_with_map for Term and Polynomial These are handled generically by MultivariatePolynomials.jl. https://claude.ai/code/session_01XSQkPA1sAWYPuKmRs3GEhd --- src/sa.jl | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/sa.jl b/src/sa.jl index a84f92a..8dcdb96 100644 --- a/src/sa.jl +++ b/src/sa.jl @@ -19,23 +19,3 @@ function SA.promote_with_map( return SA.promote_with_map(Monomial(v), all_vars, map) end -function SA.promote_with_map( - t::MP.Term{C,<:Monomial}, - all_vars::Tuple{Vararg{Variable}}, - map::MP.ExponentMap, -) where {C} - new_mono, _ = SA.promote_with_map(monomial(t), all_vars, map) - return MP.Term(coefficient(t), new_mono), map -end - -function SA.promote_with_map( - p::MP.Polynomial{C,<:MP.Term{C,<:Monomial}}, - all_vars::Tuple{Vararg{Variable}}, - map::MP.ExponentMap, -) where {C} - new_terms = [begin - new_mono, _ = SA.promote_with_map(monomial(t), all_vars, map) - MP.Term(coefficient(t), new_mono) - end for t in terms(p)] - return polynomial(new_terms), map -end From cb7b515da73b0d7e0b88f33e83e0fed868fd7f4d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Mar 2026 11:14:22 +0000 Subject: [PATCH 3/3] Point MultivariatePolynomials to branch with StarAlgebras support The released MultivariatePolynomials doesn't have ExponentMap or StarAlgebras integration yet, so use the development branch. https://claude.ai/code/session_01XSQkPA1sAWYPuKmRs3GEhd --- Project.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Project.toml b/Project.toml index 422e8fb..0398304 100644 --- a/Project.toml +++ b/Project.toml @@ -20,3 +20,6 @@ MutableArithmetics = "1" Reexport = "1" StarAlgebras = "0.3" julia = "1.10" + +[sources] +MultivariatePolynomials = {url = "https://github.com/JuliaAlgebra/MultivariatePolynomials.jl.git", rev = "claude/implement-promote-basis-0gQqp"}