import Tablet.P9_T1_ActualDispatchOperations import Tablet.ModelF64Neg import Tablet.Binary64ModelDefault import Mathlib.Tactic.NormNum open Aeneas Aeneas.Std Result ControlFlow Error set_option autoImplicit false namespace dec2flt_model -- [TABLET NODE: P616_T1_NegationWordLaw] theorem P616_T1_NegationWordLaw (f : F64) : exists g : F64, P9_T1_ActualDispatchOperations.negate f = ok g ∧ g.val = if f.val < 2 ^ 63 then f.val + 2 ^ 63 else f.val - 2 ^ 63 := by -- BODY refine ⟨⟨f.bv ^^^ BitVec.ofNat 64 (2^63)⟩, rfl, ?_⟩ change (f.bv ^^^ BitVec.ofNat 64 (2^63)).toNat = _ rw [BitVec.toNat_xor] norm_num only [BitVec.toNat_ofNat] have hf : f.val < 18446744073709551616 := f.bv.isLt change f.val ^^^ 9223372036854775808 = _ have hq : (f.val ^^^ 2^63) / 2^63 = f.val / 2^63 ^^^ 1 := by rw [Nat.xor_div_two_pow] norm_num have hm : (f.val ^^^ 2^63) % 2^63 = f.val % 2^63 := by rw [Nat.xor_mod_two_pow] simp have hdecomp := Nat.mod_add_div (f.val ^^^ 2^63) (2^63) have hdecompf := Nat.mod_add_div f.val (2^63) norm_num at hq hm hdecomp hdecompf by_cases h : f.val < 9223372036854775808 · rw [if_pos h] have hqf : f.val / 9223372036854775808 = 0 := by omega simp only [hqf, Nat.zero_xor] at hq omega · rw [if_neg h] have hqf : f.val / 9223372036854775808 = 1 := by omega simp only [hqf, Nat.xor_self] at hq omega end dec2flt_model