File size: 1,959 Bytes
e63eb7f | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import OAI.Combinatorics.EditApproximation.Binary.BinaryArithmeticWork
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! Removing only leading zero bits of an integer word. This is unrelated
to rational reduction: no common divisor is computed. -/
namespace EditApproximation
theorem trimBitWordWithWork_value (bits : List Bool) :
bitWordValue (trimBitWordWithWork bits).1 = bitWordValue bits := by
induction bits with
| nil => rfl
| cons bit bits ih =>
simp only [trimBitWordWithWork]
split_ifs with h
· have ht : bitWordValue bits = 0 := by rw [← ih, h.1]; rfl
simp [h.2, bitWordValue, ht]
· simp only [bitWordValue, ih]
theorem trimBitWordWithWork_canonical (bits : List Bool) :
(trimBitWordWithWork bits).1 = (bitWordValue bits).bits := by
induction bits with
| nil => rfl
| cons bit bits ih =>
by_cases hzero : bitWordValue bits = 0
· rw [trimBitWordWithWork, ih, hzero]
cases bit <;> simp [bitWordValue, hzero]
· have hnonempty : (bitWordValue bits).bits ≠ [] := by
intro h
have hv := bitWordValue_bits (bitWordValue bits)
rw [h] at hv
exact hzero hv.symm
have hvalue : bitWordValue (bit :: bits) = Nat.bit bit (bitWordValue bits) := by
cases bit <;> simp [bitWordValue, Nat.bit, Nat.add_comm]
rw [trimBitWordWithWork, ih, ite_eq_right (by simp [hnonempty]), hvalue,
Nat.bits_append_bit _ _ (fun h => False.elim (hzero h))]
theorem trimBitWordWithWork_length (bits : List Bool) :
(trimBitWordWithWork bits).1.length = Nat.size (bitWordValue bits) := by
rw [trimBitWordWithWork_canonical, Nat.size_eq_bits_len]
theorem trimBitWordWithWork_cost (bits : List Bool) :
(trimBitWordWithWork bits).2 = 3 * bits.length + 1 := by
induction bits with
| nil => rfl
| cons bit bits ih =>
simp only [trimBitWordWithWork, List.length_cons, ih]
omega
end EditApproximation
end OAI
|