tkluck / polynomialrings.jl Goto Github PK
View Code? Open in Web Editor NEWA library for arithmetic and algebra with multi-variable polynomials.
License: Other
A library for arithmetic and algebra with multi-variable polynomials.
License: Other
I have a vanishing ideal V
and I'm trying to compute the dimension of degree d
polynomials in the quotient ring ℚ[x,y] / V
. For example, consider the circle:
julia> @ring! ℚ[x,y]
@ring(ℚ[x,y])
julia> V = 1-x^2-y^2
-x^2 + -y^2 + 1//1
julia> @test rem(y^2, V) == y^2 && div(y^2, V) == 0
Test Passed
julia> @test rem(x*y, V) == x*y && div(x*y, V) == 0
Test Passed
julia> @test div(x^2, V) ≠ 0 # lies in the span of the other two
Test Passed
That is, we know x^2 = 1-y^2
hence [1,x^2,y^2]
are linearly dependent.
Is there a systematic way of doing this?
I see theres a QuotientRing
type but no documentation...
I would expect integers to behave like 0-degree polynomials but:
julia> @ring! ℚ[x,y]
@ring(ℚ[x,y])
julia> rem(1, x)
ERROR: MethodError: no method matching rem(::Int64, ::Generator{@variable(x), @ring(ℚ[x,y])})
Closest candidates are:
rem(::Any, ::Any, ::RoundingMode{:ToZero})
@ Base div.jl:97
rem(::Any, ::Any, ::RoundingMode{:Down})
@ Base div.jl:98
rem(::Any, ::Any, ::RoundingMode{:Up})
@ Base div.jl:99
...
Stacktrace:
[1] top-level scope
@ REPL[14]:1
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
I think we just need to overload iterate
and adjoint
to fix this:
julia> dot([x,y], [-y,x])
ERROR: MethodError: no method matching iterate(::@ring(ℚ[x,y]))
Closest candidates are:
iterate(::Union{LinRange, StepRangeLen})
@ Base range.jl:880
iterate(::Union{LinRange, StepRangeLen}, ::Integer)
@ Base range.jl:880
iterate(::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}}
@ Base dict.jl:698
...
Stacktrace:
[1] dot(x::@ring(ℚ[x,y]), y::@ring(ℚ[x,y]))
@ LinearAlgebra ~/Projects/julia-1.9/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/generic.jl:848
[2] dot(x::Vector{@ring(ℚ[x,y])}, y::Vector{@ring(ℚ[x,y])})
@ LinearAlgebra ~/Projects/julia-1.9/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/generic.jl:886
[3] top-level scope
@ REPL[24]:1
julia> [x,y]'* [-y,x]
ERROR: MethodError: no method matching adjoint(::@ring(ℚ[x,y]))
Closest candidates are:
adjoint(::Union{QR, LinearAlgebra.QRCompactWY, QRPivoted})
@ LinearAlgebra ~/Projects/julia-1.9/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/qr.jl:517
adjoint(::Union{Cholesky, CholeskyPivoted})
@ LinearAlgebra ~/Projects/julia-1.9/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/cholesky.jl:556
adjoint(::LQ)
@ LinearAlgebra ~/Projects/julia-1.9/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/lq.jl:138
...
Stacktrace:
[1] getindex
@ ~/Projects/julia-1.9/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/adjtrans.jl:302 [inlined]
[2] iterate
@ ./abstractarray.jl:1220 [inlined]
[3] iterate
@ ./abstractarray.jl:1218 [inlined]
[4] _zip_iterate_some
@ ./iterators.jl:424 [inlined]
[5] _zip_iterate_all
@ ./iterators.jl:416 [inlined]
[6] iterate
@ ./iterators.jl:406 [inlined]
[7] _foldl_impl
@ ./reduce.jl:56 [inlined]
[8] foldl_impl(op::Base.MappingRF{LinearAlgebra.var"#13#14", Base.BottomRF{typeof(Base.add_sum)}}, nt::Base._InitialValue, itr::Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}})
@ Base ./reduce.jl:48
[9] mapfoldl_impl(f::typeof(identity), op::typeof(Base.add_sum), nt::Base._InitialValue, itr::Base.Generator{Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}}, LinearAlgebra.var"#13#14"})
@ Base ./reduce.jl:44
[10] mapfoldl(f::Function, op::Function, itr::Base.Generator{Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}}, LinearAlgebra.var"#13#14"}; init::Base._InitialValue)
@ Base ./reduce.jl:170
[11] mapfoldl(f::Function, op::Function, itr::Base.Generator{Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}}, LinearAlgebra.var"#13#14"})
@ Base ./reduce.jl:170
[12] mapreduce(f::Function, op::Function, itr::Base.Generator{Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}}, LinearAlgebra.var"#13#14"}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base ./reduce.jl:302
[13] mapreduce(f::Function, op::Function, itr::Base.Generator{Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}}, LinearAlgebra.var"#13#14"})
@ Base ./reduce.jl:302
[14] sum(f::Function, a::Base.Generator{Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}}, LinearAlgebra.var"#13#14"}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base ./reduce.jl:530
[15] sum(f::Function, a::Base.Generator{Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}}, LinearAlgebra.var"#13#14"})
@ Base ./reduce.jl:530
[16] sum(a::Base.Generator{Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}}, LinearAlgebra.var"#13#14"}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base ./reduce.jl:559
[17] sum(a::Base.Generator{Base.Iterators.Zip{Tuple{Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, Vector{@ring(ℚ[x,y])}}}, LinearAlgebra.var"#13#14"})
@ Base ./reduce.jl:559
[18] _dot_nonrecursive(u::Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, v::Vector{@ring(ℚ[x,y])})
@ LinearAlgebra ~/Projects/julia-1.9/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/adjtrans.jl:428
[19] *(u::Adjoint{Union{}, Vector{@ring(ℚ[x,y])}}, v::Vector{@ring(ℚ[x,y])})
@ LinearAlgebra ~/Projects/julia-1.9/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/adjtrans.jl:435
[20] top-level scope
@ REPL[25]:1
The design of QuotientRing
is very non-standard. At the moment it stores the ring in the type information as an ID
to a dictionary, a pattern I've never seen in a Julia package before:
A more standard design would have just had a field pointing to the relevant ring.
Can you explain the motivation? Note the fact that the ID is in the type does not appear to be used anywhere.
julia> @ring! ℝ[x,y]
@ring(ℝ[x,y])
julia> I = x*(1-x^2-y^2)
-x^3 + -x*y^2 + x
julia> rem(x*(1-x^2-y^2), I)
ERROR: MethodError: no method matching //(::BigFloat, ::BigFloat)
Closest candidates are:
//(::AbstractArray, ::Number)
@ Base rational.jl:82
//(::PolynomialRings.QuotientRings.QuotientRing, ::Number)
@ PolynomialRings ~/.julia/packages/PolynomialRings/JNZGk/src/CommutativeAlgebras/QuotientRings.jl:152
//(::NumberField, ::Number)
@ PolynomialRings ~/.julia/packages/PolynomialRings/JNZGk/src/CommutativeAlgebras/NumberFields.jl:343
...
Stacktrace:
[1] maybe_div(a::(Term over BigFloat in @degrevlex(x > y)), b::(Term over BigFloat in @degrevlex(x > y)))
@ PolynomialRings.Terms ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Terms.jl:108
[2] #one_step_div!#4
@ ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Operators.jl:96 [inlined]
[3] one_step_div!
@ ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Operators.jl:85 [inlined]
[4] rem!(f::@ring(ℝ[x,y]), G::Vector{@ring(ℝ[x,y])}; order::typeof(@degrevlex(x > y)), redtype::PolynomialRings.Operators.Lead)
@ PolynomialRings.Reductions ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Reductions.jl:102
[5] rem!
@ ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Reductions.jl:87 [inlined]
[6] rem!(f::@ring(ℝ[x,y]), G::Vector{@ring(ℝ[x,y])}; order::typeof(@degrevlex(x > y)), redtype::PolynomialRings.Operators.Full)
@ PolynomialRings.Reductions ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Reductions.jl:89
[7] rem!
@ ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Reductions.jl:87 [inlined]
[8] #rem#6
@ ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Reductions.jl:351 [inlined]
[9] rem
@ ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Reductions.jl:348 [inlined]
[10] #rem#37
@ ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Reductions.jl:435 [inlined]
[11] rem(f::@ring(ℝ[x,y]), g::@ring(ℝ[x,y]))
@ PolynomialRings.Reductions ~/.julia/packages/PolynomialRings/JNZGk/src/PolynomialRings/Reductions.jl:434
[12] top-level scope
@ REPL[10]:1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.