Dear friends,
I want to write an efficient algorithm for some task in hand. Currently, I am doing it using lists. The main operations I need to use are remove minimum/maximum and insert. For this, currently I am keeping a sorted list but the issue is this takes O(n) comparisons for insert. Hence, I am planning to use tree to make it work O(logn) on extracted programs.

One way I can see , this is possible is using binary search tree (or red-black tree).

Please suggest some Coq implementations and use cases for remove_min and insert trees.

Dear Lyxia,
Thanks for the references. Basically I am looking something in line with Andrew Appel’s implementation of red-black tree. https://www.cs.princeton.edu/~appel/papers/redblack.pdf. I couldn’t find this paper’s repository online.

Also, Can you help in this test on FmapAVL.

From Coq Require Import FMapAVL.
From Coq Require Import Init.Nat.
From Coq Require Import Lia.
Set Implicit Arguments.

Section try.

Search “tree”.
Check Coq.FMapAVL.height.

End.

The answer for Search command is nil and the second line is “The reference Coq.FMapAVL.height was not found in the current environment.” Do I need to download/update something. My coq version is 8.12.2.

The Software Foundations volume I linked earlier was also written by Andrew Appel and has a chapter about red black trees.

The way to use FMapAVL is that to instantiate it with a module implementing the OrderedType interface to use for the keys of the maps. There are examples of such modules in OrderedTypeEx, notably Nat_as_OT for nat. Once you have applied the Make module, the low-level functions like height can be found in the Raw submodule:

From Coq Require Import FMapAVL.
From Coq Require Import OrderedTypeEx.
Module NatFMap := FMapAVL.Make Nat_as_OT.
About NatFMap.Raw.height.

Thanks Lyxia,
This is very useful. Is there any document/manual or web-link on more on this. Some work implemented using AVL tree?
Thanks again,
Suneel

Dear Xavier,
Thanks a lot. I am implementing my existing programs involving sorted lists (delete max in O(1) but insert is in O(n) time) using trees so that both the insertion and delete_max can be performed in O(logn) time. Hence, looking for right resource with minimum proof obligation.
This is helpful.
Regards,
Suneel