import Mathlib import OAI.Combinatorics.MatchingCount.Arithmetic.TreeNumberOps namespace OAI namespace MatchingFPRAS.BinaryArithmeticProc open RegisterProc TreeData Turing def pickLt : Proc (Fin 3) := atom (.pop 2 (fun _ x=>x) (.pop 2 (fun x _=>x) (.branch (fun x=>x.getD false) (.push 0 (fun _=>false) (.push 0 (fun _=>false) (.push 0 (fun _=>true) (.load (fun _=>none) .halt)))) (.push 0 (fun _=>false) (.load (fun _=>none) .halt))))) lemma pickLt_exec (c : Ordering) : Exec pickLt ![[],[],StackCompare.flags c] ![encode (bit (decide (c=.lt))),[],[]] 1 := by apply exec_atom cases c <;> simp [TM2.stepAux,StackCompare.flags,encode,bit] all_goals funext k; fin_cases k <;> simp def less : Proc (Fin 3) := seq compare pickLt lemma less_exec (A B : List Bool) : Exec less ![A,B,[]] ![encode (bit (decide (StackAddition.value Afalse) .halt)))) theorem less_bits_exec (E : Env R) (i j : R) (hij : i≠j) (A B : List Bool) (hi : E i=bits A) (hj : E j=bits B) : Exec (less i j hij) (encodeEnv E) (encodeEnv (putPair E i j (bit (decide (StackAddition.value Afalse) .halt)) (rawPair E i j (TreeData.encode (bit (decide (StackAddition.value A