# Multivariate polynomial ring with only one variable

5 views

### Grégory Vanuxem

May 12, 2024, 10:51:24 PMMay 12
to Nemo-Devel
Hello,

I want to use a sparse representation for, in fact, univariate
polynomials so I use the multivariate polynomial ring constructor.
But look at this, may I know why the first 'x' is a vector?

julia> R,(x)=polynomial_ring(ZZ,["x"])
(Multivariate polynomial ring in 1 variable over ZZ, ZZMPolyRingElem[x])

julia> x
1-element Vector{ZZMPolyRingElem}:
x

julia> R,x=polynomial_ring(ZZ,["x"])
(Multivariate polynomial ring in 1 variable over ZZ, ZZMPolyRingElem[x])

julia> x
1-element Vector{ZZMPolyRingElem}:
x

julia> R,(x,y)=polynomial_ring(ZZ,["x","y"])
(Multivariate polynomial ring in 2 variables over ZZ, ZZMPolyRingElem[x, y])

julia> x
x

julia> y
y

Is there a way to circumvent this?

- Greg

### Grégory Vanuxem

May 13, 2024, 5:43:56 AMMay 13
to Nemo-Devel
I should have been more careful when I exposed my question. My ring
is constructed in another application, that loads the libjulia, so all
is done automatically and this exception, with one variable, produces
the following. I can of course use the first element of the returned
vector but that is not really consistent for my purpose:

In FriCAS, a descendant of the Axiom CAS:

FriCAS Computer Algebra System
Version: FriCAS 1.3.11-dev built with SBCL 2.4.4
Timestamp: lun. 13 mai 2024 10:54:58 CEST
-----------------------------------------------------------------------------
Issue )summary for a summary of useful system commands.
-----------------------------------------------------------------------------

(1) -> x:=coerce(x)\$NMP(NINT,["x","y","z"],"lex")

(1) x
Type: NemoMultivariatePolynomial(NemoInteger,[x,y,z],:lex)

(2) -> x^7

(2) x^7
Type: NemoMultivariatePolynomial(NemoInteger,[x,y,z],:lex)
Time: 0.02 (EV) + 0.34 (OT) = 0.36 sec
(3) -> y:=coerce(y)\$NMP(NINT,["x","y","z"],"lex")

(3) y
Type: NemoMultivariatePolynomial(NemoInteger,[x,y,z],:lex)
Time: 0 sec
(4) -> x*y

(4) x*y
Type: NemoMultivariatePolynomial(NemoInteger,[x,y,z],:lex)
Time: 0.02 (EV) + 0.01 (OT) = 0.03 sec
(5) -> %^7+9

(5) x^7*y^7 + 9
Type: NemoMultivariatePolynomial(NemoInteger,[x,y,z],:lex)
Time: 0.03 (IN) + 0.01 (EV) + 0.10 (OT) = 0.14 sec
(6) -> )clear all
All user variables and function definitions have been cleared.
(1) -> x:=coerce(x)\$NMP(NINT,["x"],"lex")

(1) ZZMPolyRingElem[x]
Type: NemoMultivariatePolynomial(NemoInteger,[x],:lex)
Time: 0.16 (OT) = 0.16 sec
(2) ->

The code is always "generic" in FriCAS, that is, for example every
ring implemented in FriCAS can use a default implementation. Here this
is specific to "NemoRing" but the last returned value, a vector, needs
to be handled in a specific manner, and I would like to keep my code
relatively generic
and not just handling this particular case.

In fact, my question comes from a question from a FriCAS developer who
asked me for Nemo univariate polynomial how it behaves for specific
computation cases since they are not implemented in a sparse
representation, whereas Nemo multivariate polynomials are:

(1) -> x:=coerce(x)\$NMP(NINT,["x","y"],"lex")

(1) x
Type: NemoMultivariatePolynomial(NemoInteger,[x,y],:lex)
(2) -> y:=y::NUP(NINT,"y")

(2) y
Type: NemoUnivariatePolynomial(NemoInteger,y)
(3) -> z::POLY(INT)

(3) z
Type: Polynomial(Integer)
(4) -> )set mess time on
(4) -> degree((x^100000+1)^100)

10000000
(4) x
Type: IndexedExponents(OrderedVariableList([x,y]))
Time: 0.15 (EV) = 0.16 sec
(5) -> degree((y^100000+1)^100)

(5) 10000000
Type: PositiveInteger
Time: 0.01 (IN) + 7.25 (EV) = 7.27 sec
(6) -> degree((z^100000+1)^100)

10000000
(6) z
Type: IndexedExponents(Symbol)
Time: 0.01 sec
(7) -> degree((x^100000+1)^100)

10000000
(7) x
Type: IndexedExponents(OrderedVariableList([x,y]))
Time: 0 sec
(8) -> degree((z^100000+1)^100)

10000000
(8) z
Type: IndexedExponents(Symbol)
Time: 0 sec
(9) -> degree((y^100000+1)^100)

(9) 10000000
Type: PositiveInteger
Time: 5.52 (EV) = 5.52 sec
(10) -> degree((y^100000+1)^100)

(10) 10000000
Type: PositiveInteger
Time: 6.19 (EV) = 6.19 sec
(11) ->

- Greg

### tho...@gmail.com

May 13, 2024, 10:22:12 AMMay 13
to nemo-devel
I don't know the paricular details of the wrapper, but regarding your first message, you can do

julia> R,(x,)=polynomial_ring(ZZ,["x"]) # note that , after the x

(Multivariate polynomial ring in 1 variable over ZZ, ZZMPolyRingElem[x])

julia> x
x

julia> R,(x,y,)=polynomial_ring(ZZ,["x", "y"])

(Multivariate polynomial ring in 2 variables over ZZ, ZZMPolyRingElem[x, y])

julia> x
x

julia> y
y

Does that help?

Best wishes
Tommy