{"id":17671611,"url":"https://github.com/jonsterling/agda-calf","last_synced_at":"2025-03-30T15:21:27.788Z","repository":{"id":73170243,"uuid":"342301992","full_name":"jonsterling/agda-calf","owner":"jonsterling","description":"A cost-aware logical framework, embedded in Agda.","archived":false,"fork":false,"pushed_at":"2024-08-13T19:56:33.000Z","size":10735,"stargazers_count":60,"open_issues_count":6,"forks_count":2,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-02-05T16:48:30.707Z","etag":null,"topics":["agda","complexity","cost","logical-framework","modal-type-theory"],"latest_commit_sha":null,"homepage":"https://jonsterling.github.io/agda-calf/","language":"Agda","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonsterling.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-25T16:09:33.000Z","updated_at":"2025-02-04T21:55:10.000Z","dependencies_parsed_at":"2023-11-18T21:28:32.126Z","dependency_job_id":"75d851c7-e6c8-4bc7-87c3-dce902c88052","html_url":"https://github.com/jonsterling/agda-calf","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsterling%2Fagda-calf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsterling%2Fagda-calf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsterling%2Fagda-calf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsterling%2Fagda-calf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonsterling","download_url":"https://codeload.github.com/jonsterling/agda-calf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246334918,"owners_count":20760740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agda","complexity","cost","logical-framework","modal-type-theory"],"created_at":"2024-10-24T03:42:59.499Z","updated_at":"2025-03-30T15:21:27.751Z","avatar_url":"https://github.com/jonsterling.png","language":"Agda","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **calf**: A Cost-Aware Logical Framework\n\nThe **calf** language is a **c**ost-**a**ware **l**ogical **f**ramework for studying quantitative aspects of functional programs.\n\nThis repository contains the Agda implementation of **calf**, as well as some case studies of varying complexity.\n\n## HTML Browsing\n\nThe source code may be viewed interactively with (semantic) syntax highlighting in the browser using the HTML files in the [`./html`](./html) directory.\nThese files were generated by running:\n```sh\nagda --html --html-dir=html src/index.agda\n```\n\nYou may want to start by opening [`html/index.html`](./html/index.html).\n\nTo view a specific module `M`, open `html/M.html` in a web browser.\nFor example, open [`html/Examples.Sorting.Parallel.html`](./html/Examples.Sorting.Parallel.html) to view the module `Examples.Sorting.Parallel`.\n\n## Installation\n\nThis implementation of **calf** has been tested using:\n- Agda v2.6.3, with `agda-stdlib` v2.0 experimental\n\nInstallation instructions may be found in [`INSTALL.md`](./INSTALL.md).\n\n## Language Implementation\n\n### Cost Monoid Parameterization\n\n**calf** is parameterized by a *cost monoid* `(ℂ, +, zero, ≤)`.\nThe formal definition, `CostMonoid`, is given in [`Algebra.Cost`](./src/Algebra/Cost.agda).\nThe definition of a *parallel cost monoid* `(ℂ, ⊕, 𝟘, ⊗, 𝟙, ≤)` is given, as well, as `ParCostMonoid`.\n\nSome common cost monoids and parallel cost monoids are given in [`Algebra.Cost.Instances`](./src/Algebra/Cost/Instances.agda); for example, `ℕ-CostMonoid` simply tracks sequential cost.\nNote that every `ParCostMonoid` induces a `CostMonoid` via the additive substructure `(ℂ, ⊕, 𝟘, ≤)`.\n\n### Core Language\n\nThe language itself is implemented via the following files, which are given in a dependency-respecting order.\n\nThe following modules are not parameterized:\n- [`Calf.Prelude`](./src/Calf/Prelude.agda) contains commonly-used definitions.\n- [`Calf.CBPV`](./src/Calf/CBPV.agda) defines the basic dependent Call-By-Push-Value (CBPV) language, using Agda `postulate`s and rewrite rules.\n- [`Calf.Directed`](./src/Calf/Directed.agda) defines a preorder on each type, per the developments in [**decalf**](https://arxiv.org/abs/2307.05938).\n- [`Calf.Phase`](./src/Calf/Phase.agda) defines the phase distinction of extension and intension:\n  - [`Calf.Phase.Core`](./src/Calf/Phase/Core.agda) postulates a proposition, `ext`, for the extensional phase.\n  - [`Calf.Phase.Open`](./src/Calf/Phase/Open.agda) defines the open/extensional modality `◯` for `ext`.\n  - [`Calf.Phase.Closed`](./src/Calf/Phase/Closed.agda) defines the closed/intensional modality `●` for `ext`.\n  - [`Calf.Phase.Directed`](./src/Calf/Phase/Directed.agda) postulates the **decalf** law that under `ext`, inequality coincides with equality.\n  - [`Calf.Phase.Noninterference`](./src/Calf/Phase/Noninterference.agda) contains theorems related to the phase distinction/noninterference.\n\nThe following modules are parameterized by a `CostMonoid`:\n- [`Calf.Step`](./src/Calf/Step.agda) defines the computational effect `step` and the associated coherence laws via rewrite rules.\n\nThe following modules are parameterized by a `ParCostMonoid`:\n- [`Calf.Parallel`](./src/Calf/Parallel.agda) defines the parallel execution operation `_∥_` whose cost structure is given by the product operation of a `ParCostMonoid` (i.e., `_⊗_`).\n\n### Types\n\nIn [`src/Calf/Data`](./src/Calf/Data), we provide commonly-used data types.\n\nThe following modules are not parameterized and simply internalize the associated Agda types via the `meta⁺` primitive:\n- [`Calf.Data.Bool`](./src/Calf/Data/Bool.agda)\n- [`Calf.Data.Equality`](./src/Calf/Data/Equality.agda)\n- [`Calf.Data.List`](./src/Calf/Data/List.agda)\n- [`Calf.Data.Maybe`](./src/Calf/Data/Maybe.agda)\n- [`Calf.Data.Nat`](./src/Calf/Data/Nat.agda)\n- [`Calf.Data.Product`](./src/Calf/Data/Product.agda)\n- [`Calf.Data.Sum`](./src/Calf/Data/Sum.agda)\n\nThe following modules define custom, **calf**-specific data types for cost analysis and are parameterized by a `CostMonoid`:\n- [`Calf.Data.IsBoundedG`](./src/Calf/Data/IsBoundedG.agda) defines a generalized notion of cost bound, `IsBoundedG`, where a bound is a program of type `F unit`.\n  Additionally, it provides lemmas for proving the boundedness of common forms of computations.\n- [`Calf.Data.IsBounded`](./src/Calf/Data/IsBounded.agda) instantiates `IsBoundedG` for cost bounds of the form `step (F unit) c (ret triv)`.\n- [`Calf.Data.BoundedFunction`](./src/Calf/Data/BoundedFunction.agda) defines cost-bounded functions using `IsBounded`.\n- [`Calf.Data.BigO`](./src/Calf/Types/BigO.agda) gives a definition of \"big-O\" asymptotic bounds via `IsBounded`.\n  In particular, an element of the type `given A measured-via size , f ∈𝓞(g)` (i.e., \"given an input of type `A` and a size measure `size` on `A`, `f` is in `𝓞(g)`) is a lower bound on input sizes `n'` and a constant multiplier `k` along with a proof `h` that for all inputs `x` with `n' ≤ size x`, `f x` is bounded by `k` multiples of `g (size x)`, denoted `n' ≤n⇒f[n]≤ k g[n]via h`.\n\n## Examples\n\nWe provide a variety of case studies in [`src/Examples`](./src/Examples).\n\n### Sequential Algorithms\n\n#### [`Examples.Id`](./src/Examples/Id.agda)\n- `module Easy`\n  - Definition of the program `id` that trivially returns its input.\n  - Definition of the cost bound program `id/bound`, which here is the same as `id`.\n  - Theorem `id/is-bounded` showing that `id` is bounded by `id/bound`.\n  - Theorem `id/correct` stating the extensional correctness of `id` as a corollary of `id/is-bounded`.\n  - Theorem `id/asymptotic : given nat measured-via (λ n → n) , id ∈𝓞(λ n → 0)` stating that `id` is in `𝓞(0)`.\n- `module Hard`\n  - Definition of the program `id` that reconstructs its input via induction.\n  - Definition of the cost bound program `id/bound`, which incurs `n` cost before returning `n`.\n  - Theorem `id/is-bounded` showing that `id` is bounded by `id/bound`.\n  - Theorem `id/correct` stating the extensional correctness of `id` as a corollary of `id/is-bounded`.\n  - Theorem `id/asymptotic : given nat measured-via (λ n → n) , id ∈𝓞(λ n → n)` stating that `id` is in `𝓞(n)`, where `n` is the input number.\n- A proof that `Easy.id` and `Hard.id` are extensionally equivalent, `easy≡hard : ◯ (Easy.id ≡ Hard.id)`, as a corollary of the `id/correct` proofs.\n\n\u003c!--\n#### [`Examples.Gcd`](./src/Examples/Gcd.agda)\n- A **calf** implementation of Euclid's algorithm for gcd.\n- [`Examples.Gcd.Euclid`](./src/Examples/Gcd/Euclid.agda)\n  - Specification of the cost model via the instrumented operation `mod`.\n  - Definition of the type `gcd/i`, which specifies that inputs to Euclid's algorithm should be ordered (first is greater than second).\n  - Definition of the program `gcd/depth` that computes the recursion depth of Euclid's algorithm.\n- [`Examples.Gcd.Clocked`](./src/Examples/Gcd/Clocked.agda)\n  - The clocked version of Euclid's algorithm `gcd/clocked` in which the first parameter is used to justify recursive calls.\n  - The actual algorithm `gcd`, obtained by instantiating the clock parameter by `gcd/depth`.\n  - The theorem `gcd≤gcd/depth` stating that the cost of Euclid's algorithm is bounded by the recursion depth `gcd/depth`.\n- [`Examples.Gcd.Spec`](./src/Examples/Gcd/Spec.agda)\n  - Theorems `gcd≡spec/zero` and `gcd≡spec/suc` stating the behavioral correctness of `gcd` in terms of the defining equations of Euclid's algorithm.\n- [`Examples.Gcd.Refine`](./src/Examples/Gcd/Refine.agda)\n  - Refinement of the bound `gcd/depth` -- the theorem `gcd/depth≤gcd/depth/closed` states that the cost of `gcd` is bounded by `suc ∘ fib⁻¹`.\n--\u003e\n\n### Parallel Algorithms\n\n#### [`Examples.TreeSum`](./src/Examples/TreeSum.agda)\n- Definition of the program `sum` that sums the elements of a tree, incurring unit cost when performing each addition operation.\n  At each node, the recursive calls are computed in parallel.\n- Definition of the cost bound program `sum/bound`, which incurs `size t , depth t` cost before returning the sum of the tree via a value-level function.\n- Theorem `sum/has-cost` stating that `sum` and `sum/bound` are equivalent.\n- Theorem `sum/is-bounded` stating that the cost of `sum t` is bounded by `sum/bound`, as a corollary of `sum/has-cost`.\n\n#### [`Examples.Exp2`](./src/Examples/Exp2.agda)\n- `module Slow`\n  - Definition of the program `exp₂` that computes the exponentation of two by its input by performing two identical recursive calls.\n    Since two identical recursive calls are made in parallel, the work is exponential, but the span is still linear.\n  - Definition of the cost bound program `exp₂/bound`, incurring `2 ^ n - 1 , n` cost before returning result `2 ^ n`.\n  - Theorem `exp₂/is-bounded` showing that `exp₂` is bounded by `exp₂/bound`.\n  - Theorem `exp₂/correct` stating the extensional correctness of `exp₂` as a corollary of `exp₂/is-bounded`.\n  - Theorem `exp₂/asymptotic : given nat measured-via (λ n → n) , exp₂ ∈𝓞(λ n → 2 ^ n , n)` stating that `exp₂` is in `𝓞(2 ^ n , n)`.\n- `module Fast`\n  - Definition of the program `exp₂` which computes the exponentation of two by its input via a standard recursive algorithm.\n  - Definition of the cost bound program `exp₂/bound`, incurring `n , n` cost before returning result `2 ^ n`.\n  - Theorem `exp₂/is-bounded` showing that `exp₂` is bounded by `exp₂/bound`.\n  - Theorem `exp₂/correct` stating the extensional correctness of `exp₂` as a corollary of `exp₂/is-bounded`.\n  - Theorem `exp₂/asymptotic : given nat measured-via (λ n → n) , exp₂ ∈𝓞(λ n → n , n)` stating that `exp₂` is in `𝓞(n , n)`.\n- A proof that `Slow.exp₂` and `Fast.exp₂` are extensionally equivalent, `slow≡fast : ◯ (Slow.exp₂ ≡ Fast.exp₂)`.\n\n### Hybrid Algorithms\n\n#### [`Examples.Sorting`](./src/Examples/Sorting.agda)\nFirst, we develop a common collection of definitions and theorems used in both sequential and parallel sorting.\n- [`Examples.Sorting.Comparable`](./src/Examples/Sorting/Comparable.agda)\n  - Record `Comparable` describing the requirements for a type to be comparable, including `h-cost`, a hypothesis that each comparison is bounded by unit cost.\n    This serves as the cost model for sorting.\n- [`Examples.Sorting.Core`](./src/Examples/Sorting/Core.agda)\n  - Predicates for correctness of sorting, based on `Sorted` and the permutation relation `↭` from `agda-stdlib`.\n    The predicate `IsSort sort` states that `sort` is a correct sorting algorithm.\n  - Theorem `IsSort⇒≡`, which states that any two correct sorting algorithms are extensionally equivalent.\n\n##### [`Examples.Sorting.Sequential`](./src/Examples/Sorting/Sequential.agda)\nHere, we use cost monoid `ℕ-CostMonoid`, tracking the total number of sequential steps incurred.\n\n- [`Examples.Sorting.Sequential.InsertionSort`](./src/Examples/Sorting/Sequential/InsertionSort.agda)\n  - Definition of the program `sort` implementing insertion sort.\n  - Theorem `sort/correct : IsSort sort` verifying the correctness of `sort`.\n  - Theorem `sort≤sort/cost/closed` stating that the cost of `sort l` is bounded by `sort/cost/closed l = length l ²`.\n  - Theorem `sort/asymptotic : given (list A) measured-via length , sort ∈𝓞(λ n → n ²)` stating that `sort` is in `𝓞(n ²)`, where `n` is the length of the input list.\n- [`Examples.Sorting.Sequential.MergeSort`](./src/Examples/Sorting/Sequential/MergeSort.agda)\n    - [`Examples.Sorting.Sequential.MergeSort.Split`](./src/Examples/Sorting/Sequential/MergeSort/Split.agda)\n      - Definition of the program `split`, which splits a list in halves.\n      - Theorem `split/correct` verifying correctness properties of `split`.\n      - Theorem `split≤split/cost` stating that the cost of `split l` is bounded by `zero`, since splitting a list into halves requires no comparisons.\n    - [`Examples.Sorting.Sequential.MergeSort.Merge`](./src/Examples/Sorting/Sequential/MergeSort/Merge.agda)\n      - Definition of the program `merge`, which merges a pair of sorted lists.\n      - Theorem `merge/correct` verifying correctness properties of `merge`.\n      - Theorem `merge≤merge/cost/closed` stating that the cost of `merge (l₁ , l₂)` is bounded by `length l₁ + length l₂`.\n  - Definition of the program `sort` implementing merge sort.\n  - Theorem `sort/correct : IsSort sort` verifying the correctness of `sort`.\n  - Theorem `sort≤sort/cost/closed` stating that the cost of `sort l` is bounded by `sort/cost/closed l = ⌈log₂ length l ⌉ * length l`.\n  - Theorem `sort/asymptotic : given (list A) measured-via length , sort ∈𝓞(λ n → n * ⌈log₂ n ⌉)` stating that `sort` is in `𝓞(n * ⌈log₂ n ⌉)`, where `n` is the length of the input list.\n\nTheorem `isort≡msort : ◯ (ISort.sort ≡ MSort.sort)` states that `InsertionSort.sort` and `MergeSort.sort` are extensionally equivalent.\n\n\u003c!--\n##### [`Examples.Sorting.Parallel`](./src/Examples/Sorting/Parallel.agda)\nHere, we use *parallel* cost monoid `ℕ²-ParCostMonoid`, tracking a pair of natural numbers corresponding to the work (sequential cost) and span (idealized parallel cost), respectively.\n\n- [`Examples.Sorting.Parallel.InsertionSort`](./src/Examples/Sorting/Parallel/InsertionSort.agda)\n  - Definition of the program `sort` implementing insertion sort.\n  - Theorem `sort/correct : IsSort sort` verifying the correctness of `sort`.\n  - Theorem `sort≤sort/cost/closed` stating that the cost of `sort l` is bounded by `sort/cost/closed l = (length l ² , length l ²)`.\n  - Theorem `sort/asymptotic : given (list A) measured-via length , sort ∈𝓞(λ n → n  ² , n  ²)` stating that `sort` is in `𝓞(n  ²)` work and `𝓞(n  ²)` span, where `n` is the length of the input list.\n- [`Examples.Sorting.Parallel.MergeSort`](./src/Examples/Sorting/Parallel/MergeSort.agda)\n    - [`Examples.Sorting.Parallel.MergeSort.Split`](./src/Examples/Sorting/Parallel/MergeSort/Split.agda)\n      - Definition of the program `split`, which splits a list in halves.\n      - Theorem `split/correct` verifying correctness properties of `split`.\n      - Theorem `split≤split/cost` stating that the cost of `split l` is bounded by `𝟘 = (zero , zero)`, since splitting a list into halves requires no comparisons.\n    - [`Examples.Sorting.Parallel.MergeSort.Merge`](./src/Examples/Sorting/Parallel/MergeSort/Merge.agda)\n      - Definition of the program `merge`, which *sequentially* merges a pair of sorted lists.\n      - Theorem `merge/correct` verifying correctness properties of `merge`.\n      - Theorem `merge≤merge/cost/closed` stating that the cost of `merge (l₁ , l₂)` is bounded by `(length l₁ + length l₂ , length l₁ + length l₂)`, since this implementation of `merge` is sequential.\n  - Definition of the program `sort` implementing merge sort, where both recursive calls to `sort` are performed in parallel (via the parallel pairing operation `_∥_`).\n  - Theorem `sort/correct : IsSort sort` verifying the correctness of `sort`.\n  - Theorem `sort≤sort/cost/closed` stating that the cost of `sort l` is bounded by `sort/cost/closed l = (⌈log₂ length l ⌉ * length l , 2 * length l + ⌈log₂ length l ⌉)`.\n  - Theorem `sort/asymptotic : given (list A) measured-via length , sort ∈𝓞(λ n → n * ⌈log₂ n ⌉ , n)` stating that `sort` is in `𝓞(n * ⌈log₂ n ⌉)` work and `𝓞(n)` span, where `n` is the length of the input list.\n- [`Examples.Sorting.Parallel.MergeSortPar`](./src/Examples/Sorting/Parallel/MergeSortPar.agda)\n    - [`Examples.Sorting.Parallel.MergeSortPar.Merge`](./src/Examples/Sorting/Parallel/MergeSortPar/Merge.agda)\n      - Definition of the program `merge`, which merges a pair of sorted lists *in parallel* using auxiliary functions `splitMid` and `splitBy`.\n      - Theorem `merge/correct` verifying correctness properties of `merge`.\n      - Theorem `merge≤merge/cost/closed` stating that the cost of `merge (l₁ , l₂)` is bounded by `(pred[2^ ⌈log₂ suc (length l₁) ⌉ ] * ⌈log₂ suc (length l₂) ⌉ , ⌈log₂ suc (length l₁) ⌉ * ⌈log₂ suc (length l₂) ⌉)`, where `pred[2^ n ] = (2 ^ n) - 1`.\n  - Definition of the program `sort` implementing merge sort, where both recursive calls to `sort` are performed in parallel.\n    This is identical to `MergeSort.sort`, but using the parallel merge operation `MergeSortPar.Merge.Merge`.\n  - Theorem `sort/correct : IsSort sort` verifying the correctness of `sort`.\n  - Theorem `sort≤sort/cost/closed` stating that the cost of `sort l` is bounded by `sort/cost/closed l = (⌈log₂ length l ⌉ * length l * ⌈log₂ suc ⌈ length l /2⌉ ⌉ , ⌈log₂ length l ⌉ * ⌈log₂ suc ⌈ length l /2⌉ ⌉ ²)`.\n  - Theorem `sort/asymptotic : given (list A) measured-via length , sort ∈𝓞(λ n → n * ⌈log₂ n ⌉ ² , ⌈log₂ n ⌉ ^ 3)` stating that `sort` is in `𝓞(n * ⌈log₂ n ⌉ ²)` work and `𝓞(⌈log₂ n ⌉ ^ 3)` span, where `n` is the length of the input list.\n\nTheorem `isort≡msort : ◯ (ISort.sort ≡ MSort.sort)` states that `InsertionSort.sort` and `MergeSort.sort` are extensionally equivalent.\nSimilarly, `msort≡psort : ◯ (MSort.sort ≡ PSort.sort)` states that `MergeSort.sort` and `MergeSortPar.sort` are extensionally equivalent.\n--\u003e\n\n### Data Structures\n\n#### Amortized\n\n\u003c!--\n##### [`Examples.Queue`](./src/Examples/Queue.agda)\n- A **calf** implementation of [Batched queues](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)#Amortized_queue).\n- Specification of the cost model as the number of list iterations via the axiom `list/ind/cons`.\n- Upper bounds on the cost of individual enqueue and dequeue operations:\n  - The theorem `enq≤enq/cost` stating that enqueue has zero cost.\n  - The theorem `deq≤deq/cost` stating that dequeue has linear cost.\n- Amortized analysis of sequences of enqueue and dequeue operations:\n  - The theorem `acost≤2*|l|` stating that the amortized cost of a sequence of queue operations is at most twice the length of the sequence.\n--\u003e\n\n##### [`Examples.Amortized`](./src/Examples/Amortized.agda)\n\nAmortized data structures, [via coinduction](https://drops.dagstuhl.de/opus/volltexte/2023/18820).\n\n- [`Examples.Amortized.Simple`](./src/Examples/Amortized/Simple.agda) provides an amortized implementation of a simple amortized stream abstract data type.\n- [`Examples.Amortized.Queue`](./src/Examples/Amortized/Queue.agda) provides an implementation of [amortized queues](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)#Amortized_queue).\n- [`Examples.Amortized.DynamicArray`](./src/Examples/Amortized/DynamicArray.agda) provides an implementation of dynamically-growing arrays.\n\n\n### Decalf\n\nThe examples introduced in **decalf** are included in [`Examples.Decalf`](./src/Examples/Decalf.agda).\n\n#### [`Examples.Decalf.Basic`](./src/Examples/Decalf/Basic.agda)\n\nWe implement and analyze the basic `double` example.\n\n#### [`Examples.Decalf.Nondeterminism`](./src/Examples/Decalf/Nondeterminism.agda)\n\nWe introduce the `branch` and `fail` primitives for nondeterminism and give the corresponding examples.\n\n- `module QuickSort` includes the nondeterministic quicksort algorithm using primitives from [`Examples.Sorting.Sequential.Core`](./src/Examples/Sorting/Sequential.agda).\n- `module Lookup` includes the list lookup function that fails on out-of-bounds indices.\n- `module Pervasive` includes a simple example of pervasive (non-benign) nondeterminism.\n\n#### [`Examples.Decalf.ProbabilisticChoice`](./src/Examples/Decalf/ProbabilisticChoice.agda)\n\nWe introduce the probabilistic `flip` primitive and give the corresponding example, showing how the cost of `sublist` is bounded by the `binomial` distribution.\n\n#### [`Examples.Decalf.GlobalState`](./src/Examples/Decalf/GlobalState.agda)\n\nWe introduce the `get` and `set` primitives for global state and show a simple imperative program whose cost bound involves `get` and `set`.\n\n#### [`Examples.Decalf.HigherOrderFunction`](./src/Examples/Decalf/HigherOrderFunction.agda)\n\nWe define the `twice` and `map` higher-order functions and analyze them under assumptions about their input costs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonsterling%2Fagda-calf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonsterling%2Fagda-calf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonsterling%2Fagda-calf/lists"}