jscoq | A port of Coq to Javascript -- Run Coq in your Browser | Code Editor library
kandi X-RAY | jscoq Summary
kandi X-RAY | jscoq Summary
A port of Coq to Javascript -- Run Coq in your Browser
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of jscoq
jscoq Key Features
jscoq Examples and Code Snippets
Community Discussions
Trending Discussions on jscoq
QUESTION
I am currently reading the first volume of the softwarefoundations series. In one of the exercises I am supposed to write a function which turns a natural number (unary form) into the equivalent binary number.
This is my code/approach:
...ANSWER
Answered 2021-Mar-12 at 11:45To retain good logical properties, all functions definable in Coq are terminating. To enforce that, there is a restriction on fixpoint definitions, like the one you are trying to do, called the guard condition. This restriction is roughly that the recursive call can only be done on subterms of the argument of the function.
This is not the case in your definition, where you apply nat_to_bin
to the terms (Nat.div n 2)
and (Nat.modulo n 2)
which are functions applied to n
. Although you can mathematically prove that those are always smaller than n
, they are no subterms of n
, so your function does not respect the guard condition.
If you wanted to define nat_to_bin
in the way you are doing, you would need to resort to well-founded induction, which would use the well-foundedness of the order on nat
to allow you to call you function on any term you can prove smaller than n
. However, this solution is quite complex, because it would force you to do some proofs that are not that easy.
Instead, I would advise going another way: just above in the book, it is suggested to define a function incr : bin -> bin
that increments a binary number by one. You can use that one to define nat_to_bin
by a simple recursion on n
, like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install jscoq
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page