Note
Go to the end to download the full example code.
Resolution theorem proving.#
EGraph(_flatted_deps=[], _state=EGraphState(egraph=<builtins.EGraph object at 0x55c9c71849e0>, __egg_decls__=Declarations(_unnamed_functions=set(), _functions={'pred': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()),), arg_names=('x',), arg_defaults=(None,), return_type=TypeRefWithVars(name='Boolean', args=()), var_arg_type=None), builtin=False, egg_name=None, cost=None, default=None, on_merge=(), merge=None, unextractable=False)}, _constants={'T': ConstantDecl(type_ref=JustTypeRef(name='Boolean', args=()), egg_name=None)}, _classes={'Boolean': ClassDecl(egg_name=None, type_vars=(), builtin=False, init=None, class_methods={}, class_variables={'FALSE': ConstantDecl(type_ref=JustTypeRef(name='Boolean', args=()), egg_name=None)}, methods={'__or__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='Boolean', args=()), TypeRefWithVars(name='Boolean', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Boolean', args=()), var_arg_type=None), builtin=False, egg_name=None, cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__invert__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='Boolean', args=()),), arg_names=('self',), arg_defaults=(None,), return_type=TypeRefWithVars(name='Boolean', args=()), var_arg_type=None), builtin=False, egg_name=None, cost=None, default=None, on_merge=(), merge=None, unextractable=False)}, properties={}, preserved_methods={}), 'i64': ClassDecl(egg_name=None, type_vars=(), builtin=True, init=None, class_methods={}, class_variables={}, methods={'__add__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='+', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__sub__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='-', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__mul__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='*', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__truediv__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='/', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__mod__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='%', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__and__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='&', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__or__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='|', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__xor__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='^', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__lshift__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='<<', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__rshift__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='>>', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__invert__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()),), arg_names=('self',), arg_defaults=(None,), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='not-i64', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__lt__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Unit', args=()), var_arg_type=None), builtin=True, egg_name='<', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__gt__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Unit', args=()), var_arg_type=None), builtin=True, egg_name='>', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__le__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Unit', args=()), var_arg_type=None), builtin=True, egg_name='<=', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__ge__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Unit', args=()), var_arg_type=None), builtin=True, egg_name='>=', cost=None, default=None, on_merge=(), merge=None, unextractable=False), 'min': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='min', cost=None, default=None, on_merge=(), merge=None, unextractable=False), 'max': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='i64', args=()), var_arg_type=None), builtin=True, egg_name='max', cost=None, default=None, on_merge=(), merge=None, unextractable=False), 'to_string': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()),), arg_names=('self',), arg_defaults=(None,), return_type=TypeRefWithVars(name='String', args=()), var_arg_type=None), builtin=True, egg_name='to-string', cost=None, default=None, on_merge=(), merge=None, unextractable=False), 'bool_lt': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Bool', args=()), var_arg_type=None), builtin=True, egg_name='bool-<', cost=None, default=None, on_merge=(), merge=None, unextractable=False), 'bool_gt': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Bool', args=()), var_arg_type=None), builtin=True, egg_name='bool->', cost=None, default=None, on_merge=(), merge=None, unextractable=False), 'bool_le': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Bool', args=()), var_arg_type=None), builtin=True, egg_name='bool-<=', cost=None, default=None, on_merge=(), merge=None, unextractable=False), 'bool_ge': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='i64', args=()), TypeRefWithVars(name='i64', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Bool', args=()), var_arg_type=None), builtin=True, egg_name='bool->=', cost=None, default=None, on_merge=(), merge=None, unextractable=False)}, properties={}, preserved_methods={}), 'Unit': ClassDecl(egg_name='Unit', type_vars=(), builtin=True, init=None, class_methods={}, class_variables={}, methods={}, properties={}, preserved_methods={}), 'String': ClassDecl(egg_name=None, type_vars=(), builtin=True, init=None, class_methods={}, class_variables={}, methods={'replace': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='String', args=()), TypeRefWithVars(name='String', args=()), TypeRefWithVars(name='String', args=())), arg_names=('self', 'old', 'new'), arg_defaults=(None, None, None), return_type=TypeRefWithVars(name='String', args=()), var_arg_type=None), builtin=True, egg_name='replace', cost=None, default=None, on_merge=(), merge=None, unextractable=False)}, properties={}, preserved_methods={}), 'Bool': ClassDecl(egg_name='bool', type_vars=(), builtin=True, init=None, class_methods={}, class_variables={}, methods={'__invert__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='Bool', args=()),), arg_names=('self',), arg_defaults=(None,), return_type=TypeRefWithVars(name='Bool', args=()), var_arg_type=None), builtin=True, egg_name='not', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__and__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='Bool', args=()), TypeRefWithVars(name='Bool', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Bool', args=()), var_arg_type=None), builtin=True, egg_name='and', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__or__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='Bool', args=()), TypeRefWithVars(name='Bool', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Bool', args=()), var_arg_type=None), builtin=True, egg_name='or', cost=None, default=None, on_merge=(), merge=None, unextractable=False), '__xor__': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='Bool', args=()), TypeRefWithVars(name='Bool', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Bool', args=()), var_arg_type=None), builtin=True, egg_name='xor', cost=None, default=None, on_merge=(), merge=None, unextractable=False), 'implies': FunctionDecl(signature=FunctionSignature(arg_types=(TypeRefWithVars(name='Bool', args=()), TypeRefWithVars(name='Bool', args=())), arg_names=('self', 'other'), arg_defaults=(None, None), return_type=TypeRefWithVars(name='Bool', args=()), var_arg_type=None), builtin=True, egg_name='=>', cost=None, default=None, on_merge=(), merge=None, unextractable=False)}, properties={}, preserved_methods={})}, _rulesets={'': RulesetDecl(rules=[])}), rulesets={'': set()}, egg_fn_to_callable_refs=defaultdict(<class 'set'>, {'!=': {FunctionRef(name='!=')}, 'Boolean___invert__': {MethodRef(class_name='Boolean', method_name='__invert__')}, 'Boolean_FALSE': {ClassVariableRef(class_name='Boolean', var_name='FALSE')}, 'T': {ConstantRef(name='T')}, 'Boolean___or__': {MethodRef(class_name='Boolean', method_name='__or__')}, 'pred': {FunctionRef(name='pred')}}), callable_ref_to_egg_fn={FunctionRef(name='!='): '!=', MethodRef(class_name='Boolean', method_name='__invert__'): 'Boolean___invert__', ClassVariableRef(class_name='Boolean', var_name='FALSE'): 'Boolean_FALSE', ConstantRef(name='T'): 'T', MethodRef(class_name='Boolean', method_name='__or__'): 'Boolean___or__', FunctionRef(name='pred'): 'pred'}, type_ref_to_egg_sort={JustTypeRef(name='Boolean', args=()): 'Boolean', JustTypeRef(name='i64', args=()): 'i64', JustTypeRef(name='Unit', args=()): 'Unit'}, expr_to_egg_cache={CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', []), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])]), CallDecl(callable=ConstantRef(name='T'), args=(), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'T', []), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ConstantRef(name='T'), args=(), bound_tp_params=None)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'T', [])]), VarDecl(name='p', is_let=False): Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'p'), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p', is_let=False)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'p')]), VarDecl(name='a', is_let=False): Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), VarDecl(name='b', is_let=False): Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'b'), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='b', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'b')]), VarDecl(name='c', is_let=False): Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'c'), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='b', is_let=False))), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='c', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'b')]), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'c')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='b', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='c', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'b'), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'c')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='b', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='c', is_let=False))), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'b'), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'c')])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='c', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'c')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='b', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='c', is_let=False))), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'b'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'c')])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='b', is_let=False))), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'b')])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='b', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a')]), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'b')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='b', is_let=False))), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a')]), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'b')])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', []), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ConstantRef(name='T'), args=(), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'T', []), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ConstantRef(name='T'), args=(), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'T', [])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'p'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])]), VarDecl(name='as', is_let=False): Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'as'), VarDecl(name='bs', is_let=False): Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'bs'), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='as', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='bs', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'as'), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'bs')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='as', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a'), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'as')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='a', is_let=False)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='bs', is_let=False))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'a')]), Var(Span(SrcFile('<internal.egg>', None), 0, 0), 'bs')]), VarDecl(name='p0', is_let=True): Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p0'), LitDecl(value=0): Lit(Span(SrcFile('<internal.egg>', None), 0, 0), Int(0)), CallDecl(callable=FunctionRef(name='pred'), args=(TypedExprDecl(tp=JustTypeRef(name='i64', args=()), expr=LitDecl(value=0)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'pred', [Lit(Span(SrcFile('<internal.egg>', None), 0, 0), Int(0))]), VarDecl(name='p1', is_let=True): Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p1'), LitDecl(value=1): Lit(Span(SrcFile('<internal.egg>', None), 0, 0), Int(1)), CallDecl(callable=FunctionRef(name='pred'), args=(TypedExprDecl(tp=JustTypeRef(name='i64', args=()), expr=LitDecl(value=1)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'pred', [Lit(Span(SrcFile('<internal.egg>', None), 0, 0), Int(1))]), VarDecl(name='p2', is_let=True): Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p2'), LitDecl(value=2): Lit(Span(SrcFile('<internal.egg>', None), 0, 0), Int(2)), CallDecl(callable=FunctionRef(name='pred'), args=(TypedExprDecl(tp=JustTypeRef(name='i64', args=()), expr=LitDecl(value=2)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'pred', [Lit(Span(SrcFile('<internal.egg>', None), 0, 0), Int(2))]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p2', is_let=True)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p2')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p2', is_let=True)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p2')]), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p1', is_let=True)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p2', is_let=True)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p1'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p2')]), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p0', is_let=True)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p0')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p0', is_let=True)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p0')]), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p2', is_let=True)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p0', is_let=True)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p2'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p0')]), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p1', is_let=True)),), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p1')]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p1', is_let=True)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p1')]), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p0', is_let=True)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p1', is_let=True)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p0'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p1')]), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p2', is_let=True)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p2'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p1', is_let=True)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p2', is_let=True)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p1')]), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p2'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])])]), CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p0', is_let=True)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__invert__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p1', is_let=True)),), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=MethodRef(class_name='Boolean', method_name='__or__'), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=VarDecl(name='p2', is_let=True)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None))), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p0')]), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___invert__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p1')]), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean___or__', [Var(Span(SrcFile('<internal.egg>', None), 0, 0), '%p2'), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])])])]), CallDecl(callable=FunctionRef(name='!='), args=(TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ConstantRef(name='T'), args=(), bound_tp_params=None)), TypedExprDecl(tp=JustTypeRef(name='Boolean', args=()), expr=CallDecl(callable=ClassVariableRef(class_name='Boolean', var_name='FALSE'), args=(), bound_tp_params=None))), bound_tp_params=None): Call(Span(SrcFile('<internal.egg>', None), 0, 0), '!=', [Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'T', []), Call(Span(SrcFile('<internal.egg>', None), 0, 0), 'Boolean_FALSE', [])])}))
from __future__ import annotations
from typing import ClassVar
from egglog import *
egraph = EGraph()
class Boolean(Expr):
FALSE: ClassVar[Boolean]
def __or__(self, other: Boolean) -> Boolean: # type: ignore[empty-body]
...
def __invert__(self) -> Boolean: # type: ignore[empty-body]
...
# Show off two ways of creating constants, either as top level values or as classvars
T = constant("T", Boolean)
F = Boolean.FALSE
p, a, b, c, as_, bs = vars_("p a b c as bs", Boolean)
egraph.register(
# clauses are assumed in the normal form (or a (or b (or c False)))
union(~F).with_(T),
union(~T).with_(F),
# "Solving" negation equations
rule(eq(~p).to(T)).then(union(p).with_(F)),
rule(eq(~p).to(F)).then(union(p).with_(T)),
# canonicalize associtivity. "append" for clauses terminate with false
rewrite((a | b) | c).to(a | (b | c)),
# commutativity
rewrite(a | (b | c)).to(b | (a | c)),
# absoprtion
rewrite(a | (a | b)).to(a | b),
rewrite(a | (~a | b)).to(T),
# Simplification
rewrite(F | a).to(a),
rewrite(a | F).to(a),
rewrite(T | a).to(T),
rewrite(a | T).to(T),
# unit propagation
# This is kind of interesting actually.
# Looks a bit like equation solving
rule(eq(T).to(p | F)).then(union(p).with_(T)),
# resolution
# This counts on commutativity to bubble everything possible up to the front of the clause.
rule(
eq(T).to(a | as_),
eq(T).to(~a | bs),
).then(
union(as_ | bs).with_(T),
),
)
# Example predicate
@function
def pred(x: i64Like) -> Boolean: # type: ignore[empty-body]
...
p0 = egraph.let("p0", pred(0))
p1 = egraph.let("p1", pred(1))
p2 = egraph.let("p2", pred(2))
egraph.register(
union(p1 | (~p2 | F)).with_(T),
union(p2 | (~p0 | F)).with_(T),
union(p0 | (~p1 | F)).with_(T),
union(p1).with_(F),
union(~p0 | (~p1 | (p2 | F))).with_(T),
)
egraph.run(10)
egraph.check(ne(T).to(F))
egraph.check(eq(p0).to(F))
egraph.check(eq(p2).to(F))
egraph
Total running time of the script: (0 minutes 0.015 seconds)