Hi Santanu,
Am Mittwoch, 8. Mai 2019 15:15:06 UTC+2 schrieb Santanu:
>
> I know how to define variables over BooleanPolynomialRing.
> This is as follows.
>
> n=4
> V=BooleanPolynomialRing(n+1,['z%d'%(i) for i in range(n+1)] )
> V.inject_variables()
>
The above is what you could do *in an interactive session* in the case that
the number of variables isn't known in advance. If it is known that you
have exactly four variables, simply do
sage: V.<z0,z1,z2,z3> = BooleanPolynomialRing()
which would automatically define z0,...,z3 in the global namespace.
Similarly, you can do
sage: V.<z0,z1,z2,z3> = ZZ[]
to create a polynomial ring over the integers with generators z0,...,z3
But the above is not what you could do *in a python module* and in a module
it is also a bad idea to inject variables.
So, simply put the variables in a list or access them by methods of V.
> Can we define similar code over integers (ZZ) or rationals (QQ)?
>
Actually I wonder if we mean the same when we say "variables over ZZ". I
mean "generators of a polynomial ring with integer coefficients". When the
number of generators isn't known in advance, but the generators are named
z0,z1,z2,..., such ring can be created, e.g., by
sage: P = PolynomialRing(ZZ, 'z', 5)
sage: P
Multivariate Polynomial Ring in z0, z1, z2, z3, z4 over Integer Ring
However, I could imagine that you wanted to ask how to create a symbolic
variable that is assumed to take values in ZZ --- and that's totally
different from a generator of a polynomial ring over ZZ. So, if that's what
you mean, you could do (in an interactive session)
sage: var('z0 z1 z2 z3', domain='integer')
(which would inject the variables into the global namespace) or
Z = var('z0 z1 z2 z3', domain='integer')
(which would also work in a python module and puts the variables into a
tuple).
Also I want to store variables in an array like Z=[z0,z1,z2,z3]
> but it should be automatic. I will change only n.
>
If you really want to work with symbolic variables, you could do
sage: n = 5
sage: Z = var(['z{}'.format(i) for i in range(n)], domain='integer')
sage: Z
(z0, z1, z2, z3, z4)
sage: z0
z0
(thus, the variables are both put in a tuple and injected into the global
name space.
However, I believe that very many Sage users work with symbolic variables
when they should better use generators of polynomial rings. So, perhaps
code such as the following
sage: P = PolynomialRing(ZZ, 'z', n)
sage: Z = P.gens()
sage: Z
(z0, z1, z2, z3, z4)
sage: P.gen(0)
z0
sage: P.inject_variables()
Defining z0, z1, z2, z3, z4
(the latter only in an interactive session) suites your needs better.
Best regards,
Simon
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sage-support/d7d49151-5dc8-445c-b0dc-e494eb558965%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.