git @ Cat's Eye Technologies Philomath / 3f4a98e
Find and fix a bug in neg_elim. Add `-D` option to build-proof.sh. Chris Pressey 2 years ago
5 changed file(s) with 33 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
3434
3535 % echo $?
3636 0
37
38 If you wish to build the proof with debugging output, you can pass the `-D` flag:
39
40 ./build-proof.sh -D myproof
3741
3842 Limitations
3943 -----------
7579 - [x] demo proof showing disj_elim
7680
7781 - [x] demo bad proof (ought to really be a number of these)
78 - [ ] debug flag for (or debug version of) `build-proof.sh`
82 - [x] debug flag for (or debug version of) `build-proof.sh`
7983
8084 - [ ] Use names of greek letters for arguments to the functions
8185
00 #!/bin/sh -ex
11
2 ./build.sh
2 CFLAGS=""
3 if [ "x$1" = "x-D" ]; then
4 CFLAGS="-DDEBUG"
5 shift
6 fi
7 CFLAGS=${CFLAGS} ./build.sh
38 PROOF=$1
49 CC="gcc -ansi -pedantic"
510 ${CC} -Iinclude $PROOF.c src/*.o -o $PROOF.exe
11
22 CC="gcc -ansi -pedantic"
33 for MODULE in assert formula assumptions proof; do
4 (cd src && ${CC} -I../include -c $MODULE.c -o $MODULE.o)
4 (cd src && ${CC} ${CFLAGS} -I../include -c $MODULE.c -o $MODULE.o)
55 done
1111 * Hence, p -> q by (3)
1212 * Now, suppose q (4)
1313 * Further, suppose p (5)
14 * Hence, p -> q by (5)
14 * Hence, p -> q by (5) -- FIXME
1515 * So, p -> q by disj_elim with (2), (4)
1616 * So, ~p \/ q -> (p -> q) by (1)
1717 */
2020 #include "proof.h"
2121
2222 int main(int argc, char **argv) {
23 struct proof *step1 = suppose(disj(neg(var("p")), var("q")), 1);
24 struct proof *step2 = suppose(neg(var("p")), 2);
25 struct proof *step3 = suppose(var("p"), 3);
26 struct proof *step4 = neg_elim(step3, step2);
27 /* ... TODO ... */
28 struct proof *step99 = impl_intro(1, step1);
23 struct proof *step1 = suppose(disj(neg(var("p")), var("q")), 1); /* Suppose ~p \/ q (1) */
24 struct proof *step2 = suppose(neg(var("p")), 2); /* Now, suppose ~p (2) */
25 struct proof *step3 = suppose(var("p"), 3); /* Further, suppose p (3) */
26 struct proof *step4 = neg_elim(step3, step2); /* So bottom, by neg_elim */
27 struct proof *step5 = absr_elim(step4, var("q")); /* Hence q, by absr_elim */
28 struct proof *step6 = impl_intro(3, step5); /* Hence, p -> q by (3) */
29 struct proof *step7 = suppose(var("q"), 4); /* Now, suppose q (4) */
30 struct proof *step8 = suppose(var("p"), 5); /* Further, suppose p (5) */
31 struct proof *step9 = impl_intro(5, step8); /* Hence, p -> q by (5) */
32 /* ... TODO ... */ /* So, p -> q by disj_elim with (2), (4) */
33 /* ... TODO ... */ /* So, ~p \/ q -> (p -> q) by (1) */
2934
3035 return proves(
31 step99,
36 step1,
3237 impl(disj(neg(var("p")), var("q")), impl(var("p"), var("q")))
3338 );
3439 }
8888 /* If q is proved under the assumption p, then p -> q is proved. */
8989 struct formula *f = lookup(label, q->assumptions);
9090 struct assumptions *a = discharge(label, q->assumptions);
91 #ifdef DEBUG
92 if (f == NULL) {
93 fprintf(stdout, "Label %d not found in:", label);
94 assumptions_fprint(stdout, a);
95 fprintf(stdout, "\n");
96 }
97 #endif
9198 assert(f != NULL, "impl_intro: label not found in assumptions");
9299 return mk_proof(
93100 a,
164171 neg_elim(struct proof *p, struct proof *q)
165172 {
166173 assert(q->conclusion->type == NEG, "neg_elim: not a negation");
167 assert(formula_eq(p->conclusion, q->conclusion->lhs), "neg_elim: mismatched conclusions");
174 assert(formula_eq(p->conclusion, q->conclusion->rhs), "neg_elim: mismatched conclusions");
168175 return mk_proof(
169176 merge(p->assumptions, q->assumptions),
170177 absr()