File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -84,17 +84,27 @@ def all_models(names: 't.Iterable[Name]') -> t.Iterator[Model]:
8484 new [name ] = True
8585 yield new
8686
87+ auto_simplify = False
8788
8889class NNF (metaclass = abc .ABCMeta ):
8990 """Base class for all NNF sentences."""
9091 __slots__ = ("__weakref__" ,)
91-
92+
93+
9294 def __and__ (self : T_NNF , other : U_NNF ) -> 'And[t.Union[T_NNF, U_NNF]]' :
93- """And({self, other})"""
95+ """And({self, other})"""
96+ # prevent unnecessary nesting
97+ if auto_simplify :
98+ if type (self ) == And :
99+ return And ({* self .children , * other .children }) if type (other ) == And else And ({* self .children , other })
94100 return And ({self , other })
95101
96102 def __or__ (self : T_NNF , other : U_NNF ) -> 'Or[t.Union[T_NNF, U_NNF]]' :
97103 """Or({self, other})"""
104+ # prevent unnecessary nesting
105+ if auto_simplify :
106+ if type (self ) == Or :
107+ return Or ({* self .children , * other .children }) if type (other ) == Or else Or ({* self .children , other })
98108 return Or ({self , other })
99109
100110 def __rshift__ (self : T_NNF , other : U_NNF )-> 'Or[t.Union[T_NNF.negate(), U_NNF]]' :
You can’t perform that action at this time.
0 commit comments