Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 19204
1
r"""
2
Classification of boolean functions within an extended translation class
3
========================================================================
4
5
The ``boolean_function_extended_translate_classification`` module defines:
6
7
* the ``BooleanFunctionExtendedTranslateClassification`` class;
8
which represents the classification of the general linear classes
9
within the extended translation class of a boolean function; and
10
* the ``BooleanFunctionExtendedTranslateClassPart`` class,
11
which represents part of an extended translate classification.
12
13
AUTHORS:
14
15
- Paul Leopardi (2023-01-26): initial version
16
17
EXAMPLES:
18
19
::
20
21
The classification of the boolean function defined by the polynomial x2 + x1*x2.
22
23
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
24
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
25
....: BooleanFunctionExtendedTranslateClassification as BooleanFunctionETC)
26
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
27
sage: p = x2+x1*x2
28
sage: f = BooleanFunctionImproved(p)
29
sage: c = BooleanFunctionETC.from_function(f)
30
sage: dict(sorted(c.__dict__.items()))
31
{'algebraic_normal_form': x0*x1 + x1,
32
'boolean_function_index_matrix': [0 2 1 3]
33
[1 3 0 2]
34
[2 0 3 1]
35
[3 1 2 0],
36
'boolean_function_list': [Boolean function with 2 variables,
37
Boolean function with 2 variables,
38
Boolean function with 2 variables,
39
Boolean function with 2 variables],
40
'general_linear_class_index_matrix': [0 0 1 0]
41
[1 0 0 0]
42
[0 0 0 1]
43
[0 1 0 0],
44
'general_linear_class_list': [Boolean function with 2 variables,
45
Boolean function with 2 variables]}
46
47
REFERENCES:
48
49
The extended translation equivalence class and the general linear equivalence class
50
of a boolean function are defined by Leopardi [Leo2017]_.
51
"""
52
#*****************************************************************************
53
# Copyright (C) 2016-2023 Paul Leopardi [email protected]
54
#
55
# Distributed under the terms of the GNU General Public License (GPL)
56
# as published by the Free Software Foundation; either version 2 of
57
# the License, or (at your option) any later version.
58
# http://www.gnu.org/licenses/
59
#*****************************************************************************
60
61
62
from datetime import datetime
63
from numpy import array, argwhere
64
from sage.functions.log import log
65
from sage.graphs.graph import Graph
66
from sage.matrix.constructor import matrix
67
from sage.misc.latex import latex
68
from sage.misc.persist import load
69
from sage.plot.matrix_plot import matrix_plot
70
from sage.rings.integer import Integer
71
from sage.structure.sage_object import SageObject
72
from sys import stdout
73
74
import glob
75
import numpy as np
76
77
from boolean_cayley_graphs.boolean_function_improved import (
78
BooleanFunctionImproved)
79
from boolean_cayley_graphs.boolean_function_general_linear_class import (
80
BooleanFunctionGeneralLinearClass)
81
from boolean_cayley_graphs.containers import (
82
BijectiveList, List, ShelveBijectiveList)
83
from boolean_cayley_graphs.saveable import Saveable
84
85
import boolean_cayley_graphs.cayley_graph_controls as controls
86
import csv
87
import os.path
88
89
default_algorithm = "sage"
90
91
92
class BooleanFunctionExtendedTranslateClassPart(SageObject, Saveable):
93
r"""
94
Partial classification of the general linear classes within the
95
extended translation equivalence class of a boolean function.
96
97
EXAMPLES:
98
99
::
100
101
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
102
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
103
....: BooleanFunctionExtendedTranslateClassPart as BooleanFunctionETCPart)
104
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
105
sage: p = x1+x2+x1*x2
106
sage: f = BooleanFunctionImproved(p)
107
sage: c1 = BooleanFunctionETCPart.from_function(f, c_stop=1)
108
sage: print(c1)
109
BooleanFunctionExtendedTranslateClassPart.from_function(BooleanFunctionImproved(x0*x1 + x0 + x1, c_start=0, c_stop=1))
110
sage: latex(c1)
111
\text{\texttt{BooleanFunctionExtendedTranslateClassPart.from{\char`\_}function(BooleanFunctionImproved(x0*x1{ }+{ }x0{ }+{ }x1,{ }c{\char`\_}start=0,{ }c{\char`\_}stop=1))}}
112
113
"""
114
115
def __init__(self, *args, **kwargs):
116
r"""
117
Constructor from an object or from class attributes.
118
119
INPUT:
120
121
- ``algebraic_normal_form`` -- a polynomial of the type
122
returned by ``BooleanFunction.algebraic_normal_form()``,
123
representing the ``BooleanFunction`` whose classification this is.
124
- ``boolean_function_index_matrix`` -- a ``Matrix` of integers,
125
which are indices into ``boolean_function_list`` representing the
126
distinct boolean functions.
127
- ``boolean_function_list`` -- a list of boolean functions.
128
- ``general_linear_class_index_matrix`` -- a ``Matrix` of integers,
129
which are indices into ``general_linear_class_list`` representing the
130
general linear equivalence classes.
131
- ``general_linear_class_list`` -- a list of matrices representing the
132
general linear equivalence classes.
133
- ``c_start`` -- an integer representing the index of
134
the first row of each matrix.
135
136
OUTPUT:
137
138
None.
139
140
EFFECT:
141
142
The current object ``self`` is initialized as follows.
143
144
Each of
145
- ``algebraic_normal_form``
146
- ``boolean_function_index_matrix``
147
- ``boolean_function_list``
148
- ``general_linear_class_index_matrix``
149
- ``general_linear_class_list``
150
- ``c_start``
151
is set to the corresponding input parameter.
152
153
EXAMPLES:
154
155
The partial classification of the boolean function defined by the polynomial
156
:math:`x_1 + x_2 + x_1 x_2` is copied from `c1` to `c2`.
157
158
::
159
160
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
161
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
162
....: BooleanFunctionExtendedTranslateClassPart as BooleanFunctionETCPart)
163
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
164
sage: p = x1+x2+x1*x2
165
sage: f = BooleanFunctionImproved(p)
166
sage: c1 = BooleanFunctionETCPart.from_function(f, c_stop=1)
167
sage: c2 = BooleanFunctionETCPart(c1)
168
sage: print(c1 == c2)
169
True
170
"""
171
try:
172
sobj = args[0]
173
self.algebraic_normal_form = sobj.algebraic_normal_form
174
self.boolean_function_index_matrix = sobj.boolean_function_index_matrix
175
self.boolean_function_list = sobj.boolean_function_list
176
self.general_linear_class_index_matrix = sobj.general_linear_class_index_matrix
177
self.general_linear_class_list = sobj.general_linear_class_list
178
self.c_start=sobj.c_start
179
except:
180
self.algebraic_normal_form = kwargs.pop(
181
'algebraic_normal_form')
182
self.boolean_function_index_matrix = kwargs.pop(
183
'boolean_function_index_matrix')
184
self.boolean_function_list = kwargs.pop(
185
'boolean_function_list')
186
self.general_linear_class_index_matrix = kwargs.pop(
187
'general_linear_class_index_matrix')
188
self.general_linear_class_list = kwargs.pop(
189
'general_linear_class_list')
190
self.c_start = kwargs.pop(
191
'c_start')
192
193
194
def _repr_(self):
195
r"""
196
Sage string representation.
197
198
INPUT:
199
200
- ``self`` -- the current object.
201
202
EXAMPLES:
203
204
::
205
206
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
207
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
208
....: BooleanFunctionExtendedTranslateClassPart as BooleanFunctionETCPart)
209
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
210
sage: p = x1+x2+x1*x2
211
sage: f = BooleanFunctionImproved(p)
212
sage: c1 = BooleanFunctionETCPart.from_function(f, c_stop=1)
213
sage: print(c1)
214
BooleanFunctionExtendedTranslateClassPart.from_function(BooleanFunctionImproved(x0*x1 + x0 + x1, c_start=0, c_stop=1))
215
"""
216
c_stop = self.c_start + self.boolean_function_index_matrix.nrows()
217
return (
218
type(self).__name__ +
219
".from_function(BooleanFunctionImproved(" +
220
repr(self.algebraic_normal_form) +
221
", c_start=" +
222
repr(self.c_start) +
223
", c_stop=" +
224
repr(c_stop) +
225
"))")
226
227
228
@classmethod
229
def from_function(
230
cls,
231
boolf,
232
c_start=0,
233
c_stop=None,
234
limited_memory=False):
235
r"""
236
Constructor from the ``BooleanFunction`` ``boolf``.
237
238
INPUT:
239
240
- ``boolf`` -- an object of class ``BooleanFunction``.
241
- ``c_start`` -- integer (default: 0).
242
The smallest value of `c` to use for extended translates.
243
- ``c_stop`` -- integer (default: ``None``).
244
One more than largest value of `c` to use for extended
245
translates. ``None`` means use all remaining values.
246
- ``limited_memory`` -- boolean (default: ``False``).
247
A flag indicating whether the classification might be
248
too large to fit into memory.
249
250
OUTPUT:
251
252
An object of class BooleanFunctionExtendedTranslateClassPart,
253
initialized as follows.
254
255
- ``algebraic_normal_form`` is set to ``boolf.algebraic_normal_form()``,
256
- ``boolean_function_index_matrix`` -- a ``Matrix` of integers,
257
which are indices into ``boolean_function_list`` representing the
258
distinct boolean functions.
259
- ``boolean_function_list`` -- a list of boolean functions.
260
- ``general_linear_class_index_matrix`` -- a ``Matrix` of integers,
261
which are indices into ``general_linear_class_list`` representing the
262
general linear equivalence classes.
263
- ``general_linear_class_list`` -- a list of matrices representing the
264
general linear equivalence classes.
265
- ``c_start`` is set to smallest value of `c` used for extended translates.
266
267
Each entry ``boolean_function_index_matrix[c-c_start,b]`` corresponds to
268
the boolean function
269
:math:`x \mapsto \mathtt{boolf}(x+b) + \langle c, x \rangle + \mathtt{boolf}(b)`.
270
This enumerates all of the extended translates of ``boolf`` having ``c``
271
from ``c_start`` to but not including ``c_stop``.
272
273
EXAMPLES:
274
275
A partial classification of the boolean function defined by the polynomial
276
:math:`x_1 + x_2 + x_1 x_2`.
277
278
::
279
280
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
281
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
282
....: BooleanFunctionExtendedTranslateClassPart as BooleanFunctionETCPart)
283
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
284
sage: p = x1+x2+x1*x2
285
sage: f = BooleanFunctionImproved(p)
286
sage: c1 = BooleanFunctionETCPart.from_function(f,c_start=2,c_stop=4)
287
sage: dict(sorted(c1.__dict__.items()))
288
{'algebraic_normal_form': x0*x1 + x0 + x1,
289
'boolean_function_index_matrix': [0 2 1 3]
290
[1 3 0 2],
291
'boolean_function_list': [Boolean function with 2 variables,
292
Boolean function with 2 variables,
293
Boolean function with 2 variables,
294
Boolean function with 2 variables],
295
'c_start': 2,
296
'general_linear_class_index_matrix': [0 1 0 0]
297
[0 0 0 1],
298
'general_linear_class_list': [Boolean function with 2 variables,
299
Boolean function with 2 variables]}
300
"""
301
checking = controls.checking
302
timing = controls.timing
303
304
dim = boolf.nvariables()
305
v = 2 ** dim
306
307
if c_stop == None:
308
c_stop = v
309
else:
310
c_stop = min(c_stop, v)
311
algebraic_normal_form = boolf.algebraic_normal_form()
312
313
use_shelve = dim > 8 or (dim == 8 and limited_memory)
314
boolean_function_bijection = (
315
ShelveBijectiveList()
316
if use_shelve else
317
BijectiveList())
318
319
c_len = c_stop - c_start
320
boolean_function_index_matrix = matrix(c_len, v)
321
general_linear_class_index_matrix = matrix(c_len, v)
322
general_linear_class_list = List()
323
324
f = boolf.extended_translate()
325
for b in range(v):
326
if timing:
327
print(datetime.now(), b, end=' ')
328
print(len(boolean_function_bijection.get_list()))
329
stdout.flush()
330
for c in range(c_start, c_stop):
331
f = boolf.zero_translate(b, c)
332
tt = tuple(f(x) for x in range(v))
333
bf_tt = BooleanFunctionImproved(tt)
334
bf_tt_index = boolean_function_bijection.index_append(bf_tt)
335
boolean_function_index_matrix[c - c_start, b] = bf_tt_index
336
337
bf_etc = BooleanFunctionGeneralLinearClass(tt)
338
glc_index = general_linear_class_list.index_append(bf_etc)
339
general_linear_class_index_matrix[c - c_start, b] = glc_index
340
341
if checking:
342
pass
343
boolean_function_bijection.sync()
344
345
# Retain the list part of boolean_function_bijection, and
346
# close and remove the dict part.
347
boolean_function_list = boolean_function_bijection.get_list()
348
boolean_function_bijection.close_dict()
349
boolean_function_bijection.remove_dict()
350
351
if checking:
352
pass
353
354
if timing:
355
print(datetime.now())
356
stdout.flush()
357
358
return cls(
359
algebraic_normal_form=algebraic_normal_form,
360
boolean_function_index_matrix=boolean_function_index_matrix,
361
boolean_function_list=boolean_function_list,
362
general_linear_class_index_matrix=general_linear_class_index_matrix,
363
general_linear_class_list=general_linear_class_list,
364
c_start=c_start)
365
366
367
def __eq__(self, other):
368
"""
369
Test for equality between partial classifications.
370
371
WARNING:
372
373
This test is for strict equality rather than mathematical equivalence.
374
375
INPUT:
376
377
- ``other`` - BooleanFunctionExtendedTranslateClassPart: another partial classification.
378
379
OUTPUT:
380
381
A Boolean value indicating whether ``self`` strictly equals ``other``.
382
383
EXAMPLES:
384
385
::
386
387
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
388
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
389
....: BooleanFunctionExtendedTranslateClassPart as BooleanFunctionETCPart)
390
sage: R2.<x0,x1> = BooleanPolynomialRing(2)
391
sage: p = x0*x1
392
sage: f1 = BooleanFunctionImproved(p)
393
sage: c1 = BooleanFunctionETCPart.from_function(f1, c_stop=1)
394
sage: f2 = BooleanFunctionImproved([0,0,0,1])
395
sage: c2 = BooleanFunctionETCPart.from_function(f2, c_stop=1)
396
sage: print(c2.algebraic_normal_form)
397
x0*x1
398
sage: print(c1 == c2)
399
True
400
"""
401
if other is None:
402
return False
403
return (
404
self.algebraic_normal_form == other.algebraic_normal_form and
405
self.boolean_function_list == other.boolean_function_list and
406
self.boolean_function_index_matrix == other.boolean_function_index_matrix and
407
self.general_linear_class_list == other.general_linear_class_list and
408
self.general_linear_class_index_matrix == other.general_linear_class_index_matrix and
409
self.c_start == other.c_start)
410
411
412
class BooleanFunctionExtendedTranslateClassification(BooleanFunctionExtendedTranslateClassPart):
413
r"""
414
Classification of the Cayley graphs within the
415
extended translation equivalence class of a boolean function.
416
417
EXAMPLES:
418
419
::
420
421
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
422
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
423
....: BooleanFunctionExtendedTranslateClassification as BooleanFunctionETC)
424
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
425
sage: p = x1+x2+x1*x2
426
sage: f = BooleanFunctionImproved(p)
427
sage: c1 = BooleanFunctionETC.from_function(f)
428
sage: print(c1)
429
BooleanFunctionExtendedTranslateClassification.from_function(BooleanFunctionImproved(x0*x1 + x0 + x1))
430
sage: latex(c1)
431
\text{\texttt{BooleanFunctionExtendedTranslateClassification.from{\char`\_}function(BooleanFunctionImproved(x0*x1{ }+{ }x0{ }+{ }x1))}}
432
"""
433
434
# Suffixes used by from_csv() and save_as_csv().
435
bent_function_csv_suffix = "_bent_function.csv"
436
cg_class_list_csv_suffix = "_cg_class_list.csv"
437
matrices_csv_suffix = "_matrices.csv"
438
439
440
def __init__(self, *args, **kwargs):
441
r"""
442
Constructor from an object or from class attributes.
443
444
INPUT:
445
446
- ``sobj`` -- BooleanFunctionExtendedTranslateClassification: object to copy.
447
448
- ``algebraic_normal_form`` -- a polynomial of the type
449
returned by ``BooleanFunction.algebraic_normal_form()``,
450
representing the ``BooleanFunctionImproved`` whose classification this is.
451
- ``boolean_function_index_matrix`` -- a ``Matrix` of integers,
452
which are indices into ``boolean_function_list`` representing the
453
distinct boolean functions.
454
- ``boolean_function_list`` -- a list of boolean functions.
455
- ``general_linear_class_index_matrix`` -- a ``Matrix` of integers,
456
which are indices into ``general_linear_class_list`` representing the
457
general linear equivalence classes.
458
- ``general_linear_class_list`` -- a list of matrices representing the
459
general linear equivalence classes.
460
461
OUTPUT:
462
463
None.
464
465
EFFECT:
466
467
The current object ``self`` is initialized as follows.
468
469
Each of
470
- ``algebraic_normal_form``
471
- ``boolean_function_index_matrix``
472
- ``boolean_function_list``
473
- ``general_linear_class_index_matrix``
474
- ``general_linear_class_list``
475
is set to the corresponding input parameter.
476
477
EXAMPLES:
478
479
The classification of the boolean function defined by the polynomial
480
:math:`x_1 + x_2 + x_1 x_2` is copied from `c1` to `c2`.
481
482
::
483
484
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
485
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
486
....: BooleanFunctionExtendedTranslateClassification as BooleanFunctionETC)
487
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
488
sage: p = x1+x2+x1*x2
489
sage: f = BooleanFunctionImproved(p)
490
sage: c1 = BooleanFunctionETC.from_function(f)
491
sage: c2 = BooleanFunctionETC(c1)
492
sage: print(c1 == c2)
493
True
494
"""
495
try:
496
sobj = args[0]
497
self.algebraic_normal_form=sobj.algebraic_normal_form
498
self.boolean_function_index_matrix=sobj.boolean_function_index_matrix
499
self.boolean_function_list=sobj.boolean_function_list
500
self.general_linear_class_index_matrix=sobj.general_linear_class_index_matrix
501
self.general_linear_class_list=sobj.general_linear_class_list
502
except:
503
self.algebraic_normal_form = kwargs.pop(
504
'algebraic_normal_form')
505
self.boolean_function_index_matrix = kwargs.pop(
506
'boolean_function_index_matrix')
507
self.boolean_function_list = kwargs.pop(
508
'boolean_function_list')
509
self.general_linear_class_index_matrix = kwargs.pop(
510
'general_linear_class_index_matrix')
511
self.general_linear_class_list = kwargs.pop(
512
'general_linear_class_list')
513
514
515
def _repr_(self):
516
r"""
517
Sage string representation.
518
519
INPUT:
520
521
- ``self`` -- the current object.
522
523
EXAMPLES:
524
525
::
526
527
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
528
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
529
....: BooleanFunctionExtendedTranslateClassification as BooleanFunctionETC)
530
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
531
sage: p = x1+x2+x1*x2
532
sage: f = BooleanFunctionImproved(p)
533
sage: c1 = BooleanFunctionETC.from_function(f)
534
sage: print(c1)
535
BooleanFunctionExtendedTranslateClassification.from_function(BooleanFunctionImproved(x0*x1 + x0 + x1))
536
"""
537
return (
538
type(self).__name__ +
539
".from_function(BooleanFunctionImproved(" +
540
repr(self.algebraic_normal_form) +
541
"))")
542
543
544
@classmethod
545
def from_function(
546
cls,
547
boolf,
548
list_dual_graphs=True,
549
limited_memory=False):
550
r"""
551
Constructor from the ``BooleanFunctionImproved`` ``boolf``.
552
553
INPUT:
554
555
- ``boolf`` -- an object of class ``BooleanFunctionImproved``.
556
- ``list_dual_graphs`` -- boolean. a flag indicating
557
whether to list dual graphs.
558
- ``limited_memory`` -- boolean. A flag indicating
559
whether the classification might be too large
560
to fit into memory. Default is False.
561
562
OUTPUT:
563
564
An object of class BooleanFunctionExtendedTranslateClassification,
565
initialized as follows.
566
567
- ``algebraic_normal_form`` is set to ``boolf.algebraic_normal_form()``,
568
- ``boolean_function_index_matrix`` -- a ``Matrix` of integers,
569
which are indices into ``boolean_function_list`` representing the
570
distinct boolean functions.
571
- ``boolean_function_list`` -- a list of boolean functions.
572
- ``general_linear_class_index_matrix`` -- a ``Matrix` of integers,
573
which are indices into ``general_linear_class_list`` representing the
574
general linear equivalence classes.
575
- ``general_linear_class_list`` -- a list of matrices representing the
576
general linear equivalence classes.
577
578
Each entry ``boolean_function_index_matrix[c,b]`` corresponds to
579
the Cayley graph of the boolean function
580
:math:`x \mapsto \mathtt{boolf}(x+b) + \langle c, x \rangle + \mathtt{boolf}(b)`.
581
This enumerates all of the extended translates of ``boolf``.
582
583
EXAMPLES:
584
585
The classification of the boolean function defined by the polynomial
586
:math:`x_1 + x_2 + x_1 x_2`.
587
588
::
589
590
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
591
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
592
....: BooleanFunctionExtendedTranslateClassification as BooleanFunctionETC)
593
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
594
sage: p = x1+x2+x1*x2
595
sage: f = BooleanFunctionImproved(p)
596
sage: c3 = BooleanFunctionETC.from_function(f)
597
sage: dict(sorted(c3.__dict__.items()))
598
{'algebraic_normal_form': x0*x1 + x0 + x1,
599
'boolean_function_index_matrix': [0 2 1 3]
600
[1 3 0 2]
601
[2 0 3 1]
602
[3 1 2 0],
603
'boolean_function_list': [Boolean function with 2 variables,
604
Boolean function with 2 variables,
605
Boolean function with 2 variables,
606
Boolean function with 2 variables],
607
'general_linear_class_index_matrix': [0 1 1 1]
608
[1 1 0 1]
609
[1 0 1 1]
610
[1 1 1 0],
611
'general_linear_class_list': [Boolean function with 2 variables,
612
Boolean function with 2 variables]}
613
614
TESTS:
615
616
The classification of the boolean function defined by the polynomial
617
:math:`x_1 + x_2 + x_1 x_2`, but with list_dual_graphs=False.
618
619
::
620
621
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
622
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
623
....: BooleanFunctionExtendedTranslateClassification as BooleanFunctionETC)
624
sage: R2.<x1,x2> = BooleanPolynomialRing(2)
625
sage: p = x1+x2+x1*x2
626
sage: f = BooleanFunctionImproved(p)
627
sage: c4 = BooleanFunctionETC.from_function(f,list_dual_graphs=False)
628
sage: dict(sorted(c4.__dict__.items()))
629
{'algebraic_normal_form': x0*x1 + x0 + x1,
630
'boolean_function_index_matrix': [0 2 1 3]
631
[1 3 0 2]
632
[2 0 3 1]
633
[3 1 2 0],
634
'boolean_function_list': [Boolean function with 2 variables,
635
Boolean function with 2 variables,
636
Boolean function with 2 variables,
637
Boolean function with 2 variables],
638
'general_linear_class_index_matrix': [0 1 1 1]
639
[1 1 0 1]
640
[1 0 1 1]
641
[1 1 1 0],
642
'general_linear_class_list': [Boolean function with 2 variables,
643
Boolean function with 2 variables]}
644
"""
645
cp = BooleanFunctionExtendedTranslateClassPart.from_function(
646
boolf,
647
limited_memory=limited_memory)
648
return cls(cp)
649
650
651
def __eq__(self, other):
652
"""
653
Test for equality between classifications.
654
655
WARNING:
656
657
This test is for strict equality rather than mathematical equivalence.
658
659
INPUT:
660
661
- ``other`` - BooleanFunctionExtendedTranslateClassification: another classification.
662
663
OUTPUT:
664
665
A Boolean value indicating whether ``self`` strictly equals ``other``.
666
667
EXAMPLES:
668
669
::
670
671
sage: from boolean_cayley_graphs.boolean_function_improved import BooleanFunctionImproved
672
sage: from boolean_cayley_graphs.boolean_function_extended_translate_classification import (
673
....: BooleanFunctionExtendedTranslateClassification as BooleanFunctionETC)
674
sage: R2.<x0,x1> = BooleanPolynomialRing(2)
675
sage: p = x0*x1
676
sage: f1 = BooleanFunctionImproved(p)
677
sage: c1 = BooleanFunctionETC.from_function(f1)
678
sage: f2 = BooleanFunctionImproved([0,0,0,1])
679
sage: c2 = BooleanFunctionETC.from_function(f2)
680
sage: print(c2.algebraic_normal_form)
681
x0*x1
682
sage: print(c1 == c2)
683
True
684
"""
685
if other is None:
686
return False
687
return (
688
self.algebraic_normal_form == other.algebraic_normal_form and
689
self.boolean_function_index_matrix == other.boolean_function_index_matrix and
690
self.boolean_function_list == other.boolean_function_list and
691
self.general_linear_class_index_matrix == other.general_linear_class_index_matrix and
692
self.general_linear_class_list == other.general_linear_class_list)
693
694