functional programming - Coq: Prove equality of two factorial functions using induction -


i want prove 2 factorial functions equivalent in coq using induction.

the base case n = 0 easy, however, induction case more complicated. see, if rewrite (visit_fac_v2 n' (n * a)) n * (visit_fac_v2 n' a), done. however, translating idea coq causes me troubles.

how 1 go proving in coq?

fixpoint fac_v1 (n : nat) : nat :=   match n   | 0 => 1   | s n' =>  n * (fac_v1 n')   end.  fixpoint visit_fac_v2 (n : nat) : nat :=   match n   | 0 =>   | s n' => visit_fac_v2 n' (n * a)   end.  definition fac_v2 (n : nat) : nat :=   visit_fac_v2 n 1.  proposition equivalence_of_fac_v1_and_fac_v2 :   forall n : nat,     fac_v1 n = fac_v2 n. proof. abort. 

a typical thing when proving direct-style function , accumulator-based equivalent equal state stronger invariant ought true value accumulator may hold.

you can specialise value function called obtaining statement interested in corollary of more general one.

the general statement here follows:

theorem general_equivalence_of_fac_v1_and_fac_v2 :   forall n : nat,     * fac_v1 n = visit_fac_v2 n a. 

and proof straightforward (you have careful , ensure induction comes before intro a because want induction hypothesis valid any a):

proof. intros n; induction n; intro a.  - simpl ; ring.  - simpl ; rewrite <- ihn ; ring. qed. 

your proposition direct consequence of more general theorem.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -