-
Notifications
You must be signed in to change notification settings - Fork 22
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
Better compatibility with packages such as ApproxFun.jl and Polynomials.jl #127
Comments
I'm tempted to say that we don't want to define |
While this is true, I think the desired behavior would be: julia> @polyvar x
(x,)
julia> 0 ≤ x ≤ 1 # this would have a side effect on x
0 ≤ x ≤ 1
julia> p = Fun(Chebyshev(), [0.0, 1.0, 2.0])
Fun(Chebyshev(), [0.0, 1.0, 2.0])
juliy> p(x)
4x^2 + x - 2 for 0 ≤ x ≤ 1 Or maybe something like this to avoid side effects: julia> @polyvar x
(x,)
julia> x2 = impose(x, lowerbound=0, upperbound=1) # no side effect on x, Base.isless can be defined as x2 < y if true for all x2
0 ≤ x2 ≤ 1
julia> @impose 0 ≤ x ≤ 1 # maybe a macro overwriting x
0 ≤ x ≤ 1
julia> p = Fun(Chebyshev(), [0.0, 1.0, 2.0])
Fun(Chebyshev(), [0.0, 1.0, 2.0])
juliy> p(x2)
4x2^2 + x2 - 2 for 0 ≤ x2 ≤ 1 |
We have such concept of domain for julia> @polyvar x
(x,)
julia> p = Fun(Chebyshev(), [0.0, 1.0, 2.0])
Fun(Chebyshev(), [0.0, 1.0, 2.0])
julia> clenshaw(p.space, p.coefficients, x)
4x2^2 + x2 - 2 See https://github.com/JuliaApproximation/ApproxFunOrthogonalPolynomials.jl/blob/8bafeff745ad5191916cf26d909a152cd29b7c48/src/Spaces/PolynomialSpace.jl#L21 |
I don't think there's a way at present, although this does sound like a good idea. Perhaps @benjione can do this at present (an extension of their julia> struct InDomain{T}
x :: T
end
julia> p = Fun(Chebyshev(), [0.0, 1.0, 2.0])
Fun(Chebyshev(), [0.0, 1.0, 2.0])
julia> ApproxFunBase.tocanonical(::ChebyshevInterval{<:Number}, x::InDomain) = x.x
julia> Base.in(::InDomain, ::ChebyshevInterval) = true
julia> p(InDomain(x))
4.0x² + x - 2.0 However, using julia> clenshaw(space(p), ApproxFun.coefficients(p), x)
4.0x² + x - 2.0 |
Thanks, I think I will use the Nevertheless, I think it would be nice if polyvar would work with other polynomial packages. E.g. Maybe the |
what's the error? This seems to work for me: julia> @polyvar x
(x,)
julia> Polynomials.Polynomial([1,2,3])(x)
3x² + 2x + 1 |
I think the normal polynomials are not domain bounded. For Chebyshev, I get:
|
We try to avoid defining methods just to make a workflow work as it might break another workflow. Here, defining |
I'm adding support for ClassicalOrthogonalPolynomials.jl (which is meant to underpin ApproxFun.jl in the future.... scheduled for 2050s 😅): |
Btw, is there any support for |
Thanks for the new package, this could be useful for https://github.com/JuliaAlgebra/MultivariateBases.jl |
OK I was expecting this to work but maybe I should file an issue: julia> using DynamicPolynomials
julia> @polyvar x
(x,)
julia> x/2
0.5x
julia> x//2
ERROR: MethodError: no method matching //(::Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}, ::Int64)
The function `//` exists, but no method is defined for this combination of argument types.
Closest candidates are:
//(::Integer, ::Integer)
@ Base rational.jl:84
//(::Rational, ::Integer)
@ Base rational.jl:86
//(::Complex, ::Real)
@ Base rational.jl:100
...
Stacktrace:
[1] top-level scope
@ REPL[4]:1 |
If
DynamicPolynomials
library is used together with e.g.ApproxFun
, there is an error if the packageIntervalSets
is used and the following is executed withv
being of typePolyVar
:The error is because
Base.isless
is not defined forPolyVar
Code example producing the error:
One can manually overwrite those functions for the desired type, e.g.
Is it possible to overwrite the
IntervalSets.in
in order to get better compatibility between the polynomial packages?Or has this to be done in
MultivariatePolynomials.jl
instead of here?The text was updated successfully, but these errors were encountered: