proofs/math_gelu_lanes_certificate.bend source
proofs/math_gelu_lanes_certificate.bend on the hub · documented module
# Shape preservation reuses the traversal's gather/scatter witnesses.import Baseimport ../tensor_access.bend as Accessimport ../math_activation.bend as Actimport ../math_gelu_lanes.bend as Geluimport ../kernel_tile.bend as Tileimport ../traversal_lanes.bend as Lanesimport ../traversal_cells.bend as Cellsimport ./traversal_lanes_witness.bend as LaneWitnessimport ./storage_witness.bend as Witnessimport ./storage_tree_model.bend as Treeimport ./storage_certificate.bend as Certificateimport ./traversal_witness.bend as TraversalWitnessdef gathered(-values: Array<F32>,+position: U32,+context: Unit, evidence: LaneWitness.Gathered<values,Lanes.gather(~Unit,~Gelu.identity,values,position,context)>) -> LaneWitness.Gathered<values,Gelu.gather(values,position,context)>: LaneWitness.Gathered{cell,equation} = evidence LaneWitness.Gathered{Gelu.second(Gelu.first(cell)), Equal.cong(Array<F32> & Tile.Tile8,Array<F32> & Tile.Tile8,Gelu.gathered, Lanes.gather(~Unit,~Gelu.identity,values,position,context),(values,cell),equation)}def gather(+depth: Nat,-values: Array<F32>,+position: U32,+context: Unit,+witness: Witness.Witness(F32,depth,values)) -> LaneWitness.Gathered<values,Gelu.gather(values,position,context)>: gathered(values,position,context,LaneWitness.gather(~Unit,~Gelu.identity,depth,values,position,context,witness))def mapped(+depth: Nat,count: Nat,+position: U32,-values: Array<F32>,witness: Witness.Witness(F32,depth,values)) -> Witness.Witness(F32,depth,Gelu.map(count,position,values)): LaneWitness.rounds_with(~Unit,~Access.apply_element(~F32,~Act.gelu_tanh_value),~Gelu.gather,~gather,depth,count,Cells.State{values,Lanes.scratch(),position,0,Unit{}}, LaneWitness.Evidence{values,Lanes.scratch(),position,0,Unit{},{==},witness,Witness.fresh(Tile.Tile8,6n,Tile.filled(0.0))})def shape(covered: Bool,+depth: Nat,count: Nat,+position: U32,-values: Array<F32>,witness: Witness.Witness(F32,depth,values)) -> Witness.Witness(F32,depth,Gelu.map_when(covered,count,position,values)): match covered: case True{}: mapped(depth,count,position,values,witness) case False{}: TraversalWitness.map_in_place(~F32,~Unit,~Access.apply_element(~F32,~Act.gelu_tanh_value),depth,count,position,Unit{},values,witness)def map_when(+covered: Bool,+count: Nat,+position: U32,-values: Array<F32>,certificate: Certificate.Certificate<F32,values>) -> Certificate.Certificate<F32,Gelu.map_when(covered,count,position,values)>: Certificate.Certificate{+depth,equation} = certificate Certificate.Certificate{depth, %Certificate.restored(F32,depth,Gelu.map_when(covered,count,position,values),shape(covered,depth,count,position,values,Certificate.witness_at(F32,depth,values,equation))) : {_ == Tree.pack(F32,Certificate.normalized(F32,depth,Tree.reflect(F32,Gelu.map_when(covered,count,position,values)))) : Array<F32>} {==}}