File size: 2,336 Bytes
9425aed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | -- 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
|