[balanced_bst] AVL_treeTheory and fibonacciTheory (+fibmod3) #1397
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.
Hi,
This PR contains a slightly modified version of the AVL tree formalisation, by our student (Sineeha Kodwani) in the last year.
AVL tree is another balanced bst (binary search tree), perhaps nowadays is less famous than red-black trees. A valid AVL tree is a (finite) binary tree structure (defined by a datatype with constructors
Tip
andBin
) whose children heights differ by at most one:It's not obvious from this definition that the height of AVL trees is logarithm to the number of nodes in it (for optimal searching performance), but if we define a function
N(k)
as the minimal number of nodes of all AVL trees whose height isk
:Then we can prove the following recursive relation between different
N(k)
values and a elegant connection to the Fibonacci numbers:It's known (but the proof is not mechanised here) that the Fibonacci numbers has the exponential upper/lower bounds [1,2], and thus the height of AVL trees is indeed logarithm to the number of nodes.
The work also correctly defines insert and delete operations to AVL tree, and have some test theorems showing the correctness on concrete AVL trees, but the correctness of these operations is not fully formalised. (The overall code quality is medium but the finished parts are all correct.)
I extracted from the original work all proofs about the Fibonacci number itself and created a dedicated
fibonacciTheory
, also underexampels/balanced_bst
. It's not putting intoarithmeticTheory
ornumberTheory
because I also merged the existing smallfibmod3Theory
fromexamples/misc
but the proof depends onintLib
. I plan to formalise the exponential upper/lower bounds, but then real numbers will also involve. Therefore it's better (for now) just have a dedicatedfibonacciTheory
in examples.--Chun
[1] https://proofwiki.org/wiki/Fibonacci_Number_greater_than_Golden_Section_to_Power_less_Two
[2] https://proofwiki.org/wiki/Fibonacci_Number_less_than_Golden_Section_to_Power_less_One