AUGER_LinearLogic - coq/coq GitHub Wiki
The content of a file for linear logic.
The use of a sequent "m, 1"
ā
ā¦
ā¢ ā¦
is not natural and convenient at all for real proving; it is here only to illustrate how to use the Notation system, and what we can do with it.
(** Linear Logic in Coq *)
Require Import Utf8_core.
Require Import List.
Set Implicit Arguments.
Inductive linear_expression: Prop :=
| D: ā (is_positive: bool)
(absolute_value: expression)
, linear_expression
with expression: Prop :=
| A: ā (atom: Prop)
, expression
| B: ā (left_expression: linear_expression)
(is_multiplicative: bool)
(right_expression: linear_expression)
, expression
| C: ā (is_multiplicative: bool)
, expression
| E: ā (delayed_expression: linear_expression)
, expression
.
Notation "a ā b" := (D true (B a true b)) (at level 30).
Notation "a & b" := (D false (B a false b)) (at level 40).
Notation "a ā b" := (D true (B a false b)) (at level 50).
Notation "a ā
b" := (D false (B a true b)) (at level 60).
Notation "š" := (D true (C false)).
Notation "š" := (D true (C true)).
Notation "ā„" := (D false (C true)).
Notation "ā¤" := (D false (C false)).
Notation "! a" := (D true (E a)) (at level 20).
Notation "? a" := (D false (E a)) (at level 20).
Notation "a āŗ" := (D true (A a)) (at level 10, format "a āŗ").
Notation "a ā»" := (D false (A a)) (at level 10, format "a ā»").
Example formula (A: Prop) := (?ā„āAā»)ā!(š&šā
ā¤).
Eval compute in (formula (0>1)).
Fixpoint linear_dual (e: linear_expression) :=
match e with
| D pos abs => D (if pos then false else true) (dual abs)
end
with dual e :=
match e with
| B l m r => B (linear_dual l) m (linear_dual r)
| E l => E (linear_dual l)
| _ => e
end.
Notation "a ā½ā»ā¾" := (linear_dual a) (at level 10).
Eval compute in (Ī» (P: Prop), (formula P)ā½ā»ā¾).
Theorem linear_dual_idempotent: ā Ļ, Ļ = Ļā½ā»ā¾ā½ā»ā¾
with dual_idempotent: ā Ļ, Ļ = dual (dual Ļ).
Proof.
intros [positivity absolute]; simpl.
case dual_idempotent; case positivity; split.
Proof.
intros []; simpl; intros; repeat case linear_dual_idempotent; split.
Qed.
Fixpoint split i (lst: list linear_expression) :=
match i with
| O => (nil, lst)
|S i=> match lst with
| nil => (nil, nil)
|le::lst=> let (l, r) := split i lst in (le::l, r)
end
end.
Inductive all_delayed: list linear_expression ā Prop :=
| NoMoreDelays: all_delayed nil
| MoreDelays: ā l, all_delayed l ā ā le, all_delayed (? le::l).
Inductive three_choices: Set := Birth | Life | Death.
Definition why_choice t le :=
match t with
| Birth => nil
| Life => le::nil
| Death => ? le::? le::nil
end.
Inductive provable: list linear_expression ā Prop :=
| Move: ā n l, provable (let (l, r) := split n l in r++l) ā provable l
| Atom: ā P, provable (Pāŗ::Pā»::nil)
| Times: ā n lst a b, provable (a::(fst (split n lst))) ā
provable (b::(snd (split n lst))) ā
provable (aāb::lst)
| With: ā l a b, provable (a::l) ā provable (b::l) ā provable (a&b::l)
| Plus: ā l a b (c: bool),
provable ((if c then a else b)::l) ā provable (aāb::l)
| Par: ā l a b, provable (a::b::l) ā provable (aā
b::l)
| One: provable (š::nil)
| Bottom: ā l, provable l ā provable (ā„::l)
| Top: ā l, provable (ā¤::l)
| Bang: ā l, all_delayed l ā ā le, provable (le::l) ā provable (! le::l)
| Wnot: ā l t le, provable ((why_choice t le)++l) ā provable (? le::l)
| Cut: ā t n lst, provable (t::(fst (split n lst))) ā
provable (linear_dual t::(snd (split n lst))) ā
provable lst.
Definition stack tl := List.map linear_dual tl.
Inductive these_provable hd tl : Prop :=
ProvableWrapper: provable (hd::(stack tl)) ā
these_provable hd tl.
Notation "ā H1 .. H2 ā¢ J" :=
(these_provable J (H1::..(H2::nil)..))
(at level 100, format
"'[v' ā '/' H1 '/' .. '/' H2 '/' ']' ā¢ J"
).
Notation "ā ā¢ J" :=
(these_provable J nil)
(at level 100, format
"'[v' ā '/' ']' ā¢ J"
).
Tactic Notation "linear" tactic(tac) :=
apply ProvableWrapper;
simpl;
tac;
simpl;
match goal with
| |- provable (?hd::?tl) =>
cut (these_provable hd (stack tl)); simpl;
[now intros []; simpl; clear;
repeat case linear_dual_idempotent
|repeat case linear_dual_idempotent]
end.
Ltac move_ n :=
apply Move with n.
Ltac times_ n :=
apply Times with n.
Ltac left_ :=
apply Plus with true.
Ltac right_ :=
apply Plus with false.
Ltac bang_ :=
apply Bang; [simpl; repeat constructor|].
Ltac weak_ :=
apply Wnot with Birth.
Ltac derel_ :=
apply Wnot with Life.
Ltac contr_ :=
apply Wnot with Death.
Ltac cut_ t n :=
apply Cut with t n.
Lemma linear_em: ā Ļ, āĻā¢Ļ
with lem: ā Ļ b, āD b Ļ ā¢ D b Ļ.
Proof.
clear -lem; intros [b Ļ].
apply lem.
Proof.
clear lem; intros [a|Ļā Ī¼ Ļā|[]|Ļ];
((assert (Ī¦ā := linear_em Ļā); assert (Ī¦ā := linear_em Ļā))
||(assert (Ī¦ := linear_em Ļ))
||idtac); (try case Ī¼); intros []; simpl; clear linear_em.
now linear constructor.
linear move_ 1.
now linear constructor.
linear move_ 1.
linear constructor; move_ 2.
now linear times_ 1.
linear constructor; move_ 2.
now linear times_ 1; move_ 1.
linear move_ 1.
linear constructor; move_ 1.
now linear left_.
now linear right_.
linear constructor; move_ 1.
now linear left_; move_ 1.
now linear right_; move_ 1.
linear move_ 1.
now linear repeat constructor.
now linear repeat constructor.
linear move_ 1.
now linear constructor.
now linear constructor.
linear bang_; move_ 1.
now linear derel_; move_ 1.
linear move_ 1.
linear bang_; move_ 1.
now linear derel_.
Qed.
Goal ā Ļ, ā ā¢Ļā½ā»ā¾ā
Ļ.
intro Ļ.
linear constructor.
apply linear_em.
Qed.