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

Function _make_expr_handler

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

Build an effectful handler that maps Term ops → Lean.Expr builders. *depth* is the number of forallE binders above the expression scope. Variable ``var_names[i]`` maps to ``bvar(depth - 1 - i)``.

(eb: ExprBuilder, var_names, var_ops, depth)

Source from the content-addressed store, hash-verified

121
122
123def _make_expr_handler(eb: ExprBuilder, var_names, var_ops, depth):
124 """Build an effectful handler that maps Term ops → Lean.Expr builders.
125
126 *depth* is the number of forallE binders above the expression scope.
127 Variable ``var_names[i]`` maps to ``bvar(depth - 1 - i)``.
128 """
129 int_ops = defdata.dispatch(int)
130 h = {}
131
132 for i, name in enumerate(var_names):
133 bv = eb.mk_bvar(depth - 1 - i)
134 h[var_ops[name]] = (lambda bv=bv: lambda: bv)(bv)
135
136 def coerce(x):
137 return eb.mk_int(x) if isinstance(x, int) else x
138
139 h[int_ops.__add__] = lambda a, b: eb.mk_int_add(coerce(a), coerce(b))
140 h[int_ops.__sub__] = lambda a, b: eb.mk_int_sub(coerce(a), coerce(b))
141 h[int_ops.__mul__] = lambda a, b: eb.mk_int_mul(coerce(a), coerce(b))
142 h[int_ops.__gt__] = lambda a, b: eb.mk_int_gt(coerce(a), coerce(b))
143 h[int_ops.__ge__] = lambda a, b: eb.mk_int_ge(coerce(a), coerce(b))
144 h[int_ops.__lt__] = lambda a, b: eb.mk_int_lt(coerce(a), coerce(b))
145 h[int_ops.__le__] = lambda a, b: eb.mk_int_le(coerce(a), coerce(b))
146 return h
147
148
149def _build_vc_expr(eb: ExprBuilder, vc_term, var_names, var_ops, precond_terms):

Callers 1

_build_vc_exprFunction · 0.85

Calls 9

coerceFunction · 0.85
mk_bvarMethod · 0.80
mk_int_addMethod · 0.80
mk_int_subMethod · 0.80
mk_int_mulMethod · 0.80
mk_int_gtMethod · 0.80
mk_int_geMethod · 0.80
mk_int_ltMethod · 0.80
mk_int_leMethod · 0.80

Tested by

no test coverage detected