def negate_clause(c: Expr) -> Expr: if isinstance(c, syntax.Bool): return syntax.Bool(not c.val) elif isinstance(c, syntax.UnaryExpr): assert c.op == 'NOT' return c.arg elif isinstance(c, syntax.BinaryExpr): assert c.op in ['EQUAL', 'NOTEQ'] op = 'NOTEQ' if c.op == 'EQUAL' else 'EQUAL' return syntax.BinaryExpr(op, c.arg1, c.arg2) elif isinstance(c, syntax.NaryExpr): assert c.op == 'OR' return syntax.NaryExpr('AND', [negate_clause(arg) for arg in c.args]) elif isinstance(c, syntax.AppExpr) or isinstance(c, syntax.Id): return syntax.Not(c) else: assert False, f'unsupported expression {c} in negate_clause'
def negate_clause(c: Expr) -> Expr: if isinstance(c, syntax.Bool): return syntax.Bool(not c.val) elif isinstance(c, syntax.UnaryExpr): assert c.op == 'NOT' return c.arg elif isinstance(c, syntax.BinaryExpr): assert c.op in ['EQUAL', 'NOTEQ'] op = 'NOTEQ' if c.op == 'EQUAL' else 'EQUAL' return syntax.BinaryExpr(op, c.arg1, c.arg2) elif isinstance(c, syntax.NaryExpr): assert c.op == 'OR' return syntax.NaryExpr('AND', tuple(negate_clause(arg) for arg in c.args)) elif isinstance(c, syntax.AppExpr) or isinstance(c, syntax.Id): return syntax.Not(c) elif isinstance(c, syntax.QuantifierExpr): assert c.quant == 'FORALL' return syntax.QuantifierExpr('EXISTS', c.get_vs(), negate_clause(c.body)) else: assert False, f'unsupported expression {c} in negate_clause'
def p_expr_false(p: Any) -> None: 'expr : FALSE' p[0] = syntax.Bool(p.slice[1], False)
def p_expr_true(p: Any) -> None: 'expr : TRUE' p[0] = syntax.Bool(p.slice[1], True)
def p_expr_false(p: Any) -> None: 'expr : FALSE' p[0] = syntax.Bool(False, span=span_from_tok(p.slice[1]))
def p_expr_true(p: Any) -> None: 'expr : TRUE' p[0] = syntax.Bool(True, span=span_from_tok(p.slice[1]))