Debian Codegraph @

test-suite/success/BidirectionalityHints.v

raw
1 Set Default Proof Using "Type".
2
3 Module SimpleExamples.
4
5 Axiom c : bool -> nat.
6 Coercion c : bool >-> nat.
7 Inductive Boxed A := Box (a : A).
8 Arguments Box {A} & a.
9 Check Box true : Boxed nat.
10
11 (* Here we check that there is no regression due e.g. to refining arguments
12 in the wrong order *)
13 Axiom f : forall b : bool, (if b then bool else nat) -> Type.
14 Check f true true : Type.
15 Arguments f & _ _.
16 Check f true true : Type.
17
18 End SimpleExamples.
19
20 Module Issue7910.
21
22 Local Set Universe Polymorphism.
23
24 (** Telescopes *)
25 Inductive tele : Type :=
26 | TeleO : tele
27 | TeleS {X} (binder : X -> tele) : tele.
28
29 Arguments TeleS {_} _.
30
31 (** The telescope version of Coq's function type *)
32 Fixpoint tele_fun (TT : tele) (T : Type) : Type :=
33 match TT with
34 | TeleO => T
35 | TeleS b => forall x, tele_fun (b x) T
36 end.
37
38 Notation "TT -t> A" :=
39 (tele_fun TT A) (at level 99, A at level 200, right associativity).
40
41 (** An eliminator for elements of [tele_fun].
42 We use a [fix] because, for some reason, that makes stuff print nicer
43 in the proofs in iris:bi/lib/telescopes.v *)
44 Definition tele_fold {X Y} {TT : tele} (step : forall {A : Type}, (A -> Y) -> Y) (base : X -> Y)
45 : (TT -t> X) -> Y :=
46 (fix rec {TT} : (TT -t> X) -> Y :=
47 match TT as TT return (TT -t> X) -> Y with
48 | TeleO => fun x : X => base x
49 | TeleS b => fun f => step (fun x => rec (f x))
50 end) TT.
51 Arguments tele_fold {_ _ !_} _ _ _ /.
52
53 (** A sigma-like type for an "element" of a telescope, i.e. the data it
54 takes to get a [T] from a [TT -t> T]. *)
55 Inductive tele_arg : tele -> Type :=
56 | TargO : tele_arg TeleO
57 (* the [x] is the only relevant data here *)
58 | TargS {X} {binder} (x : X) : tele_arg (binder x) -> tele_arg (TeleS binder).
59
60 Definition tele_app {TT : tele} {T} (f : TT -t> T) : tele_arg TT -> T :=
61 fun a => (fix rec {TT} (a : tele_arg TT) : (TT -t> T) -> T :=
62 match a in tele_arg TT return (TT -t> T) -> T with
63 | TargO => fun t : T => t
64 | TargS x a => fun f => rec a (f x)
65 end) TT a f.
66 Arguments tele_app {!_ _} & _ !_ /.
67
68 Coercion tele_arg : tele >-> Sortclass.
69 Coercion tele_app : tele_fun >-> Funclass.
70
71 (** Operate below [tele_fun]s with argument telescope [TT]. *)
72 Fixpoint tele_bind {U} {TT : tele} : (TT -> U) -> TT -t> U :=
73 match TT as TT return (TT -> U) -> TT -t> U with
74 | TeleO => fun F => F TargO
75 | @TeleS X b => fun (F : TeleS b -> U) (x : X) => (* b x -t> U *)
76 tele_bind (fun a => F (TargS x a))
77 end.
78 Arguments tele_bind {_ !_} _ /.
79
80 (** Telescopic quantifiers *)
81 Definition tforall {TT : tele} (Ψ : TT -> Prop) : Prop :=
82 tele_fold (fun (T : Type) (b : T -> Prop) => forall x : T, b x) (fun x => x) (tele_bind Ψ).
83 Arguments tforall {!_} _ /.
84 Definition texist {TT : tele} (Ψ : TT -> Prop) : Prop :=
85 tele_fold ex (fun x => x) (tele_bind Ψ).
86 Arguments texist {!_} _ /.
87
88 Notation "'∀..' x .. y , P" := (tforall (fun x => .. (tforall (fun y => P)) .. ))
89 (at level 200, x binder, y binder, right associativity,
90 format "∀.. x .. y , P").
91 Notation "'∃..' x .. y , P" := (texist (fun x => .. (texist (fun y => P)) .. ))
92 (at level 200, x binder, y binder, right associativity,
93 format "∃.. x .. y , P").
94
95 (** The actual test case *)
96 Definition test {TT : tele} (t : TT -> Prop) : Prop :=
97 ∀.. x, t x /\ t x.
98
99 Notation "'[TEST' x .. z , P ']'" :=
100 (test (TT:=(TeleS (fun x => .. (TeleS (fun z => TeleO)) ..)))
101 (tele_app (fun x => .. (fun z => P) ..)))
102 (x binder, z binder).
103 Notation "'[TEST2' x .. z , P ']'" :=
104 (test (TT:=(TeleS (fun x => .. (TeleS (fun z => TeleO)) ..)))
105 (tele_app (TT:=(TeleS (fun x => .. (TeleS (fun z => TeleO)) ..)))
106 (fun x => .. (fun z => P) ..)))
107 (x binder, z binder).
108
109 Check [TEST (x y : nat), x = y].
110
111 Check [TEST2 (x y : nat), x = y].
112
113 End Issue7910.