General recursive functions
The total relation.
We assume an inconsistent axiom here, one should be added function per function.
Axiom wf_total_init : ∀ {A}, WellFounded (@total_relation A).
Remove Hints wf_total_init : typeclass_instances.
Remove Hints wf_total_init : typeclass_instances.
We fuel it with some Acc_intro constructors so that definitions relying on it
can unfold a fixed number of times still.
Instance wf_total_init_compute : ∀ {A}, WellFounded (@total_relation A).
exact (fun A ⇒ Acc_intro_generator 10 wf_total_init).
Defined.
exact (fun A ⇒ Acc_intro_generator 10 wf_total_init).
Defined.
Now we define an obviously non-terminating function.
Equations? nonterm (n : nat) : nat by wf n (@total_relation nat) :=
nonterm 0 := 0;
nonterm (S n) := S (nonterm (S n)).
Proof.
(* Every pair of arguments is in the total relation: so
total_relation (S n) (S n) *)
constructor.
Defined.
nonterm 0 := 0;
nonterm (S n) := S (nonterm (S n)).
Proof.
(* Every pair of arguments is in the total relation: so
total_relation (S n) (S n) *)
constructor.
Defined.
The automation has a little trouble here as it assumes
well-founded definitions implicitely. We show the second
equation: nonterm (S n) = S (nonterm (S n)) using the
unfolding equation.
Next Obligation.
now rewrite nonterm_unfold_eq at 1.
Defined.
(* Note this is a dangerous rewrite rule, so we should remove it from the hints *)
(* Print Rewrite HintDb nonterm. *)
now rewrite nonterm_unfold_eq at 1.
Defined.
(* Note this is a dangerous rewrite rule, so we should remove it from the hints *)
(* Print Rewrite HintDb nonterm. *)
Make nonterm transparent anyway so we can compute with it
We can compute with it (for closed natural numbers)
Fixpoint at_least_five (n : nat) : bool :=
match n with
| S (S (S (S (S x)))) ⇒ true
| _ ⇒ false
end.
match n with
| S (S (S (S (S x)))) ⇒ true
| _ ⇒ false
end.
Indeed it unfolds enough so that at_least_five gives back a result.
Example check_10 := eq_refl : at_least_five (nonterm 10) = true.
Example check_0 := eq_refl : at_least_five (nonterm 0) = false.
Example check_0 := eq_refl : at_least_five (nonterm 0) = false.
The elimination principle completely abstracts away from the
termination argument as well
This page has been generated by coqdoc