Problem: integer_exponential

Your task is to implement the Naive Exponentiation Algorithm and verify its functional correctness in Dafny. This algorithm computes the power of an integer using a simple linear iteration. Preconditions: The input base b and exponent e are of type int and are non-negative. To ensure safety, you may assume that the mathematical result $b^e$ fits within the u64 range (i.e., $spec\_pow(b, e) \le \text{0xffff\_ffff\_ffff\_ffff}$). Requirements: Implement the function to compute the exponential which returns an int. (1) Functional Correctness: You must define a recursive ghost function spec_pow(b, e) and prove that your implementation returns exactly this value. (2) Safety: You must ensure the return value is non-negative. Verification Challenges: (1) Accumulation Invariant: The algorithm runs for e iterations. You must prove the loop invariant that after i iterations, the accumulator variable equals spec_pow(b, i). (2) Monotonicity: To ensure logical consistency with the bounds, you may need to establish that $b^i \le b^e$ for $i \le e$, ensuring intermediate values stay within the assumed range.

// Following is the block for necessary definitions
// <preamble>
// Pure mathematical definition of power
function spec_pow(b: nat, e: nat): nat
  decreases e
{
  if e == 0 then
    1
  else
    b * spec_pow(b, e - 1)
}
// </preamble>

// Following is the block for potential helper specifications
// <helpers>

// </helpers>

// Following is the block for proofs of lemmas
// <proofs>

// </proofs>

// Following is the block for the main specification
// <spec>
method exponentiation(b: int, e: int) returns (res: int)
  // Simulate u64 types (non-negative)
  requires b >= 0 
  requires e >= 0
  // Precondition: Result fits in u64 (0xffff_ffff_ffff_ffff)
  requires spec_pow(b, e) <= 0xffff_ffff_ffff_ffff
  
  ensures res == spec_pow(b, e)
  // Ensure return value preserves non-negativity
  ensures res >= 0
// </spec>
// <code>
{
  // Implement and verify the algorithm to compute the exponential
}
// </code>

method Main() {
  // Empty main
}