Skip to content

Commit 96368fe

Browse files
authored
Merge pull request #24 from JuliaAlgebra/evaluation
Add default evaluations routines which assume default variable ordering
2 parents 8b2b1a0 + 9604269 commit 96368fe

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/subs.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,14 @@ end
9696
(m::Monomial)(s::MP.AbstractSubstitution...) = MP.substitute(MP.Eval(), m, s)
9797
(t::Term)(s::MP.AbstractSubstitution...) = MP.substitute(MP.Eval(), t, s)
9898
(p::Polynomial)(s::MP.AbstractSubstitution...) = MP.substitute(MP.Eval(), p, s)
99+
100+
(p::PolyVar)(x::Number) = x
101+
(p::Monomial)(x::NTuple{N, <:Number}) where N = MP.substitute(MP.Eval(), p, variables(p)=>x)
102+
(p::Monomial)(x::AbstractVector{<:Number}) = MP.substitute(MP.Eval(), p, variables(p)=>x)
103+
(p::Monomial)(x::Number...) = MP.substitute(MP.Eval(), p, variables(p)=>x)
104+
(p::Term)(x::NTuple{N, <:Number}) where N = MP.substitute(MP.Eval(), p, variables(p)=>x)
105+
(p::Term)(x::AbstractVector{<:Number}) = MP.substitute(MP.Eval(), p, variables(p)=>x)
106+
(p::Term)(x::Number...) = MP.substitute(MP.Eval(), p, variables(p)=>x)
107+
(p::Polynomial)(x::NTuple{N, <:Number}) where N = MP.substitute(MP.Eval(), p, variables(p)=>x)
108+
(p::Polynomial)(x::AbstractVector{<:Number}) = MP.substitute(MP.Eval(), p, variables(p)=>x)
109+
(p::Polynomial)(x::Number...) = MP.substitute(MP.Eval(), p, variables(p)=>x)

test/mono.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,13 @@
9494
@test variables(m) == [x, y, z, x, y]
9595
@test m.z == [2, 1, 1, 0, 0]
9696
end
97+
98+
@testset "Evaluation" begin
99+
@polyvar x y
100+
@test (x^2*y)(3,2) == 18
101+
@test (x^2*y)((3,2)) == 18
102+
@test (x^2*y)([3,2]) == 18
103+
@test (x^2)(3) == 9
104+
@test (x)(3) == 3
105+
end
97106
end

test/poly.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,15 @@
6464
@inferred polynomial(2u)
6565
@inferred polynomial(2.0u, Int)
6666
end
67+
68+
@testset "Evaluation" begin
69+
@polyvar x y
70+
@test (x^2+y^3)(2, 3) == 31
71+
@test (x^2+y^3)((2, 3)) == 31
72+
@test (x^2+y^3)([2, 3]) == 31
73+
@test (2x^2*y)(3,2) == 36
74+
@test (2x^2*y)((3,2)) == 36
75+
@test (2x^2*y)([3,2]) == 36
76+
@test (2x^2)(3) == 18
77+
end
6778
end

0 commit comments

Comments
 (0)