Convert an effectful VC Term to a ``Lean.Expr`` proposition. Builds ``∀ (x : Int) ..., preconds → body`` with correct de Bruijn indices at each binder depth.
(eb: ExprBuilder, vc_term, var_names, var_ops, precond_terms)
| 147 | |
| 148 | |
| 149 | def _build_vc_expr(eb: ExprBuilder, vc_term, var_names, var_ops, precond_terms): |
| 150 | """Convert an effectful VC Term to a ``Lean.Expr`` proposition. |
| 151 | |
| 152 | Builds ``∀ (x : Int) ..., preconds → body`` with correct de Bruijn |
| 153 | indices at each binder depth. |
| 154 | """ |
| 155 | n_vars = len(var_names) |
| 156 | n_preconds = len(precond_terms) |
| 157 | total = n_vars + n_preconds |
| 158 | |
| 159 | # Evaluate the body at the innermost depth (all binders above). |
| 160 | with handler(_make_expr_handler(eb, var_names, var_ops, total)): |
| 161 | body_expr = evaluate(vc_term) |
| 162 | |
| 163 | # Wrap preconditions from innermost outward. |
| 164 | result = body_expr |
| 165 | for j in reversed(range(n_preconds)): |
| 166 | depth = n_vars + j |
| 167 | with handler(_make_expr_handler(eb, var_names, var_ops, depth)): |
| 168 | prec_expr = evaluate(precond_terms[j]) |
| 169 | result = eb.mk_forall("_", prec_expr, result) |
| 170 | |
| 171 | # Wrap ∀ variable binders. |
| 172 | for i in reversed(range(n_vars)): |
| 173 | result = eb.mk_forall(var_names[i], eb.INT, result) |
| 174 | |
| 175 | return result |
| 176 | |
| 177 | |
| 178 | # --------------------------------------------------------------------------- |
no test coverage detected