-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSemantics.v
1426 lines (1228 loc) · 33.9 KB
/
Semantics.v
1
2
3
4
5
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
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
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
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
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
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
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Require Import String Setoid Lia.
Require Import stdpp.list.
Require Import ssreflect.
Require Import Flowers.Terms Flowers.Utils.
(** Our semantics will be the sequent calculus LJ *)
(** * Syntax *)
Inductive form :=
| FAtom (p : name) (args : list term)
| FTrue
| FFalse
| FAnd (A : form) (B : form)
| FOr (A : form) (B : form)
| FImp (A : form) (B : form)
| FForall (A : form)
| FExists (A : form).
Notation "⊤" := FTrue.
Notation "⊥" := FFalse.
Infix "∧" := FAnd.
Infix "∨" := FOr.
Infix "⊃" := FImp (at level 85, right associativity).
Notation "#∀ A" := (FForall A) (at level 1).
Notation "#∃ A" := (FExists A) (at level 1).
Lemma form_induction_full :
∀ (P : form -> Prop) (Pt : term -> Prop)
(IHt : ∀ t, Pt t)
(IHatom : ∀ p args, Forall Pt args -> P (FAtom p args))
(IHtrue : P ⊤) (IHfalse : P ⊥)
(IHand : ∀ A B, P A -> P B -> P (A ∧ B))
(IHor : ∀ A B, P A -> P B -> P (A ∨ B))
(IHimp : ∀ A B, P A -> P B -> P (A ⊃ B))
(IHfa : ∀ A, P A -> P (#∀ A))
(IHex : ∀ A, P A -> P (#∃ A)),
∀ A, P A.
Proof.
intros; move: A; fix IH 1; induction A.
* apply IHatom. elim args; auto.
* apply IHtrue.
* apply IHfalse.
* apply IHand; auto.
* apply IHor; auto.
* apply IHimp; auto.
* apply IHfa; auto.
* apply IHex; auto.
Qed.
Lemma form_induction :
∀ (P : form -> Prop)
(IHatom : ∀ p args, P (FAtom p args))
(IHtrue : P ⊤) (IHfalse : P ⊥)
(IHand : ∀ A B, P A -> P B -> P (A ∧ B))
(IHor : ∀ A B, P A -> P B -> P (A ∨ B))
(IHimp : ∀ A B, P A -> P B -> P (A ⊃ B))
(IHfa : ∀ A, P A -> P (#∀ A))
(IHex : ∀ A, P A -> P (#∃ A)),
∀ A, P A.
Proof.
intros; eapply form_induction_full; eauto.
exact (fun _ => I).
Qed.
Definition And :=
foldr FAnd ⊤.
Definition Or :=
foldr FOr ⊥.
Fixpoint nforall n A :=
match n with
| 0 => A
| S n => #∀ (nforall n A)
end.
Fixpoint nexists n A :=
match n with
| 0 => A
| S n => #∃ (nexists n A)
end.
Notation "⋀ As" := (And As) (at level 5).
Notation "⋁ As" := (Or As) (at level 5).
Notation "n #∀ A" := (nforall n A) (format "n #∀ A", at level 6).
Notation "n #∃ A" := (nexists n A) (format "n #∃ A", at level 6).
(** * Shifting and substitution *)
Fixpoint fshift (n : nat) (c : nat) (A : form) : form :=
match A with
| FAtom p args => FAtom p (tshift n c <$> args)
| FTrue | FFalse => A
| FAnd A B => FAnd (fshift n c A) (fshift n c B)
| FOr A B => FOr (fshift n c A) (fshift n c B)
| FImp A B => FImp (fshift n c A) (fshift n c B)
| FForall A => FForall (fshift n (c+1) A)
| FExists A => FExists (fshift n (c+1) A)
end.
Fixpoint funshift (n : nat) (c : nat) (A : form) : form :=
match A with
| FAtom p args => FAtom p (tunshift n c <$> args)
| FTrue | FFalse => A
| FAnd A B => FAnd (funshift n c A) (funshift n c B)
| FOr A B => FOr (funshift n c A) (funshift n c B)
| FImp A B => FImp (funshift n c A) (funshift n c B)
| FForall A => FForall (funshift n (c+1) A)
| FExists A => FExists (funshift n (c+1) A)
end.
Fixpoint fsubst (n : nat) (u : term) (A : form) : form :=
match A with
| FAtom p args => FAtom p (tsubst n u <$> args)
| FTrue | FFalse => A
| FAnd A B => FAnd (fsubst n u A) (fsubst n u B)
| FOr A B => FOr (fsubst n u A) (fsubst n u B)
| FImp A B => FImp (fsubst n u A) (fsubst n u B)
| FForall A => FForall (fsubst (n+1) (tshift 1 0 u) A)
| FExists A => FExists (fsubst (n+1) (tshift 1 0 u) A)
end.
(** ** Operations commute with n-ary connectives *)
Lemma fshift_And {T} (f : T -> form) : ∀ Γ n c,
fshift n c ⋀ (f <$> Γ) = ⋀ ((λ A, fshift n c (f A)) <$> Γ).
Proof.
elim => [n c |B Γ IH n c]//.
rewrite fmap_cons cons_app //=.
by rewrite IH.
Qed.
Lemma funshift_And {T} (f : T -> form) : ∀ Γ n t,
funshift n t ⋀ (f <$> Γ) = ⋀ ((λ A, funshift n t (f A)) <$> Γ).
Proof.
elim => [n c |B Γ IH n c]//.
rewrite fmap_cons cons_app //=.
by rewrite IH.
Qed.
Lemma fsubst_And {T} (f : T -> form) : ∀ Γ n t,
fsubst n t ⋀ (f <$> Γ) = ⋀ ((λ A, fsubst n t (f A)) <$> Γ).
Proof.
elim => [n c |B Γ IH n c]//.
rewrite fmap_cons cons_app //=.
by rewrite IH.
Qed.
Lemma fshift_Or {T} (f : T -> form) : ∀ Γ n c,
fshift n c ⋁ (f <$> Γ) = ⋁ ((λ A, fshift n c (f A)) <$> Γ).
Proof.
elim => [n c |B Γ IH n c]//.
rewrite fmap_cons cons_app //=.
by rewrite IH.
Qed.
Lemma funshift_Or {T} (f : T -> form) : ∀ Γ n c,
funshift n c ⋁ (f <$> Γ) = ⋁ ((λ A, funshift n c (f A)) <$> Γ).
Proof.
elim => [n c |B Γ IH n c]//.
rewrite fmap_cons cons_app //=.
by rewrite IH.
Qed.
Lemma fsubst_Or {T} (f : T -> form) : ∀ Γ n c,
fsubst n c ⋁ (f <$> Γ) = ⋁ ((λ A, fsubst n c (f A)) <$> Γ).
Proof.
elim => [n c |B Γ IH n c]//.
rewrite fmap_cons cons_app //=.
by rewrite IH.
Qed.
Lemma fshift_nforall : ∀ m n c A,
fshift n c m#∀ A = m#∀ (fshift n (c + m) A).
Proof.
elim => [n c A |m IH n c A]//=.
by rewrite Nat.add_0_r.
f_equal.
specialize (IH n (c + 1) A).
assert (H : c + 1 + m = c + S m). { lia. }
rewrite H in IH.
by rewrite IH.
Qed.
Lemma funshift_nforall : ∀ m n c A,
funshift n c m#∀ A = m#∀ (funshift n (c + m) A).
Proof.
elim => [n c A |m IH n c A]//=.
by rewrite Nat.add_0_r.
f_equal.
specialize (IH n (c + 1) A).
assert (H : c + 1 + m = c + S m). { lia. }
rewrite H in IH.
by rewrite IH.
Qed.
Lemma fsubst_nforall : ∀ m n t A,
fsubst n t (m#∀ A) = m#∀ (fsubst (n + m) (tshift m 0 t) A).
Proof.
elim => [|m IH] n t A //=.
by rewrite Nat.add_0_r tshift_zero.
f_equal.
specialize (IH (n + 1) (tshift 1 0 t) A).
assert (H : n + 1 + m = n + S m); first lia; rewrite H in IH; clear H.
rewrite -tshift_add in IH.
assert (H : m + 1 = S m); first lia; rewrite H in IH; clear H.
done.
Qed.
Lemma fshift_nexists : ∀ m n c A,
fshift n c m#∃ A = m#∃ (fshift n (c + m) A).
Proof.
elim => [n c A |m IH n c A]//=.
by rewrite Nat.add_0_r.
f_equal.
specialize (IH n (c + 1) A).
assert (H : c + 1 + m = c + S m). { lia. }
rewrite H in IH.
by rewrite IH.
Qed.
Lemma funshift_nexists : ∀ m n c A,
funshift n c m#∃ A = m#∃ (funshift n (c + m) A).
Proof.
elim => [n c A |m IH n c A]//=.
by rewrite Nat.add_0_r.
f_equal.
specialize (IH n (c + 1) A).
assert (H : c + 1 + m = c + S m). { lia. }
rewrite H in IH.
by rewrite IH.
Qed.
Lemma fsubst_nexists : ∀ m n t A,
fsubst n t (m#∃ A) = m#∃ (fsubst (n + m) (tshift m 0 t) A).
Proof.
elim => [|m IH] n t A //=.
by rewrite Nat.add_0_r tshift_zero.
f_equal.
specialize (IH (n + 1) (tshift 1 0 t) A).
assert (H : n + 1 + m = n + S m); first lia; rewrite H in IH; clear H.
rewrite -tshift_add in IH.
assert (H : m + 1 = S m); first lia; rewrite H in IH; clear H.
done.
Qed.
(** ** Shifting and arithmetic *)
Lemma fshift_zero : ∀ A c,
fshift 0 c A = A.
Proof.
induction A using form_induction; intros c; simpl; auto.
* pose proof (H := eq_map (tshift 0 c) id args (tshift_zero c)).
by rewrite H list_fmap_id.
* f_equal; done.
* f_equal; done.
* f_equal; done.
* f_equal. by rewrite IHA.
* f_equal. by rewrite IHA.
Qed.
Lemma cshift_zero : ∀ (Γ : list form) c,
fshift 0 c <$> Γ = Γ.
Proof.
intros. rewrite -{2}[Γ]map_id_ext. apply eq_map.
intros. by apply fshift_zero.
Qed.
Lemma fshift_add : ∀ A c n m,
fshift (n + m) c A = fshift n c (fshift m c A).
Proof.
induction A using form_induction; intros c n m; simpl; auto.
* pose proof (H := eq_map (tshift (n + m) c) _ args (tshift_add c n m)).
by rewrite H list_fmap_compose.
* f_equal; done.
* f_equal; done.
* f_equal; done.
* f_equal. by rewrite IHA.
* f_equal. by rewrite IHA.
Qed.
Lemma fshift_succ : ∀ A c n,
fshift (S n) c A = fshift 1 c (fshift n c A).
Proof.
intros.
rewrite -Nat.add_1_l.
apply fshift_add.
Qed.
Lemma fshift_comm A c n m :
fshift n c (fshift m c A) = fshift m c (fshift n c A).
Proof.
by rewrite -fshift_add Nat.add_comm fshift_add.
Qed.
(** ** Interaction of shifting and substitution *)
Lemma fsubst_fshift A : ∀ c m,
fsubst c (TVar (c + m)) (fshift m (S c) A) = fshift m c A.
Proof.
induction A; intros; simpl; auto; try by rewrite IHA1 IHA2.
* induction args; auto. list_simplifier.
f_equal. f_equal; auto. by apply (tsubst_tshift c m).
* specialize (IHA (c + 1) m). f_equal.
assert (H : c + m + 1 = c + 1 + m). { lia. } by rewrite H.
* specialize (IHA (c + 1) m). f_equal.
assert (H : c + m + 1 = c + 1 + m). { lia. } by rewrite H.
Qed.
Lemma fsubst_fshift_vacuous A : ∀ n u m c,
n < m ->
fsubst (n + c) u (fshift m c A) = fshift m c A.
Proof.
induction A; intros; simpl; auto;
try by rewrite (IHA1 n u m c H) (IHA2 n u m c H).
* induction args; auto. list_simplifier.
f_equal. f_equal; auto. by apply (tsubst_tshift_vacuous n u m c).
* epose proof (IH := IHA n (tshift 1 0 u) m (c + 1) _).
f_equal. assert (Ha : n + c + 1 = n + (c + 1)). { lia. } by rewrite Ha.
* epose proof (IH := IHA n (tshift 1 0 u) m (c + 1) _).
f_equal. assert (Ha : n + c + 1 = n + (c + 1)). { lia. } by rewrite Ha.
Unshelve.
all: auto.
Qed.
Lemma fsubst_fshift_vacuous2 : ∀ A m c,
fsubst c (TVar (c + m)) (fshift m (S c) A) = fshift m c A.
Proof.
induction A using form_induction; intros; simpl; auto;
try by rewrite (IHA1 m c) (IHA2 m c).
* rewrite -list_fmap_compose.
f_equal. apply eq_fmap. move => t /=.
by apply tsubst_tshift_vacuous2.
* f_equal. specialize (IHA m (c + 1)).
assert (H : c + 1 + m = c + m + 1). { lia. }
by rewrite -H IHA.
* f_equal. specialize (IHA m (c + 1)).
assert (H : c + 1 + m = c + m + 1). { lia. }
by rewrite -H IHA.
Qed.
Lemma funshift_fshift A : ∀ n c,
funshift n c (fshift n c A) = A.
Proof.
induction A using form_induction; intros; simpl; auto;
try by rewrite IHA1 IHA2.
* rewrite -list_fmap_compose.
rewrite (eq_map _ id).
move => t.
pose proof (H := tunshift_tshift 0 n c t).
by rewrite tunshift_zero /= in H.
by rewrite map_id_ext.
* by rewrite IHA.
* by rewrite IHA.
Qed.
(** * Contexts *)
(* Inductive fctx :=
| Chole
| CandL (X : fctx) (B : form)
| CandR (B : form) (X : fctx)
| CorL (X : fctx) (B : form)
| CorR (B : form) (X : fctx)
| CimpL (X : fctx) (B : form)
| CimpR (B : form) (X : fctx)
| Cforall (X : fctx)
| Cexists (X : fctx).
Fixpoint CAnd
Reserved Notation "X {{ A }}" (at level 0).
Fixpoint ffill (A : form) (X : fctx) : form :=
match X with
| Chole => A
| CandL X B => X{{A}} ∧ B
| CandR B X => B ∧ X{{A}}
| CorL X B => X{{A}} ∨ B
| CorR B X => B ∨ X{{A}}
| CimpL X B => X{{A}} ⊃ B
| CimpR B X => B ⊃ X{{A}}
| Cforall X => #∀ X{{A}}
| Cexists X => #∃ X{{A}}
end
where "X {{ A }}" := (ffill A X). *)
(** * Rules *)
Reserved Infix "⟹" (at level 90).
Inductive deriv : list form -> form -> Prop :=
(** ** Identity *)
| S_ax A Γ Γ' :
Γ ++ A :: Γ' ⟹ A
| S_cut A Γ Γ' C :
Γ ++ Γ' ⟹ A -> Γ ++ A :: Γ' ⟹ C ->
Γ ++ Γ' ⟹ C
(** ** Structural rules *)
| S_perm Γ Γ' C :
Γ ≡ₚ Γ' ->
Γ ⟹ C ->
Γ' ⟹ C
| S_weak A Γ Γ' C :
Γ ++ Γ' ⟹ C ->
Γ ++ A :: Γ' ⟹ C
| S_contr_r A Γ Γ' Γ'' C :
Γ ++ A :: Γ' ++ A :: Γ'' ⟹ C ->
Γ ++ Γ' ++ A :: Γ'' ⟹ C
| S_contr_l A Γ Γ' Γ'' C :
Γ ++ A :: Γ' ++ A :: Γ'' ⟹ C ->
Γ ++ A :: Γ' ++ Γ'' ⟹ C
(** ** Right rules *)
| S_R_true Γ :
Γ ⟹ ⊤
| S_R_and A B Γ :
Γ ⟹ A -> Γ ⟹ B ->
Γ ⟹ A ∧ B
| S_R_or_l A B Γ :
Γ ⟹ A ->
Γ ⟹ A ∨ B
| S_R_or_r A B Γ :
Γ ⟹ B ->
Γ ⟹ A ∨ B
| S_R_imp A B Γ :
A :: Γ ⟹ B ->
Γ ⟹ A ⊃ B
| S_R_forall Γ C :
(fshift 1 0 <$> Γ) ⟹ C ->
Γ ⟹ #∀ C
| S_R_exists t Γ C :
Γ ⟹ funshift 1 0 (fsubst 0 (tshift 1 0 t) C) ->
Γ ⟹ #∃ C
(** ** Left rules *)
| S_L_true Γ Γ' C :
Γ ++ Γ' ⟹ C ->
Γ ++ ⊤ :: Γ' ⟹ C
| S_L_false Γ Γ' C :
Γ ++ ⊥ :: Γ' ⟹ C
| S_L_and A B Γ Γ' C :
Γ ++ A :: B :: Γ' ⟹ C ->
Γ ++ (A ∧ B) :: Γ' ⟹ C
| S_L_or A B Γ Γ' C :
Γ ++ A :: Γ' ⟹ C -> Γ ++ B :: Γ' ⟹ C ->
Γ ++ (A ∨ B) :: Γ' ⟹ C
| S_L_imp A B Γ Γ' C :
Γ ++ Γ' ⟹ A -> Γ ++ B :: Γ' ⟹ C ->
Γ ++ (A ⊃ B) :: Γ' ⟹ C
| S_L_forall A t Γ Γ' C :
Γ ++ funshift 1 0 (fsubst 0 (tshift 1 0 t) A) :: Γ' ⟹ C ->
Γ ++ #∀ A :: Γ' ⟹ C
| S_L_exists A Γ Γ' C :
(fshift 1 0 <$> Γ) ++ A :: (fshift 1 0 <$> Γ') ⟹ fshift 1 0 C ->
Γ ++ #∃ A :: Γ' ⟹ C
where "Γ ⟹ C" := (deriv Γ C).
(** ** Structural-free derivations *)
Reserved Infix "s⟹" (at level 90).
Inductive sderiv : list form -> form -> Prop :=
(** ** Identity *)
| Sc_ax A Γ Γ' :
Γ ++ A :: Γ' s⟹ A
(** ** Contraction *)
| Sc_contr_r A Γ Γ' Γ'' C :
Γ ++ A :: Γ' ++ A :: Γ'' s⟹ C ->
Γ ++ Γ' ++ A :: Γ'' s⟹ C
| Sc_contr_l A Γ Γ' Γ'' C :
Γ ++ A :: Γ' ++ A :: Γ'' s⟹ C ->
Γ ++ A :: Γ' ++ Γ'' s⟹ C
(** ** Right rules *)
| Sc_R_true Γ :
Γ s⟹ ⊤
| Sc_R_and A B Γ :
Γ s⟹ A -> Γ s⟹ B ->
Γ s⟹ A ∧ B
| Sc_R_or_l A B Γ :
Γ s⟹ A ->
Γ s⟹ A ∨ B
| Sc_R_or_r A B Γ :
Γ s⟹ B ->
Γ s⟹ A ∨ B
| Sc_R_imp A B Γ :
A :: Γ s⟹ B ->
Γ s⟹ A ⊃ B
| Sc_R_forall Γ C :
(fshift 1 0 <$> Γ) s⟹ C ->
Γ s⟹ #∀ C
| Sc_R_exists t Γ C :
Γ s⟹ funshift 1 0 (fsubst 0 (tshift 1 0 t) C) ->
Γ s⟹ #∃ C
(** ** Left rules *)
| Sc_L_true Γ Γ' C :
Γ ++ Γ' s⟹ C ->
Γ ++ ⊤ :: Γ' s⟹ C
| Sc_L_false Γ Γ' C :
Γ ++ ⊥ :: Γ' s⟹ C
| Sc_L_and A B Γ Γ' C :
Γ ++ A :: B :: Γ' s⟹ C ->
Γ ++ (A ∧ B) :: Γ' s⟹ C
| Sc_L_or A B Γ Γ' C :
Γ ++ A :: Γ' s⟹ C -> Γ ++ B :: Γ' s⟹ C ->
Γ ++ (A ∨ B) :: Γ' s⟹ C
| Sc_L_imp A B Γ Γ' C :
Γ ++ Γ' s⟹ A -> Γ ++ B :: Γ' s⟹ C ->
Γ ++ (A ⊃ B) :: Γ' s⟹ C
| Sc_L_forall A t Γ Γ' C :
Γ ++ funshift 1 0 (fsubst 0 (tshift 1 0 t) A) :: Γ' s⟹ C ->
Γ ++ #∀ A :: Γ' s⟹ C
| Sc_L_exists A Γ Γ' C :
(fshift 1 0 <$> Γ) ++ A :: (fshift 1 0 <$> Γ') s⟹ fshift 1 0 C ->
Γ ++ #∃ A :: Γ' s⟹ C
where "Γ s⟹ C" := (sderiv Γ C).
(** * Basic proof search *)
Ltac passum :=
match goal with
| |- ?Γ ⟹ ?C =>
let rec aux Γl Γr :=
match Γr with
| ?C :: ?Δ => apply (S_ax C Γl Δ)
| ?A :: ?Δ => aux (Γl ++ [A]) Δ
| ?Δ ++ ?Δ' => aux (Γl ++ Δ) Δ'
| [] => fail
end
in
aux (@nil form) Γ
end.
Ltac pweak i :=
match goal with
| |- ?Γ ⟹ ?C =>
let X := eval cbn in (split_at i Γ) in
match X with
| Some (?Γl, ?A :: ?Γr) => apply (S_weak A Γl Γr)
| _ => fail
end
end.
Ltac pintroL i :=
match goal with
| |- ?Γ ⟹ _ =>
let X := eval cbn in (split_at i Γ) in
match X with
| Some (?Γl, ?A :: ?Γr) =>
let rule :=
match A with
| ⊤ => constr:(S_L_true Γl Γr)
| ⊥ => constr:(S_L_false Γl Γr)
| ?A ∧ ?B => constr:(S_L_and A B Γl Γr)
| ?A ∨ ?B => constr:(S_L_or A B Γl Γr)
| #∃ ?A => constr:(S_L_exists A Γl Γr)
end
in apply rule; simpl
end
end.
Ltac pimpL i :=
match goal with
| |- ?Γ ⟹ _ =>
let X := eval cbn in (split_at i Γ) in
match X with
| Some (?Γl, ?A :: ?Γr) =>
let rule :=
match A with
| ?A ⊃ ?B => constr:(S_L_imp A B Γl Γr)
end
in apply rule; simpl
end
end.
Ltac pfaL i t :=
match goal with
| |- ?Γ ⟹ _ =>
let X := eval cbn in (split_at i Γ) in
match X with
| Some (?Γl, ?A :: ?Γr) =>
let rule :=
match A with
| #∀ ?A => constr:(S_L_forall A t Γl Γr)
end
in apply rule; simpl
end
end.
Ltac pintroR :=
match goal with
| |- _ ⟹ ?C =>
let rule :=
match C with
| ⊤ => S_R_true
| _ ∧ _ => S_R_and
| _ ⊃ _ => S_R_imp
| #∀ _ => S_R_forall
end
in apply rule
end.
Ltac pexR t :=
match goal with
| |- _ ⟹ ?C =>
let rule :=
match C with
| #∃ _ =>
let r := eval simpl in (S_R_exists t) in r
end
in apply rule
end.
Ltac isrch :=
match goal with
| |- ?Γ ⟹ _ =>
done || passum ||
tryif pintroR then isrch else
let rec introΓ n :=
match n with
| 0 => idtac
| S ?m => tryif pintroL m then isrch else introΓ m
end
in let n := eval compute in (length Γ) in
introΓ n; simpl
end.
Ltac eqd := split; isrch.
Ltac pleft := apply S_R_or_l; isrch.
Ltac pright := apply S_R_or_r; isrch.
(** * Generalized rewriting of equiderivable formulas *)
Definition eqderiv (A B : form) : Prop :=
([A] ⟹ B) /\ ([B] ⟹ A).
Infix "⟺" := eqderiv (at level 95).
#[export] Instance equiv_eqderiv : Equivalence eqderiv.
Proof.
econs; repeat red.
* move => A. split; passum.
* move => A B [HAB HBA]; done.
* move => A B C [HAB HBA] [HBC HCB]. split.
apply (S_cut B [] [A]); simpl; auto; by pweak 1.
apply (S_cut B [] [C]); simpl; auto; by pweak 1.
Qed.
#[export] Instance : Equiv form := eqderiv.
#[global] Hint Extern 1 (_ ⟺ _) => reflexivity : core.
#[global] Instance : subrelation eq eqderiv.
Proof.
red. intros A B H. by rewrite H.
Qed.
Add Morphism FAnd with signature
eqderiv ==> eqderiv ==> eqderiv
as proper_and.
Proof.
move => A B [HAB HBA] C D [HCD HDC].
split.
* isrch. by pweak 1. by pweak 0.
* isrch. by pweak 1. by pweak 0.
Qed.
Add Morphism FOr with signature
eqderiv ==> eqderiv ==> eqderiv
as proper_or.
Proof.
move => A B [HAB HBA] C D [HCD HDC].
split.
* isrch. pleft. pright.
* isrch. pleft. pright.
Qed.
Add Morphism FImp with signature
eqderiv ==> eqderiv ==> eqderiv
as proper_imp.
Proof.
move => A B [HAB HBA] C D [HCD HDC].
split.
* isrch. pimpL 1. exact. by pweak 0.
* isrch. pimpL 1. exact. by pweak 0.
Qed.
Add Morphism FForall with signature
eqderiv ==> eqderiv
as proper_forall.
Proof.
move => A B [HAB HBA].
eqd; pfaL 0 (TVar 0); by rewrite fsubst_fshift funshift_fshift.
Qed.
Add Morphism FExists with signature
eqderiv ==> eqderiv
as proper_exists.
Proof.
move => A B [HAB HBA].
eqd; pexR (TVar 0); by rewrite fsubst_fshift funshift_fshift.
Qed.
Add Morphism And with signature
Forall2 eqderiv ==> eqderiv
as proper_And.
Proof.
elim => [|A As IHA] //=.
* elim => [H |B Bs IHB H] //=; split; decompose_Forall_hyps; isrch.
* elim => [H |B Bs IHB H] //=; split; decompose_Forall_hyps; isrch.
- pweak 1. apply H.
- pweak 0. by apply IHA.
- pweak 1. apply H.
- pweak 0. by apply IHA.
Qed.
Add Morphism And with signature
Forall2 eq ==> eq
as proper_And_eq.
Proof.
move => A B H.
apply Forall2_eq_eq in H.
by rewrite H.
Qed.
Add Morphism Or with signature
Forall2 eqderiv ==> eqderiv
as proper_Or.
Proof.
elim => [|A As IHA] //=.
* elim => [H |B Bs IHB H] //=; split; decompose_Forall_hyps; isrch.
* elim => [H |B Bs IHB H] //=; split; decompose_Forall_hyps; isrch.
- pleft. apply H.
- pright. by apply IHA.
- pleft. apply H.
- pright. by apply IHA.
Qed.
Add Morphism Or with signature
Forall2 eq ==> eq
as proper_Or_eq.
Proof.
move => A B H.
apply Forall2_eq_eq in H.
by rewrite H.
Qed.
Add Morphism nforall with signature
eq ==> eqderiv ==> eqderiv
as proper_nforall.
Proof.
elim => [|n IH A B H*] //=.
apply proper_forall. by apply IH.
Qed.
Add Morphism nexists with signature
eq ==> eqderiv ==> eqderiv
as proper_nexists.
Proof.
elim => [|n IH A B H*] //=.
apply proper_exists. by apply IH.
Qed.
Lemma proper_cons_left_deriv A B Γ C :
A ⟺ B ->
A :: Γ ⟹ C <-> B :: Γ ⟹ C.
Proof.
move => [HAB HBA]. split.
* move => HA.
have HBA' : B :: Γ ⟹ A. { elim Γ => [|D Γ' IH]; auto. by pweak 1. }
have HA' : A :: B :: Γ ⟹ C. { by pweak 1. }
apply (S_cut A [] (B :: Γ)); auto.
* move => HB.
have HAB' : A :: Γ ⟹ B. { elim Γ => [|D Γ' IH]; auto. by pweak 1. }
have HB' : B :: A :: Γ ⟹ C. { by pweak 1. }
apply (S_cut B [] (A :: Γ)); auto.
Qed.
Lemma proper_app_deriv : ∀ Γ Γ' Δ C,
Forall2 eqderiv Γ Γ' ->
Δ ++ Γ ⟹ C <-> Δ ++ Γ' ⟹ C.
Proof.
induction Γ, Γ'; move => Δ C Heq; try inv Heq; auto.
move: a f H2 H4 => B B' HB HΓ.
split; move => H.
* specialize (IHΓ Γ' (B :: Δ) C HΓ).
list_simplifier.
have Hperm1 : Δ ++ B :: Γ ≡ₚ B :: Δ ++ Γ. { by solve_Permutation. }
have Hperm2 : B' :: Δ ++ Γ' ≡ₚ Δ ++ B' :: Γ'. { by solve_Permutation. }
apply (S_perm _ _ _ Hperm2).
rewrite -(proper_cons_left_deriv _ _ _ _ HB).
have H' : B :: Δ ++ Γ ⟹ C. { by apply (S_perm _ _ _ Hperm1). }
by apply IHΓ.
* specialize (IHΓ Γ' (B' :: Δ) C HΓ).
list_simplifier.
have Hperm1 : Δ ++ B :: Γ ≡ₚ B :: Δ ++ Γ. { by solve_Permutation. }
have Hperm2 : B' :: Δ ++ Γ' ≡ₚ Δ ++ B' :: Γ'. { by solve_Permutation. }
symmetry in Hperm1. apply (S_perm _ _ _ Hperm1).
rewrite (proper_cons_left_deriv _ _ _ _ HB).
have H' : B' :: Δ ++ Γ' ⟹ C. { symmetry in Hperm2. by apply (S_perm _ _ _ Hperm2). }
by apply IHΓ.
Qed.
Add Parametric Morphism : deriv with signature
Forall2 eqderiv ==> eqderiv ==> iff
as proper_deriv_concl.
Proof.
move => Γ Δ HΓΔ C D [HCD HDC].
move: Γ Δ HΓΔ.
induction Γ, Δ; intros; try inv HΓΔ.
* split; move => H. by apply (S_cut C [] []). by apply (S_cut D [] []).
* move: a f H2 H4 => E F HEF HΓΔ.
pose proof (H := IHΓ _ HΓΔ); case: H => [H1 H2].
split; move => H.
- apply (S_cut C [] (F :: Δ)).
{ apply (proper_cons_left_deriv E F); auto.
apply (proper_app_deriv Γ Δ [E]); auto. }
pweak 1. elim Δ => [|? ? ?]; auto. by pweak 1.
- apply (S_cut D [] (E :: Γ)).
{ apply (proper_cons_left_deriv E F); auto.
apply (proper_app_deriv Δ Γ [F]); auto.
by symmetry in HΓΔ. }
pweak 1. elim Γ => [|? ? ?]; auto. by pweak 1.
Qed.
Lemma eqderiv_Forall {A} (f g : A -> form):
(∀ x, f x ⟺ g x) ->
∀ l, Forall (λ x, f x ⟺ g x) l.
Proof.
move => H. elim => [|x l IH] //=.
Qed.
Lemma eqderiv_map {A} (f g : A -> form) :
(∀ x, f x ⟺ g x) ->
∀ l, Forall2 eqderiv (f <$> l) (g <$> l).
Proof.
move => H. elim => [|x l IH] //=.
Qed.
(** * Some useful tautologies *)
Section Tautos.
#[local] Ltac L := pleft.
#[local] Ltac R := pright.
Lemma true_and A :
A ∧ ⊤ ⟺ A.
Proof.
eqd.
Qed.
Lemma true_or A :
A ∨ ⊤ ⟺ ⊤.
Proof.
eqd. R.
Qed.
Lemma true_imp_l A :
⊤ ⊃ A ⟺ A.
Proof.
eqd. pimpL 0; isrch.
Qed.
Lemma true_imp_r A :
A ⊃ ⊤ ⟺ ⊤.
Proof.
eqd.
Qed.
Lemma true_forall :
#∀ ⊤ ⟺ ⊤.
Proof.
eqd.
Qed.
Lemma true_nforall : ∀ n,
n#∀ ⊤ ⟺ ⊤.
Proof.
elim => [|n IHn] //=.
rewrite IHn. eqd.
Qed.
Lemma false_and A :
A ∧ ⊥ ⟺ ⊥.
Proof.
eqd.
Qed.
Lemma false_or A :
A ∨ ⊥ ⟺ A.
Proof.
eqd. L.
Qed.
Lemma and_comm A B :
A ∧ B ⟺ B ∧ A.
Proof.
eqd.
Qed.
Lemma and_assoc A B C :
A ∧ B ∧ C ⟺ (A ∧ B) ∧ C.
Proof.
eqd.
Qed.
Lemma or_comm A B :
A ∨ B ⟺ B ∨ A.
Proof.
eqd. R. L. R. L.
Qed.
Lemma or_assoc A B C :
A ∨ B ∨ C ⟺ (A ∨ B) ∨ C.
Proof.
eqd. L; L. L; R. R. L. R; L. R; R.
Qed.
Lemma And_app Γ Δ :
⋀ (Γ ++ Δ) ⟺ ⋀ Γ ∧ ⋀ Δ.
Proof.
rewrite /And foldr_app -/And.
elim: Γ => [|A Γ IH] //=. eqd.
rewrite IH. eqd.
Qed.
Lemma Or_app Γ Δ :
⋁ (Γ ++ Δ) ⟺ ⋁ Γ ∨ ⋁ Δ.
Proof.
rewrite /Or foldr_app -/Or.
elim: Γ => [|A Γ IH] //=. eqd. R.
rewrite IH. eqd.
L; L. L; R. R. L; L. R; L. R; R.
Qed.
Lemma And_singl A :
⋀ [A] ⟺ A.
Proof.
by rewrite /= true_and.
Qed.
Lemma Or_singl A :
⋁ [A] ⟺ A.
Proof.
by rewrite /= false_or.
Qed.
Lemma currying A B C :
A ∧ B ⊃ C ⟺ A ⊃ B ⊃ C.
Proof.
eqd.