-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoolForge_Tutorials.tex
More file actions
5595 lines (4558 loc) · 178 KB
/
BoolForge_Tutorials.tex
File metadata and controls
5595 lines (4558 loc) · 178 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\documentclass[
]{article}
\usepackage{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amssymb}
\setcounter{secnumdepth}{5}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math} % this also loads fontspec
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
% xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{longtable,booktabs,array}
\newcounter{none} % for unnumbered tables
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\newsavebox\pandoc@box
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
\sbox\pandoc@box{#1}%
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
\else\usebox{\pandoc@box}%
\fi%
}
% Set default figure placement to htbp
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\usepackage[]{natbib}
\bibliographystyle{plainnat}
\usepackage{graphicx}
\usepackage{float}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{caption}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{url}
\usepackage{etoolbox}
\usepackage{natbib}
\renewcommand{\refname}{}
\renewcommand{\bibname}{}
% --- Title handling ---
\title{$title$}
\author{$author$}
\date{$date$}
\AtBeginDocument{
\maketitle
%\tableofcontents
\clearpage
}
% --- allow alt= ---
\makeatletter
\define@key{Gin}{alt}{}
\makeatother
% --- scale figures ---
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\makeatother
\setkeys{Gin}{width=\maxwidth,height=0.8\textheight,keepaspectratio}
% --- syntax highlighting (arXiv-safe) ---
\lstdefinelanguage{Python}{
keywords={def, return, if, else, elif, for, while, import, from, as, class, try, except, raise, with, lambda, yield, True, False, None},
keywordstyle=\color{blue}\bfseries,
comment=[l]{\#},
commentstyle=\color{gray}\itshape,
stringstyle=\color{red},
morestring=[b]',
morestring=[b]",
}
\lstset{
language=Python,
basicstyle=\ttfamily\small,
keywordstyle=\color{blue}\bfseries,
commentstyle=\color{gray}\itshape,
stringstyle=\color{red},
breaklines=true,
frame=single,
showstringspaces=false,
columns=fullflexible,
keepspaces=true
}
% --- new page per section ---
%\pretocmd{\section}{\clearpage}{}{}
\makeatletter
\pretocmd{\section}{%
\ifnum\pdfstrcmp{\@currentlabelname}{References}=0
% do nothing
\else
\clearpage
\fi
}{}{}
\makeatother
% --- nicer captions ---
\captionsetup{
font=small,
labelfont=bf
}
% --- FIX bold-text bug ---
\normalfont
\renewcommand{\familydefault}{\rmdefault}
\usepackage{bookmark}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
hidelinks,
pdfcreator={LaTeX via pandoc}}
\title{Boolean Network Modeling in Systems Biology: A Hands-On Tutorial with BoolForge}
\author{Claus Kadelka}
\date{March 31, 2026}
\begin{document}
\maketitle
{
\setcounter{tocdepth}{3}
\tableofcontents
}
\section*{Abstract}\label{abstract}
\addcontentsline{toc}{section}{Abstract}
Boolean networks are a widely used modeling framework for studying
complex dynamical systems in systems biology, including gene regulatory
and signaling networks. Despite their conceptual simplicity, practical
challenges -- such as constructing biologically meaningful models,
analyzing dynamical behavior, and generating appropriate null models --
often limit their accessibility, reproducibility, and systematic use.
We present a comprehensive, hands-on tutorial to Boolean network
modeling and analysis, accompanied by the Python package BoolForge. This
tutorial is designed for researchers and students with diverse
backgrounds and provides a step-by-step introduction ranging from basic
concepts to advanced topics. Covered topics include Boolean functions
and their representations, canalization, random function generation
under structural constraints, construction of Boolean networks and
wiring diagrams, synchronous and asynchronous dynamics, attractor and
basin analysis, robustness and coherence measures, and the generation of
controlled null models for hypothesis testing.
Emphasis is placed on reproducible computational workflows and the
systematic investigation of structure--dynamics relationships. Through a
series of progressively developed examples and executable code snippets,
readers learn how to construct, analyze, and interpret Boolean network
models, as well as how to generate ensembles of randomized networks that
preserve key structural features such as degree distribution, bias, and
canalizing depth. Code and tutorials are openly available at
\url{https://github.com/ckadelka/BoolForge}.
This tutorial serves both as a practical introduction for new users and
as a reference for advanced researchers seeking to apply Boolean network
methods in systems biology. By integrating theory, algorithms, and
software implementation, it aims to facilitate the adoption of rigorous
and reproducible modeling practices in the study of complex biological
systems.
\section*{Preface}\label{preface}
\addcontentsline{toc}{section}{Preface}
This tutorial is designed as a hands-on, computational introduction to
Boolean network modeling using BoolForge.
Rather than focusing purely on theory, we emphasize executable workflows
and reproducible experiments. The goal is to enable readers to explore
structure-dynamics relationships directly through code.
To illustrate the type of analyses enabled by BoolForge, we begin with a
simple example reproducing Derrida's classical phase transition (see
\citet{derrida1986random}) in a few lines of BoolForge code.
\begin{lstlisting}
import boolforge as bf
import matplotlib.pyplot as plt
N = 100 # network size
ks = range(1,5) # constant in-degree
n_networks = 50 # ensemble size
p = 0.5 # bias p: probability of ones in truth table
derrida_values = []
for k in ks:
derrida_values.append([])
for _ in range(n_networks):
bn = bf.random_network(N, k, bias = p, allow_degenerate_functions=True)
derrida_values[-1].append( bn.get_derrida_value(exact=True) )
plt.boxplot(derrida_values, positions=list(ks))
plt.axhline(1, linestyle="--", color="gray", label="critical value")
plt.plot(ks, [2*k*p*(1-p) for k in ks], "o-", label=r"$2kp(1-p)$ (annealed theory)")
plt.xlabel("Constant in-degree k")
plt.ylabel("Derrida value")
plt.legend(frameon=False);
\end{lstlisting}
\pandocbounded{\includegraphics[keepaspectratio]{figures/tutorial00_preface_tex_fig0.png}}
The Derrida value measures the average number of nodes affected by a
single-bit random perturbation after one synchronous update of the
network.
\subsection*{Structure of the
tutorials}\label{structure-of-the-tutorials}
\addcontentsline{toc}{subsection}{Structure of the tutorials}
The tutorials gradually introduce the main concepts and tools provided
by BoolForge, moving from individual Boolean functions to full Boolean
network models and their dynamical analysis.
\begin{itemize}
\tightlist
\item
\emph{Boolean functions:} representation and structural analysis
\item
\emph{Canalization:} redundancy and robustness of regulatory rules
\item
\emph{Random function generation:} sampling functions with prescribed
properties
\item
\emph{Boolean networks:} construction and wiring diagrams
\item
\emph{Network dynamics:} attractors and state transition graphs
\item
\emph{Stability and robustness:} sensitivity to perturbations
\item
\emph{Random network ensembles:} statistical analysis of network
dynamics
\item
\emph{Biological models:} analysis of curated regulatory networks
\end{itemize}
Each tutorial contains executable code examples illustrating how these
ideas can be explored using BoolForge. Corresponding Jupyter notebook
(ipynb) files can be found at
\url{https://github.com/ckadelka/BoolForge/tree/main/tutorials}. Readers
are encouraged to run the code cells and modify the examples to explore
their own Boolean functions and networks.
\section*{Introduction}\label{introduction}
\addcontentsline{toc}{section}{Introduction}
Boolean networks have emerged as a central modeling framework for
studying complex dynamical systems in systems biology, including gene
regulatory, signaling, and cellular decision-making networks
\citep{kauffman1969metabolic}. In a Boolean network, each component is
represented by a binary variable, and its dynamics are governed by
logical update rules that capture regulatory interactions. Despite their
conceptual simplicity, Boolean networks are capable of reproducing rich
dynamical behavior such as multistability, oscillations, and robustness
to perturbations, making them a widely used tool for qualitative
modeling when detailed kinetic information is unavailable.
Over the past decades, Boolean network models have been successfully
applied to a broad range of biological systems, from cell cycle
regulation to developmental processes and disease-related signaling
pathways. At the same time, theoretical advances have deepened our
understanding of how structural properties---such as network topology,
regulatory logic, and canalization---shape dynamical behavior. In
particular, concepts such as attractors, basins of attraction,
robustness, and sensitivity have become standard tools for analyzing the
long-term behavior of these systems.
However, despite this progress, practical challenges remain.
Constructing biologically meaningful Boolean network models, analyzing
their dynamics, and interpreting results in a reproducible and
systematic way can be difficult, especially for researchers new to the
field. Moreover, many commonly used approaches rely on ad hoc
randomization or lack appropriate null models, making it challenging to
disentangle the effects of network structure from those of the update
rules. As a result, there is a growing need for tools and tutorials that
integrate theoretical concepts with practical, reproducible workflows.
This tutorial addresses these challenges by providing a comprehensive,
hands-on introduction to Boolean network modeling and analysis,
accompanied by the Python package BoolForge. The goal is to bridge the
gap between theory and practice by guiding the reader from fundamental
concepts to advanced applications, with an emphasis on reproducibility,
clarity, and methodological rigor.
We begin by introducing Boolean functions and their representations,
including truth tables and logical expressions, and discuss key
structural properties such as bias, essential variables, and
canalization. We then present methods for generating random Boolean
functions under structural constraints, including \(k\)-canalizing
functions and nested canalizing functions, which play a central role in
biological modeling. Building on these foundations, we introduce Boolean
networks and wiring diagrams, and demonstrate how to construct and
manipulate models programmatically.
A central focus of this tutorial is the analysis of network dynamics. We
cover both synchronous and asynchronous update schemes, and describe
methods for identifying attractors, computing basins of attraction, and
quantifying dynamical properties such as robustness, fragility, and
coherence. In addition, we emphasize the importance of ensemble-based
approaches and controlled null models, which allow systematic
investigation of how structural features---such as degree distribution,
bias, and canalizing depth---affect network behavior.
Throughout the tutorial, we provide executable code examples and
reproducible workflows that enable readers to directly apply the
presented methods to their own research questions. By integrating
theory, algorithms, and software implementation, this tutorial aims to
make Boolean network modeling more accessible, transparent, and
rigorous.
This document is intended for a broad audience, including students,
experimentalists, and computational researchers. Readers new to Boolean
networks will find a step-by-step introduction to the key concepts and
methods, while more experienced users may use this tutorial as a
reference for advanced topics such as constrained random function
generation and null model construction.
\subsection*{Positioning within the
literature}\label{positioning-within-the-literature}
\addcontentsline{toc}{subsection}{Positioning within the literature}
While numerous introductions to Boolean networks exist, they are often
fragmented across textbooks, review articles, and software-specific
documentation, and typically emphasize either theoretical aspects or
particular applications. In contrast, this tutorial provides a unified,
end-to-end treatment that integrates structural theory, dynamical
analysis, and reproducible computational workflows within a single
framework. A distinguishing feature is the systematic treatment of
constrained random function and network generation, including
canalization-controlled ensembles and null models that preserve key
structural properties. This enables rigorous investigation of
structure--dynamics relationships beyond traditional random network
paradigms. By combining these methodological advances with practical
implementation in BoolForge, this work is positioned not merely as an
introduction, but as a comprehensive reference for modern Boolean
network analysis in systems biology.
\textbf{Citation note}. If you use BoolForge in your research, please
cite the accompanying software paper \citep{kadelka2025boolforge}. If
this tutorial contributed to your modeling, analysis, or interpretation,
please cite this work.
\section{Working with Boolean
Functions}\label{working-with-boolean-functions}
Boolean functions are the building blocks of Boolean network models used
to represent gene regulatory networks, signaling pathways, and other
biological control systems. Understanding how to create and analyze
individual Boolean functions is essential before studying network-level
dynamics.
In this tutorial, we explore the \texttt{BooleanFunction} class --- the
foundation of BoolForge. Boolean functions form the regulatory rules in
Boolean network models of gene regulation, so understanding their
structure is essential before studying networks.
\subsection{What you will learn}\label{what-you-will-learn}
In this tutorial you will:
\begin{itemize}
\tightlist
\item
create Boolean functions from truth tables and from textual
expressions,
\item
inspect core attributes such as degree, variable names, and stored
properties,
\item
compute basic structural properties (essential variables, Hamming
weight, bias),
\item
convert Boolean functions into logical and polynomial representations,
\item
and interface with CANA objects.
\end{itemize}
\subsection{Setup}\label{setup}
\begin{lstlisting}
import boolforge as bf
\end{lstlisting}
\subsection{Create a Boolean function}\label{create-a-boolean-function}
Boolean functions can be described in logical form, as polynomials, or
as truth tables. BoolForge treats Boolean functions as binary vectors of
length \(2^n\), where \(n\) is the number of inputs. The vectors
describe the \emph{right side} of the truth table. The left side of the
truth table is not stored because it is the same for any function with n
inputs. For example, the function \[
f(A,B) = A \land B
\] is stored as \texttt{{[}0,\ 0,\ 0,\ 1{]}}, corresponding to:
{\def\LTcaptype{none} % do not increment counter
\begin{longtable}[]{@{}ccc@{}}
\toprule\noalign{}
A & B & f(A,B) \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
0 & 0 & 0 \\
0 & 1 & 0 \\
1 & 0 & 0 \\
1 & 1 & 1 \\
\end{longtable}
}
\subsubsection{Create Boolean functions from a truth
table}\label{create-boolean-functions-from-a-truth-table}
A \texttt{BooleanFunction} object can be generated by specifying the
right side of the truth table, i.e., by providing a binary vector of
length \(2^n\) for any \(n\geq 0\). For example, to create the AND
function above, we can write
\begin{lstlisting}
f = bf.BooleanFunction([0, 0, 0, 1], name="f_AND") #name is optional
print("f:", f)
print("Truth table of f:\n", f.to_truth_table().to_string())
\end{lstlisting}
\begin{lstlisting}
f: [0 0 0 1]
Truth table of f:
x0 x1 f_AND
0 0 0 0
1 0 1 0
2 1 0 0
3 1 1 1
\end{lstlisting}
Any Boolean function is stored as right side of the truth table. That
is, the outputs are ordered by the binary representation of inputs:
\begin{itemize}
\tightlist
\item
Position 0 --\textgreater{} (A,B) = (0,0)
\item
Position 1 --\textgreater{} (A,B) = (0,1)
\item
Position 2 --\textgreater{} (A,B) = (1,0)
\item
Position 3 --\textgreater{} (A,B) = (1,1)
\end{itemize}
\subsubsection{Create Boolean functions from
text}\label{create-boolean-functions-from-text}
Boolean functions can also be created from textual expressions. For
example, to define the same function as f, we can write
\begin{lstlisting}
f2 = bf.BooleanFunction("A and B")
print("f2:", f2)
\end{lstlisting}
\begin{lstlisting}
f2: [0 0 0 1]
\end{lstlisting}
The text processor is fairly versatile. For example, we can define the
same function as f also by writing
\begin{lstlisting}
f3 = bf.BooleanFunction("A + B > 1")
print("f3:", f3)
\end{lstlisting}
\begin{lstlisting}
f3: [0 0 0 1]
\end{lstlisting}
Some examples of more complicated functions include:
\begin{lstlisting}
g = bf.BooleanFunction("(A AND B) OR (NOT A AND C)")
h = bf.BooleanFunction("(x + y + z) % 2 == 0")
k = bf.BooleanFunction("(-1) * x + y + z > 0")
labels = ["g", "h", "k"]
bf.display_truth_table(g, h, k, labels=labels)
\end{lstlisting}
\begin{lstlisting}
x0 x1 x2 | g h k
-------------------------------------------------
0 0 0 | 0 1 0
0 0 1 | 1 0 1
0 1 0 | 0 0 1
0 1 1 | 1 1 1
1 0 0 | 0 0 0
1 0 1 | 0 1 0
1 1 0 | 1 1 0
1 1 1 | 1 0 1
\end{lstlisting}
\subsubsection{Combining BooleanFunction
objects}\label{combining-booleanfunction-objects}
New Boolean functions can be constructed by combining existing ones
using Boolean algebra operations. This is useful when building larger
rules from simpler components.
Supported operations include:
\begin{itemize}
\tightlist
\item
\texttt{\textasciitilde{}} NOT
\item
\texttt{\&} AND
\item
\texttt{\textbar{}} OR
\item
\texttt{\^{}} XOR
\end{itemize}
\begin{lstlisting}
a = bf.BooleanFunction("X + Y == 1")
b = bf.BooleanFunction("X OR Y")
not_a = ~a
a_and_b = a & b
a_or_b = a | b
a_xor_b = a ^ b
labels = ["a", "b", "~a", "a&b", "a|b", "a^b"]
bf.display_truth_table(a, b, not_a, a_and_b, a_or_b, a_xor_b, labels=labels)
\end{lstlisting}
\begin{lstlisting}
x0 x1 | a b ~a a&b a|b a^b
-------------------------------------------------------------------
0 0 | 0 0 1 0 0 0
0 1 | 1 1 0 1 1 0
1 0 | 1 1 0 1 1 0
1 1 | 0 1 1 0 1 1
\end{lstlisting}
\subsection{Attributes of
BooleanFunction}\label{attributes-of-booleanfunction}
Each \texttt{BooleanFunction} object has the following attributes:
{\def\LTcaptype{none} % do not increment counter
\begin{longtable}[]{@{}lll@{}}
\toprule\noalign{}
attribute & type & description \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
\texttt{f} & \texttt{np.ndarray} & truth table (right side) \\
\texttt{n} & \texttt{int} & number of variables \\
\texttt{variables} & \texttt{np.ndarray} & variable names \\
\texttt{name} & \texttt{str} & optional name \\
\texttt{properties} & \texttt{dict} & cached properties \\
\end{longtable}
}
\begin{lstlisting}
print("f.f:", f.f)
print("f.n:", f.n)
print("f.variables:", f.variables)
print("f.name:", f.name)
print("f.properties:", f.properties)
\end{lstlisting}
\begin{lstlisting}
f.f: [0 0 0 1]
f.n: 2
f.variables: ['x0' 'x1']
f.name: f_AND
f.properties: {}
\end{lstlisting}
When a function is created from a truth table, variable names default to
\texttt{x0,\ x1,\ ...}. When created from text, variable names are
inferred.
\begin{lstlisting}
print("f2.variables:", f2.variables)
print("f3.variables:", f3.variables)
print("g.variables:", g.variables)
print("h.variables:", h.variables)
\end{lstlisting}
\begin{lstlisting}
f2.variables: ['A' 'B']
f3.variables: ['A' 'B']
g.variables: ['A' 'B' 'C']
h.variables: ['x' 'y' 'z']
\end{lstlisting}
The variable order is determined by first occurrence in the expression.
See e.g.,
\begin{lstlisting}
print(bf.BooleanFunction("(x + y + z) % 2 == 0").variables)
print(bf.BooleanFunction("(y + z + x) % 2 == 0").variables)
\end{lstlisting}
\begin{lstlisting}
['x' 'y' 'z']
['y' 'z' 'x']
\end{lstlisting}
The variable order determines how the truth table is indexed. For
example, if variables are sorted as {[}x,y,z{]}, the entry in position i
corresponds to the binary expansion of i over (x,y,z). E.g., row \(i=4\)
corresponds to \(x=1,y=0,z=0\). Therefore, the same expression with a
different variable order results in a different truth table ordering.
This becomes important when combining functions inside networks or
importing networks from text files. That said, it is all handled
internally by BoolForge.
\subsection{Basic properties of Boolean
functions}\label{basic-properties-of-boolean-functions}
We can inspect various properties of a Boolean function. The degree,
i.e., the number of inputs, is readily available via `f.n'. Other
properties can be computed.
\begin{itemize}
\tightlist
\item
`is\_constant()' checks if the function is constant,
\item
`is\_degenerate()' checks if the function contains non-essential
variables,
\item
`get\_essential\_variables()' provides the indices (Python: starting
at 0!) of the essential variables,
\item
`get\_type\_of\_inputs()' describes the type of each input
(`positive', `negative', `conditional', or `non-essential').
\item
The Hamming weight is the number of 1s in the right side of the truth
table.
\item
The bias is \(\text{\#ones} / 2^n\). It equals 0.5 for unbiased
functions.
\item
The absolute bias is \(|\text{\#ones} - \text{\#zeros}| / 2^n\). It
equals 1 for constant functions and 0 for unbiased functions.
\end{itemize}
\begin{lstlisting}
print("Number of variables:", f.n)
print("Is constant?", f.is_constant())
print("Is degenerate?", f.is_degenerate())
print("Essential variables:", f.get_essential_variables())
print("Type of inputs:", f.get_type_of_inputs())
print("Hamming weight:", f.hamming_weight)
print("Bias:", f.bias)
print("Absolute bias:", f.absolute_bias)
\end{lstlisting}
\begin{lstlisting}
Number of variables: 2
Is constant? False
Is degenerate? False
Essential variables: [0 1]
Type of inputs: ['positive' 'positive']
Hamming weight: 1
Bias: 0.25
Absolute bias: 0.5
\end{lstlisting}
You may repeat this for \texttt{g} and observe how the properties
differ.
Conveniently, the \texttt{.summary()} method prints a human-readable
overview of basic properties.
\begin{lstlisting}
f = bf.BooleanFunction("(A and B) OR NOT C")
print(f.summary())
\end{lstlisting}
\begin{lstlisting}
BooleanFunction
---------------
Number of variables: 3
Hamming Weight: 5
Bias: 0.625
Absolute bias: 0.250
Variables: ['A', 'B', 'C']
\end{lstlisting}
If more advanced properties have already been computed, e.g., by
\texttt{get\_layer\_structure()} or \texttt{get\_type\_of\_inputs()},
they are also displayed. This is also the case if the optional keyword
\texttt{compute\_all} is set to True; default is False to avoid
potentially time-consuming computations.
\begin{lstlisting}
print(f.summary(compute_all=True)) #or simply print(f.summary(True))
\end{lstlisting}
\begin{lstlisting}
BooleanFunction
---------------
Number of variables: 3
Hamming Weight: 5
Bias: 0.625
Absolute bias: 0.250
Variables: ['A', 'B', 'C']
Activities: ['0.250', '0.250', '0.750']
Average sensitivity: 0.417
InputTypes: ['positive' 'positive' 'negative']
CanalizingDepth: 3
NumberOfLayers: 2
CanalizingInputs: [0 0 0]
CanalizedOutputs: [1 0 0]
CoreFunction: [1]
OrderOfCanalizingVariables:[2 0 1]
LayerStructure: [1, 2]
\end{lstlisting}
The more advanced properties displayed here (e.g., all properties
related to canalization) are the subject of later tutorials.
\subsection{Logical and polynomial
representations}\label{logical-and-polynomial-representations}
While Boolean functions are stored as truth tables, they can be
expressed in logical and polynomial format.
\begin{lstlisting}
print(f"Logical form of {f.name}:", f.to_logical(and_op=" \wedge ", or_op=" \vee ", not_op=" \neg"))
print(f"Polynomial form of {f.name}:", f.to_polynomial())
\end{lstlisting}
\begin{lstlisting}
Logical form of : (( \negC)) \vee (A \wedge B)
Polynomial form of : (1 - A) * (1 - B) * (1 - C) + (1 - A) * B * (1 - C) + A * (1 - B) * (1 - C) + A * B * (1 - C) + A * B * C
\end{lstlisting}
In addition, a \texttt{BooleanFunction} object can be turned into
\texttt{BooleanNode} object from the
\href{https://www.github.com/CASCI-lab/CANA}{CANA package}. This
requires the optional \texttt{CANA} package to be installed.
\begin{lstlisting}
cana_object = f.to_cana()
print(type(cana_object))
\end{lstlisting}
\begin{lstlisting}
<class 'cana.boolean_node.BooleanNode'>
\end{lstlisting}
\subsection{Summary}\label{summary}
Before moving on to more advanced topics, here is a short summary of the
fundamental ideas introduced in this tutorial:
\subsubsection{Boolean functions}\label{boolean-functions}
A Boolean function maps a set of binary inputs (0/1) to a single binary
output. BoolForge represents Boolean functions internally by their truth
table, i.e., the list of outputs in lexicographic order of the input
combinations.
\subsubsection{Representations of Boolean
functions}\label{representations-of-boolean-functions}
Boolean functions can be created from:
\begin{itemize}
\tightlist
\item
a truth table (a sequence of 0s and 1s of length \(2^n\) for some
\(n\)),
\item
a logical expression written in Python syntax,
\item
algebraic combinations of existing BooleanFunction objects using
operations such as\\
\texttt{+} (OR), \texttt{*} (AND), \texttt{\^{}} (XOR), and other
supported Boolean operations.
\end{itemize}
Each representation produces an equivalent internal truth-table-based
object.
\subsubsection{Variable names and
ordering}\label{variable-names-and-ordering}
BoolForge automatically infers variable names from the order of first
appearance in expressions.\\
This order determines the indexing of the truth table and therefore
affects how the function interacts with larger Boolean networks.
\subsubsection{Basic properties of Boolean
functions}\label{basic-properties-of-boolean-functions-1}
BoolForge can compute structural properties, including:
\begin{itemize}
\tightlist
\item
the number of variables (\texttt{n}),
\item
the Hamming weight (number of 1s in the truth table),
\item
absolute bias (imbalance between 0s and 1s),
\item
essential and non-essential variables,
\item
positive/negative influence of each input.
\end{itemize}
These properties help characterize the function's behavior and are used
throughout later tutorials.
\subsubsection{Conversions and
interoperability}\label{conversions-and-interoperability}
BoolForge supports conversion between representations (truth table,
polynomial, and logical form) and is compatible with external packages
such as \href{https://www.github.com/CASCI-lab/CANA}{CANA} for advanced
analysis.\\
This makes it easy to move between analytical frameworks and reuse
models.
Together, these concepts provide the foundation for understanding
canalization, random Boolean function generation, and eventually the
construction and analysis of full Boolean networks.
\subsection{Frequently Asked
Questions}\label{frequently-asked-questions}
\subsubsection{Why does the order of variables
matter?}\label{why-does-the-order-of-variables-matter}
The order in which variables appear determines the ordering of the truth
table. For a function with variables \texttt{{[}A,\ B,\ C{]}}, the entry
at position \(i\in\{0,1,\ldots,2^n-1\}\) corresponds to the binary
representation of \(i\) over \texttt{(A,\ B,\ C)}. For example, row 4
(i.e., the fifth row since Python starts indexing at 0) corresponds to
\(A = 1, B = 0, C = 0\).
If two equivalent expressions list variables in different orders, their
truth tables will be indexed differently. See, for example,
\begin{lstlisting}
print(bf.BooleanFunction('A and not B'))
print(bf.BooleanFunction('not B and A'))
\end{lstlisting}
\begin{lstlisting}
[0 0 1 0]
[0 1 0 0]
\end{lstlisting}
To ensure reproducibility, always use consistent variable names and
ordering.
\subsubsection{How do I choose between defining a function via a truth
table or via an
expression?}\label{how-do-i-choose-between-defining-a-function-via-a-truth-table-or-via-an-expression}
Short answer: It does not matter. Both methods produce identical
internal representations.
Slightly longer answer: Use a \emph{textual expression} if:
\begin{itemize}
\tightlist
\item
you know the natural logical description of your function (e.g.,
\texttt{A\ and\ B}),
\item
the function is part of a Boolean network stored in some text file.
\end{itemize}
Use a \emph{truth table} if:
\begin{itemize}
\tightlist
\item
you generated the table programmatically (e.g., using
\texttt{bf.random\_function}).
\end{itemize}
\subsubsection{\texorpdfstring{What is the difference between
\texttt{get\_type\_of\_inputs()} and
monotonicity?}{What is the difference between get\_type\_of\_inputs() and monotonicity?}}\label{what-is-the-difference-between-get_type_of_inputs-and-monotonicity}
The method \texttt{get\_type\_of\_inputs()} classifies each input
variable individually, i.e., it describes how an increase in the
variable can affect the function output:
\begin{itemize}
\tightlist
\item
positive: the function value increases at least sometimes but never
decreases,
\item
negative: the function value decreases at least sometimes but never
increases,
\item
conditional: both positive and negative,
\item
non-essential: the function value never changes.
\end{itemize}
Monotonicity, by contrast, is a \emph{global property} of the Boolean
function. A function is monotone if \emph{none} of its essential
variables are conditional.
A function can therefore be non-monotone even if some individual inputs
affect it in a monotone manner.
\subsubsection{Quick Reference}\label{quick-reference}
{\def\LTcaptype{none} % do not increment counter
\begin{longtable}[]{@{}ll@{}}
\toprule\noalign{}
Task & Example \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
Create from truth table &
\texttt{BooleanFunction({[}0,\ 0,\ 0,\ 1{]})} \\
Create from expression & \texttt{BooleanFunction("A\ and\ B")} \\
Combine with operations &
\texttt{f\ \&\ g,\ f\ \textbackslash{}\textbar{}\ g,\ \textasciitilde{}f,\ f\ \^{}\ g} \\
Check properties & \texttt{f.n}, \texttt{f.is\_constant()},
\texttt{f.is\_degenerate()} \\
Get variable names & \texttt{f.variables} \\
Convert representations & \texttt{f.to\_logical()},
\texttt{f.to\_polynomial()} \\
\end{longtable}
}
\section{Advanced Concepts for Boolean
Functions}\label{advanced-concepts-for-boolean-functions}
Understanding the structure of a Boolean function is essential for
analyzing the behavior of the Boolean networks they define. In this
tutorial, we move beyond the basics of \texttt{BooleanFunction} and
explore three core concepts:
\begin{itemize}
\tightlist