### 1 unstable release

Uses old Rust 2015

0.1.0 | Sep 22, 2017 |
---|

#**896** in Rust patterns

**MIT**license

71KB

1K
SLoC

# path_semantics_std

A Rust type checked implementation of the standard dictionary of path semantics using constrained functions

*Notice! This library is in early stage of development and might contain bugs and missing features!*

### Example: Proving addition of even numbers

`//` Prove `add[even] <=> eq`, which is equal to
`//` `even(add(a, b)) = eq(even(a), even(b))`.
`let` add`:` `Add``<``u32``>` `=` `Add``::`default`(``)``;`
`let` even`:` `Even``<``u32``>` `=` `Even``::`default`(``)``;`
`let` path`:` `Eq``<``bool``>` `=` add`.``path``(`even`)``;`

The Rust type checker proves equivalence of existential paths when calling

.`.`path

It is based on a neat theory of path semantics called "constrained functions".

All you need to do is expressing the theorem directly in Rust code!

The example above can be shortened down to a single line:

`let` path`:` `Eq``<``bool``>` `=` `Add``::``<``u32``>``::`default`(``)``.``path``(``Even``::`default`(``)``)``;`

To change the constrains, use the

method (using variable names for readability):`.`i

`let` path`:` `Eq``<``bool`, `(`Id`<``bool``>`, Not`)``>` `=` add`.``i``(``(`even`,` odd`)``)``.``path``(`even`)``;`

This changes the

function into a partial function,
and it propagates the constraint such that you can see the constraint on the predictor function.`add`

The

method returns an output function:`.`ex_path

`let` res`:` Not `=` add`.``i``(``(`even`,` odd`)``)``.``path``(`even`)``.``ex_path``(``)``;`

In this case we proved that if you add an even number and an odd number, you don't get an even number!

### What is path semantics?

A brief introduction is given here, since most people do not know what it is.

For more information about path semantics, click here.

Path semantics is an attempt to make deep ideas in mathematics more accessible and theorem proving more understandable for programmers. It is an extension and unification of dependently types and guarded commands, that are used today to reason about and verify software. The major difference from existing work is that path semantics is very high level (more expressive) and allows arbitrary constraints and properties defined by functions. This makes path semantics in general undecidable, but it has rules that allows checking for consistency for specific problems, plus the strict concept of function identity that is used when extending the theory to new domains.

The syntax and notation of path semantics is designed to be concise and easily adapted to source code.

means "constrain`f``{`g`}`

with`f``:`A`->`B

".`g``:`A`->``bool`

means "get the constraint of input of`∀f`

".`f`- Existential path:

means "what does`∃f``:`B`->``bool`

outputs? This depends on the constraint.`f``:`A`->`B - Path:

means "the property`f``[`g`]``<=``>`h

of`g``:`A`->`B

is predicted by`f``:`A`->`A

.`h``:`B`->`B - Composition:

outputs`g``.`f

.`∃g``{`∃f`}` - Sub-type:

where`x``:``[`g`]`a

, is consistent if`g``:`X`->`A

.`a``:``[`∃g`]``true` - Naming of functions:

(`false_1``,`not`,`id`,`true_1`:``bool``->``bool`

is generic`id`

).`A``->`A - Surjective xor non-surjective: All "normal" functions has

.`∃∃f``=>``{`id`,`true_1`}` - Reduction of proof:

is equal to`a``:``[`f`]`b ∧`[`g`]`c

or`a``:``[`f`{``[`g`]`c`}``]`b

.`a``:``[`g`{``[`f`]`b`}``]`c - Transform to equations:

gives`f``[`g`]``<=``>`h

(example is for binary functions).`g``(``f``(`a`,`b`)``)``=``h``(``g``(`a`)``,``g``(`b`)``)` - Propagation of constraints to paths: Used for complain-when-wrong type checking.
- Probabilistic existential path: Like existential path, but for probability theory.
- Probabilistic path: A way to predict properties of output probabilistically from properties of input.

The theory of path semantics reveals that functions are related to each other in a natural occuring space called "path semantical space", which precisely defines the identity of all functions. Because the space is organized in a way closely related to the concept of prediction, the research has lot of overlap with artificial intelligence and machine learning. Path semantics is a field that studies how this space is organized and higher order algorithms for extracting and applying knowledge related to perfect and probabilistic prediction. It is not so much about finding solutions to a single problem, but for studying and understanding higher order reasoning to solve large classes of problems.

### Features

All objects in this library are higher order representations of constrained functions. This means they do not "compute" but merely construct types of each other, in a way that Rust can type check.

trait (type`Constrain`

,`.``i``(``<`constrain`>``)`

skips existential path check)`.`i_force

trait (type`ExPath`

)`.``ex_path``(``)`

trait (type`Path`

,`.``path``(``)`

skips existential path check)`.`path_force- Complete Boolean algebra (all paths checked with all constraints)
- Some work on natural numbers

One problem is combinatorial explosion because of the complexity of functional spaces.
To work around this issue, there are some tricks applied to reduce the number of building blocks,
such as using

and `If`

for many non-trivial functions.`IfK`

has a condition that depends on the argument that is dependend on in the branches`If`

has a condition that is decided at higher order, and therefore not depended on in the branches`IfK`

The

type is used instead of a `(``)`

because this looks nicer in Rust.`True1`

### Future Goals

In the short term this library is intended for research only, but if it turns out to be useful for theorem proving, the goal is to develop enough functionality to use it as a core with an ecosystem for domain specific theories.

- Rust's unsigned integer types (u8, u16, u32, u64) for unary and binary operators
- Rust's signed integer types (i8, i16, i32, i64) for unary and binary operators
- Rust's float types
- Vectors
- Complex numbers
- Matrices