File size: 1,360 Bytes
bff4ec7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Algorithms.huffman_encoding.lean.spec_lib

namespace Algorithms.huffman_encoding.lean

open AUXLib MaxMinLib

def HuffmanResidualOptimum (input live : List Int) (accumulated : Int) : Prop :=
  sum live = sum input ∧ ∃ remaining, HuffmanOptimalCost live remaining ∧ HuffmanOptimalCost input (accumulated + remaining)

def HuffmanProgress (input scratch : List Int) (active accumulated : Int) : Prop :=
  HuffmanResidualOptimum input (sublist 0 active scratch) accumulated

def HuffmanMinScan (scratch : List Int) (scanned best : Int) : Prop :=
  ∀ k, (0 ≤ k ∧ k < scanned) → Znth best scratch 0 ≤ Znth k scratch 0

def HuffmanFirstHeld (input scratch : List Int) (active held accumulated : Int) : Prop :=
  ∃ prior_live, List.Perm prior_live (held :: sublist 0 active scratch) ∧
    (∀ weight, weight ∈ prior_live → held ≤ weight) ∧ HuffmanResidualOptimum input prior_live accumulated

def HuffmanPairReady (input scratch : List Int) (active first second accumulated : Int) : Prop :=
  ∃ prior_live, List.Perm prior_live (first :: second :: sublist 0 active scratch) ∧
    (∀ weight, weight ∈ prior_live → first ≤ weight) ∧
    (∀ weight, weight ∈ (second :: sublist 0 active scratch) → second ≤ weight) ∧
    HuffmanResidualOptimum input prior_live accumulated

end Algorithms.huffman_encoding.lean