Coder Social home page Coder Social logo

coq-tries's Introduction

Generic Tries in Coq

This library implements generic tries in Coq, capable of mapping a list of any type to values in another (or the same) type with fast lookup times (linear on the length of the key list) at the expense of greater memory consumption and slower insertion times.

Usage

Let's start by defining an empty tree that will map a list of ASCII characters (i.e. a string) to a natural number:

Definition empty := empty_trie ascii nat.

We can now insert pairs of strings and natural numbers into the trie:

Definition hello := trie_insert ascii_dec empty ["h"; "e"; "l"; "l"; "o"] 1.
Definition happy := trie_insert ascii_dec hello ["h"; "a"; "p"; "p"; "y"] 2.
Definition world := trie_insert ascii_dec happy ["w"; "o"; "r"; "l"; "d"] 3.

Upon calling Compute world. we get the following:

= Root None
  [Node None "w" [Node None "o" [Node None "r" [Node None "l" [Node (Some 3) "d" []]]]];
   Node None "h"
     [Node None "a" [Node None "p" [Node None "p" [Node (Some 2) "y" []]]];
      Node None "e" [Node None "l" [Node None "l" [Node (Some 1) "o" []]]]]]
 : Trie ascii nat

To retrieve a value, we can do so thusly:

Compute trie_get ascii_dec world ["h"; "a"; "p"; "p"; "y"].

This gives the result:

= Some 2
  : option nat

Limitations

This data structure does not have any accompanying proofs. This may be addresed in the future.

coq-tries's People

Contributors

lambdacasserole avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.