Skip to content

feat(Data/Tree/Basic): add Membership instance, new notation, rename Tree #39697

Open
sorrachai wants to merge 9 commits into
leanprover-community:masterfrom
sorrachai:BinaryTree
Open

feat(Data/Tree/Basic): add Membership instance, new notation, rename Tree #39697
sorrachai wants to merge 9 commits into
leanprover-community:masterfrom
sorrachai:BinaryTree

Conversation

@sorrachai

@sorrachai sorrachai commented May 22, 2026

Copy link
Copy Markdown
Collaborator

Summary:

  1. [Rename](#CSLib > Splay tree PR: BinaryTree vs Tree @ 💬) from Tree to BinaryTree, which propagates the changes to other files that use it.
  2. Add membership instance, prove decidability of membership.
  3. Add toListInOrder, toListPreOrder, toListPostOrder

Suggestion based on the discussion in the cslib thread#CSLib > Splay tree PR @ 💬.


@sorrachai
sorrachai requested a review from eric-wieser May 22, 2026 12:54
@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label May 22, 2026
@github-actions

Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions

github-actions Bot commented May 22, 2026

Copy link
Copy Markdown

PR summary 5e3ffb125c

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ Mem
+ all
+ all_iff
+ contains
+ contains_iff_mem
+ decidableBAll
+ instance : Membership α (BinaryTree α)
+ instance [BEq α] [LawfulBEq α] (a : α) (t : BinaryTree α) : Decidable (a ∈ t)
+ mem_singleton_iff
+ toListInOrder
+ toListPostOrder
+ toListPreOrder

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean -- pending)

Computed after the build finishes.


No changes to strong technical debt.

No changes to weak technical debt.

Current commit 5e3ffb125c
Reference commit eaa4d4093e

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@eric-wieser

Copy link
Copy Markdown
Member

Please could you split the renaming part of this PR into a standalone PR, as I originally requested on Zulip? You'll need to add a bunch of deprecations too, and it would be much easier to review if the PR only did the rename. You can leave this PR as is while waiting for the rename to be merged.

@sorrachai

Copy link
Copy Markdown
Collaborator Author

Sure, please refer to the new PR.

Comment on lines +13 to +22
# BinaryTree

Provides binary tree storage for values of any type, with O(lg n) retrieval.
See also `Lean.Data.RBTree` for red-black trees - this version allows more operations
Provides binary tree storage for values of any type.
See also `Lean.Data.RBBinaryTree` for red-black BinaryTrees - this version allows more operations
to be defined and is better suited for in-kernel computation.

We also specialize for `BinaryTree Unit`, which is a binary tree without any
We also specialize for `BinaryTree Unit`, which is a binary BinaryTree without any
additional data. We provide the notation `a △ b` for making a `BinaryTree Unit` with children
`a` and `b`.
`a` and `b`, and the notation `l △[a] r` for a binary tree with root node
containing value `a` and two children `l` and `r`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert the changes here.

Comment on lines +205 to +211
theorem mem_singleton_iff (a x : ℕ) : a ∈ ((nil △[x] nil)) ↔ a = x := by
constructor
· intro h
cases h <;> trivial
· intro h
subst h
apply Mem.node

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the not_mem_nil and mem_node_iff lemmas too, which can be simp.

Comment thread Mathlib/Data/Tree/Basic.lean Outdated
Comment thread Mathlib/Data/Tree/Basic.lean Outdated
@eric-wieser eric-wieser added the awaiting-author A reviewer has asked the author a question or requested changes. label Jun 8, 2026
@eric-wieser
eric-wieser temporarily deployed to cache-upload-forks June 8, 2026 19:58 — with GitHub Actions Inactive
sorrachai and others added 2 commits June 8, 2026 23:28
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author A reviewer has asked the author a question or requested changes. new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants