Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use rational representation if possible #182

Merged
merged 1 commit into from
Aug 21, 2024
Merged

Conversation

YingboMa
Copy link
Member

using Symbolics, RootedTrees
using Symbolics: variables
p = 5
s = 7
A = variables(:A, 1:s, 1:s)
b = variables(:b, 1:s)
c = variables(:c, 1:s)

# Explicit condition
for i in 1:s, j in 1:s
    if i <= j
        A[i, j] = 0
    end
end
c[1] = 0
c[end-1] = 1
c[end] = 1
b[end] = 0
A[end, :] = b

constraints = map(Iterators.flatten(RootedTreeIterator(i) for i in 1:p)) do t
    residual_order_condition(t, A, b, c)
end

Master:

julia> constraints[10]
(1//2)*(-0.016666666666666666 + (A₂ˏ₁^2)*A₃ˏ₂*A₄ˏ₃*b₄ + ((A₂ˏ₁^2)*A₃ˏ₂*A₅ˏ₃ + ((A₂ˏ₁^2)*A₄ˏ₂ + ((A₃ˏ₁ + A₃ˏ₂)^2)*A₄ˏ₃)*A₅ˏ₄)*b₅ + ((A₂ˏ₁^2)*A₃ˏ₂*A₆ˏ₃ + ((A₂ˏ₁^2)*A₄ˏ₂ + ((A₃ˏ₁ + A₃ˏ₂)^2)*A₄ˏ₃)*A₆ˏ₄ + ((A₂ˏ₁^2)*A₅ˏ₂ + ((A₃ˏ₁ + A₃ˏ₂)^2)*A₅ˏ₃ + ((A₄ˏ₁ + A₄ˏ₂ + A₄ˏ₃)^2)*A₅ˏ₄)*A₆ˏ₅)*b₆)

PR:

julia> constraints[10]
(1//2)*(-(1//60) + (A₂ˏ₁^2)*A₃ˏ₂*A₄ˏ₃*b₄ + ((A₂ˏ₁^2)*A₃ˏ₂*A₅ˏ₃ + ((A₂ˏ₁^2)*A₄ˏ₂ + ((A₃ˏ₁ + A₃ˏ₂)^2)*A₄ˏ₃)*A₅ˏ₄)*b₅ + ((A₂ˏ₁^2)*A₃ˏ₂*A₆ˏ₃ + ((A₂ˏ₁^2)*A₄ˏ₂ + ((A₃ˏ₁ + A₃ˏ₂)^2)*A₄ˏ₃)*A₆ˏ₄ + ((A₂ˏ₁^2)*A₅ˏ₂ + ((A₃ˏ₁ + A₃ˏ₂)^2)*A₅ˏ₃ + ((A₄ˏ₁ + A₄ˏ₂ + A₄ˏ₃)^2)*A₅ˏ₄)*A₆ˏ₅)*b₆)

@YingboMa YingboMa requested a review from ranocha August 21, 2024 16:39
@ChrisRackauckas ChrisRackauckas merged commit 84d1add into main Aug 21, 2024
6 of 7 checks passed
@ChrisRackauckas ChrisRackauckas deleted the myb/rational branch August 21, 2024 18:05
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants