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