SilverSight/formal/SilverSight/ProductSchema.lean
allaun 4f7c554981 feat(core): add Phase 1 SilverSight core modules
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.
2026-06-22 21:48:15 -05:00

48 lines
3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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