(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU Lesser General Public License for more details.                *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(***********************************************************************)
(*    Proof of Huffman algorithm: Build.v                              *)
(*                                                                     *)
(*    Define the build process iteratively  merging the two smaller    *)
(*    trees                                                            *)
(*                                                                     *)
(*    Definition: build build_fun                                      *)
(*                                    Laurent.Thery@inria.fr (2003)    *)
(***********************************************************************)
From Huffman Require Export OneStep.
From Huffman Require Export HeightPred.
From Huffman Require Export CoverMin.
From Huffman Require Export OrderedCover.
From Huffman Require Export SubstPred.
Section Build.
Variable A : Type.
Variable f : A -> nat.
(* Iterative the one step predicate *)
Inductive build : list (btree A) -> btree A -> Prop :=
| build_one : forall t : btree A, build (t :: nil) t
| build_step :
forall (t : btree A) (l1 l2 : list (btree A)),
one_step f l1 l2 -> build l2 t -> build l1 t.

(* Building gives a cover *)
Theorem build_cover : forall l t, build l t -> cover l t.
Proof using.