lecopivo / SciLean

Scientific computing in Lean 4
https://lecopivo.github.io/scientific-computing-lean/
Apache License 2.0
327 stars 29 forks source link

lsimp projection sees through let bindings #20

Open lecopivo opened 1 year ago

lecopivo commented 1 year ago

In some cases projections can destroy let bindings in lsimp

#check 
   (fun i : Nat =>
      let j := 42
      let foo := ((i * j, i+j), (i ^ j, i / j))
      foo.fst.snd)
   rewrite_by
     lsimp (config := {zeta:=false}) only

returns

(fun i : Nat =>
      let j := 42
      i + j)

which is undesirable. We want to split foo intor four let bindings

   (fun i : Nat =>
      let j := 42
      let foo := ((i * j, i+j), (i ^ j, i / j))
      foo.fst.snd)
==>
   (fun i : Nat =>
      let j := 42
      let foo_fst_fst := (i * j)
      let foo_fst_snd:= (i+j)
      let foo_snd_fst := (i ^ j)
      let foo_snd_snd := (i / j)
      ((foo_fst_fst, foo_fst_snd),(foo_snd_fst,foo_snd_snd)).fst.snd)
==>
   (fun i : Nat =>
      let j := 42
      let foo_fst_snd:= (i+j)
      foo_fst_snd)

Such transformation is currently part of let_normalize but should be an integral part of lsimp

lecopivo commented 7 months ago

This is problem again but with how Tactic.lift_lets_simproc works now.

lecopivo commented 1 month ago

I think it works as expected now when using lsimp