naturals exercises

This commit is contained in:
Michael Zhang 2021-09-09 01:17:09 -05:00
parent 84840b0d4d
commit 00ec52d94a
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 62 additions and 23 deletions

1
.gitignore vendored
View file

@ -30,6 +30,7 @@ Gemfile.lock
## Emacs files
auto/
\#*\#
## Misc build files
out/

View file

@ -1,3 +1,11 @@
(require 'use-package)
(require 'use-package-ensure)
(setq use-package-always-ensure t)
(use-package evil)
(use-package agda2-mode)
(use-package gruvbox-theme)
(setq evil-undo-system 'undo-tree)
(require 'evil)
(evil-mode 1)

View file

@ -1,12 +1,16 @@
{
inputs.nixpkgs.url = "github:nixos/nixpkgs?rev=860b56be91fb874d48e23a950815969a7b832fbc";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.plfa.url = "github:plfa/plfa.github.io";
inputs.plfa.flake = false;
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?rev=860b56be91fb874d48e23a950815969a7b832fbc";
flake-utils.url = "github:numtide/flake-utils";
plfa = {
flake = false;
url = "github:plfa/plfa.github.io";
};
};
outputs = { self, nixpkgs, flake-utils, plfa }:
flake-utils.lib.eachDefaultSystem
(system:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
agda = pkgs.agda.withPackages (p: [
@ -32,17 +36,17 @@
]) ++ (with epkgs.elpaPackages; [
undo-tree
]));
in {
devShell =
pkgs.mkShell {
in
{
devShell = pkgs.mkShell {
buildInputs = [
emacsWithPackages
agda
pkgs.vscodium
];
shellHook = ''
XDG_CONFIG_HOME=$(pwd) emacs
'';
};
});
}
);
}

View file

@ -81,7 +81,7 @@ successor of two; and so on.
Write out `7` in longhand.
```
-- Your code goes here
_ = suc (suc (suc (suc (suc (suc (suc zero))))))
```
@ -427,7 +427,8 @@ other word for evidence, which we will use interchangeably, is _proof_.
#### Exercise `+-example` (practice) {name=plus-example}
Compute `3 + 4`, writing out your reasoning as a chain of equations, using the equations for `+`.
Compute `3 + 4`, writing out your reasoning as a chain of equations, using the
equations for `+`.
```
-- Your code goes here
@ -506,7 +507,9 @@ Define exponentiation, which is given by the following equations:
Check that `3 ^ 4` is `81`.
```
-- Your code goes here
_^_ :
m ^ zero = 1
m ^ suc n = m * ( m ^ n)
```
@ -919,6 +922,29 @@ Confirm that these both give the correct answer for zero through four.
```
-- Your code goes here
inc : Bin → Bin
inc ⟨⟩ = ⟨⟩ O
inc (n O) = n I
inc (⟨⟩ I) = ⟨⟩ I O
inc (n I) = (inc n) O
_ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O
_ = refl
to : → Bin
to zero = ⟨⟩ O
to (suc n) = inc (to n)
from : Bin →
from ⟨⟩ = 0
from (n O) = 2 * (from n)
from (n I) = 2 * (from n) + 1
_ : to 12 ≡ ⟨⟩ I I O O
_ = refl
_ : from (⟨⟩ I O I I) ≡ 11
_ = refl
```