(proof-new) Proof rule checkers run on skolem forms (#4660)
[cvc5.git] / src / expr / proof_rule.h
1 /********************* */
2 /*! \file proof_rule.h
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Haniel Barbosa, Andrew Reynolds
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
11 **
12 ** \brief Proof rule enumeration
13 **/
14
15 #include "cvc4_private.h"
16
17 #ifndef CVC4__EXPR__PROOF_RULE_H
18 #define CVC4__EXPR__PROOF_RULE_H
19
20 #include <iosfwd>
21
22 namespace CVC4 {
23
24 /**
25 * An enumeration for proof rules. This enumeration is analogous to Kind for
26 * Node objects. In the documentation below, P:F denotes a ProofNode that
27 * proves formula F.
28 *
29 * Conceptually, the following proof rules form a calculus whose target
30 * user is the Node-level theory solvers. This means that the rules below
31 * are designed to reason about, among other things, common operations on Node
32 * objects like Rewriter::rewrite or Node::substitute. It is intended to be
33 * translated or printed in other formats.
34 *
35 * The following PfRule values include core rules and those categorized by
36 * theory, including the theory of equality.
37 *
38 * The "core rules" include two distinguished rules which have special status:
39 * (1) ASSUME, which represents an open leaf in a proof.
40 * (2) SCOPE, which closes the scope of assumptions.
41 * The core rules additionally correspond to generic operations that are done
42 * internally on nodes, e.g. calling Rewriter::rewrite.
43 */
44 enum class PfRule : uint32_t
45 {
46 //================================================= Core rules
47 //======================== Assume and Scope
48 // ======== Assumption (a leaf)
49 // Children: none
50 // Arguments: (F)
51 // --------------
52 // Conclusion: F
53 //
54 // This rule has special status, in that an application of assume is an
55 // open leaf in a proof that is not (yet) justified. An assume leaf is
56 // analogous to a free variable in a term, where we say "F is a free
57 // assumption in proof P" if it contains an application of F that is not
58 // bound by SCOPE (see below).
59 ASSUME,
60 // ======== Scope (a binder for assumptions)
61 // Children: (P:F)
62 // Arguments: (F1, ..., Fn)
63 // --------------
64 // Conclusion: (=> (and F1 ... Fn) F) or (not (and F1 ... Fn)) if F is false
65 //
66 // This rule has a dual purpose with ASSUME. It is a way to close
67 // assumptions in a proof. We require that F1 ... Fn are free assumptions in
68 // P and say that F1, ..., Fn are not free in (SCOPE P). In other words, they
69 // are bound by this application. For example, the proof node:
70 // (SCOPE (ASSUME F) :args F)
71 // has the conclusion (=> F F) and has no free assumptions. More generally, a
72 // proof with no free assumptions always concludes a valid formula.
73 SCOPE,
74
75 //======================== Builtin theory (common node operations)
76 // ======== Substitution
77 // Children: (P1:F1, ..., Pn:Fn)
78 // Arguments: (t, (ids)?)
79 // ---------------------------------------------------------------
80 // Conclusion: (= t t*sigma{ids}(Fn)*...*sigma{ids}(F1))
81 // where sigma{ids}(Fi) are substitutions, which notice are applied in
82 // reverse order.
83 // Notice that ids is a MethodId identifier, which determines how to convert
84 // the formulas F1, ..., Fn into substitutions.
85 SUBS,
86 // ======== Rewrite
87 // Children: none
88 // Arguments: (t, (idr)?)
89 // ----------------------------------------
90 // Conclusion: (= t Rewriter{idr}(t))
91 // where idr is a MethodId identifier, which determines the kind of rewriter
92 // to apply, e.g. Rewriter::rewrite.
93 REWRITE,
94 // ======== Substitution + Rewriting equality introduction
95 //
96 // In this rule, we provide a term t and conclude that it is equal to its
97 // rewritten form under a (proven) substitution.
98 //
99 // Children: (P1:F1, ..., Pn:Fn)
100 // Arguments: (t, (ids (idr)?)?)
101 // ---------------------------------------------------------------
102 // Conclusion: (= t t')
103 // where
104 // t' is
105 // Rewriter{idr}(t*sigma{ids}(Fn)*...*sigma{ids}(F1))
106 //
107 // In other words, from the point of view of Skolem forms, this rule
108 // transforms t to t' by standard substitution + rewriting.
109 //
110 // The argument ids and idr is optional and specify the identifier of the
111 // substitution and rewriter respectively to be used. For details, see
112 // theory/builtin/proof_checker.h.
113 MACRO_SR_EQ_INTRO,
114 // ======== Substitution + Rewriting predicate introduction
115 //
116 // In this rule, we provide a formula F and conclude it, under the condition
117 // that it rewrites to true under a proven substitution.
118 //
119 // Children: (P1:F1, ..., Pn:Fn)
120 // Arguments: (F, (ids (idr)?)?)
121 // ---------------------------------------------------------------
122 // Conclusion: F
123 // where
124 // Rewriter{idr}(toWitness(F)*sigma{ids}(Fn)*...*sigma{ids}(F1)) == true
125 // where ids and idr are method identifiers.
126 //
127 // Notice that we apply rewriting on the witness form of F, meaning that this
128 // rule may conclude an F whose Skolem form is justified by the definition of
129 // its (fresh) Skolem variables. Furthermore, notice that the rewriting and
130 // substitution is applied only within the side condition, meaning the
131 // rewritten form of the witness form of F does not escape this rule.
132 MACRO_SR_PRED_INTRO,
133 // ======== Substitution + Rewriting predicate elimination
134 //
135 // In this rule, if we have proven a formula F, then we may conclude its
136 // rewritten form under a proven substitution.
137 //
138 // Children: (P1:F, P2:F1, ..., P_{n+1}:Fn)
139 // Arguments: ((ids (idr)?)?)
140 // ----------------------------------------
141 // Conclusion: F'
142 // where
143 // F' is
144 // Rewriter{idr}(F*sigma{ids}(Fn)*...*sigma{ids}(F1)).
145 // where ids and idr are method identifiers.
146 //
147 // We rewrite only on the Skolem form of F, similar to MACRO_SR_EQ_INTRO.
148 MACRO_SR_PRED_ELIM,
149 // ======== Substitution + Rewriting predicate transform
150 //
151 // In this rule, if we have proven a formula F, then we may provide a formula
152 // G and conclude it if F and G are equivalent after rewriting under a proven
153 // substitution.
154 //
155 // Children: (P1:F, P2:F1, ..., P_{n+1}:Fn)
156 // Arguments: (G, (ids (idr)?)?)
157 // ----------------------------------------
158 // Conclusion: G
159 // where
160 // Rewriter{idr}(toWitness(F)*sigma{ids}(Fn)*...*sigma{ids}(F1)) ==
161 // Rewriter{idr}(toWitness(G)*sigma{ids}(Fn)*...*sigma{ids}(F1))
162 //
163 // Notice that we apply rewriting on the witness form of F and G, similar to
164 // MACRO_SR_PRED_INTRO.
165 MACRO_SR_PRED_TRANSFORM,
166
167 //================================================= Boolean rules
168 // ======== Split
169 // Children: none
170 // Arguments: (F)
171 // ---------------------
172 // Conclusion: (or F (not F))
173 SPLIT,
174 // ======== And elimination
175 // Children: (P:(and F1 ... Fn))
176 // Arguments: (i)
177 // ---------------------
178 // Conclusion: (Fi)
179 AND_ELIM,
180 // ======== And introduction
181 // Children: (P1:F1 ... Pn:Fn))
182 // Arguments: ()
183 // ---------------------
184 // Conclusion: (and P1 ... Pn)
185 AND_INTRO,
186 // ======== Not Or elimination
187 // Children: (P:(not (or F1 ... Fn)))
188 // Arguments: (i)
189 // ---------------------
190 // Conclusion: (not Fi)
191 NOT_OR_ELIM,
192 // ======== Implication elimination
193 // Children: (P:(=> F1 F2))
194 // Arguments: ()
195 // ---------------------
196 // Conclusion: (or (not F1) F2)
197 IMPLIES_ELIM,
198 // ======== Not Implication elimination version 1
199 // Children: (P:(not (=> F1 F2)))
200 // Arguments: ()
201 // ---------------------
202 // Conclusion: (F1)
203 NOT_IMPLIES_ELIM1,
204 // ======== Not Implication elimination version 2
205 // Children: (P:(not (=> F1 F2)))
206 // Arguments: ()
207 // ---------------------
208 // Conclusion: (not F2)
209 NOT_IMPLIES_ELIM2,
210 // ======== Equivalence elimination version 1
211 // Children: (P:(= F1 F2))
212 // Arguments: ()
213 // ---------------------
214 // Conclusion: (or (not F1) F2)
215 EQUIV_ELIM1,
216 // ======== Equivalence elimination version 2
217 // Children: (P:(= F1 F2))
218 // Arguments: ()
219 // ---------------------
220 // Conclusion: (or F1 (not F2))
221 EQUIV_ELIM2,
222 // ======== Not Equivalence elimination version 1
223 // Children: (P:(not (= F1 F2)))
224 // Arguments: ()
225 // ---------------------
226 // Conclusion: (or F1 F2)
227 NOT_EQUIV_ELIM1,
228 // ======== Not Equivalence elimination version 2
229 // Children: (P:(not (= F1 F2)))
230 // Arguments: ()
231 // ---------------------
232 // Conclusion: (or (not F1) (not F2))
233 NOT_EQUIV_ELIM2,
234 // ======== XOR elimination version 1
235 // Children: (P:(xor F1 F2)))
236 // Arguments: ()
237 // ---------------------
238 // Conclusion: (or F1 F2)
239 XOR_ELIM1,
240 // ======== XOR elimination version 2
241 // Children: (P:(xor F1 F2)))
242 // Arguments: ()
243 // ---------------------
244 // Conclusion: (or (not F1) (not F2))
245 XOR_ELIM2,
246 // ======== Not XOR elimination version 1
247 // Children: (P:(not (xor F1 F2)))
248 // Arguments: ()
249 // ---------------------
250 // Conclusion: (or F1 (not F2))
251 NOT_XOR_ELIM1,
252 // ======== Not XOR elimination version 2
253 // Children: (P:(not (xor F1 F2)))
254 // Arguments: ()
255 // ---------------------
256 // Conclusion: (or (not F1) F2)
257 NOT_XOR_ELIM2,
258 // ======== ITE elimination version 1
259 // Children: (P:(ite C F1 F2))
260 // Arguments: ()
261 // ---------------------
262 // Conclusion: (or (not C) F1)
263 ITE_ELIM1,
264 // ======== ITE elimination version 2
265 // Children: (P:(ite C F1 F2))
266 // Arguments: ()
267 // ---------------------
268 // Conclusion: (or C F2)
269 ITE_ELIM2,
270 // ======== Not ITE elimination version 1
271 // Children: (P:(not (ite C F1 F2)))
272 // Arguments: ()
273 // ---------------------
274 // Conclusion: (or (not C) (not F1))
275 NOT_ITE_ELIM1,
276 // ======== Not ITE elimination version 1
277 // Children: (P:(not (ite C F1 F2)))
278 // Arguments: ()
279 // ---------------------
280 // Conclusion: (or C (not F2))
281 NOT_ITE_ELIM2,
282 // ======== Not ITE elimination version 1
283 // Children: (P1:P P2:(not P))
284 // Arguments: ()
285 // ---------------------
286 // Conclusion: (false)
287 CONTRA,
288
289 //================================================= De Morgan rules
290 // ======== Not And
291 // Children: (P:(not (and F1 ... Fn))
292 // Arguments: ()
293 // ---------------------
294 // Conclusion: (or (not F1) ... (not Fn))
295 NOT_AND,
296 //================================================= CNF rules
297 // ======== CNF And Pos
298 // Children: ()
299 // Arguments: ((and F1 ... Fn), i)
300 // ---------------------
301 // Conclusion: (or (not (and F1 ... Fn)) Fi)
302 CNF_AND_POS,
303 // ======== CNF And Neg
304 // Children: ()
305 // Arguments: ((and F1 ... Fn))
306 // ---------------------
307 // Conclusion: (or (and F1 ... Fn) (not F1) ... (not Fn))
308 CNF_AND_NEG,
309 // ======== CNF Or Pos
310 // Children: ()
311 // Arguments: ((or F1 ... Fn))
312 // ---------------------
313 // Conclusion: (or (not (or F1 ... Fn)) F1 ... Fn)
314 CNF_OR_POS,
315 // ======== CNF Or Neg
316 // Children: ()
317 // Arguments: ((or F1 ... Fn), i)
318 // ---------------------
319 // Conclusion: (or (or F1 ... Fn) (not Fi))
320 CNF_OR_NEG,
321 // ======== CNF Implies Pos
322 // Children: ()
323 // Arguments: ((implies F1 F2))
324 // ---------------------
325 // Conclusion: (or (not (implies F1 F2)) (not F1) F2)
326 CNF_IMPLIES_POS,
327 // ======== CNF Implies Neg version 1
328 // Children: ()
329 // Arguments: ((implies F1 F2))
330 // ---------------------
331 // Conclusion: (or (implies F1 F2) F1)
332 CNF_IMPLIES_NEG1,
333 // ======== CNF Implies Neg version 2
334 // Children: ()
335 // Arguments: ((implies F1 F2))
336 // ---------------------
337 // Conclusion: (or (implies F1 F2) (not F2))
338 CNF_IMPLIES_NEG2,
339 // ======== CNF Equiv Pos version 1
340 // Children: ()
341 // Arguments: ((= F1 F2))
342 // ---------------------
343 // Conclusion: (or (not (= F1 F2)) (not F1) F2)
344 CNF_EQUIV_POS1,
345 // ======== CNF Equiv Pos version 2
346 // Children: ()
347 // Arguments: ((= F1 F2))
348 // ---------------------
349 // Conclusion: (or (not (= F1 F2)) F1 (not F2))
350 CNF_EQUIV_POS2,
351 // ======== CNF Equiv Neg version 1
352 // Children: ()
353 // Arguments: ((= F1 F2))
354 // ---------------------
355 // Conclusion: (or (= F1 F2) F1 F2)
356 CNF_EQUIV_NEG1,
357 // ======== CNF Equiv Neg version 2
358 // Children: ()
359 // Arguments: ((= F1 F2))
360 // ---------------------
361 // Conclusion: (or (= F1 F2) (not F1) (not F2))
362 CNF_EQUIV_NEG2,
363 // ======== CNF Xor Pos version 1
364 // Children: ()
365 // Arguments: ((xor F1 F2))
366 // ---------------------
367 // Conclusion: (or (not (xor F1 F2)) F1 F2)
368 CNF_XOR_POS1,
369 // ======== CNF Xor Pos version 2
370 // Children: ()
371 // Arguments: ((xor F1 F2))
372 // ---------------------
373 // Conclusion: (or (not (xor F1 F2)) (not F1) (not F2))
374 CNF_XOR_POS2,
375 // ======== CNF Xor Neg version 1
376 // Children: ()
377 // Arguments: ((xor F1 F2))
378 // ---------------------
379 // Conclusion: (or (xor F1 F2) (not F1) F2)
380 CNF_XOR_NEG1,
381 // ======== CNF Xor Neg version 2
382 // Children: ()
383 // Arguments: ((xor F1 F2))
384 // ---------------------
385 // Conclusion: (or (xor F1 F2) F1 (not F2))
386 CNF_XOR_NEG2,
387 // ======== CNF ITE Pos version 1
388 // Children: ()
389 // Arguments: ((ite C F1 F2))
390 // ---------------------
391 // Conclusion: (or (not (ite C F1 F2)) (not C) F1)
392 CNF_ITE_POS1,
393 // ======== CNF ITE Pos version 2
394 // Children: ()
395 // Arguments: ((ite C F1 F2))
396 // ---------------------
397 // Conclusion: (or (not (ite C F1 F2)) C F2)
398 CNF_ITE_POS2,
399 // ======== CNF ITE Pos version 3
400 // Children: ()
401 // Arguments: ((ite C F1 F2))
402 // ---------------------
403 // Conclusion: (or (not (ite C F1 F2)) F1 F2)
404 CNF_ITE_POS3,
405 // ======== CNF ITE Neg version 1
406 // Children: ()
407 // Arguments: ((ite C F1 F2))
408 // ---------------------
409 // Conclusion: (or (ite C F1 F2) (not C) (not F1))
410 CNF_ITE_NEG1,
411 // ======== CNF ITE Neg version 2
412 // Children: ()
413 // Arguments: ((ite C F1 F2))
414 // ---------------------
415 // Conclusion: (or (ite C F1 F2) C (not F2))
416 CNF_ITE_NEG2,
417 // ======== CNF ITE Neg version 3
418 // Children: ()
419 // Arguments: ((ite C F1 F2))
420 // ---------------------
421 // Conclusion: (or (ite C F1 F2) (not F1) (not F2))
422 CNF_ITE_NEG3,
423
424 //================================================= Equality rules
425 // ======== Reflexive
426 // Children: none
427 // Arguments: (t)
428 // ---------------------
429 // Conclusion: (= t t)
430 REFL,
431 // ======== Symmetric
432 // Children: (P:(= t1 t2)) or (P:(not (= t1 t2)))
433 // Arguments: none
434 // -----------------------
435 // Conclusion: (= t2 t1) or (not (= t2 t1))
436 SYMM,
437 // ======== Transitivity
438 // Children: (P1:(= t1 t2), ..., Pn:(= t{n-1} tn))
439 // Arguments: none
440 // -----------------------
441 // Conclusion: (= t1 tn)
442 TRANS,
443 // ======== Congruence (subsumed by Substitute?)
444 // Children: (P1:(= t1 s1), ..., Pn:(= tn sn))
445 // Arguments: (f)
446 // ---------------------------------------------
447 // Conclusion: (= (f t1 ... tn) (f s1 ... sn))
448 CONG,
449 // ======== True intro
450 // Children: (P:F)
451 // Arguments: none
452 // ----------------------------------------
453 // Conclusion: (= F true)
454 TRUE_INTRO,
455 // ======== True elim
456 // Children: (P:(= F true)
457 // Arguments: none
458 // ----------------------------------------
459 // Conclusion: F
460 TRUE_ELIM,
461 // ======== False intro
462 // Children: (P:(not F))
463 // Arguments: none
464 // ----------------------------------------
465 // Conclusion: (= F false)
466 FALSE_INTRO,
467 // ======== False elim
468 // Children: (P:(= F false)
469 // Arguments: none
470 // ----------------------------------------
471 // Conclusion: (not F)
472 FALSE_ELIM,
473
474 //================================================= Quantifiers rules
475 // ======== Witness intro
476 // Children: (P:F[t])
477 // Arguments: (t)
478 // ----------------------------------------
479 // Conclusion: (= t (witness ((x T)) F[x]))
480 // where x is a BOUND_VARIABLE unique to the pair F,t.
481 WITNESS_INTRO,
482 // ======== Exists intro
483 // Children: (P:F[t])
484 // Arguments: (t)
485 // ----------------------------------------
486 // Conclusion: (exists ((x T)) F[x])
487 // where x is a BOUND_VARIABLE unique to the pair F,t.
488 EXISTS_INTRO,
489 // ======== Skolemize
490 // Children: (P:(exists ((x1 T1) ... (xn Tn)) F))
491 // Arguments: none
492 // ----------------------------------------
493 // Conclusion: F*sigma
494 // sigma maps x1 ... xn to their representative skolems obtained by
495 // SkolemManager::mkSkolemize, returned in the skolems argument of that
496 // method.
497 SKOLEMIZE,
498 // ======== Instantiate
499 // Children: (P:(forall ((x1 T1) ... (xn Tn)) F))
500 // Arguments: (t1 ... tn)
501 // ----------------------------------------
502 // Conclusion: F*sigma
503 // sigma maps x1 ... xn to t1 ... tn.
504 INSTANTIATE,
505
506 // ======== Adding Inequalities
507 // Note: an ArithLiteral is a term of the form (>< poly const)
508 // where
509 // >< is >=, >, ==, <, <=, or not(== ...).
510 // poly is a polynomial
511 // const is a rational constant
512
513 // Children: (P1:l1, ..., Pn:ln)
514 // where each li is an ArithLiteral
515 // not(= ...) is dis-allowed!
516 //
517 // Arguments: (k1, ..., kn), non-zero reals
518 // ---------------------
519 // Conclusion: (>< (* k t1) (* k t2))
520 // where >< is the fusion of the combination of the ><i, (flipping each it
521 // its ki is negative). >< is always one of <, <=
522 // NB: this implies that lower bounds must have negative ki,
523 // and upper bounds must have positive ki.
524 // t1 is the sum of the polynomials.
525 // t2 is the sum of the constants.
526 ARITH_SCALE_SUM_UPPER_BOUNDS,
527
528 // ======== Tightening Strict Integer Upper Bounds
529 // Children: (P:(< i c))
530 // where i has integer type.
531 // Arguments: none
532 // ---------------------
533 // Conclusion: (<= i greatestIntLessThan(c)})
534 INT_TIGHT_UB,
535
536 // ======== Tightening Strict Integer Lower Bounds
537 // Children: (P:(> i c))
538 // where i has integer type.
539 // Arguments: none
540 // ---------------------
541 // Conclusion: (>= i leastIntGreaterThan(c)})
542 INT_TIGHT_LB,
543
544 // ======== Trichotomy of the reals
545 // Children: (A B)
546 // Arguments: (C)
547 // ---------------------
548 // Conclusion: (C),
549 // where (not A) (not B) and C
550 // are (> x c) (< x c) and (= x c)
551 // in some order
552 // note that "not" here denotes arithmetic negation, flipping
553 // >= to <, etc.
554 ARITH_TRICHOTOMY,
555
556 // ======== Arithmetic operator elimination
557 // Children: none
558 // Arguments: (t)
559 // ---------------------
560 // Conclusion: arith::OperatorElim::getAxiomFor(t)
561 ARITH_OP_ELIM_AXIOM,
562
563 // ======== Int Trust
564 // Children: (P1 ... Pn)
565 // Arguments: (Q)
566 // ---------------------
567 // Conclusion: (Q)
568 INT_TRUST,
569
570 //================================================= Unknown rule
571 UNKNOWN,
572 };
573
574 /**
575 * Converts a proof rule to a string. Note: This function is also used in
576 * `safe_print()`. Changing this function name or signature will result in
577 * `safe_print()` printing "<unsupported>" instead of the proper strings for
578 * the enum values.
579 *
580 * @param id The proof rule
581 * @return The name of the proof rule
582 */
583 const char* toString(PfRule id);
584
585 /**
586 * Writes a proof rule name to a stream.
587 *
588 * @param out The stream to write to
589 * @param id The proof rule to write to the stream
590 * @return The stream
591 */
592 std::ostream& operator<<(std::ostream& out, PfRule id);
593
594 } // namespace CVC4
595
596 #endif /* CVC4__EXPR__PROOF_RULE_H */