Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 19204
1
r"""
2
Cayley graph of a Boolean function
3
==================================
4
5
The ``boolean_cayley_graph`` module defines
6
a function that contructs the Cayley graph of a Boolean function.
7
8
AUTHORS:
9
10
- Paul Leopardi (2016-08-21): initial version
11
12
EXAMPLES:
13
14
::
15
16
sage: from boolean_cayley_graphs.boolean_cayley_graph import boolean_cayley_graph
17
sage: f = lambda n: (n // 2) % 2
18
sage: [f(i) for i in range(4)]
19
[0, 0, 1, 1]
20
sage: g = boolean_cayley_graph(2, f)
21
sage: g.adjacency_matrix()
22
[0 0 1 1]
23
[0 0 1 1]
24
[1 1 0 0]
25
[1 1 0 0]
26
27
REFERENCES:
28
29
Bernasconi and Codenotti [BC1999]_.
30
"""
31
#*****************************************************************************
32
# Copyright (C) 2016-2017 Paul Leopardi [email protected]
33
#
34
# Distributed under the terms of the GNU General Public License (GPL)
35
# as published by the Free Software Foundation; either version 2 of
36
# the License, or (at your option) any later version.
37
# http://www.gnu.org/licenses/
38
#*****************************************************************************
39
40
41
from sage.graphs.graph import Graph
42
43
44
def boolean_cayley_graph(dim, f):
45
r"""
46
Construct the Cayley graph of a Boolean function.
47
48
Given the non-negative integer ``dim`` and the function ``f``,
49
a Boolean function that takes a non-negative integer argument,
50
the function ``Boolean_Cayley_graph`` constructs the Cayley graph of ``f``
51
as a Boolean function on :math:`\mathbb{F}_2^{dim}`,
52
with the lexicographica ordering.
53
The value ``f(0)`` is assumed to be ``0``, so the graph is always simple.
54
55
INPUT:
56
57
- ``dim`` -- integer. The Boolean dimension of the given function.
58
- ``f`` -- function. A Boolean function expressed as a Python function
59
taking non-negative integer arguments.
60
61
OUTPUT:
62
63
A ``Graph`` object representing the Cayley graph of ``f``.
64
65
.. SEEALSO:
66
:module:`sage.graphs.graph`
67
68
EXAMPLES:
69
70
The Cayley graph of the function ``f`` where :math:`f(n) = n \mod 2`.
71
72
::
73
74
sage: from boolean_cayley_graphs.boolean_cayley_graph import boolean_cayley_graph
75
sage: f = lambda n: n % 2
76
sage: g = boolean_cayley_graph(2, f)
77
sage: g.adjacency_matrix()
78
[0 1 0 1]
79
[1 0 1 0]
80
[0 1 0 1]
81
[1 0 1 0]
82
83
"""
84
return Graph([range(2 ** dim), lambda i, j: f(i ^ j)],
85
format="rule",
86
immutable=True)
87
88