How do I prove that two Fibonacci implementations are equal in Coq?

后端 未结 6 1234
南方客
南方客 2021-01-03 16:36

I\'ve two Fibonacci implementations, seen below, that I want to prove are functionally equivalent.

I\'ve already proved properties about natural numbers, but this ex

6条回答
  •  清酒与你
    2021-01-03 17:03

    This proof script only shows the proof structure. It could be useful to explain the idea of the proof.

    Require Import Ring Arith Psatz.  (* Psatz required by firstorder *)
    
    Theorem fibfib: forall n, fib_v2 n 0 1 = fib_v1 n.
    Proof with (intros; simpl in *; ring || firstorder).
      assert (H: forall n a0 a1, fib_v2 (S n) a0 a1 = a0 * (fib_v1 n) + a1 * (fib_v1 (S n))).
      { induction n... rewrite IHn; destruct n... }
      destruct n; try rewrite H...
    Qed.
    

提交回复
热议问题