Repository navigation
Conversation
The functions are a transcription of level.cpp of the official kernel v4.35.0. They keep the order of the cases and the simplifications of mk_max and mk_imax, because the shape of a level can change the result of is_geq.
tamnd
added a commit
that referenced
this pull request
Nov 21, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refers to #3.
This PR adds
crates/rulean-core/src/level.rs. It is the first part of engine R. The functions are a transcription oflevel.cppof the official kernel v4.35.0 (spec 05.6).mk_maxandmk_imaxkeep the simplifications of the official code.normalizeflattensmax, sorts byis_norm_lt, keeps the largest offset for each base and drops a covered explicit level. The result is cached in aLevelCachewith one slot for each level handle.is_equivalentcompares normal forms. It is incomplete by design, as in the official kernel.is_geqis the structural algorithm on normal forms.instantiatemakes a changedmaxorimaxnode again withmk_maxormk_imax, as the officialupdate_maxdoes.name_cmpis the name order of the kernel. A number component is less than a string component.The code is in the Aeneas subset. The sort is an insertion sort, because the
sortmethods are outside the modelled functions. Equal levels have equal handles, so the result does not depend on the sort algorithm.Tests:
crates/rulean-core/tests/level.rshas 9 tests for the simplifications, the normal form, equivalence,is_geq, the zero tests, instantiation and the name order.