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
Symbolics.jl | Interfacing - building an expression tree to use custom rules #687
Comments
After rereading the Symbolics.jl documentation,
I thought that I had found the solution.
which generates the output
So |
If a
The matcher In your case, the composite rewriters Please try the following using Symbolics, SymbolicUtils.Rewriters
@variables x, t
@variables Φ(x, t)
Dx = Differential(x)
D2x = Dx * Dx
Dt = Differential(t)
pd_rule = @rule Dt(Dx(Dx(~Φ))) => Dx(Dx(Dt(~Φ)))
∂2Φ∂t2 = Dt(Dx(Dx(Φ))) - 2 * Dt(Φ) * Φ
∂2Φ∂t2_tree = Symbolics.value(∂2Φ∂t2)
γ2 = Postwalk(Chain([pd_rule]))(∂2Φ∂t2_tree) result: Differential(x)(Differential(x)(Differential(t)(Φ(x, t)))) - 2Differential(t)(Φ(x, t))*Φ(x, t) See also the documentation of Composing Rewriters in SymbolicUtils.jl |
Wonderful. Thank you for your detailed explanation and solution. With a test of composition
gives the same desired result:
However, including the same code in a
give the unexpected result
the rule and rewrite operations seem to have been ignored. |
I guess that's an issue for SymbolicUtils.jl term rewriting. Opened a separate issue JuliaSymbolics/SymbolicUtils.jl#460 |
Understood. Thank you for investigating and opening the new issue. |
Hello,
I would like to use the SymbolicUtils composing rewriter
Fixpoint(rw)
whichto apply a custom rule to a Symbolics.jl expression until
nothing
is returned.However, rereading the SymbolicUtils.jl and TermInterface.jl documentation it is not clear to me how to do this - specifically how to set up the interface between Symbolics.jl and SymbolicUtils.jl.
The MNWE is
The SymbolicUtils.jl documentation states
and the TermInterface.jl documentation states
Without an example, it is not clear to me, a Symbolics neophyte, what is meant and how to proceed.
In the above MNWE,
should
@variables
be replaced by@syms
?should
∂2Φ∂t2
be defined as∂2Φ∂t2::Symbolics.Term
?The text was updated successfully, but these errors were encountered: