Tree @master (Download .tar.gz)
Philomath
Version 1.1 | See also: LCF-style-Natural-Deduction ∘ Maxixe ∘ Cardboard Prolog
Philomath is an LCF-style theorem prover written in ANSI C. It implements classical propositional logic inside a Natural Deduction system with labelled assumptions. For more information on this approach, see the LCF-style-Natural-Deduction article.
How do I write a proof with this?
Create a file myproof.c:
#include "formula.h"
#include "proof.h"
int main(int argc, char **argv) {
/* Proof of p -> p */
return proves(
impl_intro(1, suppose(var("p"), 1)),
impl(var("p"), var("p"))
);
}
Then compile and run it with:
./build-proof.sh myproof
And run the resulting executable:
./myproof.exe
If the exit code is 0, the proof is valid!
% echo $?
0
If you wish to build the proof with debugging output, you can pass the -D flag:
./build-proof.sh -D myproof
Limitations
LCF-style theorem proving relies on data abstraction, i.e. information hiding.
In C, information hiding is accomplished by exposing, in a header file, only the
fact that a struct exists, and not exposing its structure. Client code can then
work with pointers to that struct without knowing what's contained in it.
It is however possible to subvert this mechanism. If your proof code does any of the following things, it is possible it is no longer a valid proof:
- includes the file
proof.cdirectly, rather than includingproof.h - casts a
struct theoremvalue to some other type - casts a value of some other type to a
struct theorem
Fortunately, it is possible to statically analyze a C source file and confirm that it does none of these things, if such a level of assurance is desired.
TODO
Should really have even more demo non-proofs, to help ensure that it's not letting non-proofs pass themselves off as proofs somewhere.
History
1.1
- When creating a
struct theoremorstruct assumptions, the suppliedstruct formula *is now cloned (deep-copied) before being stored in the structure. This prevents the theorem from being manipulated after its creation by updating the contents of thestruct formula *that was used to create it. Thanks to Proloy Mishra for pointing out this hole. - More test cases, and a driver script (
test.sh) to run the tests. - Added this "History" section to the README.
1.0-2022.0905
- Renamed
struct theoremtostruct proof, andproof.{c,h}totheorem.{c,h}to better reflect what these objects are.
1.0
- Initial release of Philomath.
Commit History
@master
git clone https://git.catseye.tc/Philomath/
- Update some links. Chris Pressey 2 years ago
- Merge pull request #1 from catseye/develop-202209xx Chris Pressey (commit: GitHub) 3 years ago
- Rename from "proof.c" to "theorem.c" because it defines theorems. Chris Pressey 3 years ago
- Fix typo in comment. Chris Pressey 3 years ago
- "struct theorem" is a better name than "struct proof" for this. Chris Pressey 3 years ago
- Add "see-also bar" to top of README. Chris Pressey 4 years ago
- Add UNLICENSE. Chris Pressey 4 years ago
- "Progress" is done, replace with a "To do" section. Chris Pressey 4 years ago
- Use less confusing (maybe) parameter names x, y, z for input proofs. Chris Pressey 4 years ago
- Implement double_neg_elim. Demo proof of reductio ad absurdum. Chris Pressey 4 years ago
- Implement neg_intro(). Chris Pressey 4 years ago
- Finish the proof by simulating the copy rule with conj-intro-elim. Chris Pressey 4 years ago
- Find and fix a bug in neg_elim. Add `-D` option to build-proof.sh. Chris Pressey 4 years ago
- Checkpoint an incomplete proof that exercises neg_elim, absr_elim. Chris Pressey 4 years ago
- Demonstrate that we do in fact reject incorrectly formed proofs. Chris Pressey 4 years ago
- Implementation of neg_elim() (untested). Chris Pressey 4 years ago
- Absurdum terms, and absr_elim() rule. Chris Pressey 4 years ago
- Add notes to README. Chris Pressey 4 years ago
- Fix bug in disj_elim(). Add demo of disj_intro(), disj_elim(). Chris Pressey 4 years ago
- Fix link. Chris Pressey 4 years ago
- A few improvements and corrections to the README. Chris Pressey 4 years ago
- Example of conj_{intro,elim}. Improve build-proof.sh. Update README. Chris Pressey 4 years ago
- Remove debugging of assumptions in impl_elim. Chris Pressey 4 years ago
- Fix algorithm for merging assumptions. Chris Pressey 4 years ago
- Add debugging prints. merge() assumptions doesn't work, it seems. Chris Pressey 4 years ago
- assumptions_fprint(). Chris Pressey 4 years ago
- formula_fprint(). Chris Pressey 4 years ago
- Have assert() display a diagnostic message. Chris Pressey 4 years ago
- Basic version of proves(), needs debugging. Chris Pressey 4 years ago
- Update README. Chris Pressey 4 years ago