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.c
directly, rather than includingproof.h
- casts a
struct theorem
value 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 theorem
orstruct 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 theorem
tostruct 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/
- Arrange licensing info in repo according to REUSE 3.2 convention. Chris Pressey 2 months ago
- Update README. Chris Pressey 11 months ago
- Demo trying to manipulate formula after theorem has been built. Chris Pressey 11 months ago
- Merge branch 'master' into develop-2023.12xx Chris Pressey 11 months ago
- Add another example non-proof. Chris Pressey 11 months ago
- We don't actually need to protect assumptions; proof internals. Chris Pressey 11 months ago
- Clone (deep copy) formulas and assumptions when using them. Chris Pressey 11 months ago
- Improve the test driver script. Chris Pressey 11 months ago
- Move towards protecting the assumptions and formula in theorems. Chris Pressey 11 months ago
- Add a rudimentary test driver which is very rudimentary. Chris Pressey 11 months ago