Skip to main content

pyFunctionHood: local computation of immediate neighbours of a given monotone non-degenerate Boolean function

This Python library implements the set of rules described in arxiv:2407.01337, to compute the immediate neighbours of a given monotone non-degenerate Boolean function, without the need to generate the whole function space.

Here, immediate neighbours, are the monotone Boolean functions that are immediately above (or below) with respect to the partial order, in other words, are the functions that add/remove the minimum number of entries in the truth table.

Monotone non-degenerate Boolean functions are represented as sets of clauses, where each clause is represented by the bitarray data structure, and each bit represents the presence/absence of a given variable/regulator.

This work is developed in Python in https://github.com/ptgm/pyfunctionhood/, correcting and extending our previous work developed in Java in https://github.com/ptgm/functionhood/ and described in arxiv:1901.07623.

Given a reference monotone Boolean function, this library can be used in three distinct manners:

  • in the command line passing the reference function as an argument
  • using a graphical interface developed with Tkinter.
  • as a library integrated in other tools

Usage - command line

Usage example: python main.py <type> <dimension> <function> [<signature>]
 <type>:          [p]arents or [c]hildren
 <dimension>:     4
 <function>:      "{{1,2,3},{1,3,4},{2,3,4}}"
 <signature>:     optional target signature, e.g. "1011" (bit i: 1 = positive, 0 = negative variable i)

Parents

To compute the parents (the functions immediately above) of a given monotone Boolean function, on can call:

python main.py p 4 "{{1,2,3},{1,3,4},{2,3,4}}"
R1 {{1,2,3},{1,2,4},{1,3,4},{2,3,4}}
R2 {{1,3},{2,3,4}}
R2 {{1,2,3},{3,4}}
R2 {{1,3,4},{2,3}}

which yields one parent function generated by Rule 1 (adding a maximal independent clause), and three parent functions generated by Rule 2 (collapsing pairs of clauses).

Children

To compute the children (the functions immediately below) of a given monotone Boolean function, one just change the first parameter:

python main.py c 4 "{{1,2,3},{1,3,4},{2,3,4}}"
R1 {{1,3,4},{2,3,4}}
R1 {{1,2,3},{1,3,4}}
R1 {{1,2,3},{2,3,4}}

Sign changes

Commands accept an optional trailing <signature> argument: the target signature, a bitstring of the same length as <dimension>, where bit i is 1 if variable/regulator i is positive and 0 if it is negative. The function is given in the all-positive signature (all 1's). When a signature with some 0 is provided, the closest parents/children in that signature are computed instead of the default fixed-topology rules:

python main.py p 4 "{{1,2,3},{1,3,4},{2,3,4}}" 1011
python main.py c 4 "{{1,2,3},{1,3,4},{2,3,4}}" 1011

When omitted (or all 1's), the behaviour is unchanged from above, i.e. fixed-topology. In the output, ~i denotes the negated variable i: for instance, python main.py p 3 "{{1,2},{3}}" 101 yields R1 {{1},{~2},{3}}.


Usage - Graphical interface

There is also a graphical interface using Tkinter where the user can define the function dimension and write the desired monotone Boolean function.

Screenshot of main window

The interface has a button to automatically write the Infimum function of the chosen dimension, and another for the Supremum function.

A Signature text box is also available to optionally specify the target signature, a bitstring of the same length as the dimension, where bit i is 1 if variable/regulator i is positive and 0 if it is negative. It is set to all 1's (the default, i.e. the fixed-topology behaviour) and goes back to all 1's whenever the dimension changes. Hovering over it shows a short explanation.

The user has two buttons to generate the immediate neighbouring functions: Generate Parents to generate the list of parent functions, and Generate Children to generate the list of children functions.

In the text area the immediate neighbouring functions are shown, as well as any error if an invalid function is provided.

The button Default values cleans the text area and resets the input text boxes to their default values.

The button Close closes the application.


Usage - programmatically

If you are using this library directly you should first initialise the Hasse Diagram with a given dimension as a parameter (example below considers monotone Boolean functions of 4 variables/regulators):

from hassediagram import *
hd = HasseDiagram(4)

Then to initialise a function one can use a set of Clauses, where each Clause is a String representing the regulators that are present ("1") or absent ("0"), of dimension 4:

f = Function(4, {Clause('1110'), Clause('1011'), Clause('0111')})

or equivalently constructing the Function from its String representation:

f = Function.fromString(4, "{{1,2,3},{1,3,4},{2,3,4}}")

Once the Hasse Diagram and the function are defined, the method hd.get_f_parents(f) or hd.get_f_children(f) can be called, each returning a tuple of three sets of functions. The functions generated by Rule 1, by Rule 2 and by Rule 3, respectively. Below an example for parent functions generation:

s1, s2, s3 = hd.get_f_parents(f)
print(f'# parents from Rule1:{len(s1)} Rule2:{len(s2)} Rule3:{len(s3)}')
print('\n'.join(['R1 ' + str(f) for f in s1]\
              + ['R2 ' + str(f) for f in s2]\
              + ['R3 ' + str(f) for f in s3]))

Sign changes

To compute parents/children considering that some variables/regulators switched sign, use hd.get_f_parents_with_sign_changes(f, changed_signs) or hd.get_f_children_with_sign_changes(f, changed_signs), where changed_signs is a bitarray of the same size as the dimension, with bit i set to True if variable i switched sign:

from bitarray import bitarray
changed_signs = bitarray('0100')
s1, s2, s3 = hd.get_f_parents_with_sign_changes(f, changed_signs)

This is the complement of the <signature> used by the command line and the GUI: changed_signs = ~bitarray(signature).


Testing

The library includes a comprehensive pytest suite to validate correctness of the core algorithms:

pytest tests/ -v

This runs 22 tests covering:

  • Sign changes computation (test_check_sign_changes.py): Validates get_f_parents/children_with_sign_changes() by exhaustive checking for small dimensions and random sampling for larger ones
  • Random walk consistency (test_check_rules.py): Performs random walks on the Hasse diagram to verify parent-child relationships are consistent
  • Rule categorization (test_rule_categorization.py): Validates that parent and children are correctly partitioned into S1, S2, and S3 rules

License

This code is available under the GNU Affero General Public License v3.0 (AGPL-3.0). See the LICENSE file.

Cite

This work is available on arxiv:2407.01337.

Authors

  • Patrícia Roxo
  • José E. R. Cury
  • Vasco Manquinho
  • Claudine Chaouiya
  • Pedro T. Monteiro

Metadata

Release files for pyfunctionhood 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfunctionhood 0.3.1
File Size Uploaded Provenance Actions
pyfunctionhood-0.3.1.tar.gz 52.0 kB With provenance Details for pyfunctionhood-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyfunctionhood 0.3.1
File Interpreter ABI Platform Actions
pyfunctionhood-0.3.1-py3-none-any.whl Python 3 none any Details for pyfunctionhood-0.3.1-py3-none-any.whl

Total release size: 77.8 kB

Release files / pyfunctionhood-0.3.1.tar.gz

Download URL pyfunctionhood-0.3.1.tar.gz
Size 52.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0d0a7393d4bc9fd9d01d38cb385422974fae286832f8a002d66962ec5706c4e1
BLAKE2b-256 checksum
How to use checksums
e1aecfec2295c81bc5199fa25de70f1efe4dc8e75af18bd4c8a2fbf4f1a677fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pyfunctionhood-0.3.1-py3-none-any.whl

Download URL pyfunctionhood-0.3.1-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
800a7ec213020e683634a40027745a0ce712072503036d4178305752eb2100f7
BLAKE2b-256 checksum
How to use checksums
ac673326878f6409d83a503d1de1d7c7d555e004ac932e9ba77e6ced7f0f9816
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for pyfunctionhood 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyfunctionhood-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page