~/bend-docscommunity

proof_run.bend source

proof_run.bend on the hub · documented module

import Baseimport ./defs.bend as Dimport ./halves.bend as Himport ./proof_force.bend as F# H.run: run_leaves (lp walks the tree once, handing out its leaves) and# run_shape.# t's leaves handed out (as xs), with leaves(t) == xs and leaves(run t) == force(xs).def LP(b, -B: Kind(b), -t: D.Tree<&1, D.Task<b, B>>) -> Type:  Sigma<&1, &1, List<&1, D.Task<b, B>>, xs => {D.leaves(&1, D.Task<b, B>, t) == xs : List<&1, D.Task<b, B>>}    & {D.leaves(b, B, H.run(b, B, t)) == D.force(b, B, xs) : List<b, B>}>def p1(b, -B: Kind(b), -l: D.Tree<&1, D.Task<b, B>>, -r: D.Tree<&1, D.Task<b, B>>,  -xl: List<&1, D.Task<b, B>>, -xr: List<&1, D.Task<b, B>>, -xl2: List<&1, D.Task<b, B>>,  el: {D.leaves(&1, D.Task<b, B>, l) == xl : List<&1, D.Task<b, B>>},  er: {D.leaves(&1, D.Task<b, B>, r) == xr : List<&1, D.Task<b, B>>},  g: {xl2 == xl : List<&1, D.Task<b, B>>})  -> {D.leaves(&1, D.Task<b, B>, D.Node{l, r}) == List.append(&1, D.Task<b, B>, xl2, xr) : List<&1, D.Task<b, B>>}:  %Equal.sym(List<&1, D.Task<b, B>>, xl2, xl, g) : {List.append(&1, D.Task<b, B>, D.leaves(&1, D.Task<b, B>, l), D.leaves(&1, D.Task<b, B>, r)) == List.append(&1, D.Task<b, B>, _, xr) : List<&1, D.Task<b, B>>}  %el : {List.append(&1, D.Task<b, B>, D.leaves(&1, D.Task<b, B>, l), D.leaves(&1, D.Task<b, B>, r)) == List.append(&1, D.Task<b, B>, _, xr) : List<&1, D.Task<b, B>>}  %er : {List.append(&1, D.Task<b, B>, D.leaves(&1, D.Task<b, B>, l), D.leaves(&1, D.Task<b, B>, r)) == List.append(&1, D.Task<b, B>, D.leaves(&1, D.Task<b, B>, l), _) : List<&1, D.Task<b, B>>}  {==}def p2(b, -B: Kind(b), -l: D.Tree<&1, D.Task<b, B>>, -r: D.Tree<&1, D.Task<b, B>>,  -xl: List<&1, D.Task<b, B>>, -xr: List<&1, D.Task<b, B>>, -xl2: List<&1, D.Task<b, B>>,  el: {D.leaves(b, B, H.run(b, B, l)) == D.force(b, B, xl) : List<b, B>},  er: {D.leaves(b, B, H.run(b, B, r)) == D.force(b, B, xr) : List<b, B>},  g: {xl2 == xl : List<&1, D.Task<b, B>>}, f: F.FAeq(b, B, xl, xr))  -> {D.leaves(b, B, H.run(b, B, D.Node{l, r})) == D.force(b, B, List.append(&1, D.Task<b, B>, xl2, xr)) : List<b, B>}:  %Equal.sym(List<&1, D.Task<b, B>>, xl2, xl, g) : {List.append(b, B, D.leaves(b, B, H.run(b, B, l)), D.leaves(b, B, H.run(b, B, r))) == D.force(b, B, List.append(&1, D.Task<b, B>, _, xr)) : List<b, B>}  %Equal.sym(List<b, B>, D.force(b, B, List.append(&1, D.Task<b, B>, xl, xr)), List.append(b, B, D.force(b, B, xl), D.force(b, B, xr)), f) : {List.append(b, B, D.leaves(b, B, H.run(b, B, l)), D.leaves(b, B, H.run(b, B, r))) == _ : List<b, B>}  %el : {List.append(b, B, D.leaves(b, B, H.run(b, B, l)), D.leaves(b, B, H.run(b, B, r))) == List.append(b, B, _, D.force(b, B, xr)) : List<b, B>}  %er : {List.append(b, B, D.leaves(b, B, H.run(b, B, l)), D.leaves(b, B, H.run(b, B, r))) == List.append(b, B, D.leaves(b, B, H.run(b, B, l)), _) : List<b, B>}  {==}def lp.node2(b, -B: Kind(b), -l: D.Tree<&1, D.Task<b, B>>, -r: D.Tree<&1, D.Task<b, B>>, -xl: List<&1, D.Task<b, B>>, xr: List<&1, D.Task<b, B>>,  el1: {D.leaves(&1, D.Task<b, B>, l) == xl : List<&1, D.Task<b, B>>},  el2: {D.leaves(b, B, H.run(b, B, l)) == D.force(b, B, xl) : List<b, B>},  er1: {D.leaves(&1, D.Task<b, B>, r) == xr : List<&1, D.Task<b, B>>},  er2: {D.leaves(b, B, H.run(b, B, r)) == D.force(b, B, xr) : List<b, B>},  s: F.FA(b, B, xl, xr)) -> LP(b, B, D.Node{l, r}):  (xl2, g) = s  (+g1, g2) = g  (List.append(&1, D.Task<b, B>, xl2, xr), (p1(b, B, l, r, xl, xr, xl2, el1, er1, g1), p2(b, B, l, r, xl, xr, xl2, el2, er2, g1, g2)))def lp.node(b, -B: Kind(b), -l: D.Tree<&1, D.Task<b, B>>, -r: D.Tree<&1, D.Task<b, B>>, s1: LP(b, B, l), s2: LP(b, B, r)) -> LP(b, B, D.Node{l, r}):  (xl, e) = s1  (el1, el2) = e  (xr, f) = s2  (er1, er2) = f  lp.node2(b, B, l, r, xl, xr, el1, el2, er1, er2, F.fa_p(b, B, xl, xr))def lp(b, -B: Kind(b), t: D.Tree<&1, D.Task<b, B>>) -> LP(b, B, t):  match t:    case D.Tip{}:      (Nil{}, ({==}, {==}))    case D.Leaf{k}:      (k <> Nil{}, ({==}, {==}))    case D.Node{l, r}:      lp.node(b, B, l, r, lp(b, B, l), lp(b, B, r))def lp.fin(b, -B: Kind(b), -t: D.Tree<&1, D.Task<b, B>>, s: LP(b, B, t))  -> {D.leaves(b, B, H.run(b, B, t)) == D.force(b, B, D.leaves(&1, D.Task<b, B>, t)) : List<b, B>}:  (xs, e) = s  (e1, e2) = e  %Equal.sym(List<&1, D.Task<b, B>>, D.leaves(&1, D.Task<b, B>, t), xs, e1) : {D.leaves(b, B, H.run(b, B, t)) == D.force(b, B, _) : List<b, B>}  e2def run_leaves(b, -B: Kind(b), t: D.Tree<&1, D.Task<b, B>>)  -> {D.leaves(b, B, H.run(b, B, t)) == D.force(b, B, D.leaves(&1, D.Task<b, B>, t)) : List<b, B>}:  lp.fin(b, B, t, lp(b, B, t))def run_shape(b, -B: Kind(b), t: D.Tree<&1, D.Task<b, B>>)  -> {D.shape(b, B, H.run(b, B, t)) == D.shape(&1, D.Task<b, B>, t) : D.Tree<&2, Unit>}:  match t:    case D.Tip{}:      {==}    case D.Leaf{k}:      {==}    case D.Node{l, r}:      %run_shape(b, B, l) : {D.Node{D.shape(b, B, H.run(b, B, l)), D.shape(b, B, H.run(b, B, r))} == D.Node{_, D.shape(&1, D.Task<b, B>, r)} : D.Tree<&2, Unit>}      %run_shape(b, B, r) : {D.Node{D.shape(b, B, H.run(b, B, l)), D.shape(b, B, H.run(b, B, r))} == D.Node{D.shape(b, B, H.run(b, B, l)), _} : D.Tree<&2, Unit>}      {==}