|
|
||
|
|
Start of topic | Skip to actions
Recall that
split '(n) slist-> '(n/2) slist, '(n/2) slist
let rec split .|n| l=
match l with cons .|m1| (x,xs)->
match xs with cons .|m2| (y,ys)->
let (o,e)=split .|m2| ys in
(x,o) (y,e)
This function will type correctly. The problem is that we have problems with n is odd. We can't guarantee that the resulting type is n/2 slist, n/2 slist. It will instead be floor(n/2) slist, floor(n/2) slist. Thus, we tried to pass in a parameter p that states whether p is even or odd. In this case, we can guarantee that the resulting type is correct. Unfortunately, there's a bug in Concoqtion where context refinement fails. Thus, we need to wait for an update before we can fix this problem. Alternatively, we can write code that does context refinement by hand, but that will be slightly more complicated.
We also need to guarantee that the slist passed into fft has a length that is a power of two. So, in Coq, we want
isPower: nat->Prop
| 1: isPower
| forall n: isPower n->isPower 2*n
Thus, in the fft function, we want
let rec fft .|n:'(nat), p:'(isPower n)| l
is (fftlength .|'(n)| l = 1 then l
else
let (o,e)=split .|n,p1| l (*p1 denotes whether the list is even.*)
(* need to show that p proves p1 *)
let y0=fft .|'(div2 n),'(isPower n/2)| dir e in
let y0=fft .|'(div2 n),'(isPower n/2)| dir 0 in
For this to work, we want a theorem that states
isPower n->(n>1)->isPower n/2
Thus, we need to guarantee that n>1. One idea is to use a match statement to catch the case when the length becomes 1. Another is to construct a new type
type 'm:'(nat) isMoreThanOne=
| NO : '(0) isMoreThanOne
| NO1 : '(1) isMoreThanOne
| Yes: forall m. '(S(S m)) isMoreThanOne
This point of this is that not only do we know that something is or is not more than one, but we also have information on the size that we can use for proofs. Thus, we can pattern match over the return of the new fftlength function. In the case where the length isMoreThanOne, we have enough information to prove that n/1 for the new theorem above
isPower n->(n>1)->isPower n/2
This is illustrative of a general Coq technique. Instead of passing around booleans, we pass around booleans with a proof that they are correct.
Topic Actions: Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
Webs: Main | TWiki | Africa | EmbeddedSystems | Gpce | Houston | International | K12 | MetaOCaml | MulticoreOCR | ProgrammingLanguages | RAP | RIDL | Sandbox | SpeechClub | Teaching | Texbot | WG211 Web Actions: |
|
This work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.