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

3
.gitignore vendored
View file

@ -30,8 +30,9 @@ Gemfile.lock
## Emacs files ## Emacs files
auto/ auto/
\#*\#
## Misc build files ## Misc build files
out/ out/
*.zip *.zip
versions/plfa.github.io-web-*/ versions/plfa.github.io-web-*/

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) (setq evil-undo-system 'undo-tree)
(require 'evil) (require 'evil)
(evil-mode 1) (evil-mode 1)

View file

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

View file

@ -81,7 +81,7 @@ successor of two; and so on.
Write out `7` in longhand. 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} #### 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 -- Your code goes here
@ -506,7 +507,9 @@ Define exponentiation, which is given by the following equations:
Check that `3 ^ 4` is `81`. 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 -- 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
``` ```