Ask Your Question

Stockfish3709's profile - activity

2019-01-28 19:43:21 -0500 asked a question Dividing Boolean Polynomials in Sage.

Hi all,

I'm working in a Boolean Polynomial Ring. I have an equation generator. My objective is to divide the highest possible monomial by the leading monomial of my equations.

B = BooleanPolynomialRing(NUMBER_OF_VARIABLES,'x', order = 'degrevlex')

Each equation that I generate looks something like this.

f = x6*x2*x1 + x6*x5*x4 + x9*x5*x4 + x9*x6*x0 + x10*x2*x1 + x10*x4*x1 + x11*x9*x7 + x11*x10*x0 + x12*x4*x0 + x12*x7*x3 + x12*x9*x0 + x12*x10*x3 + x12*x10*x5 + x13*x7*x0 + x13*x7*x5 + x13*x8*x6 + x13*x10*x9 + x13*x11*x2 + x14*x5*x4 + x14*x11*x5 + x14*x13*x12 + x6*x3 + x7*x2 + x9*x1 + x10*x9 + x14*x8 + x14*x13 + x3 + x7 + x8 + 1

Getting the leading monomial of f:

print f.lm()
>>> x6*x2*x1

Getting the highest possible monomial of my ring (15 variables)

print f.set().vars()
>>> x14*x13*x12*x11*x10*x9*x8*x7*x6*x5*x4*x3*x2*x1*x0

But somehow I get an error when I try to divide them.

>>> bad operand type for unary ~: 'sage.rings.polynomial.pbori.BooleanMonomial'

I checked the documentation and nothing seems to work. I have tried all of the methods below and they do not work.


I'm really at a loss here. I've seen answers whereby the code q,r = dividend.maxima_methods().divide(divisor) is used, but this seems like such a simple thing to do. Surely I'm missing something out. Why isn't division working? Multiplication and addition works, so why shouldn't division work?

2019-01-27 19:11:50 -0500 asked a question Subbing variables into equations not working when variables are from B.gen() function.

Hi, I'm working in a Boolean Polynomial Ring in 10 variables. The whole purpose of my project is to solve a system of equations.

As of now, I am working on an attack called the fixed XL attack. In summary, it involves guessing a value for one of the variables and then solving the system of equations. If it yields no answer, or if the values solved are not consistent with the system of equations, guess the other value for the variable and do it again. It has been shown that such a method could be faster than regular attacks.

So I have a problem with subbing in the values. The code below doesn't work. I get an error message KeyError: 'var_sub'.

B = BooleanPolynomialRing(NUMBER_OF_VARIABLES,'x', order = 'degrevlex')
var_sub = B.gen(NUMBER_OF_VARIABLES -1)
print var_sub
>>> x9
f = x0 + x1 + x7*x6*x9*x2*x0 + x6*x4*x3*x1 + x9*x7
print f.subs(var_sub = B(0))

I have no idea why it doesn't work though. I didn't get any answers from Google or documentation. It says that var_sub.parent() is stored as a Boolean Polynomial Ring, but even changing the third line of the code to var_sub = str(B.gen(NUMBER_OF_VARIABLES -1)) doesn't work.

On the other hand, simply just specifying what to sub in works. However, this is obviously not what I want as I do not want to keep specifying what to sub in when I increase the number of variables.

B = BooleanPolynomialRing(NUMBER_OF_VARIABLES,'x', order = 'degrevlex')
f = x0 + x1 + x7*x6*x9*x2*x0 + x6*x4*x3*x1 + x9*x7
print f.subs(x9 = B(0))
>>> x6*x4*x3*x1 + x0 + x1
2019-01-10 01:54:55 -0500 asked a question Is it possible to import machine learning libraries in Sage?

I'm doing a machine learning program in Sage and I wish to use Tensorflow or Scikit learn. However, I don't see any way to import the modules in Sage. I'm wondering if it is possible to import other modules outside of Sage into Sage, or if Sage is essentially a black box system that doesn't work with any other module.

2019-01-08 00:05:21 -0500 asked a question Sage Notebook IOPub data rate exceeded error?


Currently I'm running a very system intensive process on Sage and I'm getting this error.

IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

From research, I am supposed to paste the below in my command prompt.

jupyter notebook --generate-config

But when I try to do so, it says that it is not recognised as an internal or external command.

How do I resolve this issue?

2019-01-07 07:35:09 -0500 commented question Any way to make Sage display large matrices all in 1 line?

Hi, thanks for the reply. My laptop in my office has Sage in it and is running on SageNB. However, I also use CoCalc online by starting a new Sage worksheet. Not sure if it makes a difference, but all the better if I can get both formats to display matrices correctly.

2019-01-07 06:27:00 -0500 asked a question Any way to make Sage display large matrices all in 1 line?

Hi all,

Currently I have this code that generates large matrices.

B = BooleanPolynomialRing(25,'x', order = 'degneglex')
from sage.rings.polynomial.toy_variety import coefficient_matrix
from brial import *
v = BooleanPolynomialVector()
l = [B.random_element(degree = 3, terms = 4) for j in range(25)]
_ = [v.append(e) for e in l]

from sage.rings.polynomial.toy_variety import coefficient_matrix
print l
%time A, v = Sequence(l,B).coefficient_matrix()
print A
print v

The matrix generated is big, so big that it takes 2 lines to display all of it. It is hard to visualise. Is there some way of making each row of the matrix inline together such that they are not separated into different lines?

2019-01-07 02:55:20 -0500 asked a question Is there a way to make sage print out all monomials of a Boolean Ring?

Hi all,

In a finite ring, is there a way to get Sage to print out all possible monomials of the ring? I have a method, but it's very crude. It's simply doing something like taking a random variable to mutiply with a random ring element from B.random_element(). But this is obviously not what I want.

Below is the ring I'm working with.

B = BooleanPolynomialRing(20,'x', order = 'lex')

Is there a Sage function to put every monomial of the ring into a list? I can't seem to find it in Sage documentation.

2019-01-04 20:55:09 -0500 received badge  Supporter (source)
2019-01-04 03:29:42 -0500 received badge  Student (source)
2019-01-03 22:55:43 -0500 received badge  Editor (source)
2019-01-03 22:54:41 -0500 asked a question Sage not detecting intergers in Boolean Polynomial Ring?

Hi all,

I'm trying to do a detecting system for terms in the equations used in a polynomial. I'm using Boolean Polynomials here.

Here's is my code. This prints all the terms of the equations.

P.<x,y,z> = BooleanPolynomialRing(3, order = 'lex')
equations = [x+y+z-1, y*z, x+z]
for i in range(len(equations)):
    for j in equations[i]:
        print j


As you can see, 1 appears in the output. However, when I implement this logic onto it, the output is empty.

for i in range(len(equations)):
    for j in equations[i]:
        if j == 1:
            print 'true'

It's not like the logic doesn't work, if I change '1' to 'x', my logic works.

for i in range(len(equations)):
    for j in equations[i]:
        if j == x:
            print 'true'


What am I doing wrong here?

2019-01-03 06:54:39 -0500 received badge  Scholar (source)
2019-01-03 02:20:02 -0500 asked a question Using SageMath to solve Simultaneous equations in a Boolean Ring

I'm trying to get SageMath to solve a system of equations in a Boolean Ring. Here is my code.

P.<x,y,z> = BooleanPolynomialRing(3, order= 'lex')
equations = [1+x+y+z, x+y, x*y+1, x+y]
zeros = [0,0,0,0]

I know that there are equation solvers for Sage, but I do not know how to have the answers of the equation be only in the Boolean Ring (ie. only 1 or 0). Obviously I can solve the equation by hand, but that's not the point here. Is there a way to have SageMath only output 0 or 1 as the answer?

2018-12-29 17:55:55 -0500 asked a question What is the .modulus() function doing?

I came across this tutorial from Sage that I couldn't get.

Below is the code.

k.<a> = GF(2^1024)
Output: x^1024 + x^19 + x^6 + x + 1

What is going on here?

I understand that the polynomials' coefficients are either 0 or 1, and the degree of the polynomial is not more than 1024, but how does Sage assign them? And also, what is the modulus of the polynomial? I have never came before such a term and I couldn't find any such concepts on the internet.

Thanks for the help in advance.