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 709d6c86..87e64a03 100644 --- a/src/variable.jl +++ b/src/variable.jl @@ -40,6 +40,17 @@ 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(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