(* 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: OneStep.v  Definition of one step of the building process (merging the smallest tree) and its properties Laurent.Thery@inria.fr (2003) **********************************************************************)
From Huffman Require Export WeightTree.
From Huffman Require Export Ordered.
From Huffman Require Export SameSumLeaves.
Section OneStep.
Variable A : Type.
Variable f : A -> nat.
(* A step is valid if the two smallest elements of the initial list have been merged *)
Definition one_step (l1 l2 : list (btree A)) : Prop :=
exists l3 : list (btree A),
(exists t1 : btree A,
(exists t2 : btree A,
ordered (sum_order f) (t1 :: t2 :: l3) /\
permutation l1 (t1 :: t2 :: l3) /\
permutation l2 (node t1 t2 :: l3))).

(* Specifications: *)
(* Choosing one step or another does not change the weight *)
Theorem one_step_weight_tree_list :
forall l1 l2 l3 : list (btree A),
one_step l1 l2 ->
one_step l1 l3 -> weight_tree_list f l2 = weight_tree_list f l3.