# Crate pocket_prover

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: {}", prove!(&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.

#### Path Semantical Logic

Notice! Path Semantical Logic is at early stage of research.

This library has experimental support for a subset of Path Semantical Logic. Implementation is based on paper Faster Brute Force Proofs.

Path Semantical Logic separates propositions into levels, such that an equality between two propositions in level N+1, propagates into equality between uniquely associated propositions in level N.

For example, if `f` has level 1 and `x` has level 0, then `imply(f, x)` associates `x` uniquely with `f`, such that the core axiom of Path Semantics is satisfied.

This library has currently only support for level 1 and 0. These functions are prefixed with `path1_`.

The macros `count!` and `prove!` will automatically expand to `path1_count!` and `path1_prove!`.

Each function takes two arguments, consisting of tuples of propositions, e.g. `(f, g), (x, y)`. Arbitrary number of arguments is supported.

``````extern crate pocket_prover;

use pocket_prover::*;

fn main() {
println!("=== Path Semantical Logic ===");
println!("The notation `f(x)` means `x` is uniquely associated with `f`.");
println!("");

print!("(f(x), g(y), h(z), f=g ⊻ f=h) => (x=y ∨ x=z): ");
println!("{}\n", prove!(&mut |(f, g, h), (x, y, z)| {
imply(
and!(
imply(f, x),
imply(g, y),
imply(h, z),
xor(eq(f, g), eq(f, h))
),
or(eq(x, y), eq(x, z))
)
}));

print!("(f(x), g(y), f=g => h, h(z)) => (x=y => z): ");
println!("{}\n", prove!(&mut |(f, g, h), (x, y, z)| {
imply(
and!(
imply(f, x),
imply(g, y),
imply(eq(f, g), h),
imply(h, z)
),
imply(eq(x, y), z)
)
}));
}``````

#### Path Semantical Quality

Pocket-Prover has a model of Path Semantical Quality that resembles quantum logic.

To write `x ~~ y` you use `q(x, y)` or `qual(x, y)`.

`q(x, y)` is the same as `and!(eq(x, y), qubit(x), qubit(y))`. `q(x, x)` is the same as `qubit(x)`.

A qubit is a kind of “superposition”. One can also think about it as introducing a new argument `qubit(x)` that depends on `x`.

Since qubits can collide with other propositions, one must repeat measurements e.g. using `measure` to get classical states. However, sometimes one might wish to amplify quantum states, using `amplify` or `amp`.

To use quality with path semantics, one should use `ps_core`. Path Semantical Logic is designed for equality, not quality.

``````use pocket_prover::*;

fn main() {
println!("Path semantics: {}", measure(1, || prove!(&mut |a, b, c, d| {
imply(
and!(
ps_core(a, b, c, d),
imply(a, c),
imply(b, d)
),
imply(qual(a, b), qual(c, d))
)
})));
}``````

## Re-exports

`pub use qual as q;`
`pub use aqual as aq;`
`pub use contra_qual as cq;`
`pub use amplify as amp;`

## Modules

Helper utilities for extracting data from proofs.

## Macros

An AND relation of variable arguments.

Evaluates an expression for all bit configurations.

Generates a “{}{}{}…” format for bits.

Path Semantical Logic: A contractible “family of types”.

Counts the number of solutions of a variable argument boolean function.

An IMPLY chain of variable arguments.

An OR relation of variable arguments.

Path Semantical Logic: Counts the number of solutions of a variable argument boolean function.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Prints a truth table with result of a boolean expression.

Prints a truth table extracted from a theory, assigning each case a bit and automatically flip expression properly.

Returns `true` if proposition is correct, `false` otherwise.

Helper macro for counting size of a tuple.

Helper macro for binding to a tuple pattern.

An XOR relation of variable 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

Implemented by base logical systems.

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 observables.

Implemented by provable systems of logic.

## Functions

Enumerates the type, checking that all outputs are true.

Amplify a “wavefunction” of a proposition using its qubit transform.

Returns `true` if all arguments are `true`.

An 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.

Path semantical aquality `a ~¬~ b`.

Path semantical contravariant quality `a ¬~~ b`.

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.

Aligns equality of qubits up to some homotopy level.

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.

Defines a groupoid relation from `x` to `a` and `b`.

Defines an n-groupoid relation from `x` to `a` and `b`.

Defines a homotopy level `n` relation from `x` to `a` and `b`.

Defines a proposition relation of proposition `x` to potential proofs `a` and `b`.

Defines a set relation from a set `x` to potential members `a` and `b`.

Measures result repeatedly.

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.

Path Semantical Logic: Counts the number of solutions of a 1-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a 2-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a 3-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a 4-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a 5-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a 6-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a 7-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a 8-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a 9-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a 10-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a n-argument boolean function,

Path Semantical Logic: Counts the number of solutions of a n+m-argument boolean function,

Path Semantical Logic: Computes number of cases.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

Path Semantical Logic: Returns `true` if proposition is correct, `false` otherwise.

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.

Assumes the path semantical acore axiom.

Assumes the path semantical core axiom.

Path semantical quality `a ~~ b`.

Prepares a qubit using a proposition as seed.

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.

Assumes univalence axiom for some homotopy level.

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.