Mix.v 29.5 KB
Newer Older
1

Pierre Letouzey's avatar
Pierre Letouzey committed
2
3
4
5
(** * Natural deduction, with a Locally Nameless encoding *)

(** The NatDed development, Pierre Letouzey, 2019.
    This file is released under the CC0 License, see the LICENSE file *)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

Require Import Defs.
Require DecimalString.
Import ListNotations.
Local Open Scope bool_scope.
Local Open Scope lazy_bool_scope.
Local Open Scope string_scope.
Local Open Scope eqb_scope.
(** We use here a Locally nameless representation of terms.
    See for instance http://www.chargueraud.org/research/2009/ln/main.pdf
*)

(** A term is given by the following recursive definition: *)

Inductive term :=
  | FVar : variable -> term (** Free variable (global name) *)
  | BVar : nat -> term (** Bounded variable (de Bruijn indices) *)
  | Fun : function_symbol -> list term -> term.

Definition Cst (f:function_symbol) := Fun f [].

Definition peano_term_example :=
  Fun "+" [Fun "S" [Cst "O"]; FVar "x"].

(** In the case of Peano, numbers are coded as iterated successors of zero *)

Fixpoint nat2term n :=
  match n with
  | O => Cst "O"
  | S n => Fun "S" [nat2term n]
  end.

Fixpoint term2nat t :=
  match t with
  | Fun f [] => if f =? "O" then Some O else None
  | Fun f [t] => if f =? "S" then option_map S (term2nat t) else None
  | _ => None
  end.

(** Term printing

    NB: + and * are printed in infix position, S(S(...O())) is printed as
    the corresponding number.
*)

Definition print_tuple {A} (pr: A -> string) (l : list A) :=
 "(" ++ String.concat "," (List.map pr l) ++ ")".

Definition is_binop s := list_mem s ["+";"*"].

Fixpoint print_term t :=
  match term2nat t with
  | Some n => DecimalString.NilZero.string_of_uint (Nat.to_uint n)
  | None =>
     match t with
     | FVar v => v
     | BVar n => "#" ++ DecimalString.NilZero.string_of_uint (Nat.to_uint n)
     | Fun f args =>
       if is_binop f then
         match args with
         | [t1;t2] =>
           "(" ++ print_term t1 ++ ")" ++ f ++ "(" ++ print_term t2 ++ ")"
         | _ => f ++ print_tuple print_term args
         end
       else f ++ print_tuple print_term args
     end
  end.

Compute print_term peano_term_example.

(** Term parsing *)

(** Actually, parsing is not so easy and not so important.
    Let's put the details elsewhere, and take for granted that
    parsing is doable :-).
*)

(* TODO: formula parsing *)

Pierre Letouzey's avatar
Pierre Letouzey committed
85
86
87
88
89

(** Some generic functions, meant to be overloaded
    with instances for terms, formulas, context, sequent, ... *)

(** Check for known function/predicate symbols + correct arity *)
90
Class Check (A : Type) := check : signature -> A -> bool.
Pierre Letouzey's avatar
Pierre Letouzey committed
91
92
93
94
95
96
97
98
99
100
101
Arguments check {_} {_} _ !_.

(** Replace a bound variable with a term *)
Class BSubst (A : Type) := bsubst : nat -> term -> A -> A.
Arguments bsubst {_} {_} _ _ !_.

(** Level : succ of max bounded variable *)
Class Level (A : Type) := level : A -> nat.
Arguments level {_} {_} !_.

(** Compute the set of free variables *)
Pierre Letouzey's avatar
Pierre Letouzey committed
102
Class FVars (A : Type) := fvars : A -> Names.t.
Pierre Letouzey's avatar
Pierre Letouzey committed
103
104
105
106
107
108
109
110
Arguments fvars {_} {_} !_.

(** General replacement of free variables *)
Class VMap (A : Type) := vmap : (variable -> term) -> A -> A.
Arguments vmap {_} {_} _ !_.

(** Some generic definitions based on the previous ones *)

111
Definition BClosed {A}`{Level A} (a:A) := level a = 0.
112

Pierre Letouzey's avatar
Pierre Letouzey committed
113
Definition FClosed {A}`{FVars A} (a:A) := Names.Empty (fvars a).
114
115

Hint Unfold BClosed FClosed.
Pierre Letouzey's avatar
Pierre Letouzey committed
116
117
118
119
120
121
122
123
124
125
126
127

(** Substitution of a free variable in a term :
    in [t], free var [v] is replaced by [u]. *)

Definition varsubst v u x := if v =? x then u else FVar x.

Definition fsubst {A}`{VMap A} (v:variable)(u:term) :=
 vmap (varsubst v u).

(** Some structural extensions of these generic functions *)

Instance check_list {A}`{Check A} : Check (list A) :=
128
 fun (sign : signature) => List.forallb (check sign).
Pierre Letouzey's avatar
Pierre Letouzey committed
129
130
131
132
133
134
135
136

Instance bsubst_list {A}`{BSubst A} : BSubst (list A) :=
 fun n t => List.map (bsubst n t).

Instance level_list {A}`{Level A} : Level (list A) :=
 fun l => list_max (List.map level l).

Instance fvars_list {A}`{FVars A} : FVars (list A) :=
Pierre Letouzey's avatar
Pierre Letouzey committed
137
 Names.unionmap fvars.
Pierre Letouzey's avatar
Pierre Letouzey committed
138
139
140
141
142

Instance vmap_list {A}`{VMap A} : VMap (list A) :=
 fun h => List.map (vmap h).

Instance check_pair {A B}`{Check A}`{Check B} : Check (A*B) :=
143
 fun (sign : signature) '(a,b) => check sign a &&& check sign b.
Pierre Letouzey's avatar
Pierre Letouzey committed
144
145
146
147
148
149
150
151

Instance bsubst_pair {A B}`{BSubst A}`{BSubst B} : BSubst (A*B) :=
 fun n t '(a,b) => (bsubst n t a, bsubst n t b).

Instance level_pair {A B}`{Level A}`{Level B} : Level (A*B) :=
 fun '(a,b) => Nat.max (level a) (level b).

Instance fvars_pair {A B}`{FVars A}`{FVars B} : FVars (A*B) :=
Pierre Letouzey's avatar
Pierre Letouzey committed
152
 fun '(a,b) => Names.union (fvars a) (fvars b).
Pierre Letouzey's avatar
Pierre Letouzey committed
153
154
155
156
157

Instance vmap_pair {A B}`{VMap A}`{VMap B} : VMap (A*B) :=
 fun h '(a,b) => (vmap h a, vmap h b).


158
159
160
161
(** With respect to a particular signature, a term is valid
    iff it only refer to known function symbols and use them
    with the correct arity. *)

Pierre Letouzey's avatar
Pierre Letouzey committed
162
Instance check_term : Check term :=
163
 fun (sign : signature) =>
Pierre Letouzey's avatar
Pierre Letouzey committed
164
 fix check_term t :=
165
166
167
 match t with
  | FVar _ | BVar _ => true
  | Fun f args =>
168
     match sign.(funsymbs) f with
169
170
     | None => false
     | Some ar =>
Pierre Letouzey's avatar
Pierre Letouzey committed
171
       (List.length args =? ar) &&& (List.forallb check_term args)
172
173
174
     end
 end.

175
Compute check (Finite.to_infinite peano_sign) peano_term_example.
Pierre Letouzey's avatar
Pierre Letouzey committed
176
177
178

Instance term_fvars : FVars term :=
 fix term_fvars t :=
179
 match t with
Pierre Letouzey's avatar
Pierre Letouzey committed
180
181
182
 | BVar _ => Names.empty
 | FVar v => Names.singleton v
 | Fun _ args => Names.unionmap term_fvars args
183
184
 end.

Pierre Letouzey's avatar
Pierre Letouzey committed
185
186
Instance term_level : Level term :=
 fix term_level t :=
187
188
189
190
191
192
 match t with
 | BVar n => S n
 | FVar v => 0
 | Fun _ args => list_max (map term_level args)
 end.

Pierre Letouzey's avatar
Pierre Letouzey committed
193
194
195
Instance term_bsubst : BSubst term :=
 fun n u =>
 fix bsubst t :=
196
197
198
  match t with
  | FVar v => t
  | BVar k => if k =? n then u else t
Pierre Letouzey's avatar
Pierre Letouzey committed
199
  | Fun f args => Fun f (List.map bsubst args)
200
201
  end.

Pierre Letouzey's avatar
Pierre Letouzey committed
202
203
204
205
206
207
208
209
Instance term_vmap : VMap term :=
 fun (h:variable->term) =>
 fix vmap t :=
  match t with
  | BVar _ => t
  | FVar x => h x
  | Fun f args => Fun f (List.map vmap args)
  end.
Pierre Letouzey's avatar
Pierre Letouzey committed
210
211
212
213
214
215
216
217
218
219
220

Instance term_eqb : Eqb term :=
 fix term_eqb t1 t2 :=
  match t1, t2 with
  | BVar n1, BVar n2 => n1 =? n2
  | FVar v1, FVar v2 => v1 =? v2
  | Fun f1 args1, Fun f2 args2 =>
    (f1 =? f2) &&& (list_forallb2 term_eqb args1 args2)
  | _, _ => false
  end.

221
222
223
224
225
226
227
Fixpoint lift t :=
 match t with
 | BVar n => BVar (S n)
 | FVar v => FVar v
 | Fun f args => Fun f (List.map lift args)
 end.

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
(** Formulas *)

Inductive formula :=
  | True
  | False
  | Pred : predicate_symbol -> list term -> formula
  | Not : formula -> formula
  | Op : op -> formula -> formula -> formula
  | Quant : quant -> formula -> formula.

(** Note the lack of variable name after [Quant], we're using
    de Bruijn indices there. *)

(** One extra pseudo-constructor :
    [a<->b] is a shortcut for [a->b /\ b->a] *)

Definition Iff a b := Op And (Op Impl a b) (Op Impl b a).

(** Formula printing *)

(** Notes:
    - We use {  } for putting formulas into parenthesis, instead of ( ).
*)

Definition is_infix_pred s := list_mem s ["=";"∈"].

(* TODO affichage court du <-> *)

Fixpoint print_formula f :=
  match f with
  | True => "True"
  | False => "False"
  | Pred p args =>
    if is_infix_pred p then
      match args with
      | [t1;t2] =>
        "(" ++ print_term t1 ++ ")" ++ p ++ "(" ++ print_term t2 ++ ")"
      |  _ => p ++ print_tuple print_term args
      end
    else p ++ print_tuple print_term args
  | Not f => "~{" ++ print_formula f ++ "}"
  | Op o f f' =>
    "{" ++ print_formula f ++ "}" ++ pr_op o ++ "{" ++ print_formula f' ++ "}"
  | Quant q f => pr_quant q ++ "{" ++ print_formula f ++ "}"
  end.

Compute print_formula (Quant Ex True).

Compute print_formula (Iff True False).

(* TODO: Formula parsing *)

(* Instead : Coq notations *)

Delimit Scope formula_scope with form.
Bind Scope formula_scope with formula.

Notation "~ f" := (Not f) : formula_scope.
Infix "/\" := (Op And) : formula_scope.
Infix "\/" := (Op Or) : formula_scope.
Infix "->" := (Op Impl) : formula_scope.
Infix "<->" := Iff : formula_scope.

291
Notation "# n" := (BVar n) (at level 20, format "# n") : formula_scope.
292
293
294
295
296
297
298
299
300
301

Notation " A" := (Quant All A)
 (at level 200, right associativity) : formula_scope.
Notation " A" := (Quant Ex A)
 (at level 200, right associativity) : formula_scope.

Definition test_form := (∃ (True <-> Pred "p" [#0;#0]))%form.

(** Utilities about formula *)

Pierre Letouzey's avatar
Pierre Letouzey committed
302
Instance check_formula : Check formula :=
303
 fun (sign : signature) =>
Pierre Letouzey's avatar
Pierre Letouzey committed
304
 fix check_formula f :=
305
306
  match f with
  | True | False => true
Pierre Letouzey's avatar
Pierre Letouzey committed
307
308
309
  | Not f => check_formula f
  | Op _ f f' => check_formula f &&& check_formula f'
  | Quant _ f => check_formula f
310
  | Pred p args =>
311
     match sign.(predsymbs) p with
312
313
     | None => false
     | Some ar =>
Pierre Letouzey's avatar
Pierre Letouzey committed
314
       (List.length args =? ar) &&& (List.forallb (check sign) args)
315
316
317
     end
  end.

Pierre Letouzey's avatar
Pierre Letouzey committed
318
319
Instance form_level : Level formula :=
  fix form_level f :=
320
321
  match f with
  | True | False => 0
Pierre Letouzey's avatar
Pierre Letouzey committed
322
  | Not f => form_level f
323
324
  | Op _ f f' => Nat.max (form_level f) (form_level f')
  | Quant _ f => Nat.pred (form_level f)
Pierre Letouzey's avatar
Pierre Letouzey committed
325
  | Pred _ args => list_max (map level args)
326
327
  end.

328
329
330
331
332
333
(** Substitution of a bounded variable by a term [t] in a formula [f].
    Note : we try to do something sensible when [t] has itself some
    bounded variables (we lift them when entering [f]'s quantifiers).
    But this situtation is nonetheless to be used with caution.
    Actually, we'll almost always use [bsubst] when [t] is [BClosed],
    except in [Peano.v]. *)
334

Pierre Letouzey's avatar
Pierre Letouzey committed
335
336
Instance form_bsubst : BSubst formula :=
 fix form_bsubst n t f :=
337
338
 match f with
  | True | False => f
Pierre Letouzey's avatar
Pierre Letouzey committed
339
  | Pred p args => Pred p (List.map (bsubst n t) args)
340
341
  | Not f => Not (form_bsubst n t f)
  | Op o f f' => Op o (form_bsubst n t f) (form_bsubst n t f')
342
  | Quant q f' => Quant q (form_bsubst (S n) (lift t) f')
343
344
 end.

Pierre Letouzey's avatar
Pierre Letouzey committed
345
346
347
Instance form_fvars : FVars formula :=
 fix form_fvars f :=
  match f with
Pierre Letouzey's avatar
Pierre Letouzey committed
348
  | True | False => Names.empty
Pierre Letouzey's avatar
Pierre Letouzey committed
349
  | Not f => form_fvars f
Pierre Letouzey's avatar
Pierre Letouzey committed
350
  | Op _ f f' => Names.union (form_fvars f) (form_fvars f')
Pierre Letouzey's avatar
Pierre Letouzey committed
351
  | Quant _ f => form_fvars f
Pierre Letouzey's avatar
Pierre Letouzey committed
352
  | Pred _ args => Names.unionmap fvars args
Pierre Letouzey's avatar
Pierre Letouzey committed
353
  end.
Pierre Letouzey's avatar
Pierre Letouzey committed
354

Pierre Letouzey's avatar
Pierre Letouzey committed
355
356
357
358
359
360
361
362
363
364
Instance form_vmap : VMap formula :=
 fun (h:variable->term) =>
 fix form_vmap f :=
   match f with
   | True | False => f
   | Pred p args => Pred p (List.map (vmap h) args)
   | Not f => Not (form_vmap f)
   | Op o f f' => Op o (form_vmap f) (form_vmap f')
   | Quant q f' => Quant q (form_vmap f')
   end.
365

Pierre Letouzey's avatar
Pierre Letouzey committed
366
367
Instance form_eqb : Eqb formula :=
 fix form_eqb f1 f2 :=
368
369
370
  match f1, f2 with
  | True, True | False, False => true
  | Pred p1 args1, Pred p2 args2 =>
Pierre Letouzey's avatar
Pierre Letouzey committed
371
    (p1 =? p2) &&& (args1 =? args2)
372
373
374
375
376
377
378
379
380
381
  | Not f1, Not f2 => form_eqb f1 f2
  | Op o1 f1 f1', Op o2 f2 f2' =>
    (o1 =? o2) &&&
    form_eqb f1 f2 &&&
    form_eqb f1' f2'
  | Quant q1 f1', Quant q2 f2' =>
    (q1 =? q2) &&& form_eqb f1' f2'
  | _,_ => false
  end.

Pierre Letouzey's avatar
Pierre Letouzey committed
382
Compute eqb
383
        (∀ (Pred "A" [ #0 ] -> Pred "A" [ #0 ]))%form
Pierre Letouzey's avatar
Pierre Letouzey committed
384
        (∀ (Pred "A" [FVar "z"] -> Pred "A" [FVar "z"]))%form.
385
386
387
388
389
390
391
392
393


(** Contexts *)

Definition context := list formula.

Definition print_ctx Γ :=
  String.concat "," (List.map print_formula Γ).

Pierre Letouzey's avatar
Pierre Letouzey committed
394
395
(** check, bsubst, level, fvars, vmap, eqb : given by instances
    on lists. *)
396
397
398
399
400
401
402
403
404
405
406

(** Sequent *)

Inductive sequent :=
| Seq : context -> formula -> sequent.

Infix "" := Seq (at level 100).

Definition print_seq '(Γ ⊢ A) :=
  print_ctx Γ ++ "  " ++ print_formula A.

Pierre Letouzey's avatar
Pierre Letouzey committed
407
408
Instance check_seq : Check sequent :=
 fun sign '(Γ ⊢ A) => check sign Γ &&& check sign A.
409

Pierre Letouzey's avatar
Pierre Letouzey committed
410
411
Instance bsubst_seq : BSubst sequent :=
 fun n u '(Γ ⊢ A) => (bsubst n u Γ ⊢ bsubst n u A).
412

Pierre Letouzey's avatar
Pierre Letouzey committed
413
414
415
416
Instance level_seq : Level sequent :=
 fun '(Γ ⊢ A) => Nat.max (level Γ) (level A).

Instance seq_fvars : FVars sequent :=
Pierre Letouzey's avatar
Pierre Letouzey committed
417
 fun '(Γ ⊢ A) => Names.union (fvars Γ) (fvars A).
418

Pierre Letouzey's avatar
Pierre Letouzey committed
419
420
Instance seq_vmap : VMap sequent :=
 fun h '(Γ ⊢ A) => (vmap h Γ ⊢ vmap h A).
421

Pierre Letouzey's avatar
Pierre Letouzey committed
422
423
Instance seq_eqb : Eqb sequent :=
 fun '(Γ1 ⊢ A1) '(Γ2 ⊢ A2) => (Γ1 =? Γ2) &&& (A1 =? A2).
424
425
426

(** Derivation *)

427
Inductive rule_kind :=
428
429
430
431
432
433
434
435
436
437
438
439
  | Ax
  | Tr_i
  | Fa_e
  | Not_i | Not_e
  | And_i | And_e1 | And_e2
  | Or_i1 | Or_i2 | Or_e
  | Imp_i | Imp_e
  | All_i (v:variable)| All_e (wit:term)
  | Ex_i (wit:term) | Ex_e (v:variable)
  | Absu.

Inductive derivation :=
440
  | Rule : rule_kind -> sequent -> list derivation -> derivation.
441

442
443
444
445
446
(** The final sequent of a derivation *)

Definition claim '(Rule _ s _) := s.

(** Utility functions on derivations:
447
    - bounded-vars level (used by the [BClosed] predicate),
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
    - check w.r.t. signature *)

Instance level_rule_kind : Level rule_kind :=
 fun r =>
 match r with
 | All_e wit | Ex_i wit => level wit
 | _ => 0
 end.

Instance level_derivation : Level derivation :=
 fix level_derivation d :=
  let '(Rule r s ds) := d in
  list_max (level r :: level s :: List.map level_derivation ds).

Instance check_rule_kind : Check rule_kind :=
 fun sign r =>
 match r with
 | All_e wit | Ex_i wit => check sign wit
 | _ => true
 end.

Instance check_derivation : Check derivation :=
 fun sign =>
 fix check_derivation d :=
  let '(Rule r s ds) := d in
  check sign r &&&
  check sign s &&&
  List.forallb check_derivation ds.

477
478
479
Instance fvars_rule : FVars rule_kind :=
 fun r =>
 match r with
Pierre Letouzey's avatar
Pierre Letouzey committed
480
 | All_i x | Ex_e x => Names.singleton x
481
 | All_e wit | Ex_i wit => fvars wit
Pierre Letouzey's avatar
Pierre Letouzey committed
482
 | _ => Names.empty
483
484
485
486
487
 end.

Instance fvars_derivation : FVars derivation :=
 fix fvars_derivation d :=
  let '(Rule r s ds) := d in
Pierre Letouzey's avatar
Pierre Letouzey committed
488
  Names.unions [fvars r; fvars s; Names.unionmap fvars_derivation ds].
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512

Instance bsubst_rule : BSubst rule_kind :=
 fun n u r =>
 match r with
 | All_e wit => All_e (bsubst n u wit)
 | Ex_i wit => Ex_i (bsubst n u wit)
 | _ => r
 end.

Instance bsubst_deriv : BSubst derivation :=
 fix bsubst_deriv n u d :=
 let '(Rule r s ds) := d in
 Rule (bsubst n u r) (bsubst n u s ) (map (bsubst_deriv n u) ds).

Instance vmap_rule : VMap rule_kind :=
 fun h r =>
 match r with
 | All_e wit => All_e (vmap h wit)
 | Ex_i wit => Ex_i (vmap h wit)
 | r => r
 end.

(** See Meta for [vmap_deriv], which is slightly more complex
    due to some variable renaming. *)
513
514
515

(** Validity of a derivation : is it using correct rules
    of classical logic (resp. intuitionistic logic) ? *)
516

517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
(** Note that we require the witness terms in rules ∀e and ∃i
    to be [BClosed] (i.e. without any [BVar]). Otherwise
    awkward things may happen due to our implementation
    of [bsubst].

    For instance think of [∀ ∃ ~(Pred "=" [#0;#1])] i.e.
    [∀x∃y,x≠y], a possible way of saying that the world isn't
    a singleton. With an unrestricted ∀e, we could deduce
    [bsubst 0 (#0) (∃ ~(Pred "=" [#0;#1]))] which reduces
    to [∃ ~(Pred "=" [#0;#0])], a formula negating the reflexivity
    of equality !

    Apart from these witnesses, the rest of the derivation
    could technically have unbounded variables, even though
    we intend all derivations to be [BClosed]. We will be able
    to force this later on (see [Meta.forcelevel])
*)

535
Definition valid_deriv_step logic '(Rule r s ld) :=
536
  match r, s, List.map claim ld with
Pierre Letouzey's avatar
Pierre Letouzey committed
537
  | Ax,     (Γ ⊢ A), [] => list_mem A Γ
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
  | Tr_i,   (_ ⊢ True), [] => true
  | Fa_e,   (Γ ⊢ _), [s] => s =? (Γ ⊢ False)
  | Not_i,  (Γ ⊢ Not A), [s] => s =? (A::Γ ⊢ False)
  | Not_e,  (Γ ⊢ False), [Γ1 ⊢ A; Γ2 ⊢ Not A'] =>
    (A =? A') &&& (Γ =? Γ1) &&& (Γ =? Γ2)
  | And_i,  (Γ ⊢ A/\B), [s1; s2] =>
    (s1 =? (Γ ⊢ A)) &&& (s2 =? (Γ ⊢ B))
  | And_e1, s, [Γ ⊢ A/\_] => s =? (Γ ⊢ A)
  | And_e2, s, [Γ ⊢ _/\B] => s =? (Γ ⊢ B)
  | Or_i1,  (Γ ⊢ A\/_), [s] => s =? (Γ ⊢ A)
  | Or_i2,  (Γ ⊢ _\/B), [s] => s =? (Γ ⊢ B)
  | Or_e,   (Γ ⊢ C), [Γ' ⊢ A\/B; s2; s3] =>
     (Γ=?Γ') &&& (s2 =? (A::Γ ⊢ C)) &&& (s3 =? (B::Γ ⊢ C))
  | Imp_i,  (Γ ⊢ A->B), [s] => s =? (A::Γ ⊢ B)
  | Imp_e,  s, [Γ ⊢ A->B;s2] =>
     (s =? (Γ ⊢ B)) &&& (s2 =? (Γ ⊢ A))
  | All_i x,  (Γ⊢∀A), [Γ' ⊢ A'] =>
Pierre Letouzey's avatar
Pierre Letouzey committed
555
     (Γ =? Γ') &&& (A' =? bsubst 0 (FVar x) A)
Pierre Letouzey's avatar
Pierre Letouzey committed
556
     &&& negb (Names.mem x (fvars (Γ⊢A)))
557
  | All_e t, (Γ ⊢ B), [Γ'⊢ ∀A] =>
558
    (Γ =? Γ') &&& (B =? bsubst 0 t A) &&& (level t =? 0)
559
  | Ex_i t,  (Γ ⊢ ∃A), [Γ'⊢B] =>
560
    (Γ =? Γ') &&& (B =? bsubst 0 t A) &&& (level t =? 0)
561
562
  | Ex_e x,  s, [Γ⊢∃A; A'::Γ'⊢B] =>
     (s =? (Γ ⊢ B)) &&& (Γ' =? Γ)
Pierre Letouzey's avatar
Pierre Letouzey committed
563
     &&& (A' =? bsubst 0 (FVar x) A)
Pierre Letouzey's avatar
Pierre Letouzey committed
564
     &&& negb (Names.mem x (fvars (A::Γ⊢B)))
565
  | Absu, s, [Not A::Γ ⊢ False] =>
566
    (logic =? Classic) &&& (s =? (Γ ⊢ A))
567
568
569
570
571
572
573
574
  | _,_,_ => false
  end.

Fixpoint valid_deriv logic d :=
  valid_deriv_step logic d &&&
   (let '(Rule _ _ ld) := d in
    List.forallb (valid_deriv logic) ld).

575
(** Some examples of derivations *)
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640

Definition deriv_example :=
  let A := Pred "A" [] in
  Rule Imp_i ([]⊢A->A) [Rule Ax ([A]⊢A) []].

Compute valid_deriv Intuiti deriv_example.

Definition example_gen (A:formula) :=
  Rule Imp_i ([]⊢A->A) [Rule Ax ([A]⊢A) []].

Compute valid_deriv Intuiti (example_gen (Pred "A" [])).

Definition example2 (A B : term->formula):=
  (Rule Imp_i ([]⊢(∀A(#0)/\B(#0))->(∀A(#0))/\(∀B(#0)))
    (let C := (∀(A(#0)/\B(#0))) in
     [Rule And_i ([C] ⊢ (∀A(#0))/\(∀B(#0)))
       [Rule (All_i "x") ([C]⊢∀A(#0))
         [Rule And_e1 ([C]⊢A(FVar "x"))
           [Rule (All_e (FVar "x")) ([C]⊢ A(FVar "x")/\B(FVar "x"))
             [Rule Ax ([C]⊢C) []]]]
        ;
        Rule (All_i "x") ([C]⊢∀B(#0))
         [Rule And_e2 ([C]⊢B(FVar "x"))
           [Rule (All_e (FVar "x")) ([C]⊢A(FVar "x")/\B(FVar "x"))
             [Rule Ax ([C]⊢C) []]]]]]))%form.

Compute valid_deriv Intuiti
         (example2 (fun x => Pred "A" [x])
                   (fun x => Pred "B" [x])).

Definition em (A:formula) :=
  Rule Absu ([]⊢A\/~A)
    [Rule Not_e ([~(A\/~A)]⊢False)
       [Rule Or_i2 ([~(A\/~A)]⊢A\/~A)
         [Rule Not_i ([~(A\/~A)]⊢~A)
           [Rule Not_e ([A;~(A\/~A)]⊢False)
             [Rule Or_i1 ([A;~(A\/~A)]⊢A\/~A)
               [Rule Ax ([A;~(A\/~A)]⊢A) []]
              ;
              Rule Ax ([A;~(A\/~A)]⊢~(A\/~A)) []]]]
        ;
        Rule Ax ([~(A\/~A)]⊢~(A\/~A)) []]]%form.

Compute valid_deriv Classic (em (Pred "A" [])).
Compute valid_deriv Intuiti (em (Pred "A" [])).

(** Example of free alpha-renaming during a proof,
    (not provable without alpha-renaming) *)

Definition captcha :=
  let A := fun x => Pred "A" [x] in
  Rule (All_i "z") ([A(FVar "x")]⊢∀(A(#0)->A(#0)))%form
   [Rule Imp_i ([A(FVar "x")]⊢A(FVar "z")->A(FVar "z"))
     [Rule Ax ([A(FVar "z");A(FVar "x")]⊢A(FVar "z")) []]].

Compute valid_deriv Intuiti captcha.

Definition captcha_bug :=
  let A := fun x => Pred "A" [x] in
  Rule (All_i "x") ([A(FVar "x")]⊢∀(A(#0)->A(#0)))%form
   [Rule Imp_i ([A(FVar "x")]⊢A(FVar "x")->A(FVar "x"))
    [Rule Ax ([A(FVar "x");A(FVar "x")]⊢A(FVar "x")) []]].

Compute valid_deriv Intuiti captcha_bug.

641
642
(** Correctness of earlier boolean equality tests *)

Pierre Letouzey's avatar
Pierre Letouzey committed
643
Instance : EqbSpec term.
644
Proof.
Pierre Letouzey's avatar
Pierre Letouzey committed
645
646
647
648
649
650
651
652
 red.
 fix IH 1. destruct x as [v|n|f l], y as [v'|n'|f' l']; cbn; try cons.
 - case eqbspec; cons.
 - case eqbspec; cons.
 - case eqbspec; [ intros <- | cons ].
   change (list_forallb2 eqb l l') with (l =? l').
   change (EqbSpec term) in IH.
   case eqbspec; cons.
653
654
Qed.

Pierre Letouzey's avatar
Pierre Letouzey committed
655
Instance : EqbSpec formula.
656
Proof.
Pierre Letouzey's avatar
Pierre Letouzey committed
657
658
659
660
661
662
663
664
665
666
 red.
 induction x; destruct y; cbn; try cons.
 - case eqbspec; [ intros <- | cons ].
   case eqbspec; cons.
 - case IHx; cons.
 - case eqbspec; [ intros <- | cons ].
   case IHx1; [ intros <- | cons].
   case IHx2; cons.
 - case eqbspec; [ intros <- | cons ].
   case IHx; cons.
667
668
Qed.

Pierre Letouzey's avatar
Pierre Letouzey committed
669
Instance : EqbSpec context.
670
Proof.
Pierre Letouzey's avatar
Pierre Letouzey committed
671
 apply eqbspec_list.
672
673
Qed.

Pierre Letouzey's avatar
Pierre Letouzey committed
674
Instance : EqbSpec sequent.
675
Proof.
Pierre Letouzey's avatar
Pierre Letouzey committed
676
 intros [] []. cbn. repeat (case eqbspec; try cons).
677
678
Qed.

Pierre Letouzey's avatar
Pierre Letouzey committed
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
(** Better induction principle on terms *)

Lemma term_ind' (P: term -> Prop) :
  (forall v, P (FVar v)) ->
  (forall n, P (BVar n)) ->
  (forall f args, (forall a, In a args -> P a) -> P (Fun f args)) ->
  forall t, P t.
Proof.
 intros Hv Hn Hl.
 fix IH 1. destruct t.
 - apply Hv.
 - apply Hn.
 - apply Hl.
   revert l.
   fix IH' 1. destruct l.
   + intros a [ ].
   + intros a [<-|Ha]. apply IH. apply (IH' l a Ha).
Qed.

698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
(** Induction principle on derivations with correct
    handling of sub-derivation lists. *)

Lemma derivation_ind' (P: derivation -> Prop) :
  (forall r s ds, Forall P ds -> P (Rule r s ds)) ->
  forall d, P d.
Proof.
 intros Step.
 fix IH 1. destruct d as (r,s,ds).
 apply Step.
 revert ds.
 fix IH' 1. destruct ds; simpl; constructor.
 apply IH.
 apply IH'.
Qed.

(** A derivation "claims" a sequent ... if it ends with this sequent.
    This is just nicer than putting [claim ... = ...] everywhere. *)

Definition Claim d s := claim d = s.
Arguments Claim _ _ /.
Hint Extern 1 (Claim _ _) => cbn.

(** An inductive counterpart to valid_deriv, easier to use in proofs *)

Inductive Valid (l:logic) : derivation -> Prop :=
 | V_Ax Γ A : In A Γ -> Valid l (Rule Ax (Γ ⊢ A) [])
 | V_Tr_i Γ : Valid l (Rule Tr_i (Γ ⊢ True) [])
 | V_Fa_e d Γ A :
     Valid l d -> Claim d (Γ ⊢ False) ->
     Valid l (Rule Fa_e (Γ ⊢ A) [d])
 | V_Not_i d Γ A :
     Valid l d -> Claim d (A::Γ ⊢ False) ->
     Valid l (Rule Not_i (Γ ⊢ ~A) [d])
 | V_Not_e d1 d2 Γ A :
     Valid l d1 -> Valid l d2 ->
     Claim d1 (Γ ⊢ A) -> Claim d2 (Γ ⊢ ~A) ->
     Valid l (Rule Not_e (Γ ⊢ False) [d1;d2])
 | V_And_i d1 d2 Γ A B :
     Valid l d1 -> Valid l d2 ->
     Claim d1 (Γ ⊢ A) -> Claim d2 (Γ ⊢ B) ->
     Valid l (Rule And_i (Γ ⊢ A/\B) [d1;d2])
 | V_And_e1 d Γ A B :
     Valid l d -> Claim d (Γ ⊢ A/\B) ->
     Valid l (Rule And_e1 (Γ ⊢ A) [d])
 | V_And_e2 d Γ A B :
     Valid l d -> Claim d (Γ ⊢ A/\B) ->
     Valid l (Rule And_e2 (Γ ⊢ B) [d])
 | V_Or_i1 d Γ A B :
     Valid l d -> Claim d (Γ ⊢ A) ->
     Valid l (Rule Or_i1 (Γ ⊢ A\/B) [d])
 | V_Or_i2 d Γ A B :
     Valid l d -> Claim d (Γ ⊢ B) ->
     Valid l (Rule Or_i2 (Γ ⊢ A\/B) [d])
 | V_Or_e d1 d2 d3 Γ A B C :
     Valid l d1 -> Valid l d2 -> Valid l d3 ->
     Claim d1 (Γ ⊢ A\/B) -> Claim d2 (A::Γ ⊢ C) -> Claim d3 (B::Γ ⊢ C) ->
     Valid l (Rule Or_e (Γ ⊢ C) [d1;d2;d3])
 | V_Imp_i d Γ A B :
     Valid l d -> Claim d (A::Γ ⊢ B) ->
     Valid l (Rule Imp_i (Γ ⊢ A->B) [d])
 | V_Imp_e d1 d2 Γ A B :
     Valid l d1 -> Valid l d2 ->
     Claim d1 (Γ ⊢ A->B) -> Claim d2 (Γ ⊢ A) ->
     Valid l (Rule Imp_e (Γ ⊢ B) [d1;d2])
 | V_All_i x d Γ A :
Pierre Letouzey's avatar
Pierre Letouzey committed
764
     ~Names.In x (fvars (Γ ⊢ A)) ->
765
766
767
     Valid l d -> Claim d (Γ ⊢ bsubst 0 (FVar x) A) ->
     Valid l (Rule (All_i x) (Γ ⊢ ∀A) [d])
 | V_All_e t d Γ A :
768
     BClosed t -> Valid l d -> Claim d (Γ ⊢ ∀A) ->
769
770
     Valid l (Rule (All_e t) (Γ ⊢ bsubst 0 t A) [d])
 | V_Ex_i t d Γ A :
771
     BClosed t -> Valid l d -> Claim d (Γ ⊢ bsubst 0 t A) ->
772
773
     Valid l (Rule (Ex_i t) (Γ ⊢ ∃A) [d])
 | V_Ex_e x d1 d2 Γ A B :
Pierre Letouzey's avatar
Pierre Letouzey committed
774
     ~Names.In x (fvars (A::Γ⊢B)) ->
775
776
777
778
779
780
781
782
783
784
785
     Valid l d1 -> Valid l d2 ->
     Claim d1 (Γ ⊢ ∃A) -> Claim d2 ((bsubst 0 (FVar x) A)::Γ ⊢ B) ->
     Valid l (Rule (Ex_e x) (Γ ⊢ B) [d1;d2])
 | V_Absu d Γ A :
     l=Classic ->
     Valid l d -> Claim d (Not A :: Γ ⊢ False) ->
     Valid l (Rule Absu (Γ ⊢ A) [d]).

Hint Constructors Valid.

(** Let's prove now that [valid_deriv] is equivalent to [Valid] *)
786
787
788
789
790

Ltac break :=
 match goal with
 | H : match _ with true => _ | false => _ end = true |- _ =>
   rewrite !lazy_andb_iff in H
791
 | H : match claim ?x with _ => _ end = true |- _ =>
792
793
794
795
796
797
798
799
800
   destruct x; simpl in H; try easy; break
 | H : match map _ ?x with _ => _ end = true |- _ =>
   destruct x; simpl in H; try easy; break
 | H : match ?x with _ => _ end = true |- _ =>
   destruct x; simpl in H; try easy; break
 | _ => idtac
 end.

Ltac mytac :=
801
802
803
804
805
 cbn in *;
 break;
 rewrite ?andb_true_r, ?andb_true_iff, ?lazy_andb_iff in *;
 repeat match goal with H : _ /\ _ |- _ => destruct H end;
 repeat match goal with IH : Forall _ _  |- _ => inversion_clear IH end;
806
 rewrite ?@eqb_eq in * by auto with typeclass_instances.
807

808
Ltac rewr :=
809
 unfold Claim, BClosed in *;
810
811
812
813
814
815
 match goal with
 | H: _ = _ |- _ => rewrite H in *; clear H; rewr
 | _ => rewrite ?eqb_refl
 end.

Lemma Valid_equiv l d : valid_deriv l d = true <-> Valid l d.
816
Proof.
817
818
819
820
821
822
823
824
825
 split.
 - induction d as [r s ds IH] using derivation_ind'.
   cbn - [valid_deriv_step]. rewrite lazy_andb_iff. intros (H,H').
   assert (IH' : Forall (fun d => Valid l d) ds).
   { rewrite Forall_forall, forallb_forall in *. auto. }
   clear IH H'.
   mytac; subst; eauto.
   + now apply V_Ax, list_mem_in.
   + apply V_All_i; auto.
Pierre Letouzey's avatar
Pierre Letouzey committed
826
     rewrite <- Names.mem_spec. cbn. intros EQ. now rewrite EQ in *.
827
   + apply V_Ex_e with f; auto.
Pierre Letouzey's avatar
Pierre Letouzey committed
828
     rewrite <- Names.mem_spec. cbn. intros EQ. now rewrite EQ in *.
829
 - induction 1; simpl; rewr; auto.
830
   + apply list_mem_in in H. now rewrite H.
Pierre Letouzey's avatar
Pierre Letouzey committed
831
832
   + rewrite <- Names.mem_spec in H. destruct Names.mem; auto.
   + rewrite <- Names.mem_spec in H. destruct Names.mem; auto.
833
834
835
836
837
838
839
840
841
842
843
844
Qed.

(** A notion of provability, directly on a sequent *)

Definition Provable logic (s : sequent) :=
  exists d, Valid logic d /\ Claim d s.

Lemma thm_example :
  let A := Pred "A" [] in
  Provable Intuiti ([]⊢A->A).
Proof.
 exists deriv_example. now rewrite <- Valid_equiv.
845
Qed.
846

847
848
849

(** A provability notion directly on sequents, without derivations.
    Pros: lighter
850
851
    Cons: no easy way to express meta-theoretical facts about the proof
          itself (e.g. free or bounded variables used during the proof). *)
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878

Inductive Pr (l:logic) : sequent -> Prop :=
 | R_Ax Γ A : In A Γ -> Pr l (Γ ⊢ A)
 | R_Tr_i Γ : Pr l (Γ ⊢ True)
 | R_Fa_e Γ A : Pr l (Γ ⊢ False) ->
                  Pr l (Γ ⊢ A)
 | R_Not_i Γ A : Pr l (A::Γ ⊢ False) ->
                   Pr l (Γ ⊢ ~A)
 | R_Not_e Γ A : Pr l (Γ ⊢ A) -> Pr l (Γ ⊢ ~A) ->
                   Pr l (Γ ⊢ False)
 | R_And_i Γ A B : Pr l (Γ ⊢ A) -> Pr l (Γ ⊢ B) ->
                   Pr l (Γ ⊢ A/\B)
 | R_And_e1 Γ A B : Pr l (Γ ⊢ A/\B) ->
                    Pr l (Γ ⊢ A)
 | R_And_e2 Γ A B : Pr l (Γ ⊢ A/\B) ->
                    Pr l (Γ ⊢ B)
 | R_Or_i1 Γ A B : Pr l (Γ ⊢ A) ->
                   Pr l (Γ ⊢ A\/B)
 | R_Or_i2 Γ A B : Pr l (Γ ⊢ B) ->
                   Pr l (Γ ⊢ A\/B)
 | R_Or_e Γ A B C :
     Pr l (Γ ⊢ A\/B) -> Pr l (A::Γ ⊢ C) -> Pr l (B::Γ ⊢ C) ->
     Pr l (Γ ⊢ C)
 | R_Imp_i Γ A B : Pr l (A::Γ ⊢ B) ->
                     Pr l (Γ ⊢ A->B)
 | R_Imp_e Γ A B : Pr l (Γ ⊢ A->B) -> Pr l (Γ ⊢ A) ->
                   Pr l (Γ ⊢ B)
Pierre Letouzey's avatar
Pierre Letouzey committed
879
 | R_All_i x Γ A : ~Names.In x (fvars (Γ ⊢ A)) ->
880
881
                   Pr l (Γ ⊢ bsubst 0 (FVar x) A) ->
                   Pr l (Γ ⊢ ∀A)
882
883
884
885
 | R_All_e t Γ A : BClosed t -> Pr l (Γ ⊢ ∀A) ->
                   Pr l (Γ ⊢ bsubst 0 t A)
 | R_Ex_i t Γ A : BClosed t -> Pr l (Γ ⊢ bsubst 0 t A) ->
                  Pr l (Γ ⊢ ∃A)
Pierre Letouzey's avatar
Pierre Letouzey committed
886
 | R_Ex_e x Γ A B : ~Names.In x (fvars (A::Γ⊢B)) ->
887
888
889
890
891
892
893
894
      Pr l (Γ ⊢ ∃A) -> Pr l ((bsubst 0 (FVar x) A)::Γ ⊢ B) ->
      Pr l (Γ ⊢ B)
 | R_Absu Γ A : l=Classic -> Pr l (Not A :: Γ ⊢ False) ->
                  Pr l (Γ ⊢ A).
Hint Constructors Pr.

Lemma Valid_Pr lg d :
  Valid lg d -> Pr lg (claim d).
895
Proof.
896
 induction 1; cbn in *; rewr; eauto 2.
897
898
Qed.

899
900
Lemma Provable_alt lg s :
  Pr lg s <-> Provable lg s.
901
Proof.
902
903
904
905
906
907
 split.
 - induction 1;
   repeat match goal with H:Provable _ _ |- _ =>
          let d := fresh "d" in destruct H as (d & ? & ?) end;
   eexists (Rule _ _ _); split; try reflexivity; eauto 2.
 - intros (d & Hd & <-). now apply Valid_Pr.
908
909
Qed.

910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
(* A few examples of proofs in NJ1 and NK1. *)

Lemma ex1 f1 f2 : Provable Intuiti ([] ⊢ (f1 /\ f2) -> (f1 \/ f2)).
Proof.
  apply Provable_alt.
  apply R_Imp_i.
  apply R_Or_i1.
  apply R_And_e1 with (B := f2).
  apply R_Ax.
  apply in_eq.
Qed.

Lemma ex2 f1 f2 f3 : Provable Intuiti ([] ⊢ (f1 -> f2 -> f3) <-> (f1 /\ f2 -> f3)).
Proof.
  apply Provable_alt.
  apply R_And_i.
  + apply R_Imp_i.
    apply R_Imp_i.
    apply R_Imp_e with (A := f2).
    - apply R_Imp_e with (A := f1).
      * apply R_Ax. apply in_cons. apply in_eq.
      * apply R_And_e1 with (B := f2). apply R_Ax. apply in_eq.
    - apply R_And_e2 with (A := f1). apply R_Ax. apply in_eq.
  + apply R_Imp_i.
    apply R_Imp_i.
    apply R_Imp_i.
    apply R_Imp_e with (A := (f1 /\ f2)%form).
    - apply R_Ax. apply in_cons. apply in_cons. apply in_eq.
    - apply R_And_i; apply R_Ax.
      * apply in_cons. apply in_eq.
      * apply in_eq.
Qed.

943
Lemma Weakening Γ f2 lg : forall f1, Pr lg (Γ ⊢ f1) -> Pr lg (f2::Γ ⊢ f1).
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
Admitted.

Lemma RAA f1 Γ : Pr Classic (Γ ⊢ ~~f1) -> Pr Classic (Γ ⊢ f1).
Proof.
  intro.
  apply R_Absu.
  + reflexivity.
  + apply R_Not_e with (A := (~ f1)%form).
    - apply R_Ax. apply in_eq.
    - apply Weakening. exact H.
Qed.

Lemma DeMorgan f1 f2 Γ : Pr Classic (Γ ⊢ ~(~f1 /\ f2)) -> Pr Classic (Γ ⊢ ~~(f1 \/ ~f2)).
Proof.
  intro.
  apply R_Not_i.
  apply R_Not_e with (A := (~f1 /\ f2)%form).
  + apply RAA with (f1 := (~f1 /\ f2)%form).
    apply R_Not_i.
963
    apply R_Not_e with (A := (f1\/~f2)%form).
964
    - apply R_Or_i1.
965
      apply RAA.
966
      apply R_Not_i.
967
      apply R_Not_e with (A := (f1\/~f2)%form).
968
969
970
971
972
      * apply R_Or_i2. apply R_Not_i. apply R_Not_e with (A := (~f1 /\ f2)%form).
        ++ apply R_And_i.
           -- apply R_Ax. apply in_cons. apply in_eq.
           -- apply R_Ax. apply in_eq.
        ++ apply R_Ax. apply in_cons. apply in_cons. apply in_eq.
973
974
975
976
      * apply R_Ax. apply in_cons. apply in_cons. apply in_eq.
    - apply R_Ax. apply in_cons. apply in_eq.
  + apply Weakening. exact H.
Qed.
977
978
979
980
981
982
983
984
985
986
987
988
989
990

Lemma ExcludedMiddle f1 : Provable Classic ([] ⊢ f1 \/ ~f1).
Proof.
  apply Provable_alt.
  apply RAA.
  apply DeMorgan with (f2 := f1) (Γ := []).
  apply R_Not_i.
  apply R_Not_e with (A := f1).
  + apply R_And_e2 with (A := (~f1)%form). apply R_Ax. apply in_eq.
  + apply R_And_e1 with (B := f1). apply R_Ax. apply in_eq.
Qed.
      
(* Some usefull statements. *)

991
992
Lemma Pr_intuit_classic s : Pr Intuiti s -> Pr Classic s.
Proof.
993
 induction 1; eauto 2.
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
Qed.

Lemma Pr_intuit_any lg s : Pr Intuiti s -> Pr lg s.
Proof.
 destruct lg. apply Pr_intuit_classic. trivial.
Qed.

Lemma Pr_any_classic lg s : Pr lg s -> Pr Classic s.
Proof.
 destruct lg. trivial. apply Pr_intuit_classic.
Qed.

1006
Lemma intuit_classic d : Valid Intuiti d -> Valid Classic d.
1007
Proof.
1008
 induction 1; eauto.
1009
1010
Qed.

1011
Lemma any_classic d lg : Valid lg d -> Valid Classic d.
1012
1013
Proof.
 destruct lg. trivial. apply intuit_classic.
1014
Qed.