pyfunctionhood 0.1.2__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyfunctionhood-0.1.2/src/pyfunctionhood.egg-info → pyfunctionhood-0.2.1}/PKG-INFO +27 -7
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/README.md +26 -5
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/pyproject.toml +2 -6
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood/clause.py +3 -3
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood/hassediagram.py +54 -0
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood/main.py +54 -9
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood/powerset.py +2 -2
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1/src/pyfunctionhood.egg-info}/PKG-INFO +27 -7
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/LICENSE +0 -0
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/setup.cfg +0 -0
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood/__init__.py +0 -0
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood/function.py +0 -0
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood.egg-info/SOURCES.txt +0 -0
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood.egg-info/dependency_links.txt +0 -0
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood.egg-info/entry_points.txt +0 -0
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood.egg-info/requires.txt +0 -0
- {pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood.egg-info/top_level.txt +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyfunctionhood
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Local computation of immediate neighbours of a given monotone non-degenerate Boolean function
|
|
5
|
-
Author: Patrícia Roxo, José E. R. Cury, Vasco Manquinho, Claudine Chaouiya
|
|
6
5
|
Author-email: "Pedro T. Monteiro" <Pedro.Tiago.Monteiro@tecnico.ulisboa.pt>
|
|
7
6
|
License: AGPL-3.0
|
|
8
7
|
Project-URL: Homepage, https://github.com/ptgm/pyfunctionhood
|
|
@@ -34,7 +33,7 @@ Here, immediate neighbours, are the monotone Boolean functions that are immediat
|
|
|
34
33
|
|
|
35
34
|
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.
|
|
36
35
|
|
|
37
|
-
This work
|
|
36
|
+
This work is developed in Python in [https://github.com/ptgm/pyfunctionhood/](https://github.com/ptgm/pyfunctionhood/), correcting and extending our previous work developed in Java in [https://github.com/ptgm/functionhood/](https://github.com/ptgm/functionhood/) and described in [arxiv:1901.07623](https://arxiv.org/abs/1901.07623).
|
|
38
37
|
|
|
39
38
|
Given a reference monotone Boolean function, this library can be used in three distinct manners:
|
|
40
39
|
- in the command line passing the reference function as an argument
|
|
@@ -46,10 +45,11 @@ Given a reference monotone Boolean function, this library can be used in three d
|
|
|
46
45
|
Usage - command line
|
|
47
46
|
--------------------
|
|
48
47
|
```
|
|
49
|
-
Usage example: python main.py <type> <dimension> <function>
|
|
50
|
-
<type>:
|
|
51
|
-
<dimension>:
|
|
52
|
-
<function>:
|
|
48
|
+
Usage example: python main.py <type> <dimension> <function> [<changed_signs>]
|
|
49
|
+
<type>: [p]arents or [c]hildren
|
|
50
|
+
<dimension>: 4
|
|
51
|
+
<function>: "{{1,2,3},{1,3,4},{2,3,4}}"
|
|
52
|
+
<changed_signs>: optional, e.g. "0100" (bit i=1 means variable i switched sign)
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
**Parents**
|
|
@@ -74,6 +74,15 @@ R1 {{1,2,3},{1,3,4}}
|
|
|
74
74
|
R1 {{1,2,3},{2,3,4}}
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
**Sign changes**
|
|
78
|
+
|
|
79
|
+
Commands accept an optional trailing `<changed_signs>` argument: a bitstring of the same length as `<dimension>`, where bit `i=1` means variable/regulator `i` switched sign (0->1 or 1->0) with respect to the reference topology. When provided (and not all zeros), parents/children are computed considering that change of signs instead of the default fixed-topology rules:
|
|
80
|
+
```
|
|
81
|
+
python main.py p 4 "{{1,2,3},{1,3,4},{2,3,4}}" 0100
|
|
82
|
+
python main.py c 4 "{{1,2,3},{1,3,4},{2,3,4}}" 0100
|
|
83
|
+
```
|
|
84
|
+
When omitted (or all zeros), the behaviour is unchanged from above, i.e. fixed-topology.
|
|
85
|
+
|
|
77
86
|
---
|
|
78
87
|
|
|
79
88
|
Usage - Graphical interface
|
|
@@ -85,6 +94,8 @@ There is also a graphical interface using Tkinter where the user can define the
|
|
|
85
94
|
|
|
86
95
|
The interface has a button to automatically write the Infimum function of the chosen dimension, and another for the Supremum function.
|
|
87
96
|
|
|
97
|
+
A **Changed signs** text box is also available to optionally specify a bitstring of the same length as the dimension, where bit `i=1` means variable/regulator `i` switched sign. Leaving it empty (the default) keeps the fixed-topology behaviour.
|
|
98
|
+
|
|
88
99
|
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.
|
|
89
100
|
|
|
90
101
|
In the text area the immediate neighbouring functions are shown, as well as any error if an invalid function is provided.
|
|
@@ -124,6 +135,15 @@ print('\n'.join(['R1 ' + str(f) for f in s1]\
|
|
|
124
135
|
+ ['R3 ' + str(f) for f in s3]))
|
|
125
136
|
```
|
|
126
137
|
|
|
138
|
+
**Sign changes**
|
|
139
|
+
|
|
140
|
+
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:
|
|
141
|
+
```
|
|
142
|
+
from bitarray import bitarray
|
|
143
|
+
changed_signs = bitarray('0100')
|
|
144
|
+
s1, s2, s3 = hd.get_f_parents_with_sign_changes(f, changed_signs)
|
|
145
|
+
```
|
|
146
|
+
|
|
127
147
|
---
|
|
128
148
|
|
|
129
149
|
License
|
|
@@ -7,7 +7,7 @@ Here, immediate neighbours, are the monotone Boolean functions that are immediat
|
|
|
7
7
|
|
|
8
8
|
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.
|
|
9
9
|
|
|
10
|
-
This work
|
|
10
|
+
This work is developed in Python in [https://github.com/ptgm/pyfunctionhood/](https://github.com/ptgm/pyfunctionhood/), correcting and extending our previous work developed in Java in [https://github.com/ptgm/functionhood/](https://github.com/ptgm/functionhood/) and described in [arxiv:1901.07623](https://arxiv.org/abs/1901.07623).
|
|
11
11
|
|
|
12
12
|
Given a reference monotone Boolean function, this library can be used in three distinct manners:
|
|
13
13
|
- in the command line passing the reference function as an argument
|
|
@@ -19,10 +19,11 @@ Given a reference monotone Boolean function, this library can be used in three d
|
|
|
19
19
|
Usage - command line
|
|
20
20
|
--------------------
|
|
21
21
|
```
|
|
22
|
-
Usage example: python main.py <type> <dimension> <function>
|
|
23
|
-
<type>:
|
|
24
|
-
<dimension>:
|
|
25
|
-
<function>:
|
|
22
|
+
Usage example: python main.py <type> <dimension> <function> [<changed_signs>]
|
|
23
|
+
<type>: [p]arents or [c]hildren
|
|
24
|
+
<dimension>: 4
|
|
25
|
+
<function>: "{{1,2,3},{1,3,4},{2,3,4}}"
|
|
26
|
+
<changed_signs>: optional, e.g. "0100" (bit i=1 means variable i switched sign)
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
**Parents**
|
|
@@ -47,6 +48,15 @@ R1 {{1,2,3},{1,3,4}}
|
|
|
47
48
|
R1 {{1,2,3},{2,3,4}}
|
|
48
49
|
```
|
|
49
50
|
|
|
51
|
+
**Sign changes**
|
|
52
|
+
|
|
53
|
+
Commands accept an optional trailing `<changed_signs>` argument: a bitstring of the same length as `<dimension>`, where bit `i=1` means variable/regulator `i` switched sign (0->1 or 1->0) with respect to the reference topology. When provided (and not all zeros), parents/children are computed considering that change of signs instead of the default fixed-topology rules:
|
|
54
|
+
```
|
|
55
|
+
python main.py p 4 "{{1,2,3},{1,3,4},{2,3,4}}" 0100
|
|
56
|
+
python main.py c 4 "{{1,2,3},{1,3,4},{2,3,4}}" 0100
|
|
57
|
+
```
|
|
58
|
+
When omitted (or all zeros), the behaviour is unchanged from above, i.e. fixed-topology.
|
|
59
|
+
|
|
50
60
|
---
|
|
51
61
|
|
|
52
62
|
Usage - Graphical interface
|
|
@@ -58,6 +68,8 @@ There is also a graphical interface using Tkinter where the user can define the
|
|
|
58
68
|
|
|
59
69
|
The interface has a button to automatically write the Infimum function of the chosen dimension, and another for the Supremum function.
|
|
60
70
|
|
|
71
|
+
A **Changed signs** text box is also available to optionally specify a bitstring of the same length as the dimension, where bit `i=1` means variable/regulator `i` switched sign. Leaving it empty (the default) keeps the fixed-topology behaviour.
|
|
72
|
+
|
|
61
73
|
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.
|
|
62
74
|
|
|
63
75
|
In the text area the immediate neighbouring functions are shown, as well as any error if an invalid function is provided.
|
|
@@ -97,6 +109,15 @@ print('\n'.join(['R1 ' + str(f) for f in s1]\
|
|
|
97
109
|
+ ['R3 ' + str(f) for f in s3]))
|
|
98
110
|
```
|
|
99
111
|
|
|
112
|
+
**Sign changes**
|
|
113
|
+
|
|
114
|
+
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:
|
|
115
|
+
```
|
|
116
|
+
from bitarray import bitarray
|
|
117
|
+
changed_signs = bitarray('0100')
|
|
118
|
+
s1, s2, s3 = hd.get_f_parents_with_sign_changes(f, changed_signs)
|
|
119
|
+
```
|
|
120
|
+
|
|
100
121
|
---
|
|
101
122
|
|
|
102
123
|
License
|
|
@@ -4,17 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pyfunctionhood"
|
|
7
|
-
version = "0.1
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "Local computation of immediate neighbours of a given monotone non-degenerate Boolean function"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
11
11
|
license = { text = "AGPL-3.0" }
|
|
12
12
|
authors = [
|
|
13
|
-
{ name = "Pedro T. Monteiro", email="Pedro.Tiago.Monteiro@tecnico.ulisboa.pt" }
|
|
14
|
-
{ name = "Patrícia Roxo" },
|
|
15
|
-
{ name = "José E. R. Cury" },
|
|
16
|
-
{ name = "Vasco Manquinho" },
|
|
17
|
-
{ name = "Claudine Chaouiya" }
|
|
13
|
+
{ name = "Pedro T. Monteiro", email="Pedro.Tiago.Monteiro@tecnico.ulisboa.pt" }
|
|
18
14
|
]
|
|
19
15
|
keywords = ["boolean", "monotone", "hasse-diagram", "functions", "bitarray"]
|
|
20
16
|
classifiers = [
|
|
@@ -77,7 +77,7 @@ class Clause:
|
|
|
77
77
|
def __gt__(self, c: 'Clause') -> bool:
|
|
78
78
|
if self.cardinality != c.cardinality:
|
|
79
79
|
raise ValueError("Clauses must have the same cardinality!")
|
|
80
|
-
return self
|
|
80
|
+
return (self != c) and (self >= c)
|
|
81
81
|
|
|
82
82
|
def __le__(self, c: 'Clause') -> bool:
|
|
83
83
|
if self.cardinality != c.cardinality:
|
|
@@ -87,12 +87,12 @@ class Clause:
|
|
|
87
87
|
def __lt__(self, c: 'Clause') -> bool:
|
|
88
88
|
if self.cardinality != c.cardinality:
|
|
89
89
|
raise ValueError("Clauses must have the same cardinality!")
|
|
90
|
-
return self
|
|
90
|
+
return (self != c) and (self <= c)
|
|
91
91
|
|
|
92
92
|
def is_independent(self, c: 'Clause') -> bool:
|
|
93
93
|
if self.cardinality != c.cardinality:
|
|
94
94
|
raise ValueError("Clauses must have the same cardinality!")
|
|
95
|
-
return not self>=c and not self<=c
|
|
95
|
+
return (not self >= c) and (not self <= c)
|
|
96
96
|
|
|
97
97
|
def get_subsets(self) -> Set['Clause']:
|
|
98
98
|
return { self.clone_rm(l) for l in self.get_on_literals() }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from .clause import Clause
|
|
2
2
|
from .function import Function
|
|
3
3
|
from .powerset import PowerSet
|
|
4
|
+
from bitarray import bitarray
|
|
4
5
|
from typing import Tuple, Set
|
|
5
6
|
|
|
6
7
|
class HasseDiagram:
|
|
@@ -123,3 +124,56 @@ class HasseDiagram:
|
|
|
123
124
|
lmergeable.pop()
|
|
124
125
|
|
|
125
126
|
return s1Children, s2Children, s3Children
|
|
127
|
+
|
|
128
|
+
def get_f_parents_with_sign_changes(self, f: 'Function', changed_signs: bitarray) -> Tuple[Set['Function'], Set['Function'], Set['Function']]:
|
|
129
|
+
""" Returns the set of immediate parents of f when the variables/regulators
|
|
130
|
+
flagged in changed_signs have switched sign (0->1 or 1->0). """
|
|
131
|
+
if changed_signs.count() == 0:
|
|
132
|
+
raise ValueError('changed_signs must flag at least one variable!')
|
|
133
|
+
if len(changed_signs) != self.nvars:
|
|
134
|
+
raise ValueError('changed_signs must have size ' + str(self.nvars) + '!')
|
|
135
|
+
|
|
136
|
+
# S_bullet: clauses of f with all sign-changed literals removed
|
|
137
|
+
sBullet = set()
|
|
138
|
+
for c in f.clauses:
|
|
139
|
+
signature = c.get_signature() & ~changed_signs
|
|
140
|
+
if signature.count() == 0:
|
|
141
|
+
# Existence criterion: no f' exists once a clause becomes empty
|
|
142
|
+
return set(), set(), set()
|
|
143
|
+
sBullet.add(Clause(signature))
|
|
144
|
+
|
|
145
|
+
# Keep only the smallest clauses, dropping any that are supersets of another
|
|
146
|
+
sBullet = self.powerset.get_minimal(sBullet)
|
|
147
|
+
|
|
148
|
+
# S' = S_bullet union each maximal independent clause of f
|
|
149
|
+
sC = self.powerset.get_maximal(self.powerset.get_independent(sBullet))
|
|
150
|
+
sParents = { Function(self.nvars, sBullet | { c }) for c in sC }
|
|
151
|
+
|
|
152
|
+
return sParents, set(), set() # between signature changes only R1 parents are possible
|
|
153
|
+
|
|
154
|
+
def get_f_children_with_sign_changes(self, f: 'Function', changed_signs: bitarray) -> Tuple[Set['Function'], Set['Function'], Set['Function']]:
|
|
155
|
+
""" Returns the set of immediate children of f when the variables/regulators
|
|
156
|
+
flagged in changed_signs have switched sign (0->1 or 1->0). """
|
|
157
|
+
if changed_signs.count() == 0:
|
|
158
|
+
raise ValueError('changed_signs must flag at least one variable!')
|
|
159
|
+
if len(changed_signs) != self.nvars:
|
|
160
|
+
raise ValueError('changed_signs must have size ' + str(self.nvars) + '!')
|
|
161
|
+
|
|
162
|
+
# Existence criterion: f' exists only if some clause is made up exclusively of unchanged variables
|
|
163
|
+
invariants = { c for c in f.clauses if (c.get_signature() & changed_signs).count() == 0 }
|
|
164
|
+
if not invariants:
|
|
165
|
+
return set(), set(), set()
|
|
166
|
+
|
|
167
|
+
# One f' per clause s in invariants: f' = sRest union ext(s)
|
|
168
|
+
sChildren = set()
|
|
169
|
+
for s in invariants:
|
|
170
|
+
sRest = invariants - { s }
|
|
171
|
+
s_ext = s
|
|
172
|
+
for l in s.get_off_literals():
|
|
173
|
+
candidate = s_ext.clone_add(l)
|
|
174
|
+
if all(candidate.is_independent(c) for c in sRest):
|
|
175
|
+
s_ext = candidate
|
|
176
|
+
if s_ext != s: # s unextended would just recreate f, not a child
|
|
177
|
+
sChildren.add(Function(self.nvars, sRest | { s_ext }))
|
|
178
|
+
|
|
179
|
+
return sChildren, set(), set() # between signature changes only R1 children are possible
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
|
|
3
|
+
from bitarray import bitarray
|
|
3
4
|
from .hassediagram import HasseDiagram
|
|
4
5
|
from .function import Function
|
|
5
6
|
|
|
@@ -11,12 +12,26 @@ def GUI_mode():
|
|
|
11
12
|
print("Please install tkinter or run in command line mode.")
|
|
12
13
|
sys.exit(1)
|
|
13
14
|
|
|
15
|
+
def get_changed_signs(idim):
|
|
16
|
+
""" Returns None if no sign changed, otherwise the corresponding bitarray. """
|
|
17
|
+
strSigns = varChangedSigns.get().strip()
|
|
18
|
+
if not strSigns:
|
|
19
|
+
return None
|
|
20
|
+
if len(strSigns) != idim or any(c not in ('0', '1') for c in strSigns):
|
|
21
|
+
raise ValueError('changed signs must be a string of ' + str(idim) + ' bits (0/1)!')
|
|
22
|
+
changed_signs = bitarray(strSigns)
|
|
23
|
+
return changed_signs if changed_signs.count() else None
|
|
24
|
+
|
|
14
25
|
def get_parents():
|
|
15
26
|
try:
|
|
16
27
|
idim = int(varDimension.get())
|
|
17
28
|
hd = HasseDiagram(idim)
|
|
18
29
|
f = Function.fromString(idim, varFunction.get())
|
|
19
|
-
|
|
30
|
+
changed_signs = get_changed_signs(idim)
|
|
31
|
+
if changed_signs is None:
|
|
32
|
+
s1Parents, s2Parents, s3Parents = hd.get_f_parents(f)
|
|
33
|
+
else:
|
|
34
|
+
s1Parents, s2Parents, s3Parents = hd.get_f_parents_with_sign_changes(f, changed_signs)
|
|
20
35
|
lParents = ['R1 ' + str(f) for f in s1Parents]\
|
|
21
36
|
+ ['R2 ' + str(f) for f in s2Parents]\
|
|
22
37
|
+ ['R3 ' + str(f) for f in s3Parents]
|
|
@@ -31,7 +46,11 @@ def GUI_mode():
|
|
|
31
46
|
idim = int(varDimension.get())
|
|
32
47
|
hd = HasseDiagram(idim)
|
|
33
48
|
f = Function.fromString(idim, varFunction.get())
|
|
34
|
-
|
|
49
|
+
changed_signs = get_changed_signs(idim)
|
|
50
|
+
if changed_signs is None:
|
|
51
|
+
s1Children, s2Children, s3Children = hd.get_f_children(f)
|
|
52
|
+
else:
|
|
53
|
+
s1Children, s2Children, s3Children = hd.get_f_children_with_sign_changes(f, changed_signs)
|
|
35
54
|
lChildren = ['R1 ' + str(f) for f in s1Children]\
|
|
36
55
|
+ ['R2 ' + str(f) for f in s2Children]\
|
|
37
56
|
+ ['R3 ' + str(f) for f in s3Children]
|
|
@@ -44,6 +63,7 @@ def GUI_mode():
|
|
|
44
63
|
def default_values():
|
|
45
64
|
varFunction.set('{{1,2,3},{1,3,4},{2,3,4}}')
|
|
46
65
|
varDimension.set(4)
|
|
66
|
+
varChangedSigns.set('')
|
|
47
67
|
outputText.delete(1.0, "end") # Clear previous output
|
|
48
68
|
outputText.insert(1.0, '')
|
|
49
69
|
|
|
@@ -95,6 +115,13 @@ def GUI_mode():
|
|
|
95
115
|
entryFunction = tk.Entry(root, textvariable=varFunction, width=48)
|
|
96
116
|
entryFunction.grid(row=row, column=1, columnspan=2)
|
|
97
117
|
|
|
118
|
+
row += 1
|
|
119
|
+
labelChangedSigns = tk.Label(root, text="Changed Signs")
|
|
120
|
+
labelChangedSigns.grid(row=row, column=0, sticky='w')
|
|
121
|
+
varChangedSigns = tk.StringVar(value='') # empty means no sign changed
|
|
122
|
+
entryChangedSigns = tk.Entry(root, textvariable=varChangedSigns, width=48)
|
|
123
|
+
entryChangedSigns.grid(row=row, column=1, columnspan=2)
|
|
124
|
+
|
|
98
125
|
row += 1
|
|
99
126
|
bottomFrame = tk.Frame(root, padx=5, pady=5)
|
|
100
127
|
bottomFrame.grid(row=row, columnspan=2)
|
|
@@ -138,14 +165,15 @@ def GUI_mode():
|
|
|
138
165
|
def usage():
|
|
139
166
|
print('\nFor graphical mode, run without arguments: python', sys.argv[0])
|
|
140
167
|
print('\nFor command line mode, use the following arguments:')
|
|
141
|
-
print('Usage example:', sys.argv[0], '<type>', '<dimension>', '<function>')
|
|
142
|
-
print(' <type>:
|
|
143
|
-
print(' <dimension>:
|
|
144
|
-
print(' <function>:
|
|
168
|
+
print('Usage example:', sys.argv[0], '<type>', '<dimension>', '<function>', '[<changed_signs>]')
|
|
169
|
+
print(' <type>: [p]arents or [c]hildren')
|
|
170
|
+
print(' <dimension>: 4')
|
|
171
|
+
print(' <function>: "{{1,2,3},{1,3,4},{2,3,4}}"')
|
|
172
|
+
print(' <changed_signs>: optional, e.g. "0100" (bit i=1 means variable i switched sign)')
|
|
145
173
|
sys.exit(1)
|
|
146
174
|
|
|
147
175
|
def command_line_mode():
|
|
148
|
-
if len(sys.argv)
|
|
176
|
+
if len(sys.argv) not in (4, 5):
|
|
149
177
|
print('ERROR: invalid number of arguments!')
|
|
150
178
|
usage()
|
|
151
179
|
if sys.argv[1] not in ('p','parents','c','children'):
|
|
@@ -155,14 +183,31 @@ def command_line_mode():
|
|
|
155
183
|
ndim = int(sys.argv[2])
|
|
156
184
|
hd = HasseDiagram(ndim)
|
|
157
185
|
f = Function.fromString(ndim, sys.argv[3])
|
|
186
|
+
|
|
187
|
+
changed_signs = None
|
|
188
|
+
if len(sys.argv) == 5:
|
|
189
|
+
strSigns = sys.argv[4]
|
|
190
|
+
if len(strSigns) != ndim or any(c not in ('0', '1') for c in strSigns):
|
|
191
|
+
print('ERROR: invalid <changed_signs>')
|
|
192
|
+
usage()
|
|
193
|
+
changed_signs = bitarray(strSigns)
|
|
194
|
+
if changed_signs.count() == 0:
|
|
195
|
+
changed_signs = None
|
|
196
|
+
|
|
158
197
|
if sys.argv[1] in ('p','parents'):
|
|
159
|
-
|
|
198
|
+
if changed_signs is None:
|
|
199
|
+
s1Parents, s2Parents, s3Parents = hd.get_f_parents(f)
|
|
200
|
+
else:
|
|
201
|
+
s1Parents, s2Parents, s3Parents = hd.get_f_parents_with_sign_changes(f, changed_signs)
|
|
160
202
|
lParents = ['R1 ' + str(f) for f in s1Parents]\
|
|
161
203
|
+ ['R2 ' + str(f) for f in s2Parents]\
|
|
162
204
|
+ ['R3 ' + str(f) for f in s3Parents]
|
|
163
205
|
print('\n'.join(lParents))
|
|
164
206
|
else:
|
|
165
|
-
|
|
207
|
+
if changed_signs is None:
|
|
208
|
+
s1Children, s2Children, s3Children = hd.get_f_children(f)
|
|
209
|
+
else:
|
|
210
|
+
s1Children, s2Children, s3Children = hd.get_f_children_with_sign_changes(f, changed_signs)
|
|
166
211
|
lChildren = ['R1 ' + str(f) for f in s1Children]\
|
|
167
212
|
+ ['R2 ' + str(f) for f in s2Children]\
|
|
168
213
|
+ ['R3 ' + str(f) for f in s3Children]
|
|
@@ -70,10 +70,10 @@ class PowerSet:
|
|
|
70
70
|
return s_diff
|
|
71
71
|
|
|
72
72
|
def get_minimal(self, s_clauses: Set['Clause']) -> Set['Clause']:
|
|
73
|
-
return { s1 for s1 in s_clauses if not any(
|
|
73
|
+
return { s1 for s1 in s_clauses if not any(s2 < s1 for s2 in s_clauses) }
|
|
74
74
|
|
|
75
75
|
def get_maximal(self, s_clauses: Set['Clause']) -> Set['Clause']:
|
|
76
|
-
return { s1 for s1 in s_clauses if not any(
|
|
76
|
+
return { s1 for s1 in s_clauses if not any(s2 > s1 for s2 in s_clauses) }
|
|
77
77
|
|
|
78
78
|
def __str__(self) -> str:
|
|
79
79
|
s = ""
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyfunctionhood
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Local computation of immediate neighbours of a given monotone non-degenerate Boolean function
|
|
5
|
-
Author: Patrícia Roxo, José E. R. Cury, Vasco Manquinho, Claudine Chaouiya
|
|
6
5
|
Author-email: "Pedro T. Monteiro" <Pedro.Tiago.Monteiro@tecnico.ulisboa.pt>
|
|
7
6
|
License: AGPL-3.0
|
|
8
7
|
Project-URL: Homepage, https://github.com/ptgm/pyfunctionhood
|
|
@@ -34,7 +33,7 @@ Here, immediate neighbours, are the monotone Boolean functions that are immediat
|
|
|
34
33
|
|
|
35
34
|
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.
|
|
36
35
|
|
|
37
|
-
This work
|
|
36
|
+
This work is developed in Python in [https://github.com/ptgm/pyfunctionhood/](https://github.com/ptgm/pyfunctionhood/), correcting and extending our previous work developed in Java in [https://github.com/ptgm/functionhood/](https://github.com/ptgm/functionhood/) and described in [arxiv:1901.07623](https://arxiv.org/abs/1901.07623).
|
|
38
37
|
|
|
39
38
|
Given a reference monotone Boolean function, this library can be used in three distinct manners:
|
|
40
39
|
- in the command line passing the reference function as an argument
|
|
@@ -46,10 +45,11 @@ Given a reference monotone Boolean function, this library can be used in three d
|
|
|
46
45
|
Usage - command line
|
|
47
46
|
--------------------
|
|
48
47
|
```
|
|
49
|
-
Usage example: python main.py <type> <dimension> <function>
|
|
50
|
-
<type>:
|
|
51
|
-
<dimension>:
|
|
52
|
-
<function>:
|
|
48
|
+
Usage example: python main.py <type> <dimension> <function> [<changed_signs>]
|
|
49
|
+
<type>: [p]arents or [c]hildren
|
|
50
|
+
<dimension>: 4
|
|
51
|
+
<function>: "{{1,2,3},{1,3,4},{2,3,4}}"
|
|
52
|
+
<changed_signs>: optional, e.g. "0100" (bit i=1 means variable i switched sign)
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
**Parents**
|
|
@@ -74,6 +74,15 @@ R1 {{1,2,3},{1,3,4}}
|
|
|
74
74
|
R1 {{1,2,3},{2,3,4}}
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
**Sign changes**
|
|
78
|
+
|
|
79
|
+
Commands accept an optional trailing `<changed_signs>` argument: a bitstring of the same length as `<dimension>`, where bit `i=1` means variable/regulator `i` switched sign (0->1 or 1->0) with respect to the reference topology. When provided (and not all zeros), parents/children are computed considering that change of signs instead of the default fixed-topology rules:
|
|
80
|
+
```
|
|
81
|
+
python main.py p 4 "{{1,2,3},{1,3,4},{2,3,4}}" 0100
|
|
82
|
+
python main.py c 4 "{{1,2,3},{1,3,4},{2,3,4}}" 0100
|
|
83
|
+
```
|
|
84
|
+
When omitted (or all zeros), the behaviour is unchanged from above, i.e. fixed-topology.
|
|
85
|
+
|
|
77
86
|
---
|
|
78
87
|
|
|
79
88
|
Usage - Graphical interface
|
|
@@ -85,6 +94,8 @@ There is also a graphical interface using Tkinter where the user can define the
|
|
|
85
94
|
|
|
86
95
|
The interface has a button to automatically write the Infimum function of the chosen dimension, and another for the Supremum function.
|
|
87
96
|
|
|
97
|
+
A **Changed signs** text box is also available to optionally specify a bitstring of the same length as the dimension, where bit `i=1` means variable/regulator `i` switched sign. Leaving it empty (the default) keeps the fixed-topology behaviour.
|
|
98
|
+
|
|
88
99
|
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.
|
|
89
100
|
|
|
90
101
|
In the text area the immediate neighbouring functions are shown, as well as any error if an invalid function is provided.
|
|
@@ -124,6 +135,15 @@ print('\n'.join(['R1 ' + str(f) for f in s1]\
|
|
|
124
135
|
+ ['R3 ' + str(f) for f in s3]))
|
|
125
136
|
```
|
|
126
137
|
|
|
138
|
+
**Sign changes**
|
|
139
|
+
|
|
140
|
+
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:
|
|
141
|
+
```
|
|
142
|
+
from bitarray import bitarray
|
|
143
|
+
changed_signs = bitarray('0100')
|
|
144
|
+
s1, s2, s3 = hd.get_f_parents_with_sign_changes(f, changed_signs)
|
|
145
|
+
```
|
|
146
|
+
|
|
127
147
|
---
|
|
128
148
|
|
|
129
149
|
License
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyfunctionhood-0.1.2 → pyfunctionhood-0.2.1}/src/pyfunctionhood.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|