Decidable equality of nonplanar rose trees #
Two rose trees represent the same nonplanar tree exactly when they are equal up to
reordering the children of every vertex (RoseTree.PermEquiv). This file shows that the
relation is decidable, and computably so: the decision procedure reduces in the kernel,
so concrete Nonplanar equalities close by decide.
Main definitions #
RoseTree.eqv: Boolean comparison of two ordered trees up to child reordering — equal root values, and child lists matching as multisets undereqv(greedy matching).
Main results #
RoseTree.eqv_iff_permEquiv:eqvdecidesPermEquiv.RoseTree.instDecidableRelPermEquiv: the resultingDecidableRel PermEquiv.RootedTree.Nonplanar.instDecidableEq: decidable equality on the quotient, viaQuotient.decidableEq.
Implementation notes #
eqv must recurse structurally for kernel reduction (decide needs brecOn, not
WellFounded.fix), so the greedy matcher is inlined as eqv.go rather than calling the
opaque List.isPermBy; go_eq_isPermBy reconnects them and imports the generic
correctness from Core/Data/Multiset/Rel.lean.
[UPSTREAM] candidate.
Deciding PermEquiv: equality up to child reordering #
eqv t s decides whether t and s are equal up to child reordering
(eqv_iff_permEquiv).
Equations
- (RoseTree.node a cs).eqv (RoseTree.node b ds) = (decide (a = b) && RoseTree.eqv.go cs ds)
Instances For
Greedy multiset matching of child lists: List.isPermBy eqv.
Equations
- RoseTree.eqv.go [] a✝ = a✝.isEmpty
- RoseTree.eqv.go (c :: cs) a✝ = match List.findIdx? c.eqv a✝ with | some i => RoseTree.eqv.go cs (a✝.eraseIdx i) | none => false
Instances For
Correctness of the greedy matcher #
eqv.go is List.isPermBy eqv, so the generic soundness and completeness of the
greedy matcher (Core/Data/Multiset/Rel.lean) reduce eqv_iff_permEquiv to one
size-bounded induction against mk-equality.
eqv decides PermEquiv: two ordered trees are eqv-related iff they are equal up
to reordering the children of every vertex. Composite of eqv_iff_mk_eq (at a
sum-of-sizes bound) with Nonplanar.mk_eq_mk_iff.
PermEquiv is decidable, computably so: decided by eqv, which reduces in the
kernel.
Equations
- x✝¹.instDecidableRelPermEquiv x✝ = decidable_of_iff (x✝¹.eqv x✝ = true) ⋯
Equality of nonplanar trees — equality up to child reordering — is decidable and
computable: Quotient.decidableEq over RoseTree.eqv on representatives, which
reduces in the kernel, so concrete Nonplanar equalities close by decide.