Commit 8d2462b
committed
fold
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).conj, real, imag on the symbolic imaginary unit1 parent 7ffce39 commit 8d2462b
2 files changed
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
| 482 | + | |
| 483 | + | |
482 | 484 | | |
483 | 485 | | |
484 | 486 | | |
| |||
490 | 492 | | |
491 | 493 | | |
492 | 494 | | |
| 495 | + | |
493 | 496 | | |
494 | 497 | | |
495 | 498 | | |
| |||
498 | 501 | | |
499 | 502 | | |
500 | 503 | | |
| 504 | + | |
501 | 505 | | |
502 | 506 | | |
503 | 507 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
62 | 72 | | |
63 | 73 | | |
64 | 74 | | |
| |||
0 commit comments