SNAPKITTYWEST's picture
chore: push full sov-kernel-monster content from local build
9425aed verified
Raw
History Blame Contribute Delete
2.34 kB
-- Shared Loop Invariant Predicates
-- Phase 2: Loop Invariant Formalization
-- Status: Observable bookkeeping conditions (counters, flags, divisibility)
module Core.Predicates where
open import Data.Nat using (β„•; _≀_; _<_; _≑_; _mod_; zero; suc)
open import Data.Real using (ℝ; _≀_; _<_; _β‰₯_; _+_; _*_; _-_)
open import Data.Bool using (Bool; true; false)
open import Relation.Binary.PropositionalEquality using (_≑_; refl)
open import Data.Vec using (Vec; _[_]; map)
-- Predicate: step counter has reached target
stepCounterAt : (k : β„•) (target : β„•) β†’ Set
stepCounterAt k target = k ≑ target
-- Predicate: step counter is within valid range
stepInRange : (k : β„•) (num_steps : β„•) β†’ Set
stepInRange k num_steps = k ≀ num_steps
-- Predicate: error status flag is success
errorIsClear : (err : β„•) β†’ Set -- 0 = BOB_SUCCESS
errorIsClear err = err ≑ 0
-- Predicate: time value is valid (positive)
timeIsPositive : (t : ℝ) β†’ Set
timeIsPositive t = 0 < t
-- Predicate: time step is positive
dtIsPositive : (dt : ℝ) β†’ Set
dtIsPositive dt = 0 < dt
-- Predicate: step count is exact multiple of normalization period
needsNormalization : (step : β„•) (period : β„•) β†’ Set
needsNormalization step period = (step mod period) ≑ 0
-- Predicate: step has NOT exceeded target
canContinueLoop : (step : β„•) (num_steps : β„•) β†’ Set
canContinueLoop step num_steps = step < num_steps
-- Predicate: qubit index is valid
qubitIndexValid : (idx : β„•) (num_qubits : β„•) β†’ Set
qubitIndexValid idx num_qubits = idx < num_qubits
-- Predicate: basis state iterator in valid range
basisStateInRange : (i : β„•) (dim : β„•) β†’ Set
basisStateInRange i dim = i < dim
-- Predicate: Taylor series term index
taylorTermIndex : (k : β„•) (max_terms : β„•) β†’ Set
taylorTermIndex k max_terms = k ≀ max_terms
-- Predicate: dimension is power of 2
isPowerOfTwo : (n : β„•) β†’ Set
data IsPowerOfTwo : β„• β†’ Set where
base : IsPowerOfTwo 1
step : βˆ€ {n} β†’ IsPowerOfTwo n β†’ IsPowerOfTwo (n * 2)
-- Predicate: vector dimensionality preserved
dimensionPreserved : (dim₁ dimβ‚‚ : β„•) β†’ Set
dimensionPreserved dim₁ dimβ‚‚ = dim₁ ≑ dimβ‚‚
-- Predicate: all elements processed in loop
loopCompleted : (current : β„•) (limit : β„•) β†’ Set
loopCompleted current limit = current ≑ limit