Crate pocket_prover

source ·
Expand description

pocket_prover

A fast, brute force, automatic theorem prover for first order logic

extern crate pocket_prover;

use pocket_prover::*;

fn main() {
    println!("Socrates is mortal: {}", prove3(&mut |man, mortal, socrates| {
        // Using `imply` because we want to prove an inference rule.
        imply(
            // Premises.
            and(
                // All men are mortal.
                imply(man, mortal),
                // Socrates is a man.
                imply(socrates, man),
            ),

            // Conclusion.
            imply(socrates, mortal)
        )
    }));
}

Motivation

The motivation is to provide the analogue of a “pocket calculator”, but for logic, therefore called a “pocket prover”.

This library uses an approach that is simple to implement from scratch in a low level language.

This is useful in cases like:

  • Study logic without the hurdle of doing manual proofs
  • Checking your understanding of logic
  • Verify that logicians are wizards and not lizards
  • Due to a series of unfortunate events, you got only 24 hours to learn logic and just need the gist of it
  • Memorizing source code for situations like The Martian
  • A tiny mistake and the whole planet blows up (e.g. final decisions before the AI singularity and you need to press the right buttons)

In addition this library can be used to create extensible logical systems. For more information, see the Prove trait.

Implementation

This library uses brute-force to check proofs, instead of relying on axioms of logic.

64bit CPUs are capable of checking logical proofs of 6 arguments (booleans) in O(1), because proofs can be interpreted as tautologies (true for all input) and 2^6 = 64.

This is done by replacing bool with u64 and organizing inputs using bit patterns that simulate a truth table of 6 arguments.

To extend to 10 arguments, T and F are used to alternate the 4 extra arguments. To extend to N arguments, recursive calls are used down to less than 10 arguments.

Constants

The False proposition. Used to alternate higher than 6 arguments, set to 0.
0xaaaa_aaaa_aaaa_aaaa
0xcccc_cccc_cccc_cccc
0xf0f0_f0f0_f0f0_f0f0
0xff00_ff00_ff00_ff00
0xffff_0000_ffff_0000
0xffff_ffff_0000_0000
The True proposition. Used to alternate higher than 6 arguments, set to 1.

Traits

Used to construct logical systems.
Implemented by logical systems to define core rules.
Implemented by types to use with all and any.
Implemented by logical systems to extend existing ones.
Implemented by provable systems of logic.

Functions

Enumerates the type, checking that all outputs are true.
Returns true if all arguments are true.
And and relation of 3 argument.
An and relation of 4 arguments.
An and relation of 5 arguments.
An and relation of 6 arguments.
An and relation of 7 arguments.
An and relation of 8 arguments.
An and relation of 9 arguments.
An and relation of 10 arguments.
An and relation of variable number of arguments.
Enumerates the type, checking that at least one output is true.
Counts the number of solutions of a 1-argument boolean function.
Counts the number of solutions of a 2-argument boolean function.
Counts the number of solutions of a 3-argument boolean function.
Counts the number of solutions of a 4-argument boolean function.
Counts the number of solutions of a 5-argument boolean function.
Counts the number of solutions of a 6-argument boolean function.
Counts the number of solutions of a 7-argument boolean function.
Counts the number of solutions of an 8-argument boolean function.
Counts the number of solutions of a 9-argument boolean function.
Counts the number of solutions of a 10-argument boolean function.
Counts the number of solutions of an n-argument boolean function.
Returns true if arguments are equal.
Ignores argument, always returning false.
Ignores both arguments, returning false for all inputs.
Ignores all 3 arguments, returning false for all inputs.
Ignores all 4 arguments, returning false for all inputs.
Ignores all 5 arguments, returning false for all inputs.
Ignores all 6 arguments, returning false for all inputs.
Ignores all 7 arguments, returning false for all inputs.
Ignores all 8 arguments, returning false for all inputs.
Ignores all 9 arguments, returning false for all inputs.
Ignores all 10 arguments, returning false for all inputs.
Returns argument.
First argument implies the second.
An imply chain of 3 arguments.
An imply chain of 4 arguments.
An imply chain of 5 arguments.
An imply chain of 6 arguments.
An imply chain of 7 arguments.
An imply chain of 8 arguments.
An imply chain of 9 arguments.
An imply chain of 10 arguments.
An imply chain of variable number of arguments.
If input is true, returns false and vice versa.
Returns true if at least one argument is true.
An or relation of 3 arguments.
An or relation of 4 arguments.
An or relation of 5 arguments.
An or relation of 6 arguments.
An or relation of 7 arguments.
An or relation of 8 arguments.
An or relation of 9 arguments.
An or relation of 10 arguments.
An or relation of variable number of arguments.
Returns T if a is true, F otherwise. In logical terminology this corresponds to a proposition.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Returns true if proposition is correct, false otherwise.
Ignores argument, always returning true.
Ignores both arguments, returning true for all inputs.
Ignores all 3 arguments, returning true for all inputs.
Ignores all 4 arguments, returning true for all inputs.
Ignores all 5 arguments, returning true for all inputs.
Ignores all 6 arguments, returning true for all inputs.
Ignores all 7 arguments, returning true for all inputs.
Ignores all 8 arguments, returning true for all inputs.
Ignores all 9 arguments, returning true for all inputs.
Ignores all 10 arguments, returning true for all inputs.
Returns true if only one argument is true.
An xor relation of 3 arguments.
An xor relation of 4 arguments.
An xor relation of 5 arguments.
An xor relation of 6 arguments.
An xor relation of 7 arguments.
An xor relation of 8 arguments.
An xor relation of 9 arguments.
An xor relation of 10 arguments.
An xor relation of variable number of arguments.

Type Definitions

A boolean function of one argument.
A boolean function (transformed) of two arguments.