Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

substitute silently fails #1461

Open
rrwormqueen opened this issue Mar 2, 2025 · 0 comments
Open

substitute silently fails #1461

rrwormqueen opened this issue Mar 2, 2025 · 0 comments

Comments

@rrwormqueen
Copy link

rrwormqueen commented Mar 2, 2025

Hi,

I've been experimenting with combining Symbolics.jl with other mathematical libraries. I've noticed that in some cases, the substitute can fail dramatically, without any error or indication of a missing method definition.

using CliffordNumbers, Symbolics
@variables X_sym[1:4]
# Extend a function from CliffordNumbers so the variable can be printed. (Unrelated to issue, but helps see the outputs.)
import CliffordNumbers.print_clifford_coefficient
print_clifford_coefficient(io::IO, c::Num, ffn::Bool) = print(io, " + "^ffn, '(', c, ')')
# Form a CliffordNumber whose coefficients are symbolic variables.
X = KVector{1, STA, Real}(X_sym...)

typeof(X) = 1-element KVector{0, LGAWest(3), Num} which is idiomatic and expected. Compare, for example, to c = X_sym[1] + X_sym[2] * im, for which typeof(c) = Complex{Num}.

There are several open issues at time of writing about the type Complex{Num}. A similar issue is likely happening here. The actual behavior seen is

Y = substitute(X, X_sym => [1,2,3,4])
# Produces (X_sym[1])γ₀ + (X_sym[2])γ₁ + (X_sym[3])γ₂ + (X_sym[4])γ₃ which is completely unchanged.
# To demonstrate:
Y == X # true

The behavior that should happen, as compared with the analogous Complex{Num} case:

substitute(c, X_sym => [1,2,3,4]) # 1 + 2im
substitute(X, X_sym => [1,2,3,4]) # 1γ₀ + 2γ₁ + 3γ₂ + 3γ₃, with type KVector{1, LGAWest(3), Real}

I'm really quite puzzled about what's going on here. The way substitute is behaving like an identity operator is really weird. As a final puzzle piece, I'll note differentiation also silently produces unexpected results. Differential(X_sym[1])(X) |> expand_derivatives should produce γ₀ (type KVector{1, LGAWest(3), Real}), but instead produces 0. Again, compare to Differential(X_sym[1])(c) |> expand_derivatives which correctly produces 1.

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant