$\begin{split}\newcommand{\alors}{\textsf{then}} \newcommand{\alter}{\textsf{alter}} \newcommand{\as}{\kw{as}} \newcommand{\Assum}{\kw{Assum}(#1)(#2:#3)} \newcommand{\bool}{\textsf{bool}} \newcommand{\case}{\kw{case}} \newcommand{\conc}{\textsf{conc}} \newcommand{\cons}{\textsf{cons}} \newcommand{\consf}{\textsf{consf}} \newcommand{\conshl}{\textsf{cons\_hl}} \newcommand{\Def}{\kw{Def}(#1)(#2:=#3:#4)} \newcommand{\emptyf}{\textsf{emptyf}} \newcommand{\End}{\kw{End}} \newcommand{\kwend}{\kw{end}} \newcommand{\EqSt}{\textsf{EqSt}} \newcommand{\even}{\textsf{even}} \newcommand{\evenO}{\textsf{even}_\textsf{O}} \newcommand{\evenS}{\textsf{even}_\textsf{S}} \newcommand{\false}{\textsf{false}} \newcommand{\filter}{\textsf{filter}} \newcommand{\Fix}{\kw{Fix}} \newcommand{\fix}{\kw{fix}} \newcommand{\for}{\textsf{for}} \newcommand{\forest}{\textsf{forest}} \newcommand{\from}{\textsf{from}} \newcommand{\Functor}{\kw{Functor}} \newcommand{\haslength}{\textsf{has\_length}} \newcommand{\hd}{\textsf{hd}} \newcommand{\ident}{\textsf{ident}} \newcommand{\In}{\kw{in}} \newcommand{\Ind}{\kw{Ind}[#2](#3:=#4)} \newcommand{\ind}{\kw{Ind}~[#1]\left(#2\mathrm{~:=~}#3\right)} \newcommand{\Indp}{\kw{Ind}_{#5}(#1)[#2](#3:=#4)} \newcommand{\Indpstr}{\kw{Ind}_{#5}(#1)[#2](#3:=#4)/{#6}} \newcommand{\injective}{\kw{injective}} \newcommand{\kw}{\textsf{#1}} \newcommand{\lb}{\lambda} \newcommand{\length}{\textsf{length}} \newcommand{\letin}{\kw{let}~#1:=#2~\kw{in}~#3} \newcommand{\List}{\textsf{list}} \newcommand{\lra}{\longrightarrow} \newcommand{\Match}{\kw{match}} \newcommand{\Mod}{{\kw{Mod}}({#1}:{#2}\,\zeroone{:={#3}})} \newcommand{\ModA}{{\kw{ModA}}({#1}=={#2})} \newcommand{\ModS}{{\kw{Mod}}({#1}:{#2})} \newcommand{\ModType}{{\kw{ModType}}({#1}:={#2})} \newcommand{\mto}{.\;} \newcommand{\Nat}{\mathbb{N}} \newcommand{\nat}{\textsf{nat}} \newcommand{\Nil}{\textsf{nil}} \newcommand{\nilhl}{\textsf{nil\_hl}} \newcommand{\nO}{\textsf{O}} \newcommand{\node}{\textsf{node}} \newcommand{\nS}{\textsf{S}} \newcommand{\odd}{\textsf{odd}} \newcommand{\oddS}{\textsf{odd}_\textsf{S}} \newcommand{\ovl}{\overline{#1}} \newcommand{\Pair}{\textsf{pair}} \newcommand{\plus}{\mathsf{plus}} \newcommand{\Prod}{\textsf{prod}} \newcommand{\SProp}{\textsf{SProp}} \newcommand{\Prop}{\textsf{Prop}} \newcommand{\return}{\kw{return}} \newcommand{\Set}{\textsf{Set}} \newcommand{\si}{\textsf{if}} \newcommand{\sinon}{\textsf{else}} \newcommand{\Sort}{\mathcal{S}} \newcommand{\Str}{\textsf{Stream}} \newcommand{\Struct}{\kw{Struct}} \newcommand{\subst}{#1\{#2/#3\}} \newcommand{\tl}{\textsf{tl}} \newcommand{\tree}{\textsf{tree}} \newcommand{\trii}{\triangleright_\iota} \newcommand{\true}{\textsf{true}} \newcommand{\Type}{\textsf{Type}} \newcommand{\unfold}{\textsf{unfold}} \newcommand{\WEV}{\mbox{#1[] \vdash #2 \lra #3}} \newcommand{\WEVT}{\mbox{#1[] \vdash #2 \lra}\\ \mbox{ #3}} \newcommand{\WF}{{\mathcal{W\!F}}(#1)[#2]} \newcommand{\WFE}{\WF{E}{#1}} \newcommand{\WFT}{#1[] \vdash {\mathcal{W\!F}}(#2)} \newcommand{\WFTWOLINES}{{\mathcal{W\!F}}\begin{array}{l}(#1)\\\mbox{}[{#2}]\end{array}} \newcommand{\with}{\kw{with}} \newcommand{\WS}{#1[] \vdash #2 <: #3} \newcommand{\WSE}{\WS{E}{#1}{#2}} \newcommand{\WT}{#1[#2] \vdash #3 : #4} \newcommand{\WTE}{\WT{E}{#1}{#2}{#3}} \newcommand{\WTEG}{\WTE{\Gamma}{#1}{#2}} \newcommand{\WTM}{\WT{#1}{}{#2}{#3}} \newcommand{\zeroone}{[{#1}]} \newcommand{\zeros}{\textsf{zeros}} \end{split}$

# Miscellaneous extensions¶

## Program derivation¶

Coq comes with an extension called Derive, which supports program derivation. Typically in the style of Bird and Meertens or derivations of program refinements. To use the Derive extension it must first be required with Require Coq.derive.Derive. When the extension is loaded, it provides the following command:

Command Derive ident1 SuchThat type As ident2

ident1 can appear in type. This command opens a new proof presenting the user with a goal for type in which the name ident1 is bound to an existential variable ?x (formally, there are other goals standing for the existential variables but they are shelved, as described in shelve).

When the proof ends two constants are defined:

• The first one is named ident1 and is defined as the proof of the shelved goal (which is also the value of ?x). It is always transparent.
• The second one is named ident2. It has type type, and its body is the proof of the initially visible goal. It is opaque if the proof ends with Qed, and transparent if the proof ends with Defined.

Example

Require Coq.derive.Derive.
Require Import Coq.Numbers.Natural.Peano.NPeano.
Section P.
Variables (n m k:nat).
n is declared m is declared k is declared
Derive p SuchThat ((k*n)+(k*m) = p) As h.
1 focused subgoal (shelved: 1) n, m, k : nat p := ?Goal : nat ============================ k * n + k * m = p
Proof.
Any property can be used as term, not only an equation. In particular, it could be an order relation specifying some form of program refinement or a non-executable property from which deriving a program is convenient.
{"ft_lang_label":"__label__en","ft_lang_prob":0.84304625,"math_prob":0.94921684,"size":2165,"snap":"2020-10-2020-16","text_gpt3_token_len":602,"char_repetition_ratio":0.13095789,"word_repetition_ratio":0.1495098,"special_character_ratio":0.31362587,"punctuation_ratio":0.17551963,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9774205,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-03-29T20:37:19Z\",\"WARC-Record-ID\":\"<urn:uuid:dab9602d-58ec-418f-8f5f-4fd2593cf49d>\",\"Content-Length\":\"136106\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b415270d-55e5-45d0-99ce-3ed49d6f1924>\",\"WARC-Concurrent-To\":\"<urn:uuid:e86c1284-9940-4df0-8c3d-786695d02b68>\",\"WARC-IP-Address\":\"51.91.56.51\",\"WARC-Target-URI\":\"https://coq.inria.fr/refman/addendum/miscellaneous-extensions.html\",\"WARC-Payload-Digest\":\"sha1:S7V77APR6BJIWSBDF3FQAWAQR6GS2P5L\",\"WARC-Block-Digest\":\"sha1:B2H2MI2OTMPAYSI4OZOMDNR3E2IZRSNS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585370496227.25_warc_CC-MAIN-20200329201741-20200329231741-00368.warc.gz\"}"}