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

Complex-valued variables #121

Merged
merged 29 commits into from
May 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b46b905
First step to implement complex variables functionality
projekter Dec 26, 2022
a5cb35d
Move monomial function to correct file
projekter Dec 26, 2022
91583e2
Rename ordvar to ordinary_variable
projekter Apr 21, 2023
b3d8d73
Specialized complex routines for MonomialVector
projekter May 9, 2023
0cd4cfd
fix
projekter May 9, 2023
098ee29
coefficienttype -> coefficient_type
blegat May 10, 2023
43a0a61
Remove incorrect method
blegat May 10, 2023
b93b6bc
Merge branch 'bl/coefficient_type' of https://github.com/JuliaAlgebra…
projekter May 22, 2023
e417490
Merge branch 'master' of https://github.com/JuliaAlgebra/DynamicPolyn…
projekter May 28, 2023
214d169
Add a (sometimes working) implementation for incomplete substitution
projekter May 28, 2023
c5c1c99
Fix old syntax
projekter May 31, 2023
25ac2cf
Merge branch 'master' of https://github.com/JuliaAlgebra/DynamicPolyn…
projekter Jul 7, 2023
31a8d4c
Format
projekter Jul 7, 2023
a19c0b0
Remove TODO
projekter Aug 17, 2023
0bf8175
Merge branch 'master' of https://github.com/JuliaAlgebra/DynamicPolyn…
projekter Aug 24, 2023
6b055bd
Add complex kind parameter to VT("name") constructor
projekter Aug 24, 2023
a61aaa2
Remove iscomplex
projekter Sep 1, 2023
f87fb62
Remove dev dependency of MP, 0.5.3 has landed
projekter Nov 30, 2023
71ffcb5
Merge branch 'master' of https://github.com/JuliaAlgebra/DynamicPolyn…
projekter Nov 30, 2023
f9873bf
Merge remote-tracking branch 'upstream/master'
projekter Feb 19, 2024
da7fd62
Add ComplexKind docstring
projekter Feb 21, 2024
f8d3214
Rename ComplexKind instances
projekter Feb 21, 2024
7e07585
typo
projekter May 4, 2024
8cf9c12
change substitution rules
projekter May 4, 2024
6c230f6
Rename polycvar macro
projekter May 4, 2024
a6e1d80
Error for partial substitutions
projekter May 8, 2024
f9337ff
Format
projekter May 8, 2024
e0ad44d
Complex substitution test cases
projekter May 8, 2024
0845707
More strict substitution rules: only allow ordinary variable
projekter May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change substitution rules
projekter committed May 4, 2024
commit 8cf9c1215bf5e4c7641314769df217223737f449
36 changes: 13 additions & 23 deletions src/subs.jl
Original file line number Diff line number Diff line change
@@ -13,17 +13,15 @@ function fillmap!(
s::MP.Substitution,
) where {C}
# We may assign a complex or real variable to its value (ordinary substitution).
# We may also assign a complex value to its conjugate, or just the real or imaginary parts
# Any combination of z, conj(z), real(z), imag(z), imag(conj(z)) can occur in either the polynomial or the substitution,
# and we must handle all of them correctly.
# Note: This may or may not work... Issues can arise if the substitutions contain the real and imaginary (or only one of
# those) of a variable separately whenever vals is not of the correct type:
# - Unless subs() originally had a polynomial-valued rhs, vals will be scalars, monomials, or terms. So when we try to
# assign a polynomial to its value (which is necessary, as the one-step substitution of only the real or only the
# imaginary part is incomplete), this is an impossible conversion.
# - The coefficients in vals might not be complex-valued; but to assign only a part of the variable, we necessarily need to
# introduce an explicit imaginary coefficient to the value.
# Currently, we don't do anything to catch these errors.
# We follow the following rules:
# - If a single substitution rule determines the value of a real variable, just substitute it.
# - If a single substitution rule determines the value of a complex variable or its conjugate, substitute the appropriate
# value whereever something related to this variable is found (i.e., the complex variable, the conjugate variable, or
# its real or imaginary part)
# - If a single substitution rule determines the value of the real or imaginary part of a complex variable alone, then only
# replace the real or imaginary parts if they occur explicitly. Don't do a partial substitution, i.e., `z` with the rule
# `zᵣ => 1` is left alone and not changed into `1 + im*zᵢ`. Even if both the real and imaginary parts are substituted as
# two individual rules (which we don't know of in this method), `z` will not be replaced.
if s.first.kind == REAL
for j in eachindex(vars)
if vars[j] == s.first
@@ -51,28 +49,20 @@ function fillmap!(
"Cannot assign a complex value to the real part of an expression",
)
value = real(s.second) # just to make sure the type is correct
if vars[j].kind == COMPLEX
vals[j] = value + im * imag(vals[j])
elseif vars[j].kind == CONJ
vals[j] = value - im * imag(vals[j])
elseif vars[j].kind == REAL_PART
if vars[j].kind == REAL_PART
vals[j] = value
end
# else we know the real part but use the imaginary part; do nothing
# don't do a partial substitution
else
@assert(s.first.kind == IMAG_PART)
isreal(s.second) || error(
"Cannot assign a complex value to the imaginary part of an expression",
)
value = real(s.second) # just to make sure the type is correct
if vars[j].kind == COMPLEX
vals[j] = real(vals[j]) + im * value
elseif vars[j].kind == CONJ
vals[j] = real(vals[j]) - im * value
elseif vars[j].kind == IMAG_PART
if vars[j].kind == IMAG_PART
vals[j] = value
end
# else we know the imaginary part but use the real part; do nothing
# don't do a partial substitution
projekter marked this conversation as resolved.
Show resolved Hide resolved
end
end
end