fold conj, real, imag on the symbolic imaginary unit#924
Open
oameye wants to merge 1 commit into
Open
Conversation
Add three `@match` arms in `Base.real`, `Base.conj`, `Base.imag` for
`BasicSymbolic` that match `Sym(:im; type = Number)` structurally and
fold to `0`, `-im`, and `1` respectively.
`Symbolics.IM` is defined as a `Sym{VartypeT}(:im; type = Number)` and
used as a stand-in for `1im` to keep expressions inside `BasicSymbolic{<:Real}`
algebra (where multiplying by a Julia `Complex` literal would otherwise
materialise an opaque `complex(re, im)` `Term`). Until now those three
operations on `IM` produced opaque `conj(im)` / `real(im)` / `imag(im)`
wrappers that `simplify` could not reduce, so downstream code that
algebraically conjugates `IM`-bearing expressions (e.g. SQA's
`qadjoint` / `inner_adjoint`) had to special-case `IM` themselves.
Matching is structural (name + symtype) rather than by identity, so no
new dependency on Symbolics is introduced. A same-named sym with a
non-`Number` symtype is left alone (test case).
Contributor
Benchmark Results (Julia vlts)Time benchmarks
Memory benchmarks
|
Contributor
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
|
Member
|
Thanks for your attention to these edge cases. I think the better way to phrase this is to move the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three new
@matcharms inBase.real,Base.conj,Base.imagforBasicSymbolicthat matchSym(:im; type = Number)structurally and fold to0,-im,1.Symbolics.IMisSym{VartypeT}(:im; type = Number), used as a stand-in for1imso expressions stay insideBasicSymbolic{<:Real}algebra. Without these arms,conj(IM)/real(IM)/imag(IM)were opaque wrappers thatsimplifycould not reduce, and downstream code (e.g. SQA'sqadjoint/inner_adjoint) had to special-caseIMthemselves to avoidconj(im)leftovers.Matching is purely structural (name + symtype), so SymbolicUtils picks up no Symbolics-side dependency. A same-named sym with a non-
Numbersymtype is unaffected; the test covers that case.