|
4 | 4 | [](https://YingboMa.github.io/SIMDPolynomials.jl/dev)
|
5 | 5 | [](https://github.com/YingboMa/SIMDPolynomials.jl/actions/workflows/CI.yml?query=branch%3Amaster)
|
6 | 6 | [](https://codecov.io/gh/YingboMa/SIMDPolynomials.jl)
|
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +SIMDPolynomials.jl uses bit-packed monomials so that most of the operations on |
| 11 | +multivariate monomials can be done in a few CPU instructions. Currently, it is |
| 12 | +only optimized for relatively small polynomials. Contributions, especially |
| 13 | +optimizations for large polynomials, are welcome! |
| 14 | + |
| 15 | +Examples: |
| 16 | +```julia |
| 17 | +julia> using SIMDPolynomials, BenchmarkTools |
| 18 | + |
| 19 | +julia> x, y, z, t = [PackedMonomial{4,7}(i) for i in 0:3]; # PackedMonomial with maximum of 4 variables and 7 bits of exponents. |
| 20 | + |
| 21 | +julia> p = x * y + 3 * (z * t) |
| 22 | +x₀x₁ + 3x₂x₃ |
| 23 | + |
| 24 | +julia> q = (p + 1) * p |
| 25 | +x₀²x₁² + 6x₀x₁x₂x₃ + 9x₂²x₃² + x₀x₁ + 3x₂x₃ |
| 26 | + |
| 27 | +julia> @btime gcd($p, $q) |
| 28 | + 4.019 μs (94 allocations: 8.06 KiB) |
| 29 | +x₀x₁ + 3x₂x₃ |
| 30 | + |
| 31 | +julia> begin |
| 32 | + c1 = 10*(x * z + x) |
| 33 | + c2 = 2*(x^2 + z) |
| 34 | + c3 = 2*(2 - z ) |
| 35 | + c4 = 20*(x * z^2) |
| 36 | + e1 = 0 |
| 37 | + e2 = 5 |
| 38 | + e3 = 7 |
| 39 | + e4 = 10 |
| 40 | + p = c1 * y^e1 + c2 * y^e2 + c3 * y^e3 + c4 * y^e4 |
| 41 | + q = prod(i->p + i, 0:3) |
| 42 | + end; |
| 43 | + |
| 44 | +julia> @btime for i in 0:3 |
| 45 | + gcd($p + i, $q) |
| 46 | + end |
| 47 | + 350.086 μs (1159 allocations: 588.06 KiB) |
| 48 | +``` |
| 49 | + |
| 50 | +The same micro-benchmark using AbstractAlgebra: |
| 51 | +```julia |
| 52 | +julia> using AbstractAlgebra, BenchmarkTools |
| 53 | + |
| 54 | +julia> R, (x, y, z, t) = PolynomialRing(AbstractAlgebra.Integers{Int}(), [:x, :y, :z, :t], ordering=:deglex); |
| 55 | + |
| 56 | +julia> p = x * y + 3 * (z * t) |
| 57 | +x*y + 3*z*t |
| 58 | + |
| 59 | +julia> q = (p + 1) * p |
| 60 | +x^2*y^2 + 6*x*y*z*t + 9*z^2*t^2 + x*y + 3*z*t |
| 61 | + |
| 62 | +julia> @btime gcd($p, $q) # SIMDPolynomials.jl is 30x faster |
| 63 | + 119.795 μs (1320 allocations: 89.17 KiB) |
| 64 | +x*y + 3*z*t |
| 65 | + |
| 66 | +julia> begin |
| 67 | + c1 = 10*(x * z + x) |
| 68 | + c2 = 2*(x^2 + z) |
| 69 | + c3 = 2*(2 - z ) |
| 70 | + c4 = 20*(x * z^2) |
| 71 | + e1 = 0 |
| 72 | + e2 = 5 |
| 73 | + e3 = 7 |
| 74 | + e4 = 10 |
| 75 | + p = c1 * y^e1 + c2 * y^e2 + c3 * y^e3 + c4 * y^e4 |
| 76 | + q = prod(i->p + i, 0:3) |
| 77 | + end; |
| 78 | + |
| 79 | +julia> @btime for i in 0:3 # SIMDPolynomials.jl is 14x faster |
| 80 | + gcd($p + i, $q) |
| 81 | + end |
| 82 | + 4.934 ms (32235 allocations: 3.43 MiB) |
| 83 | +``` |
| 84 | + |
| 85 | +The same micro-benchmark using DynamicPolynomials: |
| 86 | +```julia |
| 87 | +julia> using DynamicPolynomials, BenchmarkTools |
| 88 | + |
| 89 | +julia> @polyvar x y z t; |
| 90 | + |
| 91 | +julia> p = x * y + 3 * (z * t) |
| 92 | +xy + 3zt |
| 93 | + |
| 94 | +julia> q = (p + 1) * p |
| 95 | +x²y² + 6xyzt + 9z²t² + xy + 3zt |
| 96 | + |
| 97 | +julia> @btime gcd($p, $q) # SIMDPolynomials.jl is 65x faster |
| 98 | + 264.561 μs (4962 allocations: 298.19 KiB) |
| 99 | +xy + 3zt |
| 100 | + |
| 101 | +julia> begin |
| 102 | + c1 = 10*(x * z + x) |
| 103 | + c2 = 2*(x^2 + z) |
| 104 | + c3 = 2*(2 - z ) |
| 105 | + c4 = 20*(x * z^2) |
| 106 | + e1 = 0 |
| 107 | + e2 = 5 |
| 108 | + e3 = 7 |
| 109 | + e4 = 10 |
| 110 | + p = c1 * y^e1 + c2 * y^e2 + c3 * y^e3 + c4 * y^e4 |
| 111 | + q = prod(i->p + i, 0:3) |
| 112 | + end; |
| 113 | + |
| 114 | +julia> @btime for i in 0:3 # SIMDPolynomials.jl is 82x faster |
| 115 | + gcd($p + i, $q) |
| 116 | + end |
| 117 | + 28.943 ms (529642 allocations: 31.20 MiB) |
| 118 | +``` |
0 commit comments