roseking's picture
Add lean source and binary files (part 44)
e320e82 verified
Raw History Blame Contribute Delete
1.81 kB
9
def dropInput (offset : Expr) : Expr → Expr
body · 9 lines
  | .const n => .const n
  | .arg i => .arg i
  | .length => .sub .length (UnaryTables.closed offset)
  | .bit x => .bit (.add (UnaryTables.closed offset) (dropInput offset x))
  | .add x y => .add (dropInput offset x) (dropInput offset y)
  | .sub x y => .sub (dropInput offset x) (dropInput offset y)
  | .mul x y => .mul (dropInput offset x) (dropInput offset y)
  | .zero x => .zero (dropInput offset x)
  | .sum b f => .sum (dropInput offset b) (dropInput offset f)
20
lemma dropInput_eval (offset e : Expr) (s : List Bool) (a : ℕ → ℕ) :
    (dropInput offset e).eval s a=e.eval (s.drop (offset.eval s (fun _ => 0))) a := by
proof · 12 lines
  have hc (a : ℕ → ℕ) : (UnaryTables.closed offset).eval s a=offset.eval s (fun _ => 0) := by
    simp [UnaryTables.closed,UnaryTables.atIndex,eval]
  induction e generalizing a with
  | const n => rfl
  | arg n => rfl
  | length => simp [dropInput,eval,hc]
  | bit e ih => simp [dropInput,eval,hc,ih,List.getElem?_drop]
  | add x y ix iy => simp [dropInput,eval,ix,iy]
  | sub x y ix iy => simp [dropInput,eval,ix,iy]
  | mul x y ix iy => simp [dropInput,eval,ix,iy]
  | zero x ix => simp [dropInput,eval,ix]
  | sum b f ib iF => simp only [dropInput,eval,ib,iF]
38
lemma words_add (f : ℕ → ℕ) (a b : ℕ) :
    words f (a+b)=words f a ++ words (fun w => f (a+w)) b := by
proof · 3 lines
  induction b with
  | zero => simp [words]
  | succ b ih => rw [Nat.add_succ,words_succ,ih,words_succ,List.append_assoc]