4
$\begingroup$

People usually say Coq does not allow writing non-terminating functions. I have a question regarding that.

Does Coq allow writing exactly all terminating functions? In other words, what are the completeness and soundness properties of Coq's procedure for checking well-foundness of fixpoint definitions?

$\endgroup$

marked as duplicate by Raphael May 2 '14 at 21:31

This question was marked as an exact duplicate of an existing question.

  • $\begingroup$ Questions about specifics of programming languages are usually off-topic here; the underlying conceptual question that answers yours already has answers on the site, though. $\endgroup$ – Raphael May 2 '14 at 21:31
4
$\begingroup$

Coq cannot always know whether a program will terminate, because that would be a solution to the halting problem.

Coq is able to notice that a certain class of programs will terminate. The main heuristic it uses is that if one of the arguments to the function must get smaller on each recursive call, the program must terminate.

If you have a function that terminates, but Coq cannot tell that it terminates, you can add an extra argument that always get smaller on recursive calls. Doing this amounts to providing a proof that the function terminates.

So basically, Coq accepts any program that the user can prove the termination of.

$\endgroup$
3
$\begingroup$

There is no effective enumeration of all decidable languages. For suppose that $P_i$ was an effective sequence of programs (meaning that the mapping $i \mapsto P_i$ is computable) such that each $P_i$ always halts, and every decidable language is $L(P_i)$ for some $i$. Consider the program $P$ which, on input $i$, runs $P_i$ on input $i$ and accepts if $P_i$ rejects. The program $P$ always halts and so $L(P)$ is decidable, hence $L(P) = L(P_i)$ for some $i$. But by construction, $i \in L(P)$ iff $i \notin L(P_i)$. This contradiction shows that no such effective enumeration is possible.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.