-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunG_prog.v
47 lines (39 loc) · 1.04 KB
/
FunG_prog.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
(** * FunG_prog : Alternative definition of Hofstadter's G function *)
From Coq Require Import Program Program.Wf.
Require Import DeltaList FunG.
Set Implicit Arguments.
(** Same as [FunG.g_spec], but via the Program framework *)
Program Fixpoint g_spec n { measure n } : { r : nat | G n r } :=
match n with
| O => O
| S n => S n - g_spec (g_spec n)
end.
Next Obligation.
autoh.
Defined.
Next Obligation.
destruct g_spec; simpl. apply le_n_S. now apply G_le.
Defined.
Next Obligation.
program_simpl.
destruct (g_spec _) as (a,Ha).
program_simpl.
destruct (g_spec _) as (b,Hb).
program_simpl.
eapply GS; eauto. change (S n = S n - b + b).
generalize (G_le Ha) (G_le Hb). lia.
Defined.
Definition g n := let (a,_) := g_spec n in a.
(*Eval lazy in g 55.*) (* Compute is very slow... *)
(*
Require Import Extraction.
Extraction Inline g_spec.
Recursive Extraction g.
*)
(** This is just an alternative presentation... *)
Lemma nothing_new n : g n = FunG.g n.
Proof.
apply G_fun with n.
unfold g. now destruct g_spec.
apply FunG.g_correct.
Qed.