Re: [sage-support] Re: How to define variables over integer

2019-05-09 Thread Santanu Sarkar
Dear friends,
   Thank you so much for your help. It is working now.

Regards,
Santanu

On Thu, 9 May 2019 at 15:19, Simon King  wrote:

> 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. = BooleanPolynomialRing()
> which would automatically define z0,...,z3 in the global namespace.
>
> Similarly, you can do
>sage: V. = 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 sage-support+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-support@googlegroups.com.
> 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.
>

-- 
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 sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
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/CAOe8sPJhKPX4jYZUPAJnjNjkGvMtj4TNCpPkcBD9zg0vo1k4ng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: How to define variables over integer

2019-05-09 Thread Simon King
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. = BooleanPolynomialRing()
which would automatically define z0,...,z3 in the global namespace.

Similarly, you can do
   sage: V. = 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 sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
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.


[sage-support] Re: How to define variables over integer

2019-05-08 Thread darwin doppelganger
I forgot to add that you can automatically put the variables in a list with:

Z = list(V.gens())


-- 
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 sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
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/8bfe3d77-6e0b-423c-8147-5f700e237732%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: How to define variables over integer

2019-05-08 Thread darwin doppelganger
Doesn't PolynomialRing() 
do
 
what you want? For example,

n=4
V=PolynomialRing(QQ,n+1,['z%d'%(i) for i in range(n+1)] )
V.inject_variables()

-- 
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 sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
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/5f2a2611-3df6-4d8a-9f71-ba5ff3e33ecf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.