Branch data Line data Source code
1 : : /******************************************************************************
2 : : * This file is part of the cvc5 project.
3 : : *
4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
5 : : * in the top-level source directory and their institutional affiliations.
6 : : * All rights reserved. See the file COPYING in the top-level source
7 : : * directory for licensing information.
8 : : * ****************************************************************************
9 : : *
10 : : * Implementation of sets proof checker.
11 : : */
12 : :
13 : : #include "theory/sets/proof_checker.h"
14 : :
15 : : #include "expr/skolem_manager.h"
16 : :
17 : : namespace cvc5::internal {
18 : : namespace theory {
19 : : namespace sets {
20 : :
21 : 49953 : SetsProofRuleChecker::SetsProofRuleChecker(NodeManager* nm)
22 : 49953 : : ProofRuleChecker(nm)
23 : : {
24 : 49953 : }
25 : :
26 : 18895 : void SetsProofRuleChecker::registerTo(ProofChecker* pc)
27 : : {
28 : 18895 : pc->registerChecker(ProofRule::SETS_SINGLETON_INJ, this);
29 : 18895 : pc->registerChecker(ProofRule::SETS_EXT, this);
30 : 18895 : pc->registerChecker(ProofRule::SETS_FILTER_UP, this);
31 : 18895 : pc->registerChecker(ProofRule::SETS_FILTER_DOWN, this);
32 : 18895 : }
33 : :
34 : 287 : Node SetsProofRuleChecker::checkInternal(ProofRule id,
35 : : const std::vector<Node>& children,
36 : : const std::vector<Node>& args)
37 : : {
38 : 287 : NodeManager* nm = nodeManager();
39 [ + + ]: 287 : if (id == ProofRule::SETS_SINGLETON_INJ)
40 : : {
41 [ - + ][ - + ]: 72 : Assert(children.size() == 1);
[ - - ]
42 [ - + ][ - + ]: 72 : Assert(args.empty());
[ - - ]
43 : 72 : Node eq = children[0];
44 [ + - ][ - + ]: 144 : if (eq.getKind() != Kind::EQUAL || eq[0].getKind() != Kind::SET_SINGLETON
[ - - ]
45 [ + - ][ - + ]: 144 : || eq[1].getKind() != Kind::SET_SINGLETON)
[ + - ][ + - ]
[ - - ]
46 : : {
47 : 0 : return Node::null();
48 : : }
49 : 72 : return eq[0][0].eqNode(eq[1][0]);
50 : 72 : }
51 [ + + ]: 215 : else if (id == ProofRule::SETS_EXT)
52 : : {
53 [ - + ][ - + ]: 179 : Assert(children.size() == 1);
[ - - ]
54 [ - + ][ - + ]: 179 : Assert(args.empty());
[ - - ]
55 : 179 : Node deq = children[0];
56 [ + - ][ - + ]: 358 : if (deq.getKind() != Kind::NOT || deq[0].getKind() != Kind::EQUAL
[ - - ]
57 : 358 : || !deq[0][0].getType().isSet())
58 : : {
59 : 0 : return Node::null();
60 : : }
61 : 179 : Node a = deq[0][0];
62 : 179 : Node b = deq[0][1];
63 : 179 : SkolemManager* sm = nm->getSkolemManager();
64 : 716 : Node k = sm->mkSkolemFunction(SkolemId::SETS_DEQ_DIFF, {a, b});
65 : 358 : Node as = nm->mkNode(Kind::SET_MEMBER, k, a);
66 : 358 : Node bs = nm->mkNode(Kind::SET_MEMBER, k, b);
67 : 358 : return as.eqNode(bs).notNode();
68 : 179 : }
69 [ + + ]: 36 : else if (id == ProofRule::SETS_FILTER_UP)
70 : : {
71 [ - + ][ - + ]: 24 : Assert(children.size() == 1);
[ - - ]
72 [ - + ][ - + ]: 24 : Assert(args.size() == 1);
[ - - ]
73 : 24 : Node mem = children[0];
74 [ - + ]: 24 : if (mem.getKind() != Kind::SET_MEMBER)
75 : : {
76 : 0 : return Node::null();
77 : : }
78 : 48 : Node pred = nm->mkNode(Kind::APPLY_UF, args[0], mem[0]);
79 : 48 : Node filter = nm->mkNode(Kind::SET_FILTER, args[0], mem[1]);
80 : 48 : Node nmem = nm->mkNode(Kind::SET_MEMBER, mem[0], filter);
81 : 24 : return nmem.eqNode(pred);
82 : 24 : }
83 [ + - ]: 12 : else if (id == ProofRule::SETS_FILTER_DOWN)
84 : : {
85 [ - + ][ - + ]: 12 : Assert(children.size() == 1);
[ - - ]
86 : 12 : Node mem = children[0];
87 : 36 : if (mem.getKind() != Kind::SET_MEMBER
88 [ + - ][ - + ]: 12 : || mem[1].getKind() != Kind::SET_FILTER)
[ + - ][ - + ]
[ - - ]
89 : : {
90 : 0 : return Node::null();
91 : : }
92 : 24 : Node nmem = nm->mkNode(Kind::SET_MEMBER, mem[0], mem[1][1]);
93 : 24 : Node pred = nm->mkNode(Kind::APPLY_UF, mem[1][0], mem[0]);
94 : 12 : return nm->mkNode(Kind::AND, nmem, pred);
95 : 12 : }
96 : : // no rule
97 : 0 : return Node::null();
98 : : }
99 : :
100 : : } // namespace sets
101 : : } // namespace theory
102 : : } // namespace cvc5::internal
|