ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 27 Oct 2016 08:15:19 -0500About Boolean Functionhttp://ask.sagemath.org/question/35258/about-boolean-function/I want to find the Algebraic Normal Form of a boolean function.
For example:
sage: R.<x1,x2,x3> = BooleanPolynomialRing(3, order='degneglex')
sage: x3>x1
True
sage: L = BooleanFunction(x1+x2*x3)
sage: L.truth_table()
(False, True, False, True, False, True, True, False)
sage: L.algebraic_normal_form()
x0 + x1*x2
Unfortunately, Algebraic Normal Form of this specific boolean function is not correct (x0 should be x3, x1 should be x2 and x2 should be x1). The answer of the ANF() method is in order='lex' (not as I desired in order = 'degneglex'). Furthermore, the ANF() form is calculated out of this ring (x0 involved?)
How should I extract the ANF() in correct syntax (where x3>x2>x1)?Wed, 26 Oct 2016 06:29:16 -0500http://ask.sagemath.org/question/35258/about-boolean-function/Answer by slelievre for <p>I want to find the Algebraic Normal Form of a boolean function.</p>
<p>For example:</p>
<pre><code>sage: R.<x1,x2,x3> = BooleanPolynomialRing(3, order='degneglex')
sage: x3>x1
True
sage: L = BooleanFunction(x1+x2*x3)
sage: L.truth_table()
(False, True, False, True, False, True, True, False)
sage: L.algebraic_normal_form()
x0 + x1*x2
</code></pre>
<p>Unfortunately, Algebraic Normal Form of this specific boolean function is not correct (x0 should be x3, x1 should be x2 and x2 should be x1). The answer of the ANF() method is in order='lex' (not as I desired in order = 'degneglex'). Furthermore, the ANF() form is calculated out of this ring (x0 involved?)</p>
<p>How should I extract the ANF() in correct syntax (where x3>x2>x1)?</p>
http://ask.sagemath.org/question/35258/about-boolean-function/?answer=35275#post-id-35275An import statement is needed to make your code work in Sage 7.4.
sage: R.<x1,x2,x3> = BooleanPolynomialRing(3, order='degneglex')
sage: x3>x1
True
sage: L = BooleanFunction(x1+x2*x3)
Traceback (most recent call last)
...
NameError: name 'BooleanFunction' is not defined
sage: from sage.crypto.boolean_function import BooleanFunction
sage: L = BooleanFunction(x1+x2*x3)
sage: L.algebraic_normal_form()
x0 + x1*x2
You can access the documentation for `algebraic_normal_form` with
sage: L.algebraic_normal_form?
and the whole source code with
sage: L.algebraic_normal_form??
Maybe you could suggest how the code should be amended to take
variable names and ordering into account.Thu, 27 Oct 2016 08:15:19 -0500http://ask.sagemath.org/question/35258/about-boolean-function/?answer=35275#post-id-35275