MCPcopy Create free account
hub / github.com/BasisResearch/lean.py / _build_vc_expr

Function _build_vc_expr

examples/06_effectful_verifier/python/refine.py:149–175  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

147
148
149def _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# ---------------------------------------------------------------------------

Callers 1

verify_functionFunction · 0.85

Calls 2

_make_expr_handlerFunction · 0.85
mk_forallMethod · 0.80

Tested by

no test coverage detected