Skip to content

Commit e5c25e4

Browse files
authored
Merge pull request #531 from blegat/[email protected]
Update to MultivariatePolynomials v0.5
2 parents 312b0ce + c6ffe2f commit e5c25e4

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ Combinatorics = "1.0"
3232
ConstructionBase = "1.1"
3333
DataStructures = "0.18"
3434
DocStringExtensions = "0.8, 0.9"
35-
DynamicPolynomials = "0.3, 0.4"
35+
DynamicPolynomials = "0.5"
3636
IfElse = "0.1"
3737
LabelledArrays = "1.5"
38-
MultivariatePolynomials = "0.3, 0.4"
38+
MultivariatePolynomials = "0.5"
3939
NaNMath = "0.3, 1"
4040
Setfield = "0.7, 0.8, 1"
4141
SpecialFunctions = "0.10, 1.0, 2"

docs/src/manual/representation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $p / q$ is represented by `Div(p, q)`. The result of `*` on `Div` is maintainted
2323

2424
Packages like DynamicPolynomials.jl provide representations that are even more efficient than the `Add` and `Mul` types mentioned above. They are designed specifically for multi-variate polynomials. They provide common algorithms such as multi-variate polynomial GCD. The restrictions that make it fast also mean some things are not possible: Firstly, DynamicPolynomials can only represent flat polynomials. For example, `(x-3)*(x+5)` can only be represented as `(x^2) + 15 - 8x`. Secondly, DynamicPolynomials does not have ways to represent generic Terms such as `sin(x-y)` in the tree.
2525

26-
To reconcile these differences while being able to use the efficient algorithms of DynamicPolynomials we have the `PolyForm` type. This type holds a polynomial and the mappings necessary to present the polynomial as a SymbolicUtils expression (i.e. by defining `operation` and `arguments`). The mappings constructed for the conversion are 1) a bijection from DynamicPolynomials PolyVar type to a Symbolics `Sym`, and 2) a mapping from `Sym`s to non-polynomial terms that the `Sym`s stand-in for. These terms may themselves contain PolyForm if there are polynomials inside them. The mappings are transiently global, that is, when all references to the mappings go out of scope, they are released and re-created.
26+
To reconcile these differences while being able to use the efficient algorithms of DynamicPolynomials we have the `PolyForm` type. This type holds a polynomial and the mappings necessary to present the polynomial as a SymbolicUtils expression (i.e. by defining `operation` and `arguments`). The mappings constructed for the conversion are 1) a bijection from DynamicPolynomials Variable type to a Symbolics `Sym`, and 2) a mapping from `Sym`s to non-polynomial terms that the `Sym`s stand-in for. These terms may themselves contain PolyForm if there are polynomials inside them. The mappings are transiently global, that is, when all references to the mappings go out of scope, they are released and re-created.
2727

2828
```julia
2929
julia> @syms x y

page/representation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $p / q$ is represented by `Div(p, q)`. The result of `*` on `Div` is maintainted
2323

2424
Packages like DynamicPolynomials.jl provide representations that are even more efficient than the `Add` and `Mul` types mentioned above. They are designed specifically for multi-variate polynomials. They provide common algorithms such as multi-variate polynomial GCD. The restrictions that make it fast also mean some things are not possible: Firstly, DynamicPolynomials can only represent flat polynomials. For example, `(x-3)*(x+5)` can only be represented as `(x^2) + 15 - 8x`. Secondly, DynamicPolynomials does not have ways to represent generic Terms such as `sin(x-y)` in the tree.
2525

26-
To reconcile these differences while being able to use the efficient algorithms of DynamicPolynomials we have the `PolyForm` type. This type holds a polynomial and the mappings necessary to present the polynomial as a SymbolicUtils expression (i.e. by defining `operation` and `arguments`). The mappings constructed for the conversion are 1) a bijection from DynamicPolynomials PolyVar type to a Symbolics `Sym`, and 2) a mapping from `Sym`s to non-polynomial terms that the `Sym`s stand-in for. These terms may themselves contain PolyForm if there are polynomials inside them. The mappings are transiently global, that is, when all references to the mappings go out of scope, they are released and re-created.
26+
To reconcile these differences while being able to use the efficient algorithms of DynamicPolynomials we have the `PolyForm` type. This type holds a polynomial and the mappings necessary to present the polynomial as a SymbolicUtils expression (i.e. by defining `operation` and `arguments`). The mappings constructed for the conversion are 1) a bijection from DynamicPolynomials Variable type to a Symbolics `Sym`, and 2) a mapping from `Sym`s to non-polynomial terms that the `Sym`s stand-in for. These terms may themselves contain PolyForm if there are polynomials inside them. The mappings are transiently global, that is, when all references to the mappings go out of scope, they are released and re-created.
2727

2828
```julia
2929
julia> @syms x y

src/SymbolicUtils.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ include("matchers.jl")
4040
include("rewriters.jl")
4141

4242
# Convert to an efficient multi-variate polynomial representation
43-
import MultivariatePolynomials
44-
const MP = MultivariatePolynomials
43+
import MultivariatePolynomials as MP
4544
import DynamicPolynomials
4645
export expand
4746
include("polyform.jl")

src/polyform.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export PolyForm, simplify_fractions, quick_cancel, flatten_fractions
22
using Bijections
3-
using DynamicPolynomials: PolyVar
43

54
"""
65
PolyForm{T} <: Symbolic
@@ -44,7 +43,7 @@ end
4443
Base.hash(p::PolyForm, u::UInt64) = xor(hash(p.p, u), trunc(UInt, 0xbabacacababacaca))
4544
Base.isequal(x::PolyForm, y::PolyForm) = isequal(x.p, y.p)
4645

47-
# We use the same PVAR2SYM bijection to maintain the PolyVar <-> Sym mapping,
46+
# We use the same PVAR2SYM bijection to maintain the MP.AbstractVariable <-> Sym mapping,
4847
# When all PolyForms go out of scope in a session, we allow it to free up memory and
4948
# start over if necessary
5049
const PVAR2SYM = Ref(WeakRef())
@@ -156,7 +155,7 @@ end
156155
function PolyForm(x,
157156
pvar2sym=get_pvar2sym(),
158157
sym2term=get_sym2term(),
159-
vtype=DynamicPolynomials.PolyVar{true};
158+
vtype=DynamicPolynomials.Variable{ DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder},DynamicPolynomials.Graded{MP.LexOrder}};
160159
Fs = Union{typeof(+), typeof(*), typeof(^)},
161160
recurse=false,
162161
metadata=metadata(x))

0 commit comments

Comments
 (0)