From ec8a51caaeba759850b8c1fc7983b24d2223164c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 29 Mar 2026 18:08:22 +0000 Subject: [PATCH 1/2] Define `is_commutative` function interface Add `is_commutative(::Type)` to the public API so that implementations like DynamicPolynomials can report whether their variable types are commutative. This is needed by JuliaAlgebra/DynamicPolynomials.jl#188. https://claude.ai/code/session_01UFdPE6xGLMLByASjKdDWJa --- src/variable.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/variable.jl b/src/variable.jl index 709d6c86..3161d6c5 100644 --- a/src/variable.jl +++ b/src/variable.jl @@ -40,6 +40,15 @@ This operation is not type stable for the TypedPolynomials implementation if `nv """ variable(t::_APL) = convert(variable_union_type(t), t) +""" + is_commutative(::Type{<:AbstractVariable})::Bool + +Returns whether variables of the given type are commutative, i.e., whether +`x * y == y * x`. +""" +function is_commutative end +is_commutative(::Union{AbstractPolynomialLike,AbstractVector{<:AbstractPolynomialLike}}) = error("`is_commutative` should be implemented for types, not instances. Use `is_commutative(typeof(x))` instead.") + """ name(v::AbstractVariable)::AbstractString From d6ad5c734c8853f51f37f1dedca323998dd0054d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Tue, 31 Mar 2026 20:31:10 +0200 Subject: [PATCH 2/2] Fixes --- docs/src/types.md | 1 + src/variable.jl | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/src/types.md b/docs/src/types.md index a8f40f4d..2acd2e9f 100644 --- a/docs/src/types.md +++ b/docs/src/types.md @@ -22,6 +22,7 @@ isrealpart isimagpart isconj ordinary_variable +is_commutative ``` ## Monomials diff --git a/src/variable.jl b/src/variable.jl index 3161d6c5..87e64a03 100644 --- a/src/variable.jl +++ b/src/variable.jl @@ -47,7 +47,9 @@ Returns whether variables of the given type are commutative, i.e., whether `x * y == y * x`. """ function is_commutative end -is_commutative(::Union{AbstractPolynomialLike,AbstractVector{<:AbstractPolynomialLike}}) = error("`is_commutative` should be implemented for types, not instances. Use `is_commutative(typeof(x))` instead.") +is_commutative(p::_APL) = is_commutative(typeof(p)) +is_commutative(v::AbstractVector) = is_commutative(eltype(v)) +is_commutative(v::Tuple) = all(is_commutative, v) """ name(v::AbstractVariable)::AbstractString