diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..49a4ca320 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,11 @@ +# Description + + + +# Checklist + +- [ ] Commit sequence broadly makes sense and commits have useful messages +- [ ] Code is formatted according to [CONTRIBUTING.md](https://github.com/input-output-hk/formal-ledger-specifications/blob/master/CONTRIBUTING.md) +- [ ] Self-reviewed the diff diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..d05e04aa9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,118 @@ +name: Formal Ledger Specs +on: + push: + branches: + - master + pull_request: + branches: + - master + +permissions: + contents: write + +env: + MAlonzo_branch: ${{ github.event.pull_request.head.ref }}-MAlonzo + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + ref: MAlonzo-code + + - name: Create branch ${{ env.MAlonzo_branch }} for generated code + if: github.event_name == 'pull_request' && github.event.action == 'opened' + run: | + git checkout -b ${{ env.MAlonzo_branch }} origin/MAlonzo-code + git push origin ${{ env.MAlonzo_branch }} + + - uses: actions/checkout@v4 + + - uses: cachix/install-nix-action@v20 + with: + nix_path: nixpkgs=channel:nixos-unstable + extra_nix_config: | + trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= + substituters = https://cache.iog.io https://cache.nixos.org/ + + - name: Build formalLedger + id: formalLedger + run: | + mkdir -p outputs + nix-build -A formalLedger -j1 -o outputs/formalLedger + rsync -r --include={'**/*.time'} outputs/formalLedger*/* docs/ + + - name: Build ledger + id: ledger + run: | + nix-build -A ledger -j1 -o outputs/ledger + rsync -r --exclude={'**/nix-support','**/lib'} outputs/ledger*/* docs/ + + - name: Build midnight + id: midnight + run: | + nix-build -A midnight -j1 -o outputs/midnight + rsync -r --exclude={'**/nix-support','**/lib'} outputs/midnight*/* docs/ + + - name: Upload PDF artifacts + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v4 + with: + name: PDF specs + path: docs/pdfs/*.pdf + + - name: Upload typechecking times + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v4 + with: + name: Typechecking durations + path: docs/*.time + + - name: Generate main website + if: github.ref == 'refs/heads/master' + run: | + echo "** Generated PDF files:"; find -L docs/ -name '*.pdf' + echo "** Generated HTML files:"; find -L docs/ -name '*.html' + echo "** Generated Haskell files:"; find -L docs/ -name '*.hs' + OUT_DIR=../docs/ make staticWebsite + + - name: Configure git + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Add files + if: github.ref == 'refs/heads/master' + run: | + git add -f docs/ + git commit -m "Updated for ${{ github.sha }}" + + - name: Push to gh-pages + if: github.ref == 'refs/heads/master' + uses: ad-m/github-push-action@v0.6.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: gh-pages + force: true + directory: . + + - name: Commit generated code at ${{ env.MAlonzo_branch }} + if: github.ref != 'refs/heads/master' + run: | + nix-build -A ledger.hsSrc -j1 -o outputs/MAlonzo + git stash push + git fetch origin ${{ env.MAlonzo_branch }} --depth 1 + git checkout ${{ env.MAlonzo_branch }} + rsync -r --exclude={'**/nix-support','**/lib'} outputs/MAlonzo/haskell/Ledger/* generated/ + git add -f generated && git commit -m "Generate code for ${{ github.sha }}" || echo "Everything is up-to-date." + + - name: Push ${{ env.MAlonzo_branch }} + if: github.ref != 'refs/heads/master' + uses: ad-m/github-push-action@v0.6.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ env.MAlonzo_branch }} + force: false + directory: . diff --git a/.github/workflows/pr_merged.yml b/.github/workflows/pr_merged.yml new file mode 100644 index 000000000..13c989600 --- /dev/null +++ b/.github/workflows/pr_merged.yml @@ -0,0 +1,53 @@ +name: Formal Ledger Specs - PR Merged +on: + pull_request: + branches: + - master + types: + - closed + +permissions: + contents: write + +env: + MAlonzo_branch: ${{ github.event.pull_request.head.ref }}-MAlonzo + +jobs: + pr-merged: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + ref: MAlonzo-code + - name: Merge ${{ env.MAlonzo_branch }} into MAlonzo-code + if: github.event.pull_request.merged + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + # GitHub Actions fetches shallow copies of remote branches + # which might not be ideal when rebasing, hence use `--unshallow`. + git fetch --unshallow origin ${{ env.MAlonzo_branch }} + git checkout ${{ env.MAlonzo_branch }} + # During `git rebase` 'ours' and 'theirs' are flipped + # so what we do here is that we keep the changes from ${{ env.MAlonzo_branch }}. + git rebase -X theirs origin/MAlonzo-code + git checkout MAlonzo-code + git merge --squash ${{ env.MAlonzo_branch }} + git commit -m "Generate code for GH-${{ github.event.pull_request.number }}" || echo "Everything is up-to-date." + + - name: Push MAlonzo-code + if: github.event.pull_request.merged + uses: ad-m/github-push-action@v0.6.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: MAlonzo-code + force: false + directory: . + + - name: Delete ${{ env.MAlonzo_branch }} branch + if: github.event.pull_request.merged + uses: dawidd6/action-delete-branch@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branches: ${{ env.MAlonzo_branch }} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..03026aa54 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,43 @@ +# Changelog + +## Conway spec + +### WIP + +- Rename `ccTermLimit` to `ccMaxTermLength` +- Add `Vote` and `Propose` script purposes +- Well-formed parameter updates can't be empty +- Add reward withdrawal restriction +- Add `pvCanFollow` check to `GOV` STS +- Fix treasury withdrawals +- Add `policy` field to `GovProposal` +- Add `Voter` type and use it for `ScriptPurpose` +- Add `minFeeRefScriptCoinsPerByte` protocol parameter +- Add security-relevant parameters +- Require reference inputs to be disjoint from regular inputs +- Fix CC expiration not being considered for `ccMinSize` check +- Replace `allEnactable` with `hasParent` in `GOV` +- Add `curTreasury` field to transactions +- Compute the voting stake distribution +- Add deposit amount to `dereg` certificate + +### V0.9 + +- Add proposal deposits +- Add proposal policy (which would become the guardrails script) +- Cold keys are now cold credentials +- Fix: governance actions were removed immediately, now delayed by one epoch +- Increment DRep activity in epochs where there was no GA to vote on +- Only allow votes for GAs that actually apply +- CC rejects every proposal when below `minCCSize` +- Fix that `RATIFY` wasn't total +- Properly implement treasury withdrawals +- Remove unused hot credentials at the epoch boundary +- Implement proper vote counting for SPOs +- Fix some protocol parameter names +- Check that `NewCommittee` actions are sensible when they are proposed +- Fix: treasury withdrawals were included in the wrong map + +### V0.8 + +First draft diff --git a/CODE-OF-CONDUCT.md b/CODE-OF-CONDUCT.md new file mode 100644 index 000000000..e9f01485c --- /dev/null +++ b/CODE-OF-CONDUCT.md @@ -0,0 +1 @@ +See the code of conduct in the [Cardano engineering handbook](https://github.com/input-output-hk/cardano-engineering-handbook/blob/main/CODE-OF-CONDUCT.md). diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 000000000..70f071401 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +. @whatisRT \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..551f31d08 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,113 @@ +# Contributing to the formal ledger specifications + +## Style guidelines + +We are currently aspiring to follow the [Agda standard library style guide][] as much as reasonable. Since some of our code will be rendered into a PDF, the formatting of the PDF takes priority over formatting of the code, so deviations are to be expected. + +We also have a separate style guide for formatting the PDF: [PDF style guide](PDF-style-guide.md). + +## Setup with emacs + +We use Agda version 2.6.4 and various dependencies. You can install the correct version of Agda and the dependencies using `nix-env -iA agda -f .`, but this is a global install which you may not want if you also have other Agda projects. + +To install Agda locally and use that install with emacs, you can do the following: + +- Build `agda` and `agda-mode` binaries by invoking the following: `nix-build -A agdaWithDeps -o ~/IOHK/ledger-agda`. You can replace `~/IOHK/ledger-agda` with whatever path you like, just make sure to replace it in `my/agda-versions` below as well. + + *Note*. You need not have built/installed Agda prior to invoking this `nix-build` command (though it's okay if you have). + + *Note*. To instruct the `Makefile` to use this local Agda binary, invoke it like so: `AGDA=~/IOHK/ledger-agda make -C src/` + +- Put the following into your init file (highlight and `M-x eval-region` to load it without restarting emacs). + + ``` + ;; Defines a function `my/switch-agda' that switches between different + ;; `agda' executables defined in `my/agda-versions'. The first entry of + ;; `my/agda-versions' is assumed to be the default Agda. + ;; + ;; If there are two entries in `my/agda-versions', `my/switch-agda' toggles + ;; between the two. If there are more entries, it will ask which one + ;; to choose. + + (setq my/agda-versions `(("Agda" "2.6.3" "agda") + ("Ledger Agda" "2.6.4" "~/IOHK/ledger-agda/bin/agda"))) + + (setq my/selected-agda (caar my/agda-versions)) + + (defun my/switch-agda (name version path) + (interactive + (cond ((> (length my/agda-versions) 2) + (assoc (completing-read "Agda" my/agda-versions '(lambda (x) 't) 't) my/agda-versions)) + ((= (length my/agda-versions) 2) + (car (seq-filter '(lambda (x) (not (string= my/selected-agda (car x)))) my/agda-versions))) + (t (error "my/agda-versions needs to have at least two elements!")))) + (message "Selecting %s, version %s" name version) + (setq my/selected-agda name + agda2-version version + agda2-program-name path) + (agda2-restart)) + + (with-eval-after-load 'agda2-mode (define-key agda2-mode-map (kbd "C-c C-x C-t") 'my/switch-agda)) + ``` + + *Note*. This assumes that your regular install of Agda is in your path with the name `agda` and version `2.6.3`, otherwise you'll have to edit `my/agda-versions`. + + You can then use `M-x my/toggle-ledger-agda`, or `C-c C-x C-t`, to switch between your regular install of Agda and the locally installed version. + + There are other options as well, but this should work with all kinds of custom emacs setups or distributions (assuming there isn't already some other stuff going on with your Agda setup). + + +## Setup with nix-shell + +`nix-shell` provides Agda complete with the correct dependencies. So you should be able to run your preferred editor within `nix-shell` and it should see the required `agda` executable. + +## Building the PDF quickly + +The Makefile can be used to build the PDF without having to build everything else. Either run `make` from within `nix-shell`, or use +``` +nix-shell --command 'make docs' +``` +to run `make` without launching an interactive shell. + +This combines well with the ability to invoke the TeX backend of Agda within Emacs, +which is much faster when you have already loaded an Agda file/interface. + +## Building other artifacts + +Apart from the PDF specification, the `Makefile` can be used to also generate the following: +- `make html`: generate HTML under `dist/html/` +- `make hs`: generate Haskell code under `dist/MAlonzo/` +- `make hsTest`: run the Haskell tests of each Agda formalisation +- `make staticWebsite`: gather all resources above in a central webpage `dist/index.html` + +If you only want to command to affect a single project, prefix with `.`, e.g. +``` +$ make ledger.html +$ make midnight.hs +``` + +## Updating nixpkgs + +To update the default nixpkgs used to build the derivations, run +``` +niv update nixpkgs -r +``` + +or +``` +niv update nixpkgs -v +``` + +For example: +``` +niv update nixpkgs -r 4e329926df7ee5fa49929a83d31ee7d541f8b45c +niv update nixpkgs -v 21.11.337905.902d91def1e +``` + +## Maintainer + +This repository is maintained by @WhatisRT. + + +[Agda]: https://wiki.portal.chalmers.se/agda/pmwiki.php +[Agda standard library style guide]: https://github.com/agda/agda-stdlib/blob/master/notes/style-guide.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..f433b1a53 --- /dev/null +++ b/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..7727dbe9d --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +%: + $(MAKE) -C src/ $@ diff --git a/NOTICE b/NOTICE new file mode 100644 index 000000000..dda069665 --- /dev/null +++ b/NOTICE @@ -0,0 +1,12 @@ +copyright: 2021-2023 Input Output Global Inc (IOG) + +Licensed under the Apache License, Version 2.0 (the "License"). +You may not use this file except in compliance with the License. +You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0.txt + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +express or implied. See the License for the specific language +governing permissions and limitations under the License. diff --git a/PDF-style-guide.md b/PDF-style-guide.md new file mode 100644 index 000000000..bda3f9b77 --- /dev/null +++ b/PDF-style-guide.md @@ -0,0 +1,88 @@ +# PDF spec guidelines + +The purpose of the PDF specs is to be readable by a wide range of people. They should not assume +- knowledge of specific (as opposed to general) concepts, notations or syntax or +- familiarity with another Cardano-specific resource, other than other specifications. + +## Notation + +We want to avoid syntax that is not commonly used outside of the +languages we use. While this is really inconvenient sometimes, the +more we use such notations the more we need to introduce them, +increasing the barrier to entry. + +| Concept | Examples | | +|-----------------------------------------------|----------------------------------------------------------|--------------------------------------------------------------------------------| +| General concepts | sets, functions, products | Should not be explained. | +| Functional programming concepts | lambdas, pattern matching, inductive data types | May be worth introducing briefly. | +| Advanced or unusual FP concepts | dependent types, `with`, copatterns | Should be avoided. | +| Functional programming names/notations/syntax | `_$_`, `map`, `fold`, `module`, `open` | Has to be explained. Avoid if reasonably possible. | +| Notation | inference rules, concrete notations for general concepts | May or may not need an explanation, depending on how standard the notation is. | + +## Hiding pieces of code + +Hiding pieces of the underlying Agda code can be a useful tool to +accomplish these objectives, but it is important that this is not +overused. Any code whose meaning depends on hidden code must be +explained by prose. However, it is always preferable if a figure can +be fully understood without extra explanation. + +## Avoiding complexity + +- reduce the number of dependencies as much as possible, which can + often be done by generalizing +- move (simple) definitions from being defined right next to their + usage to where they would naturally be defined + +## Alignment + +For better visual presentation, we should align figures properly. This +might sometimes not be possible while also maintaining other +constraints. Two cases where we usually want to align things are: +- multiple lines of the form `a = b`, where those lines are short enough +- a long expression of the form `x = a1 + ... + an` should be broken + into multiple lines where the `=` and `+` signs are aligned (also + applies to any other infix operator) + +The second point shouldn't be overused - if it is possible to use +horizontal space and save on vertical space it is probably good to do +so. + +## Cardano-specific terms + +We prefer generic naming over Cardano-specific naming. The main +example is `Coin` (instead of `Lovelace`). + +## Prose explaining figures + +The prose should supply context and should help understanding the +figures. Generally, for each definition we should answer the questions +what and why. + +- For what, note that not everything that's contained in a figure + necessarily needs an explanation - if the explanation of a + definition is simply repeating the definition in words it can + probably be omitted (like comments in a program). This ensures the + prose is relevant: a reader that reads lots of unnecessary + explanations is likely to skip reading the prose at some point. But + then why write it in the first place? + +- Why is a much more difficult question to answer, and also not every + single definition needs a direct answer to this question. Instead of + answering 'why do we need X' directly, it might be better to explain + something about the greater design that explains why we need 'X, Y + and Z' all at once. + This question can also have other shapes: why did we define it as X + instead of Y, why does this case need special handling, etc. + +Other notes: +- repetition in the prose should be avoided +- the relations (and often the functions as well) in the spec don't do + things, they define things (ex: '`feesOK` defines what conditions + the transaction fees must satisfy', not '`feesOK` computes whether + the conditions that the fees must satisfy are being met') + +## Other points + +- Don't include an empty line before `\end{code}`. This will add an + additional line in the PDF, which looks odd. diff --git a/README.md b/README.md new file mode 100644 index 000000000..c0d8af713 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# Formal ledger specifications + +This repository contains the formal ledger specifications that are intended to eventually replace the existing formal specifications of the Cardano ledger found [here](https://github.com/IntersectMBO/cardano-ledger). This project is currently incomplete and work in progress. + +This repository currently contains two specifications---the work in progress specification for Cardano (up to and including the Conway era) and a small example that was produced for the Midnight project (but is unrelated to any actual Midnight code/features). Each specification is executable and contains some documentation in the form of a PDF document. They can be built by following the steps below. + +Formal Specification | HTML Version | Haskell Tests | +----------------------|--------------|---------------| +[Full Cardano Ledger](https://IntersectMBO.github.io/formal-ledger-specifications/pdfs/cardano-ledger.pdf) | [Ledger.PDF](https://IntersectMBO.github.io/formal-ledger-specifications/html/Ledger.PDF.html) | [UTXOW test](https://IntersectMBO.github.io/formal-ledger-specifications/haskell/Ledger/test/UtxowSpec.hs) | +[Conway](https://IntersectMBO.github.io/formal-ledger-specifications/pdfs/conway-ledger.pdf) | [Ledger.PDF](https://IntersectMBO.github.io/formal-ledger-specifications/html/Ledger.PDF.html) | [UTXOW test](https://IntersectMBO.github.io/formal-ledger-specifications/haskell/Ledger/test/UtxowSpec.hs) | +[Midnight Example](https://IntersectMBO.github.io/formal-ledger-specifications/pdfs/midnight-example.pdf) | [MidnightExample.PDF](https://IntersectMBO.github.io/formal-ledger-specifications/html/MidnightExample.PDF.html) | [LEDGER test](https://IntersectMBO.github.io/formal-ledger-specifications/haskell/MidnightExample/test/LedgerSpec.hs) | + +Note: the HTML versions of the specifications are interactive, but many modules currently contain LaTeX code which is used to generate the PDF. We intend to fix this eventually. + +-------------------- + +## Build and Test the Formal Spec + +### Clone this repository and enter its directory + +``` +git clone https://github.com/IntersectMBO/formal-ledger-specifications.git +cd formal-ledger-specifications +``` + + +### Build the spec using nix-build + +Invoke the following `nix-build` commands from inside the `formal-ledger-specifications` directory. + +``` +nix-build -A ledger.docs # generate the PDF spec of the Cardano ledger +nix-build -A midnight.docs # generate the PDF spec of the Midnight example +nix-build -A ledger.hsSrc # extract the Haskell code of the Cardano ledger +nix-build -A midnight.hsSrc # extract the Haskell code of the Midnight example +``` + +### Test the spec using nix-shell + +The `hsExe` is a `cabal` package, which can be loaded into GHCI like this: + +``` +nix-shell -A run --command "cabal repl --build-depends 'cardano-ledger'" +λ> :m Lib +λ> :i UTxOState +``` + +Building the `hsExe` derivation will also run the test suite, which you can manually do using `cabal test`. + + + +## Contributions and Feedback + +If you would like more detailed information and/or you want to contribute to the Agda formalization of the spec, please see the [CONTRIBUTING.md](CONTRIBUTING.md) file. + +Please [submit a new issue][] if you find problems with, and/or wish to comment on, this repository. + +[submit a new issue]: https://github.com/IntersectMBO/formal-ledger-specifications/issues/new/choose diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..b35604de2 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1 @@ +See the security file in the [Cardano engineering handbook](https://github.com/input-output-hk/cardano-engineering-handbook/blob/main/SECURITY.md). diff --git a/cardano-interface/CardanoInterface.agda b/cardano-interface/CardanoInterface.agda new file mode 100644 index 000000000..a40e93dc4 --- /dev/null +++ b/cardano-interface/CardanoInterface.agda @@ -0,0 +1,17 @@ +module CardanoInterface where + +-------------------------------------------------------------------------------- +-- Cardano ledger interface +-- +-- An abstract interface of the ledger, which should be used by +-- consensus and implemented by ledger. +-------------------------------------------------------------------------------- + +open import Data.Unit + +record LedgerInterface : Set₁ where + field + Block Slot BBodyEnv BBodyState NewEpochState PParams : Set + getPParams : NewEpochState → PParams + _⊢_⇀⦇_,BBODY⦈_ : BBodyEnv → BBodyState → Block → BBodyState → Set + _⊢_⇀⦇_,TICK⦈_ : ⊤ → NewEpochState → Slot → NewEpochState → Set diff --git a/cardano-interface/cardano-interface.agda-lib b/cardano-interface/cardano-interface.agda-lib new file mode 100644 index 000000000..70803c1de --- /dev/null +++ b/cardano-interface/cardano-interface.agda-lib @@ -0,0 +1,6 @@ +name: cardano-interface +depend: + standard-library + standard-library-classes + standard-library-meta +include: . \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 000000000..bfa7f3eff --- /dev/null +++ b/default.nix @@ -0,0 +1,196 @@ +{ sources ? import ./nix/sources.nix +, pkgs ? import sources.nixpkgs { + overlays = [ ]; + config = { }; + } +}: + +with pkgs; +let + locales = { + LANG = "en_US.UTF-8"; + LC_ALL = "en_US.UTF-8"; + LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" + then "${pkgs.glibcLocales}/lib/locale/locale-archive" + else ""; + }; + + customAgda = import sources.agda-nixpkgs { + inherit (pkgs) system; + }; + + agdaStdlib = customAgda.agdaPackages.standard-library; + + agdaStdlibClasses = customAgda.agdaPackages.mkDerivation { + inherit (locales) LANG LC_ALL LOCALE_ARCHIVE; + pname = "agda-stdlib-classes"; + version = "2.0"; + src = fetchFromGitHub { + repo = "agda-stdlib-classes"; + owner = "omelkonian"; + rev = "v2.0"; + sha256 = "sha256-PcieRRnctjCzFCi+gUYAgyIAicMOAZPl8Sw35fZdt0E="; + }; + meta = { }; + libraryFile = "agda-stdlib-classes.agda-lib"; + everythingFile = "Classes.agda"; + buildInputs = [ agdaStdlib ]; + }; + + agdaStdlibMeta = customAgda.agdaPackages.mkDerivation { + inherit (locales) LANG LC_ALL LOCALE_ARCHIVE; + pname = "agda-stdlib-meta"; + version = "2.0"; + src = fetchFromGitHub { + repo = "stdlib-meta"; + owner = "input-output-hk"; + rev = "4fc4b1ed6e47d180516917d04be87cbacbf7d314"; + sha256 = "T+9vwccbDO1IGBcGLjgV/fOt+IN14KEV9ct/J6nQCsM="; + }; + meta = { }; + libraryFile = "agda-stdlib-meta.agda-lib"; + everythingFile = "Main.agda"; + buildInputs = [ agdaStdlib agdaStdlibClasses ]; + }; + + deps = [ agdaStdlib agdaStdlibClasses agdaStdlibMeta ]; + agdaWithPkgs = p: customAgda.agda.withPackages { pkgs = p; ghc = pkgs.ghc; }; + +in +rec { + + agdaWithDeps = agdaWithPkgs deps; + agda = agdaWithPkgs (deps ++ [ formalLedger ]); + + latex = texlive.combine { + inherit (texlive) + scheme-small + xits + collection-latexextra + collection-latexrecommended + collection-mathscience + bclogo + latexmk; + }; + + formalLedger = customAgda.agdaPackages.mkDerivation { + inherit (locales) LANG LC_ALL LOCALE_ARCHIVE; + pname = "formal-ledger"; + version = "0.1"; + src = ./src; + meta = { }; + buildInputs = deps; + buildPhase = '' + bash typeCheck.sh + ''; + postInstall = '' + cp -r latex/ Makefile typecheck.time $out + sh checkTypeChecked.sh + ''; + extraExtensions = [ "hs" "cabal" "py" ]; + }; + + mkSpecDerivation = { project, main }: rec { + docs = stdenv.mkDerivation { + inherit (locales) LANG LC_ALL LOCALE_ARCHIVE; + pname = "docs"; + version = "0.1"; + src = "${formalLedger}"; + meta = { }; + buildInputs = [ agdaWithDeps latex python3 ]; + buildPhase = '' + OUT_DIR=$out make "${project}".docs + ''; + doCheck = true; + checkPhase = '' + test -n "$(find $out/pdfs/ -type f -name '*.pdf')" + ''; + dontInstall = true; + }; + + html = stdenv.mkDerivation { + inherit (locales) LANG LC_ALL LOCALE_ARCHIVE; + pname = "html"; + version = "0.1"; + src = "${formalLedger}"; + meta = { }; + buildInputs = [ agdaWithDeps ]; + buildPhase = '' + OUT_DIR=$out make "${project}".html + ''; + doCheck = true; + checkPhase = '' + test -n "$(find $out/html/ -type f -name '*.html')" + ''; + dontInstall = true; + }; + + hsSrc = stdenv.mkDerivation { + inherit (locales) LANG LC_ALL LOCALE_ARCHIVE; + pname = "hs-src"; + version = "0.1"; + src = "${formalLedger}"; + meta = { }; + buildInputs = [ agdaWithDeps ]; + buildPhase = '' + OUT_DIR=$out make "${project}".hs + ''; + doCheck = true; + checkPhase = '' + test -n "$(find $out/haskell/ -type f -name '*.hs')" + # OUT_DIR=$out make "${project}".hsTest + ''; + dontInstall = true; + }; + + # hsDocs = stdenv.mkDerivation { + # pname = "hs-docs"; + # version = "0.1"; + # src = "${formalLedger}"; + # meta = { }; + # buildInputs = [ agdaWithDeps ]; + # configurePhase = '' + # export HOME=$TMP + # ''; + # buildPhase = '' + # OUT_DIR=$out make "${project}".hsDocs + # ''; + # doCheck = true; + # checkPhase = '' + # test -n "$(find $out/haskell/ -type f -name '*.html')" + # ''; + # dontInstall = true; + # }; + + hsExe = haskell.lib.disableLibraryProfiling (haskellPackages.callCabal2nixWithOptions "${project}" "${hsSrc}/haskell/${main}" "--no-haddock" {}); + + }; + + mkPdfDerivation = name: version: project: stdenv.mkDerivation { + inherit (locales) LANG LC_ALL LOCALE_ARCHIVE; + pname = name; + version = version; + src = "${formalLedger}"; + meta = { }; + buildInputs = [ agdaWithDeps latex python3 ]; + buildPhase = '' + OUT_DIR=$out make ${project} + ''; + doCheck = true; + checkPhase = '' + test -n "$(find $out/pdfs/ -type f -name '*.pdf')" + ''; + dontInstall = true; + }; + + ledger = mkSpecDerivation { + project = "ledger"; + main = "Ledger"; + } // { + conway = mkPdfDerivation "conway-formal-spec" "0.9" "ledger.conway.docs"; + }; + midnight = mkSpecDerivation { + project = "midnight"; + main = "MidnightExample"; + }; +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..ac6e46c9e --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + outputs = _: let + systems = [ "x86_64-linux" ]; + + # let's use niv instead of flake inputs + sources = import nix/sources.nix; + pkgs = import sources.nixpkgs { system = builtins.head systems; }; + inherit (pkgs) lib; + in { + hydraJobs = lib.genAttrs systems (system: let + exposed = import ./. { + inherit sources; + pkgs = import sources.nixpkgs { inherit system; }; + }; + + specsDerivationsPackages = key: lib.mapAttrs' + (k: lib.nameValuePair "${key}-${k}") + (lib.filterAttrs (k: v: builtins.elem k [ "docs" "hsExe" ]) exposed.${key}); + + jobs = { + inherit (exposed) + agda + agdaWithDeps + latex + formalLedger; + } // + specsDerivationsPackages "ledger" // + specsDerivationsPackages "midnight"; + in jobs // { + required = pkgs.releaseTools.aggregate { + name = "required"; + constituents = lib.collect lib.isDerivation jobs; + }; + }); + }; +} diff --git a/generated/MAlonzo/Code/Ledger/Foreign/HSLedger/Ratify.hs b/generated/MAlonzo/Code/Ledger/Foreign/HSLedger/Ratify.hs index 8e7fd4094..e4e9f350b 100644 --- a/generated/MAlonzo/Code/Ledger/Foreign/HSLedger/Ratify.hs +++ b/generated/MAlonzo/Code/Ledger/Foreign/HSLedger/Ratify.hs @@ -79,7 +79,7 @@ d_acceptedBy'63'_48 :: MAlonzo.Code.Relation.Nullary.Decidable.Core.T_Dec_20 d_acceptedBy'63'_48 = coe - MAlonzo.Code.Ledger.Ratify.d_acceptedBy'63'_2530 + MAlonzo.Code.Ledger.Ratify.d_acceptedBy'63'_2526 (coe MAlonzo.Code.Ledger.Foreign.HSLedger.Core.d_HSTransactionStructure_850) -- Ledger.Foreign.HSLedger.Ratify._.acceptedStakeRatio @@ -91,7 +91,7 @@ d_acceptedStakeRatio_50 :: MAlonzo.Code.Data.Rational.Base.T_ℚ_6 d_acceptedStakeRatio_50 = coe - MAlonzo.Code.Ledger.Ratify.d_acceptedStakeRatio_2228 + MAlonzo.Code.Ledger.Ratify.d_acceptedStakeRatio_2224 (coe MAlonzo.Code.Ledger.Foreign.HSLedger.Core.d_HSTransactionStructure_850) -- Ledger.Foreign.HSLedger.Ratify._.actualVotes @@ -55680,7 +55680,7 @@ du_govActionInfo_248 v0 v1 v2 MAlonzo.Code.Data.String.Base.d__'43''43'__20 (MAlonzo.Code.Data.Rational.Show.d_show_6 (coe - MAlonzo.Code.Ledger.Ratify.d_acceptedStakeRatio_2228 + MAlonzo.Code.Ledger.Ratify.d_acceptedStakeRatio_2224 (coe MAlonzo.Code.Ledger.Foreign.HSLedger.Core.d_HSTransactionStructure_850) (coe MAlonzo.Code.Ledger.GovernanceActions.C_SPO_670) @@ -56387,7 +56387,7 @@ du_govActionInfo_248 v0 v1 v2 (coe MAlonzo.Code.Data.String.Base.d__'43''43'__20 (let v5 - = MAlonzo.Code.Ledger.Ratify.d_acceptedBy'63'_2530 + = MAlonzo.Code.Ledger.Ratify.d_acceptedBy'63'_2526 (coe MAlonzo.Code.Ledger.Foreign.HSLedger.Core.d_HSTransactionStructure_850) (coe @@ -56420,7 +56420,7 @@ du_govActionInfo_248 v0 v1 v2 MAlonzo.Code.Data.String.Base.d__'43''43'__20 (MAlonzo.Code.Data.Rational.Show.d_show_6 (coe - MAlonzo.Code.Ledger.Ratify.d_acceptedStakeRatio_2228 + MAlonzo.Code.Ledger.Ratify.d_acceptedStakeRatio_2224 (coe MAlonzo.Code.Ledger.Foreign.HSLedger.Core.d_HSTransactionStructure_850) (coe MAlonzo.Code.Ledger.GovernanceActions.C_DRep_668) @@ -57138,7 +57138,7 @@ du_govActionInfo_248 v0 v1 v2 (coe MAlonzo.Code.Data.String.Base.d__'43''43'__20 (let v5 - = MAlonzo.Code.Ledger.Ratify.d_acceptedBy'63'_2530 + = MAlonzo.Code.Ledger.Ratify.d_acceptedBy'63'_2526 (coe MAlonzo.Code.Ledger.Foreign.HSLedger.Core.d_HSTransactionStructure_850) (coe @@ -57176,7 +57176,7 @@ du_govActionInfo_248 v0 v1 v2 MAlonzo.Code.Data.String.Base.d__'43''43'__20 (MAlonzo.Code.Data.Rational.Show.d_show_6 (coe - MAlonzo.Code.Ledger.Ratify.d_acceptedStakeRatio_2228 + MAlonzo.Code.Ledger.Ratify.d_acceptedStakeRatio_2224 (coe MAlonzo.Code.Ledger.Foreign.HSLedger.Core.d_HSTransactionStructure_850) (coe @@ -57928,7 +57928,7 @@ du_govActionInfo_248 v0 v1 v2 (coe MAlonzo.Code.Data.String.Base.d__'43''43'__20 (let v5 - = MAlonzo.Code.Ledger.Ratify.d_acceptedBy'63'_2530 + = MAlonzo.Code.Ledger.Ratify.d_acceptedBy'63'_2526 (coe MAlonzo.Code.Ledger.Foreign.HSLedger.Core.d_HSTransactionStructure_850) (coe diff --git a/generated/MAlonzo/Code/Ledger/Ratify.hs b/generated/MAlonzo/Code/Ledger/Ratify.hs index 28da9c4b9..5b58be361 100644 --- a/generated/MAlonzo/Code/Ledger/Ratify.hs +++ b/generated/MAlonzo/Code/Ledger/Ratify.hs @@ -1338,7 +1338,7 @@ d_actualVotes_2068 v0 v1 v2 v3 v4 v5 MAlonzo.Code.Ledger.GovernanceActions.C_credVoter_678 (coe MAlonzo.Code.Ledger.GovernanceActions.C_CC_666)) (coe - du_actualCCVotes_2196 (coe v0) (coe v1) (coe v2) (coe v3) + du_actualCCVotes_2192 (coe v0) (coe v1) (coe v2) (coe v3) (coe v5))) (coe MAlonzo.Code.Axiom.Set.Map.du__'8746''737'__884 @@ -1351,7 +1351,7 @@ d_actualVotes_2068 v0 v1 v2 v3 v4 v5 (MAlonzo.Code.Ledger.GovernanceActions.d_DecEq'45'VDeleg_806 (coe MAlonzo.Code.Ledger.Transaction.d_govStructure_2350 (coe v0)))) - (coe du_actualPDRepVotes_2204 (coe v0) (coe v4)) + (coe du_actualPDRepVotes_2200 (coe v0) (coe v4)) (coe MAlonzo.Code.Axiom.Set.Map.du__'8746''737'__884 (coe @@ -1363,8 +1363,8 @@ d_actualVotes_2068 v0 v1 v2 v3 v4 v5 (MAlonzo.Code.Ledger.GovernanceActions.d_DecEq'45'VDeleg_806 (coe MAlonzo.Code.Ledger.Transaction.d_govStructure_2350 (coe v0)))) - (coe du_actualDRepVotes_2206 (coe v0) (coe v1) (coe v5)) - (coe du_actualSPOVotes_2208 (coe v0) (coe v1) (coe v5) (coe v4)))) + (coe du_actualDRepVotes_2202 (coe v0) (coe v1) (coe v5)) + (coe du_actualSPOVotes_2204 (coe v0) (coe v1) (coe v5) (coe v4)))) -- Ledger.Ratify._._.ccHotKeys d_ccHotKeys_2086 :: T_RatifyEnv_1890 -> @@ -1714,32 +1714,8 @@ du_actualCCVote_2182 v0 v1 v2 v3 v4 MAlonzo.Code.Axiom.Set.Rel.du_dom_338 v7 (coe MAlonzo.Code.Axiom.Set.Map.du__'738'_534 (coe v2)))))) _ -> coe MAlonzo.Code.Ledger.GovernanceActions.C_abstain_734) --- Ledger.Ratify._.activeCC -d_activeCC_2192 :: - MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> - T_RatifyEnv_1890 -> - MAlonzo.Code.Ledger.PParams.T_PParams_244 -> - Maybe MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> - MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> - MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> - MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> - [MAlonzo.Code.Ledger.Address.T_Credential_16] -d_activeCC_2192 v0 v1 ~v2 ~v3 ~v4 ~v5 v6 - = du_activeCC_2192 v0 v1 v6 -du_activeCC_2192 :: - MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> - T_RatifyEnv_1890 -> - MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> - [MAlonzo.Code.Ledger.Address.T_Credential_16] -du_activeCC_2192 v0 v1 v2 - = coe - MAlonzo.Code.Axiom.Set.du_mapPartial_564 - (MAlonzo.Code.Axiom.Set.d_th_1458 - (coe MAlonzo.Code.Ledger.Set.Theory.d_List'45'Model'7496'_10)) - (coe du_getCCHotCred_2172 (coe v0) (coe v1)) - (coe MAlonzo.Code.Axiom.Set.Map.du__'738'_534 (coe v2)) -- Ledger.Ratify._.actualCCVotes -d_actualCCVotes_2196 :: +d_actualCCVotes_2192 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.PParams.T_PParams_244 -> @@ -1747,16 +1723,16 @@ d_actualCCVotes_2196 :: MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_actualCCVotes_2196 v0 v1 v2 v3 ~v4 v5 - = du_actualCCVotes_2196 v0 v1 v2 v3 v5 -du_actualCCVotes_2196 :: +d_actualCCVotes_2192 v0 v1 v2 v3 ~v4 v5 + = du_actualCCVotes_2192 v0 v1 v2 v3 v5 +du_actualCCVotes_2192 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.PParams.T_PParams_244 -> Maybe MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_actualCCVotes_2196 v0 v1 v2 v3 v4 +du_actualCCVotes_2192 v0 v1 v2 v3 v4 = case coe v3 of MAlonzo.Code.Agda.Builtin.Maybe.C_just_16 v5 -> case coe v5 of @@ -1770,17 +1746,44 @@ du_actualCCVotes_2196 v0 v1 v2 v3 v4 (coe MAlonzo.Code.Ledger.Set.Theory.du_length'738'_226 (coe - MAlonzo.Code.Ledger.Address.du_DecEq'45'Credential_142 + MAlonzo.Code.Class.DecEq.Instances.du_DecEq'45''215'_160 (coe - MAlonzo.Code.Ledger.Crypto.d_DecEq'45'THash_22 + MAlonzo.Code.Class.DecEq.Instances.du_DecEq'45''215'_160 (coe - MAlonzo.Code.Ledger.Crypto.d_khs_200 - (coe MAlonzo.Code.Ledger.Transaction.d_crypto_1234 (coe v0)))) + MAlonzo.Code.Ledger.Address.du_DecEq'45'Credential_142 + (coe + MAlonzo.Code.Ledger.Crypto.d_DecEq'45'THash_22 + (coe + MAlonzo.Code.Ledger.Crypto.d_khs_200 + (coe + MAlonzo.Code.Ledger.Transaction.d_crypto_1234 + (coe v0)))) + (coe + MAlonzo.Code.Ledger.Crypto.d_DecEq'45'ScriptHash_204 + (coe MAlonzo.Code.Ledger.Transaction.d_crypto_1234 (coe v0)))) + (coe + MAlonzo.Code.Ledger.Types.Epoch.d_DecEq'45'Epoch_58 + (coe + MAlonzo.Code.Ledger.Transaction.d_epochStructure_1520 + (coe v0)))) (coe - MAlonzo.Code.Ledger.Crypto.d_DecEq'45'ScriptHash_204 - (coe MAlonzo.Code.Ledger.Transaction.d_crypto_1234 (coe v0)))) - (coe MAlonzo.Code.Interface.IsSet.du_IsSet'45'Set_544) - (coe du_activeCC_2192 (coe v0) (coe v1) (coe v6)))) + MAlonzo.Code.Ledger.Address.du_DecEq'45'Credential_142 + (coe + MAlonzo.Code.Ledger.Crypto.d_DecEq'45'THash_22 + (coe + MAlonzo.Code.Ledger.Crypto.d_khs_200 + (coe MAlonzo.Code.Ledger.Transaction.d_crypto_1234 (coe v0)))) + (coe + MAlonzo.Code.Ledger.Crypto.d_DecEq'45'ScriptHash_204 + (coe MAlonzo.Code.Ledger.Transaction.d_crypto_1234 (coe v0))))) + (coe MAlonzo.Code.Interface.IsSet.du_IsSet'45'Map_548) + (coe + MAlonzo.Code.Axiom.Set.Map.du_mapFromPartialFun_1176 + (coe + MAlonzo.Code.Axiom.Set.d_th_1458 + (coe MAlonzo.Code.Ledger.Set.Theory.d_List'45'Model'7496'_10)) + (coe du_getCCHotCred_2172 (coe v0) (coe v1)) + (coe MAlonzo.Code.Axiom.Set.Map.du__'738'_534 (coe v6))))) (coe (\ v8 -> coe @@ -1812,7 +1815,7 @@ du_actualCCVotes_2196 v0 v1 v2 v3 v4 (coe MAlonzo.Code.Ledger.Set.Theory.d_List'45'Model'7496'_10)) _ -> MAlonzo.RTE.mazUnreachableError -- Ledger.Ratify._.actualPDRepVotes -d_actualPDRepVotes_2204 :: +d_actualPDRepVotes_2200 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.PParams.T_PParams_244 -> @@ -1821,13 +1824,13 @@ d_actualPDRepVotes_2204 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_actualPDRepVotes_2204 v0 ~v1 ~v2 ~v3 ~v4 ~v5 v6 - = du_actualPDRepVotes_2204 v0 v6 -du_actualPDRepVotes_2204 :: +d_actualPDRepVotes_2200 v0 ~v1 ~v2 ~v3 ~v4 ~v5 v6 + = du_actualPDRepVotes_2200 v0 v6 +du_actualPDRepVotes_2200 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_actualPDRepVotes_2204 v0 v1 +du_actualPDRepVotes_2200 v0 v1 = let v2 = coe MAlonzo.Code.Axiom.Set.Map.du__'8746''737'__884 @@ -1892,7 +1895,7 @@ du_actualPDRepVotes_2204 v0 v1 (coe MAlonzo.Code.Ledger.GovernanceActions.C_yes_730))) _ -> coe v2) -- Ledger.Ratify._.actualDRepVotes -d_actualDRepVotes_2206 :: +d_actualDRepVotes_2202 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.PParams.T_PParams_244 -> @@ -1900,14 +1903,14 @@ d_actualDRepVotes_2206 :: MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_actualDRepVotes_2206 v0 v1 ~v2 ~v3 ~v4 v5 - = du_actualDRepVotes_2206 v0 v1 v5 -du_actualDRepVotes_2206 :: +d_actualDRepVotes_2202 v0 v1 ~v2 ~v3 ~v4 v5 + = du_actualDRepVotes_2202 v0 v1 v5 +du_actualDRepVotes_2202 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_actualDRepVotes_2206 v0 v1 v2 +du_actualDRepVotes_2202 v0 v1 v2 = coe MAlonzo.Code.Axiom.Set.Map.du__'8746''737'__884 (coe @@ -1937,7 +1940,7 @@ du_actualDRepVotes_2206 v0 v1 v2 (coe du_activeDReps_2164 (coe v0) (coe v1))) (coe MAlonzo.Code.Ledger.GovernanceActions.C_no_732)) -- Ledger.Ratify._.actualSPOVotes -d_actualSPOVotes_2208 :: +d_actualSPOVotes_2204 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.PParams.T_PParams_244 -> @@ -1946,15 +1949,15 @@ d_actualSPOVotes_2208 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_actualSPOVotes_2208 v0 v1 ~v2 ~v3 ~v4 v5 v6 - = du_actualSPOVotes_2208 v0 v1 v5 v6 -du_actualSPOVotes_2208 :: +d_actualSPOVotes_2204 v0 v1 ~v2 ~v3 ~v4 v5 v6 + = du_actualSPOVotes_2204 v0 v1 v5 v6 +du_actualSPOVotes_2204 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_actualSPOVotes_2208 v0 v1 v2 v3 +du_actualSPOVotes_2204 v0 v1 v2 v3 = let v4 = coe MAlonzo.Code.Axiom.Set.Map.du__'8746''737'__884 @@ -2003,29 +2006,29 @@ du_actualSPOVotes_2208 v0 v1 v2 v3 (coe MAlonzo.Code.Ledger.GovernanceActions.C_no_732)) _ -> coe v4) -- Ledger.Ratify._/₀_ -d__'47''8320'__2210 :: +d__'47''8320'__2206 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> Integer -> Integer -> MAlonzo.Code.Data.Rational.Base.T_ℚ_6 -d__'47''8320'__2210 ~v0 v1 v2 = du__'47''8320'__2210 v1 v2 -du__'47''8320'__2210 :: +d__'47''8320'__2206 ~v0 v1 v2 = du__'47''8320'__2206 v1 v2 +du__'47''8320'__2206 :: Integer -> Integer -> MAlonzo.Code.Data.Rational.Base.T_ℚ_6 -du__'47''8320'__2210 v0 v1 +du__'47''8320'__2206 v0 v1 = case coe v1 of 0 -> coe MAlonzo.Code.Data.Rational.Base.d_0ℚ_178 _ -> coe MAlonzo.Code.Data.Rational.Base.du__'47'__156 (coe v0) (coe v1) -- Ledger.Ratify.getStakeDist -d_getStakeDist_2218 :: +d_getStakeDist_2214 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovRole_664 -> [MAlonzo.Code.Ledger.GovernanceActions.T_VDeleg_676] -> T_StakeDistrs_1884 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_getStakeDist_2218 ~v0 v1 v2 v3 = du_getStakeDist_2218 v1 v2 v3 -du_getStakeDist_2218 :: +d_getStakeDist_2214 ~v0 v1 v2 v3 = du_getStakeDist_2214 v1 v2 v3 +du_getStakeDist_2214 :: MAlonzo.Code.Ledger.GovernanceActions.T_GovRole_664 -> [MAlonzo.Code.Ledger.GovernanceActions.T_VDeleg_676] -> T_StakeDistrs_1884 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_getStakeDist_2218 v0 v1 v2 +du_getStakeDist_2214 v0 v1 v2 = case coe v0 of MAlonzo.Code.Ledger.GovernanceActions.C_CC_666 -> coe @@ -2071,43 +2074,43 @@ du_getStakeDist_2218 v0 v1 v2 (d_stakeDistr_1888 (coe v2)) _ -> MAlonzo.RTE.mazUnreachableError -- Ledger.Ratify.acceptedStakeRatio -d_acceptedStakeRatio_2228 :: +d_acceptedStakeRatio_2224 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovRole_664 -> [MAlonzo.Code.Ledger.GovernanceActions.T_VDeleg_676] -> T_StakeDistrs_1884 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Data.Rational.Base.T_ℚ_6 -d_acceptedStakeRatio_2228 v0 v1 v2 v3 v4 +d_acceptedStakeRatio_2224 v0 v1 v2 v3 v4 = coe - du__'47''8320'__2210 + du__'47''8320'__2206 (coe - d_acceptedStake_2244 (coe v0) (coe v1) (coe v2) (coe v3) (coe v4)) + d_acceptedStake_2240 (coe v0) (coe v1) (coe v2) (coe v3) (coe v4)) (coe - d_totalStake_2246 (coe v0) (coe v1) (coe v2) (coe v3) (coe v4)) + d_totalStake_2242 (coe v0) (coe v1) (coe v2) (coe v3) (coe v4)) -- Ledger.Ratify._.dist -d_dist_2242 :: +d_dist_2238 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovRole_664 -> [MAlonzo.Code.Ledger.GovernanceActions.T_VDeleg_676] -> T_StakeDistrs_1884 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_dist_2242 ~v0 v1 v2 v3 ~v4 = du_dist_2242 v1 v2 v3 -du_dist_2242 :: +d_dist_2238 ~v0 v1 v2 v3 ~v4 = du_dist_2238 v1 v2 v3 +du_dist_2238 :: MAlonzo.Code.Ledger.GovernanceActions.T_GovRole_664 -> [MAlonzo.Code.Ledger.GovernanceActions.T_VDeleg_676] -> T_StakeDistrs_1884 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_dist_2242 v0 v1 v2 - = coe du_getStakeDist_2218 (coe v0) (coe v1) (coe v2) +du_dist_2238 v0 v1 v2 + = coe du_getStakeDist_2214 (coe v0) (coe v1) (coe v2) -- Ledger.Ratify._.acceptedStake -d_acceptedStake_2244 :: +d_acceptedStake_2240 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovRole_664 -> [MAlonzo.Code.Ledger.GovernanceActions.T_VDeleg_676] -> T_StakeDistrs_1884 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> Integer -d_acceptedStake_2244 v0 v1 v2 v3 v4 +d_acceptedStake_2240 v0 v1 v2 v3 v4 = coe MAlonzo.Code.Ledger.Set.Theory.du_indexedSum'7515'''_1160 (coe @@ -2132,7 +2135,7 @@ d_acceptedStake_2244 v0 v1 v2 v3 v4 (MAlonzo.Code.Ledger.GovernanceActions.d_DecEq'45'VDeleg_806 (coe MAlonzo.Code.Ledger.Transaction.d_govStructure_2350 (coe v0)))) - (coe du_dist_2242 (coe v1) (coe v2) (coe v3)) + (coe du_dist_2238 (coe v1) (coe v2) (coe v3)) (coe MAlonzo.Code.Axiom.Set.Map.du__'8315''185'__1602 (coe @@ -2144,13 +2147,13 @@ d_acceptedStake_2244 v0 v1 v2 v3 v4 (coe MAlonzo.Code.Ledger.GovernanceActions.du_DecEq'45'Vote_804)) (coe v4) (coe MAlonzo.Code.Ledger.GovernanceActions.C_yes_730))) -- Ledger.Ratify._.totalStake -d_totalStake_2246 :: +d_totalStake_2242 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovRole_664 -> [MAlonzo.Code.Ledger.GovernanceActions.T_VDeleg_676] -> T_StakeDistrs_1884 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> Integer -d_totalStake_2246 v0 v1 v2 v3 v4 +d_totalStake_2242 v0 v1 v2 v3 v4 = coe MAlonzo.Code.Ledger.Set.Theory.du_indexedSum'7515'''_1160 (coe @@ -2175,7 +2178,7 @@ d_totalStake_2246 v0 v1 v2 v3 v4 (MAlonzo.Code.Ledger.GovernanceActions.d_DecEq'45'VDeleg_806 (coe MAlonzo.Code.Ledger.Transaction.d_govStructure_2350 (coe v0)))) - (coe du_dist_2242 (coe v1) (coe v2) (coe v3)) + (coe du_dist_2238 (coe v1) (coe v2) (coe v3)) (coe MAlonzo.Code.Interface.IsSet.du_dom_540 (coe @@ -2208,40 +2211,40 @@ d_totalStake_2246 v0 v1 v2 v3 v4 (coe MAlonzo.Code.Ledger.Set.Theory.d_List'45'Model'7496'_10)) erased (coe MAlonzo.Code.Ledger.GovernanceActions.C_no_732)))))) -- Ledger.Ratify.acceptedBy -d_acceptedBy_2252 :: +d_acceptedBy_2248 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovRole_664 -> () -d_acceptedBy_2252 = erased +d_acceptedBy_2248 = erased -- Ledger.Ratify.accepted -d_accepted_2346 :: +d_accepted_2342 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> () -d_accepted_2346 = erased +d_accepted_2342 = erased -- Ledger.Ratify.expired -d_expired_2354 :: +d_expired_2350 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> AgdaAny -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> () -d_expired_2354 = erased +d_expired_2350 = erased -- Ledger.Ratify.verifyPrev -d_verifyPrev_2362 :: +d_verifyPrev_2358 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> AgdaAny -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> () -d_verifyPrev_2362 = erased +d_verifyPrev_2358 = erased -- Ledger.Ratify.delayingAction -d_delayingAction_2384 :: +d_delayingAction_2380 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> Bool -d_delayingAction_2384 ~v0 v1 = du_delayingAction_2384 v1 -du_delayingAction_2384 :: +d_delayingAction_2380 ~v0 v1 = du_delayingAction_2380 v1 +du_delayingAction_2380 :: MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> Bool -du_delayingAction_2384 v0 +du_delayingAction_2380 v0 = case coe v0 of MAlonzo.Code.Ledger.GovernanceActions.C_NoConfidence_696 -> coe MAlonzo.Code.Agda.Builtin.Bool.C_true_10 @@ -2259,19 +2262,19 @@ du_delayingAction_2384 v0 -> coe MAlonzo.Code.Agda.Builtin.Bool.C_false_8 _ -> MAlonzo.RTE.mazUnreachableError -- Ledger.Ratify.delayed -d_delayed_2388 :: +d_delayed_2384 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> AgdaAny -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> Bool -> () -d_delayed_2388 = erased +d_delayed_2384 = erased -- Ledger.Ratify.acceptConds -d_acceptConds_2398 :: +d_acceptConds_2394 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> T_RatifyState_1912 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> () -d_acceptConds_2398 = erased +d_acceptConds_2394 = erased -- Ledger.Ratify._.ccHotKeys -d_ccHotKeys_2414 :: +d_ccHotKeys_2410 :: T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> @@ -2279,12 +2282,12 @@ d_ccHotKeys_2414 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_ccHotKeys_2414 v0 ~v1 ~v2 ~v3 ~v4 ~v5 = du_ccHotKeys_2414 v0 -du_ccHotKeys_2414 :: +d_ccHotKeys_2410 v0 ~v1 ~v2 ~v3 ~v4 ~v5 = du_ccHotKeys_2410 v0 +du_ccHotKeys_2410 :: T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_ccHotKeys_2414 v0 = coe d_ccHotKeys_1908 (coe v0) +du_ccHotKeys_2410 v0 = coe d_ccHotKeys_1908 (coe v0) -- Ledger.Ratify._.currentEpoch -d_currentEpoch_2416 :: +d_currentEpoch_2412 :: T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> @@ -2292,12 +2295,12 @@ d_currentEpoch_2416 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> AgdaAny -d_currentEpoch_2416 v0 ~v1 ~v2 ~v3 ~v4 ~v5 - = du_currentEpoch_2416 v0 -du_currentEpoch_2416 :: T_RatifyEnv_1890 -> AgdaAny -du_currentEpoch_2416 v0 = coe d_currentEpoch_1904 (coe v0) +d_currentEpoch_2412 v0 ~v1 ~v2 ~v3 ~v4 ~v5 + = du_currentEpoch_2412 v0 +du_currentEpoch_2412 :: T_RatifyEnv_1890 -> AgdaAny +du_currentEpoch_2412 v0 = coe d_currentEpoch_1904 (coe v0) -- Ledger.Ratify._.dreps -d_dreps_2418 :: +d_dreps_2414 :: T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> @@ -2305,12 +2308,12 @@ d_dreps_2418 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_dreps_2418 v0 ~v1 ~v2 ~v3 ~v4 ~v5 = du_dreps_2418 v0 -du_dreps_2418 :: +d_dreps_2414 v0 ~v1 ~v2 ~v3 ~v4 ~v5 = du_dreps_2414 v0 +du_dreps_2414 :: T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_dreps_2418 v0 = coe d_dreps_1906 (coe v0) +du_dreps_2414 v0 = coe d_dreps_1906 (coe v0) -- Ledger.Ratify._.stakeDistrs -d_stakeDistrs_2420 :: +d_stakeDistrs_2416 :: T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> @@ -2318,11 +2321,11 @@ d_stakeDistrs_2420 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> T_StakeDistrs_1884 -d_stakeDistrs_2420 v0 ~v1 ~v2 ~v3 ~v4 ~v5 = du_stakeDistrs_2420 v0 -du_stakeDistrs_2420 :: T_RatifyEnv_1890 -> T_StakeDistrs_1884 -du_stakeDistrs_2420 v0 = coe d_stakeDistrs_1902 (coe v0) +d_stakeDistrs_2416 v0 ~v1 ~v2 ~v3 ~v4 ~v5 = du_stakeDistrs_2416 v0 +du_stakeDistrs_2416 :: T_RatifyEnv_1890 -> T_StakeDistrs_1884 +du_stakeDistrs_2416 v0 = coe d_stakeDistrs_1902 (coe v0) -- Ledger.Ratify._.treasury -d_treasury_2422 :: +d_treasury_2418 :: T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> @@ -2330,17 +2333,17 @@ d_treasury_2422 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> Integer -d_treasury_2422 v0 ~v1 ~v2 ~v3 ~v4 ~v5 = du_treasury_2422 v0 -du_treasury_2422 :: T_RatifyEnv_1890 -> Integer -du_treasury_2422 v0 = coe d_treasury_1910 (coe v0) +d_treasury_2418 v0 ~v1 ~v2 ~v3 ~v4 ~v5 = du_treasury_2418 v0 +du_treasury_2418 :: T_RatifyEnv_1890 -> Integer +du_treasury_2418 v0 = coe d_treasury_1910 (coe v0) -- Ledger.Ratify.verifyPrev? -d_verifyPrev'63'_2444 :: +d_verifyPrev'63'_2440 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> AgdaAny -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> MAlonzo.Code.Relation.Nullary.Decidable.Core.T_Dec_20 -d_verifyPrev'63'_2444 v0 v1 v2 v3 +d_verifyPrev'63'_2440 v0 v1 v2 v3 = case coe v1 of MAlonzo.Code.Ledger.GovernanceActions.C_NoConfidence_696 -> coe @@ -2438,18 +2441,18 @@ d_verifyPrev'63'_2444 v0 v1 v2 v3 (coe MAlonzo.Code.Agda.Builtin.Unit.C_tt_8)) _ -> MAlonzo.RTE.mazUnreachableError -- Ledger.Ratify.delayed? -d_delayed'63'_2498 :: +d_delayed'63'_2494 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -> AgdaAny -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> Bool -> MAlonzo.Code.Relation.Nullary.Decidable.Core.T_Dec_20 -d_delayed'63'_2498 v0 v1 v2 v3 v4 +d_delayed'63'_2494 v0 v1 v2 v3 v4 = coe MAlonzo.Code.Relation.Nullary.Decidable.Core.du__'8846''45'dec__84 (coe MAlonzo.Code.Relation.Nullary.Decidable.Core.du__'8594''45'dec__94 - (coe d_verifyPrev'63'_2444 (coe v0) (coe v1) (coe v2) (coe v3)) + (coe d_verifyPrev'63'_2440 (coe v0) (coe v1) (coe v2) (coe v3)) (coe MAlonzo.Code.Relation.Nullary.Decidable.Core.C__because__32 (coe MAlonzo.Code.Agda.Builtin.Bool.C_false_8) @@ -2461,16 +2464,16 @@ d_delayed'63'_2498 v0 v1 v2 v3 v4 (coe MAlonzo.Code.Data.Bool.Properties.d__'8799'__2950) (coe v4) (coe MAlonzo.Code.Agda.Builtin.Bool.C_true_10))) -- Ledger.Ratify.Is-nothing? -d_Is'45'nothing'63'_2514 :: +d_Is'45'nothing'63'_2510 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> () -> Maybe AgdaAny -> MAlonzo.Code.Relation.Nullary.Decidable.Core.T_Dec_20 -d_Is'45'nothing'63'_2514 ~v0 ~v1 v2 = du_Is'45'nothing'63'_2514 v2 -du_Is'45'nothing'63'_2514 :: +d_Is'45'nothing'63'_2510 ~v0 ~v1 v2 = du_Is'45'nothing'63'_2510 v2 +du_Is'45'nothing'63'_2510 :: Maybe AgdaAny -> MAlonzo.Code.Relation.Nullary.Decidable.Core.T_Dec_20 -du_Is'45'nothing'63'_2514 v0 +du_Is'45'nothing'63'_2510 v0 = coe MAlonzo.Code.Data.Maybe.Relation.Unary.All.du_dec_254 (let v1 @@ -2481,14 +2484,14 @@ du_Is'45'nothing'63'_2514 v0 coe (coe (\ v2 -> v1))) (coe v0) -- Ledger.Ratify.acceptedBy? -d_acceptedBy'63'_2530 :: +d_acceptedBy'63'_2526 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovRole_664 -> MAlonzo.Code.Relation.Nullary.Decidable.Core.T_Dec_20 -d_acceptedBy'63'_2530 v0 v1 v2 v3 v4 +d_acceptedBy'63'_2526 v0 v1 v2 v3 v4 = coe MAlonzo.Code.Relation.Nullary.Decidable.Core.du__'215''45'dec__74 (coe @@ -2509,7 +2512,7 @@ d_acceptedBy'63'_2530 v0 v1 v2 v3 v4 (coe MAlonzo.Code.Ledger.Enact.d_cc_842 (coe v2)))) (MAlonzo.Code.Ledger.GovernanceActions.d_action_798 (coe v3)) v4)) (coe - d_acceptedStakeRatio_2228 (coe v0) (coe v4) + d_acceptedStakeRatio_2224 (coe v0) (coe v4) (coe MAlonzo.Code.Interface.IsSet.du_dom_540 (coe @@ -2581,7 +2584,7 @@ d_acceptedBy'63'_2530 v0 v1 v2 v3 v4 MAlonzo.Code.Agda.Builtin.Sigma.d_fst_28 (coe MAlonzo.Code.Ledger.Enact.d_pparams_848 (coe v2))))) (coe - du_Is'45'nothing'63'_2514 + du_Is'45'nothing'63'_2510 (coe d_threshold_1756 v0 (MAlonzo.Code.Agda.Builtin.Sigma.d_fst_28 @@ -2596,33 +2599,33 @@ d_acceptedBy'63'_2530 v0 v1 v2 v3 v4 (MAlonzo.Code.Ledger.GovernanceActions.d_action_798 (coe v3)) v4)))) -- Ledger.Ratify.accepted? -d_accepted'63'_2542 :: +d_accepted'63'_2538 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> MAlonzo.Code.Relation.Nullary.Decidable.Core.T_Dec_20 -d_accepted'63'_2542 v0 v1 v2 v3 +d_accepted'63'_2538 v0 v1 v2 v3 = coe MAlonzo.Code.Relation.Nullary.Decidable.Core.du__'215''45'dec__74 (coe - d_acceptedBy'63'_2530 (coe v0) (coe v1) (coe v2) (coe v3) + d_acceptedBy'63'_2526 (coe v0) (coe v1) (coe v2) (coe v3) (coe MAlonzo.Code.Ledger.GovernanceActions.C_CC_666)) (coe MAlonzo.Code.Relation.Nullary.Decidable.Core.du__'215''45'dec__74 (coe - d_acceptedBy'63'_2530 (coe v0) (coe v1) (coe v2) (coe v3) + d_acceptedBy'63'_2526 (coe v0) (coe v1) (coe v2) (coe v3) (coe MAlonzo.Code.Ledger.GovernanceActions.C_DRep_668)) (coe - d_acceptedBy'63'_2530 (coe v0) (coe v1) (coe v2) (coe v3) + d_acceptedBy'63'_2526 (coe v0) (coe v1) (coe v2) (coe v3) (coe MAlonzo.Code.Ledger.GovernanceActions.C_SPO_670))) -- Ledger.Ratify.expired? -d_expired'63'_2558 :: +d_expired'63'_2554 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> AgdaAny -> MAlonzo.Code.Ledger.GovernanceActions.T_GovActionState_780 -> MAlonzo.Code.Relation.Nullary.Decidable.Core.T_Dec_20 -d_expired'63'_2558 v0 v1 v2 +d_expired'63'_2554 v0 v1 v2 = coe MAlonzo.Code.Class.Decidable.Core.du_'191'_'191'_42 (coe @@ -2647,14 +2650,14 @@ d_expired'63'_2558 v0 v1 v2 (MAlonzo.Code.Ledger.GovernanceActions.d_expiresIn_796 (coe v2)) v1)) -- Ledger.Ratify._⊢_⇀⦇_,RATIFY'⦈_ -d__'8866'_'8640''10631'_'44'RATIFY'''10632'__2574 a0 a1 a2 a3 a4 +d__'8866'_'8640''10631'_'44'RATIFY'''10632'__2570 a0 a1 a2 a3 a4 = () -data T__'8866'_'8640''10631'_'44'RATIFY'''10632'__2574 - = C_RATIFY'45'Accept_2614 MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 | - C_RATIFY'45'Reject_2640 MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 | - C_RATIFY'45'Continue_2666 MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 +data T__'8866'_'8640''10631'_'44'RATIFY'''10632'__2570 + = C_RATIFY'45'Accept_2610 MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 | + C_RATIFY'45'Reject_2636 MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 | + C_RATIFY'45'Continue_2662 MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -- Ledger.Ratify._.ccHotKeys -d_ccHotKeys_2590 :: +d_ccHotKeys_2586 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2663,12 +2666,12 @@ d_ccHotKeys_2590 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_ccHotKeys_2590 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 = du_ccHotKeys_2590 v1 -du_ccHotKeys_2590 :: +d_ccHotKeys_2586 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 = du_ccHotKeys_2586 v1 +du_ccHotKeys_2586 :: T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_ccHotKeys_2590 v0 = coe d_ccHotKeys_1908 (coe v0) +du_ccHotKeys_2586 v0 = coe d_ccHotKeys_1908 (coe v0) -- Ledger.Ratify._.currentEpoch -d_currentEpoch_2592 :: +d_currentEpoch_2588 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2676,12 +2679,12 @@ d_currentEpoch_2592 :: Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> AgdaAny -d_currentEpoch_2592 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 - = du_currentEpoch_2592 v1 -du_currentEpoch_2592 :: T_RatifyEnv_1890 -> AgdaAny -du_currentEpoch_2592 v0 = coe d_currentEpoch_1904 (coe v0) +d_currentEpoch_2588 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 + = du_currentEpoch_2588 v1 +du_currentEpoch_2588 :: T_RatifyEnv_1890 -> AgdaAny +du_currentEpoch_2588 v0 = coe d_currentEpoch_1904 (coe v0) -- Ledger.Ratify._.dreps -d_dreps_2594 :: +d_dreps_2590 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2690,12 +2693,12 @@ d_dreps_2594 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_dreps_2594 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 = du_dreps_2594 v1 -du_dreps_2594 :: +d_dreps_2590 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 = du_dreps_2590 v1 +du_dreps_2590 :: T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_dreps_2594 v0 = coe d_dreps_1906 (coe v0) +du_dreps_2590 v0 = coe d_dreps_1906 (coe v0) -- Ledger.Ratify._.stakeDistrs -d_stakeDistrs_2596 :: +d_stakeDistrs_2592 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2703,12 +2706,12 @@ d_stakeDistrs_2596 :: Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> T_StakeDistrs_1884 -d_stakeDistrs_2596 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 - = du_stakeDistrs_2596 v1 -du_stakeDistrs_2596 :: T_RatifyEnv_1890 -> T_StakeDistrs_1884 -du_stakeDistrs_2596 v0 = coe d_stakeDistrs_1902 (coe v0) +d_stakeDistrs_2592 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 + = du_stakeDistrs_2592 v1 +du_stakeDistrs_2592 :: T_RatifyEnv_1890 -> T_StakeDistrs_1884 +du_stakeDistrs_2592 v0 = coe d_stakeDistrs_1902 (coe v0) -- Ledger.Ratify._.treasury -d_treasury_2598 :: +d_treasury_2594 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2716,11 +2719,11 @@ d_treasury_2598 :: Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> Integer -d_treasury_2598 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 = du_treasury_2598 v1 -du_treasury_2598 :: T_RatifyEnv_1890 -> Integer -du_treasury_2598 v0 = coe d_treasury_1910 (coe v0) +d_treasury_2594 ~v0 v1 ~v2 ~v3 ~v4 ~v5 ~v6 = du_treasury_2594 v1 +du_treasury_2594 :: T_RatifyEnv_1890 -> Integer +du_treasury_2594 v0 = coe d_treasury_1910 (coe v0) -- Ledger.Ratify._.action -d_action_2604 :: +d_action_2600 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2729,16 +2732,16 @@ d_action_2604 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -d_action_2604 ~v0 ~v1 ~v2 ~v3 ~v4 v5 ~v6 = du_action_2604 v5 -du_action_2604 :: +d_action_2600 ~v0 ~v1 ~v2 ~v3 ~v4 v5 ~v6 = du_action_2600 v5 +du_action_2600 :: MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.GovernanceActions.T_GovAction_694 -du_action_2604 v0 +du_action_2600 v0 = coe MAlonzo.Code.Ledger.GovernanceActions.d_action_798 (coe MAlonzo.Code.Agda.Builtin.Sigma.d_snd_30 (coe v0)) -- Ledger.Ratify._.ccHotKeys -d_ccHotKeys_2628 :: +d_ccHotKeys_2624 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2746,23 +2749,23 @@ d_ccHotKeys_2628 :: Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_ccHotKeys_2628 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_ccHotKeys_2628 v1 -du_ccHotKeys_2628 :: +d_ccHotKeys_2624 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_ccHotKeys_2624 v1 +du_ccHotKeys_2624 :: T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_ccHotKeys_2628 v0 = coe d_ccHotKeys_1908 (coe v0) +du_ccHotKeys_2624 v0 = coe d_ccHotKeys_1908 (coe v0) -- Ledger.Ratify._.currentEpoch -d_currentEpoch_2630 :: +d_currentEpoch_2626 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> AgdaAny -d_currentEpoch_2630 ~v0 v1 ~v2 ~v3 ~v4 ~v5 - = du_currentEpoch_2630 v1 -du_currentEpoch_2630 :: T_RatifyEnv_1890 -> AgdaAny -du_currentEpoch_2630 v0 = coe d_currentEpoch_1904 (coe v0) +d_currentEpoch_2626 ~v0 v1 ~v2 ~v3 ~v4 ~v5 + = du_currentEpoch_2626 v1 +du_currentEpoch_2626 :: T_RatifyEnv_1890 -> AgdaAny +du_currentEpoch_2626 v0 = coe d_currentEpoch_1904 (coe v0) -- Ledger.Ratify._.dreps -d_dreps_2632 :: +d_dreps_2628 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2770,33 +2773,33 @@ d_dreps_2632 :: Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_dreps_2632 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_dreps_2632 v1 -du_dreps_2632 :: +d_dreps_2628 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_dreps_2628 v1 +du_dreps_2628 :: T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_dreps_2632 v0 = coe d_dreps_1906 (coe v0) +du_dreps_2628 v0 = coe d_dreps_1906 (coe v0) -- Ledger.Ratify._.stakeDistrs -d_stakeDistrs_2634 :: +d_stakeDistrs_2630 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> T_StakeDistrs_1884 -d_stakeDistrs_2634 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_stakeDistrs_2634 v1 -du_stakeDistrs_2634 :: T_RatifyEnv_1890 -> T_StakeDistrs_1884 -du_stakeDistrs_2634 v0 = coe d_stakeDistrs_1902 (coe v0) +d_stakeDistrs_2630 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_stakeDistrs_2630 v1 +du_stakeDistrs_2630 :: T_RatifyEnv_1890 -> T_StakeDistrs_1884 +du_stakeDistrs_2630 v0 = coe d_stakeDistrs_1902 (coe v0) -- Ledger.Ratify._.treasury -d_treasury_2636 :: +d_treasury_2632 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> Integer -d_treasury_2636 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_treasury_2636 v1 -du_treasury_2636 :: T_RatifyEnv_1890 -> Integer -du_treasury_2636 v0 = coe d_treasury_1910 (coe v0) +d_treasury_2632 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_treasury_2632 v1 +du_treasury_2632 :: T_RatifyEnv_1890 -> Integer +du_treasury_2632 v0 = coe d_treasury_1910 (coe v0) -- Ledger.Ratify._.ccHotKeys -d_ccHotKeys_2654 :: +d_ccHotKeys_2650 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2804,23 +2807,23 @@ d_ccHotKeys_2654 :: Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_ccHotKeys_2654 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_ccHotKeys_2654 v1 -du_ccHotKeys_2654 :: +d_ccHotKeys_2650 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_ccHotKeys_2650 v1 +du_ccHotKeys_2650 :: T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_ccHotKeys_2654 v0 = coe d_ccHotKeys_1908 (coe v0) +du_ccHotKeys_2650 v0 = coe d_ccHotKeys_1908 (coe v0) -- Ledger.Ratify._.currentEpoch -d_currentEpoch_2656 :: +d_currentEpoch_2652 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> AgdaAny -d_currentEpoch_2656 ~v0 v1 ~v2 ~v3 ~v4 ~v5 - = du_currentEpoch_2656 v1 -du_currentEpoch_2656 :: T_RatifyEnv_1890 -> AgdaAny -du_currentEpoch_2656 v0 = coe d_currentEpoch_1904 (coe v0) +d_currentEpoch_2652 ~v0 v1 ~v2 ~v3 ~v4 ~v5 + = du_currentEpoch_2652 v1 +du_currentEpoch_2652 :: T_RatifyEnv_1890 -> AgdaAny +du_currentEpoch_2652 v0 = coe d_currentEpoch_1904 (coe v0) -- Ledger.Ratify._.dreps -d_dreps_2658 :: +d_dreps_2654 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> @@ -2828,36 +2831,36 @@ d_dreps_2658 :: Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -d_dreps_2658 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_dreps_2658 v1 -du_dreps_2658 :: +d_dreps_2654 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_dreps_2654 v1 +du_dreps_2654 :: T_RatifyEnv_1890 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -du_dreps_2658 v0 = coe d_dreps_1906 (coe v0) +du_dreps_2654 v0 = coe d_dreps_1906 (coe v0) -- Ledger.Ratify._.stakeDistrs -d_stakeDistrs_2660 :: +d_stakeDistrs_2656 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> T_StakeDistrs_1884 -d_stakeDistrs_2660 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_stakeDistrs_2660 v1 -du_stakeDistrs_2660 :: T_RatifyEnv_1890 -> T_StakeDistrs_1884 -du_stakeDistrs_2660 v0 = coe d_stakeDistrs_1902 (coe v0) +d_stakeDistrs_2656 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_stakeDistrs_2656 v1 +du_stakeDistrs_2656 :: T_RatifyEnv_1890 -> T_StakeDistrs_1884 +du_stakeDistrs_2656 v0 = coe d_stakeDistrs_1902 (coe v0) -- Ledger.Ratify._.treasury -d_treasury_2662 :: +d_treasury_2658 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> MAlonzo.Code.Ledger.Enact.T_EnactState_830 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> Bool -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> Integer -d_treasury_2662 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_treasury_2662 v1 -du_treasury_2662 :: T_RatifyEnv_1890 -> Integer -du_treasury_2662 v0 = coe d_treasury_1910 (coe v0) +d_treasury_2658 ~v0 v1 ~v2 ~v3 ~v4 ~v5 = du_treasury_2658 v1 +du_treasury_2658 :: T_RatifyEnv_1890 -> Integer +du_treasury_2658 v0 = coe d_treasury_1910 (coe v0) -- Ledger.Ratify._⊢_⇀⦇_,RATIFY⦈_ -d__'8866'_'8640''10631'_'44'RATIFY'10632'__2668 :: +d__'8866'_'8640''10631'_'44'RATIFY'10632'__2664 :: MAlonzo.Code.Ledger.Transaction.T_TransactionStructure_20 -> T_RatifyEnv_1890 -> T_RatifyState_1912 -> [MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14] -> T_RatifyState_1912 -> () -d__'8866'_'8640''10631'_'44'RATIFY'10632'__2668 = erased +d__'8866'_'8640''10631'_'44'RATIFY'10632'__2664 = erased diff --git a/generated/MAlonzo/Code/Ledger/Ratify/Properties.hs b/generated/MAlonzo/Code/Ledger/Ratify/Properties.hs index 8a78365b6..ad04a7728 100644 --- a/generated/MAlonzo/Code/Ledger/Ratify/Properties.hs +++ b/generated/MAlonzo/Code/Ledger/Ratify/Properties.hs @@ -68,7 +68,7 @@ du_exp'63'_1994 :: MAlonzo.Code.Relation.Nullary.Decidable.Core.T_Dec_20 du_exp'63'_1994 v0 v1 v2 = coe - MAlonzo.Code.Ledger.Ratify.d_expired'63'_2558 (coe v0) + MAlonzo.Code.Ledger.Ratify.d_expired'63'_2554 (coe v0) (coe MAlonzo.Code.Ledger.Ratify.d_currentEpoch_1904 (coe v1)) (coe MAlonzo.Code.Agda.Builtin.Sigma.d_snd_30 (coe v2)) -- Ledger.Ratify.Properties.Implementation.acceptConds? @@ -91,7 +91,7 @@ du_acceptConds'63'_2000 v0 v1 v2 v3 = coe MAlonzo.Code.Relation.Nullary.Decidable.Core.du__'215''45'dec__74 (coe - MAlonzo.Code.Ledger.Ratify.d_accepted'63'_2542 (coe v0) (coe v1) + MAlonzo.Code.Ledger.Ratify.d_accepted'63'_2538 (coe v0) (coe v1) (coe MAlonzo.Code.Ledger.Ratify.d_es_1920 (coe v2)) (coe MAlonzo.Code.Agda.Builtin.Sigma.d_snd_30 (coe v3))) (coe @@ -99,7 +99,7 @@ du_acceptConds'63'_2000 v0 v1 v2 v3 (coe MAlonzo.Code.Relation.Nullary.Decidable.Core.du__'8594''45'dec__94 (coe - MAlonzo.Code.Ledger.Ratify.d_delayed'63'_2498 (coe v0) + MAlonzo.Code.Ledger.Ratify.d_delayed'63'_2494 (coe v0) (coe MAlonzo.Code.Ledger.GovernanceActions.d_action_798 (coe MAlonzo.Code.Agda.Builtin.Sigma.d_snd_30 (coe v3))) @@ -140,7 +140,7 @@ d_RATIFY'''45'total_2004 v0 v1 v2 v3 du_acceptConds'63'_2000 (coe v0) (coe v1) (coe v2) (coe v3) in coe (let v5 - = MAlonzo.Code.Ledger.Ratify.d_expired'63'_2558 + = MAlonzo.Code.Ledger.Ratify.d_expired'63'_2554 (coe v0) (coe MAlonzo.Code.Ledger.Ratify.d_currentEpoch_1904 (coe v1)) (coe MAlonzo.Code.Agda.Builtin.Sigma.d_snd_30 (coe v3)) in @@ -179,14 +179,14 @@ d_RATIFY'''45'total_2004 v0 v1 v2 v3 MAlonzo.Code.Ledger.Ratify.d_removed_1922 (coe v2)))) (coe - MAlonzo.Code.Ledger.Ratify.du_delayingAction_2384 + MAlonzo.Code.Ledger.Ratify.du_delayingAction_2380 (coe MAlonzo.Code.Ledger.GovernanceActions.d_action_798 (coe MAlonzo.Code.Agda.Builtin.Sigma.d_snd_30 (coe v3))))) (coe - MAlonzo.Code.Ledger.Ratify.C_RATIFY'45'Accept_2614 + MAlonzo.Code.Ledger.Ratify.C_RATIFY'45'Accept_2610 (coe MAlonzo.Code.Agda.Builtin.Sigma.C__'44'__32 (coe v8) (coe v14))) @@ -229,7 +229,7 @@ d_RATIFY'''45'total_2004 v0 v1 v2 v3 MAlonzo.Code.Ledger.Ratify.d_delay_1924 (coe v2))) (coe - MAlonzo.Code.Ledger.Ratify.C_RATIFY'45'Reject_2640 + MAlonzo.Code.Ledger.Ratify.C_RATIFY'45'Reject_2636 (coe MAlonzo.Code.Agda.Builtin.Sigma.C__'44'__32 erased (coe v10))) @@ -240,7 +240,7 @@ d_RATIFY'''45'total_2004 v0 v1 v2 v3 MAlonzo.Code.Data.Product.Base.du_'45''44'__92 (coe v2) (coe - MAlonzo.Code.Ledger.Ratify.C_RATIFY'45'Continue_2666 + MAlonzo.Code.Ledger.Ratify.C_RATIFY'45'Continue_2662 (coe MAlonzo.Code.Agda.Builtin.Sigma.C__'44'__32 erased erased))) @@ -264,7 +264,7 @@ d_RATIFY'''45'completeness_2026 :: MAlonzo.Code.Ledger.Ratify.T_RatifyState_1912 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.Ratify.T_RatifyState_1912 -> - MAlonzo.Code.Ledger.Ratify.T__'8866'_'8640''10631'_'44'RATIFY'''10632'__2574 -> + MAlonzo.Code.Ledger.Ratify.T__'8866'_'8640''10631'_'44'RATIFY'''10632'__2570 -> MAlonzo.Code.Agda.Builtin.Equality.T__'8801'__12 d_RATIFY'''45'completeness_2026 = erased -- Ledger.Ratify.Properties.Implementation.completeness @@ -274,7 +274,7 @@ d_completeness_2084 :: MAlonzo.Code.Ledger.Ratify.T_RatifyState_1912 -> MAlonzo.Code.Agda.Builtin.Sigma.T_Σ_14 -> MAlonzo.Code.Ledger.Ratify.T_RatifyState_1912 -> - MAlonzo.Code.Ledger.Ratify.T__'8866'_'8640''10631'_'44'RATIFY'''10632'__2574 -> + MAlonzo.Code.Ledger.Ratify.T__'8866'_'8640''10631'_'44'RATIFY'''10632'__2570 -> MAlonzo.Code.Agda.Builtin.Equality.T__'8801'__12 d_completeness_2084 = erased -- Ledger.Ratify.Properties.Computational-RATIFY' diff --git a/generated/cardano-ledger-executable-spec.cabal b/generated/cardano-ledger-executable-spec.cabal index a2c8c1496..77eea2ff0 100644 --- a/generated/cardano-ledger-executable-spec.cabal +++ b/generated/cardano-ledger-executable-spec.cabal @@ -56,573 +56,573 @@ library -- This will be generated automatically when building with nix other-modules: MAlonzo.RTE - MAlonzo.Code.MetaPrelude - MAlonzo.Code.MyDebugOptions - MAlonzo.Code.Induction - MAlonzo.Code.Reflection.Utils.TCI - MAlonzo.Code.Reflection.Utils.Debug + MAlonzo.RTE.Float + MAlonzo.Code.Reflection.Debug MAlonzo.Code.Reflection.TCM + MAlonzo.Code.Reflection.Tactic MAlonzo.Code.Reflection.AST - MAlonzo.Code.Reflection.Debug - MAlonzo.Code.Reflection.TCI - MAlonzo.Code.Reflection.TCM.Syntax - MAlonzo.Code.Reflection.TCM.Format - MAlonzo.Code.Reflection.AST.Argument + MAlonzo.Code.Reflection.Syntax + MAlonzo.Code.Reflection.AST.Pattern + MAlonzo.Code.Reflection.AST.Argument.Modality + MAlonzo.Code.Reflection.AST.Argument.Information + MAlonzo.Code.Reflection.AST.Argument.QQuantity + MAlonzo.Code.Reflection.AST.Argument.Relevance + MAlonzo.Code.Reflection.AST.Argument.Visibility MAlonzo.Code.Reflection.AST.Term - MAlonzo.Code.Reflection.AST.Traversal + MAlonzo.Code.Reflection.AST.Argument MAlonzo.Code.Reflection.AST.Definition - MAlonzo.Code.Reflection.AST.Pattern MAlonzo.Code.Reflection.AST.Name + MAlonzo.Code.Reflection.AST.Traversal MAlonzo.Code.Reflection.AST.Show - MAlonzo.Code.Reflection.AST.Argument.Information - MAlonzo.Code.Reflection.AST.Argument.Visibility - MAlonzo.Code.Reflection.AST.Argument.Relevance - MAlonzo.Code.Reflection.AST.Argument.Modality - MAlonzo.Code.Reflection.AST.Argument.QQuantity MAlonzo.Code.Reflection.AST.Literal - MAlonzo.Code.Reflection.AST.DeBruijn MAlonzo.Code.Reflection.AST.Abstraction MAlonzo.Code.Reflection.AST.AlphaEquality MAlonzo.Code.Reflection.AST.Meta - MAlonzo.Code.Reflection.Syntax + MAlonzo.Code.Reflection.AST.DeBruijn + MAlonzo.Code.Reflection.TCI + MAlonzo.Code.Reflection.TCM.Syntax + MAlonzo.Code.Reflection.TCM.Format + MAlonzo.Code.Reflection.Utils.TCI + MAlonzo.Code.Reflection.Utils.Debug MAlonzo.Code.Reflection.Ext - MAlonzo.Code.Reflection.Tactic MAlonzo.Code.Reflection.Utils + MAlonzo.Code.MyDebugOptions + MAlonzo.Code.Induction.WellFounded + MAlonzo.Code.Induction.Lexicographic MAlonzo.Code.Text.Printf - MAlonzo.Code.Text.Format MAlonzo.Code.Text.Format.Generic MAlonzo.Code.Text.Printf.Generic - MAlonzo.Code.IO.Primitive - MAlonzo.Code.Agda.Builtin.String.Properties - MAlonzo.Code.Agda.Builtin.FromNat - MAlonzo.Code.Agda.Builtin.Int - MAlonzo.Code.Agda.Builtin.List - MAlonzo.Code.Agda.Builtin.String - MAlonzo.Code.Agda.Builtin.Bool - MAlonzo.Code.Agda.Builtin.Maybe - MAlonzo.Code.Agda.Builtin.Float - MAlonzo.Code.Agda.Builtin.Char - MAlonzo.Code.Agda.Builtin.Word.Properties - MAlonzo.Code.Agda.Builtin.Sigma - MAlonzo.Code.Agda.Builtin.Reflection - MAlonzo.Code.Agda.Builtin.Reflection.Properties - MAlonzo.Code.Agda.Builtin.Float.Properties - MAlonzo.Code.Agda.Builtin.Equality - MAlonzo.Code.Agda.Builtin.Word - MAlonzo.Code.Agda.Builtin.Strict - MAlonzo.Code.Agda.Builtin.IO - MAlonzo.Code.Agda.Builtin.Unit - MAlonzo.Code.Agda.Builtin.Nat - MAlonzo.Code.Agda.Builtin.Char.Properties - MAlonzo.Code.Agda.Primitive - MAlonzo.Code.Class.MonadError.Instances - MAlonzo.Code.Class.Applicative - MAlonzo.Code.Class.Bifunctor - MAlonzo.Code.Class.Foldable.Core + MAlonzo.Code.Text.Format + MAlonzo.Code.Axiom.Extensionality.Propositional + MAlonzo.Code.Axiom.Set + MAlonzo.Code.Axiom.UniquenessOfIdentityProofs + MAlonzo.Code.Axiom.Set.Properties + MAlonzo.Code.Axiom.Set.Map + MAlonzo.Code.Axiom.Set.List + MAlonzo.Code.Axiom.Set.TotalMapOn + MAlonzo.Code.Axiom.Set.Sum + MAlonzo.Code.Axiom.Set.Map.Dec + MAlonzo.Code.Axiom.Set.Rel + MAlonzo.Code.Axiom.Set.TotalMap + MAlonzo.Code.Axiom.Set.Factor + MAlonzo.Code.Class.Show + MAlonzo.Code.Class.Core + MAlonzo.Code.Class.DecEq.Core + MAlonzo.Code.Class.DecEq.Instances + MAlonzo.Code.Class.Monoid MAlonzo.Code.Class.Foldable.Instances - MAlonzo.Code.Class.Applicative.Instances - MAlonzo.Code.Class.Applicative.Core + MAlonzo.Code.Class.Foldable.Core + MAlonzo.Code.Class.Semigroup + MAlonzo.Code.Class.MonadReader.Instances + MAlonzo.Code.Class.Foldable + MAlonzo.Code.Class.Monoid.Instances + MAlonzo.Code.Class.Monoid.Core + MAlonzo.Code.Class.MonadError.Instances MAlonzo.Code.Class.DecEq + MAlonzo.Code.Class.MonadReader + MAlonzo.Code.Class.Monad.Instances + MAlonzo.Code.Class.Monad.Core MAlonzo.Code.Class.Traversable.Core MAlonzo.Code.Class.Traversable.Instances - MAlonzo.Code.Class.MonadTC - MAlonzo.Code.Class.Monad - MAlonzo.Code.Class.Decidable - MAlonzo.Code.Class.Foldable - MAlonzo.Code.Class.Functor + MAlonzo.Code.Class.MonadTC.Instances MAlonzo.Code.Class.Decidable.Instances MAlonzo.Code.Class.Decidable.Core - MAlonzo.Code.Class.Monoid.Core - MAlonzo.Code.Class.Monoid.Instances - MAlonzo.Code.Class.Show - MAlonzo.Code.Class.Monad.Core - MAlonzo.Code.Class.Monad.Instances - MAlonzo.Code.Class.Core - MAlonzo.Code.Class.Semigroup.Instances - MAlonzo.Code.Class.Semigroup.Core - MAlonzo.Code.Class.MonadError - MAlonzo.Code.Class.MonadTC.Instances - MAlonzo.Code.Class.Functor.Instances MAlonzo.Code.Class.Functor.Core - MAlonzo.Code.Class.MonadReader - MAlonzo.Code.Class.Semigroup - MAlonzo.Code.Class.Monoid - MAlonzo.Code.Class.Prelude + MAlonzo.Code.Class.Functor.Instances MAlonzo.Code.Class.Traversable - MAlonzo.Code.Class.MonadReader.Instances - MAlonzo.Code.Class.DecEq.Core - MAlonzo.Code.Class.DecEq.Instances - MAlonzo.Code.Class.Show.Core + MAlonzo.Code.Class.Semigroup.Instances + MAlonzo.Code.Class.Semigroup.Core MAlonzo.Code.Class.Show.Instances - MAlonzo.Code.Meta + MAlonzo.Code.Class.Show.Core + MAlonzo.Code.Class.Decidable + MAlonzo.Code.Class.Monad + MAlonzo.Code.Class.Prelude + MAlonzo.Code.Class.Applicative.Core + MAlonzo.Code.Class.Applicative.Instances + MAlonzo.Code.Class.Applicative + MAlonzo.Code.Class.Functor + MAlonzo.Code.Class.Bifunctor + MAlonzo.Code.Class.MonadError + MAlonzo.Code.Class.MonadTC MAlonzo.Code.Prelude - MAlonzo.Code.Axiom.Set - MAlonzo.Code.Axiom.Extensionality.Propositional - MAlonzo.Code.Axiom.UniquenessOfIdentityProofs - MAlonzo.Code.Axiom.Set.Sum - MAlonzo.Code.Axiom.Set.Factor - MAlonzo.Code.Axiom.Set.Map - MAlonzo.Code.Axiom.Set.List - MAlonzo.Code.Axiom.Set.Properties - MAlonzo.Code.Axiom.Set.TotalMap - MAlonzo.Code.Axiom.Set.TotalMapOn - MAlonzo.Code.Axiom.Set.Rel - MAlonzo.Code.Axiom.Set.Map.Dec + MAlonzo.Code.IO.Primitive + MAlonzo.Code.Agda.Builtin.Float + MAlonzo.Code.Agda.Builtin.Float.Properties + MAlonzo.Code.Agda.Builtin.Word.Properties + MAlonzo.Code.Agda.Builtin.Nat + MAlonzo.Code.Agda.Builtin.Sigma + MAlonzo.Code.Agda.Builtin.Unit + MAlonzo.Code.Agda.Builtin.Strict + MAlonzo.Code.Agda.Builtin.Reflection + MAlonzo.Code.Agda.Builtin.Word + MAlonzo.Code.Agda.Builtin.Maybe + MAlonzo.Code.Agda.Builtin.Char.Properties + MAlonzo.Code.Agda.Builtin.Reflection.Properties + MAlonzo.Code.Agda.Builtin.Char + MAlonzo.Code.Agda.Builtin.String + MAlonzo.Code.Agda.Builtin.Int + MAlonzo.Code.Agda.Builtin.Bool + MAlonzo.Code.Agda.Builtin.String.Properties + MAlonzo.Code.Agda.Builtin.List + MAlonzo.Code.Agda.Builtin.FromNat + MAlonzo.Code.Agda.Builtin.Equality + MAlonzo.Code.Agda.Builtin.IO + MAlonzo.Code.Agda.Primitive + MAlonzo.Code.Meta + MAlonzo.Code.Interface.HasSubtract.Instance + MAlonzo.Code.Interface.HasEmptySet + MAlonzo.Code.Interface.IsSet + MAlonzo.Code.Interface.STS + MAlonzo.Code.Interface.HasSingleton + MAlonzo.Code.Interface.HasAdd + MAlonzo.Code.Interface.HasEmptySet.Instances + MAlonzo.Code.Interface.Hashable + MAlonzo.Code.Interface.HasOrder.Instance + MAlonzo.Code.Interface.ToBool + MAlonzo.Code.Interface.HasSubtract + MAlonzo.Code.Interface.HasOrder + MAlonzo.Code.Interface.ComputationalRelation + MAlonzo.Code.Interface.HasAdd.Instance + MAlonzo.Code.Interface.IsCommutativeMonoid MAlonzo.Code.Algebra - MAlonzo.Code.Reflection - MAlonzo.Code.PreludeMeta - MAlonzo.Code.Induction.WellFounded - MAlonzo.Code.Induction.Lexicographic - MAlonzo.Code.Tactic.Premises - MAlonzo.Code.Tactic.Constrs - MAlonzo.Code.Tactic.Defaults - MAlonzo.Code.Tactic.ByEq - MAlonzo.Code.Tactic.MonoidSolver.NonNormalising - MAlonzo.Code.Tactic.AnyOf - MAlonzo.Code.Tactic.ClauseBuilder MAlonzo.Code.Tactic.MonoidSolver - MAlonzo.Code.Tactic.ReduceDec + MAlonzo.Code.Tactic.Assumption + MAlonzo.Code.Tactic.MonoidSolver.NonNormalising + MAlonzo.Code.Tactic.ByEq + MAlonzo.Code.Tactic.GenError MAlonzo.Code.Tactic.Derive.DecEq - MAlonzo.Code.Tactic.Derive.Show MAlonzo.Code.Tactic.Derive.TestTypes - MAlonzo.Code.Tactic.Cong - MAlonzo.Code.Tactic.GenError + MAlonzo.Code.Tactic.Derive.Show + MAlonzo.Code.Tactic.Inline + MAlonzo.Code.Tactic.Premises MAlonzo.Code.Tactic.Derive + MAlonzo.Code.Tactic.Defaults + MAlonzo.Code.Tactic.Cong + MAlonzo.Code.Tactic.ClauseBuilder + MAlonzo.Code.Tactic.Constrs MAlonzo.Code.Tactic.EquationalReasoning - MAlonzo.Code.Tactic.Inline - MAlonzo.Code.Tactic.Assumption - MAlonzo.Code.Function.Consequences - MAlonzo.Code.Function.Definitions - MAlonzo.Code.Function.Identity.Effectful - MAlonzo.Code.Function.Core - MAlonzo.Code.Function.Construct.Composition - MAlonzo.Code.Function.Construct.Symmetry - MAlonzo.Code.Function.Construct.Identity - MAlonzo.Code.Function.Related.TypeIsomorphisms - MAlonzo.Code.Function.Related.Propositional - MAlonzo.Code.Function.Properties.Inverse.HalfAdjointEquivalence - MAlonzo.Code.Function.Properties.RightInverse - MAlonzo.Code.Function.Properties.Bijection - MAlonzo.Code.Function.Properties.Surjection - MAlonzo.Code.Function.Properties.Inverse - MAlonzo.Code.Function.Strict - MAlonzo.Code.Function.Dependent.Bundles - MAlonzo.Code.Function.Structures - MAlonzo.Code.Function.Metric.Bundles - MAlonzo.Code.Function.Metric.Nat.Bundles - MAlonzo.Code.Function.Metric.Nat.Core - MAlonzo.Code.Function.Metric.Nat.Definitions - MAlonzo.Code.Function.Metric.Nat.Structures - MAlonzo.Code.Function.Metric.Definitions - MAlonzo.Code.Function.Metric.Structures - MAlonzo.Code.Function.Metric.Core - MAlonzo.Code.Function.Metric.Nat - MAlonzo.Code.Function.Bundles - MAlonzo.Code.Function.Consequences.Setoid - MAlonzo.Code.Function.Consequences.Propositional - MAlonzo.Code.Function.Indexed.Relation.Binary.Equality - MAlonzo.Code.Function.Structures.Biased - MAlonzo.Code.Function.Base - MAlonzo.Code.Function.Nary.NonDependent - MAlonzo.Code.Function.Nary.NonDependent.Base - MAlonzo.Code.Relation.Nullary.Indexed - MAlonzo.Code.Relation.Nullary.Decidable - MAlonzo.Code.Relation.Nullary.Negation.Core - MAlonzo.Code.Relation.Nullary.Decidable.Core + MAlonzo.Code.Tactic.ReduceDec + MAlonzo.Code.Tactic.AnyOf + MAlonzo.Code.PreludeMeta + MAlonzo.Code.Data.String + MAlonzo.Code.Data.Sign.Properties + MAlonzo.Code.Data.Sign.Base + MAlonzo.Code.Data.Maybe + MAlonzo.Code.Data.Empty.Polymorphic + MAlonzo.Code.Data.Empty.Irrelevant + MAlonzo.Code.Data.Refinement + MAlonzo.Code.Data.Unit + MAlonzo.Code.Data.Rational.Show + MAlonzo.Code.Data.Rational.Unnormalised.Properties + MAlonzo.Code.Data.Rational.Unnormalised.Base + MAlonzo.Code.Data.Rational.Properties + MAlonzo.Code.Data.Rational.Base + MAlonzo.Code.Data.Integer + MAlonzo.Code.Data.Bool.Base + MAlonzo.Code.Data.Bool.Properties + MAlonzo.Code.Data.Bool.Show + MAlonzo.Code.Data.Vec + MAlonzo.Code.Data.Maybe.Relation.Binary.Connected + MAlonzo.Code.Data.Maybe.Relation.Unary.Any + MAlonzo.Code.Data.Maybe.Relation.Unary.All + MAlonzo.Code.Data.Maybe.Effectful + MAlonzo.Code.Data.Maybe.Base + MAlonzo.Code.Data.Maybe.Properties + MAlonzo.Code.Data.Relation.Nullary.Decidable.Ext + MAlonzo.Code.Data.Record + MAlonzo.Code.Data.Word.Properties + MAlonzo.Code.Data.Word.Base + MAlonzo.Code.Data.String.Base + MAlonzo.Code.Data.String.Properties + MAlonzo.Code.Data.Sum + MAlonzo.Code.Data.Sum.Properties + MAlonzo.Code.Data.Sum.Function.Propositional + MAlonzo.Code.Data.Sum.Function.Setoid + MAlonzo.Code.Data.Sum.Relation.Unary.All + MAlonzo.Code.Data.Sum.Relation.Binary.Pointwise + MAlonzo.Code.Data.Sum.Base + MAlonzo.Code.Data.Sum.Algebra + MAlonzo.Code.Data.Sum.Effectful.Left + MAlonzo.Code.Data.Fin + MAlonzo.Code.Data.Universe + MAlonzo.Code.Data.These.Base + MAlonzo.Code.Data.These.Properties + MAlonzo.Code.Data.Word + MAlonzo.Code.Data.Product + MAlonzo.Code.Data.Float.Base + MAlonzo.Code.Data.Float.Properties + MAlonzo.Code.Data.Parity.Base + MAlonzo.Code.Data.List.Base + MAlonzo.Code.Data.List.NonEmpty.Base + MAlonzo.Code.Data.List.Membership.DecSetoid + MAlonzo.Code.Data.List.Membership.DecPropositional + MAlonzo.Code.Data.List.Membership.Propositional.Properties.Core + MAlonzo.Code.Data.List.Membership.Propositional.Properties + MAlonzo.Code.Data.List.Membership.Propositional + MAlonzo.Code.Data.List.Membership.Setoid + MAlonzo.Code.Data.List.Membership.Setoid.Properties + MAlonzo.Code.Data.List.Effectful + MAlonzo.Code.Data.List.Sort + MAlonzo.Code.Data.List.Extrema + MAlonzo.Code.Data.List.Sort.MergeSort + MAlonzo.Code.Data.List.Sort.Base + MAlonzo.Code.Data.List.Properties + MAlonzo.Code.Data.List.Extrema.Core + MAlonzo.Code.Data.List.NonEmpty + MAlonzo.Code.Data.List.Relation.Unary.AllPairs.Core + MAlonzo.Code.Data.List.Relation.Unary.AllPairs.Properties + MAlonzo.Code.Data.List.Relation.Unary.All.Properties + MAlonzo.Code.Data.List.Relation.Unary.Any.Properties + MAlonzo.Code.Data.List.Relation.Unary.All + MAlonzo.Code.Data.List.Relation.Unary.Linked + MAlonzo.Code.Data.List.Relation.Unary.MOf + MAlonzo.Code.Data.List.Relation.Unary.Sorted.TotalOrder.Properties + MAlonzo.Code.Data.List.Relation.Unary.Sorted.TotalOrder + MAlonzo.Code.Data.List.Relation.Unary.AllPairs + MAlonzo.Code.Data.List.Relation.Unary.Any + MAlonzo.Code.Data.List.Relation.Unary.Unique.Setoid + MAlonzo.Code.Data.List.Relation.Unary.Unique.DecSetoid + MAlonzo.Code.Data.List.Relation.Unary.Unique.DecPropositional.Properties + MAlonzo.Code.Data.List.Relation.Unary.Unique.Propositional.Properties + MAlonzo.Code.Data.List.Relation.Unary.Unique.Propositional.Properties.WithK + MAlonzo.Code.Data.List.Relation.Unary.Unique.DecSetoid.Properties + MAlonzo.Code.Data.List.Relation.Unary.Unique.Propositional + MAlonzo.Code.Data.List.Relation.Unary.Unique.DecPropositional + MAlonzo.Code.Data.List.Relation.Unary.Unique.Setoid.Properties + MAlonzo.Code.Data.List.Relation.Unary.Linked.Properties + MAlonzo.Code.Data.List.Relation.Binary.Sublist.Ext + MAlonzo.Code.Data.List.Relation.Binary.Sublist.Heterogeneous + MAlonzo.Code.Data.List.Relation.Binary.Sublist.Setoid.Properties + MAlonzo.Code.Data.List.Relation.Binary.Sublist.Propositional + MAlonzo.Code.Data.List.Relation.Binary.Sublist.Heterogeneous.Core + MAlonzo.Code.Data.List.Relation.Binary.Sublist.Heterogeneous.Properties + MAlonzo.Code.Data.List.Relation.Binary.Sublist.Setoid + MAlonzo.Code.Data.List.Relation.Binary.BagAndSetEquality + MAlonzo.Code.Data.List.Relation.Binary.Lex.Core + MAlonzo.Code.Data.List.Relation.Binary.Lex.Strict + MAlonzo.Code.Data.List.Relation.Binary.Pointwise.Base + MAlonzo.Code.Data.List.Relation.Binary.Pointwise.Properties + MAlonzo.Code.Data.List.Relation.Binary.Pointwise + MAlonzo.Code.Data.List.Relation.Binary.Lex + MAlonzo.Code.Data.List.Relation.Binary.Disjoint.Propositional + MAlonzo.Code.Data.List.Relation.Binary.Disjoint.Setoid + MAlonzo.Code.Data.List.Relation.Binary.Disjoint.Setoid.Properties + MAlonzo.Code.Data.List.Relation.Binary.Subset.Propositional.Properties + MAlonzo.Code.Data.List.Relation.Binary.Subset.Propositional + MAlonzo.Code.Data.List.Relation.Binary.Subset.Setoid + MAlonzo.Code.Data.List.Relation.Binary.Subset.Setoid.Properties + MAlonzo.Code.Data.List.Relation.Binary.Permutation.Setoid + MAlonzo.Code.Data.List.Relation.Binary.Permutation.Homogeneous + MAlonzo.Code.Data.List.Relation.Binary.Permutation.Propositional.Properties + MAlonzo.Code.Data.List.Relation.Binary.Permutation.Propositional + MAlonzo.Code.Data.List.Relation.Binary.Permutation.Setoid.Properties + MAlonzo.Code.Data.List.Relation.Binary.Equality.Propositional + MAlonzo.Code.Data.List.Relation.Binary.Equality.Setoid + MAlonzo.Code.Data.List.Ext.Properties + MAlonzo.Code.Data.List.Ext + MAlonzo.Code.Data.Float + MAlonzo.Code.Data.Irrelevant + MAlonzo.Code.Data.Container + MAlonzo.Code.Data.Digit + MAlonzo.Code.Data.Product.Properties.Ext + MAlonzo.Code.Data.Product.Nary.NonDependent + MAlonzo.Code.Data.Product.Base + MAlonzo.Code.Data.Product.Ext + MAlonzo.Code.Data.Product.Algebra + MAlonzo.Code.Data.Product.Properties + MAlonzo.Code.Data.Product.Relation.Unary.All + MAlonzo.Code.Data.Product.Relation.Binary.Pointwise.NonDependent + MAlonzo.Code.Data.Product.Function.NonDependent.Propositional + MAlonzo.Code.Data.Product.Function.NonDependent.Setoid + MAlonzo.Code.Data.Product.Function.Dependent.Propositional + MAlonzo.Code.Data.Char + MAlonzo.Code.Data.Nat + MAlonzo.Code.Data.Integer.GCD + MAlonzo.Code.Data.Integer.Base + MAlonzo.Code.Data.Integer.Solver + MAlonzo.Code.Data.Integer.Show + MAlonzo.Code.Data.Integer.Properties + MAlonzo.Code.Data.Integer.Coprimality + MAlonzo.Code.Data.Integer.Divisibility + MAlonzo.Code.Data.Integer.Ext + MAlonzo.Code.Data.These + MAlonzo.Code.Data.Bool + MAlonzo.Code.Data.Sign + MAlonzo.Code.Data.Rational + MAlonzo.Code.Data.W + MAlonzo.Code.Data.Vec.Bounded.Base + MAlonzo.Code.Data.Vec.Base + MAlonzo.Code.Data.Vec.Properties + MAlonzo.Code.Data.Vec.Functional + MAlonzo.Code.Data.Vec.NZ45Zary + MAlonzo.Code.Data.Vec.Relation.Unary.All + MAlonzo.Code.Data.Vec.Relation.Unary.Any + MAlonzo.Code.Data.Vec.Relation.Binary.Equality.Cast + MAlonzo.Code.Data.Vec.Membership.Propositional + MAlonzo.Code.Data.Vec.Membership.Setoid + MAlonzo.Code.Data.List + MAlonzo.Code.Data.Nat.Induction + MAlonzo.Code.Data.Nat.Literals + MAlonzo.Code.Data.Nat.GCD.Lemmas + MAlonzo.Code.Data.Nat.Coprimality + MAlonzo.Code.Data.Nat.GeneralisedArithmetic + MAlonzo.Code.Data.Nat.Divisibility + MAlonzo.Code.Data.Nat.GCD + MAlonzo.Code.Data.Nat.Properties + MAlonzo.Code.Data.Nat.Show + MAlonzo.Code.Data.Nat.DivMod.Core + MAlonzo.Code.Data.Nat.Solver + MAlonzo.Code.Data.Nat.DivMod + MAlonzo.Code.Data.Nat.Divisibility.Core + MAlonzo.Code.Data.Nat.Properties.Ext + MAlonzo.Code.Data.Nat.Primality + MAlonzo.Code.Data.Nat.Base + MAlonzo.Code.Data.Empty + MAlonzo.Code.Data.Container.Morphism + MAlonzo.Code.Data.Container.Related + MAlonzo.Code.Data.Container.Membership + MAlonzo.Code.Data.Container.Properties + MAlonzo.Code.Data.Container.Morphism.Properties + MAlonzo.Code.Data.Container.Core + MAlonzo.Code.Data.Container.Relation.Binary.Pointwise.Properties + MAlonzo.Code.Data.Container.Relation.Binary.Pointwise + MAlonzo.Code.Data.Container.Relation.Binary.Equality.Setoid + MAlonzo.Code.Data.Container.Relation.Unary.Any + MAlonzo.Code.Data.Container.Relation.Unary.All + MAlonzo.Code.Data.Fin.Properties + MAlonzo.Code.Data.Fin.Patterns + MAlonzo.Code.Data.Fin.Base + MAlonzo.Code.Data.Char.Base + MAlonzo.Code.Data.Char.Properties + MAlonzo.Code.Data.Unit.Polymorphic + MAlonzo.Code.Data.Unit.Base + MAlonzo.Code.Data.Unit.Properties + MAlonzo.Code.Data.Unit.Polymorphic.Base + MAlonzo.Code.Data.Unit.Polymorphic.Properties + MAlonzo.Code.Level + MAlonzo.Code.Function.Consequences.Propositional + MAlonzo.Code.Function.Consequences.Setoid + MAlonzo.Code.Function.Definitions + MAlonzo.Code.Function.Indexed.Relation.Binary.Equality + MAlonzo.Code.Function.Base + MAlonzo.Code.Function.Consequences + MAlonzo.Code.Function.Metric.Nat + MAlonzo.Code.Function.Metric.Bundles + MAlonzo.Code.Function.Metric.Nat.Bundles + MAlonzo.Code.Function.Metric.Nat.Definitions + MAlonzo.Code.Function.Metric.Nat.Structures + MAlonzo.Code.Function.Metric.Nat.Core + MAlonzo.Code.Function.Metric.Core + MAlonzo.Code.Function.Metric.Definitions + MAlonzo.Code.Function.Metric.Structures + MAlonzo.Code.Function.Structures + MAlonzo.Code.Function.Nary.NonDependent.Base + MAlonzo.Code.Function.Nary.NonDependent + MAlonzo.Code.Function.Related.Propositional + MAlonzo.Code.Function.Related.TypeIsomorphisms + MAlonzo.Code.Function.Identity.Effectful + MAlonzo.Code.Function.Bundles + MAlonzo.Code.Function.Core + MAlonzo.Code.Function.Structures.Biased + MAlonzo.Code.Function.Construct.Composition + MAlonzo.Code.Function.Construct.Symmetry + MAlonzo.Code.Function.Construct.Identity + MAlonzo.Code.Function.Properties.Inverse.HalfAdjointEquivalence + MAlonzo.Code.Function.Properties.RightInverse + MAlonzo.Code.Function.Properties.Surjection + MAlonzo.Code.Function.Properties.Bijection + MAlonzo.Code.Function.Properties.Inverse + MAlonzo.Code.Function.Strict + MAlonzo.Code.Function.Dependent.Bundles + MAlonzo.Code.Relation.Nullary.Negation.Core + MAlonzo.Code.Relation.Nullary.Decidable + MAlonzo.Code.Relation.Nullary.Indexed MAlonzo.Code.Relation.Nullary.Reflects MAlonzo.Code.Relation.Nullary.Negation - MAlonzo.Code.Relation.Unary.Properties + MAlonzo.Code.Relation.Nullary.Decidable.Core MAlonzo.Code.Relation.Unary - MAlonzo.Code.Relation.Binary.PropositionalEquality - MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Construct.Trivial - MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Structures - MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Bundles - MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Definitions - MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Core - MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous - MAlonzo.Code.Relation.Binary.Lattice - MAlonzo.Code.Relation.Binary.Reasoning.Setoid - MAlonzo.Code.Relation.Binary.Reasoning.Syntax + MAlonzo.Code.Relation.Nullary MAlonzo.Code.Relation.Binary.Reasoning.Preorder MAlonzo.Code.Relation.Binary.Reasoning.PartialOrder - MAlonzo.Code.Relation.Binary.Reasoning.Base.Triple MAlonzo.Code.Relation.Binary.Reasoning.Base.Single + MAlonzo.Code.Relation.Binary.Reasoning.Base.Triple MAlonzo.Code.Relation.Binary.Reasoning.Base.Double - MAlonzo.Code.Relation.Binary.Properties.DecTotalOrder - MAlonzo.Code.Relation.Binary.Properties.ApartnessRelation - MAlonzo.Code.Relation.Binary.Properties.Setoid - MAlonzo.Code.Relation.Binary.Properties.TotalOrder - MAlonzo.Code.Relation.Binary.Properties.Poset - MAlonzo.Code.Relation.Binary.Properties.Preorder - MAlonzo.Code.Relation.Binary.Morphism - MAlonzo.Code.Relation.Binary.Reflection - MAlonzo.Code.Relation.Binary.Definitions + MAlonzo.Code.Relation.Binary.Reasoning.Setoid + MAlonzo.Code.Relation.Binary.Reasoning.Syntax + MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous + MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Structures + MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Bundles + MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Core + MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Definitions + MAlonzo.Code.Relation.Binary.Indexed.Heterogeneous.Construct.Trivial MAlonzo.Code.Relation.Binary.PropositionalEquality.Properties - MAlonzo.Code.Relation.Binary.PropositionalEquality.Algebra MAlonzo.Code.Relation.Binary.PropositionalEquality.Core - MAlonzo.Code.Relation.Binary.Core - MAlonzo.Code.Relation.Binary.Consequences - MAlonzo.Code.Relation.Binary.Construct.On + MAlonzo.Code.Relation.Binary.PropositionalEquality.Algebra + MAlonzo.Code.Relation.Binary.Lattice + MAlonzo.Code.Relation.Binary.Reflection MAlonzo.Code.Relation.Binary.Construct.NonStrictToStrict MAlonzo.Code.Relation.Binary.Construct.Closure.Reflexive MAlonzo.Code.Relation.Binary.Construct.Closure.Reflexive.Properties - MAlonzo.Code.Relation.Binary.Construct.Intersection - MAlonzo.Code.Relation.Binary.Construct.Subst.Equality - MAlonzo.Code.Relation.Binary.Construct.Constant.Core - MAlonzo.Code.Relation.Binary.Construct.Flip.EqAndOrd + MAlonzo.Code.Relation.Binary.Construct.On MAlonzo.Code.Relation.Binary.Construct.StrictToNonStrict MAlonzo.Code.Relation.Binary.Construct.NaturalOrder.Left - MAlonzo.Code.Relation.Binary.Structures.Biased + MAlonzo.Code.Relation.Binary.Construct.Flip.EqAndOrd + MAlonzo.Code.Relation.Binary.Construct.Intersection + MAlonzo.Code.Relation.Binary.Construct.Constant.Core + MAlonzo.Code.Relation.Binary.Construct.Subst.Equality + MAlonzo.Code.Relation.Binary.Morphism.OrderMonomorphism + MAlonzo.Code.Relation.Binary.Morphism.Construct.Identity MAlonzo.Code.Relation.Binary.Morphism.RelMonomorphism + MAlonzo.Code.Relation.Binary.Morphism.Definitions MAlonzo.Code.Relation.Binary.Morphism.Structures - MAlonzo.Code.Relation.Binary.Morphism.Construct.Identity MAlonzo.Code.Relation.Binary.Morphism.Bundles - MAlonzo.Code.Relation.Binary.Morphism.Definitions - MAlonzo.Code.Relation.Binary.Morphism.OrderMonomorphism - MAlonzo.Code.Relation.Binary.Structures + MAlonzo.Code.Relation.Binary.Structures.Biased + MAlonzo.Code.Relation.Binary.PropositionalEquality + MAlonzo.Code.Relation.Binary.Morphism MAlonzo.Code.Relation.Binary.Bundles - MAlonzo.Code.Relation.Binary.Lattice.Structures - MAlonzo.Code.Relation.Binary.Lattice.Properties.JoinSemilattice - MAlonzo.Code.Relation.Binary.Lattice.Properties.BoundedJoinSemilattice + MAlonzo.Code.Relation.Binary.Core + MAlonzo.Code.Relation.Binary.Structures + MAlonzo.Code.Relation.Binary.Properties.Preorder + MAlonzo.Code.Relation.Binary.Properties.Setoid + MAlonzo.Code.Relation.Binary.Properties.DecTotalOrder + MAlonzo.Code.Relation.Binary.Properties.ApartnessRelation + MAlonzo.Code.Relation.Binary.Properties.Poset + MAlonzo.Code.Relation.Binary.Properties.TotalOrder + MAlonzo.Code.Relation.Binary.Definitions + MAlonzo.Code.Relation.Binary.Consequences MAlonzo.Code.Relation.Binary.Lattice.Definitions + MAlonzo.Code.Relation.Binary.Lattice.Properties.BoundedJoinSemilattice + MAlonzo.Code.Relation.Binary.Lattice.Properties.JoinSemilattice MAlonzo.Code.Relation.Binary.Lattice.Bundles + MAlonzo.Code.Relation.Binary.Lattice.Structures MAlonzo.Code.Relation.Binary - MAlonzo.Code.Relation.Nullary - MAlonzo.Code.Level - MAlonzo.Code.Foreign.Convertible - MAlonzo.Code.Foreign.Convertible.Deriving - MAlonzo.Code.Foreign.Haskell.Pair - MAlonzo.Code.Foreign.Haskell.List.NonEmpty - MAlonzo.Code.Foreign.Haskell.Either - MAlonzo.Code.Foreign.Haskell.Coerce - MAlonzo.Code.Foreign.Haskell + MAlonzo.Code.Relation.Unary.Properties + MAlonzo.Code.Ledger.Ledger + MAlonzo.Code.Ledger.ScriptValidation + MAlonzo.Code.Ledger.Utxo + MAlonzo.Code.Ledger.Utxo.Haskell + MAlonzo.Code.Ledger.Utxo.Haskell.Properties + MAlonzo.Code.Ledger.Utxo.Properties + MAlonzo.Code.Ledger.Epoch + MAlonzo.Code.Ledger.Set.Theory + MAlonzo.Code.Ledger.Set.HashMap + MAlonzo.Code.Ledger.Utxow.Properties + MAlonzo.Code.Ledger.Certs.Properties + MAlonzo.Code.Ledger.Certs.Haskell + MAlonzo.Code.Ledger.Certs.Haskell.Properties + MAlonzo.Code.Ledger.Ledger.Properties + MAlonzo.Code.Ledger.Gov + MAlonzo.Code.Ledger.Chain + MAlonzo.Code.Ledger.Script + MAlonzo.Code.Ledger.Gov.Properties + MAlonzo.Code.Ledger.Types.Epoch + MAlonzo.Code.Ledger.Types.GovStructure + MAlonzo.Code.Ledger.Certs + MAlonzo.Code.Ledger.Interface.HasCoin + MAlonzo.Code.Ledger.GovernanceActions.Properties + MAlonzo.Code.Ledger.TokenAlgebra + MAlonzo.Code.Ledger.Ratify.Properties + MAlonzo.Code.Ledger.Utxow + MAlonzo.Code.Ledger.Set + MAlonzo.Code.Ledger.Prelude.Base + MAlonzo.Code.Ledger.Foreign.HSLedger + MAlonzo.Code.Ledger.Foreign.HSLedger.Ledger + MAlonzo.Code.Ledger.Foreign.HSLedger.Core + MAlonzo.Code.Ledger.Foreign.HSLedger.Enact + MAlonzo.Code.Ledger.Foreign.HSLedger.NewEpoch + MAlonzo.Code.Ledger.Foreign.HSLedger.Chain + MAlonzo.Code.Ledger.Foreign.HSLedger.BaseTypes + MAlonzo.Code.Ledger.Foreign.HSLedger.Gov + MAlonzo.Code.Ledger.Foreign.HSLedger.Epoch + MAlonzo.Code.Ledger.Foreign.HSLedger.Cert + MAlonzo.Code.Ledger.Foreign.HSLedger.Utxo + MAlonzo.Code.Ledger.Foreign.HSLedger.Certs + MAlonzo.Code.Ledger.Foreign.HSLedger.Ratify + MAlonzo.Code.Ledger.Foreign.LedgerTypes + MAlonzo.Code.Ledger.Abstract + MAlonzo.Code.Ledger.Ratify + MAlonzo.Code.Ledger.Transaction + MAlonzo.Code.Ledger.Address + MAlonzo.Code.Ledger.Chain.Properties + MAlonzo.Code.Ledger.Crypto + MAlonzo.Code.Ledger.GovernanceActions + MAlonzo.Code.Ledger.PParams + MAlonzo.Code.Ledger.Enact + MAlonzo.Code.Ledger.Prelude + MAlonzo.Code.Ledger.Epoch.Properties + MAlonzo.Code.Effect.Empty + MAlonzo.Code.Effect.Functor + MAlonzo.Code.Effect.Comonad + MAlonzo.Code.Effect.Applicative + MAlonzo.Code.Effect.Monad + MAlonzo.Code.Effect.Choice + MAlonzo.Code.Induction + MAlonzo.Code.Algebra.Bundles.Raw + MAlonzo.Code.Algebra.Function + MAlonzo.Code.Algebra.Definitions + MAlonzo.Code.Algebra.Core + MAlonzo.Code.Algebra.PairOp + MAlonzo.Code.Algebra.Apartness.Structures + MAlonzo.Code.Algebra.Apartness.Bundles + MAlonzo.Code.Algebra.Structures + MAlonzo.Code.Algebra.Morphism.MagmaMonomorphism + MAlonzo.Code.Algebra.Morphism.Structures + MAlonzo.Code.Algebra.Morphism.MonoidMonomorphism + MAlonzo.Code.Algebra.Morphism.Construct.Identity + MAlonzo.Code.Algebra.Morphism.RingMonomorphism + MAlonzo.Code.Algebra.Morphism.Definitions + MAlonzo.Code.Algebra.Morphism.GroupMonomorphism + MAlonzo.Code.Algebra.Lattice + MAlonzo.Code.Algebra.Lattice.Morphism.LatticeMonomorphism + MAlonzo.Code.Algebra.Lattice.Morphism.Structures + MAlonzo.Code.Algebra.Lattice.Structures + MAlonzo.Code.Algebra.Lattice.Properties.DistributiveLattice + MAlonzo.Code.Algebra.Lattice.Properties.BooleanAlgebra + MAlonzo.Code.Algebra.Lattice.Properties.Lattice + MAlonzo.Code.Algebra.Lattice.Properties.Semilattice + MAlonzo.Code.Algebra.Lattice.Bundles.Raw + MAlonzo.Code.Algebra.Lattice.Bundles + MAlonzo.Code.Algebra.Lattice.Construct.NaturalChoice.MaxOp + MAlonzo.Code.Algebra.Lattice.Construct.NaturalChoice.MinOp + MAlonzo.Code.Algebra.Lattice.Construct.NaturalChoice.MinMaxOp + MAlonzo.Code.Algebra.Lattice.Structures.Biased MAlonzo.Code.Algebra.Morphism MAlonzo.Code.Algebra.Construct.NaturalChoice.MinMaxOp - MAlonzo.Code.Algebra.Construct.NaturalChoice.Max MAlonzo.Code.Algebra.Construct.NaturalChoice.MaxOp MAlonzo.Code.Algebra.Construct.NaturalChoice.MinOp - MAlonzo.Code.Algebra.Construct.NaturalChoice.Base + MAlonzo.Code.Algebra.Construct.NaturalChoice.Max MAlonzo.Code.Algebra.Construct.NaturalChoice.Min + MAlonzo.Code.Algebra.Construct.NaturalChoice.Base MAlonzo.Code.Algebra.Construct.LiftedChoice - MAlonzo.Code.Algebra.Definitions - MAlonzo.Code.Algebra.Lattice - MAlonzo.Code.Algebra.PairOp - MAlonzo.Code.Algebra.Apartness.Bundles - MAlonzo.Code.Algebra.Apartness.Structures - MAlonzo.Code.Algebra.Function MAlonzo.Code.Algebra.Structures.Biased - MAlonzo.Code.Algebra.Bundles.Raw - MAlonzo.Code.Algebra.Core - MAlonzo.Code.Algebra.Consequences.Propositional - MAlonzo.Code.Algebra.Consequences.Setoid - MAlonzo.Code.Algebra.Consequences.Base - MAlonzo.Code.Algebra.Definitions.RawMonoid - MAlonzo.Code.Algebra.Definitions.RawMagma - MAlonzo.Code.Algebra.Definitions.RawSemiring MAlonzo.Code.Algebra.Solver.Ring.Simple - MAlonzo.Code.Algebra.Solver.Ring.AlmostCommutativeRing MAlonzo.Code.Algebra.Solver.Ring.Lemmas + MAlonzo.Code.Algebra.Solver.Ring.AlmostCommutativeRing MAlonzo.Code.Algebra.Solver.Ring MAlonzo.Code.Algebra.Bundles - MAlonzo.Code.Algebra.Structures - MAlonzo.Code.Algebra.Lattice.Construct.NaturalChoice.MinMaxOp - MAlonzo.Code.Algebra.Lattice.Construct.NaturalChoice.MinOp - MAlonzo.Code.Algebra.Lattice.Construct.NaturalChoice.MaxOp - MAlonzo.Code.Algebra.Lattice.Structures - MAlonzo.Code.Algebra.Lattice.Structures.Biased - MAlonzo.Code.Algebra.Lattice.Bundles.Raw - MAlonzo.Code.Algebra.Lattice.Morphism.Structures - MAlonzo.Code.Algebra.Lattice.Morphism.LatticeMonomorphism - MAlonzo.Code.Algebra.Lattice.Bundles - MAlonzo.Code.Algebra.Lattice.Properties.DistributiveLattice - MAlonzo.Code.Algebra.Lattice.Properties.BooleanAlgebra - MAlonzo.Code.Algebra.Lattice.Properties.Semilattice - MAlonzo.Code.Algebra.Lattice.Properties.Lattice - MAlonzo.Code.Algebra.Properties.Monoid.Mult - MAlonzo.Code.Algebra.Properties.AbelianGroup + MAlonzo.Code.Algebra.Consequences.Base + MAlonzo.Code.Algebra.Consequences.Setoid + MAlonzo.Code.Algebra.Consequences.Propositional + MAlonzo.Code.Algebra.Definitions.RawMagma + MAlonzo.Code.Algebra.Definitions.RawMonoid + MAlonzo.Code.Algebra.Definitions.RawSemiring + MAlonzo.Code.Algebra.Properties.Ring + MAlonzo.Code.Algebra.Properties.Group MAlonzo.Code.Algebra.Properties.CommutativeSemigroup MAlonzo.Code.Algebra.Properties.CommutativeMonoid + MAlonzo.Code.Algebra.Properties.RingWithoutOne MAlonzo.Code.Algebra.Properties.Semiring.Exp - MAlonzo.Code.Algebra.Properties.Ring + MAlonzo.Code.Algebra.Properties.Monoid.Mult MAlonzo.Code.Algebra.Properties.Semigroup - MAlonzo.Code.Algebra.Properties.Group - MAlonzo.Code.Algebra.Properties.RingWithoutOne - MAlonzo.Code.Algebra.Morphism.Structures - MAlonzo.Code.Algebra.Morphism.MonoidMonomorphism - MAlonzo.Code.Algebra.Morphism.GroupMonomorphism - MAlonzo.Code.Algebra.Morphism.Definitions - MAlonzo.Code.Algebra.Morphism.Construct.Identity - MAlonzo.Code.Algebra.Morphism.RingMonomorphism - MAlonzo.Code.Algebra.Morphism.MagmaMonomorphism + MAlonzo.Code.Algebra.Properties.AbelianGroup MAlonzo.Code.Algebra.Apartness - MAlonzo.Code.Interface.HasSubtract.Instance - MAlonzo.Code.Interface.HasAdd - MAlonzo.Code.Interface.HasOrder.Instance - MAlonzo.Code.Interface.HasAdd.Instance - MAlonzo.Code.Interface.HasSingleton - MAlonzo.Code.Interface.HasEmptySet.Instances - MAlonzo.Code.Interface.HasEmptySet - MAlonzo.Code.Interface.Hashable - MAlonzo.Code.Interface.STS - MAlonzo.Code.Interface.IsCommutativeMonoid - MAlonzo.Code.Interface.IsSet - MAlonzo.Code.Interface.ToBool - MAlonzo.Code.Interface.HasOrder - MAlonzo.Code.Interface.ComputationalRelation - MAlonzo.Code.Interface.HasSubtract - MAlonzo.Code.Effect.Choice - MAlonzo.Code.Effect.Empty - MAlonzo.Code.Effect.Comonad - MAlonzo.Code.Effect.Functor - MAlonzo.Code.Effect.Monad - MAlonzo.Code.Effect.Applicative - MAlonzo.Code.Ledger.Utxo - MAlonzo.Code.Ledger.Certs - MAlonzo.Code.Ledger.GovernanceActions.Properties - MAlonzo.Code.Ledger.Types.GovStructure - MAlonzo.Code.Ledger.Types.Epoch - MAlonzo.Code.Ledger.ScriptValidation - MAlonzo.Code.Ledger.Utxow.Properties - MAlonzo.Code.Ledger.GovernanceActions - MAlonzo.Code.Ledger.Certs.Haskell.Properties - MAlonzo.Code.Ledger.Certs.Properties - MAlonzo.Code.Ledger.Certs.Haskell - MAlonzo.Code.Ledger.Crypto - MAlonzo.Code.Ledger.Epoch - MAlonzo.Code.Ledger.Utxo.Haskell.Properties - MAlonzo.Code.Ledger.Utxo.Properties - MAlonzo.Code.Ledger.Utxo.Haskell - MAlonzo.Code.Ledger.Ratify - MAlonzo.Code.Ledger.Ratify.Properties - MAlonzo.Code.Ledger.Set - MAlonzo.Code.Ledger.Chain - MAlonzo.Code.Ledger.TokenAlgebra - MAlonzo.Code.Ledger.Ledger - MAlonzo.Code.Ledger.Epoch.Properties - MAlonzo.Code.Ledger.Address - MAlonzo.Code.Ledger.Prelude.Base - MAlonzo.Code.Ledger.Script - MAlonzo.Code.Ledger.Enact - MAlonzo.Code.Ledger.PParams - MAlonzo.Code.Ledger.Abstract - MAlonzo.Code.Ledger.Prelude - MAlonzo.Code.Ledger.Foreign.HSLedger.Gov - MAlonzo.Code.Ledger.Foreign.HSLedger.Ratify - MAlonzo.Code.Ledger.Foreign.HSLedger.NewEpoch - MAlonzo.Code.Ledger.Foreign.HSLedger.Cert - MAlonzo.Code.Ledger.Foreign.HSLedger.Utxo - MAlonzo.Code.Ledger.Foreign.HSLedger.Enact - MAlonzo.Code.Ledger.Foreign.HSLedger.Chain - MAlonzo.Code.Ledger.Foreign.HSLedger.Epoch - MAlonzo.Code.Ledger.Foreign.HSLedger.Certs - MAlonzo.Code.Ledger.Foreign.HSLedger.Ledger - MAlonzo.Code.Ledger.Foreign.HSLedger.Core - MAlonzo.Code.Ledger.Foreign.HSLedger.BaseTypes - MAlonzo.Code.Ledger.Foreign.HSLedger - MAlonzo.Code.Ledger.Foreign.LedgerTypes - MAlonzo.Code.Ledger.Gov.Properties - MAlonzo.Code.Ledger.Chain.Properties - MAlonzo.Code.Ledger.Transaction - MAlonzo.Code.Ledger.Set.HashMap - MAlonzo.Code.Ledger.Set.Theory - MAlonzo.Code.Ledger.Utxow - MAlonzo.Code.Ledger.Interface.HasCoin - MAlonzo.Code.Ledger.Ledger.Properties - MAlonzo.Code.Ledger.Gov - MAlonzo.Code.Data.Nat.GCD - MAlonzo.Code.Data.Nat.Properties - MAlonzo.Code.Data.Nat.DivMod.Core - MAlonzo.Code.Data.Nat.Coprimality - MAlonzo.Code.Data.Nat.Base - MAlonzo.Code.Data.Nat.Literals - MAlonzo.Code.Data.Nat.DivMod - MAlonzo.Code.Data.Nat.Solver - MAlonzo.Code.Data.Nat.Primality - MAlonzo.Code.Data.Nat.Properties.Ext - MAlonzo.Code.Data.Nat.Divisibility.Core - MAlonzo.Code.Data.Nat.Induction - MAlonzo.Code.Data.Nat.GCD.Lemmas - MAlonzo.Code.Data.Nat.Show - MAlonzo.Code.Data.Nat.GeneralisedArithmetic - MAlonzo.Code.Data.Nat.Divisibility - MAlonzo.Code.Data.Integer.Show - MAlonzo.Code.Data.Integer.Solver - MAlonzo.Code.Data.Integer.Ext - MAlonzo.Code.Data.Integer.Coprimality - MAlonzo.Code.Data.Integer.Base - MAlonzo.Code.Data.Integer.Divisibility - MAlonzo.Code.Data.Integer.Properties - MAlonzo.Code.Data.Integer.GCD - MAlonzo.Code.Data.Fin.Base - MAlonzo.Code.Data.Fin.Properties - MAlonzo.Code.Data.Fin.Patterns - MAlonzo.Code.Data.Char - MAlonzo.Code.Data.Maybe.Base - MAlonzo.Code.Data.Maybe.Properties - MAlonzo.Code.Data.Maybe.Relation.Unary.All - MAlonzo.Code.Data.Maybe.Relation.Unary.Any - MAlonzo.Code.Data.Maybe.Relation.Binary.Connected - MAlonzo.Code.Data.Maybe.Effectful - MAlonzo.Code.Data.Unit.Base - MAlonzo.Code.Data.Unit.Properties - MAlonzo.Code.Data.Unit.Polymorphic.Base - MAlonzo.Code.Data.Unit.Polymorphic.Properties - MAlonzo.Code.Data.Unit.Polymorphic - MAlonzo.Code.Data.Char.Properties - MAlonzo.Code.Data.Char.Base - MAlonzo.Code.Data.Product.Relation.Unary.All - MAlonzo.Code.Data.Product.Relation.Binary.Pointwise.NonDependent - MAlonzo.Code.Data.Product.Function.Dependent.Propositional - MAlonzo.Code.Data.Product.Function.NonDependent.Setoid - MAlonzo.Code.Data.Product.Function.NonDependent.Propositional - MAlonzo.Code.Data.Product.Nary.NonDependent - MAlonzo.Code.Data.Product.Algebra - MAlonzo.Code.Data.Product.Base - MAlonzo.Code.Data.Product.Properties - MAlonzo.Code.Data.Product.Ext - MAlonzo.Code.Data.Product.Properties.Ext - MAlonzo.Code.Data.Product - MAlonzo.Code.Data.W - MAlonzo.Code.Data.Empty.Polymorphic - MAlonzo.Code.Data.Empty.Irrelevant - MAlonzo.Code.Data.Vec - MAlonzo.Code.Data.Digit - MAlonzo.Code.Data.Universe - MAlonzo.Code.Data.Vec.Bounded.Base - MAlonzo.Code.Data.Vec.Relation.Binary.Equality.Cast - MAlonzo.Code.Data.Vec.Relation.Unary.Any - MAlonzo.Code.Data.Vec.Relation.Unary.All - MAlonzo.Code.Data.Vec.Membership.Setoid - MAlonzo.Code.Data.Vec.Membership.Propositional - MAlonzo.Code.Data.Vec.Functional - MAlonzo.Code.Data.Vec.Base - MAlonzo.Code.Data.Vec.NZ45Zary - MAlonzo.Code.Data.Vec.Properties - MAlonzo.Code.Data.Empty - MAlonzo.Code.Data.Fin - MAlonzo.Code.Data.Sum - MAlonzo.Code.Data.String.Base - MAlonzo.Code.Data.String.Properties - MAlonzo.Code.Data.Container - MAlonzo.Code.Data.List - MAlonzo.Code.Data.Float.Base - MAlonzo.Code.Data.Float.Properties - MAlonzo.Code.Data.Irrelevant - MAlonzo.Code.Data.These.Properties - MAlonzo.Code.Data.These.Base - MAlonzo.Code.Data.Container.Morphism.Properties - MAlonzo.Code.Data.Container.Related - MAlonzo.Code.Data.Container.Properties - MAlonzo.Code.Data.Container.Relation.Unary.All - MAlonzo.Code.Data.Container.Relation.Unary.Any - MAlonzo.Code.Data.Container.Relation.Binary.Pointwise.Properties - MAlonzo.Code.Data.Container.Relation.Binary.Pointwise - MAlonzo.Code.Data.Container.Relation.Binary.Equality.Setoid - MAlonzo.Code.Data.Container.Membership - MAlonzo.Code.Data.Container.Core - MAlonzo.Code.Data.Container.Morphism - MAlonzo.Code.Data.These - MAlonzo.Code.Data.Integer - MAlonzo.Code.Data.Parity.Base - MAlonzo.Code.Data.Bool - MAlonzo.Code.Data.Sign - MAlonzo.Code.Data.String - MAlonzo.Code.Data.Rational.Unnormalised.Base - MAlonzo.Code.Data.Rational.Unnormalised.Properties - MAlonzo.Code.Data.Rational.Show - MAlonzo.Code.Data.Rational.Properties - MAlonzo.Code.Data.Rational.Base - MAlonzo.Code.Data.List.Sort.MergeSort - MAlonzo.Code.Data.List.Sort.Base - MAlonzo.Code.Data.List.NonEmpty.Base - MAlonzo.Code.Data.List.Sort - MAlonzo.Code.Data.List.Ext - MAlonzo.Code.Data.List.Effectful - MAlonzo.Code.Data.List.Base - MAlonzo.Code.Data.List.Membership.DecPropositional - MAlonzo.Code.Data.List.Membership.Setoid.Properties - MAlonzo.Code.Data.List.Membership.Setoid - MAlonzo.Code.Data.List.Membership.Propositional - MAlonzo.Code.Data.List.Membership.DecSetoid - MAlonzo.Code.Data.List.Membership.Propositional.Properties.Core - MAlonzo.Code.Data.List.Membership.Propositional.Properties - MAlonzo.Code.Data.List.Ext.Properties - MAlonzo.Code.Data.List.Properties - MAlonzo.Code.Data.List.NonEmpty - MAlonzo.Code.Data.List.Extrema - MAlonzo.Code.Data.List.Relation.Binary.Lex.Strict - MAlonzo.Code.Data.List.Relation.Binary.Lex.Core - MAlonzo.Code.Data.List.Relation.Binary.Pointwise - MAlonzo.Code.Data.List.Relation.Binary.Sublist.Heterogeneous.Core - MAlonzo.Code.Data.List.Relation.Binary.Sublist.Heterogeneous.Properties - MAlonzo.Code.Data.List.Relation.Binary.Sublist.Setoid.Properties - MAlonzo.Code.Data.List.Relation.Binary.Sublist.Propositional - MAlonzo.Code.Data.List.Relation.Binary.Sublist.Setoid - MAlonzo.Code.Data.List.Relation.Binary.Sublist.Ext - MAlonzo.Code.Data.List.Relation.Binary.Sublist.Heterogeneous - MAlonzo.Code.Data.List.Relation.Binary.Subset.Propositional.Properties - MAlonzo.Code.Data.List.Relation.Binary.Subset.Setoid - MAlonzo.Code.Data.List.Relation.Binary.Subset.Setoid.Properties - MAlonzo.Code.Data.List.Relation.Binary.Subset.Propositional - MAlonzo.Code.Data.List.Relation.Binary.Equality.Propositional - MAlonzo.Code.Data.List.Relation.Binary.Equality.Setoid - MAlonzo.Code.Data.List.Relation.Binary.Permutation.Propositional.Properties - MAlonzo.Code.Data.List.Relation.Binary.Permutation.Setoid - MAlonzo.Code.Data.List.Relation.Binary.Permutation.Homogeneous - MAlonzo.Code.Data.List.Relation.Binary.Permutation.Propositional - MAlonzo.Code.Data.List.Relation.Binary.Permutation.Setoid.Properties - MAlonzo.Code.Data.List.Relation.Binary.BagAndSetEquality - MAlonzo.Code.Data.List.Relation.Binary.Pointwise.Properties - MAlonzo.Code.Data.List.Relation.Binary.Pointwise.Base - MAlonzo.Code.Data.List.Relation.Binary.Disjoint.Setoid.Properties - MAlonzo.Code.Data.List.Relation.Binary.Disjoint.Propositional - MAlonzo.Code.Data.List.Relation.Binary.Disjoint.Setoid - MAlonzo.Code.Data.List.Relation.Binary.Lex - MAlonzo.Code.Data.List.Relation.Unary.AllPairs.Core - MAlonzo.Code.Data.List.Relation.Unary.AllPairs.Properties - MAlonzo.Code.Data.List.Relation.Unary.AllPairs - MAlonzo.Code.Data.List.Relation.Unary.All - MAlonzo.Code.Data.List.Relation.Unary.All.Properties - MAlonzo.Code.Data.List.Relation.Unary.Any.Properties - MAlonzo.Code.Data.List.Relation.Unary.Sorted.TotalOrder - MAlonzo.Code.Data.List.Relation.Unary.Sorted.TotalOrder.Properties - MAlonzo.Code.Data.List.Relation.Unary.MOf - MAlonzo.Code.Data.List.Relation.Unary.Unique.DecSetoid - MAlonzo.Code.Data.List.Relation.Unary.Unique.DecSetoid.Properties - MAlonzo.Code.Data.List.Relation.Unary.Unique.DecPropositional.Properties - MAlonzo.Code.Data.List.Relation.Unary.Unique.Setoid - MAlonzo.Code.Data.List.Relation.Unary.Unique.Propositional - MAlonzo.Code.Data.List.Relation.Unary.Unique.DecPropositional - MAlonzo.Code.Data.List.Relation.Unary.Unique.Propositional.Properties - MAlonzo.Code.Data.List.Relation.Unary.Unique.Propositional.Properties.WithK - MAlonzo.Code.Data.List.Relation.Unary.Unique.Setoid.Properties - MAlonzo.Code.Data.List.Relation.Unary.Linked.Properties - MAlonzo.Code.Data.List.Relation.Unary.Any - MAlonzo.Code.Data.List.Relation.Unary.Linked - MAlonzo.Code.Data.List.Extrema.Core - MAlonzo.Code.Data.Unit - MAlonzo.Code.Data.Relation.Nullary.Decidable.Ext - MAlonzo.Code.Data.Rational - MAlonzo.Code.Data.Sum.Base - MAlonzo.Code.Data.Sum.Effectful.Left - MAlonzo.Code.Data.Sum.Algebra - MAlonzo.Code.Data.Sum.Relation.Unary.All - MAlonzo.Code.Data.Sum.Relation.Binary.Pointwise - MAlonzo.Code.Data.Sum.Function.Propositional - MAlonzo.Code.Data.Sum.Function.Setoid - MAlonzo.Code.Data.Sum.Properties - MAlonzo.Code.Data.Nat - MAlonzo.Code.Data.Maybe - MAlonzo.Code.Data.Word.Base - MAlonzo.Code.Data.Word.Properties - MAlonzo.Code.Data.Record - MAlonzo.Code.Data.Float - MAlonzo.Code.Data.Bool.Show - MAlonzo.Code.Data.Bool.Base - MAlonzo.Code.Data.Bool.Properties - MAlonzo.Code.Data.Refinement - MAlonzo.Code.Data.Word - MAlonzo.Code.Data.Sign.Properties - MAlonzo.Code.Data.Sign.Base + MAlonzo.Code.Reflection + MAlonzo.Code.Foreign.Convertible + MAlonzo.Code.Foreign.Convertible.Deriving + MAlonzo.Code.Foreign.Haskell + MAlonzo.Code.Foreign.Haskell.Pair + MAlonzo.Code.Foreign.Haskell.Coerce + MAlonzo.Code.Foreign.Haskell.Either + MAlonzo.Code.Foreign.Haskell.List.NonEmpty MAlonzo.Code.Function - MAlonzo.RTE.Float + MAlonzo.Code.MetaPrelude diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 000000000..c095f5b4b --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,27 @@ +{ + "agda-nixpkgs": { + "branch": "nixpkgs-unstable", + "description": "Nix Packages collection", + "homepage": "", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7148a46c2a1163faecb2915f5f1e6e6c43bcd3ee", + "sha256": "1aygdbj86xiyalgy21xk4gzgvjphhm7dr0ni1j4n32rmziwr4r97", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/7148a46c2a1163faecb2915f5f1e6e6c43bcd3ee.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "release-21.05", + "description": "Nix Packages collection", + "homepage": "", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7148a46c2a1163faecb2915f5f1e6e6c43bcd3ee", + "sha256": "1aygdbj86xiyalgy21xk4gzgvjphhm7dr0ni1j4n32rmziwr4r97", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/7148a46c2a1163faecb2915f5f1e6e6c43bcd3ee.tar.gz", + "url_template": "https://github.com///archive/.tar.gz", + "version": "21.11.337905.902d91def1e" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/scripts/bump-executable-spec.sh b/scripts/bump-executable-spec.sh new file mode 100755 index 000000000..d4cb96e3f --- /dev/null +++ b/scripts/bump-executable-spec.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +set -e + +EXEC_SPEC_REPO_DIR=$1 +if [ ! $EXEC_SPEC_REPO_DIR ]; then + echo "No repository path provided." + echo "Usage: ./bump-executable-spec.sh EXEC_SPEC_REPO_DIR [LEDGER_REPO_DIR]" + exit 1 +fi + +AGDA_COMMIT=$(git rev-parse HEAD) +echo "Building executable spec.." +nix-build -A ledger.hsSrc +EXEC_SPEC_OUT=$(readlink -f result/haskell/Ledger) + +echo "Entering executable spec repo.." +chmod 755 -R $EXEC_SPEC_REPO_DIR +pushd $EXEC_SPEC_REPO_DIR + +echo "Removing old files.." +FILES_TO_RM=$(git ls-tree -r main --name-only | grep -vE "flake.lock|flake.nix|CHANGELOG.md|.gitignore") +for f in $FILES_TO_RM; do + rm -rf $f +done + +echo "Copying generated files to repo.." +cp -r $EXEC_SPEC_OUT/* . + +git add . +git commit -m "formal-ledger-specification commit $AGDA_COMMIT" || true +popd + +echo "" +echo "" +echo "Created a commit in the executable spec repo for rev $AGDA_COMMIT" + +pushd $EXEC_SPEC_REPO_DIR +git push +EXEC_SPEC_COMMIT=$(git rev-parse HEAD) +popd + +LEDGER_REPO_DIR=$2 +if [ $LEDGER_REPO_DIR ]; then + pushd $LEDGER_REPO_DIR + sed -i "s/tag: .*/tag: $EXEC_SPEC_COMMIT/" cabal.project + sed -i "s/--sha256: .*/--sha256: sha256-0000000000000000000000000000000000000000000=/" cabal.project + popd + echo "Updated cabal.project in cardano-ledger. Replace sha256 with the hash given by 'nix develop'" +fi +echo "Done!" diff --git a/shell.nix b/shell.nix new file mode 100644 index 000000000..5a37091e7 --- /dev/null +++ b/shell.nix @@ -0,0 +1,31 @@ +{ sources ? import ./nix/sources.nix +, pkgs ? import sources.nixpkgs { + overlays = [ ]; + config = { }; + } +}: + +with pkgs; + +let specs = callPackage ./default.nix {}; + +in { + shell = mkShell { + nativeBuildInputs = [ + specs.agdaWithDeps + specs.latex + python3 + ]; + }; + + run.shell = mkShell { + nativeBuildInputs = [ + specs.agda + cabal-install + (haskellPackages.ghcWithPackages (pkgs: with pkgs; [ + specs.ledger.hsExe + specs.midnight.hsExe + ])) + ]; + }; +} diff --git a/src/Algebra/Literals.agda b/src/Algebra/Literals.agda new file mode 100644 index 000000000..bfc5e7147 --- /dev/null +++ b/src/Algebra/Literals.agda @@ -0,0 +1,27 @@ +{-# OPTIONS --without-K --safe #-} + +module Algebra.Literals where + +open import Algebra + +open import Agda.Builtin.FromNat +open import Agda.Builtin.FromNeg +open import Level + +variable a b : Level + +module Semiring-Lit (R : Semiring a b) where + open Semiring R + + open import Data.Unit.Polymorphic + open import Data.Nat using (ℕ; zero; suc) + + private + ℕ→R : ℕ → Carrier + ℕ→R zero = 0# + ℕ→R (suc n) = 1# + ℕ→R n + + instance + number : Number Carrier + number .Number.Constraint = λ _ → ⊤ + number .fromNat = λ n → ℕ→R n diff --git a/src/Algebra/PairOp.agda b/src/Algebra/PairOp.agda new file mode 100644 index 000000000..ec25302bf --- /dev/null +++ b/src/Algebra/PairOp.agda @@ -0,0 +1,55 @@ +{-# OPTIONS --safe #-} + +open import Prelude + +open import Algebra +open import Data.Product.Relation.Binary.Pointwise.NonDependent +open import Relation.Binary + +module Algebra.PairOp (X : Type) (ε : X) (_≈_ : Rel X zeroˡ) (_∙_ : Op₂ X) where + +_∙ᵖ_ : (X × X) → (X × X) → (X × X) +(a , b) ∙ᵖ (c , d) = (a ∙ c) , (b ∙ d) + +_≈ᵖ_ : Rel (X × X) zeroˡ +_≈ᵖ_ = Pointwise _≈_ _≈_ + +pairOpIdentityˡ : + Algebra.LeftIdentity _≈_ ε _∙_ → Algebra.LeftIdentity _≈ᵖ_ (ε , ε) _∙ᵖ_ +pairOpIdentityˡ idˡ (a , b) = ×-refl (idˡ a) (idˡ b) {ε , ε} + +pairOpIdentityʳ : + Algebra.RightIdentity _≈_ ε _∙_ → Algebra.RightIdentity _≈ᵖ_ (ε , ε) _∙ᵖ_ +pairOpIdentityʳ idʳ (a , b) = ×-refl (idʳ a) (idʳ b) {ε , ε} + +pairOpIdentity : Algebra.Identity _≈_ ε _∙_ → Algebra.Identity _≈ᵖ_ (ε , ε) _∙ᵖ_ +pairOpIdentity (idˡ , idʳ) = (pairOpIdentityˡ idˡ) , (pairOpIdentityʳ idʳ) + +pairOpAssoc : Algebra.Associative _≈_ _∙_ → Algebra.Associative _≈ᵖ_ _∙ᵖ_ +pairOpAssoc assoc (a , b) (c , d) (e , f) = + ×-refl (assoc a c e) (assoc b d f) {ε , ε} + +pairOpIsMonoid : IsMonoid _≈_ _∙_ ε → IsMonoid _≈ᵖ_ _∙ᵖ_ (ε , ε) +pairOpIsMonoid record { isSemigroup = isSemigroup ; identity = identity } = record + { isSemigroup = record + { isMagma = record + { isEquivalence = ×-isEquivalence + (IsMagma.isEquivalence (IsSemigroup.isMagma isSemigroup)) + (IsMagma.isEquivalence (IsSemigroup.isMagma isSemigroup)) + ; ∙-cong = λ (p , q) (p′ , q′) + → IsMagma.∙-cong (IsSemigroup.isMagma isSemigroup) p p′ + , IsMagma.∙-cong (IsSemigroup.isMagma isSemigroup) q q′ + } + ; assoc = pairOpAssoc (IsSemigroup.assoc isSemigroup) + } + ; identity = pairOpIdentity identity + } + +pairOpComm : Algebra.Commutative _≈_ _∙_ → Algebra.Commutative _≈ᵖ_ _∙ᵖ_ +pairOpComm comm (a , b) (c , d) = + ×-refl (comm a c) (comm b d) {ε , ε} + +pairOpRespectsComm : + IsCommutativeMonoid _≈_ _∙_ ε → IsCommutativeMonoid _≈ᵖ_ _∙ᵖ_ (ε , ε) +pairOpRespectsComm record { isMonoid = isMonoid ; comm = comm } = record + { isMonoid = pairOpIsMonoid isMonoid ; comm = pairOpComm comm } diff --git a/src/Axiom/Set.agda b/src/Axiom/Set.agda new file mode 100644 index 000000000..84e005be6 --- /dev/null +++ b/src/Axiom/Set.agda @@ -0,0 +1,366 @@ +{-# OPTIONS --safe --no-import-sorts #-} + +module Axiom.Set where + +open import Prelude hiding (map) + +import Function.Related.Propositional as R +open import Data.List.Ext.Properties using (∈-dedup; _×-cong_) +open import Data.List.Relation.Unary.Any using (here; there) +open import Data.List.Relation.Unary.Unique.DecPropositional.Properties using (deduplicate-!) +open import Data.List.Relation.Unary.Unique.Propositional using (Unique; []) +open import Data.Product.Algebra using (×-comm) +open import Data.Product.Properties using (∃∃↔∃∃) +open import Data.Product.Properties.Ext using (∃-cong′; ∃-≡) +open import Class.DecEq using (DecEq; _≟_) +open import Relation.Binary using () renaming (Decidable to Dec₂) + +private variable + ℓ : Level + A B C : Type ℓ + P : A → Type + l : List A + +_Preserves₁_⟶_ : {A : Type ℓ} → (A → B) → Pred A 0ℓ → Pred B 0ℓ → Type ℓ +f Preserves₁ P ⟶ Q = ∀ {a} → P a → Q (f a) + +_Preserves₁₂_⟶_⟶_ : {A B : Type ℓ} → (A → B → C) → Pred A ℓ → Pred B ℓ → Pred C ℓ → Type ℓ +f Preserves₁₂ P ⟶ P' ⟶ Q = ∀ {a b} → P a → P' b → Q (f a b) + +record SpecProperty {ℓ} : Type (sucˡ ℓ) where + field specProperty : {A : Type ℓ} → (A → Type) → Type + sp-∘ : specProperty P → (f : B → A) → specProperty (P ∘ f) + sp-¬ : specProperty P → specProperty (¬_ ∘ P) + +Dec-SpecProperty : SpecProperty +Dec-SpecProperty = record + { specProperty = Decidable¹ + ; sp-∘ = λ P? → P? ∘_ + ; sp-¬ = λ P? → ¬? ∘ P? + } + +record Theory {ℓ} : Type (sucˡ ℓ) where + infix 4 _⊆_ _≡ᵉ_ _∈_ _∉_ + infixr 6 _∪_ + + field Set : Type ℓ → Type ℓ + _∈_ : A → Set A → Type + sp : SpecProperty + open SpecProperty sp public + + _⊆_ : Set A → Set A → Type ℓ + X ⊆ Y = ∀ {a} → a ∈ X → a ∈ Y + + -- we might want to either have all properties or + -- decidable properties allowed for specification + field specification : (X : Set A) + → specProperty P → ∃[ Y ] ∀ {a} → (P a × a ∈ X) ⇔ a ∈ Y + unions : (X : Set (Set A)) + → ∃[ Y ] ∀ {a} → (∃[ T ] (T ∈ X × a ∈ T)) ⇔ a ∈ Y + replacement : (f : A → B) (X : Set A) + → ∃[ Y ] ∀ {b} → (∃[ a ] b ≡ f a × a ∈ X) ⇔ b ∈ Y + listing : (l : List A) + → ∃[ X ] ∀ {a} → a ∈ˡ l ⇔ a ∈ X + -- ^ equivalent to pairing + empty set + -- power-set : (X : Set A) → ∃[ Y ] ∀ {T} → T ⊆ X → T ∈ Y + + private variable X X' Y : Set A + + _≡ᵉ_ : Set A → Set A → Type ℓ + X ≡ᵉ Y = X ⊆ Y × Y ⊆ X + + _≡ᵉ'_ : Set A → Set A → Type ℓ + X ≡ᵉ' Y = ∀ a → a ∈ X ⇔ a ∈ Y + + _∉_ : A → Set A → Type + _∉_ = ¬_ ∘₂ _∈_ + + ≡→∈ : {X : Set A}{a a' : A} → a ∈ X → a ≡ a' → a' ∈ X + ≡→∈ a∈X refl = a∈X + + -- The following is useful in case we have `(a , p)` and `(a , q)`, where `p` + -- and `q` are proofs of `a ∈ X`, and we want to prove `(a , p) ≡ (a , q)`. + ∈-irrelevant : Set A → Type ℓ + ∈-irrelevant X = ∀ {a} (p q : a ∈ X) → p ≡ q + + open Equivalence + + _Preservesˢ_ : (Set A → Set B) → (∀ {A} → Set A → Type) → Type ℓ + f Preservesˢ P = f Preserves₁ P ⟶ P + + _Preservesˢ₂_ : (Set A → Set B → Set C) → (∀ {A : Type ℓ} → Set A → Type ℓ) → Type ℓ + f Preservesˢ₂ P = f Preserves₁₂ P ⟶ P ⟶ P + + disjoint : Set A → Set A → Type ℓ + disjoint X Y = ∀ {a} → a ∈ X → a ∈ Y → ⊥ + + finite : Set A → Type ℓ + finite X = ∃[ l ] ∀ {a} → a ∈ X ⇔ a ∈ˡ l + + weakly-finite : Set A → Type ℓ + weakly-finite X = ∃[ l ] ∀ {a} → a ∈ X → a ∈ˡ l + + -- there exists a list without duplicates that has exactly the members of the set + strongly-finite : Set A → Type ℓ + strongly-finite X = ∃[ l ] Unique l × ∀ {a} → a ∈ X ⇔ a ∈ˡ l + + DecEq∧finite⇒strongly-finite : ⦃ _ : DecEq A ⦄ (X : Set A) + → finite X → strongly-finite X + DecEq∧finite⇒strongly-finite ⦃ eq? ⦄ X (l , h) = let _≟_ = eq? ._≟_ in + deduplicate _≟_ l , deduplicate-! _≟_ l , λ {a} → + a ∈ X ∼⟨ h ⟩ + a ∈ˡ l ∼⟨ ∈-dedup ⟩ + a ∈ˡ deduplicate _≟_ l ∎ + where open R.EquationalReasoning + + card : Σ (Set A) strongly-finite → ℕ + card (_ , l , _) = length l + + ⊆-weakly-finite : X ⊆ Y → weakly-finite Y → weakly-finite X + ⊆-weakly-finite X⊆Y (l , hl) = l , hl ∘ X⊆Y + + isMaximal : Set A → Type ℓ + isMaximal {A} X = {a : A} → a ∈ X + + maximal-⊆ : isMaximal Y → X ⊆ Y + maximal-⊆ maxY _ = maxY + + maximal-unique : isMaximal X → isMaximal Y → X ≡ᵉ Y + maximal-unique maxX maxY = maximal-⊆ maxY , maximal-⊆ maxX + + FinSet : Type ℓ → Type ℓ + FinSet A = Σ (Set A) finite + + -- if you can construct a set that contains all elements satisfying + -- P, you can construct a set containing exactly the elements satisfying P + strictify : specProperty P → (∃[ Y ] ∀ {a} → P a → a ∈ Y) → ∃[ Y ] ∀ {a} → P a ⇔ a ∈ Y + strictify sp p with specification (proj₁ p) sp + ... | (Y , p') = Y , (mk⇔ (λ a∈l → to p' (a∈l , proj₂ p a∈l)) (proj₁ ∘ from p')) + + map : (A → B) → Set A → Set B + map = proj₁ ∘₂ replacement + + ∈-map : ∀ {f : A → B} {b} → (∃[ a ] b ≡ f a × a ∈ X) ⇔ b ∈ map f X + ∈-map = proj₂ $ replacement _ _ + + ∈-map′ : ∀ {f : A → B} {a} → a ∈ X → f a ∈ map f X + ∈-map′ {a = a} a∈X = to ∈-map (a , refl , a∈X) + + -- don't know that there's a set containing all members of a type, which this is equivalent to + -- _⁻¹_ : (A → B) → Set B → Set A + -- f ⁻¹ X = {!!} + + filter : {P : A → Type} → specProperty P → Set A → Set A + filter = proj₁ ∘₂ flip specification + + ∈-filter : ∀ {sp-P : specProperty P} {a} → (P a × a ∈ X) ⇔ a ∈ filter sp-P X + ∈-filter = proj₂ $ specification _ _ + + fromList : List A → Set A + fromList = proj₁ ∘ listing + + ∈-fromList : ∀ {a} → a ∈ˡ l ⇔ a ∈ fromList l + ∈-fromList = proj₂ $ listing _ + + ∈-unions : {a : A} {U : Set (Set A)} → (∃[ T ] T ∈ U × a ∈ T) ⇔ a ∈ proj₁ (unions U) + ∈-unions = proj₂ $ unions _ + + ∅ : Set A + ∅ = fromList [] + + ∅-strongly-finite : strongly-finite {A} ∅ + ∅-strongly-finite = [] , [] , R.SK-sym ∈-fromList + + card-∅ : card (∅ {A} , ∅-strongly-finite) ≡ 0 + card-∅ = refl + + singleton : A → Set A + singleton a = fromList [ a ] + + ❴_❵ = singleton + + ∈-singleton : {a b : A} → a ≡ b ⇔ a ∈ singleton b + ∈-singleton {_} {a} {b} = + a ≡ b ∼⟨ mk⇔ (λ where refl → here refl) (λ where (here refl) → refl) ⟩ + a ∈ˡ [ b ] ∼⟨ ∈-fromList ⟩ + a ∈ singleton b ∎ + where open R.EquationalReasoning + + partialToSet : (A → Maybe B) → A → Set B + partialToSet f a = maybe (fromList ∘ [_]) ∅ (f a) + + ∈-partialToSet : ∀ {a : A} {b : B} {f} → f a ≡ just b ⇔ b ∈ partialToSet f a + ∈-partialToSet {a = a} {b} {f} = mk⇔ + (λ h → subst (λ x → b ∈ maybe (fromList ∘ [_]) ∅ x) (sym h) (to ∈-singleton refl)) + (case f a returning (λ y → b ∈ maybe (λ x → fromList [ x ]) ∅ y → y ≡ just b) of + λ where (just x) → λ h → cong just (sym $ from ∈-singleton h) + nothing → λ h → case from ∈-fromList h of λ ()) + + concatMapˢ : (A → Set B) → Set A → Set B + concatMapˢ f a = proj₁ $ unions (map f a) + + ∈-concatMapˢ : {y : B} {f : A → Set B} + → (∃[ x ] x ∈ X × y ∈ f x) ⇔ y ∈ concatMapˢ f X + ∈-concatMapˢ {X = X} {y} {f} = + (∃[ x ] x ∈ X × y ∈ f x) + ∼⟨ ∃-cong′ (λ {x} → ∃-≡ (λ T → x ∈ X × y ∈ T)) ⟩ + (∃[ x ] ∃[ T ] T ≡ f x × x ∈ X × y ∈ T) + ↔⟨ ∃∃↔∃∃ (λ x T → T ≡ f x × x ∈ X × y ∈ T) ⟩ + (∃[ T ] ∃[ x ] T ≡ f x × x ∈ X × y ∈ T) + ∼⟨ ∃-cong′ $ mk⇔ + (λ where (x , p₁ , p₂ , p₃) → (x , p₁ , p₂) , p₃) + (λ where ((x , p₁ , p₂) , p₃) → x , p₁ , p₂ , p₃) ⟩ + (∃[ T ] (∃[ x ] T ≡ f x × x ∈ X) × y ∈ T) + ∼⟨ ∃-cong′ (∈-map ×-cong R.K-refl) ⟩ + (∃[ T ] T ∈ map f X × y ∈ T) + ∼⟨ ∈-unions ⟩ + y ∈ concatMapˢ f X ∎ + where open R.EquationalReasoning + + mapPartial : (A → Maybe B) → Set A → Set B + mapPartial f = concatMapˢ (partialToSet f) + + ∈-mapPartial : {y : B} {f : A → Maybe B} + → (∃[ x ] x ∈ X × f x ≡ just y) ⇔ y ∈ mapPartial f X + ∈-mapPartial {X = X} {y} {f} = + (∃[ x ] x ∈ X × f x ≡ just y) + ∼⟨ ∃-cong′ (R.K-refl ×-cong (∈-partialToSet {f = f})) ⟩ + (∃[ x ] x ∈ X × y ∈ partialToSet f x) + ∼⟨ ∈-concatMapˢ ⟩ + y ∈ mapPartial f X ∎ + where open R.EquationalReasoning + + ⊆-mapPartial : ∀ {f : A → Maybe B} → map just (mapPartial f X) ⊆ map f X + ⊆-mapPartial {f = f} a∈m with from ∈-map a∈m + ... | x , refl , a∈mp with from (∈-mapPartial {f = f}) a∈mp + ... | x' , x'∈X , jx≡fx = to ∈-map (x' , sym jx≡fx , x'∈X) + + binary-unions : ∃[ Y ] ∀ {a} → (a ∈ X ⊎ a ∈ X') ⇔ a ∈ Y + binary-unions {X = X} {X'} with unions (fromList (X ∷ [ X' ])) + ... | (Y , h) = Y , mk⇔ (λ where + (inj₁ a∈X) → to h (X , to ∈-fromList (here refl) , a∈X) + (inj₂ a∈X') → to h (X' , to ∈-fromList (there (here refl)) , a∈X')) + (λ a∈Y → case from h a∈Y of λ (T , H , a∈T) → case from ∈-fromList H of λ where + (here refl) → inj₁ a∈T + (there (here refl)) → inj₂ a∈T) + + _∪_ : Set A → Set A → Set A + X ∪ Y = proj₁ binary-unions + + ∈-∪ : ∀ {a} → (a ∈ X ⊎ a ∈ Y) ⇔ a ∈ X ∪ Y + ∈-∪ = proj₂ binary-unions + + spec-∈ : Type ℓ → Type ℓ + spec-∈ A = {X : Set A} → specProperty (_∈ X) + + -- membership needs to be a specProperty to have intersections + module Intersection (sp-∈ : spec-∈ A) where + + infixr 7 _∩_ + _∩_ : Set A → Set A → Set A + X ∩ Y = filter sp-∈ X + + ∈-∩ : ∀ {a} → (a ∈ X × a ∈ Y) ⇔ a ∈ X ∩ Y + ∈-∩ {X} {Y} {a} = (a ∈ X × a ∈ Y) ↔⟨ ×-comm _ _ ⟩ + (a ∈ Y × a ∈ X) ∼⟨ ∈-filter ⟩ + a ∈ X ∩ Y ∎ + where open R.EquationalReasoning + + disjoint' : Set A → Set A → Type ℓ + disjoint' X Y = X ∩ Y ≡ᵉ ∅ + + _\_ : Set A → Set A → Set A + X \ Y = filter (sp-¬ (sp-∈ {Y})) X + + All : (A → Type) → Set A → Type ℓ + All P X = ∀ {a} → a ∈ X → P a + + Any : (A → Type) → Set A → Type ℓ + Any P X = ∃[ a ] a ∈ X × P a + +-- finite set theories +record Theoryᶠ : Type₁ where + field theory : Theory + open Theory theory public + + field finiteness : (X : Set A) → finite X + + DecEq⇒strongly-finite : ⦃ DecEq A ⦄ → (X : Set A) → strongly-finite X + DecEq⇒strongly-finite X = DecEq∧finite⇒strongly-finite X (finiteness X) + + lengthˢ : ⦃ DecEq A ⦄ → Set A → ℕ + lengthˢ X = card (X , DecEq⇒strongly-finite X) + +-- set theories with an infinite set (containing all natural numbers) +record Theoryⁱ : Type₁ where + field theory : Theory + open Theory theory public + + field infinity : ∃[ Y ] ((n : ℕ) → n ∈ Y) + +-- theories with decidable properties +record Theoryᵈ : Type₁ where + field th : Theory + open Theory th public + open Equivalence + + field + ∈-sp : ⦃ DecEq A ⦄ → spec-∈ A + _∈?_ : ⦃ DecEq A ⦄ → Decidable² (_∈_ {A = A}) + all? : {P : A → Type} (P? : Decidable¹ P) {X : Set A} → Dec (All P X) + any? : {P : A → Type} (P? : Decidable¹ P) (X : Set A) → Dec (Any P X) + + + module _ {A : Type} {P : A → Type} where + module _ ⦃ _ : P ⁇¹ ⦄ where instance + Dec-Allˢ : All P ⁇¹ + Dec-Allˢ = ⁇¹ λ x → all? dec¹ {x} + + Dec-Anyˢ : Any P ⁇¹ + Dec-Anyˢ = ⁇¹ any? dec¹ + + module _ (P? : Decidable¹ P) where + allᵇ anyᵇ : (X : Set A) → Bool + allᵇ X = ⌊ all? P? {X} ⌋ + anyᵇ X = ⌊ any? P? X ⌋ + + module _ {A : Type} ⦃ _ : DecEq A ⦄ where + + _∈ᵇ_ : A → Set A → Bool + a ∈ᵇ X = ⌊ a ∈? X ⌋ + + instance + Dec-∈ : _∈_ {A = A} ⁇² + Dec-∈ = ⁇² _∈?_ + + _ = _∈_ {A = A} ⁇² ∋ it + _ = _⊆_ {A = A} ⁇² ∋ it + _ = _≡ᵉ_ {A = A} ⁇² ∋ it + + incl-set' : (X : Set A) → A → Maybe (∃[ a ] a ∈ X) + incl-set' X x with x ∈? X + ... | yes p = just (x , p) + ... | no p = nothing + + incl-set : (X : Set A) → Set (∃[ a ] a ∈ X) + incl-set X = mapPartial (incl-set' X) X + + module _ {X : Set A} where + incl-set-proj₁⊆ : map proj₁ (incl-set X) ⊆ X + incl-set-proj₁⊆ x with from ∈-map x + ... | (_ , pf) , refl , _ = pf + + incl-set-proj₁⊇ : X ⊆ map proj₁ (incl-set X) + incl-set-proj₁⊇ {x} x∈X with x ∈? X in eq + ... | no ¬p = contradiction x∈X ¬p + ... | yes p = to ∈-map + ( (x , p) + , refl + , to (∈-mapPartial {f = incl-set' X}) (x , x∈X , helper eq) + ) + where helper : x ∈? X ≡ yes p → incl-set' X x ≡ just (x , p) + helper h with x ∈? X | h + ... | _ | refl = refl + + incl-set-proj₁ : map proj₁ (incl-set X) ≡ᵉ X + incl-set-proj₁ = incl-set-proj₁⊆ , incl-set-proj₁⊇ diff --git a/src/Axiom/Set/Factor.agda b/src/Axiom/Set/Factor.agda new file mode 100644 index 000000000..77607b271 --- /dev/null +++ b/src/Axiom/Set/Factor.agda @@ -0,0 +1,74 @@ +{-# OPTIONS --safe --no-import-sorts #-} + +open import Prelude +open import Axiom.Set + +module Axiom.Set.Factor (th : Theory {lzero}) where + +open Theory th +open import Axiom.Set.Properties th + +import Function.Related.Propositional as R +open import Data.List.Ext.Properties +open import Data.List.Membership.Propositional using () renaming (_∈_ to _∈ˡ_) +open import Data.List.Relation.Binary.BagAndSetEquality +open import Data.List.Relation.Binary.Disjoint.Propositional +open import Data.List.Relation.Binary.Permutation.Propositional +open import Data.List.Relation.Unary.Unique.DecPropositional.Properties +open import Data.List.Relation.Unary.Unique.Propositional +open import Data.List.Relation.Unary.Unique.Propositional.Properties.WithK +open import Class.DecEq +open import Relation.Binary + +open Equivalence + +private variable A B : Type + +_ᶠ : (X : Set A) → ⦃ finite X ⦄ → FinSet A +_ᶠ X ⦃ Xᶠ ⦄ = X , Xᶠ + +instance + ∪-preserves-finite' : {X Y : Set A} → ⦃ finite X ⦄ → ⦃ finite Y ⦄ → finite (X ∪ Y) + ∪-preserves-finite' ⦃ Xᶠ ⦄ ⦃ Yᶠ ⦄ = ∪-preserves-finite Xᶠ Yᶠ + +module Factor (_≈_ : B → B → Type) (f : List A → B) (f-cong : ∀ {l l'} → l ∼[ set ] l' → f l ≈ f l') where + + factor : FinSet A → B + factor (_ , l , _) = f l + + factor-cong : factor Preserves (_≡ᵉ_ on proj₁) ⟶ _≈_ + factor-cong {X , Xˡ , hX} {Y , Yˡ , hY} X≡ᵉY = f-cong λ {a} → + a ∈ˡ Xˡ ∼⟨ R.SK-sym hX ⟩ a ∈ X ∼⟨ to ≡ᵉ⇔≡ᵉ' X≡ᵉY _ ⟩ + a ∈ Y ∼⟨ hY ⟩ a ∈ˡ Yˡ ∎ + where open R.EquationalReasoning + + factor-∪ : ∀ {R : B → B → B → Type} {X Y : Set A} ⦃ Xᶠ : finite X ⦄ ⦃ Yᶠ : finite Y ⦄ + → (∀ {l l'} → R (f l) (f l') (f (l ++ l'))) + → R (factor (X ᶠ)) (factor (Y ᶠ)) (factor ((X ∪ Y) ᶠ)) + factor-∪ hR = hR + +module FactorUnique ⦃ _ : DecEq A ⦄ (_≈_ : B → B → Type) (f : (Σ (List A) Unique) → B) + (f-cong : ∀ {l l'} → proj₁ l ↭ proj₁ l' → f l ≈ f l') where + + f-cong' : ∀ {l l'} → (∀ {a} → a ∈ˡ proj₁ l ⇔ a ∈ˡ proj₁ l') → f l ≈ f l' + f-cong' {l} {l'} h = f-cong (∼bag⇒↭ (unique∧set⇒bag (proj₂ l) (proj₂ l') h)) + + deduplicate-Σ : List A → Σ (List A) Unique + deduplicate-Σ l = (deduplicate _≟_ l , deduplicate-! _≟_ _) + + ext : List A → B + ext = f ∘ deduplicate-Σ + + ext-cong : ∀ {l l'} → l ∼[ set ] l' → ext l ≈ ext l' + ext-cong {l} {l'} h = f-cong' λ {a} → + a ∈ˡ deduplicate _≟_ l ∼⟨ R.SK-sym ∈-dedup ⟩ a ∈ˡ l ∼⟨ h ⟩ + a ∈ˡ l' ∼⟨ ∈-dedup ⟩ a ∈ˡ deduplicate _≟_ l' ∎ + where open R.EquationalReasoning + + open Factor _≈_ ext ext-cong public + + factor-∪' : ∀ {R : B → B → B → Type} {X Y : Set A} ⦃ Xᶠ : finite X ⦄ ⦃ Yᶠ : finite Y ⦄ + → disjoint X Y + → (∀ {l l'} → Disjoint l l' → R (ext l) (ext l') (ext (l ++ l'))) + → R (factor (X ᶠ)) (factor (Y ᶠ)) (factor ((X ∪ Y) ᶠ)) + factor-∪' ⦃ _ , Xᶠ ⦄ ⦃ _ , Yᶠ ⦄ disj hR = hR λ where (a∈X , a∈Y) → ⊥-elim $ disj (from Xᶠ a∈X) (from Yᶠ a∈Y) diff --git a/src/Axiom/Set/List.agda b/src/Axiom/Set/List.agda new file mode 100644 index 000000000..b74e78846 --- /dev/null +++ b/src/Axiom/Set/List.agda @@ -0,0 +1,65 @@ +{-# OPTIONS --safe --no-import-sorts #-} + +module Axiom.Set.List where + +open import Prelude hiding (find) + +open import Axiom.Set + +open import Data.List using (filter) +import Data.List.Relation.Unary.All as All +import Data.List.Relation.Unary.Any as Any +import Function +import Function.Properties.Inverse as I +import Function.Related.Propositional as R +import Relation.Nullary.Decidable as Dec +open import Data.List.Membership.Propositional using (find; lose) renaming (_∈_ to _∈ˡ_) +open import Data.List.Membership.Propositional.Properties +open import Data.Product +open import Data.Product.Algebra +open import Data.Product.Properties.Ext +open import Class.DecEq +open import Relation.Binary using () renaming (Decidable to Dec₂) +open import Relation.Nullary.Decidable + +List-Model : Theory +List-Model = λ where + .Set → List + ._∈_ → _∈ˡ_ + .sp → Dec-SpecProperty + .specification → λ X P? → filter P? X , mk⇔ + (λ where (Pa , a∈X) → ∈-filter⁺ P? a∈X Pa) + (λ a∈f → Data.Product.swap (∈-filter⁻ P? a∈f)) + .unions → λ X → concat X , mk⇔ + (λ where (T , T∈X , a∈T) → ∈-concat⁺′ a∈T T∈X) + (λ a∈cX → case ∈-concat⁻′ _ a∈cX of λ where (T , a∈T , T∈X) → (T , T∈X , a∈T)) + .replacement → λ f X → Data.List.map f X , λ {b} → + (∃[ a ] b ≡ f a × a ∈ˡ X) ∼⟨ ∃-cong′ (I.↔⇒⇔ (×-comm _ _)) ⟩ + (∃[ a ] a ∈ˡ X × b ≡ f a) ⤖⟨ I.↔⇒⤖ (map-∈↔ f) ⟩ + b ∈ˡ Data.List.map f X ∎ + .listing → λ l → l , mk⇔ id id + where open Theory hiding (filter) + open R.EquationalReasoning + +List-Modelᶠ : Theoryᶠ +List-Modelᶠ = λ where + .theory → List-Model + .finiteness → λ X → X , mk⇔ id id + where open Theoryᶠ + +module Decˡ {A : Type} ⦃ _ : DecEq A ⦄ where + open Theory List-Model + + _∈?_ : Dec₂ (_∈ˡ_ {A = A}) + _∈?_ a = Any.any? (a ≟_) + + DecEq-Set : DecEq (Set A) + DecEq-Set = DecEq-List + +List-Modelᵈ : Theoryᵈ +List-Modelᵈ = record + { th = List-Model + ; ∈-sp = Decˡ._∈? _ + ; _∈?_ = Decˡ._∈?_ + ; all? = λ P? {X} → Dec.map (mk⇔ All.lookup All.tabulate) (All.all? P? X) + ; any? = λ P? X → Dec.map (mk⇔ find (uncurry lose ∘ proj₂)) (Any.any? P? X) } diff --git a/src/Axiom/Set/Map.agda b/src/Axiom/Set/Map.agda new file mode 100644 index 000000000..3d12497c2 --- /dev/null +++ b/src/Axiom/Set/Map.agda @@ -0,0 +1,386 @@ +{-# OPTIONS --safe --no-import-sorts #-} +{-# OPTIONS -v allTactics:100 #-} + +open import Prelude +open import Axiom.Set using (Theory) + +module Axiom.Set.Map (th : Theory {lzero}) where + +open Theory th renaming (map to mapˢ) + +open import Axiom.Set.Rel th hiding (_∣'_; _∣^'_) +open import Axiom.Set.Properties th + +import Data.Sum as ⊎ +open import Data.List.Ext.Properties using (AllPairs⇒≡∨R∨Rᵒᵖ) +open import Data.Product.Ext using (×-dup) +open import Data.Product.Properties using (×-≡,≡→≡; ×-≡,≡←≡) +open import Data.Maybe.Properties using (just-injective) +open import Relation.Unary using (Decidable) +import Relation.Binary.PropositionalEquality as I +import Relation.Binary.Reasoning.Setoid as SetoidReasoning + +open Equivalence + +open import Class.DecEq using (DecEq; _≟_) + +open import Reflection.Tactic using (initTac) +open import Tactic.AnyOf +open import Tactic.Assumption +open import Tactic.Defaults +open import Tactic.ByEq + +-- Because of missing macro hygiene, we have to copy&paste this. +-- c.f. https://github.com/agda/agda/issues/3819 +private macro + ∈⇒P = anyOfⁿᵗ + (quote ∈-filter⁻' ∷ quote ∈-∪⁻ ∷ quote ∈-map⁻' ∷ quote ∈-fromList⁻ ∷ []) + P⇒∈ = anyOfⁿᵗ + (quote ∈-filter⁺' ∷ quote ∈-∪⁺ ∷ quote ∈-map⁺' ∷ quote ∈-fromList⁺ ∷ []) + ∈⇔P = anyOfⁿᵗ + ( quote ∈-filter⁻' ∷ quote ∈-∪⁻ ∷ quote ∈-map⁻' ∷ quote ∈-fromList⁻ + ∷ quote ∈-filter⁺' ∷ quote ∈-∪⁺ ∷ quote ∈-map⁺' ∷ quote ∈-fromList⁺ ∷ []) + +private variable + A A' B B' C D : Type + R R' : Rel A B + X Y : Set A + a : A + a' : A' + b : B + b' : B' + +left-unique : Rel A B → Type +left-unique R = ∀ {a b b'} → (a , b) ∈ R → (a , b') ∈ R → b ≡ b' + +record IsLeftUnique (R : Rel A B) : Type where + field isLeftUnique : left-unique R + +instance + ∅-left-unique : IsLeftUnique {A = A} {B = B} ∅ + ∅-left-unique .IsLeftUnique.isLeftUnique h h' = ⊥-elim $ ∉-∅ h + +⊆-left-unique : R ⊆ R' → left-unique R' → left-unique R +⊆-left-unique R⊆R' h = R⊆R' -⟨ h ⟩- R⊆R' -- on isn't dependent enough + +left-unique-mapˢ : {f : A → B} (X : Set A) → left-unique (mapˢ (λ y → (y , f y)) X) +left-unique-mapˢ _ p q with from ∈-map p | from ∈-map q +... | _ , refl , _ | _ , refl , _ = refl + +Map : Type → Type → Type +Map A B = Σ (Rel A B) left-unique + +_≡ᵐ_ : Map A B → Map A B → Type +(x , _) ≡ᵐ (y , _) = x ≡ᵉ y + +private variable m m' : Map A B + +_ˢ : Map A B → Rel A B +_ˢ = proj₁ + +_ᵐ : (R : Rel A B) → ⦃ IsLeftUnique R ⦄ → Map A B +_ᵐ R ⦃ record { isLeftUnique = h } ⦄ = R , h + +infix 4 _≡ᵉᵐ_ + +_≡ᵉᵐ_ : Map A B → Map A B → Type +_≡ᵉᵐ_ = _≡ᵉ_ on _ˢ + +⊆-map : (f : Rel A B → Rel A B) → (∀ {R} → f R ⊆ R) → Map A B → Map A B +⊆-map f H m = f (m ˢ) , ⊆-left-unique H (proj₂ m) + +ˢ-left-unique : IsLeftUnique (m ˢ) +ˢ-left-unique {m = m} = record { isLeftUnique = proj₂ m } + +instance + _ = ˢ-left-unique + +∅ᵐ : Map A B +∅ᵐ = _ᵐ ∅ ⦃ ∅-left-unique ⦄ + +fromListᵐ : ⦃ _ : DecEq A ⦄ → List (A × B) → Map A B +fromListᵐ l = fromList (deduplicate (λ x y → proj₁ x ≟ proj₁ y) l) , + (λ where (inj₁ refl) → refl + (inj₂ (inj₁ x)) → ⊥-elim (x refl) + (inj₂ (inj₂ x)) → ⊥-elim (x refl)) + ∘₂ (∈⇒P -⟨ AllPairs⇒≡∨R∨Rᵒᵖ + $ deduplicate-! (On.decSetoid (Prelude.decSetoid _≟_) proj₁) l ⟩- ∈⇒P) + where open import Data.List.Relation.Unary.Unique.DecSetoid.Properties + open import Relation.Binary.Construct.On as On + +FinMap : Type → Type → Type +FinMap A B = Σ (Rel A B) (λ R → left-unique R × finite R) + +toFinMap : (m : Map A B) → finite (m ˢ) → FinMap A B +toFinMap (m , h) fin = m , h , fin + +toMap : FinMap A B → Map A B +toMap (m , l , _) = m , l + +toRel : FinMap A B → Rel A B +toRel (m , l , _) = m + +module Intersectionᵐ (sp-∈ : spec-∈ (A × B)) where + open Intersection sp-∈ + open Intersectionᵖ sp-∈ + + _∩ᵐ_ : Map A B → Map A B → Map A B + m ∩ᵐ m' = (m ˢ ∩ m' ˢ , ⊆-left-unique ∩-⊆ˡ (proj₂ m)) + +disj-∪ : (m m' : Map A B) → disjoint (dom (m ˢ)) (dom (m' ˢ)) → Map A B +disj-∪ m m' disj = m ˢ ∪ m' ˢ , λ h h' → case ∈⇔P h , ∈⇔P h' of λ where + (inj₁ hm , inj₁ h'm) → proj₂ m hm h'm + (inj₂ hm' , inj₁ h'm) → ⊥-elim $ disj (∈-map⁺'' h'm) (∈-map⁺'' hm') + (inj₁ hm , inj₂ h'm') → ⊥-elim $ disj (∈-map⁺'' hm) (∈-map⁺'' h'm') + (inj₂ hm' , inj₂ h'm') → proj₂ m' hm' h'm' + +filterᵐ : {P : Pred (A × B) 0ℓ} → specProperty P → Map A B → Map A B +filterᵐ sp-P m = filter sp-P (m ˢ) , ⊆-left-unique filter-⊆ (proj₂ m) + +filterᵐ-finite : {P : A × B → Type} → (sp : specProperty P) → Decidable P + → finite (m ˢ) → finite (filterᵐ sp m ˢ) +filterᵐ-finite = filter-finite + +filterKeys : {P : A → Type} → specProperty P → Map A B → Map A B +filterKeys sp-P = filterᵐ (sp-∘ sp-P proj₁) + +singletonᵐ : A → B → Map A B +singletonᵐ a b = ❴ (a , b) ❵ + , (from ∈-singleton -⟨ (λ where refl refl → refl) ⟩- from ∈-singleton) + +❴_❵ᵐ : A × B → Map A B +❴ k , v ❵ᵐ = singletonᵐ k v + +disj-dom : ∀ {m m₁ m₂ : Map A B} + → (m ˢ) ≡ (m₁ ˢ) ⨿ (m₂ ˢ) + → disjoint (dom (m₁ ˢ)) (dom (m₂ ˢ)) +disj-dom {m = m@(_ , uniq)} {m₁} {m₂} (m≡m₁∪m₂ , disj) a∈domm₁ a∈domm₂ + with (a , b₁) , (refl , h₁) ← ∈⇔P a∈domm₁ + with (_ , b₂) , (refl , h₂) ← ∈⇔P a∈domm₂ + = disj (subst _ (uniq (∈mᵢ⇒∈m (inj₁ h₁)) (∈mᵢ⇒∈m (inj₂ h₂))) h₁) h₂ + where + ∈mᵢ⇒∈m : ∀ {a} → a ∈ (m₁ ˢ) ⊎ a ∈ (m₂ ˢ) → a ∈ (m ˢ) + ∈mᵢ⇒∈m = proj₂ m≡m₁∪m₂ ∘ to ∈-∪ + +InjectiveOn : Set A → (A → B) → Type +InjectiveOn X f = ∀ {x y} → x ∈ X → y ∈ X → f x ≡ f y → x ≡ y + +weaken-Injective : ∀ {X : Set A} {f : A → B} → Injective _≡_ _≡_ f → InjectiveOn X f +weaken-Injective p _ _ = p + +mapˡ-uniq : {f : A → A'} + → {@(tactic by-eq) inj : InjectiveOn (dom R) f} + → left-unique R + → left-unique (mapˡ f R) +mapˡ-uniq {inj = inj} uniq = λ h h' → case ∈⇔P h ,′ ∈⇔P h' of λ where + (((_ , b) , refl , Ha) , ((_ , b') , eqb , Hb)) → uniq Ha + $ subst _ ( sym + $ ×-≡,≡→≡ + $ map₁ (inj (to dom∈ (b , Ha)) (to dom∈ (b' , Hb))) + (×-≡,≡←≡ eqb)) + Hb + +mapʳ-uniq : {f : B → B'} → left-unique R → left-unique (mapʳ f R) +mapʳ-uniq uniq = λ h h' → case ∈⇔P h ,′ ∈⇔P h' of λ where + ((_ , refl , Ha) , (_ , refl , Hb)) → cong _ $ uniq Ha Hb + +mapKeys : (f : A → A') → (m : Map A B) + → {@(tactic by-eq) _ : InjectiveOn (dom (m ˢ)) f} + → Map A' B +mapKeys f (R , uniq) {inj} = mapˡ f R , mapˡ-uniq {inj = inj} uniq + +mapValues : (B → B') → Map A B → Map A B' +mapValues f (R , uniq) = mapʳ f R , mapʳ-uniq uniq + +module Unionᵐ (sp-∈ : spec-∈ A) where + infixr 6 _∪ˡ_ + + _∪ˡ'_ : Rel A B → Rel A B → Rel A B + m ∪ˡ' m' = m ∪ filter (sp-∘ (sp-¬ (sp-∈ {dom m})) proj₁) m' + + _∪ˡ_ : Map A B → Map A B → Map A B + m ∪ˡ m' = disj-∪ m (filterᵐ (sp-∘ (sp-¬ sp-∈) proj₁) m') + (∈⇔P -⟨ (λ where x (_ , refl , hy) → proj₁ (∈⇔P hy) (∈⇔P x)) ⟩- ∈⇔P) + + disjoint-∪ˡ-∪ : (H : disjoint (dom R) (dom R')) → R ∪ˡ' R' ≡ᵉ R ∪ R' + disjoint-∪ˡ-∪ disj = from ≡ᵉ⇔≡ᵉ' λ _ → mk⇔ + (∈-∪⁺ ∘′ ⊎.map₂ (proj₂ ∘′ ∈⇔P) ∘′ ∈⇔P) + (∈⇔P ∘′ ⊎.map₂ (to ∈-filter ∘′ (λ h → (flip disj (∈-map⁺'' h)) , h)) ∘ ∈⇔P) + + insert : Map A B → A → B → Map A B + insert m a b = ❴ a , b ❵ᵐ ∪ˡ m + + insertIfJust : ⦃ DecEq A ⦄ → A → Maybe B → Map A B → Map A B + insertIfJust x nothing m = m + insertIfJust x (just y) m = insert m x y + + disjoint-∪ˡ-mapValues : {M M' : Map A B} + (f : B → C) + → (H : disjoint (dom (M ˢ)) (dom (M' ˢ))) + → (mapValues f (M ∪ˡ M')) ˢ ≡ᵉ (mapValues f M ∪ˡ mapValues f M') ˢ + disjoint-∪ˡ-mapValues {M = M} {M'} f disj = begin + proj₁ (mapValues f (M ∪ˡ M')) + ≈⟨ map-≡ᵉ (disjoint-∪ˡ-∪ disj) ⟩ + (mapʳ f ((proj₁ M) ∪ (proj₁ M'))) + ≈⟨ map-∪ _ ⟩ + (mapʳ f (proj₁ M) ∪ mapʳ f (proj₁ M')) + ≈˘⟨ disjoint-∪ˡ-∪ (λ x₁ x₂ → disj (dom-mapʳ⊆ x₁) (dom-mapʳ⊆ x₂)) ⟩ + proj₁ (mapValues f M ∪ˡ mapValues f M') + ∎ + where open SetoidReasoning ≡ᵉ-Setoid + +map⦅×-dup⦆-uniq : ∀ {x : Set A} → left-unique (mapˢ ×-dup x) +map⦅×-dup⦆-uniq x y with ∈-map⁻' x | ∈-map⁻' y +... | fst , refl , _ | .fst , refl , _ = refl + +mapˡ∘map⦅×-dup⦆-uniq : ∀ {S : Set A} {f : A → B} + → {@(tactic by-eq) inj : Injective _≡_ _≡_ f} + → left-unique $ mapˡ f (mapˢ ×-dup S) +mapˡ∘map⦅×-dup⦆-uniq {inj = inj} = mapˡ-uniq {inj = λ _ _ → inj} map⦅×-dup⦆-uniq + +idMap : Set A → Map A A +idMap s = -, map⦅×-dup⦆-uniq {x = s} + +mapFromFun : (A → B) → Set A → Map A B +mapFromFun f s = mapValues f (idMap s) + +mapWithKey-uniq : {f : A → B → B'} + → left-unique R + → left-unique (mapˢ (λ { (x , y) → x , f x y }) R) +mapWithKey-uniq {f = f} uniq p q with from ∈-map p | from ∈-map q +... | (x , y) , refl , xy∈r | (x' , y') , refl , xy'∈r = cong (f x) (uniq xy∈r xy'∈r) + +mapWithKey : (A → B → B') → Map A B → Map A B' +mapWithKey f m@(r , p) = mapˢ (λ { (x , y) → x , f x y}) r , mapWithKey-uniq p + +mapValues-dom : {f : B → C} → dom (m ˢ) ≡ᵉ dom (mapValues f m ˢ) +mapValues-dom {m = _ , _} = mapʳ-dom + +_∣'_ : {P : A → Type} → Map A B → specProperty P → Map A B +m ∣' P? = filterᵐ (sp-∘ P? proj₁) m + +_∣^'_ : {P : B → Type} → Map A B → specProperty P → Map A B +m ∣^' P? = filterᵐ (sp-∘ P? proj₂) m + +constMap : Set A → B → Map A B +constMap X b = mapˢ (_, b) X , λ x x₁ → + trans (proj₂ $ ×-≡,≡←≡ $ proj₁ $ proj₂ (∈⇔P x)) + (sym $ proj₂ $ ×-≡,≡←≡ $ proj₁ $ proj₂ (∈⇔P x₁)) + +mapPartialLiftKey-just-uniq : ∀ {f : A → B → Maybe B'} + → left-unique R + → just (a , b) ∈ mapˢ (mapPartialLiftKey f) R + → just (a , b') ∈ mapˢ (mapPartialLiftKey f) R + → b ≡ b' +mapPartialLiftKey-just-uniq {f = f} prop a∈ a'∈ = + let _ , eq , ax∈r = mapPartialLiftKey-map {f = f} a∈ + _ , eq' , ax'∈r = mapPartialLiftKey-map {f = f} a'∈ + in + just-injective $ trans eq (trans (cong (f _) (prop ax∈r ax'∈r)) (sym eq')) + +mapPartial-uniq : ∀ {r : Rel A B} {f : A → B → Maybe B' } + → left-unique r + → left-unique (mapPartial (mapPartialLiftKey f) r) +mapPartial-uniq {f = f} prop {a} {b} {b'} p q = + let p = ∈-map′ p + q = ∈-map′ q + in mapPartialLiftKey-just-uniq {f = f} prop (⊆-mapPartial p) (⊆-mapPartial q) + +mapMaybeWithKeyᵐ : (A → B → Maybe B') → Map A B → Map A B' +mapMaybeWithKeyᵐ f (rel , prop) = mapMaybeWithKey f rel , mapPartial-uniq {f = f} prop + +mapFromPartialFun : (A → Maybe B) → Set A → Map A B +mapFromPartialFun f s = mapMaybeWithKeyᵐ (λ _ → f) (idMap s) + +module Restrictionᵐ (sp-∈ : spec-∈ A) where + private module R = Restriction sp-∈ + open Unionᵐ sp-∈ + + _∣_ : Map A B → Set A → Map A B + m ∣ X = ⊆-map (R._∣ X) R.res-⊆ m + + _∣_ᶜ : Map A B → Set A → Map A B + m ∣ X ᶜ = ⊆-map (R._∣ X ᶜ) R.ex-⊆ m + + resᵐ-∅ᶜ : {M : Map A B} → (M ∣ ∅ ᶜ) ˢ ≡ᵉ M ˢ + resᵐ-∅ᶜ = R.res-∅ᶜ + + -- map only values in X + mapValueRestricted : (B → B) → Map A B → Set A → Map A B + mapValueRestricted f m X = mapValues f (m ∣ X) ∪ˡ m + + -- map only value at a + mapSingleValue : (B → B) → Map A B → A → Map A B + mapSingleValue f m a = mapValueRestricted f m ❴ a ❵ + + curryᵐ : Map (A × B) C → A → Map B C + curryᵐ m a = R.curryʳ (m ˢ) a , λ h h' → proj₂ m (R.∈-curryʳ h) (R.∈-curryʳ h') + + res-singleton : ∀ {k} → k ∈ dom (m ˢ) → ∃[ v ] m ∣ ❴ k ❵ ≡ᵉᵐ ❴ k , v ❵ᵐ + res-singleton {m = m@(_ , uniq)} k∈domm + with (k , v) , (refl , h) ← ∈⇔P k∈domm + = v + , (λ a∈m∣k → to ∈-singleton $ case ∈⇔P a∈m∣k of λ (mem₁ , mem₂) → + let eq = from ∈-singleton mem₁ + in ×-≡,≡→≡ (eq , (uniq mem₂ (subst _ (sym eq) h)))) + , λ a∈❴k,v❵ → subst (_∈ ((m ∣ ❴ k ❵) ˢ)) + (sym $ from ∈-singleton a∈❴k,v❵) + (∈⇔P (to ∈-singleton refl , h)) + + res-singleton' : ∀ {k v} → (k , v) ∈ m ˢ → m ∣ ❴ k ❵ ≡ᵉᵐ ❴ k , v ❵ᵐ + res-singleton' {m = m} kv∈m + with _ , h ← res-singleton {m = m} (∈⇔P (-, (refl , kv∈m))) + = subst _ (sym $ proj₂ m kv∈m (R.res-⊆ $ proj₂ h $ to ∈-singleton refl)) h + + res-singleton⁺ : {k : A}{v : B} → (k , v) ∈ m ˢ → (k , v) ∈ (m ∣ ❴ k ❵)ˢ + res-singleton⁺ kv∈m = to ∈-filter ((to ∈-singleton refl) , kv∈m) + + res-singleton-inhabited : ∀ {k a} → a ∈ (m ∣ ❴ k ❵) ˢ → k ∈ dom (m ˢ) + res-singleton-inhabited {m = m} {k} {a} a∈ = + to dom∈ ( proj₂ a , subst (λ x → (x , proj₂ a) ∈ (m ˢ)) + (from ∈-singleton (R.res-dom (∈-dom a∈))) + (R.res-⊆ a∈) ) + + res-singleton'' : ∀ {k a} → a ∈ (m ∣ ❴ k ❵)ˢ → ∃[ v ] a ≡ (k , v) + res-singleton'' {m = m}{k}{a} a∈m = + let (v , m|≡) = res-singleton {m = m} (res-singleton-inhabited{m = m} a∈m) in + v , from ∈-singleton (proj₁ m|≡ a∈m) + + -- f(x,-) + infix 30 _⦅_,-⦆ + _⦅_,-⦆ = curryᵐ + + update : A → Maybe B → Map A B → Map A B + update x (just y) m = insert m x y + update x nothing m = m ∣ ❴ x ❵ ᶜ + +module Lookupᵐ (sp-∈ : spec-∈ A) where + open import Relation.Nullary.Decidable + private module R = Restriction sp-∈ + open Unionᵐ sp-∈ + open Restriction sp-∈ + + module _ (m : Map A B) (x : A) where + lookupᵐ : {@(tactic initTac assumption') _ : x ∈ dom (m ˢ)} → B + lookupᵐ {h} = proj₁ (from dom∈ h) + + lookupᵐ? : ⦃ (x ∈ dom (m ˢ)) ⁇ ⦄ → Maybe B + lookupᵐ? ⦃ ⁇ no _ ⦄ = nothing + lookupᵐ? ⦃ ⁇ yes _ ⦄ = just lookupᵐ + + pullbackMap : (m : Map A B) → ⦃ ∀ {x} → (x ∈ dom (m ˢ)) ⁇ ⦄ → (A' → A) → Set A' → Map A' B + pullbackMap m f s = mapMaybeWithKeyᵐ (λ a _ → lookupᵐ? m (f a)) (idMap s) + +module Corestrictionᵐ (sp-∈ : spec-∈ B) where + private module R = Corestriction sp-∈ + + _∣^_ : Map A B → Set B → Map A B + m ∣^ X = ⊆-map (R._∣^ X) R.cores-⊆ m + + _∣^_ᶜ : Map A B → Set B → Map A B + m ∣^ X ᶜ = ⊆-map (R._∣^ X ᶜ) R.coex-⊆ m + + -- f⁻¹(x) + infix 25 _⁻¹_ + _⁻¹_ : Map A B → B → Set A + m ⁻¹ a = dom ((m ∣^ ❴ a ❵) ˢ) diff --git a/src/Axiom/Set/Map/Dec.agda b/src/Axiom/Set/Map/Dec.agda new file mode 100644 index 000000000..473f3382c --- /dev/null +++ b/src/Axiom/Set/Map/Dec.agda @@ -0,0 +1,86 @@ +{-# OPTIONS --safe --no-import-sorts #-} +open import Axiom.Set using (Theoryᵈ; Theory) + +module Axiom.Set.Map.Dec (thᵈ : Theoryᵈ) where + +open import Prelude hiding (map; Monoid) + +open import Algebra using (Monoid) +import Data.Sum as Sum +open import Data.These hiding (map) +open import Class.DecEq using (DecEq) + +open Theoryᵈ thᵈ using (_∈?_; th; incl-set'; incl-set; incl-set-proj₁⊇) +open Theory th +open import Axiom.Set.Rel th using (dom; dom∈) +open import Axiom.Set.Map th +open import Data.Product.Properties using (×-≡,≡→≡; ×-≡,≡←≡) + +open import Interface.IsCommutativeMonoid + +open Equivalence + +private variable A B C D : Type + +module Lookupᵐᵈ (sp-∈ : spec-∈ A) where + open Lookupᵐ sp-∈ + + unionThese : ⦃ DecEq A ⦄ → (m : Map A B) (m' : Map A C) (x : A) + → x ∈ dom (m ˢ) ∪ dom (m' ˢ) → These B C + unionThese m m' x dp with x ∈? dom (m ˢ) | x ∈? dom (m' ˢ) + ... | yes mr | yes mr' = these (lookupᵐ m x) (lookupᵐ m' x) + ... | yes mr | no mr' = this (lookupᵐ m x) + ... | no mr | yes mr' = that (lookupᵐ m' x) + ... | no mr | no mr' = Sum.[ flip contradiction mr , flip contradiction mr' ] + (from ∈-∪ dp) + + unionWith : ⦃ DecEq A ⦄ → (These B C → D) → Map A B → Map A C → Map A D + unionWith f m@(r , p) m'@(r' , p') = m'' , helper + where + d = dom r ∪ dom r' + m'' = map (λ (x , p) → x , f (unionThese m m' x p)) (incl-set d) + + helper : left-unique m'' + helper q q' + with _ , refl , t ← from ∈-map q + with _ , refl , t' ← from ∈-map q' + with from (∈-mapPartial {f = incl-set' _}) t + | from (∈-mapPartial {f = incl-set' _}) t' + ... | z , _ | z' , _ + with z ∈? d in eq | z' ∈? d in eq' + helper _ _ | _ , _ , refl | _ , _ , refl | yes _ | yes _ + with refl ← trans (sym eq) eq' = refl + + module _ {V : Type} ⦃ mon : IsCommutativeMonoid' 0ℓ 0ℓ V ⦄ ⦃ _ : DecEq A ⦄ where + infixr 6 _∪⁺_ + open IsCommutativeMonoid' mon + + _∪⁺_ : Map A V → Map A V → Map A V + _∪⁺_ = unionWith (fold id id _◇_) + + aggregate₊ : FinSet (A × V) → Map A V + aggregate₊ (_ , l , _) = foldl (λ m x → m ∪⁺ ❴ x ❵ᵐ) ∅ᵐ l + + module _ {m m' : Map A V} where + ∪dom-lookup : ∃[ a ] a ∈ dom (m ˢ) ∪ dom (m' ˢ) → A × V + ∪dom-lookup (a , a∈) = a , (fold id id _◇_)(unionThese m m' a a∈) + + dom∪⁺⊆∪dom : dom ((m ∪⁺ m') ˢ) ⊆ dom (m ˢ) ∪ dom (m' ˢ) + dom∪⁺⊆∪dom {a} a∈ = subst (_∈ dom (m ˢ) ∪ dom (m' ˢ)) + (Prelude.sym $ proj₁ (×-≡,≡←≡ $ proj₁ (proj₂ ∈-dom∪⁺))) + (proj₂ $ proj₁ ∈-dom∪⁺) + where + ∈-dom∪⁺ : ∃[ c ] (a , proj₁ (from dom∈ a∈)) ≡ ∪dom-lookup c + × c ∈ incl-set (dom (m ˢ) ∪ dom (m' ˢ)) + ∈-dom∪⁺ = from ∈-map $ proj₂ $ from dom∈ a∈ + + ∪dom⊆dom∪⁺ : dom (m ˢ) ∪ dom (m' ˢ) ⊆ dom ((m ∪⁺ m') ˢ) + ∪dom⊆dom∪⁺ {a} a∈ with from ∈-map (incl-set-proj₁⊇ a∈) + ... | c' , a≡c₁' , c'∈ = + to dom∈ (proj₂ (∪dom-lookup c') , to ∈-map (c' , ×-≡,≡→≡ (a≡c₁' , Prelude.refl) , c'∈)) + + dom∪⁺⇔∪dom : ∀ {a} → a ∈ dom ((m ∪⁺ m')ˢ) ⇔ a ∈ dom (m ˢ) ∪ dom (m' ˢ) + dom∪⁺⇔∪dom {a} = mk⇔ dom∪⁺⊆∪dom ∪dom⊆dom∪⁺ + + dom∪⁺≡∪dom : dom ((m ∪⁺ m')ˢ) ≡ᵉ dom (m ˢ) ∪ dom (m' ˢ) + dom∪⁺≡∪dom = to dom∪⁺⇔∪dom , from dom∪⁺⇔∪dom diff --git a/src/Axiom/Set/Properties.agda b/src/Axiom/Set/Properties.agda new file mode 100644 index 000000000..ea68e4b4b --- /dev/null +++ b/src/Axiom/Set/Properties.agda @@ -0,0 +1,428 @@ +{-# OPTIONS --safe --no-import-sorts #-} + +open import Axiom.Set using (Theory) + +module Axiom.Set.Properties {ℓ} (th : Theory {ℓ}) where + +open import Prelude hiding (isEquivalence; trans; map; map₂) +open Theory th + +import Data.List +import Data.Sum +import Function.Related.Propositional as R +import Relation.Nullary.Decidable +open import Data.List.Ext.Properties using (_×-cong_; _⊎-cong_) +open import Data.List.Membership.DecPropositional using () renaming (_∈?_ to _∈ˡ?_) +open import Data.List.Membership.Propositional.Properties using (∈-filter⁺; ∈-filter⁻; ∈-++⁺ˡ; ∈-++⁺ʳ; ∈-++⁻) +open import Data.List.Relation.Binary.BagAndSetEquality using (∼bag⇒↭) +open import Data.List.Relation.Binary.Permutation.Propositional.Properties using (↭-length) +open import Data.List.Relation.Binary.Subset.Propositional using () renaming (_⊆_ to _⊆ˡ_) +open import Data.List.Relation.Unary.Any using (here; there) +open import Data.List.Relation.Unary.Unique.Propositional.Properties.WithK using (unique∧set⇒bag) +open import Data.Product using (map₂; swap) +open import Data.Product.Properties.Ext +open import Data.Relation.Nullary.Decidable.Ext using (map′⇔) +open import Relation.Binary hiding (_⇔_) +open import Relation.Binary.Lattice +import Relation.Binary.Lattice.Properties.BoundedJoinSemilattice as Bounded∨Semilattice +import Relation.Binary.Lattice.Properties.JoinSemilattice as ∨Semilattice +open import Relation.Binary.Morphism using (IsOrderHomomorphism) + +open Equivalence + +private variable + A B C : Type ℓ + X Y Z : Set A + +module _ {f : A → B} {X} {b} where + ∈-map⁻' : b ∈ map f X → (∃[ a ] b ≡ f a × a ∈ X) + ∈-map⁻' = from ∈-map + + ∈-map⁺' : (∃[ a ] b ≡ f a × a ∈ X) → b ∈ map f X + ∈-map⁺' = to ∈-map + +∈-map⁺'' : ∀ {f : A → B} {X} {a} → a ∈ X → f a ∈ map f X +∈-map⁺'' h = to ∈-map (-, refl , h) + +module _ {X : Set A} {P : A → Type} {sp-P : specProperty P} {a} where + ∈-filter⁻' : a ∈ filter sp-P X → (P a × a ∈ X) + ∈-filter⁻' = from ∈-filter + + ∈-filter⁺' : (P a × a ∈ X) → a ∈ filter sp-P X + ∈-filter⁺' = to ∈-filter + +module _ {X Y : Set A} {a} where + ∈-∪⁻ : a ∈ X ∪ Y → a ∈ X ⊎ a ∈ Y + ∈-∪⁻ = from ∈-∪ + + ∈-∪⁺ : a ∈ X ⊎ a ∈ Y → a ∈ X ∪ Y + ∈-∪⁺ = to ∈-∪ + +module _ {l : List A} {a} where + ∈-fromList⁻ : a ∈ fromList l → a ∈ˡ l + ∈-fromList⁻ = from ∈-fromList + + ∈-fromList⁺ : a ∈ˡ l → a ∈ fromList l + ∈-fromList⁺ = to ∈-fromList + +open import Tactic.AnyOf +open import Tactic.Defaults + +-- Because of missing macro hygiene, we have to copy&paste this. +-- c.f. https://github.com/agda/agda/issues/3819 +private macro + ∈⇒P = anyOfⁿᵗ + (quote ∈-filter⁻' ∷ quote ∈-∪⁻ ∷ quote ∈-map⁻' ∷ quote ∈-fromList⁻ ∷ []) + P⇒∈ = anyOfⁿᵗ + (quote ∈-filter⁺' ∷ quote ∈-∪⁺ ∷ quote ∈-map⁺' ∷ quote ∈-fromList⁺ ∷ []) + ∈⇔P = anyOfⁿᵗ + ( quote ∈-filter⁻' ∷ quote ∈-∪⁻ ∷ quote ∈-map⁻' ∷ quote ∈-fromList⁻ + ∷ quote ∈-filter⁺' ∷ quote ∈-∪⁺ ∷ quote ∈-map⁺' ∷ quote ∈-fromList⁺ ∷ []) + +_≡_⨿_ : Set A → Set A → Set A → Type ℓ +X ≡ Y ⨿ Z = X ≡ᵉ Y ∪ Z × disjoint Y Z + +-- FIXME: proving this has some weird issues when making a implicit in +-- in the definiton of _≡ᵉ'_ +≡ᵉ⇔≡ᵉ' : X ≡ᵉ Y ⇔ X ≡ᵉ' Y +≡ᵉ⇔≡ᵉ' = mk⇔ + (λ where (X⊆Y , Y⊆X) _ → mk⇔ X⊆Y Y⊆X) + (λ a∈X⇔a∈Y → (λ {_} → to (a∈X⇔a∈Y _)) , λ {_} → from (a∈X⇔a∈Y _)) + +cong-⊆⇒cong : {f : Set A → Set B} → f Preserves _⊆_ ⟶ _⊆_ → f Preserves _≡ᵉ_ ⟶ _≡ᵉ_ +cong-⊆⇒cong h X≡ᵉX' = h (proj₁ X≡ᵉX') , h (proj₂ X≡ᵉX') + +cong-⊆⇒cong₂ : {f : Set A → Set B → Set C} + → f Preserves₂ _⊆_ ⟶ _⊆_ ⟶ _⊆_ → f Preserves₂ _≡ᵉ_ ⟶ _≡ᵉ_ ⟶ _≡ᵉ_ +cong-⊆⇒cong₂ h X≡ᵉX' Y≡ᵉY' = h (proj₁ X≡ᵉX') (proj₁ Y≡ᵉY') + , h (proj₂ X≡ᵉX') (proj₂ Y≡ᵉY') + +⊆-Transitive : Transitive (_⊆_ {A}) +⊆-Transitive X⊆Y Y⊆Z = Y⊆Z ∘ X⊆Y + +≡ᵉ-isEquivalence : IsEquivalence (_≡ᵉ_ {A}) +≡ᵉ-isEquivalence = record + { refl = id , id + ; sym = λ where (h , h') → (h' , h) + ; trans = λ eq₁ eq₂ → ⊆-Transitive (proj₁ eq₁) (proj₁ eq₂) + , ⊆-Transitive (proj₂ eq₂) (proj₂ eq₁) + } + +≡ᵉ-Setoid : ∀ {A} → Setoid ℓ ℓ +≡ᵉ-Setoid {A} = record + { Carrier = Set A + ; _≈_ = _≡ᵉ_ + ; isEquivalence = ≡ᵉ-isEquivalence + } + +⊆-isPreorder : IsPreorder (_≡ᵉ_ {A}) _⊆_ +⊆-isPreorder = λ where + .isEquivalence → ≡ᵉ-isEquivalence + .reflexive → proj₁ + .trans → ⊆-Transitive + where open IsPreorder + +⊆-Preorder : {A} → Preorder _ _ _ +⊆-Preorder {A} = record + { Carrier = Set A ; _≈_ = _≡ᵉ_ ; _≲_ = _⊆_ ; isPreorder = ⊆-isPreorder } + +⊆-PartialOrder : IsPartialOrder (_≡ᵉ_ {A}) _⊆_ +⊆-PartialOrder = record + { isPreorder = ⊆-isPreorder + ; antisym = _,_ } + +∈-× : {a : A} {b : B} → (a , b) ∈ X → (a ∈ map proj₁ X × b ∈ map proj₂ X) +∈-× {a = a} {b} x = to ∈-map ((a , b) , refl , x) , to ∈-map ((a , b) , refl , x) + +module _ {f : A → B} {g : B → C} where + map-⊆∘ : map g (map f X) ⊆ map (g ∘ f) X + map-⊆∘ a∘∈ + with b , a≡gb , b∈prfX ← from ∈-map a∘∈ + with a , refl , a∈X ← from ∈-map b∈prfX + = to ∈-map (a , a≡gb , a∈X) + + map-∘⊆ : map (g ∘ f) X ⊆ map g (map f X) + map-∘⊆ a∈∘ with from ∈-map a∈∘ + ... | a₁ , a₁≡gfa , a₁∈X = to ∈-map (f a₁ , a₁≡gfa , to ∈-map (a₁ , refl , a₁∈X)) + + map-∘ : map g (map f X) ≡ᵉ map (g ∘ f) X + map-∘ = map-⊆∘ , map-∘⊆ + + ∈-map⁺-∘ : ∀ {b} → b ∈ map f X → g b ∈ map (g ∘ f) X + ∈-map⁺-∘ = map-⊆∘ ∘ ∈-map⁺'' + +map-⊆ : {X Y : Set A} {f : A → B} → X ⊆ Y → map f X ⊆ map f Y +map-⊆ x⊆y a∈map with from ∈-map a∈map +... | a₁ , a≡fa₁ , a₁∈x = to ∈-map (a₁ , a≡fa₁ , x⊆y a₁∈x) + +map-≡ᵉ : {X Y : Set A} {f : A → B} → X ≡ᵉ Y → map f X ≡ᵉ map f Y +map-≡ᵉ (x⊆y , y⊆x) = map-⊆ x⊆y , map-⊆ y⊆x + +∉-∅ : {a : A} → a ∉ ∅ +∉-∅ h = case ∈⇔P h of λ () + +∅-minimum : Minimum (_⊆_ {A}) ∅ +∅-minimum = λ _ → ⊥-elim ∘ ∉-∅ + +∅-least : X ⊆ ∅ → X ≡ᵉ ∅ +∅-least X⊆∅ = (X⊆∅ , ∅-minimum _) + +∅-weakly-finite : weakly-finite {A = A} ∅ +∅-weakly-finite = [] , ⊥-elim ∘ ∉-∅ + +∅-finite : finite {A = A} ∅ +∅-finite = [] , mk⇔ (⊥-elim ∘ ∉-∅) λ () + +map-∅ : {X : Set A} {f : A → B} → map f ∅ ≡ᵉ ∅ +map-∅ = ∅-least λ x∈map → case ∈-map⁻' x∈map of λ where (_ , _ , h) → ⊥-elim (∉-∅ h) + +map-∪ : {X Y : Set A} → (f : A → B) → map f (X ∪ Y) ≡ᵉ map f X ∪ map f Y +map-∪ {X = X} {Y} f = from ≡ᵉ⇔≡ᵉ' λ b → + b ∈ map f (X ∪ Y) + ∼⟨ R.SK-sym ∈-map ⟩ + (∃[ a ] b ≡ f a × a ∈ X ∪ Y) + ∼⟨ ∃-cong′ (R.K-refl ×-cong R.SK-sym ∈-∪) ⟩ + (∃[ a ] b ≡ f a × (a ∈ X ⊎ a ∈ Y)) + ↔⟨ ∃-cong′ ×-distribˡ-⊎' ⟩ + (∃[ a ] (b ≡ f a × a ∈ X ⊎ b ≡ f a × a ∈ Y)) + ↔⟨ ∃-distrib-⊎' ⟩ + (∃[ a ] b ≡ f a × a ∈ X ⊎ ∃[ a ] b ≡ f a × a ∈ Y) + ∼⟨ ∈-map ⊎-cong ∈-map ⟩ + (b ∈ map f X ⊎ b ∈ map f Y) + ∼⟨ ∈-∪ ⟩ + b ∈ map f X ∪ map f Y ∎ + where open R.EquationalReasoning + +mapPartial-∅ : {f : A → Maybe B} → mapPartial f ∅ ≡ᵉ ∅ +mapPartial-∅ {f = f} = ∅-least λ x∈map → case from (∈-mapPartial {f = f}) x∈map of λ where + (_ , h , _) → ⊥-elim (∉-∅ h) + +card-≡ᵉ : (X Y : Σ (Set A) strongly-finite) → proj₁ X ≡ᵉ proj₁ Y → card X ≡ card Y +card-≡ᵉ (X , lX , lXᵘ , eqX) (Y , lY , lYᵘ , eqY) X≡Y = + ↭-length $ ∼bag⇒↭ $ unique∧set⇒bag lXᵘ lYᵘ λ {a} → + a ∈ˡ lX ∼⟨ R.SK-sym eqX ⟩ + a ∈ X ∼⟨ to ≡ᵉ⇔≡ᵉ' X≡Y a ⟩ + a ∈ Y ∼⟨ eqY ⟩ + a ∈ˡ lY ∎ + where open R.EquationalReasoning + +module _ {P : A → Type} {sp-P : specProperty P} where + + filter-∅ : (∀ a → a ∈ X → ¬ P a) → filter sp-P X ≡ᵉ ∅ + proj₁ (filter-∅ h) {a} h' with from ∈-filter h' + ... | (Pa , a∈) = ⊥-elim (h a a∈ Pa) + proj₂ (filter-∅ h) {a} h' = ⊥-elim (∉-∅ h') + + filter-⊆ : filter sp-P X ⊆ X + filter-⊆ = proj₂ ∘′ ∈⇔P + + filter-pres-⊆ : X ⊆ Y → filter sp-P X ⊆ filter sp-P Y + filter-pres-⊆ xy a∈ = let Pa∈ = from ∈-filter a∈ in + to ∈-filter (map₂ xy Pa∈) + + filter-pres-≡ᵉ : X ≡ᵉ Y → filter sp-P X ≡ᵉ filter sp-P Y + filter-pres-≡ᵉ (X⊆Y , Y⊆X) = filter-pres-⊆ X⊆Y , filter-pres-⊆ Y⊆X + + filter-split-∪ : ∀ {a} → a ∈ filter sp-P (X ∪ Y) → (P a × a ∈ X) ⊎ (P a × a ∈ Y) + filter-split-∪ a∈ = case (proj₁ (from ∈-filter a∈) , from ∈-∪ (proj₂ (from ∈-filter a∈))) of + λ where + (Pa , inj₁ a∈X) → inj₁ (Pa , a∈X) + (Pa , inj₂ a∈Y) → inj₂ (Pa , a∈Y) + + filter-hom-⊆ : filter sp-P (X ∪ Y) ⊆ filter sp-P X ∪ filter sp-P Y + filter-hom-⊆ {a = a} a∈ = to ∈-∪ (case filter-split-∪ a∈ of λ where + (inj₁ v) → inj₁ (to ∈-filter v) + (inj₂ v) → inj₂ (to ∈-filter v)) + + filter-hom-⊇ : filter sp-P X ∪ filter sp-P Y ⊆ filter sp-P (X ∪ Y) + filter-hom-⊇ a∈ = to ∈-filter (case (from ∈-∪ a∈) of λ where + (inj₁ v) → proj₁ (from ∈-filter v) , to ∈-∪ (inj₁ (proj₂ (from ∈-filter v))) + (inj₂ v) → proj₁ (from ∈-filter v) , to ∈-∪ (inj₂ (proj₂ (from ∈-filter v))) ) + + filter-hom-∪ : filter sp-P (X ∪ Y) ≡ᵉ (filter sp-P X) ∪ (filter sp-P Y) + filter-hom-∪ = filter-hom-⊆ , filter-hom-⊇ + +Dec-∈-fromList : ∀ {a : A} → ⦃ DecEq A ⦄ → (l : List A) → Decidable¹ (_∈ fromList l) +Dec-∈-fromList _ _ = Relation.Nullary.Decidable.map ∈-fromList (_∈ˡ?_ _≟_ _ _) + +Dec-∈-singleton : ∀ {a : A} → ⦃ DecEq A ⦄ → Decidable¹ (_∈ ❴ a ❵) +Dec-∈-singleton _ = Relation.Nullary.Decidable.map ∈-singleton (_ ≟ _) + +singleton-finite : ∀ {a : A} → finite ❴ a ❵ +singleton-finite {a = a} = [ a ] , λ {x} → + x ∈ ❴ a ❵ ∼⟨ R.SK-sym ∈-fromList ⟩ + x ∈ˡ [ a ] ∎ + where open R.EquationalReasoning + +filter-finite : ∀ {P : A → Type} + → (sp : specProperty P) → Decidable¹ P → finite X → finite (filter sp X) +filter-finite {X = X} {P} sp P? (l , hl) = Data.List.filter P? l , λ {a} → + a ∈ filter sp X ∼⟨ R.SK-sym ∈-filter ⟩ + (P a × a ∈ X) ∼⟨ R.K-refl ×-cong hl ⟩ + (P a × a ∈ˡ l) ∼⟨ mk⇔ (uncurry $ flip $ ∈-filter⁺ P?) + (swap ∘ ∈-filter⁻ P?) ⟩ + a ∈ˡ Data.List.filter P? l ∎ + where open R.EquationalReasoning + +∪-⊆ˡ : X ⊆ X ∪ Y +∪-⊆ˡ = ∈⇔P ∘′ inj₁ + +∪-⊆ʳ : Y ⊆ X ∪ Y +∪-⊆ʳ = ∈⇔P ∘′ inj₂ + +∪-⊆ : X ⊆ Z → Y ⊆ Z → X ∪ Y ⊆ Z +∪-⊆ X⊆Z Y⊆Z = λ a∈X∪Y → [ X⊆Z , Y⊆Z ]′ (∈⇔P a∈X∪Y) + +⊆→∪ : X ⊆ Y → X ∪ Y ≡ᵉ Y +⊆→∪ X⊆Y = (λ {a} x → case from ∈-∪ x of λ where + (inj₁ v) → X⊆Y v + (inj₂ v) → v) , ∪-⊆ʳ + +∪-Supremum : Supremum (_⊆_ {A}) _∪_ +∪-Supremum _ _ = ∪-⊆ˡ , ∪-⊆ʳ , λ _ → ∪-⊆ + +∪-cong-⊆ : _∪_ {A} Preserves₂ _⊆_ ⟶ _⊆_ ⟶ _⊆_ +∪-cong-⊆ X⊆X' Y⊆Y' = ∈⇔P ∘′ (Data.Sum.map X⊆X' Y⊆Y') ∘′ ∈⇔P + +∪-cong : _∪_ {A} Preserves₂ _≡ᵉ_ ⟶ _≡ᵉ_ ⟶ _≡ᵉ_ +∪-cong = cong-⊆⇒cong₂ ∪-cong-⊆ + +∪-preserves-finite : _∪_ {A} Preservesˢ₂ finite +∪-preserves-finite {a = X} {Y} (l , hX) (l' , hY) = (l ++ l') , λ {a} → + a ∈ X ∪ Y ∼⟨ R.SK-sym ∈-∪ ⟩ + (a ∈ X ⊎ a ∈ Y) ∼⟨ hX ⊎-cong hY ⟩ + (a ∈ˡ l ⊎ a ∈ˡ l') ∼⟨ mk⇔ Data.Sum.[ ∈-++⁺ˡ , ∈-++⁺ʳ _ ] (∈-++⁻ _) ⟩ + a ∈ˡ l ++ l' ∎ + where open R.EquationalReasoning + +∪-sym : X ∪ Y ≡ᵉ Y ∪ X +∪-sym = ∪-⊆ ∪-⊆ʳ ∪-⊆ˡ , ∪-⊆ ∪-⊆ʳ ∪-⊆ˡ + +Set-JoinSemilattice : IsJoinSemilattice (_≡ᵉ_ {A}) _⊆_ _∪_ +Set-JoinSemilattice = record + { isPartialOrder = ⊆-PartialOrder ; supremum = ∪-Supremum } + +Set-BoundedJoinSemilattice : IsBoundedJoinSemilattice (_≡ᵉ_ {A}) _⊆_ _∪_ ∅ +Set-BoundedJoinSemilattice = record + { isJoinSemilattice = Set-JoinSemilattice ; minimum = ∅-minimum } + +Set-BddSemilattice : {A : Type ℓ} → BoundedJoinSemilattice _ _ _ +Set-BddSemilattice {A} = record + { Carrier = Set A + ; _≈_ = _≡ᵉ_ {A} + ; _≤_ = _⊆_ + ; _∨_ = _∪_ + ; ⊥ = ∅ + ; isBoundedJoinSemilattice = Set-BoundedJoinSemilattice + } + +module _ {A : Type ℓ} where + open Bounded∨Semilattice (Set-BddSemilattice {A}) + open ∨Semilattice (BoundedJoinSemilattice.joinSemilattice (Set-BddSemilattice {A})) + using (∨-comm; ∨-assoc) + + ∪-identityˡ : (X : Set A) → ∅ ∪ X ≡ᵉ X + ∪-identityˡ = identityˡ + + ∪-identityʳ : (X : Set A) → X ∪ ∅ ≡ᵉ X + ∪-identityʳ = identityʳ + + ∪-comm : (X Y : Set A) → X ∪ Y ≡ᵉ Y ∪ X + ∪-comm = ∨-comm + + ∪-assoc : (X Y Z : Set A) → (X ∪ Y) ∪ Z ≡ᵉ X ∪ (Y ∪ Z) + ∪-assoc = ∨-assoc + +fromList-∪-singleton : {A : Type ℓ} {x : A} {l : List A} → fromList (x ∷ l) ≡ᵉ ❴ x ❵ ∪ fromList l +fromList-∪-singleton .proj₁ h with from ∈-fromList h +... | here refl = ∈-∪⁺ (inj₁ (to ∈-fromList (here refl))) +... | there q = ∈-∪⁺ (inj₂ (to ∈-fromList q)) +fromList-∪-singleton .proj₂ h with ∈-∪⁻ h +... | (inj₁ a∈) = to ∈-fromList (here (from ∈-singleton a∈)) +... | (inj₂ a∈) = to ∈-fromList (there (from ∈-fromList a∈)) + +∪-fromList-++ : (ll lr : List A) → fromList ll ∪ fromList lr ≡ᵉ fromList (ll ++ lr) +∪-fromList-++ [] lr = ∪-identityˡ (fromList lr) +∪-fromList-++ (x ∷ l) lr = + begin + fromList (x ∷ l) ∪ fromList lr ≈⟨ ∪-cong fromList-∪-singleton ≡ᵉ.refl ⟩ + (❴ x ❵ ∪ fromList l) ∪ fromList lr ≈⟨ ∪-assoc ❴ x ❵ (fromList l) (fromList lr) ⟩ + ❴ x ❵ ∪ (fromList l ∪ fromList lr) ≈⟨ ∪-cong ≡ᵉ.refl (∪-fromList-++ l lr) ⟩ + ❴ x ❵ ∪ fromList (l ++ lr) ≈˘⟨ fromList-∪-singleton ⟩ + fromList (x ∷ (l ++ lr)) ∎ + where + module ≡ᵉ = IsEquivalence (≡ᵉ-isEquivalence) + open import Relation.Binary.Reasoning.Setoid ≡ᵉ-Setoid + +disjoint-sym : disjoint X Y → disjoint Y X +disjoint-sym disj = flip disj + +module Intersectionᵖ (sp-∈ : spec-∈ A) where + open Intersection sp-∈ + + disjoint⇒disjoint' : disjoint X Y → disjoint' X Y + disjoint⇒disjoint' h = ∅-least (⊥-elim ∘ uncurry h ∘ from ∈-∩) + + disjoint'⇒disjoint : disjoint' X Y → disjoint X Y + disjoint'⇒disjoint h a∈X a∈Y = ∉-∅ (to (to ≡ᵉ⇔≡ᵉ' h _) (to ∈-∩ (a∈X , a∈Y))) + + ∩-⊆ˡ : X ∩ Y ⊆ X + ∩-⊆ˡ = proj₁ ∘ from ∈-∩ + + ∩-⊆ʳ : X ∩ Y ⊆ Y + ∩-⊆ʳ = proj₂ ∘ from ∈-∩ + + ∩-⊆ : Z ⊆ X → Z ⊆ Y → Z ⊆ X ∩ Y + ∩-⊆ Z⊆X Z⊆Y = λ x∈Z → to ∈-∩ (< Z⊆X , Z⊆Y > x∈Z) + + ∩-Infimum : Infimum _⊆_ _∩_ + ∩-Infimum X Y = ∩-⊆ˡ , ∩-⊆ʳ , λ _ → ∩-⊆ + + ∩-preserves-finite : _∩_ Preservesˢ₂ weakly-finite + ∩-preserves-finite _ = ⊆-weakly-finite ∩-⊆ʳ + + ∩-cong-⊆ : _∩_ Preserves₂ _⊆_ ⟶ _⊆_ ⟶ _⊆_ + ∩-cong-⊆ X⊆X' Y⊆Y' a∈X∩Y = to ∈-∩ (Data.Product.map X⊆X' Y⊆Y' (from ∈-∩ a∈X∩Y)) + + ∩-cong : _∩_ Preserves₂ _≡ᵉ_ ⟶ _≡ᵉ_ ⟶ _≡ᵉ_ + ∩-cong = cong-⊆⇒cong₂ ∩-cong-⊆ + + ∩-OrderHomomorphismʳ : ∀ {X} → IsOrderHomomorphism _≡ᵉ_ _≡ᵉ_ _⊆_ _⊆_ (X ∩_) + ∩-OrderHomomorphismʳ = record { cong = ∩-cong (id , id) ; mono = ∩-cong-⊆ id } + + ∩-OrderHomomorphismˡ : ∀ {X} → IsOrderHomomorphism _≡ᵉ_ _≡ᵉ_ _⊆_ _⊆_ (_∩ X) + ∩-OrderHomomorphismˡ = record + { cong = flip ∩-cong (id , id) ; mono = flip ∩-cong-⊆ id } + + Set-Lattice : IsLattice _≡ᵉ_ _⊆_ _∪_ _∩_ + Set-Lattice = record + { isPartialOrder = ⊆-PartialOrder ; supremum = ∪-Supremum ; infimum = ∩-Infimum } + + ∩-sym⊆ : X ∩ Y ⊆ Y ∩ X + ∩-sym⊆ a∈X∩Y with from ∈-∩ a∈X∩Y + ... | a∈X , a∈Y = to ∈-∩ (a∈Y , a∈X) + + ∩-sym : X ∩ Y ≡ᵉ Y ∩ X + ∩-sym = ∩-sym⊆ , ∩-sym⊆ + +-- Additional properties of lists and sets. +module _ {L : List A} where + open Equivalence + + sublist-⇔ : {l : List A} → fromList l ⊆ fromList L ⇔ l ⊆ˡ L + sublist-⇔ {[]} = mk⇔ (λ x ()) (λ _ {_} → ⊥-elim ∘ ∉-∅) + sublist-⇔ {x ∷ xs} = mk⇔ onlyif (λ u → to ∈-fromList ∘ u ∘ from ∈-fromList) + where + onlyif : ({a : A} → a ∈ fromList (x ∷ xs) → a ∈ fromList L) → x ∷ xs ⊆ˡ L + onlyif h (here refl) = from ∈-fromList (h (to ∈-fromList (here refl))) + onlyif h (there x'∈) = from ∈-fromList (h (to ∈-fromList (there x'∈))) + + module _ {ℓ : Level} {P : Pred (List A) ℓ} where + ∃-sublist-⇔ : (∃[ l ] fromList l ⊆ fromList L × P l) ⇔ (∃[ l ] l ⊆ˡ L × P l) + ∃-sublist-⇔ = mk⇔ (λ (l , l⊆L , Pl) → l , to sublist-⇔ l⊆L , Pl) + (λ (l , l⊆L , Pl) → l , from sublist-⇔ l⊆L , Pl) + + ∃?-sublist-⇔ : Dec (∃[ l ] fromList l ⊆ fromList L × P l) ⇔ Dec (∃[ l ] l ⊆ˡ L × P l) + ∃?-sublist-⇔ = map′⇔ ∃-sublist-⇔ + + diff --git a/src/Axiom/Set/Rel.agda b/src/Axiom/Set/Rel.agda new file mode 100644 index 000000000..3971f9250 --- /dev/null +++ b/src/Axiom/Set/Rel.agda @@ -0,0 +1,284 @@ +{-# OPTIONS --safe --no-import-sorts #-} +{-# OPTIONS -v allTactics:100 #-} + +open import Prelude hiding (map) +open import Axiom.Set using (Theory) + +module Axiom.Set.Rel (th : Theory {lzero}) where + +import Relation.Binary.Reasoning.Setoid as SetoidReasoning +import Function.Related.Propositional as R + +open Theory th +open import Axiom.Set.Properties th + +import Data.Product +open import Data.List.Ext.Properties using (_⊎-cong_) +open import Data.These hiding (map) +open import Data.Maybe.Base using () renaming (map to map?) +open import Data.Product.Properties using (,-injectiveˡ; ×-≡,≡→≡) +open import Data.Product.Properties.Ext using (∃-cong′; ∃-distrib-⊎') +open import Relation.Unary using (Decidable) +open import Relation.Nullary using (yes; no) +open import Relation.Binary using (_Preserves_⟶_) +import Relation.Binary.PropositionalEquality as I + +open Equivalence + +open import Tactic.AnyOf +open import Tactic.Defaults + +-- Because of missing macro hygiene, we have to copy&paste this. +-- c.f. https://github.com/agda/agda/issues/3819 +private macro + ∈⇒P = anyOfⁿᵗ + (quote ∈-filter⁻' ∷ quote ∈-∪⁻ ∷ quote ∈-map⁻' ∷ quote ∈-fromList⁻ ∷ []) + P⇒∈ = anyOfⁿᵗ + (quote ∈-filter⁺' ∷ quote ∈-∪⁺ ∷ quote ∈-map⁺' ∷ quote ∈-fromList⁺ ∷ []) + ∈⇔P = anyOfⁿᵗ + ( quote ∈-filter⁻' ∷ quote ∈-∪⁻ ∷ quote ∈-map⁻' ∷ quote ∈-fromList⁻ + ∷ quote ∈-filter⁺' ∷ quote ∈-∪⁺ ∷ quote ∈-map⁺' ∷ quote ∈-fromList⁺ ∷ []) + +Rel : Type → Type → Type +Rel A B = Set (A × B) + +private variable A A' B B' C : Type + R R' : Rel A B + X : Set A + +relatedˡ : Rel A B → Set A +relatedˡ = map proj₁ + +∅ʳ : Rel A B +∅ʳ = ∅ + +dom : Rel A B → Set A +dom = map proj₁ + +range : Rel A B → Set B +range = map proj₂ + +disjoint-dom⇒disjoint : disjoint (dom R) (dom R') → disjoint R R' +disjoint-dom⇒disjoint disj = ∈-map⁺'' -⟨ disj ⟩- ∈-map⁺'' + +_∣'_ : {P : A → Type} → Rel A B → specProperty P → Rel A B +m ∣' P? = filter (sp-∘ P? proj₁) m + +_∣^'_ : {P : B → Type} → Rel A B → specProperty P → Rel A B +m ∣^' P? = filter (sp-∘ P? proj₂) m + +impl⇒res⊆ : ∀ {X : Rel A B} {P P'} (sp-P : specProperty P) (sp-P' : specProperty P') + → (∀ {a} → P a → P' a) → X ∣' sp-P ⊆ X ∣' sp-P' +impl⇒res⊆ sp-P sp-P' P⇒P' a∈X∣'P = ∈⇔P (Data.Product.map₁ P⇒P' (∈⇔P a∈X∣'P)) + +impl⇒cores⊆ : ∀ {X : Rel A B} {P P'} (sp-P : specProperty P) (sp-P' : specProperty P') + → (∀ {b} → P b → P' b) → X ∣^' sp-P ⊆ X ∣^' sp-P' +impl⇒cores⊆ sp-P sp-P' P⇒P' a∈X∣^'P = ∈⇔P (Data.Product.map₁ P⇒P' (∈⇔P a∈X∣^'P)) + +mapˡ : (A → A') → Rel A B → Rel A' B +mapˡ f R = map (Data.Product.map₁ f) R + +mapʳ : (B → B') → Rel A B → Rel A B' +mapʳ f R = map (Data.Product.map₂ f) R + +dom∈ : ∀ {a} → (∃[ b ] (a , b) ∈ R) ⇔ a ∈ dom R +dom∈ {R = R} {a} = + (∃[ b ] (a , b) ∈ R) ∼⟨ R.SK-sym (mk⇔ (λ { ((_ , y) , refl , ay∈R) → y , ay∈R }) + (λ (x , ax∈R) → (a , x) , refl , ax∈R)) ⟩ + (∃[ a₁ ] a ≡ proj₁ a₁ × a₁ ∈ R) ∼⟨ ∈-map ⟩ + + a ∈ dom R ∎ + where open R.EquationalReasoning + +module _ {x : A} {y : B} where + module _ {a : A} where + ∈-dom-singleton-pair : a ≡ x ⇔ a ∈ dom ❴ x , y ❵ + ∈-dom-singleton-pair = mk⇔ (λ a≡x → to dom∈ (y , to ∈-singleton (×-≡,≡→≡ (a≡x , refl)))) + (,-injectiveˡ ∘ from ∈-singleton ∘ proj₂ ∘ from dom∈) + + dom-single→single : a ∈ dom ❴ x , y ❵ → a ∈ ❴ x ❵ + dom-single→single = to ∈-singleton ∘ from ∈-dom-singleton-pair + + single→dom-single : a ∈ ❴ x ❵ → a ∈ dom ❴ x , y ❵ + single→dom-single = to ∈-dom-singleton-pair ∘ from ∈-singleton + + dom-single≡single : dom ❴ x , y ❵ ≡ᵉ ❴ x ❵ + dom-single≡single = dom-single→single , single→dom-single + +∈-dom : {a : A × B} → a ∈ R → proj₁ a ∈ dom R +∈-dom {a = a} a∈ = to ∈-map (a , (refl , a∈)) + +∉-dom∅ : {a : A} → a ∉ dom{A}{B} ∅ +∉-dom∅ {a} a∈dom∅ = ⊥-elim $ ∉-∅ $ proj₂ $ (from dom∈) a∈dom∅ + +dom∅ : dom{A}{B} ∅ ≡ᵉ ∅ +dom∅ = ⊥-elim ∘ ∉-dom∅ , ∅-minimum (dom ∅) + +dom∪ : dom (R ∪ R') ≡ᵉ dom R ∪ dom R' +dom∪ {R = R} {R'} = from ≡ᵉ⇔≡ᵉ' λ a → + a ∈ dom (R ∪ R') ∼⟨ R.SK-sym dom∈ ⟩ + (∃[ b ] (a , b) ∈ R ∪ R') ∼⟨ ∃-cong′ (R.SK-sym ∈-∪) ⟩ + (∃[ b ] ((a , b) ∈ R ⊎ (a , b) ∈ R')) ↔⟨ ∃-distrib-⊎' ⟩ + (∃[ b ] (a , b) ∈ R ⊎ ∃[ b ] (a , b) ∈ R') ∼⟨ dom∈ ⊎-cong dom∈ ⟩ + (a ∈ dom R ⊎ a ∈ dom R') ∼⟨ ∈-∪ ⟩ + a ∈ dom R ∪ dom R' ∎ + where open R.EquationalReasoning + +dom⊆ : dom{A}{B} Preserves _⊆_ ⟶ _⊆_ +dom⊆ R⊆R' a∈ = to dom∈ $ proj₁ (from dom∈ a∈) , R⊆R' (proj₂ (from dom∈ a∈)) + +dom-cong : R ≡ᵉ R' → dom R ≡ᵉ dom R' +dom-cong RR' = (dom⊆ (proj₁ RR')) , (dom⊆ (proj₂ RR')) + +dom-⊆mapʳ : {f : B → B'} → dom R ⊆ dom (mapʳ f R) +dom-⊆mapʳ {f = f} {a} a∈domR with from dom∈ a∈domR +... | b , ab∈R = to dom∈ (f b , to ∈-map ((a , b) , refl , ab∈R)) + +dom-mapʳ⊆ : {f : B → B'} → dom (mapʳ f R) ⊆ dom R +dom-mapʳ⊆ a∈dmR with from dom∈ a∈dmR +... | _ , p∈map with from ∈-map p∈map +... | (_ , b) , refl , ab∈R = to dom∈ (b , ab∈R) + +mapʳ-dom : {f : B → B'} → dom R ≡ᵉ dom (mapʳ f R) +mapʳ-dom = dom-⊆mapʳ , dom-mapʳ⊆ + +dom-∅ : dom R ⊆ ∅ → R ≡ᵉ ∅ +dom-∅ dom⊆∅ = ∅-least (λ {x} x∈R → ⊥-elim $ ∉-∅ $ dom⊆∅ $ to dom∈ (-, x∈R)) + +mapPartialLiftKey : (A → B → Maybe B') → A × B → Maybe (A × B') +mapPartialLiftKey f (k , v) = map? (k ,_) (f k v) + +mapPartialLiftKey-map : ∀ {a : A} {b' : B'} {f : A → B → Maybe B'} {r : Rel A B} + → just (a , b') ∈ map (mapPartialLiftKey f) r + → ∃[ b ] just b' ≡ f a b × (a , b) ∈ r +mapPartialLiftKey-map {f = f} ab∈m + with from ∈-map ab∈m +... | (a' , b') , ≡ , a'b'∈r + with f a' b' in eq +mapPartialLiftKey-map {f = f} ab∈m | (a' , b') , refl , a'b'∈r | just x + = b' , sym eq , a'b'∈r + +mapMaybeWithKey : (A → B → Maybe B') → Rel A B → Rel A B' +mapMaybeWithKey f r = mapPartial (mapPartialLiftKey f) r + +∈-mapMaybeWithKey : ∀ {a : A} {b' : B'} {f : A → B → Maybe B'} {r : Rel A B} + → (a , b') ∈ mapMaybeWithKey f r + → ∃[ b ] (just b' ≡ f a b × (a , b) ∈ r) +∈-mapMaybeWithKey {a = a} {b'} {f} ab'∈ + = mapPartialLiftKey-map {f = f} + $ ⊆-mapPartial + $ to (∈-map {f = just}) ((a , b') , refl , ab'∈) + +module Restriction (sp-∈ : spec-∈ A) where + + _∣_ : Rel A B → Set A → Rel A B + m ∣ X = m ∣' sp-∈ {X} + + _∣_ᶜ : Rel A B → Set A → Rel A B + m ∣ X ᶜ = m ∣' sp-¬ (sp-∈ {X}) + + _⟪$⟫_ : Rel A B → Set A → Set B + m ⟪$⟫ X = range (m ∣ X) + + res-cong : (R ∣_) Preserves _≡ᵉ_ ⟶ _≡ᵉ_ + res-cong (X⊆Y , Y⊆X) = (λ ∈R∣X → ∈⇔P (Data.Product.map₁ X⊆Y (∈⇔P ∈R∣X))) + , (λ ∈R∣Y → ∈⇔P (Data.Product.map₁ Y⊆X (∈⇔P ∈R∣Y))) + + res-dom : dom (R ∣ X) ⊆ X + res-dom a∈dom with ∈⇔P a∈dom + ... | _ , refl , h = proj₁ $ ∈⇔P h + + res-domᵐ : dom (R ∣ X) ⊆ dom R + res-domᵐ a∈dom with ∈⇔P a∈dom + ... | _ , refl , h = ∈-map⁺'' $ proj₂ (∈⇔P h) + + res-comp-cong : (R ∣_ᶜ) Preserves _≡ᵉ_ ⟶ _≡ᵉ_ + res-comp-cong (X⊆Y , Y⊆X) = (λ ∈R∣X → ∈⇔P (Data.Product.map₁ (_∘ Y⊆X) (∈⇔P ∈R∣X))) + , (λ ∈R∣Y → ∈⇔P (Data.Product.map₁ (_∘ X⊆Y) (∈⇔P ∈R∣Y))) + + res-comp-dom : ∀ {a} → a ∈ dom (R ∣ X ᶜ) → a ∉ X + res-comp-dom a∈dom with ∈⇔P a∈dom + ... | _ , refl , h = proj₁ $ ∈⇔P h + + + res-comp-domᵐ : dom (R ∣ X ᶜ) ⊆ dom R + res-comp-domᵐ a∈dom with ∈⇔P a∈dom + ... | _ , refl , h = ∈-map⁺'' (proj₂ (∈⇔P h)) + + res-⊆ : (R ∣ X) ⊆ R + res-⊆ = proj₂ ∘′ ∈⇔P + + ex-⊆ : (R ∣ X ᶜ) ⊆ R + ex-⊆ = proj₂ ∘′ ∈⇔P + + res-∅ : R ∣ ∅ ≡ᵉ ∅ + res-∅ = dom-∅ res-dom + + res-∅ᶜ : R ∣ ∅ ᶜ ≡ᵉ R + res-∅ᶜ = ex-⊆ , λ a∈R → ∈⇔P (∉-∅ , a∈R) + + ∈-resᶜ-dom⁻ : ∀ {a} → a ∈ dom (R ∣ X ᶜ) → a ∉ X × ∃[ b ] (a , b) ∈ R + ∈-resᶜ-dom⁻ a∈ = res-comp-dom a∈ , from dom∈ (dom⊆ ex-⊆ a∈) + + ∈-resᶜ-dom⁺ : ∀ {a} → a ∉ X × ∃[ b ] (a , b) ∈ R → a ∈ dom (R ∣ X ᶜ) + ∈-resᶜ-dom⁺ (a∉X , (b , ab∈R)) = to dom∈ (b , (∈⇔P (a∉X , ab∈R))) + + ∈-resᶜ-dom : ∀ {a} → a ∈ dom (R ∣ X ᶜ) ⇔ (a ∉ X × ∃[ b ] (a , b) ∈ R) + ∈-resᶜ-dom = mk⇔ ∈-resᶜ-dom⁻ ∈-resᶜ-dom⁺ + + res-ex-∪ : Decidable (_∈ X) → (R ∣ X) ∪ (R ∣ X ᶜ) ≡ᵉ R + res-ex-∪ ∈X? = ∪-⊆ res-⊆ ex-⊆ , λ {a} h → case ∈X? (proj₁ a) of λ where + (yes p) → ∈⇔P (inj₁ (∈⇔P (p , h))) + (no ¬p) → ∈⇔P (inj₂ (∈⇔P (¬p , h))) + + res-ex-disjoint : disjoint (dom (R ∣ X)) (dom (R ∣ X ᶜ)) + res-ex-disjoint h h' = res-comp-dom h' (res-dom h) + + res-ex-disj-∪ : Decidable (_∈ X) → R ≡ (R ∣ X) ⨿ (R ∣ X ᶜ) + res-ex-disj-∪ ∈X? = IsEquivalence.sym ≡ᵉ-isEquivalence (res-ex-∪ ∈X?) + , disjoint-dom⇒disjoint res-ex-disjoint + where open import Relation.Binary using (IsEquivalence) + + curryʳ : Rel (A × B) C → A → Rel B C + curryʳ R a = mapˡ proj₂ (R ∣' (sp-∘ (sp-∈ {X = ❴ a ❵}) proj₁)) + + ∈-curryʳ : ∀ {a} {b : B} {c : C} → (b , c) ∈ curryʳ R a → ((a , b) , c) ∈ R + ∈-curryʳ h = case ∈⇔P h of λ where + (((a , b) , c) , refl , h'') → case ∈⇔P h'' of λ where + (p , p') → case from ∈-singleton p of λ where refl → p' + + open Intersection sp-∈ + open Intersectionᵖ sp-∈ + + res-dom-comm⊆∩ : {m : Rel A B} {m' : Rel A C} → dom (m ∣ dom m') ⊆ dom m ∩ dom m' + res-dom-comm⊆∩ x = to ∈-∩ (res-domᵐ x , res-dom x) + + res-dom-comm∩⊆ : {m : Rel A B} {m' : Rel A C} → dom m ∩ dom m' ⊆ dom (m ∣ dom m') + res-dom-comm∩⊆ {m = m} {m' = m'} x with from ∈-∩ x + ... | a∈dm , a∈dm' with from dom∈ a∈dm | from dom∈ a∈dm' + ... | b , ab∈m | c , ac∈m = to dom∈ (b , to ∈-filter (a∈dm' , ab∈m)) + + res-dom-comm' : {m : Rel A B} {m' : Rel A C} → dom (m ∣ dom m') ≡ᵉ dom m ∩ dom m' + res-dom-comm' = res-dom-comm⊆∩ , res-dom-comm∩⊆ + + res-dom-comm : {m : Rel A B} {m' : Rel A C} → dom (m ∣ dom m') ≡ᵉ dom (m' ∣ dom m) + res-dom-comm {m = m} {m'} = begin + dom (m ∣ dom m') ≈⟨ res-dom-comm' ⟩ + dom m ∩ dom m' ≈˘⟨ ∩-sym ⟩ + dom m' ∩ dom m ≈˘⟨ res-dom-comm' ⟩ + dom (m' ∣ dom m) ∎ + where open SetoidReasoning ≡ᵉ-Setoid + +module Corestriction (sp-∈ : spec-∈ B) where + + _∣^_ : Rel A B → Set B → Rel A B + m ∣^ X = m ∣^' sp-∈ {X} + + _∣^_ᶜ : Rel A B → Set B → Rel A B + m ∣^ X ᶜ = m ∣^' sp-¬ (sp-∈ {X}) + + cores-⊆ : (R ∣^ X) ⊆ R + cores-⊆ = proj₂ ∘′ ∈⇔P + + coex-⊆ : (R ∣^ X ᶜ) ⊆ R + coex-⊆ = proj₂ ∘′ ∈⇔P diff --git a/src/Axiom/Set/Sum.agda b/src/Axiom/Set/Sum.agda new file mode 100644 index 000000000..8e38eabd7 --- /dev/null +++ b/src/Axiom/Set/Sum.agda @@ -0,0 +1,157 @@ +{-# OPTIONS --safe --no-import-sorts #-} + +open import Axiom.Set using (Theory) +open import Algebra using (CommutativeMonoid) + +open import Prelude hiding (ε) + +-- FIXME: this presents a much nicer interface if we use IsCommutativeMonoid' instead +module Axiom.Set.Sum (th : Theory {lzero}) ⦃ M : CommutativeMonoid 0ℓ 0ℓ ⦄ where +open Theory th +open import Axiom.Set.Factor th +open import Axiom.Set.Properties th +open import Axiom.Set.Rel th +open import Axiom.Set.Map th + +open import Algebra.Properties.CommutativeSemigroup using (x∙yz≈y∙xz) +import Data.Sum.Properties as ⊎ +open import Data.List.Ext.Properties using (dedup-++-↭) +open import Data.List.Relation.Binary.Permutation.Propositional +open import Data.List.Relation.Unary.Unique.Propositional using (Unique) +open import Relation.Binary using (_Preserves_⟶_; IsEquivalence) +open import Relation.Unary using (Decidable) + +open import Tactic.AnyOf +open import Tactic.Defaults + +-- Because of missing macro hygiene, we have to copy&paste this. +-- c.f. https://github.com/agda/agda/issues/3819 +private macro + ∈⇒P = anyOfⁿᵗ + (quote ∈-filter⁻' ∷ quote ∈-∪⁻ ∷ quote ∈-map⁻' ∷ quote ∈-fromList⁻ ∷ []) + P⇒∈ = anyOfⁿᵗ + (quote ∈-filter⁺' ∷ quote ∈-∪⁺ ∷ quote ∈-map⁺' ∷ quote ∈-fromList⁺ ∷ []) + ∈⇔P = anyOfⁿᵗ + ( quote ∈-filter⁻' ∷ quote ∈-∪⁻ ∷ quote ∈-map⁻' ∷ quote ∈-fromList⁻ + ∷ quote ∈-filter⁺' ∷ quote ∈-∪⁺ ∷ quote ∈-map⁺' ∷ quote ∈-fromList⁺ ∷ []) + +private variable + A B : Type + X Y : Set A + +open CommutativeMonoid M renaming (trans to ≈-trans) +import Relation.Binary.Reasoning.Setoid as SetoidReasoning +open SetoidReasoning (CommutativeMonoid.setoid M) +open import Data.List.Properties using (foldr-++) + +private variable f : A → Carrier + +indexedSumL : (A → Carrier) → List A → Carrier +indexedSumL f = foldr (λ x → f x ∙_) ε + +syntax indexedSumL (λ a → x) m = ∑ˡ[ a ← m ] x + +indexedSumL' : (A → Carrier) → Σ (List A) Unique → Carrier +indexedSumL' f = indexedSumL f ∘ proj₁ + +fold-cong↭ : ∀ {l l' : List A} + → l ↭ l' + → foldr (λ x → f x ∙_) ε l ≈ foldr (λ x → f x ∙_) ε l' +fold-cong↭ refl = begin _ ∎ +fold-cong↭ (prep _ h) = ∙-congˡ (fold-cong↭ h) +fold-cong↭ {f = f} (swap {xs} {ys} x y h) = begin + f x ∙ (f y ∙ indexedSumL f xs) ≈⟨ x∙yz≈y∙xz commutativeSemigroup _ _ _ ⟩ + f y ∙ (f x ∙ indexedSumL f xs) ≈⟨ ∙-congˡ (∙-congˡ (fold-cong↭ h)) ⟩ + f y ∙ (f x ∙ indexedSumL f ys) ∎ +fold-cong↭ (trans h h₁) = ≈-trans (fold-cong↭ h) (fold-cong↭ h₁) + +indexedSum : ⦃ _ : DecEq A ⦄ → (A → Carrier) → FinSet A → Carrier +indexedSum f = let open FactorUnique _≈_ (indexedSumL' f) fold-cong↭ in factor + +indexedSumL-++ : {l l' : List A} + → indexedSumL f (l ++ l') ≈ indexedSumL f l ∙ indexedSumL f l' +indexedSumL-++ {f = f} {l = l} {l'} = begin + indexedSumL f (l ++ l') ≡⟨ foldr-++ (λ x → f x ∙_) ε l l' ⟩ + foldr (λ x → f x ∙_) (indexedSumL f l') l ≈⟨ helper (indexedSumL f l') l f ⟩ + indexedSumL f l ∙ indexedSumL f l' ∎ + where + helper : ∀ m (l : List A) f → foldr (λ x → f x ∙_) m l ≈ indexedSumL f l ∙ m + helper m [] f = begin m ≈˘⟨ identityˡ m ⟩ ε ∙ m ∎ + helper m (x ∷ l) f = begin + f x ∙ foldr (λ y → f y ∙_) m l ≈⟨ ∙-congˡ (helper m l f) ⟩ + f x ∙ (indexedSumL f l ∙ m) ≈˘⟨ assoc _ _ _ ⟩ + f x ∙ indexedSumL f l ∙ m ∎ + + +module _ ⦃ _ : DecEq A ⦄ {f : A → Carrier} where + open FactorUnique _≈_ (indexedSumL' f) fold-cong↭ + + indexedSum-cong : indexedSum f Preserves (_≡ᵉ_ on proj₁) ⟶ _≈_ + indexedSum-cong {x} {y} = factor-cong {x = x} {y} + + indexedSum-∅ : indexedSum f (∅ , ∅-finite) ≈ ε + indexedSum-∅ = begin _ ∎ + + indexedSum-∪ : ⦃ Xᶠ : finite X ⦄ ⦃ Yᶠ : finite Y ⦄ → disjoint X Y + → indexedSum f ((X ∪ Y) ᶠ) ≈ indexedSum f (X ᶠ) ∙ indexedSum f (Y ᶠ) + indexedSum-∪ disj = factor-∪' {λ x y z → z ≈ x ∙ y} disj + λ {l} disj' → ≈-trans (fold-cong↭ (dedup-++-↭ disj')) + (indexedSumL-++ {l = deduplicate _≟_ l}) + + indexedSum-singleton : ∀ {x} → indexedSum f (❴ x ❵ , singleton-finite) ≈ f x + indexedSum-singleton = identityʳ _ + + indexedSum-singleton' : ∀ {x} → (pf : finite ❴ x ❵) + → indexedSum f (❴ x ❵ , pf) ≈ f x + indexedSum-singleton' {x = x} pf = + ≈-trans (indexedSum-cong {x = -, pf} {y = -, singleton-finite} ≡ᵉ.refl) + indexedSum-singleton + where module ≡ᵉ = IsEquivalence ≡ᵉ-isEquivalence + +module _ ⦃ _ : DecEq A ⦄ ⦃ _ : DecEq B ⦄ where + + indexedSumᵐ : (A × B → Carrier) → FinMap A B → Carrier + indexedSumᵐ f (m , _ , h) = indexedSum f (m , h) + + indexedSumᵛ : (B → Carrier) → FinMap A B → Carrier + indexedSumᵛ f = indexedSumᵐ (f ∘ proj₂) + + indexedSumᵐ-cong : {f : A × B → Carrier} + → indexedSumᵐ f Preserves (_≡ᵉ_ on proj₁) ⟶ _≈_ + indexedSumᵐ-cong {x = x , _ , h} {y , _ , h'} = indexedSum-cong {x = x , h} {y , h'} + + module IndexedSumUnionᵐ + (sp-∈ : spec-∈ A) (∈-A-dec : {X : Set A} → Decidable¹ (_∈ X)) where + + open Unionᵐ sp-∈ + + ∪ˡ-finite : {R R' : Rel A B} → finite R → finite R' → finite (R ∪ˡ' R') + ∪ˡ-finite Rᶠ R'ᶠ = ∪-preserves-finite Rᶠ + $ filter-finite (sp-∘ (sp-¬ sp-∈) _) (¬? ∘ ∈-A-dec ∘ _) R'ᶠ + + _∪ˡᶠ_ : FinMap A B → FinMap A B → FinMap A B + (_ , hX , Xᶠ) ∪ˡᶠ (_ , hY , Yᶠ) = + toFinMap ((_ , hX) ∪ˡ (_ , hY)) (∪ˡ-finite Xᶠ Yᶠ) + + indexedSumᵐ-∪ : ∀ {X Y : FinMap A B} {f} + → disjoint (dom (toRel X)) (dom (toRel Y)) + → indexedSumᵐ f (X ∪ˡᶠ Y) ≈ indexedSumᵐ f X ∙ indexedSumᵐ f Y + indexedSumᵐ-∪ {X = X'@(X , _ , Xᶠ)} {Y'@(Y , _ , Yᶠ)} {f} disj = begin + indexedSumᵐ f (X' ∪ˡᶠ Y') ≈⟨ indexedSum-cong {x = -, ∪ˡ-finite Xᶠ Yᶠ} {(X ∪ Y) ᶠ} + $ disjoint-∪ˡ-∪ disj ⟩ + indexedSum f ((X ∪ Y) ᶠ) ≈⟨ indexedSum-∪ (disjoint-dom⇒disjoint disj) ⟩ + indexedSumᵐ f X' ∙ indexedSumᵐ f Y' ∎ + where instance _ = Xᶠ + _ = Yᶠ + + indexedSumᵐ-partition : ∀ {m m₁ m₂ : FinMap A B} {f} → toRel m ≡ toRel m₁ ⨿ toRel m₂ + → indexedSumᵐ f m ≈ indexedSumᵐ f m₁ ∙ indexedSumᵐ f m₂ + indexedSumᵐ-partition {m} {m₁} {m₂} {f} m≡m₁∪m₂ = begin + indexedSumᵐ f m ≈⟨ indexedSumᵐ-cong {x = m} {m₁ ∪ˡᶠ m₂} helper ⟩ + indexedSumᵐ f (m₁ ∪ˡᶠ m₂) ≈⟨ indexedSumᵐ-∪ {X = m₁} {Y = m₂} disj-dom' ⟩ + indexedSumᵐ f m₁ ∙ indexedSumᵐ f m₂ ∎ + where module ≡ᵉ = IsEquivalence ≡ᵉ-isEquivalence + disj-dom' = disj-dom {m = toMap m} {toMap m₁} {toMap m₂} m≡m₁∪m₂ + + helper : toRel m ≡ᵉ toRel (m₁ ∪ˡᶠ m₂) + helper = ≡ᵉ.trans (proj₁ m≡m₁∪m₂) (≡ᵉ.sym $ disjoint-∪ˡ-∪ disj-dom') diff --git a/src/Axiom/Set/TotalMap.agda b/src/Axiom/Set/TotalMap.agda new file mode 100644 index 000000000..e03e65ec7 --- /dev/null +++ b/src/Axiom/Set/TotalMap.agda @@ -0,0 +1,109 @@ +{-# OPTIONS --safe --no-import-sorts #-} + +open import Axiom.Set using ( Theory ) + +module Axiom.Set.TotalMap (th : Theory) where + +open import Prelude hiding (lookup; map) + +open import Data.Product.Properties using (Σ-≡,≡→≡) +open import Axiom.Set.Map th using (left-unique; Map ; mapWithKey-uniq ; left-unique-mapˢ) +open import Axiom.Set.Rel th using (Rel ; dom ; dom∈) +open import Class.DecEq using (DecEq ; _≟_) + +open Theory th using (_∈_ ; map ; Set ; ∈-map ; ∈-map′ ; isMaximal) +open Equivalence using (to ; from) + +private variable A B : Type + + +-- defines a total map for a given set +total : Rel A B → Type +total R = ∀ {a} → a ∈ dom R + + +record TotalMap (A B : Type) : Type where + field rel : Set (A × B) + left-unique-rel : left-unique rel + total-rel : total rel + + toMap : Map A B + toMap = rel , left-unique-rel + + lookup : A → B + lookup _ = proj₁ (from dom∈ total-rel) + + -- verify that lookup is what we expect + lookup∈rel : {a : A} → (a , lookup a) ∈ rel + lookup∈rel = proj₂ (from dom∈ total-rel) + + -- this is useful for proving equalities involving lookup + ∈-rel⇒lookup-≡ : {a : A}{b : B} → (a , b) ∈ rel → lookup a ≡ b + ∈-rel⇒lookup-≡ ab∈rel = sym (left-unique-rel ab∈rel (proj₂ (from dom∈ total-rel))) + + +module Update {B : Type} ⦃ _ : DecEq A ⦄ where + + private + updateFn : A × B → A → B → B + updateFn (a , b) x y with (x ≟ a) + ... | yes _ = b + ... | no _ = y + + updateFn-id : {a : A}{b b' : B} → b ≡ updateFn (a , b) a b' + updateFn-id {a = a} with (a ≟ a) + ... | yes _ = refl + ... | no ¬p = ⊥-elim (¬p refl) + + + open TotalMap + + mapWithKey : {B' : Type} → (A → B → B') → TotalMap A B → TotalMap A B' + mapWithKey f tm .rel = map (λ{(x , y) → x , f x y}) (rel tm) + mapWithKey _ tm .left-unique-rel = mapWithKey-uniq (left-unique-rel tm) + mapWithKey _ tm .total-rel = ∈-map′ (∈-map′ (proj₂ (from dom∈ (total-rel tm)))) + + update : A → B → TotalMap A B → TotalMap A B + update a b = mapWithKey (updateFn (a , b)) + + + +module LookupUpdate + {X : Set A} + {a : A} {a∈X : a ∈ X} + {b : B} + ⦃ decEqA : DecEq A ⦄ where + + open TotalMap + open Update + + ∈-rel-update : (tm : TotalMap A B) → (a , b) ∈ rel (update a b tm) + ∈-rel-update tm = to ∈-map ((a , lookup tm a) , Σ-≡,≡→≡ (refl , updateFn-id {A = A}) , lookup∈rel tm) + + lookup-update-id : (tm : TotalMap A B) → lookup (update a b tm) a ≡ b + lookup-update-id tm = ∈-rel⇒lookup-≡ (update _ _ tm) (∈-rel-update tm) + + + +------------------------------------------------------ +-- Correspondences between total maps and functions -- + +module FunTot (X : Set A) (⋁A≡X : isMaximal X) where + open TotalMap + + Fun⇒Map : ∀ {A B} {f : A → B} (X : Set A) → Map A B + Fun⇒Map {f = f} X = map (λ x → (x , f x)) X , left-unique-mapˢ X + + + Fun⇒TotalMap : (f : A → B) → TotalMap A B + Fun⇒TotalMap f .rel = map (λ x → (x , f x)) X + Fun⇒TotalMap _ .left-unique-rel = left-unique-mapˢ X + Fun⇒TotalMap _ .total-rel = ∈-map′ (∈-map′ ⋁A≡X) + + Fun∈TotalMap : {f : A → B}{a : A} + → a ∈ X → (a , f a) ∈ rel (Fun⇒TotalMap f) + Fun∈TotalMap a∈X = ∈-map′ a∈X + + lookup∘Fun⇒TotalMap-id : {f : A → B}{a : A} + → lookup (Fun⇒TotalMap f) a ≡ f a + lookup∘Fun⇒TotalMap-id {f = f} = ∈-rel⇒lookup-≡ ((Fun⇒TotalMap f)) (Fun∈TotalMap ⋁A≡X) diff --git a/src/Axiom/Set/TotalMapOn.agda b/src/Axiom/Set/TotalMapOn.agda new file mode 100644 index 000000000..e542b0ba8 --- /dev/null +++ b/src/Axiom/Set/TotalMapOn.agda @@ -0,0 +1,59 @@ +{-# OPTIONS --safe --no-import-sorts #-} + +open import Axiom.Set using (Theory) + +module Axiom.Set.TotalMapOn (th : Theory) where + +open import Prelude hiding (lookup; map) + +open import Axiom.Set.Map th using (left-unique ; Map ; mapWithKey-uniq) +open import Axiom.Set.Rel th using (Rel ; dom ; dom∈) +open import Class.DecEq using (DecEq ; _≟_) + +open Theory th using ( Set ; _⊆_ ; _∈_ ; map ; ∈-map′ ) +open Equivalence using (from) + +private variable A B : Type + +_TotalOn_ : Rel A B → Set A → Type +R TotalOn X = X ⊆ dom R + + +record TotalMapOn {A : Type}(X : Set A)(B : Type) : Type where + field rel : Set (A × B) + left-unique-rel : left-unique rel + total-rel : rel TotalOn X + + toMap : Map A B + toMap = rel , left-unique-rel + + lookup : Σ A (_∈ X) → B + lookup (_ , a∈X) = proj₁ (from dom∈ (total-rel a∈X)) + + -- verify that lookup is what we expect + lookup∈rel : {a : A} (a∈X : a ∈ X) → (a , lookup (a , a∈X)) ∈ rel + lookup∈rel a∈X = proj₂ (from dom∈ (total-rel a∈X)) + + -- this is useful for proving equalities involving lookup + rel⇒lookup : {a : A} {a∈dom : a ∈ X} {b : B} → (a , b) ∈ rel → lookup (a , a∈dom) ≡ b + rel⇒lookup {a} {a∈dom} ab∈rel = sym (left-unique-rel ab∈rel (proj₂ (from dom∈ (total-rel a∈dom)))) + + +module UpdateOn {B : Type} ⦃ _ : DecEq A ⦄ where + + private + updateFn : A × B → A → B → B + updateFn (a , b) x y with (x ≟ a) + ... | yes _ = b + ... | no _ = y + + open TotalMapOn + + mapWithKeyOn : {X : Set A}{B' : Type} → (A → B → B') → TotalMapOn X B → TotalMapOn X B' + mapWithKeyOn f tm .rel = map (λ{(x , y) → x , f x y}) (rel tm) + mapWithKeyOn _ tm .left-unique-rel = mapWithKey-uniq (left-unique-rel tm) + mapWithKeyOn _ tm .total-rel a∈X = ∈-map′ (∈-map′ (proj₂ (from dom∈ ((total-rel tm) a∈X)))) + + -- Return a new total map which is the same as the given total map except at a. + update : {X : Set A} → A → B → TotalMapOn X B → TotalMapOn X B + update a b = mapWithKeyOn (updateFn (a , b)) diff --git a/src/Data/Integer/Ext.agda b/src/Data/Integer/Ext.agda new file mode 100644 index 000000000..5604a540e --- /dev/null +++ b/src/Data/Integer/Ext.agda @@ -0,0 +1,29 @@ +{-# OPTIONS --safe #-} + +module Data.Integer.Ext where + +open import Data.Integer +open import Data.Integer.Properties using ([1+m]⊖[1+n]≡m⊖n) +open import Data.Nat +open import Data.Product +open import Data.Sign +open import Relation.Binary.PropositionalEquality using (_≡_; sym; cong; trans) + +ℤtoSignedℕ : ℤ → Sign × ℕ +ℤtoSignedℕ x = (sign x , ∣ x ∣) + +posPart : ℤ → ℕ +posPart x with ℤtoSignedℕ x +... | (Sign.+ , x) = x +... | _ = 0 + +negPart : ℤ → ℕ +negPart x with ℤtoSignedℕ x +... | (Sign.- , x) = x +... | _ = 0 + +∸≡posPart⊖ : {m n : ℕ} → (m ∸ n) ≡ posPart (m ⊖ n) +∸≡posPart⊖ {zero} {zero} = _≡_.refl +∸≡posPart⊖ {zero} {ℕ.suc n} = _≡_.refl +∸≡posPart⊖ {ℕ.suc m} {zero} = _≡_.refl +∸≡posPart⊖ {ℕ.suc m} {ℕ.suc n} = trans (∸≡posPart⊖{m}{n}) (sym (cong posPart (([1+m]⊖[1+n]≡m⊖n m n)))) diff --git a/src/Data/List/Ext.agda b/src/Data/List/Ext.agda new file mode 100644 index 000000000..4a48151e4 --- /dev/null +++ b/src/Data/List/Ext.agda @@ -0,0 +1,51 @@ +{-# OPTIONS --safe #-} +module Data.List.Ext where + +open import Agda.Primitive using () renaming (Set to Type) + +open import Data.List using (List; _++_; map; concatMap; filter) +open import Data.List.Membership.Propositional using (_∈_) +open import Data.List.Membership.Propositional.Properties using (∈-map⁻; ∈-map⁺; ∈-filter⁻; ∈-filter⁺) +open import Data.Maybe using (Maybe) +open import Data.Nat using (ℕ) +open import Data.Product using (∃-syntax; _×_; _,_; proj₁; proj₂) +open import Function.Bundles using (_⇔_; mk⇔; Equivalence) +open import Level using (Level) +open import Relation.Binary.PropositionalEquality using (_≡_) +open import Relation.Unary using (Decidable) +open Maybe; open List; open ℕ +private variable + ℓ : Level + A B : Type ℓ + +-- Looking up an index into the list; fails when out-of-bounds. +_⁉_ : List A → ℕ → Maybe A +[] ⁉ _ = nothing +(x ∷ _) ⁉ zero = just x +(_ ∷ xs) ⁉ suc n = xs ⁉ n + +-- sublists of the given list +sublists : List A → List (List A) +sublists [] = [] ∷ [] +sublists (x ∷ xs) = map (x ∷_) (sublists xs) ++ sublists xs + +-- insert the given element in every position of the given list +insert : A → List A → List (List A) +insert x [] = (x ∷ []) ∷ [] +insert x (y ∷ ys) = (x ∷ y ∷ ys) ∷ map (y ∷_) (insert x ys) + +-- permutations of all sublists of the given list +subpermutations : List A → List (List A) +subpermutations [] = [] ∷ [] +subpermutations (x ∷ xs) = concatMap (insert x) (subpermutations xs) ++ subpermutations xs + +module _ {f : A → B} {l : List A} {b} {P : A → Type} {P? : Decidable P} where + ∈ˡ-map-filter⁻ : b ∈ map f (filter P? l) → (∃[ a ] a ∈ l × b ≡ f a × P a) + ∈ˡ-map-filter⁻ h with ∈-map⁻ f h + ... | a , a∈X , _≡_.refl = a , proj₁ (∈-filter⁻ P? a∈X) , _≡_.refl , proj₂ (∈-filter⁻ P? {xs = l} a∈X) + + ∈ˡ-map-filter⁺ : (∃[ a ] a ∈ l × b ≡ f a × P a) → b ∈ map f (filter P? l) + ∈ˡ-map-filter⁺ (a , a∈l , _≡_.refl , Pa) = ∈-map⁺ f (∈-filter⁺ P? a∈l Pa) + + ∈ˡ-map-filter : (∃[ a ] a ∈ l × b ≡ f a × P a) ⇔ b ∈ map f (filter P? l) + ∈ˡ-map-filter = mk⇔ ∈ˡ-map-filter⁺ ∈ˡ-map-filter⁻ diff --git a/src/Data/List/Ext/Properties.agda b/src/Data/List/Ext/Properties.agda new file mode 100644 index 000000000..37766254f --- /dev/null +++ b/src/Data/List/Ext/Properties.agda @@ -0,0 +1,334 @@ +{-# OPTIONS --safe #-} + +module Data.List.Ext.Properties where + +open import Prelude hiding (lookup; map) + +import Data.Product +import Data.Sum +import Function.Related.Propositional as R +open import Data.List using (List; [_]; []; _++_; head; tail; length; map; filter) +open import Data.List.Ext using (insert; subpermutations; sublists) +open import Data.List.Properties using (concat-++; map-++; ++-identityʳ; ++-assoc) +open import Data.List.Membership.Propositional using (_∈_) +open import Data.List.Membership.Propositional.Properties + using (∈-++⁻; ∈-++⁺ˡ; ∈-++⁺ʳ; ∈-deduplicate⁻; ∈-deduplicate⁺; ∈-map⁺) +open import Data.List.Relation.Binary.BagAndSetEquality using (∼bag⇒↭) +open import Data.List.Relation.Binary.Disjoint.Propositional using (Disjoint) +open import Data.List.Relation.Binary.Permutation.Propositional using (_↭_) +open import Data.List.Relation.Binary.Subset.Propositional using (_⊆_) +open import Data.List.Relation.Binary.Subset.Propositional.Properties as P + using (xs⊆ys++xs; xs⊆xs++ys; ⊆-reflexive; ⊆-trans) +open import Data.List.Relation.Unary.AllPairs using (AllPairs; []; _∷_) +open import Data.List.Relation.Unary.All using (all?; All; lookup) renaming (tail to Alltail) +open import Data.List.Relation.Unary.Any using (Any; here; there) +open import Data.List.Relation.Unary.Unique.Propositional using (Unique) +open import Data.List.Relation.Unary.Unique.Propositional.Properties using (drop⁺) +open import Data.List.Relation.Unary.Unique.Propositional.Properties.WithK using (unique∧set⇒bag) +open import Data.Nat.Properties using (_≤?_; ⊔-identityʳ; ≤-reflexive; ≤-trans; m≤n⊔m; m≤m⊔n) +open import Data.Nat using (_⊔_; _≤_) + +open Equivalence + +-- TODO: stdlib? +_×-cong_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {k} → A R.∼[ k ] B → C R.∼[ k ] D → (A × C) R.∼[ k ] (B × D) +h ×-cong h' = (h M.×-cong h') + where open import Data.Product.Function.NonDependent.Propositional as M + +_⊎-cong_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {k} → A R.∼[ k ] B → C R.∼[ k ] D → (A ⊎ C) R.∼[ k ] (B ⊎ D) +h ⊎-cong h' = (h M.⊎-cong h') + where open import Data.Sum.Function.Propositional as M + +-- TODO: stdlib? +AllPairs⇒≡∨R∨Rᵒᵖ : ∀ {ℓ ℓ'} {A : Set ℓ} {R : A → A → Set ℓ'} {a b l} + → AllPairs R l → a ∈ l → b ∈ l → a ≡ b ⊎ R a b ⊎ R b a +AllPairs⇒≡∨R∨Rᵒᵖ (_ ∷ _) (here refl) (here refl) = inj₁ refl +AllPairs⇒≡∨R∨Rᵒᵖ (x ∷ _) (here refl) (there b∈l) = inj₂ (inj₁ (lookup x b∈l)) +AllPairs⇒≡∨R∨Rᵒᵖ (x ∷ _) (there a∈l) (here refl) = inj₂ (inj₂ (lookup x a∈l)) +AllPairs⇒≡∨R∨Rᵒᵖ (x ∷ h) (there a∈l) (there b∈l) = AllPairs⇒≡∨R∨Rᵒᵖ h a∈l b∈l + +-------------------------------------------------------------- +------- duplicate entries in lists and deduplication --------- +-------------------------------------------------------------- +module _ {a} {A : Set a} ⦃ _ : DecEq A ⦄ where + open import Data.List.Relation.Unary.Unique.DecPropositional.Properties {A = A} _≟_ + + deduplicate≡ : List A → List A + deduplicate≡ = deduplicate _≟_ + + disj-on-dedup : ∀ {l l'} → Disjoint l l' → Disjoint (deduplicate≡ l) (deduplicate≡ l') + disj-on-dedup = _∘ Data.Product.map (∈-deduplicate⁻ _≟_ _) (∈-deduplicate⁻ _≟_ _) + + ∈-dedup : ∀ {l a} → a ∈ l ⇔ a ∈ deduplicate≡ l + ∈-dedup = mk⇔ (∈-deduplicate⁺ _≟_) (∈-deduplicate⁻ _≟_ _) + + -- TODO: stdlib? + dedup-++-↭ : {l l' : List A} → Disjoint l l' → deduplicate≡ (l ++ l') ↭ deduplicate≡ l ++ deduplicate≡ l' + dedup-++-↭ {l = l} {l'} disj = let dedup-unique = λ {l} → deduplicate-! l in ∼bag⇒↭ $ + unique∧set⇒bag dedup-unique (++⁺ dedup-unique dedup-unique (disj-on-dedup disj)) λ {a} → + a ∈ deduplicate≡ (l ++ l') ∼⟨ R.SK-sym ∈-dedup ⟩ + a ∈ l ++ l' ∼⟨ helper ⟩ + (a ∈ l ⊎ a ∈ l') ∼⟨ ∈-dedup ⊎-cong ∈-dedup ⟩ + (a ∈ deduplicate≡ l ⊎ a ∈ deduplicate≡ l') ∼⟨ R.SK-sym helper ⟩ + a ∈ deduplicate≡ l ++ deduplicate≡ l' ∎ + where open R.EquationalReasoning + helper : ∀ {l l' a} → a ∈ l ++ l' ⇔ (a ∈ l ⊎ a ∈ l') + helper = mk⇔ (∈-++⁻ _) Data.Sum.[ ∈-++⁺ˡ , ∈-++⁺ʳ _ ] + +------------------------------------------------------------ +-------- maximum length of lists in a list of lists -------- +------------------------------------------------------------ +module _ {a} {A : Set a} where + maxlen : List (List A) → ℕ + maxlen ls = foldr (λ l n → length l ⊔ n) 0 ls + + maxlen≤∷ : ∀ ls l → maxlen ls ≤ maxlen (l ∷ ls) + maxlen≤∷ [] _ = z≤n + maxlen≤∷ (l' ∷ ls) l = subst (maxlen (l' ∷ ls) ≤_) refl (m≤n⊔m (length l) (maxlen (l' ∷ ls))) + + ∈-maxlen-≤ : ∀ {ls} l → l ∈ ls → length l ≤ maxlen ls + ∈-maxlen-≤ {l ∷ ls} .l (here refl) = subst (length l ≤_) refl (m≤m⊔n (length l) (maxlen ls)) + ∈-maxlen-≤ {l' ∷ ls} l (there l∈) = ≤-trans (∈-maxlen-≤ l l∈) (maxlen≤∷ ls l') + +------------------------------- +------ properties of map ------ +------------------------------- +module _ {a} {A : Set a} where + + ¬[]∈map : {ls : List (List A)} {z : A} → ¬ [] ∈ map (z ∷_) ls + ¬[]∈map {_ ∷ _} (there p) = ¬[]∈map p + + map∷decomp∈ : {ls : List (List A)} {xs : List A} {y x : A} → x ∷ xs ∈ map (y ∷_) ls → x ≡ y × xs ∈ ls + map∷decomp∈ {_ ∷ _} (here refl) = refl , (here refl) + map∷decomp∈ {_ ∷ _} (there xxs∈) = (proj₁ (map∷decomp∈ xxs∈)) , there (proj₂ (map∷decomp∈ xxs∈)) + + map∷decomp : {ls : List (List A)} {xs : List A} {y : A} + → xs ∈ map (y ∷_) ls → ∃[ ys ] ys ∈ ls × y ∷ ys ≡ xs + map∷decomp {l ∷ _} {.(_ ∷ l)} (here refl) = l , ((here refl) , refl) + map∷decomp {_ ∷ _} {[]} (there xs∈) = ⊥-elim (¬[]∈map xs∈) + map∷decomp {_ ∷ _} {x ∷ xs} (there xs∈) = + xs , there (proj₂ (map∷decomp∈ xs∈)) , subst (λ u → u ∷ xs ≡ x ∷ xs) (proj₁ (map∷decomp∈ xs∈)) refl + + ∈-map : {ls : List (List A)} {y : A} → ∀ l → l ∈ map (y ∷_) ls → y ∈ l + ∈-map {l ∷ _} .(_ ∷ l) (here refl) = here refl + ∈-map {_ ∷ _} l (there l∈) = ∈-map l l∈ + +------------------------------------------------------ +-------- Properties of list-subset inclusion --------- +------------------------------------------------------ +module _ {a} {A : Set a} where + ⊆y∷∧y∉→⊆ys : ∀ {ys xs} {y : A} → xs ⊆ y ∷ ys → ¬ y ∈ xs → xs ⊆ ys + ⊆y∷∧y∉→⊆ys xsyys y∉xs x∈xs with xsyys x∈xs + ... | here refl = ⊥-elim (y∉xs x∈xs) + ... | there p = p + + ¬∈[] : {x : A} → ¬ x ∈ [] + ¬∈[] = λ () + + ¬⊆[] : {xs : List A} {x : A} → ¬ x ∷ xs ⊆ [] + ¬⊆[] p = ¬∈[] (p (here refl)) + + ∈∷∧⊆→∈ : {ys xs : List A} {y x : A} → x ∈ y ∷ xs → xs ⊆ ys → x ∈ y ∷ ys + ∈∷∧⊆→∈ (here px) _ = here px + ∈∷∧⊆→∈ (there x∈) xs⊆ = there (xs⊆ x∈) + +------------------------------------------ +-------- Properties of concatMap --------- +------------------------------------------ +module _ {a} {A : Set a} where + + concatMap⁺ : {ys xs : List A} {f : A → List A} → xs ⊆ ys → concatMap f xs ⊆ concatMap f ys + concatMap⁺ = P.concat⁺ ∘ P.map⁺ _ + + concatMap-++ : ∀ {b} {B : Set b} (f : A → List B) xs ys + → concatMap f (xs ++ ys) ≡ concatMap f xs ++ concatMap f ys + concatMap-++ f xs ys = begin + concatMap f (xs ++ ys) ≡⟨⟩ + concat (map f (xs ++ ys)) ≡⟨ cong concat $ map-++ f xs ys ⟩ + concat (map f xs ++ map f ys) ≡˘⟨ concat-++ (map f xs) (map f ys) ⟩ + concatMap f xs ++ concatMap f ys ∎ where open ≡-Reasoning + + concatMap-decomp : ∀ {b} {B : Set b} {l : List A} {x : B} {f : A → List B} + → x ∈ concatMap f l ⇔ (∃[ z ] z ∈ l × x ∈ f z) + concatMap-decomp {l = []} = mk⇔ (λ ()) (λ (_ , v , _) → ⊥-elim (¬∈[] v)) + concatMap-decomp {l = y ∷ ys} {x} {f} = mk⇔ i ii + where + i : x ∈ concatMap f (y ∷ ys) → ∃[ z ] z ∈ y ∷ ys × x ∈ f z + i x∈ with ∈-++⁻ _ x∈ + ...| inj₁ v = y , (here refl , v) + ...| inj₂ v with to concatMap-decomp v + ...| z , z∈ys , x∈fz = z , there z∈ys , x∈fz + + ii : ∃[ z ] z ∈ y ∷ ys × x ∈ f z → x ∈ concatMap f (y ∷ ys) + ii (z , here refl , x∈) = xs⊆xs++ys (f z) _ x∈ + ii (z , there z∈ , x∈) = xs⊆ys++xs _ (f y) (from concatMap-decomp (z , (z∈ , x∈))) + +------------------------------------ +------- properties of insert ------- +------------------------------------ +module _ {a} {A : Set a} where + ∷∈insert : {ys : List A} {x : A} → x ∷ ys ∈ insert x ys + ∷∈insert {[]} = here refl + ∷∈insert {_ ∷ _} = here refl + + ∈-insert : ∀ {ys} {x : A} l → l ∈ insert x ys → x ∈ l + ∈-insert {[]} _ (here refl) = here refl + ∈-insert {_ ∷ _} _ (here refl) = here refl + ∈-insert {_ ∷ _} {x} _ (there l∈) with map∷decomp l∈ + ... | (l' , l'∈ , yl'l) = subst (x ∈_) yl'l (there (∈-insert l' l'∈)) + + ∈→∈-insert : ∀ {ys : List A} {y x : A} l → x ∈ ys → l ∈ insert y ys → x ∈ l + ∈→∈-insert {_ ∷ _} _ x∈ (here refl) = there x∈ + ∈→∈-insert {_ ∷ _} l (here refl) (there l∈) = ∈-map l l∈ + ∈→∈-insert {_ ∷ _} {y} {x} l (there x∈) (there l∈) with map∷decomp l∈ + ... | (l' , l'∈ , y'l'l) = subst (x ∈_) y'l'l (there (∈→∈-insert l' x∈ l'∈)) + + insert⊆∷ : ∀ {xs : List A} {x : A} l → l ∈ insert x xs → l ⊆ x ∷ xs + insert⊆∷ {[]} (_ ∷ _) (here refl) y∈ = y∈ + insert⊆∷ {_ ∷ _} (_ ∷ _) (here refl) y∈ = y∈ + insert⊆∷ {_ ∷ _} (_ ∷ _) (there l∈) {y} y∈ with map∷decomp l∈ + ... | (l' , l'∈ , x'l'zzs) = case (subst (y ∈ˡ_) (sym x'l'zzs) y∈) of λ where + (here refl) → there (here refl) + (there q) → case (insert⊆∷ l' l'∈ q) of λ where + (here refl) → here refl + (there x) → there (there x) + + insert-decomp : {ls : List (List A)} {x : A} → ∀ ys → ys ∈ concatMap (insert x) ls + → ∃[ l ] l ∈ ls × ys ⊆ x ∷ l + insert-decomp _ h = case to concatMap-decomp h of λ where + (x , y , z) → x , y , λ {_} → insert⊆∷ _ z + + insert-decomp≡ : ∀ {ys : List A} {y : A} xs → xs ∈ insert y ys + → ∃[ ll ] ∃[ lr ] xs ≡ ll ++ [ y ] ++ lr × ys ≡ ll ++ lr + insert-decomp≡ {[]} _ (here refl) = [] , [] , refl , refl + insert-decomp≡ {y ∷ ys} _ (here refl) = [] , y ∷ ys , refl , refl + insert-decomp≡ {_ ∷ _} [] (there h) = ⊥-elim (¬[]∈map h) + insert-decomp≡ {y' ∷ _} (z ∷ zs) (there h) = + case insert-decomp≡ zs (proj₂ (map∷decomp∈ h)) , proj₁ (map∷decomp∈ h) of λ where + ((ll , lr , zs≡llylr , ys≡lllr) , refl) → + y' ∷ ll , lr , cong (y' ∷_) zs≡llylr , cong (y' ∷_) ys≡lllr + +---------------------------------------------- +------- properties of subpermutations -------- +---------------------------------------------- +module _ {a} {A : Set a} where + []∈subpermutations : (l : List A) → [] ∈ subpermutations l + []∈subpermutations [] = here refl + []∈subpermutations (x ∷ xs) = xs⊆ys++xs _ (concatMap (insert x) (subpermutations xs)) + ([]∈subpermutations xs) + + Unique→dropSubheadUnique : {xs : List A} {x y : A} → Unique (x ∷ y ∷ xs) → Unique (x ∷ xs) + Unique→dropSubheadUnique ((_ All.∷ xxsU) ∷ yxsU) = xxsU ∷ (drop⁺ 1 yxsU) + + Unique→head∉tail : {xs : List A} {x : A} → Unique (x ∷ xs) → ¬ x ∈ xs + Unique→head∉tail ((px All.∷ _) ∷ _) (here refl) = px refl + Unique→head∉tail xxsU (there p) = Unique→head∉tail (Unique→dropSubheadUnique xxsU) p + + ∈-insert-cancelˡ : (ls : List (List A)) {xs : List A} {y : A} + → ¬ y ∈ xs → xs ∈ concatMap (insert y) ls ++ ls → xs ∈ ls + ∈-insert-cancelˡ ls {xs} y∉xs xs∈yls = case (∈-++⁻ _ xs∈yls) of λ where + (inj₁ v) → case (to (concatMap-decomp {l = ls}) v) of λ where + (l' , l'∈ , l∈xl') → ⊥-elim (y∉xs (∈-insert xs l∈xl')) + (inj₂ v) → v + +module _ {a} {A : Set a} where + ∈insert→∷∈insert' : {ys xs : List A} {y x : A} → x ∈ ys → ¬ x ∈ xs + → ∃[ sp ] sp ∈ subpermutations ys × xs ∈ insert y sp + → ∃[ sp' ] sp' ∈ subpermutations ys × x ∷ xs ∈ insert y sp' + + ∈insert→∷∈insert' {x ∷ ys} {xs} {y} {x} (here refl) h₂ (sp , h₃ , h₄) + = case ∈-++⁻ (concatMap (insert x) (subpermutations ys)) h₃ of λ where + (inj₁ v) → case to (concatMap-decomp {l = subpermutations ys}) v of λ where + (x , y , z) → ⊥-elim (h₂ (∈→∈-insert xs (∈-insert sp z) h₄)) + (inj₂ v) → case insert-decomp≡ _ h₄ of λ where + (ll , lr , xs≡ , sp≡) → x ∷ sp , ∈-++⁺ˡ (from concatMap-decomp (sp , v , ∷∈insert)) + , there (∈-map⁺ (x ∷_) h₄) + + ∈insert→∷∈insert' {y' ∷ ys} {xs} {y} {x} (there h₁) h₂ (sp , h₃ , h₄) + = case ∈-++⁻ (concatMap (insert y') (subpermutations ys)) h₃ of λ where + (inj₁ v) → case to concatMap-decomp v of λ where + (l , l∈ , xs∈) → case ∈insert→∷∈insert' h₁ (λ p → h₂ (∈→∈-insert xs p h₄)) (l , l∈ , xs∈) of λ where + f → let v' = x ∷ sp ∈ concatMap (insert y') (subpermutations ys) ∋ from concatMap-decomp f + in to concatMap-decomp (subst (x ∷ xs ∈ˡ_) + (sym (concatMap-++ (insert y) (concatMap (insert y') (subpermutations ys)) _)) + (∈-++⁺ˡ (from concatMap-decomp (x ∷ sp , v' , (there $ ∈-map⁺ (x ∷_) h₄))))) + (inj₂ v) → case ∈insert→∷∈insert' h₁ h₂ (sp , v , h₄) of λ where + (sp' , h'₁ , h'₂) → sp' , ∈-++⁺ʳ _ h'₁ , h'₂ + + + ∈insert→∷∈insert : {ys xs : List A} {y x : A} → x ∈ ys → ¬ x ∈ xs + → xs ∈ concatMap (insert y) (subpermutations ys) + → x ∷ xs ∈ concatMap (insert y) (subpermutations ys) + + ∈insert→∷∈insert h₁ h₂ h₃ = from concatMap-decomp $ ∈insert→∷∈insert' h₁ h₂ $ to concatMap-decomp h₃ + + + ∈-subperm-addhead : {ys xs : List A} {x : A} → x ∈ ys → ¬ x ∈ xs + → xs ∈ subpermutations ys → x ∷ xs ∈ subpermutations ys + + ∈-subperm-addhead {_ ∷ ys} (here refl) y∉xs xs∈sp = + xs⊆xs++ys _ _ (from concatMap-decomp (_ , ∈-insert-cancelˡ (subpermutations ys) y∉xs xs∈sp , ∷∈insert)) + + ∈-subperm-addhead {_ ∷ _} (there x∈ys) x∉xs xs∈sp = case ∈-++⁻ _ xs∈sp of λ where + (inj₁ v) → xs⊆xs++ys _ _ (∈insert→∷∈insert x∈ys x∉xs v) + (inj₂ v) → xs⊆ys++xs _ _ (∈-subperm-addhead x∈ys x∉xs v) + + +---------------------------------------------------------------- +------------ maximal sublists satisfying a predicate ---------- +---------------------------------------------------------------- +module _ {a} {A : Set a} + {p} {P : Pred (List A) p} where + + -- sublists of a given list which satisfy P + sublists⊧P : Decidable¹ P → List A → List (List A) + sublists⊧P P? ys = filter P? (sublists ys) + + -- sublists of a given list which satisfy P and are of maximum length among those satisfying P + maxsublists⊧P : Decidable¹ P → List A → List (List A) + maxsublists⊧P P? ys = filter (λ l → length l ≟ maxlen (sublists⊧P P? ys)) (sublists⊧P P? ys) + +-------------------------------------------------------------------------- +------------ l ⊆ ys ⋀ l Unique ⇔ l ∈ subpermutations ys ---------- +-------------------------------------------------------------------------- +module _ {a} {A : Set a} where + -- If l ⊆ ys and l has no repeated elements, then l is a subpermutation of ys. + uniqueSubset→subperm : ∀ {ys : List A} l → Unique l → l ⊆ ys → l ∈ subpermutations ys + uniqueSubset→subperm {[]} [] _ _ = here refl + uniqueSubset→subperm {[]} (_ ∷ _) _ l⊆ = ⊥-elim (¬⊆[] l⊆) + uniqueSubset→subperm {_ ∷ ys} [] _ _ = xs⊆ys++xs _ _ ([]∈subpermutations ys) + uniqueSubset→subperm {_ ∷ _} (_ ∷ xs) lU l⊆ = case l⊆ (here refl) of λ where + (here refl) → let + xs⊆ys = ⊆y∷∧y∉→⊆ys (l⊆ ∘ there) (Unique→head∉tail lU) in + xs⊆xs++ys _ _ (from concatMap-decomp (xs , uniqueSubset→subperm xs (drop⁺ 1 lU) xs⊆ys , ∷∈insert)) + (there p) → case ∈-++⁻ _ (uniqueSubset→subperm xs (drop⁺ 1 lU) (l⊆ ∘ there)) of λ where + (inj₁ v) → xs⊆xs++ys _ _ (∈insert→∷∈insert p (Unique→head∉tail lU) v) + (inj₂ v) → xs⊆ys++xs _ _ (∈-subperm-addhead p (Unique→head∉tail lU) v) + + -- If l is a subpermutation of ys, then l ⊆ ys. + subperm→subset : ∀ {ys : List A} l → l ∈ subpermutations ys → l ⊆ ys + subperm→subset {[]} .[] (here refl) () + subperm→subset {y ∷ ys} l l∈ x∈l = case ∈-++⁻ (concatMap (insert y) (subpermutations ys)) l∈ of λ where + (inj₂ v) → there (subperm→subset l v x∈l) + (inj₁ v) → case insert-decomp l v of λ where + (l' , l'∈sp , l⊆yl') → ∈∷∧⊆→∈ (l⊆yl' x∈l) (subperm→subset l' l'∈sp) + +module _ {a} {p} {A : Set a} {L : List A} {P : Pred (List A) p} where + + ∃uniqueSubset→∃subperm : ∃[ l ] l ⊆ L × Unique l × P l → ∃[ l ] l ∈ subpermutations L × P l + ∃uniqueSubset→∃subperm (l , l⊆L , lU , Pl) = l , uniqueSubset→subperm l lU l⊆L , Pl + + ∃subperm→∃subset : ∃[ l ] l ∈ subpermutations L × P l → ∃[ l ] l ⊆ L × P l + ∃subperm→∃subset (l , l∈spL , Pl) = l , subperm→subset l l∈spL , Pl + + ∃uniqueSubset→∃uniqueSubperm : ∃[ l ] l ⊆ L × Unique l × P l + → ∃[ l ] l ∈ subpermutations L × Unique l × P l + ∃uniqueSubset→∃uniqueSubperm (l , l⊆L , lU , Pl) = l , uniqueSubset→subperm l lU l⊆L , lU , Pl + + ∃uniqueSubperm→∃uniqueSubset : ∃[ l ] l ∈ subpermutations L × Unique l × P l + → ∃[ l ] l ⊆ L × Unique l × P l + ∃uniqueSubperm→∃uniqueSubset (l , l∈spL , lU , Pl) = l , subperm→subset l l∈spL , lU , Pl + + ∃uniqueSubset⇔∃uniqueSubperm : (∃[ l ] l ⊆ L × Unique l × P l) + ⇔ (∃[ l ] l ∈ subpermutations L × Unique l × P l) + ∃uniqueSubset⇔∃uniqueSubperm = mk⇔ ∃uniqueSubset→∃uniqueSubperm ∃uniqueSubperm→∃uniqueSubset diff --git a/src/Data/List/Relation/Binary/Sublist/Ext.agda b/src/Data/List/Relation/Binary/Sublist/Ext.agda new file mode 100644 index 000000000..daecc23fe --- /dev/null +++ b/src/Data/List/Relation/Binary/Sublist/Ext.agda @@ -0,0 +1,10 @@ +{-# OPTIONS --safe #-} +module Data.List.Relation.Binary.Sublist.Ext where + +open import Data.List.Relation.Binary.Sublist.Propositional public + using (_⊆_; []; _∷_; _∷ʳ_) +open import Data.List using (List; []; _∷_) + +[]⊆ : ∀ {ℓ}{A : Set ℓ} {xs : List A} → [] ⊆ xs +[]⊆ {xs = []} = [] +[]⊆ {xs = _ ∷ _} = _ ∷ʳ []⊆ diff --git a/src/Data/List/Relation/Unary/MOf.agda b/src/Data/List/Relation/Unary/MOf.agda new file mode 100644 index 000000000..272780469 --- /dev/null +++ b/src/Data/List/Relation/Unary/MOf.agda @@ -0,0 +1,57 @@ +{-# OPTIONS --safe #-} +module Data.List.Relation.Unary.MOf where + +open import Level using (Level; _⊔_) renaming (suc to lsuc) +open import Function using (_$_; case_of_) + +open import Data.Empty using (⊥-elim) +open import Data.List using (List; []; _∷_; length) +open import Data.List.Relation.Unary.All using (All; []; _∷_) +open import Data.Nat using (ℕ; zero; suc) +open import Data.Nat.Properties using (suc-injective) + +open import Relation.Nullary using (Dec; yes; no; ¬_) +open import Relation.Nullary.Decidable using () renaming (map′ to mapDec) +open import Relation.Unary using (Decidable; Pred) +open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong) + +open import Data.List.Relation.Binary.Sublist.Ext + +-- States that "m-of-n" elements of a n-element list satisfy a given predicate. +data MOf {ℓ ℓ′}{A : Set ℓ} (m : ℕ) (P : Pred A ℓ′) (xs : List A) : Set (ℓ ⊔ ℓ′) where + mOf : ∀ ys + → m ≡ length ys + → ys ⊆ xs + → All P ys + → MOf m P xs + +private module _ {ℓ ℓ′} {A : Set ℓ} {P : Pred A ℓ′} where + cons : ∀ {x xs m} → P x → MOf m P xs → MOf (suc m) P (x ∷ xs) + cons p (mOf ys refl sub ps) = mOf (_ ∷ ys) refl (refl ∷ sub) (p ∷ ps) + + skip : ∀ {x xs m} → MOf m P xs → MOf m P (x ∷ xs) + skip (mOf ys len sub ps) = mOf ys len (_ ∷ʳ sub) ps + + done : ∀ {xs} → MOf 0 P xs + done = mOf [] refl []⊆ [] + + wk : ∀ {m xs} → MOf (suc m) P xs → MOf m P xs + wk (mOf (_ ∷ ys) refl (_ ∷ sub) (_ ∷ ps)) = mOf ys refl (_ ∷ʳ sub) ps + wk (mOf ys len (_ ∷ʳ sub) ps) = skip (wk (mOf ys len sub ps)) + + uncons : ∀ {m x xs} → MOf (suc m) P (x ∷ xs) → MOf m P xs + uncons (mOf ys len (_ ∷ʳ sub) ps) = wk $ mOf ys len sub ps + uncons (mOf (_ ∷ ys) refl (_ ∷ sub) (_ ∷ ps)) = mOf ys refl sub ps + + unskip : ∀ {m x xs} → ¬ P x → MOf (suc m) P (x ∷ xs) → MOf (suc m) P xs + unskip ¬px (mOf ys len (_ ∷ʳ sub) ps) = mOf ys len sub ps + unskip ¬px (mOf ys len (refl ∷ sub) (px ∷ ps)) = ⊥-elim $ ¬px px + +module _ {ℓ ℓ′} {A : Set ℓ} {P : Pred A ℓ′} (P? : Decidable P) where + MOf? : ∀ m xs → Dec (MOf m P xs) + MOf? zero xs = yes done + MOf? (suc m) [] = no λ where (mOf (_ ∷ _) len≡ () _) + MOf? (suc m) (x ∷ xs) = + case (P? x) of λ where + (yes px) → mapDec (cons px) uncons (MOf? m xs) + (no ¬px) → mapDec skip (unskip ¬px) (MOf? (suc m) xs) diff --git a/src/Data/List/Relation/Unary/Unique/Propositional/Properties/WithK.agda b/src/Data/List/Relation/Unary/Unique/Propositional/Properties/WithK.agda new file mode 100644 index 000000000..1ed86e59c --- /dev/null +++ b/src/Data/List/Relation/Unary/Unique/Propositional/Properties/WithK.agda @@ -0,0 +1,48 @@ +------------------------------------------------------------------------ +-- The Agda standard library +-- +-- Properties of unique lists (setoid equality) using K +------------------------------------------------------------------------ + +{-# OPTIONS --safe --with-K #-} + +module Data.List.Relation.Unary.Unique.Propositional.Properties.WithK where + +open import Data.Empty +open import Data.List using (List) +open import Data.List.Membership.Propositional +open import Data.List.Relation.Binary.BagAndSetEquality +open import Data.List.Relation.Unary.All.Properties +open import Data.List.Relation.Unary.Any +open import Data.List.Relation.Unary.Unique.Propositional +open import Data.Product +open import Relation.Binary.PropositionalEquality +open import Relation.Nullary +open import Level using (Level) +open import Function.Bundles + +private + variable + a : Level + A : Set a + l l' : List A + +------------------------------------------------------------------------ +-- membership + +unique⇒∈-prop : Unique l → (x : A) → Irrelevant (x ∈ l) +unique⇒∈-prop (hx ∷ h) x (here refl) (here refl) = refl +unique⇒∈-prop (hx ∷ h) x (here refl) (there b) = ⊥-elim (All¬⇒¬Any hx b) +unique⇒∈-prop (hx ∷ h) x (there a) (here refl) = ⊥-elim (All¬⇒¬Any hx a) +unique⇒∈-prop (hx ∷ h) x (there a) (there b) rewrite unique⇒∈-prop h x a b = refl + +unique∧set⇒bag : Unique l → Unique l' → l ∼[ set ] l' → l ∼[ bag ] l' +unique∧set⇒bag h h' eq {a} = record + { to = to + ; from = from + ; to-cong = to-cong + ; from-cong = from-cong + ; inverse = (λ {x} {y} _ → unique⇒∈-prop h' a (to y) x) + , (λ {x} {y} _ → unique⇒∈-prop h a (from y) x) + } + where open Equivalence (eq {a}) diff --git a/src/Data/Nat/Properties/Ext.agda b/src/Data/Nat/Properties/Ext.agda new file mode 100644 index 000000000..b6719f6a6 --- /dev/null +++ b/src/Data/Nat/Properties/Ext.agda @@ -0,0 +1,30 @@ +{-# OPTIONS --safe #-} + +module Data.Nat.Properties.Ext where + +open import Data.Nat +open import Data.Nat.Properties +open import Prelude +open import Relation.Nullary.Decidable + +-- if P holds for 0 but not for some N, then there exists a k where the induction step fails +negInduction : {P : ℕ → Set} → Decidable¹ P + → P 0 + → ∃[ N ] ¬ P N + → ∃[ k ] P k × ¬ P (suc k) +negInduction {P = P} P? P0 (N , ¬PN) + with anyUpTo? (λ x → P? x ×-dec ¬? (P? $ suc x)) N +... | yes (k , _ , h) = k , h +... | no ¬p = contradiction (k≤N⇒Pk ≤-refl) ¬PN + where + helper : ∀ {k} → k < N → P k → P k × P (suc k) + helper {k} k