add examples and reference

This commit is contained in:
Arkitu 2025-12-20 19:11:28 +01:00
parent 096aeabd6d
commit efc220b38f
4 changed files with 129 additions and 0 deletions

7
Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "plouf"
version = "0.1.0"

44
doc/README.md Normal file
View File

@ -0,0 +1,44 @@
This is a reference for the language. It is for now in construction, messy and can change at any time.
- Comments are C style comments
## Predicates
- You can create a predicate with `let predicate_name = predicate`
- You can create an implication with `let predicate_name = conditions => result` where conditions and result are predicates
- Predicates have to be proven with `predicate : {proof}` in order to be used in other proofs
- You can combine predicates with `(predicate1; predicate2; predicate3)`
## Truths
- A truth is a predicate that has been proven to be true
- A predicate alone is interpreted as a truth : `predicate;`
## Axioms
- You can use `ax` instead of `let` to define an axiom, or any externaly proven predicate
- Axioms are considered true without needing a proof
## Proofs
- You can prove a new predicate by "running" a true predicate `p1` on an other true predicate `p2` that fulfill its conditions : `let p = predicate : {p1(p2)}`
- The verifier will do its best to prove your predicates automatically, and tell you were it has not been able to
## Variables
- You have to define a set/type before doing anything with a variable : `let x in set.R`
- You can define multiple variable with the same type together : `let a,b,c in set.N`
- If you give a value to a variable, the type is implicit : `let x = 3`
- Variable definition is a predicate, but you don't have to prove it
- In a predicate combination, you can define a variable in a predicate and use it in another predicate : `(n in set.N, n/2=0)`
- If you define a variable with the same name as an other one, it will shadow it during the time of its existence
## Expressions
- Expressions are OCamL style
- They are evaluated from left to right (generally)
## Functions
- Predicates are functions that take truths as input and return a truth
- You can use `_` instead of an argument and the verifier will try to deduce what didn't put. For example, if a truth is needed as an argument, the verifier will try to prove it itself

71
examples/complex.plf Normal file
View File

@ -0,0 +1,71 @@
import set.Predicate as P;
import set.Truth as T;
import func.Function as F;
import set.R;
import set.N;
import set.parts;
import set.Finite;
import lim.infty;
ax rec = (
p in P;
init in N;
p(init);
n in [init;infty[ => (
p n => (p (n+1))
)
) => (
n in [init; infty[ => (p n)
);
ax triangle_inequality = a,b in R => abs (a+b) <= (abs a + (abs b));
let f in F(R, R);
let alpha in [0; 1[;
let u in F(R, N);
// axioms
ax ax1 = f is func.Continuous;
ax ax2 = (x,y) in R^2 => (
abs (f x - (f y)) <= (alpha * (abs (x-y)))
);
ax ax3 = u(0) = 0;
ax ax4 = n in N => (
u (n+1) = (f (u n));
abs (u (n+1) - (u n)) <= (alpha^n * (abs (u 1)))
);
let n,p in N;
ax a6 = n <= p;
let x = u(p)-u(n);
x = sum (k in [|n,p-1|]) (u(k+1)-u(k)) : {
rec
(
l in N => (
u(l+1)-u(n) = sum(k in [|n, l|], u(k+1)-u(k))
)
)
n
_
(
l in [init;infty[ => (
let rec_p = u(l+1)-u(n) = sum(k in [|n, l|], u(k+1)-u(k));
rec_p => u(l+2)-u(n) = sum(k in [|n, l+1|], u(k+1)-u(k)) : {
let x = u(l+2)-u(n);
x = u(l+2)-u(l+1) + u(l+1)-u(n);
x = u(l+2)-u(l+1) + sum(k in [|n, l|], u(k+1)-u(k)) : {rec_p};
x = sum(k in [|n, l+1|], u(k+1)-u(k))
}
)
)
}
// TODO : Finish this example
abs x <= (sum (k in [|n, p-1|]) (abs (u (k+1) - (u k)))) : {
rec
(
l in N => abs (sum (k in [|n,p-1|]) (u(k+1)-u(k)))
)
}

View File

@ -0,0 +1,7 @@
let Even in Sets;
ax a2 = (x in N, x/2 = 0) => x in Even;
let n = 4;
n in Even : {
a2(n)
}