Problem: fast_exponential

Your task is to implement the Fast Exponentiation Algorithm (Exponentiation by Squaring) and verify its correctness in Lean. Given a base b and a non-negative exponent e, compute b to the power of e in logarithmic time complexity. Preconditions: Result must fit within 64-bit unsigned integer limits (UInt64). Postconditions: Implement the function `exponentiation`. (1) Structure: Implementation should involve `exponentiation_by_squaring_aux`. (2) Functional Correctness: You must verify that your implementation returns exactly `b ^ e` (as defined by `Nat.pow`). (3) Safety: You must prove that neither the accumulator updates nor the squaring of the base ever cause a `UInt64` overflow. Verification Challenges: (1) Algebraic Lemmas: The core logic relies on $(b^2)^k = b^{2k}$. You must state and verify helper lemmas to handle this non-linear arithmetic. (2) Conservation Invariant: You must prove that at every step of the recursion/loop, $current\_res \times current\_base^{current\_exp} = original\_base^{original\_exp}$. (3) Intermediate Overflow Safety: You must prove that the base `b` is never squared if it would exceed `UInt64` limits, or that such squaring is avoided when unnecessary.

import Mathlib

-- Precondition definitions
@[reducible, simp]
def exponentiation_precond (b e : UInt64) : Prop :=
  -- !benchmark @start precond
  b.toNat ^ e.toNat ≤ (2 ^ 64 - 1)
  -- !benchmark @end precond

-- !benchmark @start auxcode
-- !benchmark @end auxcode

-- Main function definitions
def exponentiation (b e : UInt64) (h_precond : exponentiation_precond b e) : UInt64 :=
  -- !benchmark @start code
  sorry
  -- !benchmark @end code

-- Postcondition definitions
@[reducible, simp]
def exponentiation_postcond (b e : UInt64) (result : UInt64) (h_precond : exponentiation_precond b e) : Prop :=
  -- !benchmark @start postcond
  result.toNat = b.toNat ^ e.toNat
  -- !benchmark @end postcond

-- !benchmark @start lemma
-- !benchmark @end lemma

-- Proof content
theorem exponentiation_postcond_satisfied (b e : UInt64)
    (h_precond : exponentiation_precond b e) :
    exponentiation_postcond b e (exponentiation b e h_precond) h_precond := by
  -- !benchmark @start proof
  sorry
  -- !benchmark @end proof