mirror of
https://github.com/allaunthefox/SilverSight.git
synced 2026-08-12 13:20:34 +00:00
New modules in formal/SilverSight/: - Schema.lean: Schema class with 6 type instances - WireFormat.lean: WireFormat structure + Layout enum - ProductSchema.lean: Schema (α × β) instance - ProductWireFormat.lean: Row-major pair encoders - Receipt.lean: Receipt structure + GateType enum - Bind.lean: bindReceipt composition primitive Build: 3307 jobs, 0 errors (from Research Stack lake build SilverSight) All modules use Semantics.FixedPoint cross-project import.
48 lines
3 KiB
Text
48 lines
3 KiB
Text
import SilverSight.Schema
|
||
|
||
namespace SilverSight
|
||
|
||
open Semantics.FixedPoint
|
||
|
||
-- ═══════════════════════════════════════════════════════════════════════════
|
||
-- §1 Product Schema instance
|
||
-- ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
/-- Schema instance for fixed-size product types (α × β).
|
||
byteSize is the sum of component sizes.
|
||
wellFormed requires both components to be well-formed. -/
|
||
instance [Schema α] [Schema β] : Schema (α × β) where
|
||
byteSize := Schema.byteSize α + Schema.byteSize β
|
||
wellFormed := fun (a, b) => Schema.wellFormed a && Schema.wellFormed b
|
||
|
||
@[simp] theorem prod_byteSize [Schema α] [Schema β] :
|
||
Schema.byteSize (α × β) = Schema.byteSize α + Schema.byteSize β := rfl
|
||
|
||
theorem prod_wellFormed [Schema α] [Schema β] (a : α) (b : β) :
|
||
Schema.wellFormed (a, b) = (Schema.wellFormed a && Schema.wellFormed b) := rfl
|
||
|
||
-- ═══════════════════════════════════════════════════════════════════════════
|
||
-- §2 Nested product schemas
|
||
-- ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
@[simp] theorem prod3_byteSize [Schema α] [Schema β] [Schema γ] :
|
||
Schema.byteSize ((α × β) × γ) = Schema.byteSize α + Schema.byteSize β + Schema.byteSize γ := by
|
||
simp [prod_byteSize, Nat.add_assoc]
|
||
|
||
@[simp] theorem prod3_byteSize' [Schema α] [Schema β] [Schema γ] :
|
||
Schema.byteSize (α × β × γ) = Schema.byteSize α + Schema.byteSize β + Schema.byteSize γ := by
|
||
simp [prod_byteSize, Nat.add_assoc]
|
||
|
||
-- ═══════════════════════════════════════════════════════════════════════════
|
||
-- §3 #eval witnesses
|
||
-- ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
#eval Schema.byteSize (UInt8 × UInt8) -- expected: 2
|
||
#eval Schema.byteSize (UInt8 × Bool) -- expected: 2
|
||
#eval Schema.byteSize (UInt32 × UInt32) -- expected: 8
|
||
#eval Schema.byteSize (Q16_16 × Q16_16) -- expected: 8
|
||
#eval Schema.byteSize (UInt8 × UInt32) -- expected: 5
|
||
#eval Schema.byteSize ((UInt8 × UInt8) × UInt32) -- expected: 6
|
||
#eval Schema.byteSize (UInt8 × UInt8 × UInt32) -- expected: 6
|
||
|
||
end SilverSight
|