-
Notifications
You must be signed in to change notification settings - Fork 174
Open
Description
While experimenting, I came across some inconsistencies when it comes to the extraction of common factors in simplify. Depending on the number of terms in the expressions, a sole common factor in all the terms is successfully determined in some case while not in the other case. I give an example below:
zarr = Symbolics.variables(:z, 1:N)
csum = [sum(zarr[1:i]) for i=1:N-1]
csum2_sum = expand.(sum(csum.^2))
quad_terms = filter(t -> Symbolics.degree(t) == 2, terms(csum2_sum))
cross_quad_terms = filter(qi -> length(Symbolics.get_variables(qi)) == 2, quad_terms)
cqt_decomposition = []
cqt_remaining = copy(cross_quad_terms)
for zi in reverse(zarr)
push!(cqt_decomposition, filter(t -> Symbolics.coeff(t, zi) !== 0, cqt_remaining))
filter!(t -> Symbolics.coeff(t, zi) === 0, cqt_remaining)
end
cqt_zi = sum.(cqt_decomposition)
cqt_zi_simplify = simplify.(cqt_zi)
cqt_zi_manual = []
for (cqt, zi) in zip(cqt_decomp_terms, reverse(zarr))
push!(cqt_zi_manual,
simplify(Symbolics.coeff(cqt, zi)) * zi
)
endOutput:
cqt_zi_simplify = Symbolics.Num[0, 2(z₁ + z₆)*z₉ + 2z₂*z₉ + 2(z₃ + z₅ + z₇ + z₈)*z₉ + 2z₄*z₉, 4(z₁ + z₆)*z₈ + 4z₂*z₈ + 4z₃*z₈ + 4z₄*z₈ + 4z₅*z₈ + 4z₇*z₈, 6(z₁ + z₂ + z₃ + z₄ + z₅ + z₆)*z₇, 8z₁*z₆ + 8z₂*z₆ + 8z₃*z₆ + 8z₄*z₆ + 8z₅*z₆, 10(z₁ + z₂ + z₃ + z₄)*z₅, 12z₁*z₄ + 12(z₂ + z₃)*z₄, 14z₁*z₃ + 14z₂*z₃, 16z₁*z₂, 0]
cqt_zi_manual = Any[0, (2//1)*(z₁ + z₂ + z₃ + z₄ + z₅ + z₆ + z₇ + z₈)*z₉, (4//1)*(z₁ + z₂ + z₃ + z₄ + z₅ + z₆ + z₇)*z₈, (6//1)*(z₁ + z₂ + z₃ + z₄ + z₅ + z₆)*z₇, (8//1)*(z₁ + z₂ + z₃ + z₄ + z₅)*z₆, (10//1)*(z₁ + z₂ + z₃ + z₄)*z₅, (12//1)*(z₁ + z₂ + z₃)*z₄, (14//1)*(z₁ + z₂)*z₃, (16//1)*z₁*z₂, 0]
In this example, what I expected to obtain was cqt_zi_manual whereas cqt_zi_simplify doesn't contain all the terms with the common factor resolved completely.
- Version info:
Julia Version 1.11.5
Commit 760b2e5b73 (2025-04-14 06:53 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 16 × AMD Ryzen 7 PRO 8840U w/ Radeon 780M Graphics
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
Threads: 8 default, 0 interactive, 4 GC (on 16 virtual cores)
Environment:
JULIA_REVISE_WORKER_ONLY = 1
Pkg.status():
Status `C:\Users\...`
⌅ [d1185830] SymbolicUtils v3.32.0
[0c5d862f] Symbolics v6.57.0
[44cfe95a] Pkg v1.11.0
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated`
This is a follow-up after the comments received on my discourse post here.
ggkountouras
Metadata
Metadata
Assignees
Labels
No labels