-- nox/T3.ei โ parallel commutativity of witness traces
-- Source: nox/proofs/lean/T3_parallel_commutativity.lean
-- T3.1 (sort permutation invariant), T3.2 (multiset equiv), T3 main
import "Model.ei"
-- โโ PathStep: structural trace position โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
inductive PathStep : Type 0 where
| left : PathStep
| right : PathStep
| test : PathStep
| yes : PathStep
| no : PathStep
| sub : PathStep
| continuation : PathStep
| tag : PathStep
| check : PathStep
-- โโ StructuralIndex (abstract) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
axiom StructuralIndex : Type 0
-- โโ Perm: permutation relation over abstract traces (Nat) โโโโโโโโโโโโโโโโโโโโ
axiom Perm : Nat -> Nat -> Type 0
-- nil case: empty traces (both 0) are trivially permutations
axiom Perm.nil : Perm 0 0
-- โโ sortByPath: canonical sort of a trace โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
axiom sortByPath : Nat -> Nat
-- โโ keyInjective: injectivity predicate for a trace โโโโโโโโโโโโโโโโโโโโโโโโโโ
axiom keyInjective : Nat -> Type 0
-- โโ T3.1 โ sort is permutation-invariant โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
-- Requires mergeSort Perm case analysis โ stays as axiom.
axiom sort_permutation_invariant (t1 : Nat) (t2 : Nat)
(h : Perm t1 t2)
(uniq : keyInjective t1) :
Eq Nat (sortByPath t1) (sortByPath t2)
-- keyInjective holds for the empty (0) trace
axiom keyInjective_nil : keyInjective 0
-- โโ T3.2 โ multiset equivalence โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
-- Both stubs reduce to 0 via empty-trace axioms; Perm.nil closes.
theorem threaded_trace_is_permutation (o : Noun) (t : Noun) (f : Nat) :
Perm (trace_seq o t f) (trace_par o t f) := by {
rewrite [trace_seq_empty o t f]
rewrite [trace_par_empty o t f]
exact Perm.nil
}
-- โโ keyInjective holds for stub traces โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
theorem trace_seq_key_injective (o : Noun) (t : Noun) (f : Nat) :
keyInjective (trace_seq o t f) := by {
rewrite [trace_seq_empty o t f]
exact keyInjective_nil
}
-- โโ T3 main โ canonical-sorted trace equivalence โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
theorem canonical_trace_equivalence (o : Noun) (t : Noun) (f : Nat)
(uniq : keyInjective (trace_seq o t f)) :
Eq Nat (sortByPath (trace_seq o t f)) (sortByPath (trace_par o t f)) := by {
rewrite [trace_seq_empty o t f]
rewrite [trace_par_empty o t f]
rfl
}