[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"zEr6JjNeML":3},"\n\n# Functional Algorithms Design \u003Ca href='#'>\u003Cimg src=\"img/cover.jpeg\" align=\"right\" height=\"168\" />\u003C/a>\n\n[![Build and Deploy Documentation](https://github.com/arademaker/fad/actions/workflows/docs.yaml/badge.svg)](https://github.com/arademaker/fad/actions/workflows/docs.yml)\n[![Lean Version](https://img.shields.io/badge/Lean-4.20.0-blue)](https://lean-lang.org/)\n[![Mathlib](https://img.shields.io/badge/Mathlib-✓-green)](https://github.com/leanprover-community/mathlib4)\n\n> *\"Algorithm design meets formal verification\"*\n\n## Introduction\n\nThis [Lean](https://lean-lang.org/) adaptation of [Algorithm Design with Haskell](https://www.cs.ox.ac.uk/publications/books/adwh/) reinterprets five essential principles of algorithm design—divide and conquer, greedy algorithms, thinning, dynamic programming, and exhaustive search—within a dependently typed setting. All examples are reimplemented in Lean, a functional language and proof assistant based on dependent type theory. More than a translation, this version makes explicit the informal equational reasoning of the original by turning it into fully formal, machine-checked proofs.\n\nThe main goals of this adaptation are:\n\n- to demonstrate the expressive power of dependent types in representing and reasoning about algorithms,\n- to show how informal proofs can be systematically formalized,\n- to explore how different refinements of the same algorithm can be proven equivalent.\n- and to explore how to prove termination of functional algorithms.\n\nAlong the way, readers gain experience not only in algorithm design, but also in writing correct-by-construction programs and proving their properties rigorously. This book invites students and practitioners to see algorithmics not just as a matter of clever ideas, but also as a foundation for precise, verifiable software.\n\n## Table of Contents\n\n### Part One: Basics\n\n1.  Functional programming\n\n    - [x] 1.1 Basic types and functions\n    - [x] 1.2 Processing lists\n    - [x] 1.3 Inductive and recursive definitions\n    - [x] 1.4 Fusion\n    - [x] 1.5 Accumulating and tupling\n    - [x] Exercises\n\n2.  Timing\n\n    - [ ] 2.1 Asymptotic notation\n    - [ ] 2.2 Estimating running times\n    - [ ] 2.3 Running times in context\n    - [ ] 2.4 Amortised running times\n    - [ ] Exercises\n\n3.  Useful data structures\n\n    - [x] 3.1 Symmetric lists\n    - [x] 3.2 Random-access lists\n    - [x] 3.3 Arrays\n    - [ ] Exercises\n\n### Part Two: Divide And Conquer\n\n1.  Binary search\n\n    - [x] 4.1 A one‑dimensional search problem\n    - [x] 4.2 A two‑dimensional search problem\n    - [x] 4.3 Binary search trees\n    - [x] 4.4 Dynamic sets\n    - [ ] Exercises\n\n2.  Sorting\n\n    - [x] 5.1 Quicksort\n    - [x] 5.2 Mergesort\n    - [x] 5.3 Heapsort\n    - [x] 5.4 Bucketsort and Radixsort\n    - [x] 5.5 Sorting sums\n    - [ ] Exercises\n\n3.  Selection\n\n    - [x] 6.1 Minimum and maximum\n    - [x] 6.2 Selection from one set\n    - [ ] 6.3 Selection from two sets\n    - [ ] 6.4 Selection from the complement of a set\n    - [ ] Exercises\n\n### Part Three: Greedy Algorithms\n\n1.  Greedy algorithms on lists\n\n    - [x] 7.1 A generic greedy algorithm\n    - [x] 7.2 Greedy sorting algorithms\n    - [x] 7.3 Coin‑changing\n    - [ ] 7.4 Decimal fractions in TeX\n    - [ ] 7.5 Nondeterministic functions and refinement\n    - [ ] Exercises\n\n2.  Greedy algorithms on trees\n\n    - [x] 8.1 Minimum‑height trees\n    - [x] 8.2 Huffman coding trees\n    - [x] 8.3 Priority queues\n    - [ ] Exercises\n\n3.  Greedy algorithms on graphs\n\n    - [ ] 9.1 Graphs and spanning trees\n    - [ ] 9.2 Kruskal\\'s algorithm\n    - [ ] 9.3 Disjoint sets and the union--find algorithm\n    - [ ] 9.4 Prim\\'s algorithm\n    - [ ] 9.5 Single‑source shortest paths\n    - [ ] 9.6 Dijkstra\\'s algorithm\n    - [ ] 9.7 The jogger\\'s problem\n    - [ ] Exercises\n\n### Part Four: Thinning Algorithms\n\n1.  Introduction to thinning\n\n    - [ ] 10.1 Theory\n    - [ ] 10.2 Paths in a layered network\n    - [ ] 10.3 Coin‑changing revisited\n    - [ ] 10.4 The knapsack problem\n    - [ ] 10.5 A general thinning algorithm\n    - [ ] Exercises\n\n2.  Segments and subsequences\n\n    - [ ] 11.1 The longest upsequence\n    - [ ] 11.2 The longest common subsequence\n    - [ ] 11.3 A short segment with maximum sum\n    - [ ] Exercises\n\n3.  Partitions\n\n    - [x] 12.1 Ways of generating partitions\n    - [ ] 12.2 Managing two bank accounts\n    - [x] 12.3 The paragraph problem\n    - [ ] Exercises\n\n### Part Five: Dynamic Programming\n\n1.  Efficient recursions\n\n    - [ ] 13.1 Two numeric examples\n    - [ ] 13.2 Knapsack revisited\n    - [ ] 13.3 Minimum‑cost edit sequences\n    - [ ] 13.4 Longest common subsequence revisited\n    - [ ] 13.5 The shuttle‑bus problem\n    - [ ] Exercises\n\n2.  Optimum bracketing\n\n    - [ ] 14.1 A cubic‑time algorithm\n    - [ ] 14.2 A quadratic‑time algorithm\n    - [ ] 14.3 Examples\n    - [ ] 14.4 Proof of monotonicity\n    - [ ] 14.5 Optimum binary search trees\n    - [ ] 14.6 The Garsia--Wachs algorithm\n    - [ ] Exercises\n\n## Part Six: Exhaustive Search\n\n1.  Ways of searching\n\n    - [ ] 15.1 Implicit search and the n‑queens problem\n    - [ ] 15.2 Expressions with a given sum\n    - [ ] 15.3 Depth‑first and breadth‑first search\n    - [ ] 15.4 Lunar Landing\n    - [ ] 15.5 Forward planning\n    - [ ] 15.6 Rush Hour\n    - [ ] Exercises\n\n2.  Heuristic search\n\n    - [ ] 16.1 Searching with an optimistic heuristic\n    - [ ] 16.2 Searching with a monotonic heuristic\n    - [ ] 16.3 Navigating a warehouse\n    - [ ] 16.4 The 8‑puzzle\n    - [ ] Exercises\n\n\n## :handshake: Contributing\n\nPlease see [CONTRIBUTING.org](CONTRIBUTING.org) for guidelines on how to contribute to this project.\n\n## :book: References\n\n- [Algorithm Design with Haskell](https://www.cs.ox.ac.uk/publications/books/adwh/) - The original book this adaptation is based on\n\n- [Lean 4 Manual](https://lean-lang.org/lean4/doc/) - Official Lean 4 documentation\n\n## :pushpin: License\n\nThis project is licensed under Apache License 2.0. See LICENSE.\n",1787954245125]