Skip to content

Add the expression operations of rulean-core - #28

Merged
tamnd merged 1 commit into
mainfrom
m2/expr
Nov 21, 2026
Merged

tamnd merged 1 commit into
mainfrom
m2/expr

Conversation

@tamnd

@tamnd tamnd commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Refers to #3.

This PR comes after #27. It adds crates/rulean-core/src/expr.rs and crates/rulean-core/src/memo.rs.

The expression operations are a transcription of instantiate.cpp, abstract.cpp, the loose bound variable part of expr.cpp and expr_eq_fn.cpp of the official kernel v4.35.0:

  • instantiate, instantiate_from, instantiate1 and instantiate_rev. A substituted value is lifted under the binders, as in the official code.
  • lift_loose_bvars, lower_loose_bvars, has_loose_bvar and abstract_fvars.
  • instantiate_lparams. A changed level is made again with the simplifications of level::instantiate.
  • app_fn, app_args, app_num_args and mk_rev_app.
  • apply_beta, head_beta and cheap_beta_reduce.
  • expr_equal, the == of the official kernel. It ignores binder names and binder info, and it uses the pair cache of expr_eq_fn.

The official functions use replace with a cache for shared nodes. Here each operation has its own recursion and a Memo keyed by the node and the binder offset. Memo is a small map on the verified Table with epochs, so a clear is O(1). A free variable is an atom, so the operations do not go into its type.

Store change. The hash of a lam, pi or let node no longer mixes the binder name or the binder info. This is the method of Lean. Alpha-equivalent terms now have equal hashes, so expr_equal can reject on a hash mismatch. The interning table still compares the full node, so handles stay exact.

Tests: crates/rulean-core/tests/expr.rs has 9 tests. The store tests pass without a change.

@tamnd tamnd added this to the M2 Engine R milestone Nov 21, 2026
@tamnd tamnd added area/store Handles, the term store, names and levels area/core The type checker: engines F and R, declarations, profiles type/feature New function labels Nov 21, 2026
Base automatically changed from m2/levels to main November 21, 2026 16:33
@tamnd tamnd mentioned this pull request Nov 21, 2026
1 of 20 tasks
@tamnd
tamnd merged commit 1c3d361 into main Nov 21, 2026
17 checks passed
@tamnd
tamnd deleted the m2/expr branch November 21, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core The type checker: engines F and R, declarations, profiles area/store Handles, the term store, names and levels type/feature New function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant