ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 10 Aug 2014 10:20:59 +0200How to get the variables present in an boolean expressionhttps://ask.sagemath.org/question/23732/how-to-get-the-variables-present-in-an-boolean-expression/Consider the boolean variables `x`, `y` and `z`.
I need something like
sage: variables(x+yz)
[x, y, z]
sage: variables(x+z)
[x, z]
What should I do?
For a starting point, you may like (copied from [the answer given here](http://ask.sagemath.org/question/23729/how-to-count-degree-of-a-monomial-in-boolean-polynomial/)):
sage: R = BooleanPolynomialRing(3, 'x')
sage: x, y, z = R.gens()
Sun, 10 Aug 2014 04:21:15 +0200https://ask.sagemath.org/question/23732/how-to-get-the-variables-present-in-an-boolean-expression/Answer by FrédéricC for <p>Consider the boolean variables <code>x</code>, <code>y</code> and <code>z</code>.</p>
<p>I need something like</p>
<pre><code> sage: variables(x+yz)
[x, y, z]
sage: variables(x+z)
[x, z]
</code></pre>
<p>What should I do? </p>
<p>For a starting point, you may like (copied from <a href="http://ask.sagemath.org/question/23729/how-to-count-degree-of-a-monomial-in-boolean-polynomial/">the answer given here</a>):</p>
<pre><code>sage: R = BooleanPolynomialRing(3, 'x')
sage: x, y, z = R.gens()
</code></pre>
https://ask.sagemath.org/question/23732/how-to-get-the-variables-present-in-an-boolean-expression/?answer=23734#post-id-23734You should read the doc before asking such questions here.
In particular, give a name to your object and use the automatic `TAB `-completion to get the list of available methods. In this way, you can learn about the methods `.degree` and `.variables ` by hitting the `TAB ` key after `too. `
sage: sage: R = BooleanPolynomialRing(3, 'x')
sage: sage: x, y, z = R.gens()
sage: too = x+z
sage: sage: too.v # (pressing TAB key here)
too.variable too.vars_as_monomial
too.variables too.version
sage: too.variables()
(x0, x2)
sage: len(too.variables())
2
Sun, 10 Aug 2014 10:20:59 +0200https://ask.sagemath.org/question/23732/how-to-get-the-variables-present-in-an-boolean-expression/?answer=23734#post-id-23734