SemanticEquivalenceCommon #
Shared helper lemmas for the semantic equivalence proof in NN.Runtime.Autograd.Compiled.IRExec.Correctness.
This module contains correctness infrastructure used by the end-to-end semantic equivalence proof. We keep
these lemmas separate from ...Correctness.Common because they are specific to the recursive
buildFrom proof shape rather than generally useful per-op infrastructure.
Reading map:
denoteAllState_nil: base case table lemma for the empty compiled prefix.permuteDVal_eq_applySwapsTensor(+ helper): connects IR permutation semantics to the runtime swap-based implementation.buildFrom_denoteAllFrom_{unary,binary}_exact: convenience wrappers that package the standard semantic equivalence proof pattern once anodeDataclosure has been constructed.
These helpers exist because the main correctness proof is expensive to elaborate. They keep the
recursive theorem from re-solving the same typed-context and dynamic-value facts for every operator.
When a new proof starts to repeat parent lookup, DVal casting, or tail-of-graph preservation
steps, it usually belongs here.
Maintenance note: add focused, well-named lemmas here instead of adding another large tactic block to the recursive proof.
Correctness (Semantic Equivalence Helpers) #
These lemmas are shared by the branch-by-branch proof in Correctness.SemanticEquivalence.
Base case: evaluating the empty compiled prefix yields the singleton table containing just the input.
Relate the IR permutation lowering (applySwapDepth folded over swap depths) to applySwapsTensor.
This is used to connect NN.IR.Graph.permuteDVal to the runtime implementation used by the
compiler-generated node.
Specialize NN.IR.Graph.permuteDVal to the swap-based implementation used by this compiler.
Given a successful permute? witness and computed swap depths, permuteDVal returns the tensor
produced by applySwapsTensor with the expected final shape.
Semantic Equivalence lemma for a unary op compilation step (already-compiled nodeData).
This packages the common pattern for unary operators: compile the node, compute its forward value, push it onto the value table, and appeal to the inductive hypothesis for the tail.
Semantic Equivalence lemma for a binary op compilation step (already-compiled nodeData).
This is the two-parent analogue of buildFrom_denoteAllFrom_unary_exact.
If a dynamic value v is definitionally a dependent pair ⟨s, t⟩, then extracting its second
component requires a transport across the (propositional) shape equality.
This lemma packages the standard Sigma-transport pattern used throughout the semantic equivalence
proof: when v = DVal.mk s t, transporting v.snd across the induced shape equality yields t.
Transport the tensor component of a dynamic value across the induced shape equality.
We spell this as a separate theorem (rather than using by simpa ... inside the statement) so
that the module system does not need to elaborate a tactic block in a public header.
Boolean Shape Equality Helpers #
The IR evaluator uses boolean equality/inequality checks on Shape (via BEq Shape) in a few
places. For example, evalAt's .conv2d case checks a computed output shape against the node's
declared outShape using != (rather than a propositional ≠) because it is part of the
runtime error-reporting path.
In the proof layer we frequently have a propositional equality s = t and need to discharge such
boolean guards. Since BEq Shape is defined as an explicit structural test (Shape.areEqual) and
we do not globally assume LawfulBEq Shape, we prove the small bridge lemmas locally here.
Reflexivity of the explicit structural boolean equality test Shape.areEqual.
Reflexivity of BEq Shape (==).
Reflexivity of boolean inequality (!=) on shapes.
Propositional shape equality implies the boolean inequality guard s != t is false.