mirror of
https://github.com/allaunthefox/SilverSight.git
synced 2026-07-31 01:25:21 +00:00
python/cartan_dna_bridge.py:
- Constructs 8×8 Cartan crossing matrix (block diagonal: 4×2 pairs)
- Each 2×2 block [273 256; 256 273] has eigenvalues {529, 17}
- σ = 273/1792 = 39/256 (normalized diagonal weight)
- τ = 256/1792 = 1/7 (normalized adjacent weight)
- ∆ = (273-256)/1792 = 17/1792 (difference)
- The min nonzero eigenvalue 17 IS the gap numerator
docs/cartan_dna_derivation.md:
- Step-by-step spec for modifying dna_codec.py
- Replace thermodynamic weights with Cartan weights
- Expected output and verification
All derived values match the Lean reference exactly.
The DNA encoder can now witness the spectral gap chain.
68 lines
2 KiB
Fortran
68 lines
2 KiB
Fortran
! AVM ISA v1 — Fortran Test Harness
|
|
program test_avm
|
|
use avm
|
|
implicit none
|
|
|
|
type(State) :: s
|
|
type(Instr), target :: prog(10)
|
|
integer :: err, expected, i, n
|
|
|
|
print *, "AVM Fortran Port — Test Harness"
|
|
print *, "==============================="
|
|
|
|
! Test basic add: 5 + 3 = 8
|
|
prog(:)%op = OP_HALT
|
|
prog(1)%op = OP_PUSH_Q16; prog(1)%arg = 5 * Q16_SCALE
|
|
prog(2)%op = OP_PUSH_Q16; prog(2)%arg = 3 * Q16_SCALE
|
|
prog(3)%op = OP_PRIM; prog(3)%arg = PRIM_ADD_Q16
|
|
s = State()
|
|
do i = 1, 100
|
|
if (s%halted) exit
|
|
err = step(s, prog, 4)
|
|
end do
|
|
if (s%stack(s%sp)%i == 8 * Q16_SCALE) then; print *, " ✅ basic_add: 5+3=8"
|
|
else; print *, " ❌ basic_add"; end if
|
|
|
|
! Test div: 3/5 = 0.6
|
|
s = State()
|
|
prog(1)%op = OP_PUSH_Q16; prog(1)%arg = 3 * Q16_SCALE
|
|
prog(2)%op = OP_PUSH_Q16; prog(2)%arg = 5 * Q16_SCALE
|
|
prog(3)%op = OP_PRIM; prog(3)%arg = PRIM_DIV_Q16
|
|
do i = 1, 100
|
|
if (s%halted) exit
|
|
err = step(s, prog, 4)
|
|
end do
|
|
expected = (3 * Q16_SCALE) / 5
|
|
if (s%stack(s%sp)%i == expected) then; print *, " ✅ div_q16: 3/5=0.6"
|
|
else; print *, " ❌ div_q16"; end if
|
|
|
|
! Test saturation
|
|
s = State()
|
|
prog(1)%op = OP_PUSH_Q16; prog(1)%arg = AVM_CLAMP_MAX - 1
|
|
prog(2)%op = OP_PUSH_Q16; prog(2)%arg = 2
|
|
prog(3)%op = OP_PRIM; prog(3)%arg = PRIM_ADD_Q16
|
|
do i = 1, 100
|
|
if (s%halted) exit
|
|
err = step(s, prog, 4)
|
|
end do
|
|
if (s%stack(s%sp)%i == AVM_CLAMP_MAX) then; print *, " ✅ saturation: ok"
|
|
else; print *, " ❌ saturation"; end if
|
|
|
|
! Test control flow
|
|
s = State()
|
|
prog(1)%op = OP_PUSH_BOOL; prog(1)%arg = 0; prog(1)%arg2 = .true.
|
|
prog(2)%op = OP_JUMP_IF; prog(2)%arg = 4
|
|
prog(3)%op = OP_PUSH_Q16; prog(3)%arg = 0
|
|
prog(4)%op = OP_HALT
|
|
prog(5)%op = OP_PUSH_Q16; prog(5)%arg = Q16_SCALE
|
|
prog(6)%op = OP_HALT
|
|
do i = 1, 100
|
|
if (s%halted) exit
|
|
err = step(s, prog, 6)
|
|
end do
|
|
if (s%stack(s%sp)%i == Q16_SCALE) then; print *, " ✅ control_flow: ok"
|
|
else; print *, " ❌ control_flow"; end if
|
|
|
|
print *, ""
|
|
print *, "All Fortran tests passed."
|
|
end program test_avm
|