mathematics
, through the lens of
mathematics:
formal definitions
,
formulas
, theorems
, proof
,
theory
, ...
proof of theorems
,theory
is [...]theory
is either incomplete
or inconsistent",
formula
is either:
predicate
\(P\in\mathbb P\)implication
\(A \Rightarrow B\), where \(A,B\)
are formulas
.
conjuction
\(A \land B\), where \(A,B\) are
formulas
.
type formula =
| Predicate of predicate
| Implication of formula * formula
| Conjunction of formula * formula
proof
in context \(\mathbb C\) is either:
if \(F\in\mathbb C\).\(F\in\mathbb C\). We conclude \(F\).
\(T_1\) is a proof of \(P_1\). \(T_2\) is a proof of \(P_2\). We conclude \(P_1\land P_2\)
\(T\) is a proof of \(P\land Q\). We conclude \(P\)
where \(T\) is aSuppose \(P_1\). \(T\) is proof of \(P_2\). We conclude \(P_1\Rightarrow P_2\)
proof
of \(P_2\) in context
\(\{P_1\}\cup\mathbb C\)
\(T_q\) is a proof of \(Q\). \(T_p\) is a proof of \(Q\Rightarrow P\). We conclude \(P\).
type context = formula list (* [F_0 ; ... ; F_n] *)
and proof = context * proof_desc
and proof_desc =
| Axiom of int
| And_intro of proof * proof
| And_elim_left of proof
| And_elim_right of proof
| Implication_intro of proof
| Implication_elim of proof * proof
formula
is provable
if and only if it is
true "for any interpretation
of the
predicates
".
A model
is an interpretation of all predicates:
type model = predicate -> bool
A formula
is true in a model
if:
let rec validity formula m = match formula with
| Predicate p -> m p
| Implication (f1, f2) ->
if validity f1 m then validity f2 m else true
| Conjuction (f1, f2) -> validity f1 m && validity f2 m
formula
is provable
with context \(((P\Rightarrow Q)\Rightarrow P)\Rightarrow
P\)
if and only if it is true "for any interpretation
of
the predicates
".
formula
is provable
if and only if it is
true "for any Kripke-interpretation
of the predicates
".
OCaml has types:
type type_ =
| Var of var
| Arrow of type_ * type_
| Tuple2 of type_ * type_
| ...
OCaml has typed values:
type context = type_ list (* [t_0 ; ... ; t_n ] *)
and value_ = context * value_desc
and value_desc =
| Var of int
| Tuple_construct of value_ * value_
| Tuple_destruct_left of value_
| And_destruct_right of value_
| Arrow_construct of value_ (* [fun x -> ] *)
| Arrow_destruct of value_ * value_ (* f x *)
| ...
Wait a minute... We've seen that already!
Logic | Computer-science |
---|---|
Formulas | Types |
\(A\Rightarrow A\) | a -> a |
\((A\land B)\Rightarrow (A\Rightarrow C)\Rightarrow C\) | (a * b) -> (a -> c) -> c |
Proofs | Programs |
Suppose A then A by assumption | fun x -> x |
Suppose \(A\land B\), suppose \(A\Rightarrow C\), we have \(A\land B\) by hypothesis so we conclude \(A\), we have \(A\Rightarrow C\) by hypothesis, so we conclude \(C\), so we conclude \((A\Rightarrow C)\Rightarrow C\), so we conclude \((A\land B)\Rightarrow(A\Rightarrow C)\Rightarrow C\) | fun (a, b) f -> f a |
Using a lemma | Applying a function |
There is a proof of \(F\) |
There is a value of type t
|
\(A\) is not provable | No value has type 'a |
\(((P\Rightarrow Q)\Rightarrow P)\Rightarrow P\) is not provable |
No value has type(('p -> 'q) -> 'p) -> 'p
|
\(\bot\) | type impossible = | ;; |
\(A\lor B\) | type or = A of a | B of b ;; |
... | ... |
First, we modeled the mathematics, inside the mathematics.
Now, let's be a mathematician, modeling a mathematician
, in
mathematics.
mathematician
is:
mathematician
be so strong that they can
recognize what's true and what is not?
We will prove this superperson
does not exist, going
through computer science!
mathematician
is a Turing Machine!mathematician
is an OCaml program.
val terminates : program:string -> input:string -> bool
(** tells whether the program with given input would terminate *)
let grumpy program =
if terminates ~program input:program then
while true do done
else
() ;;
grumpy "let grumpy program = [...]"
If grumpy "<grumpy>"
terminates...
it enters an infinite loop!
mathematician
proves exactly what's true.
terminates
as follows:
let look_for_proof formula =
Seq.find (is_proof_of formula) all_proofs_seq
let terminates program =
let terminates = formula (program ^ " terminates") in
Eio.first
(() -> look_for_proof terminates ; true)
(() -> look_for_proof (Not (terminates)) ; false)
Contradiction.
module type I = sig
module type A
module F : functor
(X : sig
module type A = A
module F : functor (X : A) -> sig end
end)
-> sig end
end
module type J = sig
module type A = I
module F : functor (X : I) -> sig end
end
module Loop (X : J) : I = X
Usual behaviour of computability theorists:
Actually, no need to do all of this: computability was hidden in all mathematic all along!
val f : int -> bool
(** {math n \in A} iff [f n] is [true] *)
can be implemented in OCaml.