1 | initial version |
Once the ring B
is created, you can access its variables as B.gens()
.
To name hundreds of variables, the alphabet is too short,
so using a0
, a1
, etc., seems better.
Calling a
the tuple of generators then means a[0]
is a0
and so on.
An illustration with 10 variables.
sage: B = BooleanPolynomialRing(10,names='a')
sage: B
Boolean PolynomialRing in a0, a1, a2, a3, a4, a5, a6, a7, a8, a9
sage: a = B.gens()
sage: a[0]
a0
2 | No.2 Revision |
Once the ring B
is created, you can access its variables as B.gens()
.
To name hundreds of variables, the alphabet is too short,
so using a0
, a1
, etc., seems better.
Calling a
the tuple of generators then means a[0]
is a0
and so on.
An illustration with 10 variables.
sage: B = BooleanPolynomialRing(10,names='a')
sage: B
Boolean PolynomialRing in a0, a1, a2, a3, a4, a5, a6, a7, a8, a9
sage: a = B.gens()
sage: a[0]
a0
Generators can also be called directly without giving a name to the tuple, by the shortcut
sage: B.8
a8
or the following syntax
sage: B.gen(8)
a8
which allows to call the k
-th generator where k
is an index in a loop (contrary to the shortcut above).
3 | No.3 Revision |
Once the ring B
is created, you can access its variables can be accessed (a) as
.B.gens()
To name hundreds of variables, the alphabet is too short,
so using a0
, a1
, etc., seems better.
Calling a
the tuple of generators then means a[0]
is a0
B.0, B.1
, and so on.
An illustration with 10 variables.on,
and (b) as B.gen(0)
, B.gen(1)
, and so on. Use the second syntax if you need a literal index, eg B.gen(k)
, in a loop, a sum, etc. The command B.gens()
will provide a tuple of all the variables in B
.
The syntax BooleanPolynomialRing(10,names='a')
allows to name the variables
a0
, a1
, etc. For hundreds of variables, this naming scheme is more adapted
than using the alphabet.
That syntax combines well with the naming of the tuple of generators, see below.
Create the boolean polynomial ring:
sage: B = BooleanPolynomialRing(10,names='a')
sage: B
Boolean PolynomialRing in a0, a1, a2, a3, a4, a5, a6, a7, a8, a9
Access its variables with method (a):
sage: B.8
a8
or with method (b):
sage: B.gen(8)
a8
Use method (b) with literal indices:
sage: sum(B.gen(k) for k in (1,3,5,7))
a1 + a3 + a5 + a7
Give a name to the tuple of generators, consistent with the naming scheme
for the variables, eg a = B.gens()
, so that a[0]
is a0
and so on.
sage: a = B.gens()
sage: a[0]
a0
Generators can also be called directly without giving a name to the tuple, by the shortcut
sage: B.8
a8
or the following syntax
sage: B.gen(8)
a8
which allows to call the k
-th generator where k
is an index in a loop (contrary to the shortcut above).
Use that for looping, summing, etc.
sage: sum(a[k]*a[k+1] for k in (1,3,5,7))
a1*a2 + a3*a4 + a5*a6 + a7*a8
4 | No.4 Revision |
Once There are many ways to call the variables of the boolean polynomial ring B
is
after it has been created, its variables can be accessed (a) and to assign them to Python variables.
We will list four below. Sometimes you may want to use more than one.
Suppose we have defined, as in the question,
sage: B = BooleanPolynomialRing(names=['a', 'b'])
Ways to access the variables of B
include:
Call them as B.0
, B.1
, and (and so on,
and (b) as on if there are more than two).B.gen(0)
, B.gen(1)
, and so on. Use the second syntax
This works only with actuan numbers after the dot; for instance, even
if you have defined k = 0
you can't do B.k
to get B.0
.
Call them as B.gen(0)
, B.gen(1)
(and so on if there are more than two).
If you need a literal index, eg to call these variables in a loop, an iterator, or a sum,
this syntax B.gen(k)
, in a loop, a sum, etc. is usually helpful.
The command B.gens()
will provide a tuple of all the variables in B
.
You could use that to give a name to all the generators, say gen_B = B.gens()
and then call gen_B[0]
, gen_B[1]
(and so on if there are more than two).
The command B.inject_variables()
will make some Python variables with
the correct names to call the variables as named in the declaration of B
.
For example,
sage: B = BooleanPolynomialRing(names=['a', 'b'])
sage: B.inject_variables()
sage: (a + b)*(a - b)
a + b
The syntax
allows to name the variables
BooleanPolynomialRing(10,names='a')BooleanPolynomialRing(10, names='a')a0
, a1
, etc. For hundreds of variables, this naming scheme is more adapted
than using the alphabet.
That syntax combines well with the naming of the tuple of generators, see below.
Create the boolean polynomial ring:
sage: B = BooleanPolynomialRing(10,names='a')
BooleanPolynomialRing(10, names='a')
sage: B
Boolean PolynomialRing in a0, a1, a2, a3, a4, a5, a6, a7, a8, a9
Access its variables with method (a):1:
sage: B.8
a8
or with method (b):2:
sage: B.gen(8)
a8
Use method (b) 2 with literal indices:
sage: sum(B.gen(k) for k in (1,3,5,7))
(1, 3, 5, 7))
a1 + a3 + a5 + a7
Give a name to the tuple of generators, consistent with the naming scheme
for the variables, eg a = B.gens()
, so that a[0]
is a0
and so on.
sage: a = B.gens()
sage: a
(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
sage: a[3]
a3
Use that for looping, summing, etc.
sage: sum(a[k]*a[k+1] for k in (1,3,5,7))
(1, 3, 5, 7))
a1*a2 + a3*a4 + a5*a6 + a7*a8
If you have variables named with several letters and numbers, as in
sage: B = BooleanPolynomialRing(7, ['a0', 'a1', 'a2', 'a3', 'b0', 'b1', 'b2'])
then you could inject the variables and use them:
sage: B.inject_variables()
sage: (a0 + b0)*(a1 - b1)
a0*a1 + a0*b1 + a1*b0 + b0*b1
and/or you could do something like
sage: ab = B.gens()
sage: a = ab[:4]
sage: b = ab[4:]
so that
sage: a
(a0, a1, a2, a3)
sage: b
(b0, b1, b2)
and
sage: a[0] + a[3] + b[1]
a0 + a3 + b1