num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift

Lean checked

Definition and explanation

This explanation was written alongside the formalization to describe the statement and its reasoning.

No paired prose available.

Lean definition

This module includes declarations linked to the Aeneas extraction. The source view pairs each matched declaration with its Rust input.

import Tablet.Assumptions
import Tablet.Preamble
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_trim
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
noncomputable section
namespace dec2flt_model

-- [TABLET NODE: num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift]
/-- [dec2flt_model::num::imp::dec2flt::decimal_seq::{dec2flt_model::num::imp::dec2flt::decimal_seq::DecimalSeq}::right_shift]: loop body 1:
    Source: 'num/imp/../../dec2flt/decimal_seq.rs', lines 190:16-193:17 -/
@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0_loop0.body
  (shift : Std.Usize) (read_index : Std.Usize) (n : Std.U64) :
  Result (ControlFlow (Std.Usize × Std.U64) (Std.Usize × Std.U64))
  :=
-- BODY
do
  let i ← n >>> shift
  if i = 0#u64
  then
    let n1 ← n * 10#u64
    let read_index1 ← read_index + 1#usize
    ok (cont (read_index1, n1))
  else ok (done (read_index, n))


/-- [dec2flt_model::num::imp::dec2flt::decimal_seq::{dec2flt_model::num::imp::dec2flt::decimal_seq::DecimalSeq}::right_shift]: loop 1:
    Source: 'num/imp/../../dec2flt/decimal_seq.rs', lines 190:16-193:17 -/
@[rust_loop]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0_loop0
  (shift : Std.Usize) (read_index : Std.Usize) (n : Std.U64) :
  Result (Std.Usize × Std.U64)
  := do
  loop
    (fun (read_index1, n1) =>
      num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0_loop0.body shift
      read_index1 n1)
    (read_index, n)


/-- [dec2flt_model::num::imp::dec2flt::decimal_seq::{dec2flt_model::num::imp::dec2flt::decimal_seq::DecimalSeq}::right_shift]: loop body 0:
    Source: 'num/imp/../../dec2flt/decimal_seq.rs', lines 180:8-196:9 -/
@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0.body
  (self : num.imp.dec2flt.decimal_seq.DecimalSeq) (shift : Std.Usize)
  (read_index : Std.Usize) (n : Std.U64) (all_zero : Bool) :
  Result (ControlFlow (Std.Usize × Std.U64 × Bool)
    (num.imp.dec2flt.decimal_seq.DecimalSeq × Std.Usize × Std.U64 × Bool))
  := do
  let i ← n >>> shift
  if i = 0#u64
  then
    if all_zero
    then ok (done (self, read_index, n, true))
    else
      if read_index < self.num_digits
      then
        let i1 ← 10#u64 * n
        let i2 ← Array.index_usize self.digits read_index
        let i3 ← lift (UScalar.cast .U64 i2)
        let n1 ← i1 + i3
        let read_index1 ← read_index + 1#usize
        ok (cont (read_index1, n1, false))
      else
        if n = 0#u64
        then ok (cont (read_index, n, true))
        else
          let (read_index1, n1) ←
            num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0_loop0
              shift read_index n
          ok (done (self, read_index1, n1, false))
  else ok (done (self, read_index, n, all_zero))


/-- [dec2flt_model::num::imp::dec2flt::decimal_seq::{dec2flt_model::num::imp::dec2flt::decimal_seq::DecimalSeq}::right_shift]: loop 0:
    Source: 'num/imp/../../dec2flt/decimal_seq.rs', lines 180:8-196:9 -/
@[rust_loop]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0
  (self : num.imp.dec2flt.decimal_seq.DecimalSeq) (shift : Std.Usize)
  (read_index : Std.Usize) (n : Std.U64) (all_zero : Bool) :
  Result (num.imp.dec2flt.decimal_seq.DecimalSeq × Std.Usize × Std.U64 ×
    Bool)
  := do
  loop
    (fun (read_index1, n1, all_zero1) =>
      num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0.body self shift
      read_index1 n1 all_zero1)
    (read_index, n, all_zero)


/-- [dec2flt_model::num::imp::dec2flt::decimal_seq::{dec2flt_model::num::imp::dec2flt::decimal_seq::DecimalSeq}::right_shift]: loop body 2:
    Source: 'num/imp/../../dec2flt/decimal_seq.rs', lines 209:8-215:9 -/
@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1.body
  (i : Std.Usize) (shift : Std.Usize) (mask : Std.U64)
  (a : Array Std.U8 768#usize) (read_index : Std.Usize)
  (write_index : Std.Usize) (n : Std.U64) :
  Result (ControlFlow ((Array Std.U8 768#usize) × Std.Usize × Std.Usize ×
    Std.U64) ((Array Std.U8 768#usize) × Std.Usize × Std.U64))
  := do
  if read_index < i
  then
    let i1 ← n >>> shift
    let new_digit ← lift (UScalar.cast .U8 i1)
    let i2 ← lift (n &&& mask)
    let i3 ← 10#u64 * i2
    let i4 ← Array.index_usize a read_index
    let i5 ← lift (UScalar.cast .U64 i4)
    let n1 ← i3 + i5
    let read_index1 ← read_index + 1#usize
    let a1 ← Array.update a write_index new_digit
    let write_index1 ← write_index + 1#usize
    ok (cont (a1, read_index1, write_index1, n1))
  else ok (done (a, write_index, n))


/-- [dec2flt_model::num::imp::dec2flt::decimal_seq::{dec2flt_model::num::imp::dec2flt::decimal_seq::DecimalSeq}::right_shift]: loop 2:
    Source: 'num/imp/../../dec2flt/decimal_seq.rs', lines 209:8-215:9 -/
@[rust_loop]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
  (i : Std.Usize) (a : Array Std.U8 768#usize) (shift : Std.Usize)
  (read_index : Std.Usize) (write_index : Std.Usize) (n : Std.U64)
  (mask : Std.U64) :
  Result ((Array Std.U8 768#usize) × Std.Usize × Std.U64)
  := do
  loop
    (fun (a1, read_index1, write_index1, n1) =>
      num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1.body i shift
      mask a1 read_index1 write_index1 n1)
    (a, read_index, write_index, n)


/-- [dec2flt_model::num::imp::dec2flt::decimal_seq::{dec2flt_model::num::imp::dec2flt::decimal_seq::DecimalSeq}::right_shift]: loop body 3:
    Source: 'num/imp/../../dec2flt/decimal_seq.rs', lines 216:8-225:9 -/
@[rust_loop_body]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body
  (shift : Std.Usize) (mask : Std.U64) (b : Bool) (a : Array Std.U8 768#usize)
  (write_index : Std.Usize) (n : Std.U64) :
  Result (ControlFlow (Bool × (Array Std.U8 768#usize) × Std.Usize ×
    Std.U64) (Bool × (Array Std.U8 768#usize) × Std.Usize))
  := do
  if n > 0#u64
  then
    let i ← n >>> shift
    let new_digit ← lift (UScalar.cast .U8 i)
    let i1 ← lift (n &&& mask)
    let n1 ← 10#u64 * i1
    if write_index < num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS
    then
      let a1 ← Array.update a write_index new_digit
      let write_index1 ← write_index + 1#usize
      ok (cont (b, a1, write_index1, n1))
    else
      if new_digit > 0#u8
      then ok (cont (true, a, write_index, n1))
      else ok (cont (b, a, write_index, n1))
  else ok (done (b, a, write_index))


/-- [dec2flt_model::num::imp::dec2flt::decimal_seq::{dec2flt_model::num::imp::dec2flt::decimal_seq::DecimalSeq}::right_shift]: loop 3:
    Source: 'num/imp/../../dec2flt/decimal_seq.rs', lines 216:8-225:9 -/
@[rust_loop]
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
  (b : Bool) (a : Array Std.U8 768#usize) (shift : Std.Usize)
  (write_index : Std.Usize) (n : Std.U64) (mask : Std.U64) :
  Result (Bool × (Array Std.U8 768#usize) × Std.Usize)
  := do
  loop
    (fun (b1, a1, write_index1, n1) =>
      num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2.body shift mask
      b1 a1 write_index1 n1)
    (b, a, write_index, n)


/-- [dec2flt_model::num::imp::dec2flt::decimal_seq::{dec2flt_model::num::imp::dec2flt::decimal_seq::DecimalSeq}::right_shift]:
    Source: 'num/imp/../../dec2flt/decimal_seq.rs', lines 175:4-228:5 -/
def num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
  (self : num.imp.dec2flt.decimal_seq.DecimalSeq) (shift : Std.Usize) :
  Result num.imp.dec2flt.decimal_seq.DecimalSeq
  := do
  let (self1, read_index, n, all_zero) ←
    num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop0 self shift 0#usize
      0#u64 false
  if all_zero
  then ok self1
  else
    let i ← lift (UScalar.hcast .I32 read_index)
    let i1 ← i - 1#i32
    let i2 ← self1.decimal_point - i1
    let i3 ← -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
    if i2 < i3
    then
      ok
        {
          self1
            with
            num_digits := 0#usize, decimal_point := 0#i32, truncated := false
        }
    else
      let i4 ← 1#u64 <<< shift
      let mask ← i4 - 1#u64
      let (a, write_index, n1) ←
        num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop1
          self1.num_digits self1.digits shift read_index 0#usize n mask
      let (b, a1, write_index1) ←
        num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift_loop2
          self1.truncated a shift write_index n1 mask
      num.imp.dec2flt.decimal_seq.DecimalSeq.trim
        {
          num_digits := write_index1,
          decimal_point := i2,
          truncated := b,
          digits := a1
        }
Preservation and explanation

Natural-language argument

The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.

Explanatory prose status

Prose retained as authored. The explanatory prose is preserved as it stood when captured.

The authored explanation is included with the statement above.

Download Lean source · Download TeX source

Proof structure

Follow the declared dependencies to read the supporting statements and proofs.

Explore this dependency tree

Inspect related source (58)
More program dependencies (25)
Standard-library dependencies (30)

Related source and models come from the extraction records and declared dependencies.

Proof assumptions and review

Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.

Transitive assumptions

This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.

Helper theorems included
Technical checking records
Local closure summary
{
  "node": "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "13fc13d22d10f0013f802c593bba22671090e7e43810757cd772c56c3a0dfe41",
  "active_statement_hash": "",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "d5c04ffa333d9b33b238a527f5beaa2be82e021d3e9c0bbe01b1310280f7f55a",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-23",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "13e3cec939d02f51",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE": "0cc5155758bc976a",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_trim": "faa9fd92b8c29c14"
  }
}
Prose assessment
{
  "label": "Prose review has no verdict in this snapshot",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": null,
  "superseded_for_theorem_closure": false
}
Review verdicts
{}