lean-ja / lean-by-example

コード例で学ぶ Lean 言語
https://lean-ja.github.io/lean-by-example/
MIT License
15 stars 5 forks source link

メモ:infer_var #394

Open Seasawher opened 4 days ago

Seasawher commented 4 days ago

SciLean に登場するすごく良いアイデアのひとつ

see: https://lecopivo.github.io/scientific-computing-lean/working-with-arrays/tensor-operations.html#pooling-and-difficulties-with-dependent-types

Seasawher commented 4 days ago

The most flexible way of writing the avgPool function is as follows:

def avgPool (x : Float^[n]) {m} (h : m = n/2 := by infer_var) : Float^[m] :=
  ⊞ (i : Fin m) =>
    let i1 : Fin n := ⟨2*i.1, by omega⟩
    let i2 : Fin n := ⟨2*i.1+1, by omega⟩
    0.5 * (x[i1] + x[i2])