Skip to content

Commit

Permalink
Fix term ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Oct 29, 2023
1 parent 142e115 commit 255e74a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/library/function/term.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ function varlt(u::Term{V}, v::Term{V}) where {V}
end

function varmul(u::Term{V}, v::Term{V}) where {V}
return Term{V}(sortedmergewith(u.ω, v.ω))
return Term{V}(sortedmergewith(u.ω, v.ω; lt = varlt))
end

function varmul(u::Term{V}, v::V) where {V}
return Term{V}(sortedmergewith(u.ω, V[v]))
return Term{V}(sortedmergewith(u.ω, V[v]; lt = varlt))
end

function varmul(u::V, v::Term{V}) where {V}
return Term{V}(sortedmergewith(V[u], v.ω))
return Term{V}(sortedmergewith(V[u], v.ω; lt = varlt))
end

function varmul(u::V, v::V) where {V}
Expand Down
6 changes: 5 additions & 1 deletion test/assets/assets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ end

const VI = VariableIndex

function PBO.varlt(u::VariableIndex, v::VariableIndex)::Bool
function PBO.varlt(u::VariableIndex, v::VariableIndex)
return PBO.varlt(u.index, v.index)
end

function PBO.varshow(v::VariableIndex)
return PBO.varshow(v.index)
end

# Test foreign packages
function run_foreign_pkg_tests(pkg_name::AbstractString, dep_path::AbstractString = PBO.__PROJECT__; kws...)
@info "Running Tests for '$pkg_name'"
Expand Down
34 changes: 34 additions & 0 deletions test/integration/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,40 @@ function test_variable_interface()
@test PBO.varlt(VI(1), VI(-1)) === true
@test PBO.varlt(VI(-1), VI(1)) === false
@test PBO.varlt(VI(-1), VI(-1)) === false

@test PBO.Term([VI(4), VI(2), VI(1), VI(2), VI(4)]) == PBO.Term{VI}([VI(1), VI(2), VI(4)])
end

@testset "varshow" begin
@test PBO.varshow(VI(101)) == "x₁₀₁"
@test PBO.varshow(VI(-12)) == "x₋₁₂"

@test PBO.varshow(PBO.Term([VI(1), VI(2), VI(4)])) == "x₁ x₂ x₄"
end

@testset "varmul" begin
let x = VI(1)
y = VI(2)
z = VI(3)

let xy = PBO.Term([x, y])
xz = PBO.Term([x, z])
yz = PBO.Term([y, z])

@test PBO.varmul(x, y) == xy
@test PBO.varmul(y, x) == xy

@test PBO.varmul(x, z) == xz
@test PBO.varmul(z, x) == xz

@test PBO.varmul(y, z) == yz
@test PBO.varmul(z, y) == yz

@test PBO.varmul(xy, z) == PBO.Term([x, y, z])
@test PBO.varmul(xz, y) == PBO.Term([x, y, z])
@test PBO.varmul(x, yz) == PBO.Term([x, y, z])
end
end
end
end

Expand Down

2 comments on commit 255e74a

@pedromxavier
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/94362

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.3 -m "<description of version>" 255e74a81ecadd9d14eb3dfb78c37dd8e81c499b
git push origin v0.2.3

Please sign in to comment.