Ask Your Question
1

In sagemath, why can't i take the maximum degree from a differentiated monomial?

asked 2021-10-21 16:38:38 +0100

Sam gravatar image

updated 2021-10-21 16:54:51 +0100

The code :

from sage.crypto.boolean_function import BooleanFunction from random import randint import random import numpy from sage.all import *

R.<s0, s1,="" s2,="" s3,="" s4,="" s5,="" s6,="" s7,="" s8,="" s9,="" s10,="" s11,="" s12,="" s13,="" s14,="" s15,="" s16,="" s17,="" s18,="" s19,="" s20,="" s21,="" s22,="" s23,="" s24,="" s25,="" s26,="" s27,="" s28,="" s29,="" s30,="" s31,="" s32,="" s33,="" s34,="" s35,="" s36,="" s37,="" s38,="" s39,="" s40,="" s41,="" s42,="" s43,="" s44,="" s45,="" s46,="" s47,="" s48,="" s49,="" s50,="" s51,="" s52,="" s53,="" s54,="" s55,="" s56,="" s57,="" s58,="" s59,="" s60,="" s61,="" s62,="" s63,="" s64,="" s65,="" s66,="" s67,="" s68,="" s69,="" s70,="" s71,="" s72,="" s73,="" s74,="" s75,="" s76,="" s77,="" s78,="" s79,="" s80,="" s81,="" s82,="" s83,="" s84,="" s85,="" s86,="" s87,s88,="" s89,="" s90,="" s91,="" s92,="" s93,="" s94,="" s95,="" s96,="" s97,="" s98,="" s99,="" s100,="" s101,="" s102,="" s103,="" s104,="" s105,="" s106,="" s107,="" s108,="" s109,="" s110,="" s111,="" s112,="" s113,="" s114,="" s115,="" s116,="" s117,="" s118,="" s119,="" s120,="" s121,="" s122,="" s123,="" s124,="" s125,="" s126,="" s127,="" k0,="" k1,="" k2,="" k3,="" k4,="" k5,="" k6,="" k7,="" k8,="" k9,="" k10,="" k11,="" k12,="" k13,="" k14,="" k15,="" k16,="" k17,="" k18,="" k19,="" k20,="" k21,="" k22,="" k23,="" k24,="" k25,="" k26,="" k27,="" k28,="" k29,="" k30,="" k31,="" k32,="" k33,="" k34,="" k35,="" k36,="" k37,="" k38,="" k39,="" k40,="" k41,="" k42,="" k43,="" k44,="" k45,="" k46,="" k47,="" k48,="" k49,="" k50,="" k51,="" k52,="" k53,="" k54,="" k55,="" k56,="" k57,="" k58,="" k59,="" k60,="" k61,="" k62,="" k63,="" k64,="" k65,="" k66,="" k67,="" k68,="" k69,="" k70,="" k71,="" k72,="" k73,="" k74,="" k75,="" k76,="" k77,="" k78,="" k79,="" k80,="" k81,="" k82,="" k83,="" k84,="" k85,="" k86,="" k87,="" k88,="" k89,="" k90,="" k91,="" k92,="" k93,="" k94,="" k95,="" k96,="" k97,="" k98,="" k99,="" k100,="" k101,="" k102,="" k103,="" k104,="" k105,="" k106,="" k107,="" k108,="" k109,="" k110,="" k111,="" k112,="" k113,="" k114,="" k115,="" k116,="" k117,="" k118,="" k119,="" k120,="" k121,="" k122,="" k123,="" k124,="" k125,="" k126,="" k127=""> = BooleanPolynomialRing() R = BooleanPolynomialRing(names=('s0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's10', 's11', 's12', 's13', 's14', 's15', 's16', 's17', 's18', 's19', 's20', 's21', 's22', 's23', 's24', 's25', 's26', 's27', 's28', 's29', 's30', 's31', 's32', 's33', 's34', 's35', 's36', 's37', 's38', 's39', 's40', 's41', 's42', 's43', 's44', 's45', 's46', 's47', 's48', 's49', 's50', 's51', 's52', 's53', 's54', 's55', 's56', 's57', 's58', 's59', 's60', 's61', 's62', 's63', 's64', 's65', 's66', 's67', 's68', 's69', 's70', 's71', 's72', 's73', 's74', 's75', 's76', 's77', 's78', 's79', 's80', 's81', 's82', 's83', 's84', 's85', 's86', 's87', 's88', 's89', 's90', 's91', 's92', 's93', 's94', 's95', 's96', 's97', 's98', 's99', 's100', 's101', 's102', 's103', 's104', 's105', 's106', 's107', 's108', 's109', 's110', 's111', 's112', 's113', 's114', 's115', 's116', 's117', 's118', 's119', 's120', 's121', 's122', 's123', 's124', 's125', 's126', 's127', 'k0', 'k1', 'k2', 'k3', 'k4', 'k5', 'k6', 'k7', 'k8', 'k9', 'k10', 'k11', 'k12', 'k13', 'k14', 'k15', 'k16', 'k17', 'k18', 'k19', 'k20', 'k21', 'k22', 'k23', 'k24', 'k25', 'k26', 'k27', 'k28', 'k29', 'k30', 'k31', 'k32', 'k33', 'k34', 'k35', 'k36', 'k37', 'k38', 'k39', 'k40', 'k41', 'k42', 'k43', 'k44', 'k45', 'k46', 'k47', 'k48', 'k49', 'k50', 'k51', 'k52', 'k53', 'k54', 'k55', 'k56', 'k57', 'k58', 'k59', 'k60', 'k61', 'k62', 'k63', 'k64', 'k65', 'k66', 'k67', 'k68', 'k69', 'k70', 'k71', 'k72', 'k73', 'k74', 'k75', 'k76', 'k77', 'k78', 'k79', 'k80', 'k81', 'k82', 'k83', 'k84', 'k85', 'k86', 'k87', 'k88', 'k89', 'k90', 'k91', 'k92', 'k93', 'k94', 'k95', 'k96', 'k97', 'k98', 'k99', 'k100', 'k101', 'k102', 'k103', 'k104', 'k105', 'k106', 'k107', 'k108', 'k109', 'k110', 'k111', 'k112', 'k113', 'k114', 'k115', 'k116', 'k117', 'k118', 'k119', 'k120', 'k121', 'k122', 'k123', 'k124', 'k125', 'k126', 'k127'))

R.inject_variables()

S = list(R.gens()[0:128])

S_128 = list(R.gens()[0:128])

K = list(R.gens()[128:256])

eqList = ["eq"]

for i in range(128): feedback = S[0] + S[47] + S[70]*S[85] + S[91] + 1 + K[i%128] for j in range(127): S[j] = S[j+1] S[127] = feedback

print(S[64]) X = diff(S[64], S_128[21]) print('\n') print(X) print('\n') print(X.degree(S_128)) print('\n') print ('--------------------------------------------------------------------------------------------------------------')

I am using e booleanpolynomial ring and all defined. It says the error : degree() takes exactly one argument (0 given). The degree() function works properly for other function unrelated to the diff() function such as s[64].degree().

edit retag flag offensive close merge delete

Comments

Please edit your example code to make it self-contained (with all variables defined).

rburing gravatar imagerburing ( 2021-10-21 16:49:51 +0100 )edit

Please try to run this code in your SageMath and you'll see what I mean

Sam gravatar imageSam ( 2021-10-21 16:55:12 +0100 )edit

Please refer to the link above, I asked the same question in stackoverflow, that has a clearer question and no errors in the formatting

Sam gravatar imageSam ( 2021-10-21 17:01:14 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-10-21 17:44:09 +0100

rburing gravatar image

Differentiation of boolean polynomials themselves is not implemented, so what diff does is: first convert to a symbolic expression and then take the derivative. The resulting object is a symbolic expression, which explains the different behavior of the degree method on the result.

What you can do instead is convert your boolean polynomial to an ordinary polynomial (lift it to the cover ring), then take the derivative, and then convert back to a boolean polynomial, like so:

sage: C = R.cover_ring()
sage: X = R(diff(C(S[64]), C(S_128[21]))); X
s6 + s53 + s76*s91 + s97 + k6 + 1
sage: X.degree()
2

I guess that is what you want to do.

Beware that $\frac{\partial}{\partial x_i}\bigl(x_i^2 + x_i\bigr)=2x_i+1=1$ in $\mathbb{F}_2[x_1,\ldots,x_n]$, so the meaning/sense of differentiating a boolean polynomial, which is an element of $\mathbb{F}_2[x_1,\ldots,x_n]/\langle x_1^2+x_1, \ldots, x_n^2+x_n \rangle$, is questionable.

edit flag offensive delete link more

Comments

Works well now. Thank you so much for the help and insights!

Sam gravatar imageSam ( 2021-10-22 04:46:29 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-10-21 16:38:38 +0100

Seen: 446 times

Last updated: Oct 21 '21