Debian Codegraph @

test-suite/bugs/bug_3209.v

raw
1 (* Avoiding some occur-check *)
2
3 (* 1. Original example *)
4
5 Inductive eqT {A} (x : A) : A -> Type :=
6 reflT : eqT x x.
7 Definition Bi_inv (A B : Type) (f : (A -> B)) :=
8 sigT (fun (g : B -> A) =>
9 sigT (fun (h : B -> A) =>
10 sigT (fun (α : forall b : B, eqT (f (g b)) b) =>
11 forall a : A, eqT (h (f a)) a))).
12 Definition TEquiv (A B : Type) := sigT (fun (f : A -> B) => Bi_inv _ _ f).
13
14 Axiom UA : forall (A B : Type), TEquiv (TEquiv A B) (eqT A B).
15 Definition idtoeqv {A B} (e : eqT A B) : TEquiv A B :=
16 sigT_rect (fun _ => TEquiv A B)
17 (fun (f : TEquiv A B -> eqT A B) H =>
18 sigT_rect _ (* (fun _ => TEquiv A B) *)
19 (fun g _ => g e)
20 H)
21 (UA A B).
22
23 (* 2. Alternative example by Guillaume *)
24
25 Inductive foo (A : Prop) : Prop := Foo : foo A.
26 Axiom bar : forall (A : Prop) (P : foo A -> Prop), (A -> P (Foo A)) -> Prop.
27
28 (* This used to fail with a Not_found, we fail more graciously but a
29 heuristic could be implemented, e.g. in some smart occur-check
30 function, to find a solution of then form ?P := fun _ => ?P' *)
31
32 Fail Check (fun e : ?[T] => bar ?[A] ?[P] (fun g : ?[A'] => g e)).
33
34 (* This works and tells which solution we could have inferred *)
35
36 Check (fun e : ?[T] => bar ?[A] (fun _ => ?[P]) (fun g : ?[A'] => g e)).
37
38 (* For the record, here is the trace in the failing example:
39
40 In (fun e : ?T => bar ?[A] ?[P] (fun g : ?A' => g e)), we have the existential variables
41
42 e:?T |- ?A : Prop
43 e:?T |- ?P : foo ?A -> Prop
44 e:?T |- ?A' : Type
45
46 with constraints
47
48 ?A' == ?A
49 ?A' == ?T -> ?P (Foo ?A)
50
51 To type (g e), unification first defines
52
53 ?A := forall x:?B, ?P'{e:=e,x:=x}
54 with ?T <= ?B
55 and ?P'@{e:=e,x:=e} <= ?P@{e:=e} (Foo (forall x:?B, ?P'{e:=e,x:=x}))
56
57 Then, since ?P'@{e:=e,x:=e} may use "e" in two different ways, it is
58 not a pattern and we define a new
59
60 e:?T x:?B|- ?P'' : foo (?B' -> ?P''') -> Prop
61
62 for some ?B' and ?P''', together with
63
64 ?P'@{e,x} := ?P''{e:=e,x:=e} (Foo (?B -> ?P')
65 ?P@{e} := ?P''{e:=e,x:=e}
66
67 Moreover, ?B' and ?P''' have to satisfy
68
69 ?B'@{e:=e,x:=e} == ?B@{e:=e}
70 ?P'''@{e:=e,x:=e} == ?P'@{e:=e,x:=x}
71
72 and this leads to define ?P' which was the initial existential
73 variable to define.
74 *)