diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a88afb4b..b4400b60 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,32 +1,23 @@ name: Publish to GitHub Pages - on: push: branches: - master - jobs: publish: runs-on: ubuntu-latest steps: - - name: Check out - uses: actions/checkout@v1 - - - name: Set-up OCaml - uses: ocaml/setup-ocaml@v2 + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 with: - ocaml-compiler: "5.0" - - - name: Install dependencies - run: opam install -y dune base js_of_ocaml-compiler js_of_ocaml-ppx - - - name: Build the type-checker - run: opam exec -- dune build - - - name: Include the backend to the file - run: opam exec -- dune install --prefix="./_install" + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - run: nix build ./.#catt-web + - id: find-web-path + run: | + path=$(nix eval ./.#catt-web.outPath --raw) + echo "web-path=$path" >> "$GITHUB_OUTPUT" - name: Deploy 🚀 uses: JamesIves/github-pages-deploy-action@v4 with: - folder: _install/share \ No newline at end of file + folder: ${{ steps.find-web-path.outputs.web-path }}/share \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a037de9f..2fbd1491 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,24 +1,12 @@ name: Check All - on: [push] - jobs: - test: + tests: runs-on: ubuntu-latest steps: - - name: Check out - uses: actions/checkout@v1 - - - name: Set-up OCaml - uses: ocaml/setup-ocaml@v2 - with: - ocaml-compiler: "5.0" - - - name: Install dependencies - run: opam install -y dune base js_of_ocaml-compiler js_of_ocaml-ppx - - - name: Build the type-checker - run: opam exec -- dune build - - - name: Run tests - run: bash ./check_all.sh + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - run: nix build + - run: nix flake check --all-systems \ No newline at end of file diff --git a/.ocamlformat b/.ocamlformat new file mode 100644 index 00000000..b416ddab --- /dev/null +++ b/.ocamlformat @@ -0,0 +1,2 @@ + +profile=default \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 50d6e055..00000000 --- a/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -# Frontend to dune. - -.PHONY: default build install uninstall test clean web - -default: build - -build: - dune build - -test: - dune runtest -f - -install: - dune install - -uninstall: - dune uninstall - -clean: - dune clean - rm -f pages/catt.js - -web: - dune build - cp _build/default/web/web.bc.js pages/catt.js diff --git a/bin/catt.ml b/bin/catt.ml index 7b33e14d..94a845ae 100644 --- a/bin/catt.ml +++ b/bin/catt.ml @@ -14,22 +14,35 @@ let usage = "catt [options] [file]" let interactive = ref false let no_builtins = ref false let debug = ref false +let keep_going = ref false let () = Printexc.record_backtrace true; let file_in = ref [] in Stdlib.Arg.parse [ - "-i", Stdlib.Arg.Set interactive, "Interactive mode."; - "--no-builtins", Stdlib.Arg.Set no_builtins, "Prevent using built-in compositions and identities"; - "--debug", Stdlib.Arg.Set debug, "Debug mode: stop on error and drops a menu" + ("-i", Stdlib.Arg.Set interactive, "Interactive mode."); + ( "--no-builtins", + Stdlib.Arg.Set no_builtins, + "Prevent using built-in compositions and identities" ); + ( "--debug", + Stdlib.Arg.Set debug, + "Debug mode: stop on error and drops a menu" ); + ( "--keep-going", + Stdlib.Arg.Set keep_going, + "Do not exit on terms that don't typecheck." ); ] - (fun s -> file_in := s::!file_in) + (fun s -> file_in := s :: !file_in) usage; - let _ = match !file_in with - | [f] -> - Catt.Settings.use_builtins := not !no_builtins; - Catt.Settings.debug := !debug; - Catt.Command.exec ~loop_fn:Catt.Prover.loop (parse_file f) + let _ = + match !file_in with + | [ f ] -> ( + Catt.Settings.use_builtins := not !no_builtins; + Catt.Settings.keep_going := !keep_going; + Catt.Settings.debug := !debug; + match parse_file f with + | Ok cmds -> Catt.Command.exec ~loop_fn:Catt.Prover.loop cmds + | Error () -> exit 1) | _ -> () - in if !interactive then Catt.Prover.loop () + in + if !interactive then Catt.Prover.loop () diff --git a/bin/dune b/bin/dune index f717761c..8f381deb 100644 --- a/bin/dune +++ b/bin/dune @@ -1,8 +1,8 @@ (executable + (package catt) (public_name catt) (name catt) - (libraries - ; landmarks - catt) - ; (preprocess (pps landmarks-ppx --auto)) -) + (libraries catt)) + +(cram + (deps %{bin:catt})) diff --git a/catt-mode.el b/catt-mode.el deleted file mode 100644 index 3285b1db..00000000 --- a/catt-mode.el +++ /dev/null @@ -1,37 +0,0 @@ -;; catt-mode.el -- CATT major emacs mode - -(defvar catt-font-lock-keywords - '( - ("#.*" . 'font-lock-comment-face) - ("\\<\\(let\\|check\\|set\\|coh\\|fcoh\\|hyp\\|eval\\|env\\)\\>\\|:\\|=" . font-lock-keyword-face) - ("\\<\\(Hom\\|Type\\)\\>\\|->" . font-lock-builtin-face) - ;; ("\\<\\(\\)\\>" . font-lock-constant-face) - ("\\" st) - st) - "Syntax table for CATT major mode.") - -(defvar catt-tab-width 4) - -(define-derived-mode catt-mode prog-mode - "CATT" "Major mode for CATT files." - :syntax-table catt-mode-syntax-table - (set (make-local-variable 'comment-start) "#") - (set (make-local-variable 'comment-start-skip) "#+\\s-*") - (set (make-local-variable 'font-lock-defaults) '(catt-font-lock-keywords)) - (setq mode-name "CATT") - ) - -(provide 'catt-mode) - -;;;###autoload -(add-to-list 'auto-mode-alist '("\\.catt\\'" . catt-mode)) diff --git a/catt-web.opam b/catt-web.opam new file mode 100644 index 00000000..27cdcba9 --- /dev/null +++ b/catt-web.opam @@ -0,0 +1,30 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "Browser embedded version of the catt theorem prover" +description: "Browser embedded version of the catt theorem prover" +maintainer: ["Thibaut Benjamin" "Chiara Sarti"] +authors: ["Thibaut Benjamin" "Chiara Sarti"] +license: "MIT" +tags: ["higher-categories" "dependent-type-theory"] +homepage: "https://github.com/thibautbenjamin/catt" +bug-reports: "https://github.com/thibautbenjamin/catt/issues" +depends: [ + "ocaml" + "dune" {>= "3.16"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/thibautbenjamin/catt.git" diff --git a/check_all.sh b/check_all.sh deleted file mode 100755 index ca6bc91d..00000000 --- a/check_all.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -TESTS=( -"test/bug.catt" -"test/builtin-comp.catt" -"test/functorialisation.catt" -"test/functoriality.catt" -"test/implicit_subs.catt" -"test/inverses.catt" -"test/issue7.catt" -"test/naturality.catt" -"test/opposites.catt" -"test/pretty-print.catt" -"test/ps-syntax.catt" -"test/suspension.catt" -"test/test.catt" -"test/vanilla.catt" -"test/wildcards.catt" -) - -for file in ${TESTS[@]}; do - echo "Running: $file" - opam exec -- dune exec -- catt "$file" || exit 1 -done - diff --git a/default.nix b/default.nix deleted file mode 100644 index 90fefe10..00000000 --- a/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock); -in fetchTarball { - url = - lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; -}) { src = ./.; }).defaultNix diff --git a/dune-project b/dune-project index 9caabb4a..b605b2d2 100644 --- a/dune-project +++ b/dune-project @@ -1,19 +1,15 @@ -(lang dune 3.7) +(lang dune 3.16) (name catt) - (generate_opam_files true) - -(source - (github thibautbenjamin/catt)) - -(authors "Thibaut Benjamin") - -(maintainers "Thibaut Benjamin") - +(source (github thibautbenjamin/catt)) +(authors "Thibaut Benjamin" + "Chiara Sarti") +(maintainers "Thibaut Benjamin" + "Chiara Sarti") (license MIT) - (using menhir 2.0) +(cram enable) (package (name catt) @@ -21,4 +17,13 @@ (description "An infinity-categorical coherence typechecker") (depends ocaml dune) (tags - (higher-categories dependent-type-theory))) \ No newline at end of file + (higher-categories dependent-type-theory))) + +(package + (name catt-web) + (synopsis "Browser embedded version of the catt theorem prover") + (description "Browser embedded version of the catt theorem prover") + (depends ocaml dune) + (allow_empty) + (tags + (higher-categories dependent-type-theory))) diff --git a/examples/eckmann-hilton-dimensions/eh2d.catt b/examples/eckmann-hilton-dimensions/eh2d.catt new file mode 100644 index 00000000..84eadbf4 --- /dev/null +++ b/examples/eckmann-hilton-dimensions/eh2d.catt @@ -0,0 +1,19 @@ +coh unitl (x(f)y) : comp (id _) f -> f +coh unit (x) : comp (id x) (id x) -> id x +coh lsimp (x) : (unitl (id x)) -> unit x +coh Ilsimp (x) : I (unitl (id x)) -> I (unit x) +coh exch (x(f(a)g)y(h(b)k)z) : comp (comp _ [b]) (id (comp f k)) (comp [a] _) -> comp [a] [b] + +coh eh1 (x(f(a)g(b)h)y) : +comp a b -> comp (I (unitl f)) + (comp (comp _ [a]) (comp (unitl g) (I (op { 1 } (unitl g)))) (comp [b] _)) + (op { 1 } (unitl h)) + +let eh2 (x : *) (a : id x -> id x) (b : id x -> id x) = +comp [Ilsimp _] + [comp (comp _ [comp (comp [lsimp _] [op { 1 } (Ilsimp _)]) (U (unit _))] _) + (exch b a)] + [op { 1 } (lsimp _)] + +let eh (x : *) (a : id x -> id x) (b : id x -> id x) = +comp (eh1 a b) (eh2 a b) (I (op { 1 } (eh2 b a))) (I (op { 1 } (eh1 b a))) diff --git a/examples/eckmann-hilton-dimensions/eh3d.catt b/examples/eckmann-hilton-dimensions/eh3d.catt new file mode 100644 index 00000000..8a616396 --- /dev/null +++ b/examples/eckmann-hilton-dimensions/eh3d.catt @@ -0,0 +1,44 @@ +coh unitl (x(f)y) : comp (id _) f -> f +coh unit (x) : comp (id x) (id x) -> id x +coh lsimp (x) : (unitl (id x)) -> unit x +coh Ilsimp (x) : I (unitl (id x)) -> I (unit x) + +coh sandwisk (x(f)y(g(a)h)z(k)w) : comp f g k -> comp f h k + +let sandwich (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g) = comp (I (unitl f)) (comp [id (id x)] [a]) (unitl g) +coh uunitl (x(f(a)g)y) : a -> sandwich a + +coh step1 (x(f(a(m)b(n)c)g)y) : comp m n -> + comp (uunitl a) (comp (sandwich [m]) (comp (I (uunitl b)) (op { 1 } (uunitl b))) (op { 1 } (sandwich [n]))) (op { 1 } (I (uunitl c))) + +coh toaster (x) : comp (I (uunitl (id (id x)))) (op { 1 } (uunitl (id (id x)))) -> + comp + (comp [Ilsimp _] (comp [id (id x)] [id (id x)]) [lsimp _]) + (comp [I (op { 1 } (Ilsimp _))] (comp [id (id x)] [id (id x)]) [I (op { 1 } (lsimp _))]) + +coh unfocus (x(f)y(g)z(h)w(k)u) : comp f (comp g h) k -> comp (comp f g) (comp h k) + +let step21 (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = + comp (sandwich [m]) [toaster _] (op { 1 } (sandwich [n])) + +let step23 (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = + comp [sandwisk [Ilsimp x] (comp [id (id x)] [[m]]) [lsimp x]] + [I (sandwisk [I (op { 1 } (Ilsimp x))] (comp [[n]] [id (id x)]) [I (op { 1 } (lsimp x))])] + +coh sandswitch (x(f)y(g(a)h(b)k)z(l)w) : comp (sandwisk f a l) (sandwisk f b l) -> sandwisk f (comp a b) l + +let step24 (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = + sandswitch (I (unit x)) (comp [id (id x)] [[m]]) (comp [[n]] [id (id x)]) (unit x) + +coh intch20 (x(f(a(n)b)g)y(h(c(m)d)k)z) : comp (comp [a] [[m]]) (comp [[n]] [d]) -> comp [[n]] [[m]] + +let step25 (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = + sandwisk (I (unit x)) [intch20 n m] (unit x) + +let step2inner (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = + comp (step21 m n) (unfocus (sandwich [m]) _ _ _ ) (step23 m n) (I (unfocus (comp [Ilsimp x] _ [lsimp x]) _ _ _)) (comp _ [comp (step24 m n) (step25 m n)] _) + +let step2 (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = + comp (uunitl (id (id x))) [step2inner m n] (op { 1 } (I (uunitl (id (id x))))) + +let final (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = comp (step1 m n) (step2 m n) diff --git a/examples/eckmann-hilton-dimensions/eh4d.catt b/examples/eckmann-hilton-dimensions/eh4d.catt new file mode 100644 index 00000000..1438ffef --- /dev/null +++ b/examples/eckmann-hilton-dimensions/eh4d.catt @@ -0,0 +1,108 @@ +coh unitl (x(f)y) : comp (id _) f -> f +coh unit (x) : comp (id x) (id x) -> id x +coh lsimp (x) : (unitl (id x)) -> unit x +coh Ilsimp (x) : I (unitl (id x)) -> I (unit x) + +coh sandwisk (x(f)y(g(a)h)z(k)w) : comp f g k -> comp f h k + +let sandwich (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g) = comp (I (unitl f)) (comp [id (id x)] [a]) (unitl g) +coh uunitl (x(f(a)g)y) : a -> sandwich a + +let ssandwich (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g) (b : f -> g) (m : a -> b) = comp (uunitl a) (comp (I (unitl f)) [comp [[id (id (id x))]] [[m]]] (unitl g)) (I (uunitl b)) +coh uuunitl (x(f(a(m)b)g)y) : m -> ssandwich m + +coh step1 (x(f(a(m(p)n(q)o)b)g)y) : comp p q -> + comp (uuunitl m) (comp (ssandwich [p]) (comp (I (uuunitl n)) (op { 1 } (uuunitl n))) (op { 1 } (ssandwich [q]))) (op { 1 } (I (uuunitl o))) + +let usandwich (x : *) (a : id x -> id x) = comp (I (unit _)) (comp [id (id x)] [a]) (unit _) +coh uunit (x : *) : id (id x) -> usandwich (id (id x)) +let ussandwich (x : *) (m : id (id x) -> id (id x)) = comp (uunit _) (comp (I (unit _)) [comp [[id (id (id x))]] [[m]]] (unit _)) (I (uunit _)) + +coh assoc (x(f)y(g)z(h)w(k)v) : comp f (comp g h) k -> comp (comp f g) h k +coh assoc2 (x(f)y(g)z(h)w(k)v) : comp f g (comp h k) -> comp f (comp g h) k +coh sandsimp (x) : comp (uunitl _) (comp [(Ilsimp x)] (comp [(id (id x))] [(id (id x))]) [(lsimp x)]) -> uunit x +coh Isandsimpl (x) : comp (comp [(Ilsimp x)] (comp [(id (id x))] [(id (id x))]) [(lsimp x)]) (I (uunit _)) -> I (uunitl (id (id x))) + +let test (x : *) = +comp (comp (uunitl _) (comp (I (unitl (id x))) [comp [[id (id (id x))]] [[id (id (id x))]]] (unitl (id x))) [I (Isandsimpl x)]) + (assoc2 (uunitl _) (comp (I (unitl (id x))) [comp [[id (id (id x))]] [[id (id (id x))]]] (unitl (id x))) _ _) + (comp (uunitl _) [sandwisk [Ilsimp x] (comp [[id (id (id x))]] [[id (id (id x))]]) [lsimp x]] (I (uunit _))) + (assoc (uunitl _) (comp [(Ilsimp x)] (comp [(id (id x))] [(id (id x))]) [(lsimp x)]) _ _) + (comp [sandsimp x] _ _) + +coh toaster (x) : comp (I (uuunitl (id (id (id x))))) (op { 1 } (uuunitl (id (id (id x))))) -> + comp + (test x) + (I (op { 1 } (test x))) + +# coh unfocus (x(f)y(g)z(h)w(k)u) : comp f (comp g h) k -> comp (comp f g) (comp h k) + +# let step21 (x : *) (p : id (id (id x)) -> id (id (id x))) (q : id (id (id x)) -> id (id (id x))) = +# comp (ssandwich [p]) [toaster x] (op { 1 } (ssandwich [q])) + +# let aaa (x : *) (p : id (id (id x)) -> id (id (id x))) (q : id (id (id x)) -> id (id (id x))) = +# comp (step21 p q) (unfocus (ssandwich [p]) _ _ (op { 1 } (ssandwich [q]))) + +let step31 (x : *) (p : id (id (id x)) -> id (id (id x))) = + sandwisk (uunitl (id (id x))) (comp (I (unitl (id x))) [[comp [[id (id (id x))]] [[[p]]]]] (unitl (id x))) [I (Isandsimpl x)] + +let step32 (x : *) (p : id (id (id x)) -> id (id (id x))) = + assoc2 (uunitl _) [comp (I (unitl (id x))) [[comp [[id (id (id x))]] [[[p]]]]] (unitl (id x))] (comp [(Ilsimp x)] (comp [(id (id x))] [(id (id x))]) [(lsimp x)]) (I (uunit _)) + +let sandwisknat (x : *) (y : *) (z : *) (w : *) (f : x -> y) (f' : x -> y) (a : f -> f') (g : y -> z) (g' : y -> z) (b : g -> g') (h : z -> w) (h' : z -> w) (c : h -> h') = sandwisk [a] b [c] +let step33 (x : *) (p : id (id (id x)) -> id (id (id x))) = +comp (uunitl _) [[sandwisknat (Ilsimp x) [comp [[id (id (id x))]] [[[p]]]] (lsimp x)]] (I (uunit _)) + +let step34 (x : *) (p : id (id (id x)) -> id (id (id x))) = + assoc (uunitl _) (comp [(Ilsimp x)] (comp [(id (id x))] [(id (id x))]) [(lsimp x)]) [comp (I (unit x)) [[comp [[id (id (id x))]] [[[p]]]]] (unit x)] (I (uunit _)) + +let step35 (x : *) (p : id (id (id x)) -> id (id (id x))) = + sandwisk [sandsimp x] (comp (I (unit x)) [[comp [[id (id (id x))]] [[[p]]]]] (unit x)) (I (uunit _)) + +coh assoc31 (x(f)y(g)z(h)w(i)a(j)b(k)c) : comp f (comp g h i j k) -> comp (comp f g) h i j k +coh assoc32 (x(f)y(g)z(h)w(i)a(j)b(k)c) : comp (comp f g) h i j k -> comp f (comp g h) i j k +coh assoc33 (x(f)y(g)z(h)w(i)a(j)b(k)c) : comp f (comp g h) i j k -> comp f g (comp h i) j k +coh assoc34 (x(f)y(g)z(h)w(i)a(j)b(k)c) : comp f g (comp h i) j k -> comp f g h (comp i j) k +coh assoc35 (x(f)y(g)z(h)w(i)a(j)b(k)c) : comp f g h (comp i j) k -> comp f g h i (comp j k) +coh assoc35 (x(f)y(g)z(h)w(i)a(j)b(k)c) : comp f g h i (comp j k) -> comp (comp f g h i j) k +let step3a (x : *) (p : id (id (id x)) -> id (id (id x))) = + comp (assoc31 _ _ _ _ _ (comp [sandsimp x] _ _)) + (comp [step31 p] _ (comp (uunitl _) [sandwisk [Ilsimp x] (comp [[id (id (id x))]] [[id (id (id x))]]) [lsimp x]] (I (uunit _))) (assoc (uunitl _) (comp [(Ilsimp x)] (comp [(id (id x))] [(id (id x))]) [(lsimp x)]) _ _) _) + (assoc32 _ _ _ _ _ (comp [sandsimp x] _ _)) + (comp _ [I (step32 p)] _ _ _) + (assoc33 _ _ _ _ _ (comp [sandsimp x] _ _)) + # (comp _ _ [step33 p] _ _) + # (assoc34 _ _ _ _ _ (comp [sandsimp x] _ _)) + # (comp _ _ _ [I (step34 p)] _) + # (assoc35 _ _ _ _ _ (comp [sandsimp x] _ _)) + # (comp _ _ _ _ [step35 p]) + # (assoc36 ((comp (uunitl _) (comp (I (unitl (id x))) [comp [[id (id (id x))]] [[id (id (id x))]]] (unitl (id x))) [I (Isandsimpl x)])) _ _ _ _ _) + + +# let step3a (x : *) (p : id (id (id x)) -> id (id (id x))) = +# @comp [_] [_] [step35 p] [_] [step34 p] [_] [step33 p] [_] [step32 p] [_] [step31 p] + + +# let step23 (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = +# comp [sandwisk [Ilsimp x] (comp [id (id x)] [[m]]) [lsimp x]] +# [I (sandwisk [I (op { 1 } (Ilsimp x))] (comp [[n]] [id (id x)]) [I (op { 1 } (lsimp x))])] + +# let usandwich_eliminator (x : *) = comp [Ilsimp x] (comp [id (id x)] [id (id x)]) [lsimp x] + +# coh sandswitch (x(f(a)g(b(m)c(n)d)h(e)k)y) : comp (sandwisk a m e) (sandwisk a n e) -> sandwisk a (comp m n) e + +# let step24 (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = +# sandswitch (I (unit x)) (comp [id (id x)] [[m]]) (comp [[n]] [id (id x)]) (unit x) + +# coh intch20 (x(f(a(n)b)g)y(h(c(m)d)k)z) : comp (comp [a] [[m]]) (comp [[n]] [d]) -> comp [[n]] [[m]] + +# let step25 (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = +# sandwisk (I (unit x)) [intch20 n m] (unit x) + +# let step2inner (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = +# comp (step21 m n) (unfocus (sandwich [m]) _ _ _ ) (step23 m n) (I (unfocus (comp [Ilsimp x] _ [lsimp x]) _ _ _)) (comp _ [comp (step24 m n) (step25 m n)] _) + +# let step2 (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = +# comp (uunitl (id (id x))) [step2inner m n] (op { 1 } (I (uunitl (id (id x))))) + +# let final (x : *) (m : id (id x) -> id (id x)) (n : id (id x) -> id (id x)) = comp (step1 m n) (step2 m n) diff --git a/flake.lock b/flake.lock index eff265d6..d5f0ffab 100644 --- a/flake.lock +++ b/flake.lock @@ -1,29 +1,15 @@ { "nodes": { - "flake-compat": { - "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", - "revCount": 57, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" - }, - "original": { - "type": "tarball", - "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" - } - }, "flake-utils": { "inputs": { "systems": "systems" }, "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { @@ -32,13 +18,28 @@ "type": "github" } }, + "nix-filter": { + "locked": { + "lastModified": 1710156097, + "narHash": "sha256-1Wvk8UP7PXdf8bCCaEoMnOT1qe5/Duqgj+rL8sRQsSM=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "3342559a24e85fc164b295c3444e8a139924675b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1705496572, - "narHash": "sha256-rPIe9G5EBLXdBdn9ilGc0nq082lzQd0xGGe092R/5QE=", + "lastModified": 1726463316, + "narHash": "sha256-gI9kkaH0ZjakJOKrdjaI/VbaMEo9qBbSUl93DnU7f4c=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "842d9d80cfd4560648c785f8a4e6f3b096790e19", + "rev": "99dc8785f6a0adac95f5e2ab05cc2e1bf666d172", "type": "github" }, "original": { @@ -50,8 +51,8 @@ }, "root": { "inputs": { - "flake-compat": "flake-compat", "flake-utils": "flake-utils", + "nix-filter": "nix-filter", "nixpkgs": "nixpkgs" } }, diff --git a/flake.nix b/flake.nix index e6ea2b7e..919c03e4 100644 --- a/flake.nix +++ b/flake.nix @@ -4,56 +4,178 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; - flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; + nix-filter.url = "github:numtide/nix-filter"; }; - outputs = inputs@{ self, nixpkgs, flake-utils, ... }: + outputs = { self, nixpkgs, flake-utils, nix-filter, ... }: flake-utils.lib.eachDefaultSystem (system: - let pkgs = (import nixpkgs { inherit system; }); + let + pkgs = (import nixpkgs { inherit system; }); + ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_14; + sources = { + ocaml = nix-filter.lib { + root = ./.; + include = [ + ".ocamlformat" + "dune-project" + (nix-filter.lib.inDirectory "bin") + (nix-filter.lib.inDirectory "lib") + (nix-filter.lib.inDirectory "test.t") + ]; + }; + + web = nix-filter.lib { + root = ./.; + include = [ + ".ocamlformat" + "dune-project" + (nix-filter.lib.inDirectory "web") + ]; + }; + + nix = nix-filter.lib { + root = ./.; + include = [ (nix-filter.lib.matchExt "nix") ]; + }; + + elisp = ./share/site-lisp; + }; + in { - # Exports a package that can be built with - # nix built. The build environment can be accessed - # via nix develop. - packages = rec { + packages = { default = self.packages.${system}.catt; - catt = pkgs.callPackage - ({ stdenv, dune_3, ocaml, opam, ocamlPackages, ... }: - stdenv.mkDerivation { - pname = "catt"; - version = "0.2.0"; - src = ./.; - buildInputs = [ dune_3 ocaml opam ] ++ (with ocamlPackages; [ - fmt - js_of_ocaml - js_of_ocaml-ppx - menhir - sedlex - ]); - buildPhase = '' - rm -rf result - dune build - ''; - installPhase = '' - mkdir -p $out/bin - install -Dm755 _build/default/bin/catt.exe $out/bin - mkdir -p $out/web - #install -Dm644 _build/default/web/index.html $out/web - #install -Dm644 _build/default/web/*.js $out/web - ''; - }) { }; - - catt-dev = catt.overrideAttrs (old: { - buildInputs = - catt.buildInputs ++ - (with pkgs.ocamlPackages; [ - ocamlformat - ocaml-lsp - ocp-indent - ]); - }); + catt = ocamlPackages.buildDunePackage { + pname = "catt"; + version = "1.0"; + minimalOcamlVersion = "4.08"; + doCheck = false; + + src = sources.ocaml; + + nativeBuildInputs = with ocamlPackages; [ menhir ]; + + buildInputs = with ocamlPackages; [ fmt sedlex ]; + + propagatedBuildInputs = with ocamlPackages; [ base ]; + + meta = { + description = "A proof assistant for weak omega-categories"; + homepage = "https://www.github.com/thibautbenjamin/catt"; + license = nixpkgs.lib.licenses.mit; + maintainers = [ "Thibaut Benjamin" "Chiara Sarti" ]; + mainProgram = "catt"; + }; + }; + + catt-web = ocamlPackages.buildDunePackage { + pname = "catt-web"; + version = "1.0"; + minimalOcamlVersion = "4.08"; + doCheck = false; + + src = sources.web; + + nativeBuildInputs = with ocamlPackages; [ js_of_ocaml ]; + + buildInputs = with ocamlPackages; [ + js_of_ocaml + self.outputs.packages.${system}.catt + js_of_ocaml-ppx + fmt + sedlex + ]; + + meta = { + description = + "Browser embedded version of the catt proof-assistant"; + homepage = "https://www.github.com/thibautbenjamin/catt"; + license = nixpkgs.lib.licenses.mit; + maintainers = [ "Thibaut Benjamin" "Chiara Sarti" ]; + }; + }; + + catt-mode = pkgs.emacs.pkgs.trivialBuild rec { + pname = "catt-mode"; + version = "1.0"; + src = sources.elisp; + + meta = { + description = "An emacs mode for the catt proof-assistant"; + homepage = "https://www.github.com/thibautbenjamin/catt"; + license = pkgs.lib.licenses.mit; + maintainers = [ "Thibaut Benjamin" ]; + }; + }; + }; + + formatter = pkgs.nixfmt-classic; + + checks = { + lint-nix = pkgs.runCommand "check-flake-format" { + nativeBuildInputs = [ pkgs.nixfmt-classic ]; + } '' + echo "checking nix formatting" + nixfmt --check ${sources.nix} + touch $out + ''; + + dune-fmt = pkgs.runCommand "check-ocaml-fmt" { + nativeBuildInputs = [ + ocamlPackages.dune_3 + ocamlPackages.ocaml + ocamlPackages.ocamlformat + ]; + } '' + echo "checking dune and ocaml formatting for catt" + dune build \ + --display=short \ + --no-print-directory \ + --root="${sources.ocaml}" \ + --build-dir="$(pwd)/_build" \ + @fmt + touch $out + ''; + + web-fmt = pkgs.runCommand "check-ocaml-fmt" { + nativeBuildInputs = [ + ocamlPackages.dune_3 + ocamlPackages.ocaml + ocamlPackages.ocamlformat + ]; + } '' + echo "checking dune and ocaml formatting for catt-web" + dune build \ + --display=short \ + --no-print-directory \ + --root="${sources.web}" \ + --build-dir="$(pwd)/_build" \ + @fmt + touch $out + ''; + + default = self.packages.${system}.catt.overrideAttrs (oldAttrs: { + name = "check-${oldAttrs.name}"; + dontInstall = true; + doCheck = true; + }); + }; + + devShells.default = pkgs.mkShell { + packages = (with pkgs; [ nixfmt-classic fswatch ]) + ++ (with ocamlPackages; [ + odoc + ocaml-lsp + ocamlformat + ocp-indent + ocamlformat-rpc-lib + utop + ]); + + inputsFrom = + [ self.packages.${system}.catt self.packages.${system}.catt-web ]; }; - devShells.default = self.packages.${system}.catt-dev; + devShells.web = self.packages.${system}.catt-web; }); } diff --git a/lib/builtin.ml b/lib/builtin.ml index 79275d6c..70682399 100644 --- a/lib/builtin.ml +++ b/lib/builtin.ml @@ -1,42 +1,38 @@ open Common open Kernel -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) module Memo = struct let tbl = Hashtbl.create 97 let find i f = - try Hashtbl.find tbl i with - | Not_found -> + try Hashtbl.find tbl i + with Not_found -> let res = f i in Hashtbl.add tbl i res; res let id = - check_coh (Br[]) (Arr(Obj,Var(Db 0),Var(Db 0))) ("builtin_id", 0, []) + check_coh (Br []) (Arr (Obj, Var (Db 0), Var (Db 0))) ("builtin_id", 0, []) end let rec ps_comp i = match i with | i when i <= 0 -> Error.fatal "builtin composition with less than 0 argument" - | i when i = 1 -> Br [Br[]] - | i -> - match ps_comp (i-1) with - | Br l -> Br (Br[] :: l) + | i when i = 1 -> Br [ Br [] ] + | i -> ( match ps_comp (i - 1) with Br l -> Br (Br [] :: l)) let comp_n arity = let build_comp i = let ps = ps_comp i in - let pp_data = (Printf.sprintf "builtin_comp%i" arity), 0, [] in - Coh.check_noninv ps (Var (Db 0)) (Var(Db 0)) pp_data + let pp_data = (Printf.sprintf "builtin_comp%i" arity, 0, []) in + Coh.check_noninv ps (Var (Db 0)) (Var (Db 0)) pp_data in Memo.find arity build_comp let arity_comp s expl = let n = List.length s in - if expl || !Settings.explicit_substitutions then - (n-1)/2 - else n + if expl || !Settings.explicit_substitutions then (n - 1) / 2 else n let comp s expl = let arity = arity_comp s expl in @@ -49,30 +45,31 @@ let id_all_max ps = let rec id_map l = let t = Var (Db 0) in match l with - | [] -> [t, false] - | Br[]::l -> (Coh(id, [t,true]), true)::(t,false)::(id_map l) + | [] -> [ (t, false) ] + | Br [] :: l -> (Coh (id, [ (t, true) ]), true) :: (t, false) :: id_map l | _ -> Error.fatal "identity must be inserted on maximal argument" in let rec aux i ps = - match i,ps with - | _, Br [] -> [Var (Db 0), true] + match (i, ps) with + | _, Br [] -> [ (Var (Db 0), true) ] | 0, Br l -> id_map l - | i, Br l -> Unchecked.suspwedge_subs_ps - (List.map (aux (i-1)) l) - (List.map (Unchecked.ps_bdry) l) + | i, Br l -> + Unchecked.suspwedge_subs_ps + (List.map (aux (i - 1)) l) + (List.map Unchecked.ps_bdry l) in - aux (d-1) ps + aux (d - 1) ps let unbiased_unitor ps t = - let bdry = Unchecked.ps_bdry ps in + let bdry = Unchecked.ps_bdry ps in let src = - let coh = Coh.check_noninv ps t t ("endo",0,[]) in - Coh(coh, id_all_max ps) + let coh = Coh.check_noninv ps t t ("endo", 0, []) in + Coh (coh, id_all_max ps) in - let - a = Ty.forget (Tm.typ (check_term (Ctx.check (Unchecked.ps_to_ctx bdry)) t)) + let a = + Ty.forget (Tm.typ (check_term (Ctx.check (Unchecked.ps_to_ctx bdry)) t)) in let da = Unchecked.dim_ty a in let sub_base = Unchecked.ty_to_sub_ps a in - let tgt = Coh (Suspension.coh (Some da) id, (t,true)::sub_base) in - Coh.check_inv bdry src tgt ("unbiased_unitor",0,[]) + let tgt = Coh (Suspension.coh (Some da) id, (t, true) :: sub_base) in + Coh.check_inv bdry src tgt ("unbiased_unitor", 0, []) diff --git a/lib/command.ml b/lib/command.ml index 9a90c268..103fb2c1 100644 --- a/lib/command.ml +++ b/lib/command.ml @@ -1,7 +1,7 @@ open Common open Kernel open Raw_types -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) exception UnknownOption of string exception NotAnInt of string @@ -10,39 +10,40 @@ exception NotABoolean of string (**toplevel commands. *) type cmd = | Coh of Var.t * (Var.t * tyR) list * tyR - | Check of ((Var.t * tyR) list) * tmR * tyR option + | Check of (Var.t * tyR) list * tmR * tyR option | Decl of Var.t * (Var.t * tyR) list * tmR * tyR option | Set of string * string type prog = cmd list -let postprocess_fn : (ctx -> tm -> ctx * tm) ref = - ref (fun c e -> c,e) +let postprocess_fn : (ctx -> tm -> ctx * tm) ref = ref (fun c e -> (c, e)) let exec_coh v ps ty = - let ps,ty = Elaborate.ty_in_ps ps ty in + let ps, ty = Elaborate.ty_in_ps ps ty in Environment.add_coh v ps ty let exec_decl v l e t = - let c,e = Elaborate.tm l e in - let c,e = if !Settings.postprocess then !postprocess_fn c e else c,e in + let c, e = Elaborate.tm l e in + let c, e = if !Settings.postprocess then !postprocess_fn c e else (c, e) in match t with | None -> Environment.add_let v c e | Some ty -> - let _,ty = Elaborate.ty l ty in - Environment.add_let v c ~ty e + let _, ty = Elaborate.ty l ty in + Environment.add_let v c ~ty e let check l e t = - let c,e = Elaborate.tm l e in + let c, e = Elaborate.tm l e in let ty = match t with | None -> None - | Some ty -> let _,ty = Elaborate.ty l ty in Some ty + | Some ty -> + let _, ty = Elaborate.ty l ty in + Some ty in let c = Kernel.Ctx.check c in let tm = Kernel.check_term c ?ty e in let ty = Kernel.(Ty.forget (Tm.typ tm)) in - e,ty + (e, ty) let exec_set o v = let parse_bool v = @@ -56,86 +57,100 @@ let exec_set o v = | _ -> raise (NotABoolean v) in let parse_int v = - match int_of_string_opt v with - | Some s -> s - | None -> raise (NotAnInt v) + match int_of_string_opt v with Some s -> s | None -> raise (NotAnInt v) in match o with | _ when String.equal o "explicit_substitutions" -> - let v = parse_bool v in - Settings.explicit_substitutions := v + let v = parse_bool v in + Settings.explicit_substitutions := v | _ when String.equal o "print_explicit_substitutions" -> - let v = parse_bool v in - Settings.print_explicit_substitutions := v + let v = parse_bool v in + Settings.print_explicit_substitutions := v | _ when String.equal o "postprocess" -> - let v = parse_bool v in - Settings.postprocess := v + let v = parse_bool v in + Settings.postprocess := v | _ when String.equal o "unroll_coherences" -> - let v = parse_bool v in - Settings.unroll_coherences := v + let v = parse_bool v in + Settings.unroll_coherences := v | _ when String.equal o "implicit_suspension" -> - let v = parse_bool v in - Settings.implicit_suspension := v + let v = parse_bool v in + Settings.implicit_suspension := v | _ when String.equal o "verbosity" -> - let v = parse_int v in - Settings.verbosity := v + let v = parse_int v in + Settings.verbosity := v | _ -> raise (UnknownOption o) let exec_cmd cmd = match cmd with - | Coh (x,ps,e) -> - Io.command "coh %s = %s" (Var.to_string x) (Raw.string_of_ty e); - let coh = exec_coh x ps e in - Io.info (lazy (Printf.sprintf "successfully defined %s" (Coh.to_string coh))) + | Coh (x, ps, e) -> + Io.command "coh %s = %s" (Var.to_string x) (Raw.string_of_ty e); + let coh = exec_coh x ps e in + Io.info + (lazy (Printf.sprintf "successfully defined %s" (Coh.to_string coh))) | Check (l, e, t) -> - Io.command "check %s" (Raw.string_of_tm e); - let e,ty = check l e t in - Io.info (lazy (Printf.sprintf "valid term %s of type %s" (Unchecked.tm_to_string e) (Unchecked.ty_to_string ty))); - | Decl (v,l,e,t) -> - Io.command "let %s = %s" (Var.to_string v) (Raw.string_of_tm e); - let tm,ty = exec_decl v l e t in - Io.info (lazy (Printf.sprintf "successfully defined term %s of type %s" (Unchecked.tm_to_string tm) (Unchecked.ty_to_string ty))) - | Set (o,v) -> - begin + Io.command "check %s" (Raw.string_of_tm e); + let e, ty = check l e t in + Io.info + (lazy + (Printf.sprintf "valid term %s of type %s" (Unchecked.tm_to_string e) + (Unchecked.ty_to_string ty))) + | Decl (v, l, e, t) -> + Io.command "let %s = %s" (Var.to_string v) (Raw.string_of_tm e); + let tm, ty = exec_decl v l e t in + Io.info + (lazy + (Printf.sprintf "successfully defined term %s of type %s" + (Unchecked.tm_to_string tm) + (Unchecked.ty_to_string ty))) + | Set (o, v) -> ( try exec_set o v with | UnknownOption o -> Error.unknown_option o | NotAnInt v -> Error.wrong_option_argument ~expected:"int" o v - | NotABoolean v -> Error.wrong_option_argument ~expected:"boolean" o v - end + | NotABoolean v -> Error.wrong_option_argument ~expected:"boolean" o v) -type next = - | Abort - | KeepGoing - | Interactive +type next = Abort | KeepGoing | Interactive let show_menu () = - Io.eprintf "Chose an option: \n\t [x/SPC]: ignore and keep going; \n\t [i]: drop in interactive mode; \n\t [q/RET]: quit\n%!"; + Io.eprintf + "Chose an option: \n\ + \t [x/SPC]: ignore and keep going; \n\ + \t [i]: drop in interactive mode; \n\ + \t [q/RET]: quit\n\ + %!"; let rec decision () = - let c = read_line() in + let c = read_line () in if c = "x" || c = " " then KeepGoing else if c = "q" || c = "" then Abort else if c = "i" then Interactive - else - (Io.printf "Please chose a valid option"; - decision ()) - in decision () + else ( + Io.printf "Please chose a valid option"; + decision ()) + in + decision () -let initialise () = Cubical_composite.init() +let initialise () = Cubical_composite.init () let exec ~loop_fn prog = initialise (); let rec aux = function | [] -> () - | (t::l) -> - let next = try exec_cmd t; KeepGoing - with - | Error.InvalidEntry -> - if !Settings.debug then show_menu() else (Io.printf "Aborting..."; Abort) - | Error.OptionsError -> KeepGoing - in - match next with - | KeepGoing -> aux l - | Abort -> exit 1 - | Interactive -> loop_fn() + | t :: l -> ( + let next = + try + exec_cmd t; + KeepGoing + with + | Error.InvalidEntry -> + if !Settings.keep_going then KeepGoing + else if !Settings.debug then show_menu () + else ( + Io.printf "Aborting..."; + Abort) + | Error.OptionsError -> KeepGoing + in + match next with + | KeepGoing -> aux l + | Abort -> exit 1 + | Interactive -> loop_fn ()) in aux prog diff --git a/lib/command.mli b/lib/command.mli index 4ae8718a..78a2aa7b 100644 --- a/lib/command.mli +++ b/lib/command.mli @@ -5,12 +5,11 @@ open Unchecked_types.Unchecked_types(Coh) type cmd = | Coh of Var.t * (Var.t * tyR) list * tyR - | Check of ((Var.t * tyR) list) * tmR * tyR option + | Check of (Var.t * tyR) list * tmR * tyR option | Decl of Var.t * (Var.t * tyR) list * tmR * tyR option | Set of string * string type prog = cmd list val postprocess_fn : (ctx -> tm -> ctx * tm) ref - val exec : loop_fn:(unit -> unit) -> prog -> unit diff --git a/lib/common.ml b/lib/common.ml index e644cf8f..f716ba7d 100644 --- a/lib/common.ml +++ b/lib/common.ml @@ -1,6 +1,7 @@ exception NotEqual of string * string exception DoubledVar of string exception WrongNumberOfArguments +exception NotInImage type ps = Br of ps list @@ -17,36 +18,35 @@ module Var = struct | Name s -> s | New i -> "_" ^ string_of_int i | Db i -> "." ^ string_of_int i - | Plus v -> (to_string v) ^ "+" - | Bridge v -> (to_string v) ^ "~" + | Plus v -> to_string v ^ "+" + | Bridge v -> to_string v ^ "~" let make_var s = Name s let rec check_equal v1 v2 = - match v1, v2 with + match (v1, v2) with | Name s1, Name s2 -> - if not (String.equal s1 s2) then raise (NotEqual(s1,s2)) else () + if not (String.equal s1 s2) then raise (NotEqual (s1, s2)) else () | New i, New j -> - if i != j then raise (NotEqual(to_string v1, to_string v2)) else () + if i != j then raise (NotEqual (to_string v1, to_string v2)) else () | Db i, Db j -> - if i != j then raise (NotEqual(to_string v1, to_string v2)) else () + if i != j then raise (NotEqual (to_string v1, to_string v2)) else () | Plus v1, Plus v2 | Bridge v1, Bridge v2 -> check_equal v1 v2 - | _, _ -> raise (NotEqual(to_string v1, to_string v2)) + | _, _ -> raise (NotEqual (to_string v1, to_string v2)) let rec suspend_n v n = match v with - | Db i -> Db (i+2*n) + | Db i -> Db (i + (2 * n)) | Plus v -> Plus (suspend_n v n) | Bridge v -> Bridge (suspend_n v n) - | Name _ | New _ as v -> v + | (Name _ | New _) as v -> v let suspend v = suspend_n v 1 - let next_fresh = ref 0 let fresh () = - let fresh = New (!next_fresh) in - incr(next_fresh); + let fresh = New !next_fresh in + incr next_fresh; fresh end diff --git a/lib/common.mli b/lib/common.mli index dd1e1f04..58d4c224 100644 --- a/lib/common.mli +++ b/lib/common.mli @@ -1,6 +1,7 @@ exception NotEqual of string * string exception DoubledVar of string exception WrongNumberOfArguments +exception NotInImage type ps = Br of ps list diff --git a/lib/cubical_composite.ml b/lib/cubical_composite.ml index 54cb0248..d372dea0 100644 --- a/lib/cubical_composite.ml +++ b/lib/cubical_composite.ml @@ -1,7 +1,6 @@ open Common open Kernel -open Unchecked_types.Unchecked_types(Coh) - +open Unchecked_types.Unchecked_types (Coh) module F = Functorialisation module LinearComp = struct @@ -9,8 +8,8 @@ module LinearComp = struct let tbl = Hashtbl.create 24 let find arity list f = - try Hashtbl.find tbl (arity,list) with - | Not_found -> + try Hashtbl.find tbl (arity, list) + with Not_found -> let res = f arity list in Hashtbl.add tbl (arity, list) res; res @@ -19,11 +18,13 @@ module LinearComp = struct let arity ps = let d = Unchecked.dim_ps ps in let rec aux ps i = - match i,ps with + match (i, ps) with | 0, Br l -> List.length l - | i, Br [ps] -> aux ps (i-1) - | _, _ -> Error.fatal "cubical composite must be on suspended linear composite"; - in aux ps (d-1) + | i, Br [ ps ] -> aux ps (i - 1) + | _, _ -> + Error.fatal "cubical composite must be on suspended linear composite" + in + aux ps (d - 1) let tdb i = Var (Db i) let tpl i = Var (Plus (Db i)) @@ -31,171 +32,180 @@ module LinearComp = struct let bcomp x y f z g = let comp = Builtin.comp_n 2 in - let sub = [g, true; z, false; f, true; y, false; x, false] in - Coh(comp, sub) - - let idx_src i = - if i = 2 then 0 else i-3 + let sub = [ (g, true); (z, false); (f, true); (y, false); (x, false) ] in + Coh (comp, sub) + let idx_src i = if i = 2 then 0 else i - 3 let plus i l = if List.mem (Var.Db i) l then tpl i else tdb i let src_i_f i active = - if active - then bcomp (tdb (idx_src i)) (tdb (i-1)) (tdb i) (tpl (i-1)) (tbr (i-1)) + if active then + bcomp (tdb (idx_src i)) (tdb (i - 1)) (tdb i) (tpl (i - 1)) (tbr (i - 1)) else tdb i let tgt_i_f i active l = - if active - then + if active then let isrc = idx_src i in - bcomp (tdb isrc) (tpl isrc) (tbr isrc) (plus (i-1) l) (tpl i) + bcomp (tdb isrc) (tpl isrc) (tbr isrc) (plus (i - 1) l) (tpl i) else Var (Plus (Db i)) let comp_biased_start arity = let lin_incl = let rec sub k = match k with - | 0 -> [tdb 1, false] - | k -> (tdb (k+2), k mod 2 == 0)::(sub(k-1)) - in sub (2*arity) + | 0 -> [ (tdb 1, false) ] + | k -> (tdb (k + 2), k mod 2 == 0) :: sub (k - 1) + in + sub (2 * arity) in - let lin_comp = Coh(Builtin.comp_n arity, lin_incl) in - bcomp (tdb 0) (tdb 1) (tdb 2) (tdb (2*arity + 1)) lin_comp + let lin_comp = Coh (Builtin.comp_n arity, lin_incl) in + bcomp (tdb 0) (tdb 1) (tdb 2) (tdb ((2 * arity) + 1)) lin_comp let comp_biased_end arity = let lin_incl = Unchecked.identity_ps (Builtin.ps_comp arity) in - let lin_comp = Coh(Builtin.comp_n arity, lin_incl) in - bcomp (tdb 0) (tdb (2*arity-1)) lin_comp (tdb (2*arity+1)) (tdb (2*arity+2)) + let lin_comp = Coh (Builtin.comp_n arity, lin_incl) in + bcomp (tdb 0) + (tdb ((2 * arity) - 1)) + lin_comp + (tdb ((2 * arity) + 1)) + (tdb ((2 * arity) + 2)) let comp_biased_middle arity pos = let comp = Builtin.comp_n arity in let rec sub k = match k with - | _ when k = 0 -> [tdb 0, false] - | _ when k < pos -> (tdb k, true)::(tdb (k-1), false)::(sub (k-2)) - | _ when k = pos+1 -> - let bcomp = - bcomp (tdb (idx_src k)) (tdb (k-1)) (tdb k) (tdb (k+1)) (tdb (k+2)) - in - (bcomp, true)::(tdb (k+1), false)::sub(k-2) - | _ when k > pos+1 -> - (tdb (k+2), true)::(tdb (k+1), false)::(sub (k-2)) - |_ -> assert false + | _ when k = 0 -> [ (tdb 0, false) ] + | _ when k < pos -> (tdb k, true) :: (tdb (k - 1), false) :: sub (k - 2) + | _ when k = pos + 1 -> + let bcomp = + bcomp + (tdb (idx_src k)) + (tdb (k - 1)) + (tdb k) + (tdb (k + 1)) + (tdb (k + 2)) + in + (bcomp, true) :: (tdb (k + 1), false) :: sub (k - 2) + | _ when k > pos + 1 -> + (tdb (k + 2), true) :: (tdb (k + 1), false) :: sub (k - 2) + | _ -> assert false in - Coh (comp, sub (2*arity)) + Coh (comp, sub (2 * arity)) let comp_biased arity pos = match pos with | _ when pos = 0 -> comp_biased_start arity - | _ when pos = 2 * arity + 1 -> comp_biased_end arity + | _ when pos = (2 * arity) + 1 -> comp_biased_end arity | _ -> comp_biased_middle arity pos let sub_whisk_i i arity l src tgt = let rec sub k = match k with - | k when k = 0 -> [tdb 0, false] - | k when k < i -> (tdb k, true)::(tdb (k-1), false)::(sub (k-2)) + | k when k = 0 -> [ (tdb 0, false) ] + | k when k < i -> (tdb k, true) :: (tdb (k - 1), false) :: sub (k - 2) | k when k = i -> - List.append - [tbr i, true; tgt, false; src, false; plus (i-1) l, false] - (sub (i-2)) - | k when k > i -> (plus k l, true)::(plus (k-1) l, false)::(sub (k-2)) + List.append + [ + (tbr i, true); (tgt, false); (src, false); (plus (i - 1) l, false); + ] + (sub (i - 2)) + | k when k > i -> + (plus k l, true) :: (plus (k - 1) l, false) :: sub (k - 2) | _ -> assert false - in sub (2*arity) + in + sub (2 * arity) let sub_assc_i i arity l = let rec sub k = match k with - | k when k = 0 && i = 0 -> [tbr 0, true ;tpl 0, false ;tdb 0, false] - | k when k = 0 -> [tdb 0, false] - | k when k < i+1 -> (tdb k, true)::(tdb (k-1), false)::(sub (k-2)) - | k when k = i+1 -> - List.append - [tbr i, true; tpl i, false ;tdb k, true; tdb i, false] - (sub (k-2)) - | k when k > i+1 -> (plus k l, true)::(plus (k-1) l, false)::(sub (k-2)) + | k when k = 0 && i = 0 -> + [ (tbr 0, true); (tpl 0, false); (tdb 0, false) ] + | k when k = 0 -> [ (tdb 0, false) ] + | k when k < i + 1 -> (tdb k, true) :: (tdb (k - 1), false) :: sub (k - 2) + | k when k = i + 1 -> + List.append + [ (tbr i, true); (tpl i, false); (tdb k, true); (tdb i, false) ] + (sub (k - 2)) + | k when k > i + 1 -> + (plus k l, true) :: (plus (k - 1) l, false) :: sub (k - 2) | _ -> assert false - in sub (2*arity) + in + sub (2 * arity) let assc i arity l = - let src = comp_biased arity (if i = 0 then 1 else i+2) in + let src = comp_biased arity (if i = 0 then 1 else i + 2) in let tgt = comp_biased arity i in let ps = Builtin.ps_comp (arity + 1) in - let assc = Coh.check_inv ps src tgt ("builtin_assc",0,[])in + let assc = Coh.check_inv ps src tgt ("builtin_assc", 0, []) in let sub = sub_assc_i i arity l in - let _,ty,_ = Coh.forget assc in - Coh (assc, sub), Unchecked.ty_apply_sub_ps ty sub + let _, ty, _ = Coh.forget assc in + (Coh (assc, sub), Unchecked.ty_apply_sub_ps ty sub) let whsk i arity l = - let src = src_i_f i (List.mem (Var.Db (i-1)) l) in + let src = src_i_f i (List.mem (Var.Db (i - 1)) l) in let tgt = tgt_i_f i (List.mem (Var.Db (idx_src i)) l) l in let sub = sub_whisk_i i arity l src tgt in let comp = Builtin.comp_n arity in - let whsk = F.coh_depth0 comp [Db i] in - let _,ty,_ = Coh.forget whsk in - Coh(whsk, sub), Unchecked.ty_apply_sub_ps ty sub + let whsk = F.coh_depth0 comp [ Db i ] in + let _, ty, _ = Coh.forget whsk in + (Coh (whsk, sub), Unchecked.ty_apply_sub_ps ty sub) let move_at v l arity = - let mv,ty = + let mv, ty = match v with - | Var.Db i when i = 0 -> assc 0 arity l + | Var.Db i when i = 0 -> assc 0 arity l | Var.Db i when i mod 2 = 0 -> whsk i arity l | Var.Db i -> assc i arity l | _ -> - Error.fatal - "cubical composite can only compute on De Bruijn variables" + Error.fatal + "cubical composite can only compute on De Bruijn variables" in - match ty with - | Arr(_,s,t) -> mv,s,t - | _ -> assert false + match ty with Arr (_, s, t) -> (mv, s, t) | _ -> assert false let build_cubical_long arity list = let append_onto_if cond l1 l2 = if cond then List.append l1 l2 else l2 in - let rec sub ctx ?(add_src=false) onto = + let rec sub ctx ?(add_src = false) onto = match ctx with | [] -> onto - | [v,_] -> - if List.mem v list then - let mv,_,tgtv = move_at v list arity in - (mv,true)::(tgtv, false)::onto - else onto - | (v,_)::(tv,_)::ctx -> - let mv,srcv,tgtv = move_at v list arity in - let mtv,srctv,tgttv = move_at tv list arity in - let src = if List.mem tv list then srctv else srcv in - let onto = - append_onto_if - (List.mem v list) - [mv,true; tgtv, false] - (append_onto_if - (List.mem tv list) - [mtv,true; tgttv, false] - (append_onto_if add_src [src, false] onto)) - in - sub ctx onto + | [ (v, _) ] -> + if List.mem v list then + let mv, _, tgtv = move_at v list arity in + (mv, true) :: (tgtv, false) :: onto + else onto + | (v, _) :: (tv, _) :: ctx -> + let mv, srcv, tgtv = move_at v list arity in + let mtv, srctv, tgttv = move_at tv list arity in + let src = if List.mem tv list then srctv else srcv in + let onto = + append_onto_if (List.mem v list) + [ (mv, true); (tgtv, false) ] + (append_onto_if (List.mem tv list) + [ (mtv, true); (tgttv, false) ] + (append_onto_if add_src [ (src, false) ] onto)) + in + sub ctx onto in let comp = Suspension.coh (Some 1) (Builtin.comp_n (List.length list)) in - let base = [plus (2*arity-1) list, false; tdb 0, false] in + let base = [ (plus ((2 * arity) - 1) list, false); (tdb 0, false) ] in let ctx_comp = Unchecked.ps_to_ctx (Builtin.ps_comp arity) in let s = sub ctx_comp ~add_src:true base in - let _,ty,_ = Coh.forget comp in - Coh (comp, s), (Unchecked.ty_apply_sub_ps ty s) + let _, ty, _ = Coh.forget comp in + (Coh (comp, s), Unchecked.ty_apply_sub_ps ty s) let build_cubical arity list = match arity with | 1 -> - let src_on = List.mem (Var.Db 1) list in - let tgt_on = List.mem (Var.Db 0) list in - tbr 2, Arr(Obj, src_i_f 2 src_on, tgt_i_f 2 tgt_on list) + let src_on = List.mem (Var.Db 1) list in + let tgt_on = List.mem (Var.Db 0) list in + (tbr 2, Arr (Obj, src_i_f 2 src_on, tgt_i_f 2 tgt_on list)) | arity -> build_cubical_long arity list - let cubical arity list = - Memo.find arity list build_cubical + let cubical arity list = Memo.find arity list build_cubical end let desuspend_db v d = match v with - | Var.Db i -> Var.Db (i-2*d) + | Var.Db i -> Var.Db (i - (2 * d)) | _ -> Error.fatal "only de Bruijn levels expected in coherences" (* source and source inclusion of a functorialised ps *) @@ -204,10 +214,10 @@ let ctx_src ps l = let bdry = Unchecked.ps_bdry ps in let tgt_incl_ps = Unchecked.ps_tgt ps in let tgt_f, bdry_f, names, l = F.sub_w_tgt bdry tgt_incl_ps l in - let src_ctx,i1,i2 = Unchecked.ps_compose (d-1) ps bdry_f in + let src_ctx, i1, i2 = Unchecked.ps_compose (d - 1) ps bdry_f in let in_minus = Unchecked.identity_ps ps in - let src_incl = Unchecked.pullback_up (d-1) ps bdry_f in_minus tgt_f in - src_ctx, src_incl, i1, i2, bdry_f, l, names + let src_incl = Unchecked.pullback_up (d - 1) ps bdry_f in_minus tgt_f in + (src_ctx, src_incl, i1, i2, bdry_f, l, names) (* target and target inclusion of a functorialised ps *) let ctx_tgt ps l = @@ -215,14 +225,14 @@ let ctx_tgt ps l = let bdry = Unchecked.ps_bdry ps in let src_incl_ps = Unchecked.ps_src ps in let src_f, bdry_f, names, l_bdry = F.sub_w_tgt bdry src_incl_ps l in - let tgt_ctx,i1,i2 = Unchecked.ps_compose (d-1) bdry_f ps in + let tgt_ctx, i1, i2 = Unchecked.ps_compose (d - 1) bdry_f ps in let in_plus = Unchecked.sub_to_sub_ps ps (F.tgt_subst l) in - let tgt_incl = Unchecked.pullback_up (d-1) bdry_f ps src_f in_plus in - tgt_ctx, tgt_incl, i1, i2, bdry_f, l_bdry, names + let tgt_incl = Unchecked.pullback_up (d - 1) bdry_f ps src_f in_plus in + (tgt_ctx, tgt_incl, i1, i2, bdry_f, l_bdry, names) (* Construct source (t[i1]) * (tgt_f[i2]) *) let naturality_src coh ty tgt ty_base dim l i1 i2 names = - let t = Coh(coh, i1) in + let t = Coh (coh, i1) in if l = [] then t else let tgt_f_ty = Unchecked.rename_ty (F.ty ty_base l tgt) names in @@ -231,12 +241,12 @@ let naturality_src coh ty tgt ty_base dim l i1 i2 names = let tgt_f = Unchecked.tm_apply_sub_ps tgt_f i2 in let ty = Unchecked.ty_apply_sub_ps ty i1 in let coh_src_sub_ps = F.whisk_sub_ps 0 t ty tgt_f tgt_f_ty in - let comp = Suspension.coh (Some (dim-1)) (Builtin.comp_n 2) in - Coh(comp,coh_src_sub_ps) + let comp = Suspension.coh (Some (dim - 1)) (Builtin.comp_n 2) in + Coh (comp, coh_src_sub_ps) (* Construct target (src_f[i1]) * (t[i2]) *) let naturality_tgt coh ty src ty_base dim l i1 i2 names = - let t = Coh(coh, i2) in + let t = Coh (coh, i2) in if l = [] then t else let src_f_ty = Unchecked.rename_ty (F.ty ty_base l src) names in @@ -245,25 +255,25 @@ let naturality_tgt coh ty src ty_base dim l i1 i2 names = let src_f = Unchecked.tm_apply_sub_ps src_f i1 in let ty = Unchecked.ty_apply_sub_ps ty i2 in let coh_tgt_sub_ps = F.whisk_sub_ps 0 src_f src_f_ty t ty in - let comp = Suspension.coh (Some (dim-1)) (Builtin.comp_n 2) in - Coh(comp,coh_tgt_sub_ps) + let comp = Suspension.coh (Some (dim - 1)) (Builtin.comp_n 2) in + Coh (comp, coh_tgt_sub_ps) let biasor_sub_intch_src ps bdry_f i1 i2 d = - let ps_red = Ps_reduction.reduce (d-1) ps in - let prod,_,_ = Unchecked.ps_compose (d-1) ps_red bdry_f in + let ps_red = Ps_reduction.reduce (d - 1) ps in + let prod, _, _ = Unchecked.ps_compose (d - 1) ps_red bdry_f in let red_sub_prod = Ps_reduction.reduction_sub prod in let red_sub_ps = Ps_reduction.reduction_sub ps in let left_leg = Unchecked.sub_ps_apply_sub_ps red_sub_ps i1 in - let prod_to_src = Unchecked.pullback_up (d-1) ps_red bdry_f left_leg i2 in + let prod_to_src = Unchecked.pullback_up (d - 1) ps_red bdry_f left_leg i2 in Unchecked.sub_ps_apply_sub_ps red_sub_prod prod_to_src let biasor_sub_intch_tgt ps bdry_f i1 i2 d = - let ps_red = Ps_reduction.reduce (d-1) ps in - let prod,_,_ = Unchecked.ps_compose (d-1) bdry_f ps_red in + let ps_red = Ps_reduction.reduce (d - 1) ps in + let prod, _, _ = Unchecked.ps_compose (d - 1) bdry_f ps_red in let red_sub_prod = Ps_reduction.reduction_sub prod in let red_sub_ps = Ps_reduction.reduction_sub ps in let right_leg = Unchecked.sub_ps_apply_sub_ps red_sub_ps i2 in - let prod_to_src = Unchecked.pullback_up (d-1) bdry_f ps_red i1 right_leg in + let prod_to_src = Unchecked.pullback_up (d - 1) bdry_f ps_red i1 right_leg in Unchecked.sub_ps_apply_sub_ps red_sub_prod prod_to_src (* Interchange needed for source of depth-1 non-inv coh *) @@ -271,30 +281,30 @@ let biasor_sub_intch_tgt ps bdry_f i1 i2 d = https://q.uiver.app/#q=WzAsOCxbMSwwLCJcXHBhcnRpYWxcXEdhbW1hIl0sWzIsMSwiXFxvdmVycmlnaHRhcnJvd3tcXHBhcnRpYWxcXEdhbW1hfV57WF9cXHRhdX0iXSxbMCwzLCJcXEdhbW1hIl0sWzAsMSwiXFxHYW1tYV57cmVkfSJdLFsxLDIsIlxcRGVsdGEiXSxbMSwzLCJcXFBoaSJdLFszLDIsIlxcRGVsdGFee3JlZH0iXSxbMSw0LCJcXG92ZXJyaWdodGFycm93e1xcR2FtbWF9XlgiXSxbMCwxLCJcXHNpZ21hIl0sWzAsMiwiXFx0YXUiLDEseyJsYWJlbF9wb3NpdGlvbiI6NzAsImN1cnZlIjo1fV0sWzMsMiwiXFxyaG9fXFxHYW1tYSIsMl0sWzAsMywiXFx0YXVfciIsMV0sWzEsNCwial8yIiwxXSxbMyw0LCJqXzEiLDFdLFs0LDAsIiIsMCx7InN0eWxlIjp7Im5hbWUiOiJjb3JuZXIifX1dLFs0LDUsIiIsMCx7InN0eWxlIjp7ImJvZHkiOnsibmFtZSI6ImRhc2hlZCJ9fX1dLFsyLDUsImlfMSIsMV0sWzEsNSwiaV8yIiwxXSxbNSwwLCIiLDEseyJzdHlsZSI6eyJuYW1lIjoiY29ybmVyIn19XSxbNiw0LCJcXHJob19cXERlbHRhIiwxLHsiY3VydmUiOjF9XSxbMiw3XSxbMSw3LCJcXG92ZXJyaWdodGFycm93e1xcdGF1fV5YIiwxLHsiY3VydmUiOi0zfV0sWzUsNywiIiwxLHsic3R5bGUiOnsiYm9keSI6eyJuYW1lIjoiZGFzaGVkIn19fV1d *) let depth1_interchanger_src coh coh_bridge l = - let gamma,coh_ty,_ = Coh.forget coh in - let _,tgt,ty_base = Coh.noninv_srctgt coh in + let gamma, coh_ty, _ = Coh.forget coh in + let _, tgt, ty_base = Coh.noninv_srctgt coh in let d = Unchecked.dim_ps gamma in let src_ctx, src_incl, i1, i2, bdry_f, l_tgt, names = ctx_src gamma l in let coh_src = naturality_src coh coh_ty tgt ty_base d l_tgt i1 i2 names in - let coh_tgt = Coh(coh_bridge, biasor_sub_intch_src gamma bdry_f i1 i2 d) in - let intch_coh = Coh.check_inv src_ctx coh_src coh_tgt ("intch_src",0,[]) in - let _,ty,_ = Coh.forget intch_coh in - let intch = Coh(intch_coh,src_incl) in + let coh_tgt = Coh (coh_bridge, biasor_sub_intch_src gamma bdry_f i1 i2 d) in + let intch_coh = Coh.check_inv src_ctx coh_src coh_tgt ("intch_src", 0, []) in + let _, ty, _ = Coh.forget intch_coh in + let intch = Coh (intch_coh, src_incl) in let ty = Unchecked.ty_apply_sub_ps ty src_incl in - intch, ty + (intch, ty) let depth1_interchanger_tgt coh coh_bridge l = - let gamma,coh_ty,_ = Coh.forget coh in - let src,_,ty_base = Coh.noninv_srctgt coh in + let gamma, coh_ty, _ = Coh.forget coh in + let src, _, ty_base = Coh.noninv_srctgt coh in let d = Unchecked.dim_ps gamma in - let tgt_ctx,tgt_incl, i1, i2, bdry_f, l_src, names = ctx_tgt gamma l in + let tgt_ctx, tgt_incl, i1, i2, bdry_f, l_src, names = ctx_tgt gamma l in let coh_tgt = naturality_tgt coh coh_ty src ty_base d l_src i1 i2 names in - let coh_src = Coh(coh_bridge, biasor_sub_intch_tgt gamma bdry_f i1 i2 d) in - let intch_coh = Coh.check_inv tgt_ctx coh_src coh_tgt ("intch_tgt",0,[]) in - let _,ty,_ = Coh.forget intch_coh in - let intch = Coh(intch_coh,tgt_incl) in + let coh_src = Coh (coh_bridge, biasor_sub_intch_tgt gamma bdry_f i1 i2 d) in + let intch_coh = Coh.check_inv tgt_ctx coh_src coh_tgt ("intch_tgt", 0, []) in + let _, ty, _ = Coh.forget intch_coh in + let intch = Coh (intch_coh, tgt_incl) in let ty = Unchecked.ty_apply_sub_ps ty tgt_incl in - intch, ty + (intch, ty) (* Compare substitutions out of the same ps-context @@ -305,100 +315,100 @@ let depth1_bridge_sub ps_inter l_inter d = let rec aux red = match red with | [] -> [] - | (t,true)::(w,false)::red -> - let ps_comp,s = - match t with - | Coh(comp,s) -> - let ps_comp,_,_ = Coh.forget comp in - ps_comp,s - | Var v -> - let ty,_ = List.assoc v (Unchecked.ps_to_ctx ps_inter) in - let s = (Var v,true)::(Unchecked.ty_to_sub_ps ty) in - let ps_comp = Suspension.ps (Some (Unchecked.dim_ty ty)) (Br[]) in - ps_comp,s - | Meta_tm _ -> Error.fatal "meta_variables must have been resolved" - in - let l = F.preimage (Unchecked.ps_to_ctx ps_comp) s l_inter in - if l <> [] then - let arity = LinearComp.arity ps_comp in - let s = F.sub (Unchecked.sub_ps_to_sub s) l in - let w_plus = Unchecked.tm_apply_sub w (F.tgt_subst l_inter) in - let list = List.map (fun v -> desuspend_db v (d-1)) l in - let ccomp,ty = LinearComp.cubical arity list in - let ccomp = Suspension.tm (Some (d-1)) ccomp in - let ccomp = Unchecked.tm_apply_sub ccomp s in - let ty = Suspension.ty (Some (d-1)) ty in - let ty = Unchecked.ty_apply_sub ty s in - let src,tgt = - match ty with - | Arr(_,s,t) -> s,t - | _ -> assert false + | (t, true) :: (w, false) :: red -> + let ps_comp, s = + match t with + | Coh (comp, s) -> + let ps_comp, _, _ = Coh.forget comp in + (ps_comp, s) + | Var v -> + let ty, _ = List.assoc v (Unchecked.ps_to_ctx ps_inter) in + let s = (Var v, true) :: Unchecked.ty_to_sub_ps ty in + let ps_comp = + Suspension.ps (Some (Unchecked.dim_ty ty)) (Br []) + in + (ps_comp, s) + | Meta_tm _ -> Error.fatal "meta_variables must have been resolved" in - (ccomp, true):: - (tgt, false):: - (src, false):: - (w_plus,false)::(aux red) - else - (t,true)::(w,false)::(aux red) - | (t,e)::red -> (t,e)::(aux red) - in aux (Ps_reduction.reduction_sub ps_inter) + let l = F.preimage (Unchecked.ps_to_ctx ps_comp) s l_inter in + if l <> [] then + let arity = LinearComp.arity ps_comp in + let s = F.sub (Unchecked.sub_ps_to_sub s) l in + let w_plus = Unchecked.tm_apply_sub w (F.tgt_subst l_inter) in + let list = List.map (fun v -> desuspend_db v (d - 1)) l in + let ccomp, ty = LinearComp.cubical arity list in + let ccomp = Suspension.tm (Some (d - 1)) ccomp in + let ccomp = Unchecked.tm_apply_sub ccomp s in + let ty = Suspension.ty (Some (d - 1)) ty in + let ty = Unchecked.ty_apply_sub ty s in + let src, tgt = + match ty with Arr (_, s, t) -> (s, t) | _ -> assert false + in + (ccomp, true) :: (tgt, false) :: (src, false) :: (w_plus, false) + :: aux red + else (t, true) :: (w, false) :: aux red + | (t, e) :: red -> (t, e) :: aux red + in + aux (Ps_reduction.reduction_sub ps_inter) let loc_max_dim d ps x = let ctx = Unchecked.ps_to_ctx ps in - let ty,expl = List.assoc x ctx in - expl && (Unchecked.dim_ty ty = d) + let ty, expl = List.assoc x ctx in + expl && Unchecked.dim_ty ty = d let intermediate_ps ps l d = - let l_d0,l_d1 = List.partition (loc_max_dim (d-1) ps) l in - if l_d0 = [] then - ps,l,Unchecked.(sub_ps_to_sub (identity_ps ps)) + let l_d0, l_d1 = List.partition (loc_max_dim (d - 1) ps) l in + if l_d0 = [] then (ps, l, Unchecked.(sub_ps_to_sub (identity_ps ps))) else - let ps_f_c = F.ctx (Unchecked.ps_to_ctx ps) l_d0 in - let _,names,_ = Unchecked.db_levels ps_f_c in - let ps_f = PS.(forget (mk (Ctx.check ps_f_c))) in - let l_psf = (List.map (fun x -> Var.Db (List.assoc x names)) l_d1) in - let names = List.map (fun (x,n) -> (Var.Db n, Var x)) names in - ps_f, l_psf, names + let ps_f_c = F.ctx (Unchecked.ps_to_ctx ps) l_d0 in + let _, names, _ = Unchecked.db_levels ps_f_c in + let ps_f = PS.(forget (mk (Ctx.check ps_f_c))) in + let l_psf = List.map (fun x -> Var.Db (List.assoc x names)) l_d1 in + let names = List.map (fun (x, n) -> (Var.Db n, Var x)) names in + (ps_f, l_psf, names) let bridge_ps ps_inter l_inter d = let red_sub = Ps_reduction.reduction_sub ps_inter in - let ps_red = Ps_reduction.reduce (d-1) ps_inter in + let ps_red = Ps_reduction.reduce (d - 1) ps_inter in let ps_red_c = Unchecked.ps_to_ctx ps_red in let coh_l = F.preimage ps_red_c red_sub l_inter in let coh_l = List.filter (loc_max_dim d ps_red) coh_l in - ps_red, coh_l + (ps_red, coh_l) let bridge_coh coh ps_bridge = - let _,_,name = Coh.forget coh in - let src,tgt,_ = Coh.noninv_srctgt coh in - let name_red = Unchecked.full_name name^"_red",0,[] in + let _, _, name = Coh.forget coh in + let src, tgt, _ = Coh.noninv_srctgt coh in + let name_red = (Unchecked.full_name name ^ "_red", 0, []) in let coh_bridge = Coh.check_noninv ps_bridge src tgt name_red in coh_bridge let coh_depth1 coh l = - let ps,_,_ = Coh.forget coh in + let ps, _, _ = Coh.forget coh in let d = Unchecked.dim_ps ps in let ps_inter, l_inter, names = intermediate_ps ps l d in let ps_bridge, l_bridge = bridge_ps ps_inter l_inter d in let coh_bridge = bridge_coh coh ps_bridge in - let intch_src,intch_src_ty = depth1_interchanger_src coh coh_bridge l in - let intch_tgt,intch_tgt_ty = depth1_interchanger_tgt coh coh_bridge l in + let intch_src, intch_src_ty = depth1_interchanger_src coh coh_bridge l in + let intch_tgt, intch_tgt_ty = depth1_interchanger_tgt coh coh_bridge l in let bridge = depth1_bridge_sub ps_inter l_inter d in let bridge = Unchecked.sub_ps_apply_sub bridge (F.sub names l_inter) in let coh_bridge_f = F.coh_depth0 coh_bridge l_bridge in - let middle = Coh(coh_bridge_f, bridge) in - let inner_tgt,final_tgt = - match intch_tgt_ty with - | Arr(_,t,t') -> t,t' - | _ -> assert false + let middle = Coh (coh_bridge_f, bridge) in + let inner_tgt, final_tgt = + match intch_tgt_ty with Arr (_, t, t') -> (t, t') | _ -> assert false in let comp_sub_ps = List.append - [intch_tgt,true;final_tgt,false;middle,true;inner_tgt,false;intch_src,true] + [ + (intch_tgt, true); + (final_tgt, false); + (middle, true); + (inner_tgt, false); + (intch_src, true); + ] (Unchecked.ty_to_sub_ps intch_src_ty) in let comp = Suspension.coh (Some d) (Builtin.comp_n 3) in - Coh(comp, comp_sub_ps), F.ctx (Unchecked.ps_to_ctx ps) l + (Coh (comp, comp_sub_ps), F.ctx (Unchecked.ps_to_ctx ps) l) -let init () = - F.coh_depth1 := coh_depth1 +let init () = F.coh_depth1 := coh_depth1 diff --git a/lib/cubical_composite.mli b/lib/cubical_composite.mli index c7ad4a69..28ead8dc 100644 --- a/lib/cubical_composite.mli +++ b/lib/cubical_composite.mli @@ -1 +1 @@ -val init : unit -> unit +val init : unit -> unit diff --git a/lib/dune b/lib/dune index 2db0c66d..5a8f9749 100644 --- a/lib/dune +++ b/lib/dune @@ -1,11 +1,10 @@ -(menhir (modules parser)) +(menhir + (modules parser)) + (ocamllex lexer) (library (name catt) (public_name catt) (modules_without_implementation raw_types) - (libraries base) - ;(libraries landmarks) - ;(preprocess (pps landmarks-ppx --auto)) -) + (libraries base)) diff --git a/lib/elaborate.ml b/lib/elaborate.ml index 76200d37..13b9e8f3 100644 --- a/lib/elaborate.ml +++ b/lib/elaborate.ml @@ -1,293 +1,292 @@ open Std open Common open Kernel -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) exception NotUnifiable of string * string module Queue = Base.Queue module Constraints = struct - type t = {ty : (ty * ty) Queue.t; tm : (tm * tm) Queue.t} + type t = { ty : (ty * ty) Queue.t; tm : (tm * tm) Queue.t } - let create () = {ty = Queue.create(); tm = Queue.create()} + let create () = { ty = Queue.create (); tm = Queue.create () } let _to_string c = let print_ty = - Queue.fold - c.ty - ~init:"" - ~f:(fun s (ty1,ty2) -> - Printf.sprintf "%s (%s = %s)" - s - (Unchecked.ty_to_string ty1) - (Unchecked.ty_to_string ty2)) + Queue.fold c.ty ~init:"" ~f:(fun s (ty1, ty2) -> + Printf.sprintf "%s (%s = %s)" s + (Unchecked.ty_to_string ty1) + (Unchecked.ty_to_string ty2)) in let print_tm = - Queue.fold - c.tm - ~init:"" - ~f:(fun s (tm1, tm2) -> - Printf.sprintf "%s (%s = %s)" - s - (Unchecked.tm_to_string tm1) - (Unchecked.tm_to_string tm2)) + Queue.fold c.tm ~init:"" ~f:(fun s (tm1, tm2) -> + Printf.sprintf "%s (%s = %s)" s + (Unchecked.tm_to_string tm1) + (Unchecked.tm_to_string tm2)) in Printf.sprintf "[%s] [%s]" print_ty print_tm let rec unify_ty cst ty1 ty2 = - match ty1, ty2 with + match (ty1, ty2) with | Obj, Obj -> () - | Arr(a1,u1,v1), Arr(a2,u2,v2) -> - unify_ty cst a1 a2; - unify_tm cst u1 u2; - unify_tm cst v1 v2 - | Meta_ty _, _ - | _, Meta_ty _ -> Queue.enqueue cst.ty (ty1, ty2) - | Arr(_,_,_), Obj - | Obj, Arr(_,_,_) -> - raise (NotUnifiable (Unchecked.ty_to_string ty1, Unchecked.ty_to_string ty2)) + | Arr (a1, u1, v1), Arr (a2, u2, v2) -> + unify_ty cst a1 a2; + unify_tm cst u1 u2; + unify_tm cst v1 v2 + | Meta_ty _, _ | _, Meta_ty _ -> Queue.enqueue cst.ty (ty1, ty2) + | Arr (_, _, _), Obj | Obj, Arr (_, _, _) -> + raise + (NotUnifiable (Unchecked.ty_to_string ty1, Unchecked.ty_to_string ty2)) + and unify_tm cst tm1 tm2 = - match tm1, tm2 with + match (tm1, tm2) with | Var v1, Var v2 when v1 = v2 -> () - | Coh(coh1,s1), Coh(coh2,s2) -> - begin + | Coh (coh1, s1), Coh (coh2, s2) -> ( try Coh.check_equal coh1 coh2; unify_sub cst s1 s2 with Invalid_argument _ -> - raise (NotUnifiable (Coh.to_string coh1, Coh.to_string coh2)) - end + raise (NotUnifiable (Coh.to_string coh1, Coh.to_string coh2))) | Meta_tm _, Meta_tm _ when tm1 = tm2 -> () - | Meta_tm _, _ - | _, Meta_tm _ -> Queue.enqueue cst.tm (tm1, tm2) + | Meta_tm _, _ | _, Meta_tm _ -> Queue.enqueue cst.tm (tm1, tm2) | Var _, Coh _ | Coh _, Var _ | Var _, Var _ -> - raise (NotUnifiable (Unchecked.tm_to_string tm1, Unchecked.tm_to_string tm2)) + raise + (NotUnifiable (Unchecked.tm_to_string tm1, Unchecked.tm_to_string tm2)) + and unify_sub cst s1 s2 = - match s1, s2 with - | [],[] -> () - | (t1,_)::s1, (t2,_)::s2 -> unify_tm cst t1 t2; unify_sub cst s1 s2 - | [], _::_ | _::_,[] -> - raise (NotUnifiable (Unchecked.sub_ps_to_string s1, Unchecked.sub_ps_to_string s2)) - -type mgu = { uty : (int * ty) list; utm : (int * tm) list } - -let combine_mgu m1 m2 = - {uty = List.append m1.uty m2.uty; - utm = List.append m1.utm m2.utm} - -let rec ty_replace_meta_ty (i,ty') ty = - match ty with - | Meta_ty j when i = j -> ty' - | Meta_ty _ -> ty - | Obj -> Obj - | Arr(a,u,v) -> - Arr (ty_replace_meta_ty (i,ty') a, u, v) - -let rec tm_replace_meta_tm (i,tm') tm = - match tm with - | Meta_tm j when i = j -> tm' - | Meta_tm _ -> tm - | Var v -> Var v - | Coh(c,s) -> Coh(c, List.map (fun (t,expl) -> tm_replace_meta_tm (i,tm') t, expl) s) - -let rec ty_replace_meta_tm (i,tm') ty = - match ty with - | Meta_ty _ -> ty - | Obj -> Obj - | Arr(a,u,v) -> - Arr (ty_replace_meta_tm (i,tm') a, - tm_replace_meta_tm (i,tm') u, - tm_replace_meta_tm (i,tm') v) - -let queue_map_both f = - Queue.map ~f:(fun (x,y) -> (f x, f y)) - -let cst_replace_ty (i,ty) c = - {ty = queue_map_both (ty_replace_meta_ty (i,ty)) c.ty; tm = c.tm} - -let cst_replace_tm (i,tm) c = - let ty_replace = ty_replace_meta_tm (i,tm) in - let tm_replace = tm_replace_meta_tm (i,tm) in - {ty = queue_map_both ty_replace c.ty; - tm = queue_map_both tm_replace c.tm} - -let mgu_replace_ty (i,ty) l = - {uty = List.map_right (ty_replace_meta_ty (i,ty)) l.uty; utm = l.utm} - -let mgu_replace_tm (i,tm) l = - let ty_replace = ty_replace_meta_tm (i,tm) in - let tm_replace = tm_replace_meta_tm (i,tm) in - {uty = List.map_right ty_replace l.uty; - utm = List.map_right tm_replace l.utm} - -let substitute_ty l ty = - let ty = - List.fold_left (fun ty (i,tm) -> ty_replace_meta_tm (i,tm) ty) ty l.utm - in - List.fold_left (fun ty (i,ty') -> ty_replace_meta_ty (i,ty') ty) ty l.uty - -let substitute_tm l tm = - List.fold_left (fun tm (i,tm') -> tm_replace_meta_tm (i,tm') tm) tm l.utm + match (s1, s2) with + | [], [] -> () + | (t1, _) :: s1, (t2, _) :: s2 -> + unify_tm cst t1 t2; + unify_sub cst s1 s2 + | [], _ :: _ | _ :: _, [] -> + raise + (NotUnifiable + (Unchecked.sub_ps_to_string s1, Unchecked.sub_ps_to_string s2)) + + type mgu = { uty : (int * ty) list; utm : (int * tm) list } + + let combine_mgu m1 m2 = + { uty = List.append m1.uty m2.uty; utm = List.append m1.utm m2.utm } + + let rec ty_replace_meta_ty (i, ty') ty = + match ty with + | Meta_ty j when i = j -> ty' + | Meta_ty _ -> ty + | Obj -> Obj + | Arr (a, u, v) -> Arr (ty_replace_meta_ty (i, ty') a, u, v) + + let rec tm_replace_meta_tm (i, tm') tm = + match tm with + | Meta_tm j when i = j -> tm' + | Meta_tm _ -> tm + | Var v -> Var v + | Coh (c, s) -> + Coh + ( c, + List.map (fun (t, expl) -> (tm_replace_meta_tm (i, tm') t, expl)) s + ) + + let rec ty_replace_meta_tm (i, tm') ty = + match ty with + | Meta_ty _ -> ty + | Obj -> Obj + | Arr (a, u, v) -> + Arr + ( ty_replace_meta_tm (i, tm') a, + tm_replace_meta_tm (i, tm') u, + tm_replace_meta_tm (i, tm') v ) + + let queue_map_both f = Queue.map ~f:(fun (x, y) -> (f x, f y)) + + let cst_replace_ty (i, ty) c = + { ty = queue_map_both (ty_replace_meta_ty (i, ty)) c.ty; tm = c.tm } + + let cst_replace_tm (i, tm) c = + let ty_replace = ty_replace_meta_tm (i, tm) in + let tm_replace = tm_replace_meta_tm (i, tm) in + { ty = queue_map_both ty_replace c.ty; tm = queue_map_both tm_replace c.tm } + + let mgu_replace_ty (i, ty) l = + { uty = List.map_right (ty_replace_meta_ty (i, ty)) l.uty; utm = l.utm } + + let mgu_replace_tm (i, tm) l = + let ty_replace = ty_replace_meta_tm (i, tm) in + let tm_replace = tm_replace_meta_tm (i, tm) in + { + uty = List.map_right ty_replace l.uty; + utm = List.map_right tm_replace l.utm; + } + + let substitute_ty l ty = + let ty = + List.fold_left (fun ty (i, tm) -> ty_replace_meta_tm (i, tm) ty) ty l.utm + in + List.fold_left (fun ty (i, ty') -> ty_replace_meta_ty (i, ty') ty) ty l.uty + + let substitute_tm l tm = + List.fold_left (fun tm (i, tm') -> tm_replace_meta_tm (i, tm') tm) tm l.utm (* Martelli-Montanari algorithm *) let resolve_one_step c knowns = match Queue.dequeue c.ty with - | Some (ty1,ty2) -> - begin - match ty1,ty2 with - | Meta_ty i, Meta_ty j when i = j -> c, knowns + | Some (ty1, ty2) -> ( + match (ty1, ty2) with + | Meta_ty i, Meta_ty j when i = j -> (c, knowns) | Meta_ty i, ty | ty, Meta_ty i -> - let c = cst_replace_ty (i,ty) c in - let knowns = mgu_replace_ty (i,ty) knowns in - c,{uty = (i,ty)::knowns.uty; utm = knowns.utm} + let c = cst_replace_ty (i, ty) c in + let knowns = mgu_replace_ty (i, ty) knowns in + (c, { uty = (i, ty) :: knowns.uty; utm = knowns.utm }) | ty1, ty2 -> - unify_ty c ty1 ty2; - c, knowns - end - | None -> - match Queue.dequeue c.tm with - | Some (tm1,tm2) -> - begin - match tm1,tm2 with - | Meta_tm i, Meta_tm j when i = j -> c, knowns - | Meta_tm i, tm | tm, Meta_tm i -> - let c = cst_replace_tm (i,tm) c in - let knowns = mgu_replace_tm (i,tm) knowns in - c,{uty = knowns.uty; utm = (i,tm)::knowns.utm} - | tm1, tm2 -> - unify_tm c tm1 tm2; - c, knowns - end - | None -> Error.fatal "resolving empty constraints" + unify_ty c ty1 ty2; + (c, knowns)) + | None -> ( + match Queue.dequeue c.tm with + | Some (tm1, tm2) -> ( + match (tm1, tm2) with + | Meta_tm i, Meta_tm j when i = j -> (c, knowns) + | Meta_tm i, tm | tm, Meta_tm i -> + let c = cst_replace_tm (i, tm) c in + let knowns = mgu_replace_tm (i, tm) knowns in + (c, { uty = knowns.uty; utm = (i, tm) :: knowns.utm }) + | tm1, tm2 -> + unify_tm c tm1 tm2; + (c, knowns)) + | None -> Error.fatal "resolving empty constraints") let resolve c = let rec aux c knowns = if Queue.is_empty c.tm && Queue.is_empty c.ty then knowns else - let c,knowns = resolve_one_step c knowns in + let c, knowns = resolve_one_step c knowns in aux c knowns - in aux c {uty = []; utm = []} + in + aux c { uty = []; utm = [] } end module Constraints_typing = struct - let rec tm ctx meta_ctx t cst = Io.info ~v:5 (lazy - (Printf.sprintf - "constraint typing term %s in ctx %s, meta_ctx %s" + (Printf.sprintf "constraint typing term %s in ctx %s, meta_ctx %s" (Unchecked.tm_to_string t) (Unchecked.ctx_to_string ctx) (Unchecked.meta_ctx_to_string meta_ctx))); - match t with - | Var v -> begin - try t, fst (List.assoc v ctx) with - | Not_found -> - Error.fatal (Printf.sprintf - "variable %s not found in context" - (Var.to_string v)) - end - | Meta_tm i -> t, List.assoc i meta_ctx - | Coh(c,s)-> let ps,ty,_ = Coh.forget c in + match t with + | Var v -> ( + try (t, fst (List.assoc v ctx)) + with Not_found -> + Error.fatal + (Printf.sprintf "variable %s not found in context" (Var.to_string v)) + ) + | Meta_tm i -> (t, List.assoc i meta_ctx) + | Coh (c, s) -> + let ps, ty, _ = Coh.forget c in let tgt = Unchecked.ps_to_ctx ps in let s1 = Unchecked.sub_ps_to_sub s in let s1 = sub ctx meta_ctx s1 tgt cst in - Coh(c,(List.map2 (fun (_,t) (_,expl) -> t,expl) s1 s)), - Unchecked.ty_apply_sub ty s1 + ( Coh (c, List.map2 (fun (_, t) (_, expl) -> (t, expl)) s1 s), + Unchecked.ty_apply_sub ty s1 ) + and sub src meta_ctx s tgt cst = Io.info ~v:5 (lazy (Printf.sprintf - "constraint typing substitution %s in ctx %s, \ - target %s, meta_ctx %s" + "constraint typing substitution %s in ctx %s, target %s, meta_ctx %s" (Unchecked.sub_to_string s) (Unchecked.ctx_to_string src) (Unchecked.ctx_to_string tgt) (Unchecked.meta_ctx_to_string meta_ctx))); - match s,tgt with - | [],[] -> [] - | (x,u)::s, (_,(t,_))::c -> - let u,ty= tm src meta_ctx u cst in - let s = sub src meta_ctx s c cst in - Constraints.unify_ty cst ty (Unchecked.ty_apply_sub t s); - (x,u)::s - |[],_::_ | _::_, [] -> Error.fatal "wrong number of arguments" + match (s, tgt) with + | [], [] -> [] + | (x, u) :: s, (_, (t, _)) :: c -> + let u, ty = tm src meta_ctx u cst in + let s = sub src meta_ctx s c cst in + Constraints.unify_ty cst ty (Unchecked.ty_apply_sub t s); + (x, u) :: s + | [], _ :: _ | _ :: _, [] -> Error.fatal "wrong number of arguments" + and ty ctx meta_ctx t cst = Io.info ~v:5 (lazy - (Printf.sprintf - "constraint typing type %s in ctx %s, meta_ctx %s" + (Printf.sprintf "constraint typing type %s in ctx %s, meta_ctx %s" (Unchecked.ty_to_string t) (Unchecked.ctx_to_string ctx) (Unchecked.meta_ctx_to_string meta_ctx))); match t with | Obj -> Obj - | Arr(a,u,v) -> - let u, tu = tm ctx meta_ctx u cst in - let v, tv = tm ctx meta_ctx v cst in - let a = ty ctx meta_ctx a cst in - Constraints.unify_ty cst a tu; - Constraints.unify_ty cst a tv; - Arr (a,u,v) + | Arr (a, u, v) -> + let u, tu = tm ctx meta_ctx u cst in + let v, tv = tm ctx meta_ctx v cst in + let a = ty ctx meta_ctx a cst in + Constraints.unify_ty cst a tu; + Constraints.unify_ty cst a tv; + Arr (a, u, v) | Meta_ty _ -> t - let tm ctx meta_ctx t cst = - fst (tm ctx meta_ctx t cst) + let tm ctx meta_ctx t cst = fst (tm ctx meta_ctx t cst) let rec ctx c meta_ctx = match c with - | [] -> [], {Constraints.uty=[]; utm=[]} - | (x,(t,expl))::c -> - let c,known_mgu = ctx c meta_ctx in - let t = Constraints.substitute_ty known_mgu t in - let cstt = Constraints.create () in - let t = ty c meta_ctx t cstt in - let new_mgu = Constraints.resolve cstt in - let t = Constraints.substitute_ty new_mgu t in - (x,(t,expl))::c, - Constraints.combine_mgu known_mgu new_mgu + | [] -> ([], { Constraints.uty = []; utm = [] }) + | (x, (t, expl)) :: c -> + let c, known_mgu = ctx c meta_ctx in + let t = Constraints.substitute_ty known_mgu t in + let cstt = Constraints.create () in + let t = ty c meta_ctx t cstt in + let new_mgu = Constraints.resolve cstt in + let t = Constraints.substitute_ty new_mgu t in + ((x, (t, expl)) :: c, Constraints.combine_mgu known_mgu new_mgu) end -let ctx c = - let c,meta_ctx = Translate_raw.ctx c in - Io.info ~v:2 (lazy (Printf.sprintf "elaborating context %s" (Unchecked.ctx_to_string c))); - let c,_ = Constraints_typing.ctx c meta_ctx in - Io.info ~v:4 (lazy (Printf.sprintf "elaborated context:%s" (Unchecked.ctx_to_string c))); - c - let preprocess_ty ctx ty = let ty = Raw.remove_let_ty ty in - if !Settings.implicit_suspension then - Raw.infer_susp_ty ctx ty - else ty + if !Settings.implicit_suspension then Raw.infer_susp_ty ctx ty else ty let preprocess_tm ctx tm = let tm = Raw.remove_let_tm tm in - if !Settings.implicit_suspension then - Raw.infer_susp_tm ctx tm - else tm + if !Settings.implicit_suspension then Raw.infer_susp_tm ctx tm else tm let rec preprocess_ctx = function | [] -> [] - | (v,t)::c -> - let c = preprocess_ctx c in - (v, preprocess_ty c t)::c + | (v, t) :: c -> + let c = preprocess_ctx c in + (v, preprocess_ty c t) :: c -let resolve_constraints ~ty_fn ~sub_fn ~print_fn ~kind ctx meta_ctx x = - let name = kind^": "^(print_fn x) in +let solve_cst ~elab_fn ~print_fn ~kind x = + let name = kind ^ ": " ^ print_fn x in Io.info ~v:2 (lazy (Printf.sprintf "inferring constraints for %s" name)); - let cst = Constraints.create() in try - let x = ty_fn ctx meta_ctx x cst in - Io.info ~v:4 (lazy (Printf.sprintf "inferred constraints:%s" (Constraints._to_string cst))); - let x = sub_fn (Constraints.resolve cst) x in + let x = elab_fn x in Io.info ~v:3 (lazy (Printf.sprintf "%s elaborated to %s" kind (print_fn x))); - ctx, x - with - | NotUnifiable(a,b) -> Error.unsatisfiable_constraints - name - (Printf.sprintf "could not unify %s and %s" a b) + x + with NotUnifiable (a, b) -> + Error.unsatisfiable_constraints name + (Printf.sprintf "could not unify %s and %s" a b) + +let ctx c = + let c, meta_ctx = Translate_raw.ctx c in + let elab_fn c = fst (Constraints_typing.ctx c meta_ctx) in + solve_cst ~elab_fn ~print_fn:Unchecked.ctx_to_string ~kind:"context" c + +let elab_ty ctx meta_ctx ty = + let cst = Constraints.create () in + let x = Constraints_typing.ty ctx meta_ctx ty cst in + Io.info ~v:4 + (lazy + (Printf.sprintf "inferred constraints:%s" (Constraints._to_string cst))); + let x = Constraints.substitute_ty (Constraints.resolve cst) x in + x + +let elab_tm ctx meta_ctx tm = + let cst = Constraints.create () in + let x = Constraints_typing.tm ctx meta_ctx tm cst in + Io.info ~v:4 + (lazy + (Printf.sprintf "inferred constraints:%s" (Constraints._to_string cst))); + let x = Constraints.substitute_tm (Constraints.resolve cst) x in + x let ty c ty = try @@ -295,14 +294,10 @@ let ty c ty = let ty = preprocess_ty c ty in let c = ctx c in let ty, meta_ctx = Translate_raw.ty ty in - resolve_constraints - ~ty_fn:Constraints_typing.ty - ~sub_fn:Constraints.substitute_ty - ~print_fn:Unchecked.ty_to_string - ~kind:"type" - c meta_ctx ty - with - Error.UnknownId(s) -> raise (Error.unknown_id s) + let elab_fn ty = elab_ty c meta_ctx ty in + let print_fn = Unchecked.ty_to_string in + (c, solve_cst ~elab_fn ~print_fn ~kind:"type" ty) + with Error.UnknownId s -> raise (Error.unknown_id s) let tm c tm = try @@ -310,14 +305,10 @@ let tm c tm = let tm = preprocess_tm c tm in let c = ctx c in let tm, meta_ctx = Translate_raw.tm tm in - resolve_constraints - ~ty_fn:Constraints_typing.tm - ~sub_fn:Constraints.substitute_tm - ~print_fn:Unchecked.tm_to_string - ~kind:"term" - c meta_ctx tm - with - Error.UnknownId(s) -> raise (Error.unknown_id s) + let elab_fn tm = elab_tm c meta_ctx tm in + let print_fn = Unchecked.tm_to_string in + (c, solve_cst ~elab_fn ~print_fn ~kind:"term" tm) + with Error.UnknownId s -> raise (Error.unknown_id s) let ty_in_ps ps t = try @@ -326,15 +317,14 @@ let ty_in_ps ps t = let ps = ctx ps in let t, meta_ctx = Translate_raw.ty t in let t = - resolve_constraints - ~ty_fn:Constraints_typing.ty - ~sub_fn:Constraints.substitute_ty - ~print_fn:Unchecked.ty_to_string - ~kind:"type" - ps meta_ctx t + let elab_fn ty = elab_ty ps meta_ctx ty in + solve_cst ~elab_fn ~print_fn:Unchecked.ty_to_string ~kind:"type" t in - let _, names,_ = Unchecked.db_levels ps in - Kernel.PS.(forget (mk (Kernel.Ctx.check ps))), - Unchecked.rename_ty (snd t) names - with - Error.UnknownId(s) -> raise (Error.unknown_id s) + try + let _, names, _ = Unchecked.db_levels ps in + ( Kernel.PS.(forget (mk (Kernel.Ctx.check ps))), + Unchecked.rename_ty t names ) + with + | Kernel.PS.Invalid -> raise (Error.invalid_ps (Unchecked.ctx_to_string ps)) + | DoubledVar x -> raise (Error.doubled_var (Unchecked.ctx_to_string ps) x) + with Error.UnknownId s -> raise (Error.unknown_id s) diff --git a/lib/environment.ml b/lib/environment.ml index 438d4715..2ae529bc 100644 --- a/lib/environment.ml +++ b/lib/environment.ml @@ -1,53 +1,43 @@ open Common open Kernel -open Unchecked_types.Unchecked_types(Coh) - -type value = - | Coh of Coh.t - | Tm of ctx * tm - -type v = {value : value; dim_input : int; dim_output : int} +open Unchecked_types.Unchecked_types (Coh) +type value = Coh of Coh.t | Tm of ctx * tm +type v = { value : value; dim_input : int; dim_output : int } type t = (Var.t, v) Hashtbl.t let env : t = Hashtbl.create 70 let add_let v c ?ty t = - let kc = Kernel.Ctx.check c in - let tm = Kernel.check_term kc ?ty t in - let ty = Kernel.(Ty.forget (Tm.typ tm)) in - let dim_input = Unchecked.dim_ctx c in - let dim_output = Unchecked.dim_ty ty in - Io.info ~v:4 - (lazy - (Printf.sprintf - "term %s of type %s added to environment" - (Unchecked.tm_to_string t) - (Unchecked.ty_to_string ty))); - Hashtbl.add env v ({value = Tm (c,t); dim_input; dim_output}); - (t,ty) + try + let kc = Kernel.Ctx.check c in + let tm = Kernel.check_term kc ?ty t in + let ty = Kernel.(Ty.forget (Tm.typ tm)) in + let dim_input = Unchecked.dim_ctx c in + let dim_output = Unchecked.dim_ty ty in + Io.info ~v:4 + (lazy + (Printf.sprintf "term %s of type %s added to environment" + (Unchecked.tm_to_string t) + (Unchecked.ty_to_string ty))); + Hashtbl.add env v { value = Tm (c, t); dim_input; dim_output }; + (t, ty) + with DoubledVar x -> Error.doubled_var (Unchecked.ctx_to_string c) x let add_coh v ps ty = - let coh = check_coh ps ty (Var.to_string v, 0,[]) in + let coh = check_coh ps ty (Var.to_string v, 0, []) in let dim_input = Unchecked.dim_ps ps in let dim_output = Unchecked.dim_ty ty in Io.info ~v:4 (lazy - (Printf.sprintf - "coherence %s added to environment" - (Var.to_string v))); - Hashtbl.add env v ({value = Coh coh; dim_input; dim_output}); + (Printf.sprintf "coherence %s added to environment" (Var.to_string v))); + Hashtbl.add env v { value = Coh coh; dim_input; dim_output }; coh let find v = try Hashtbl.find env v - with Not_found -> raise (Error.UnknownId (Var.to_string(v))) - -let val_var v = - (find v).value - -let dim_output v = - (find v).dim_output + with Not_found -> raise (Error.UnknownId (Var.to_string v)) -let dim_input v = - (find v).dim_input +let val_var v = (find v).value +let dim_output v = (find v).dim_output +let dim_input v = (find v).dim_input diff --git a/lib/environment.mli b/lib/environment.mli index eda249b7..ffe335c6 100644 --- a/lib/environment.mli +++ b/lib/environment.mli @@ -2,10 +2,7 @@ open Common open Kernel open Unchecked_types.Unchecked_types(Coh) -type value = - | Coh of Coh.t - | Tm of ctx * tm - +type value = Coh of Coh.t | Tm of ctx * tm type t val add_let : Var.t -> ctx -> ?ty:ty -> tm -> tm * ty diff --git a/lib/error.ml b/lib/error.ml index a3a84953..ba7387f6 100644 --- a/lib/error.ml +++ b/lib/error.ml @@ -5,19 +5,27 @@ exception FatalError exception UnknownId of string let fatal s = - Io.error "The following error occurred: \n%s\n This is a bug, please report.\n%!" s; + Io.error + "The following error occurred: \n%s\n This is a bug, please report.\n%!" s; raise FatalError let unsatisfiable_constraints t s = - Io.error "The constraints generated for the %s could not be solved for the following reason:\n%s%!" t s; + Io.error + "The constraints generated for the %s could not be solved for the \ + following reason:\n\ + %s%!" + t s; raise InvalidEntry let incomplete_constraints t = - Io.error "Incomplete constraints: some of the meta-variable could not be resolved in the following %s%!" t; + Io.error + "Incomplete constraints: some of the meta-variable could not be resolved \ + in the following %s%!" + t; raise InvalidEntry let untypable t s = - Io.error"The %s could not be typed for the following reason:\n%s%!" t s; + Io.error "The %s could not be typed for the following reason:\n%s%!" t s; raise InvalidEntry let not_valid_coherence c s = @@ -25,7 +33,10 @@ let not_valid_coherence c s = raise InvalidEntry let wrong_option_argument ~expected o a = - Io.error "Wrong argument for options %s, options %s given is not compatible with the expected type %s%!" o a expected; + Io.error + "Wrong argument for options %s, options %s given is not compatible with \ + the expected type %s%!" + o a expected; raise OptionsError let incompatible_options o1 o2 = @@ -42,14 +53,26 @@ let unknown_id s = let functorialisation t s = Io.error - "Could not compute the functorialisation of %s for the following reason:\n%s%!" t s; + "Could not compute the functorialisation of %s for the following reason:\n\ + %s%!" + t s; raise InvalidEntry let inversion t s = - Io.error - "Could not compute the inverse of %s for the following reason:\n%s%!" t s; + Io.error "Could not compute the inverse of %s for the following reason:\n%s%!" + t s; raise InvalidEntry let parsing_error t s = Io.error "Could not parse %s for the following reason:\n%s%!" t s; raise InvalidEntry + +let invalid_ps s = + Io.error "The following context is not a pasting scheme:\n%s%!" s; + raise InvalidEntry + +let doubled_var ctx v = + Io.error + "The following context is invalid because variable %s is repeated:\n%s%!" v + ctx; + raise InvalidEntry diff --git a/lib/error.mli b/lib/error.mli index a2cadd1f..5169cf36 100644 --- a/lib/error.mli +++ b/lib/error.mli @@ -15,3 +15,5 @@ val unknown_id : string -> 'a val functorialisation : string -> string -> 'a val inversion : string -> string -> 'a val parsing_error : string -> string -> 'a +val invalid_ps : string -> 'a +val doubled_var : string -> string -> 'a diff --git a/lib/functorialisation.ml b/lib/functorialisation.ml index 0703c0b3..dd4eb8e4 100644 --- a/lib/functorialisation.ml +++ b/lib/functorialisation.ml @@ -1,6 +1,6 @@ open Common open Kernel -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) exception FunctorialiseMeta @@ -10,8 +10,8 @@ module Memo = struct let tbl_whisk = Hashtbl.create 97 let find_whisk i f = - try Hashtbl.find tbl_whisk i with - | Not_found -> + try Hashtbl.find tbl_whisk i + with Not_found -> let res = f i in Hashtbl.add tbl_whisk i res; res @@ -19,13 +19,13 @@ end let rec next_round l = match l with - | [] -> [],[] - | (_,0)::l -> - let vars,left = next_round l in - vars, left - | (v,n)::l when n >= 1 -> - let vars,left = next_round l in - v::vars, (Var.Bridge v,n-1)::left + | [] -> ([], []) + | (_, 0) :: l -> + let vars, left = next_round l in + (vars, left) + | (v, n) :: l when n >= 1 -> + let vars, left = next_round l in + (v :: vars, (Var.Bridge v, n - 1) :: left) | _ -> Error.fatal "cannot functorialise a negative number of times." (* Functorialised coherences with respect to locally maximal variables are @@ -33,22 +33,18 @@ let rec next_round l = coherence that come from a functorialisation *) let compute_func_data l func = let incr_db v i = - match v with - | Var.Db k -> Var.Db (k+i) - | _ -> assert false + match v with Var.Db k -> Var.Db (k + i) | _ -> assert false in let rec add_in func v = match func with - | [] -> [((incr_db v 2),1)] - | (w,n)::func when v = w -> (incr_db v 2,n+1)::func - | (w,n)::func -> (incr_db w 2,n)::(add_in func v) + | [] -> [ (incr_db v 2, 1) ] + | (w, n) :: func when v = w -> (incr_db v 2, n + 1) :: func + | (w, n) :: func -> (incr_db w 2, n) :: add_in func v in let rec add_all func l = - match l with - | [] -> func - | v::l -> - add_all (add_in func v) l - in add_all func l + match l with [] -> func | v :: l -> add_all (add_in func v) l + in + add_all func l (* Given a context, a ps-substitution and a list of variables, returns @@ -56,30 +52,31 @@ let compute_func_data l func = in the substitution contains a variable from the input list *) let rec preimage ctx s l = - match ctx,s with + match (ctx, s) with | [], [] -> [] - | (x,_)::c,(t,_)::s when Unchecked.tm_contains_vars t l -> x::(preimage c s l) - | _::c, _::s -> preimage c s l - | [],_::_ | _::_,[] -> Error.fatal "functorialisation in a non-existant place" + | (x, _) :: c, (t, _) :: s when Unchecked.tm_contains_vars t l -> + x :: preimage c s l + | _ :: c, _ :: s -> preimage c s l + | [], _ :: _ | _ :: _, [] -> + Error.fatal "functorialisation in a non-existant place" let rec tgt_subst l = - match l with - | [] -> [] - | v::tl -> (v,Var(Var.Plus v))::(tgt_subst tl) + match l with [] -> [] | v :: tl -> (v, Var (Var.Plus v)) :: tgt_subst tl (* returns the n-composite of a (n+j)-cell with a (n+k)-cell *) let rec whisk n j k = let build_whisk t = - let n,j,k = t in + let n, j, k = t in let comp = Builtin.comp_n 2 in - let func_data = [(Var.Db 4, k);(Var.Db 2, j)] in + let func_data = [ (Var.Db 4, k); (Var.Db 2, j) ] in let whisk = match coh_successively comp func_data with - | Coh(c,_),_ -> c + | Coh (c, _), _ -> c | _ -> assert false - in Suspension.coh (Some n) whisk + in + Suspension.coh (Some n) whisk in - Memo.find_whisk (n,j,k) build_whisk + Memo.find_whisk (n, j, k) build_whisk (* How long should substitutions for whisk be? @@ -92,98 +89,99 @@ let rec whisk n j k = *) and whisk_sub_ps k t1 ty1 t2 ty2 = let rec take n l = - match l with - | h::t when n > 0 -> h::(take (n-1) t) - | _ -> [] in + match l with h :: t when n > 0 -> h :: take (n - 1) t | _ -> [] + in let sub_base = Unchecked.ty_to_sub_ps ty1 in - let sub_ext = take (2*k+1) (Unchecked.ty_to_sub_ps ty2) in - List.concat [[(t2,true)];sub_ext;[(t1,true)];sub_base] - + let sub_ext = take ((2 * k) + 1) (Unchecked.ty_to_sub_ps ty2) in + List.concat [ [ (t2, true) ]; sub_ext; [ (t1, true) ]; sub_base ] (* Invariant maintained: src_prod returns a term of same dimension as tm *) and src_prod t l tm tm_t d n = match t with - | Arr(ty',src,_tgt) when Unchecked.tm_contains_vars src l -> - let whisk = whisk n 0 (d-n-1) in - let _,whisk_ty,_ = Coh.forget whisk in - let prod, prod_ty = src_prod ty' l tm tm_t d (n-1) in - let ty_f = ty ty' l src in - let src_f = tm_one_step_tm src l in - let sub_ps = whisk_sub_ps (d-n-1) src_f ty_f prod prod_ty in - let sub = Unchecked.sub_ps_to_sub sub_ps in - (Coh(whisk, sub_ps), Unchecked.ty_apply_sub whisk_ty sub) - | Arr(_,_,_) | Obj -> (tm, tm_t) + | Arr (ty', src, _tgt) when Unchecked.tm_contains_vars src l -> + let whisk = whisk n 0 (d - n - 1) in + let _, whisk_ty, _ = Coh.forget whisk in + let prod, prod_ty = src_prod ty' l tm tm_t d (n - 1) in + let ty_f = ty ty' l src in + let src_f = tm_one_step_tm src l in + let sub_ps = whisk_sub_ps (d - n - 1) src_f ty_f prod prod_ty in + let sub = Unchecked.sub_ps_to_sub sub_ps in + (Coh (whisk, sub_ps), Unchecked.ty_apply_sub whisk_ty sub) + | Arr (_, _, _) | Obj -> (tm, tm_t) | _ -> raise FunctorialiseMeta + and tgt_prod t l tm tm_t d n = match t with - | Arr(ty',_src,tgt) when Unchecked.tm_contains_vars tgt l -> - let whisk = whisk n (d-n-1) 0 in - let _,whisk_ty,_ = Coh.forget whisk in - let prod, prod_ty = tgt_prod ty' l tm tm_t d (n-1) in - let ty_f = ty ty' l tgt in - let tgt_f = tm_one_step_tm tgt l in - let sub_ps = whisk_sub_ps 0 prod prod_ty tgt_f ty_f in - let sub = Unchecked.sub_ps_to_sub sub_ps in - (Coh(whisk, sub_ps), Unchecked.ty_apply_sub whisk_ty sub) - | Arr(_,_,_) | Obj -> (tm, tm_t) + | Arr (ty', _src, tgt) when Unchecked.tm_contains_vars tgt l -> + let whisk = whisk n (d - n - 1) 0 in + let _, whisk_ty, _ = Coh.forget whisk in + let prod, prod_ty = tgt_prod ty' l tm tm_t d (n - 1) in + let ty_f = ty ty' l tgt in + let tgt_f = tm_one_step_tm tgt l in + let sub_ps = whisk_sub_ps 0 prod prod_ty tgt_f ty_f in + let sub = Unchecked.sub_ps_to_sub sub_ps in + (Coh (whisk, sub_ps), Unchecked.ty_apply_sub whisk_ty sub) + | Arr (_, _, _) | Obj -> (tm, tm_t) | _ -> raise FunctorialiseMeta + and ty t l tm = let d = Unchecked.dim_ty t in let tgt_subst = tgt_subst l in let tm_incl = Unchecked.tm_apply_sub tm tgt_subst in let t_incl = Unchecked.ty_apply_sub t tgt_subst in - let src, src_t = tgt_prod t l tm t d (d-1) in - let tgt, _tgt_t = src_prod t l tm_incl t_incl d (d-1) in + let src, src_t = tgt_prod t l tm t d (d - 1) in + let tgt, _tgt_t = src_prod t l tm_incl t_incl d (d - 1) in Arr (src_t, src, tgt) and ctx c l = match c with | [] -> [] - | (x,(t,expl))::c when List.mem x l -> - let ty_tgt = Unchecked.ty_apply_sub t (tgt_subst l) in - let tf = ty t l (Var x) in - (Var.Bridge(x),(tf,expl))::(Var.Plus(x),(ty_tgt,false))::(x,(t,false))::(ctx c l) - | (x,a)::c -> (x,a)::(ctx c l) + | (x, (t, expl)) :: c when List.mem x l -> + let ty_tgt = Unchecked.ty_apply_sub t (tgt_subst l) in + let tf = ty t l (Var x) in + (Var.Bridge x, (tf, expl)) + :: (Var.Plus x, (ty_tgt, false)) + :: (x, (t, false)) + :: ctx c l + | (x, a) :: c -> (x, a) :: ctx c l - (* Functorialisation of a coherence once with respect to a list of - variables *) +(* Functorialisation of a coherence once with respect to a list of + variables *) and coh_depth0 coh l = - let ps,t,(name,susp,func) = Coh.forget coh in + let ps, t, (name, susp, func) = Coh.forget coh in let ctxf = ctx (Unchecked.ps_to_ctx ps) l in - let _,names,_ = Unchecked.db_levels ctxf in + let _, names, _ = Unchecked.db_levels ctxf in let psf = PS.forget (PS.mk (Ctx.check ctxf)) in - let ty = ty t l (Coh(coh,Unchecked.identity_ps ps)) in + let ty = ty t l (Coh (coh, Unchecked.identity_ps ps)) in let ty = Unchecked.rename_ty ty names in let func_data = compute_func_data l func in - check_coh psf ty (name,susp,func_data) + check_coh psf ty (name, susp, func_data) and coh coh l = - let ps,_,_ = Coh.forget coh in + let ps, _, _ = Coh.forget coh in let c = Unchecked.ps_to_ctx ps in - let depth0 = - List.for_all - (fun (x,(_,e)) -> (e || not(List.mem x l))) c - in - let cohf = if depth0 then - let id = Unchecked.identity_ps ps in - let sf = sub_ps id l in - let pscf = ctx (Unchecked.ps_to_ctx ps) l in - let cohf = coh_depth0 coh l in - Coh(cohf,sf), pscf + let depth0 = List.for_all (fun (x, (_, e)) -> e || not (List.mem x l)) c in + let cohf = + if depth0 then + let id = Unchecked.identity_ps ps in + let sf = sub_ps id l in + let pscf = ctx (Unchecked.ps_to_ctx ps) l in + let cohf = coh_depth0 coh l in + (Coh (cohf, sf), pscf) else !coh_depth1 coh l in cohf -and coh_successively c l = +and coh_successively c l = let l, next = next_round l in if l = [] then - let ps,_,_ = Coh.forget c in + let ps, _, _ = Coh.forget c in let id = Unchecked.identity_ps ps in - Coh(c,id), Unchecked.ps_to_ctx ps + (Coh (c, id), Unchecked.ps_to_ctx ps) else - let cohf,ctxf = coh c l in + let cohf, ctxf = coh c l in tm ctxf cohf next (* @@ -193,60 +191,55 @@ and coh_successively c l = *) and tm_one_step t l expl = match t with - | Var v -> [Var (Var.Bridge v), expl; Var (Var.Plus v), false; Var v, false] - | Coh(c,s) -> - begin + | Var v -> + [ (Var (Var.Bridge v), expl); (Var (Var.Plus v), false); (Var v, false) ] + | Coh (c, s) -> let t' = Unchecked.tm_apply_sub t (tgt_subst l) in let sf = sub_ps s l in - let ps,_,_ = Coh.forget c in + let ps, _, _ = Coh.forget c in let psc = Unchecked.ps_to_ctx ps in let places = preimage psc s l in - let cohf,pscf = coh c places in + let cohf, pscf = coh c places in let subf = Unchecked.list_to_sub (List.map fst sf) pscf in let tm = Unchecked.tm_apply_sub cohf subf in - [tm, expl; t', false; t, false] - end - | Meta_tm _ -> (raise FunctorialiseMeta) + [ (tm, expl); (t', false); (t, false) ] + | Meta_tm _ -> raise FunctorialiseMeta + and tm_one_step_tm t l = fst (List.hd (tm_one_step t l true)) + and sub_ps s l = match s with | [] -> [] - | (t, expl)::s -> - if (not (Unchecked.tm_contains_vars t l)) then (t,expl)::(sub_ps s l) - else - List.append - (tm_one_step t l expl) - (sub_ps s l) + | (t, expl) :: s -> + if not (Unchecked.tm_contains_vars t l) then (t, expl) :: sub_ps s l + else List.append (tm_one_step t l expl) (sub_ps s l) -and tm c t s = +and tm c t s = let l, next = next_round s in if l <> [] then let c = ctx c l in let t = tm_one_step_tm t l in tm c t next - else t,c + else (t, c) (* Functorialisation of a coherence: exposed function *) let coh c l = try coh c l - with - | FunctorialiseMeta -> + with FunctorialiseMeta -> Error.functorialisation ("coherence: " ^ Coh.to_string c) (Printf.sprintf "cannot functorialise meta-variables") let coh_depth0 c l = try coh_depth0 c l - with - | FunctorialiseMeta -> + with FunctorialiseMeta -> Error.functorialisation ("coherence: " ^ Coh.to_string c) (Printf.sprintf "cannot functorialise meta-variables") let coh_successively c l = try coh_successively c l - with - | FunctorialiseMeta -> + with FunctorialiseMeta -> Error.functorialisation ("coherence: " ^ Coh.to_string c) (Printf.sprintf "cannot functorialise meta-variables") @@ -254,24 +247,24 @@ let coh_successively c l = let rec sub s l = match s with | [] -> [] - | (x,t)::s when not (List.mem x l) -> (x,t)::(sub s l) - | (x,t)::s -> - match tm_one_step t l true with - | [(tm_f,_); (tgt_t,_); (src_t,_)] -> - (Var.Bridge x, tm_f)::(Var.Plus x, tgt_t)::(x,src_t)::(sub s l) - | [(t,_)] -> - Io.debug "no functorialisation needed for %s" (Var.to_string x); - (x,t)::(sub s l) - | _ -> assert false + | (x, t) :: s when not (List.mem x l) -> (x, t) :: sub s l + | (x, t) :: s -> ( + match tm_one_step t l true with + | [ (tm_f, _); (tgt_t, _); (src_t, _) ] -> + (Var.Bridge x, tm_f) :: (Var.Plus x, tgt_t) :: (x, src_t) :: sub s l + | [ (t, _) ] -> + Io.debug "no functorialisation needed for %s" (Var.to_string x); + (x, t) :: sub s l + | _ -> assert false) (* Functorialisation once with respect to every maximal argument *) let coh_all c = - let ps,_,_ = Coh.forget c in + let ps, _, _ = Coh.forget c in let ct = Unchecked.ps_to_ctx ps in let d = Unchecked.dim_ps ps in let l = List.filter_map - (fun (x,(ty,_)) -> if Unchecked.dim_ty ty = d then Some x else None) + (fun (x, (ty, _)) -> if Unchecked.dim_ty ty = d then Some x else None) ct in coh_depth0 c l @@ -279,19 +272,18 @@ let coh_all c = (* Functorialisation a term: exposed function *) let tm c t s = try tm c t s - with - | FunctorialiseMeta -> + with FunctorialiseMeta -> Error.functorialisation ("term: " ^ Unchecked.tm_to_string t) (Printf.sprintf "cannot functorialise meta-variables") let ps p l = let c = ctx (Unchecked.ps_to_ctx p) l in - let _,names,_ = Unchecked.db_levels c in - PS.(forget (mk (Ctx.check c))), names + let _, names, _ = Unchecked.db_levels c in + (PS.(forget (mk (Ctx.check c))), names) let sub_w_tgt p s l = let s_f = sub_ps s l in let l = preimage (Unchecked.ps_to_ctx p) s l in let p_f, names = ps p l in - s_f,p_f,names,l + (s_f, p_f, names, l) diff --git a/lib/functorialisation.mli b/lib/functorialisation.mli index 85b32661..4f06b9a6 100644 --- a/lib/functorialisation.mli +++ b/lib/functorialisation.mli @@ -2,11 +2,9 @@ open Common open Kernel open Unchecked_types.Unchecked_types(Coh) -val coh_depth1 : (Coh.t -> (Var.t list) -> tm * ctx) ref - -val preimage : ctx -> sub_ps -> (Var.t list) -> (Var.t list) -val tgt_subst : (Var.t list) -> sub - +val coh_depth1 : (Coh.t -> Var.t list -> tm * ctx) ref +val preimage : ctx -> sub_ps -> Var.t list -> Var.t list +val tgt_subst : Var.t list -> sub val coh : Coh.t -> Var.t list -> tm * ctx val coh_successively : Coh.t -> (Var.t * int) list -> tm * ctx val coh_depth0 : Coh.t -> Var.t list -> Coh.t @@ -16,8 +14,10 @@ val ty : ty -> Var.t list -> tm -> ty val ctx : ctx -> Var.t list -> ctx val sub_ps : sub_ps -> Var.t list -> sub_ps val tm : ctx -> tm -> (Var.t * int) list -> tm * ctx -val ps : ps -> Var.t list -> ps * (Var.t * int) list +val ps : ps -> Var.t list -> ps * (Var.t * int) list val sub : sub -> Var.t list -> sub -val sub_w_tgt : ps -> sub_ps -> Var.t list -> sub_ps * ps * (Var.t * int) list * Var.t list + +val sub_w_tgt : + ps -> sub_ps -> Var.t list -> sub_ps * ps * (Var.t * int) list * Var.t list val whisk_sub_ps : int -> tm -> ty -> tm -> ty -> sub_ps diff --git a/lib/inverse.ml b/lib/inverse.ml index cbbffecf..389a2fc8 100644 --- a/lib/inverse.ml +++ b/lib/inverse.ml @@ -1,265 +1,249 @@ open Common open Kernel -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) open Std exception NotInvertible of string exception CohNonInv let coh c = - if (not (Coh.is_inv c)) then raise CohNonInv; - let ps,ty,(name,susp,func) = Coh.forget c in - let ty_inv = match ty with + if not (Coh.is_inv c) then raise CohNonInv; + let ps, ty, (name, susp, func) = Coh.forget c in + let ty_inv = + match ty with | Obj | Meta_ty _ -> assert false - | Arr (a,u,v) -> Arr (a,v,u) + | Arr (a, u, v) -> Arr (a, v, u) in - check_coh ps ty_inv (name^"^-1",susp,func) + check_coh ps ty_inv (name ^ "^-1", susp, func) let rec compute_inverse t = match t with | Var x -> raise (NotInvertible (Var.to_string x)) | Meta_tm _ -> t - | Coh(c,sub) -> - try - Coh (coh c, sub) - with CohNonInv -> - let ps,_,_ = Coh.forget c in - let d = Unchecked.dim_ps ps in - let pctx = Unchecked.ps_to_ctx ps in - let sub = Unchecked.sub_ps_to_sub sub in - let sub_inv = sub_inv sub pctx d in - let equiv = Opposite.equiv_op_ps ps [d] in - let coh = Opposite.coh c [d] in - Coh(coh, Unchecked.sub_ps_apply_sub equiv sub_inv) + | Coh (c, sub) -> ( + try Coh (coh c, sub) + with CohNonInv -> + let ps, _, _ = Coh.forget c in + let d = Unchecked.dim_ps ps in + let pctx = Unchecked.ps_to_ctx ps in + let sub = Unchecked.sub_ps_to_sub sub in + let sub_inv = sub_inv sub pctx d in + let equiv = Opposite.equiv_op_ps ps [ d ] in + let coh = Opposite.coh c [ d ] in + Coh (coh, Unchecked.sub_ps_apply_sub equiv sub_inv)) + and sub_inv s ps i = - match s,ps with + match (s, ps) with | [], [] -> [] - | (x,t)::sub, (_,(ty,_))::ctx when Unchecked.dim_ty ty = i -> - (x,compute_inverse t)::(sub_inv sub ctx i) - | (x,t)::sub, _::ctx -> - (x,t)::(sub_inv sub ctx i) - | _,_ -> assert false + | (x, t) :: sub, (_, (ty, _)) :: ctx when Unchecked.dim_ty ty = i -> + (x, compute_inverse t) :: sub_inv sub ctx i + | (x, t) :: sub, _ :: ctx -> (x, t) :: sub_inv sub ctx i + | _, _ -> assert false let compute_inverse t = - try compute_inverse t with - | NotInvertible s -> - Error.inversion - ("term: " ^ (Unchecked.tm_to_string t)) - (Printf.sprintf "term %s is not invertible" s) + try compute_inverse t + with NotInvertible s -> + Error.inversion + ("term: " ^ Unchecked.tm_to_string t) + (Printf.sprintf "term %s is not invertible" s) let group_vertically ps t src_t tgt_t = - let coh_unbiased = Coh.check_noninv ps src_t tgt_t ("unbiased_comp",0,[]) in + let coh_unbiased = Coh.check_noninv ps src_t tgt_t ("unbiased_comp", 0, []) in let coh_vertically_grouped = Ps_reduction.coh coh_unbiased in let reduce = Ps_reduction.reduction_sub ps in - let t_vertically_grouped = Coh(coh_vertically_grouped, reduce) in - Coh.check_inv ps t t_vertically_grouped ("vertical_grouping",0,[]) + let t_vertically_grouped = Coh (coh_vertically_grouped, reduce) in + Coh.check_inv ps t t_vertically_grouped ("vertical_grouping", 0, []) -type lin_comp = {arity: int; dim: int; sub_ps: sub_ps} +type lin_comp = { arity : int; dim : int; sub_ps : sub_ps } let tm_to_lin_comp t = - let ps,sub_ps = match t with - | Coh (c,s) -> let ps,_,_ = Coh.forget c in ps, s + let ps, sub_ps = + match t with + | Coh (c, s) -> + let ps, _, _ = Coh.forget c in + (ps, s) | _ -> Error.fatal "term must be a linear composite" in let dim = Unchecked.dim_ps ps in let rec arity i ps = - match i,ps with + match (i, ps) with | 0, Br l -> List.length l - | _, Br [Br l] -> arity (i-1) (Br l) + | _, Br [ Br l ] -> arity (i - 1) (Br l) | _ -> Error.fatal "term must be a linear composite" in - {arity = arity (dim - 1) ps; dim; sub_ps} + { arity = arity (dim - 1) ps; dim; sub_ps } let rec cancel_linear_comp lc = let k = lc.arity / 2 in let rec sub_to_telescope i sub invs = - match i, sub, invs with - | 0,s,_ -> (List.map fst s) - | i, (t,_):: _::s, invs when i > k -> - sub_to_telescope (i-1) s (t::invs) - | i,(t,_)::(x,_)::s, t_inv::invs -> - (compute_witness t):: - t_inv:: - t:: - x:: - (sub_to_telescope (i-1) s invs) - |_,_,_ -> Error.fatal "term must be a linear composite" + match (i, sub, invs) with + | 0, s, _ -> List.map fst s + | i, (t, _) :: _ :: s, invs when i > k -> + sub_to_telescope (i - 1) s (t :: invs) + | i, (t, _) :: (x, _) :: s, t_inv :: invs -> + compute_witness t :: t_inv :: t :: x :: sub_to_telescope (i - 1) s invs + | _, _, _ -> Error.fatal "term must be a linear composite" in let tel = Telescope.telescope k in let ctel = Telescope.ctx k in - let - stel = + let stel = Unchecked.list_to_sub - (sub_to_telescope (2*k) lc.sub_ps []) - (Suspension.ctx (Some (lc.dim-1)) ctel) + (sub_to_telescope (2 * k) lc.sub_ps []) + (Suspension.ctx (Some (lc.dim - 1)) ctel) in - Unchecked.tm_apply_sub (Suspension.tm (Some (lc.dim-1)) tel) stel + Unchecked.tm_apply_sub (Suspension.tm (Some (lc.dim - 1)) tel) stel and cancel_all_linear_comp t = - let c,sub = - match t with - | Coh(c,sub) -> c,sub - | _ -> Error.fatal "" - in - let ps,_,_ = Coh.forget c in + let c, sub = match t with Coh (c, sub) -> (c, sub) | _ -> Error.fatal "" in + let ps, _, _ = Coh.forget c in let d = Unchecked.dim_ps ps in let rec compute_sub i ps sub ty_base = - match ps,sub with - | Br [], [t] -> [t] - | Br [Br[]], (t,_)::(_,_)::(src_t,_)::sub when i = d-1 -> - let t_wit = cancel_linear_comp (tm_to_lin_comp t) in - let id_src_t = - let sub_base = Unchecked.ty_to_sub_ps ty_base in - let id = Suspension.coh (Some (Unchecked.dim_ty ty_base)) Builtin.id in - Coh(id, (src_t,true)::sub_base) - in - (t_wit, true):: - (id_src_t, false):: - (t,false):: - (src_t,false):: - (src_t,false):: - sub + match (ps, sub) with + | Br [], [ t ] -> [ t ] + | Br [ Br [] ], (t, _) :: (_, _) :: (src_t, _) :: sub when i = d - 1 -> + let t_wit = cancel_linear_comp (tm_to_lin_comp t) in + let id_src_t = + let sub_base = Unchecked.ty_to_sub_ps ty_base in + let id = + Suspension.coh (Some (Unchecked.dim_ty ty_base)) Builtin.id + in + Coh (id, (src_t, true) :: sub_base) + in + (t_wit, true) :: (id_src_t, false) :: (t, false) :: (src_t, false) + :: (src_t, false) :: sub | Br l, sub -> - let incls = Unchecked.canonical_inclusions l in - let sub = Unchecked.sub_ps_to_sub sub in - let lsubs = - (List.map2 - (fun p incl -> - let s = Unchecked.(sub_ps_to_sub_ps_bp - (sub_ps_apply_sub incl sub)) + let incls = Unchecked.canonical_inclusions l in + let sub = Unchecked.sub_ps_to_sub sub in + let lsubs = + List.map2 + (fun p incl -> + let s = + Unchecked.(sub_ps_to_sub_ps_bp (sub_ps_apply_sub incl sub)) in - {Unchecked.sub_ps = - compute_sub (i+1) p s.sub_ps (Arr(ty_base,s.l,s.r)); - l = s.l; - r = s.r}) - l incls) - in - Unchecked.wedge_sub_ps_bp lsubs + { + Unchecked.sub_ps = + compute_sub (i + 1) p s.sub_ps (Arr (ty_base, s.l, s.r)); + l = s.l; + r = s.r; + }) + l incls + in + Unchecked.wedge_sub_ps_bp lsubs in - Coh(Functorialisation.coh_all c,compute_sub 0 ps sub Obj) + Coh (Functorialisation.coh_all c, compute_sub 0 ps sub Obj) -and compute_witness t = +and compute_witness t = match t with | Var x -> raise (NotInvertible (Var.to_string x)) | Meta_tm _ -> - raise (NotInvertible "Meta_variable not allowed in witness generation") - | Coh(c,s) -> - let ps,ty,pp_data = Coh.forget c in - let d = Coh.dim c in - let sub_base,u,v = - match ty with - | Arr(ty,u,v) -> Unchecked.ty_to_sub_ps ty, u, v - | _ -> Error.fatal "invertible coherence has to be an arrow type" - in - if Coh.is_inv c then - compute_witness_coh_inv c s ~ps ~d ~pp_data ~sub_base ~u ~v - else - compute_witness_comp c s ~ps ~d ~sub_base ~u ~v + raise (NotInvertible "Meta_variable not allowed in witness generation") + | Coh (c, s) -> + let ps, ty, pp_data = Coh.forget c in + let d = Coh.dim c in + let sub_base, u, v = + match ty with + | Arr (ty, u, v) -> (Unchecked.ty_to_sub_ps ty, u, v) + | _ -> Error.fatal "invertible coherence has to be an arrow type" + in + if Coh.is_inv c then + compute_witness_coh_inv c s ~ps ~d ~pp_data ~sub_base ~u ~v + else compute_witness_comp c s ~ps ~d ~sub_base ~u ~v and compute_witness_coh_inv c s ~ps ~pp_data ~d ~sub_base ~u ~v = - let name,susp,func = pp_data in + let name, susp, func = pp_data in let src_wit = let id_ps = Unchecked.identity_ps ps in let c_inv = coh c in let comp = Suspension.coh (Some (d - 1)) (Builtin.comp_n 2) in let c_c_inv = - (Coh(c_inv, id_ps),true):: - (u,false):: - (Coh(c,id_ps),true):: - (v,true):: - (u,true):: - sub_base + (Coh (c_inv, id_ps), true) + :: (u, false) + :: (Coh (c, id_ps), true) + :: (v, true) :: (u, true) :: sub_base in - Coh(comp, c_c_inv) + Coh (comp, c_c_inv) in let tgt_wit = - let id = Suspension.coh (Some (d-1)) Builtin.id in - let sub_id_u = (u,true)::sub_base in - Coh(id, sub_id_u) + let id = Suspension.coh (Some (d - 1)) Builtin.id in + let sub_id_u = (u, true) :: sub_base in + Coh (id, sub_id_u) in - let - c_wit = Coh.check_inv ps src_wit tgt_wit (name^"_Unit",susp,func) - in - Coh(c_wit,s) + let c_wit = Coh.check_inv ps src_wit tgt_wit (name ^ "_Unit", susp, func) in + Coh (c_wit, s) and compute_witness_comp c s ~ps ~d ~sub_base ~u ~v = - let ps_doubled, inl, inr = Unchecked.ps_compose (d-1) ps ps in + let ps_doubled, inl, inr = Unchecked.ps_compose (d - 1) ps ps in let t = - let tm1 = Coh(c,inl) in - let c_op = Opposite.coh c [d] in - let tm2 = Coh(c_op, inr) in + let tm1 = Coh (c, inl) in + let c_op = Opposite.coh c [ d ] in + let tm2 = Coh (c_op, inr) in let sub_inr = Unchecked.sub_ps_to_sub inr in let sub_inl = Unchecked.sub_ps_to_sub inl in - let w = match Coh.forget c_op with - | _,Arr(_,_,v),_ -> - Unchecked.tm_apply_sub v sub_inr + let w = + match Coh.forget c_op with + | _, Arr (_, _, v), _ -> Unchecked.tm_apply_sub v sub_inr | _ -> Error.fatal "coherence must have an arrow type" in - let comp = Suspension.coh (Some (d-1)) (Builtin.comp_n 2) in - Coh(comp, - (tm2,true):: - (w,false):: - (tm1,true):: - (Unchecked.sub_ps_apply_sub ((v,false)::(u,false)::sub_base) sub_inl)) + let comp = Suspension.coh (Some (d - 1)) (Builtin.comp_n 2) in + Coh + ( comp, + (tm2, true) :: (w, false) :: (tm1, true) + :: Unchecked.sub_ps_apply_sub + ((v, false) :: (u, false) :: sub_base) + sub_inl ) in let ps_reduced = Ps_reduction.reduce (Unchecked.dim_ps ps_doubled - 1) ps_doubled in - let src_c,_,_ = Coh.noninv_srctgt c in + let src_c, _, _ = Coh.noninv_srctgt c in let cps = Unchecked.ps_to_ctx ps in let sub = Unchecked.sub_ps_to_sub s in - let m1,src_m1,tgt_m1 = + let m1, src_m1, tgt_m1 = let coh = group_vertically ps_doubled t src_c src_c in - let src,tgt = + let src, tgt = match Coh.forget coh with - | _,Arr(_,src,tgt),_ -> src,tgt + | _, Arr (_, src, tgt), _ -> (src, tgt) | _ -> Error.fatal "coherence must be of arrow type" in - let - sinv = - (Unchecked.sub_ps_apply_sub - (Opposite.equiv_op_ps ps [d]) - (sub_inv sub cps d)) + let sinv = + Unchecked.sub_ps_apply_sub + (Opposite.equiv_op_ps ps [ d ]) + (sub_inv sub cps d) in - let ssinv = Unchecked.pullback_up (d-1) ps ps s sinv in + let ssinv = Unchecked.pullback_up (d - 1) ps ps s sinv in let subsinv = Unchecked.sub_ps_to_sub ssinv in - Coh(coh,ssinv), - Unchecked.tm_apply_sub src subsinv, - Unchecked.tm_apply_sub tgt subsinv + ( Coh (coh, ssinv), + Unchecked.tm_apply_sub src subsinv, + Unchecked.tm_apply_sub tgt subsinv ) in let m2 = cancel_all_linear_comp tgt_m1 in - let m3,src_m3,tgt_m3 = - let coh= Builtin.unbiased_unitor ps_reduced src_c in - let src,tgt = + let m3, src_m3, tgt_m3 = + let coh = Builtin.unbiased_unitor ps_reduced src_c in + let src, tgt = match Coh.forget coh with - | _,Arr(_,src,tgt),_ -> src,tgt + | _, Arr (_, src, tgt), _ -> (src, tgt) | _ -> Error.fatal "coherence must be of arrow type" in let s = Unchecked.sub_ps_apply_sub (Unchecked.ps_src ps) sub in let sub = Unchecked.sub_ps_to_sub s in - Coh(coh,s), - Unchecked.tm_apply_sub src sub, - Unchecked.tm_apply_sub tgt sub + ( Coh (coh, s), + Unchecked.tm_apply_sub src sub, + Unchecked.tm_apply_sub tgt sub ) in let sub_total = - (m3, true):: - (tgt_m3, false):: - (m2, true):: - (src_m3, false):: - (m1, true):: - (tgt_m1, false):: - (src_m1, false):: - (Unchecked.sub_ps_apply_sub ((u,false)::(u,false)::sub_base) sub) + (m3, true) :: (tgt_m3, false) :: (m2, true) :: (src_m3, false) :: (m1, true) + :: (tgt_m1, false) :: (src_m1, false) + :: Unchecked.sub_ps_apply_sub ((u, false) :: (u, false) :: sub_base) sub in - Coh(Suspension.coh (Some d) (Builtin.comp_n 3), sub_total) + Coh (Suspension.coh (Some d) (Builtin.comp_n 3), sub_total) let compute_witness t = - try let r = compute_witness t in - Io.info ~v:3 - (lazy - (Printf.sprintf "inverse term: %s" - (Unchecked.tm_to_string r))); - r - with - | NotInvertible s -> Error.inversion ("term: " ^ (Unchecked.tm_to_string t)) - (Printf.sprintf "term %s is not invertible" s) + try + let r = compute_witness t in + Io.info ~v:3 + (lazy (Printf.sprintf "inverse term: %s" (Unchecked.tm_to_string r))); + r + with NotInvertible s -> + Error.inversion + ("term: " ^ Unchecked.tm_to_string t) + (Printf.sprintf "term %s is not invertible" s) diff --git a/lib/io.ml b/lib/io.ml index 5458ce76..4ec37062 100644 --- a/lib/io.ml +++ b/lib/io.ml @@ -1,15 +1,12 @@ -let print_string_fun = ref print_string -let print_string s = !print_string_fun s -let print_newline () = print_string "\n" -let print_endline s = print_string s; print_newline () -let read_line_fun = ref read_line -let read_lin () = !read_line_fun () - let printf e = Printf.printf e let eprintf e = Printf.eprintf e -let debug e = Printf.ksprintf (fun s -> printf "[=D.D=] %s\n\n%!" s) e +let debug e = Printf.ksprintf (fun s -> Printf.printf "[=D.D=] %s\n\n%!" s) e + let info ?(v = 0) e = if !Settings.verbosity >= v then - printf "[=I.I=] %s.\n%!" (Lazy.force e) -let command e = Printf.ksprintf (fun s -> printf "[=^.^=] %s\n%!" s) e -let error e = Printf.ksprintf (fun s -> eprintf "\027[1;91m[=X.X=] %s\n\027[0m%!" s) e + print_string (Printf.sprintf "[=I.I=] %s.\n%!" (Lazy.force e)) + +let command e = Printf.ksprintf (fun s -> Printf.printf "[=^.^=] %s\n%!" s) e + +let error e = + Printf.ksprintf (fun s -> eprintf "\027[1;91m[=X.X=] %s\n\027[0m%!" s) e diff --git a/lib/io.mli b/lib/io.mli index a9ab3097..de5219a8 100644 --- a/lib/io.mli +++ b/lib/io.mli @@ -1,8 +1,3 @@ -val print_string_fun : (string -> unit) ref -val print_newline : unit -> unit -val print_endline : string -> unit -val read_line_fun : (unit -> string) ref -val read_lin : unit -> string val printf : ('a, out_channel, unit) format -> 'a val eprintf : ('a, out_channel, unit) format -> 'a val debug : ('a, unit, string, unit) format4 -> 'a diff --git a/lib/kernel.ml b/lib/kernel.ml index 3c77e7a0..76c69edc 100644 --- a/lib/kernel.ml +++ b/lib/kernel.ml @@ -9,63 +9,64 @@ exception InvalidSubTarget of string * string exception MetaVariable (** Operations on substitutions. *) -module rec Sub - : sig - type t - val check_to_ps : Ctx.t -> Unchecked_types(Coh).sub_ps -> PS.t -> t - val forget : t -> Unchecked_types(Coh).sub - val free_vars : t -> Var.t list - val src : t -> Ctx.t - val tgt : t -> Ctx.t - end -= struct - type t = {list : Tm.t list; - src : Ctx.t; - tgt : Ctx.t; - unchecked : Unchecked_types(Coh).sub} +module rec Sub : sig + type t + + val check_to_ps : Ctx.t -> Unchecked_types(Coh).sub_ps -> PS.t -> t + val forget : t -> Unchecked_types(Coh).sub + val free_vars : t -> Var.t list + val src : t -> Ctx.t + val tgt : t -> Ctx.t +end = struct + type t = { + list : Tm.t list; + src : Ctx.t; + tgt : Ctx.t; + unchecked : Unchecked_types(Coh).sub; + } let src s = s.src let tgt s = s.tgt - open Unchecked(Coh) - module Unchecked = Make(Coh) + open Unchecked (Coh) + module Unchecked = Make (Coh) - let free_vars s = - List.concat (List.map Tm.free_vars s.list) + let free_vars s = List.concat (List.map Tm.free_vars s.list) let check src s tgt = Io.info ~v:5 (lazy (Printf.sprintf - "building kernel substitution \ - : source = %s; substitution = %s; target = %s" + "building kernel substitution : source = %s; substitution = %s; \ + target = %s" (Ctx.to_string src) (Unchecked.sub_to_string s) (Ctx.to_string tgt))); - let - sub_exn = InvalidSubTarget(Unchecked.sub_to_string s, Ctx.to_string tgt) + let sub_exn = + InvalidSubTarget (Unchecked.sub_to_string s, Ctx.to_string tgt) in let rec aux src s tgt = let expr s tgt = - match s, Ctx.value tgt with + match (s, Ctx.value tgt) with | [], [] -> [] - | (_::_,[] |[],_::_) -> raise sub_exn - | (x1,_)::_, (x2,_)::_ when x1 <> x2 -> raise sub_exn - | (_,t)::s, (_,a)::_ -> - let sub = aux src s (Ctx.tail tgt) in - let t = Tm.check src t in - Ty.check_equal (Tm.typ t) (Ty.apply_sub a sub); - t::sub.list + | _ :: _, [] | [], _ :: _ -> raise sub_exn + | (x1, _) :: _, (x2, _) :: _ when x1 <> x2 -> raise sub_exn + | (_, t) :: s, (_, a) :: _ -> + let sub = aux src s (Ctx.tail tgt) in + let t = Tm.check src t in + Ty.check_equal (Tm.typ t) (Ty.apply_sub a sub); + t :: sub.list in - {list = expr s tgt; src; tgt; unchecked = s} + { list = expr s tgt; src; tgt; unchecked = s } in aux src s tgt let check_to_ps src s tgt = let tgt = PS.to_ctx tgt in let s = - try List.map2 (fun (x,_) (t,_) -> (x,t)) (Ctx.value tgt) s - with Invalid_argument _ -> Error.fatal "uncaught wrong number of arguments" + try List.map2 (fun (x, _) (t, _) -> (x, t)) (Ctx.value tgt) s + with Invalid_argument _ -> + Error.fatal "uncaught wrong number of arguments" in check src s tgt @@ -73,43 +74,42 @@ module rec Sub end (** A context, associating a type to each context variable. *) -and Ctx - : sig - type t - val empty : unit -> t - val tail : t -> t - val to_string : t -> string - val ty_var : t -> Var.t -> Ty.t - val domain : t -> Var.t list - val value : t -> (Var.t * Ty.t) list - val extend : t -> expl:bool -> Var.t -> Unchecked_types(Coh).ty -> t - val forget : t -> Unchecked_types(Coh).ctx - val check : Unchecked_types(Coh).ctx -> t - val check_notin : t -> Var.t -> unit - val check_equal : t -> t -> unit - end = struct - type t = {c : (Var.t * Ty.t) list; - unchecked : Unchecked_types(Coh).ctx} - - open Unchecked(Coh) - module Unchecked = Make(Coh) +and Ctx : sig + type t + + val empty : unit -> t + val tail : t -> t + val to_string : t -> string + val ty_var : t -> Var.t -> Ty.t + val domain : t -> Var.t list + val value : t -> (Var.t * Ty.t) list + val extend : t -> expl:bool -> Var.t -> Unchecked_types(Coh).ty -> t + val forget : t -> Unchecked_types(Coh).ctx + val check : Unchecked_types(Coh).ctx -> t + val check_notin : t -> Var.t -> unit + val check_equal : t -> t -> unit +end = struct + type t = { c : (Var.t * Ty.t) list; unchecked : Unchecked_types(Coh).ctx } + + open Unchecked (Coh) + module Unchecked = Make (Coh) let tail ctx = - match ctx.c, ctx.unchecked with - | [],(_::_|[]) -> Error.fatal "computing tail of an empty context" - | _::_,[] -> Error.fatal "safe and unchecked context out of sync" - | _::c,_::unchecked -> {c;unchecked} + match (ctx.c, ctx.unchecked) with + | [], (_ :: _ | []) -> Error.fatal "computing tail of an empty context" + | _ :: _, [] -> Error.fatal "safe and unchecked context out of sync" + | _ :: c, _ :: unchecked -> { c; unchecked } let ty_var ctx x = try List.assoc x ctx.c with Not_found -> raise (Error.UnknownId (Var.to_string x)) - let empty () = {c = []; unchecked = []} - + let empty () = { c = []; unchecked = [] } let domain ctx = List.map fst ctx.c let value ctx = ctx.c let forget c = c.unchecked let to_string ctx = Unchecked.ctx_to_string (forget ctx) + let check_equal ctx1 ctx2 = Unchecked.check_equal_ctx (forget ctx1) (forget ctx2) @@ -122,18 +122,23 @@ and Ctx let extend ctx ~expl x t = let ty = Ty.check ctx t in Ctx.check_notin ctx x; - {c = (x,ty)::(Ctx.value ctx); unchecked = (x, (t,expl))::(Ctx.forget ctx)} + { + c = (x, ty) :: Ctx.value ctx; + unchecked = (x, (t, expl)) :: Ctx.forget ctx; + } let check c = List.fold_right - (fun (x,(t,expl)) c -> Ctx.extend ~expl c x t ) - c - (Ctx.empty ()) + (fun (x, (t, expl)) c -> Ctx.extend ~expl c x t) + c (Ctx.empty ()) end (** Operations on pasting schemes. *) and PS : sig + exception Invalid + type t + val to_string : t -> string val mk : Ctx.t -> t val to_ctx : t -> Ctx.t @@ -142,12 +147,11 @@ and PS : sig val target : t -> Sub.t val forget : t -> ps val check_equal : t -> t -> unit -end -= -struct +end = struct exception Invalid - open Unchecked(Coh) - module Unchecked = Make(Coh) + + open Unchecked (Coh) + module Unchecked = Make (Coh) (** A pasting scheme. *) type ps_derivation = @@ -155,43 +159,45 @@ struct | PCons of ps_derivation * (Var.t * Ty.t) * (Var.t * Ty.t) | PDrop of ps_derivation - type t = { tree : ps; ctx : Ctx.t} + type t = { tree : ps; ctx : Ctx.t } - (** Create a context from a pasting scheme. *) (* TODO:fix level of explicitness here *) + + (** Create a context from a pasting scheme. *) let old_rep_to_ctx ps = let rec list ps = match ps with - |PDrop ps -> list ps - |PCons (ps,(x1,t1),(x2,t2)) -> - (x2,(Ty.forget t2, true))::(x1,(Ty.forget t1, true))::(list ps) - |PNil (x,t) -> [(x,(Ty.forget t, true))] - in Ctx.check (list ps) + | PDrop ps -> list ps + | PCons (ps, (x1, t1), (x2, t2)) -> + (x2, (Ty.forget t2, true)) :: (x1, (Ty.forget t1, true)) :: list ps + | PNil (x, t) -> [ (x, (Ty.forget t, true)) ] + in + Ctx.check (list ps) (** Dangling variable. *) let rec marker (ps : ps_derivation) = match ps with - | PNil (x,t) -> x,t - | PCons (_,_,f) -> f + | PNil (x, t) -> (x, t) + | PCons (_, _, f) -> f | PDrop ps -> - let _,tf = marker ps in - let v = try Ty.target tf with IsObj -> raise Invalid in - let y = try Tm.to_var v with IsCoh -> raise Invalid in - let t = - let rec aux = function - | PNil (x,t) -> assert (x = y); t - | PCons (ps,(y',ty),(f,tf)) -> - if y' = y then ty - else if f = y then tf - else aux ps - | PDrop ps -> aux ps + let _, tf = marker ps in + let v = try Ty.target tf with IsObj -> raise Invalid in + let y = try Tm.to_var v with IsCoh -> raise Invalid in + let t = + let rec aux = function + | PNil (x, t) -> + assert (x = y); + t + | PCons (ps, (y', ty), (f, tf)) -> + if y' = y then ty else if f = y then tf else aux ps + | PDrop ps -> aux ps + in + aux ps in - aux ps - in - y,t + (y, t) (** Create a pasting scheme from a context. *) - let make_old (l : Ctx.t) = + let make_old (l : Ctx.t) = let rec close ps tx = if Ty.is_obj tx then ps else @@ -199,86 +205,81 @@ struct close (PDrop ps) tx in let build l = - let x0,ty,l = + let x0, ty, l = match l with - | (x,ty)::l when Ty.is_obj ty -> x,ty,l + | (x, ty) :: l when Ty.is_obj ty -> (x, ty, l) | _ -> raise Invalid in let rec aux ps = function - | ((y,ty)::(f,tf)::l) as l1 -> - begin - let _,u,v = + | (y, ty) :: (f, tf) :: l as l1 -> + let _, u, v = try Ty.retrieve_arrow tf with IsObj -> raise Invalid in - let fx,fy = - try Tm.to_var u, Tm.to_var v with IsCoh -> raise Invalid + let fx, fy = + try (Tm.to_var u, Tm.to_var v) with IsCoh -> raise Invalid in - if (y <> fy) then raise Invalid; - let x,_ = marker ps in - if x = fx then + if y <> fy then raise Invalid; + let x, _ = marker ps in + if x = fx then ( let varps = Ctx.domain (old_rep_to_ctx ps) in - if (List.mem f varps) then - raise (DoubledVar (Var.to_string f)); - if (List.mem y varps) then - raise (DoubledVar (Var.to_string y)); - let ps = PCons (ps,(y,ty),(f,tf)) in - aux ps l - else - aux (PDrop ps) l1 - end - | [_,_] -> raise Invalid + if List.mem f varps then raise (DoubledVar (Var.to_string f)); + if List.mem y varps then raise (DoubledVar (Var.to_string y)); + let ps = PCons (ps, (y, ty), (f, tf)) in + aux ps l) + else aux (PDrop ps) l1 + | [ (_, _) ] -> raise Invalid | [] -> - let _,tx = marker ps in close ps tx + let _, tx = marker ps in + close ps tx in - aux (PNil (x0,ty)) l - in build (List.rev (Ctx.value l)) + aux (PNil (x0, ty)) l + in + build (List.rev (Ctx.value l)) (* assumes that all ps are completed with enough PDrop in the end *) let make_tree ps = let rec find_previous ps list = match ps with | PNil x -> (Br list, PNil x) - | PCons (ps,_,_) -> (Br list, ps) + | PCons (ps, _, _) -> (Br list, ps) | PDrop _ as ps -> - let p,ps = build_till_previous ps in - Br p, ps + let p, ps = build_till_previous ps in + (Br p, ps) and build_till_previous ps = match ps with - | PNil x -> [], PNil x - | PCons (ps,_,_) -> [], ps + | PNil x -> ([], PNil x) + | PCons (ps, _, _) -> ([], ps) | PDrop ps -> - let p,ps = find_previous ps [] in - let prev,ps = build_till_previous ps in - p::prev, ps + let p, ps = find_previous ps [] in + let prev, ps = build_till_previous ps in + (p :: prev, ps) in Br (fst (build_till_previous ps)) let mk (l : Ctx.t) = let oldrep = make_old l in - {tree = make_tree oldrep; ctx = l} + { tree = make_tree oldrep; ctx = l } let forget ps = ps.tree - let to_string ps = Unchecked.ps_to_string (forget ps) (** Create a context from a pasting scheme. *) - let to_ctx ps = - ps.ctx + let to_ctx ps = ps.ctx - let bdry ps = - (mk (Ctx.check (Unchecked.ps_to_ctx (Unchecked.ps_bdry ps.tree)))) + let bdry ps = mk (Ctx.check (Unchecked.ps_to_ctx (Unchecked.ps_bdry ps.tree))) let source ps = Sub.check_to_ps (to_ctx ps) (Unchecked.ps_src ps.tree) (bdry ps) + let target ps = Sub.check_to_ps (to_ctx ps) (Unchecked.ps_tgt ps.tree) (bdry ps) - let check_equal ps1 ps2 = - Unchecked.check_equal_ps ps1.tree ps2.tree + let check_equal ps1 ps2 = Unchecked.check_equal_ps ps1.tree ps2.tree end and Ty : sig type t + val to_string : t -> string val free_vars : t -> Var.t list val is_full : t -> bool @@ -288,69 +289,54 @@ and Ty : sig val forget : t -> Unchecked_types(Coh).ty val check : Ctx.t -> Unchecked_types(Coh).ty -> t val apply_sub : t -> Sub.t -> t - val retrieve_arrow : t -> (t * Tm.t * Tm.t) + val retrieve_arrow : t -> t * Tm.t * Tm.t val under_type : t -> t val target : t -> Tm.t val ctx : t -> Ctx.t val dim : t -> int - -end -= -struct +end = struct (** A type exepression. *) - type expr = - | Obj - | Arr of t * Tm.t * Tm.t - and t = {c : Ctx.t; e : expr; unchecked : Unchecked_types(Coh).ty} + type expr = Obj | Arr of t * Tm.t * Tm.t - open Unchecked(Coh) - module Unchecked = Make(Coh) + and t = { c : Ctx.t; e : expr; unchecked : Unchecked_types(Coh).ty } - let is_obj t = (t.e = Obj) + open Unchecked (Coh) + module Unchecked = Make (Coh) - let retrieve_arrow ty = - match ty.e with - | Obj -> raise IsObj - | Arr(a,u,v) -> a,u,v + let is_obj t = t.e = Obj - let under_type ty = - match ty.e with - | Obj -> raise IsObj - | Arr(a,_,_) -> a + let retrieve_arrow ty = + match ty.e with Obj -> raise IsObj | Arr (a, u, v) -> (a, u, v) - let target ty = - match ty.e with - | Obj -> raise IsObj - | Arr(_,_,v) -> v + let under_type ty = match ty.e with Obj -> raise IsObj | Arr (a, _, _) -> a + let target ty = match ty.e with Obj -> raise IsObj | Arr (_, _, v) -> v let rec check c t = Io.info ~v:5 (lazy - (Printf.sprintf - "building kernel type %s in context %s" - (Unchecked.ty_to_string t) - (Ctx.to_string c))); + (Printf.sprintf "building kernel type %s in context %s" + (Unchecked.ty_to_string t) (Ctx.to_string c))); let e = match t with | Obj -> Obj - | Arr(a,u,v) -> - let a = check c a in - let u = Tm.check c ~ty:a u in - let v = Tm.check c ~ty:a v in - Arr(a,u,v) + | Arr (a, u, v) -> + let a = check c a in + let u = Tm.check c ~ty:a u in + let v = Tm.check c ~ty:a v in + Arr (a, u, v) | Meta_ty _ -> raise MetaVariable - in {c; e; unchecked = t} + in + { c; e; unchecked = t } (** Free variables of a type. *) let rec free_vars ty = match ty.e with | Obj -> [] - | Arr (t,u,v) -> List.unions [free_vars t; Tm.free_vars u; Tm.free_vars v] + | Arr (t, u, v) -> + List.unions [ free_vars t; Tm.free_vars u; Tm.free_vars v ] let is_full t = List.included (Ctx.domain t.c) (free_vars t) - let forget t = t.unchecked - let to_string ty = Unchecked.ty_to_string (forget ty) (** Test for equality. *) @@ -362,24 +348,24 @@ struct let a1 = Tm.ty t1 in let a2 = Tm.ty t2 in check_equal a1 a2; - {c=a1.c; e=Arr(a1,t1,t2); - unchecked = Arr(forget a1, Tm.forget t1, Tm.forget t2)} + { + c = a1.c; + e = Arr (a1, t1, t2); + unchecked = Arr (forget a1, Tm.forget t1, Tm.forget t2); + } let apply_sub t s = Ctx.check_equal t.c (Sub.tgt s); check (Sub.src s) (Unchecked.ty_apply_sub (forget t) (Sub.forget s)) let ctx t = t.c - - let rec dim t = - match t.e with - | Obj -> 0 - | Arr(a,_,_) -> 1 + dim a + let rec dim t = match t.e with Obj -> 0 | Arr (a, _, _) -> 1 + dim a end (** Operations on terms. *) and Tm : sig type t + val to_var : t -> Var.t val typ : t -> Ty.t val free_vars : t -> Var.t list @@ -389,55 +375,45 @@ and Tm : sig val apply_sub : t -> Sub.t -> t val preimage : t -> Sub.t -> t val ty : t -> Ty.t -end -= -struct - type expr = - | Var of Var.t (** a context variable *) - | Coh of Coh.t * Sub.t - and t = {ty : Ty.t; e : expr; unchecked : Unchecked_types(Coh).tm} +end = struct + type expr = Var of Var.t (** a context variable *) | Coh of Coh.t * Sub.t + and t = { ty : Ty.t; e : expr; unchecked : Unchecked_types(Coh).tm } let typ t = t.ty - open Unchecked(Coh) - module Unchecked = Make(Coh) + open Unchecked (Coh) + module Unchecked = Make (Coh) - let to_var tm = - match tm.e with - | Var v -> v - | Coh _ -> raise IsCoh + let to_var tm = match tm.e with Var v -> v | Coh _ -> raise IsCoh let free_vars tm = let fvty = Ty.free_vars tm.ty in - match tm.e with - | Var x -> x::fvty - | Coh (_,sub) -> Sub.free_vars sub - - let is_full tm = - List.included (Ctx.domain (Ty.ctx tm.ty)) (free_vars tm) + match tm.e with Var x -> x :: fvty | Coh (_, sub) -> Sub.free_vars sub + let is_full tm = List.included (Ctx.domain (Ty.ctx tm.ty)) (free_vars tm) let forget tm = tm.unchecked let check c ?ty t = Io.info ~v:5 (lazy - (Printf.sprintf - "building kernel term %s in context %s" - (Unchecked.tm_to_string t) - (Ctx.to_string c))); + (Printf.sprintf "building kernel term %s in context %s" + (Unchecked.tm_to_string t) (Ctx.to_string c))); let tm = match t with | Var x -> - let e, ty = Var x, Ty.check c (Ty.forget (Ctx.ty_var c x)) in - ({ty; e; unchecked = t}) + let e, ty = (Var x, Ty.check c (Ty.forget (Ctx.ty_var c x))) in + { ty; e; unchecked = t } | Meta_tm _ -> raise MetaVariable - | Coh (coh,s) -> - let sub = Sub.check_to_ps c s (Coh.ps coh) in - let e, ty = Coh(coh,sub), Ty.apply_sub (Coh.ty coh) sub in - {ty; e; unchecked = t} - in match ty with + | Coh (coh, s) -> + let sub = Sub.check_to_ps c s (Coh.ps coh) in + let e, ty = (Coh (coh, sub), Ty.apply_sub (Coh.ty coh) sub) in + { ty; e; unchecked = t } + in + match ty with | None -> tm - | Some ty -> Ty.check_equal ty tm.ty; tm + | Some ty -> + Ty.check_equal ty tm.ty; + tm let apply_sub t sub = Ctx.check_equal (Sub.tgt sub) (Ty.ctx t.ty); @@ -458,70 +434,66 @@ end (** A coherence. *) and Coh : sig type t + val ps : t -> PS.t val ty : t -> Ty.t val check : ps -> Unchecked_types(Coh).ty -> coh_pp_data -> t + val check_noninv : ps -> Unchecked_types(Coh).tm -> Unchecked_types(Coh).tm -> coh_pp_data -> t + val check_inv : ps -> Unchecked_types(Coh).tm -> Unchecked_types(Coh).tm -> coh_pp_data -> t + val to_string : t -> string val is_inv : t -> bool - val noninv_srctgt : t -> Unchecked_types(Coh).tm * Unchecked_types(Coh).tm * Unchecked_types(Coh).ty + + val noninv_srctgt : + t -> + Unchecked_types(Coh).tm * Unchecked_types(Coh).tm * Unchecked_types(Coh).ty + val forget : t -> ps * Unchecked_types(Coh).ty * coh_pp_data - val func_data : t -> (Var.t * int) list + val func_data : t -> (Var.t * int) list val check_equal : t -> t -> unit val dim : t -> int end = struct - - type cohInv = {ps : PS.t; ty : Ty.t} - type cohNonInv = {ps : PS.t; - src : Tm.t; - tgt : Tm.t; - total_ty: Ty.t} - - type t = - | Inv of cohInv * coh_pp_data - | NonInv of cohNonInv * coh_pp_data + type cohInv = { ps : PS.t; ty : Ty.t } + type cohNonInv = { ps : PS.t; src : Tm.t; tgt : Tm.t; total_ty : Ty.t } + type t = Inv of cohInv * coh_pp_data | NonInv of cohNonInv * coh_pp_data exception NotAlgebraic - open Unchecked(Coh) - module Unchecked = Make(Coh) + open Unchecked (Coh) + module Unchecked = Make (Coh) - let ps = function - | Inv(data,_) -> data.ps - | NonInv(data,_) -> data.ps + let ps = function Inv (data, _) -> data.ps | NonInv (data, _) -> data.ps let ty = function - | Inv(data,_) -> data.ty - | NonInv(data,_) -> data.total_ty + | Inv (data, _) -> data.ty + | NonInv (data, _) -> data.total_ty - let is_inv = function - | Inv(_,_) -> true - | NonInv(_,_) -> false + let is_inv = function Inv (_, _) -> true | NonInv (_, _) -> false let algebraic ps ty name = - if Ty.is_full ty then - (Ctx.check_equal (PS.to_ctx ps) (Ty.ctx ty); - Inv({ps; ty}, name)) + if Ty.is_full ty then ( + Ctx.check_equal (PS.to_ctx ps) (Ty.ctx ty); + Inv ({ ps; ty }, name)) else - let _,src,tgt = + let _, src, tgt = try Ty.retrieve_arrow ty with IsObj -> raise NotAlgebraic in - let src_inclusion = PS.source ps in - let src = Tm.preimage src src_inclusion in - if not (Tm.is_full src) then - raise NotAlgebraic - else - let tgt_inclusion = PS.target ps in - let tgt = Tm.preimage tgt tgt_inclusion in - if not (Tm.is_full tgt) then - raise NotAlgebraic - else - NonInv ({ps; src; tgt; total_ty=ty}, name) - - let check ps t ((name,_,_) as pp_data) = + try + let src_inclusion = PS.source ps in + let src = Tm.preimage src src_inclusion in + if not (Tm.is_full src) then raise NotAlgebraic + else + let tgt_inclusion = PS.target ps in + let tgt = Tm.preimage tgt tgt_inclusion in + if not (Tm.is_full tgt) then raise NotAlgebraic + else NonInv ({ ps; src; tgt; total_ty = ty }, name) + with NotInImage -> raise NotAlgebraic + + let check ps t ((name, _, _) as pp_data) = Io.info ~v:5 (lazy (Printf.sprintf "checking coherence (%s,%s)" @@ -534,13 +506,13 @@ end = struct algebraic ps t pp_data with | NotAlgebraic -> - Error.not_valid_coherence name - (Printf.sprintf "type %s not algebraic in pasting scheme %s" - (Unchecked.ty_to_string t) - (Unchecked.(ctx_to_string (ps_to_ctx ps)))) - | DoubledVar(s) -> - Error.not_valid_coherence name - (Printf.sprintf "variable %s appears twice in the context" s) + Error.not_valid_coherence name + (Printf.sprintf "type %s not full in pasting scheme %s" + (Unchecked.ty_to_string t) + Unchecked.(ctx_to_string (ps_to_ctx ps))) + | DoubledVar s -> + Error.not_valid_coherence name + (Printf.sprintf "variable %s appears twice in the context" s) let check_noninv ps src tgt name = let ps = PS.mk (Ctx.check (Unchecked.ps_to_ctx ps)) in @@ -549,17 +521,17 @@ end = struct let bdry = PS.bdry ps in let cbdry = PS.to_ctx bdry in let src = Tm.check cbdry src in - if not(Tm.is_full src) then raise NotAlgebraic + if not (Tm.is_full src) then raise NotAlgebraic else let tgt = Tm.check cbdry tgt in - if not(Tm.is_full tgt) - then raise NotAlgebraic + if not (Tm.is_full tgt) then raise NotAlgebraic else let total_ty = - Ty.morphism (Tm.apply_sub src src_inclusion) + Ty.morphism + (Tm.apply_sub src src_inclusion) (Tm.apply_sub tgt tgt_inclusion) in - NonInv ({ps; src; tgt; total_ty}, name) + NonInv ({ ps; src; tgt; total_ty }, name) let check_inv ps src tgt name = let ctx = Ctx.check (Unchecked.ps_to_ctx ps) in @@ -567,85 +539,81 @@ end = struct let src = Tm.check ctx src in let tgt = Tm.check ctx tgt in let ty = Ty.morphism src tgt in - if Ty.is_full ty then - Inv({ps; ty}, name) - else raise NotAlgebraic + if Ty.is_full ty then Inv ({ ps; ty }, name) else raise NotAlgebraic let data c = match c with - | Inv (d,pp_data) -> d.ps, d.ty, pp_data - | NonInv (d,pp_data) -> d.ps, d.total_ty, pp_data + | Inv (d, pp_data) -> (d.ps, d.ty, pp_data) + | NonInv (d, pp_data) -> (d.ps, d.total_ty, pp_data) let to_string c = - let ps,ty,pp_data = data c in - if not (!Settings.unroll_coherences) then + let ps, ty, pp_data = data c in + if not !Settings.unroll_coherences then Unchecked.coh_pp_data_to_string pp_data - else - Printf.sprintf "Coh(%s,%s)" (PS.to_string ps) (Ty.to_string ty) + else Printf.sprintf "Coh(%s,%s)" (PS.to_string ps) (Ty.to_string ty) let noninv_srctgt c = match c with - | Inv (_,_) -> Error.fatal "non-invertible data of an invertible coh" - | NonInv (d,_) -> Tm.forget d.src, Tm.forget d.tgt, Ty.forget (Tm.ty d.src) + | Inv (_, _) -> Error.fatal "non-invertible data of an invertible coh" + | NonInv (d, _) -> + (Tm.forget d.src, Tm.forget d.tgt, Ty.forget (Tm.ty d.src)) let dim c = - let ty = match c with - | Inv (d,_) -> d.ty - | NonInv(d,_) -> d.total_ty - in Ty.dim ty + let ty = match c with Inv (d, _) -> d.ty | NonInv (d, _) -> d.total_ty in + Ty.dim ty let func_data = function - | Inv(_,(_,_,func)) |NonInv(_,(_,_,func)) -> func + | Inv (_, (_, _, func)) | NonInv (_, (_, _, func)) -> func let forget c = - let ps,ty,pp_data = data c in - PS.forget ps, Ty.forget ty, pp_data + let ps, ty, pp_data = data c in + (PS.forget ps, Ty.forget ty, pp_data) let check_equal coh1 coh2 = - match coh1, coh2 with - | Inv(d1,_) , Inv(d2,_) -> - PS.check_equal d1.ps d2.ps; - Ty.check_equal d1.ty d2.ty - | NonInv (d1,_), NonInv(d2,_) -> - PS.check_equal d1.ps d2.ps; - Ty.check_equal d1.total_ty d2.total_ty + match (coh1, coh2) with + | Inv (d1, _), Inv (d2, _) -> + PS.check_equal d1.ps d2.ps; + Ty.check_equal d1.ty d2.ty + | NonInv (d1, _), NonInv (d2, _) -> + PS.check_equal d1.ps d2.ps; + Ty.check_equal d1.total_ty d2.total_ty | Inv _, NonInv _ | NonInv _, Inv _ -> - raise (NotEqual (to_string coh1, to_string coh2)) + raise (NotEqual (to_string coh1, to_string coh2)) end -module U = Unchecked(Coh) -module Unchecked = U.Make(Coh) +module U = Unchecked (Coh) +module Unchecked = U.Make (Coh) let check check_fn name = let v = 2 in let fname = if !Settings.verbosity >= v then Lazy.force name else "" in - Io.info ~v (lazy ("checking "^fname)); - try check_fn() with - | NotEqual(s1,s2) -> - Error.untypable - (if !Settings.verbosity >= v then fname else Lazy.force name) - (Printf.sprintf "%s and %s are not equal" s1 s2) - | InvalidSubTarget (s,tgt) -> - Error.untypable - (if !Settings.verbosity >= v then fname else Lazy.force name) - (Printf.sprintf "substitution %s does not apply from context %s" s tgt) - | Error.UnknownId (s) -> - Error.untypable - (if !Settings.verbosity >= v then fname else Lazy.force name) - (Printf.sprintf "unknown identifier :%s" s) + Io.info ~v (lazy ("checking " ^ fname)); + try check_fn () with + | NotEqual (s1, s2) -> + Error.untypable + (if !Settings.verbosity >= v then fname else Lazy.force name) + (Printf.sprintf "%s and %s are not equal" s1 s2) + | InvalidSubTarget (s, tgt) -> + Error.untypable + (if !Settings.verbosity >= v then fname else Lazy.force name) + (Printf.sprintf "substitution %s does not apply from context %s" s tgt) + | Error.UnknownId s -> + Error.untypable + (if !Settings.verbosity >= v then fname else Lazy.force name) + (Printf.sprintf "unknown identifier :%s" s) | MetaVariable -> - Error.incomplete_constraints - (if !Settings.verbosity >= v then fname else Lazy.force name) + Error.incomplete_constraints + (if !Settings.verbosity >= v then fname else Lazy.force name) let check_type ctx a = - let ty = lazy ("type: "^Unchecked.ty_to_string a) in + let ty = lazy ("type: " ^ Unchecked.ty_to_string a) in check (fun () -> Ty.check ctx a) ty let check_term ctx ?ty t = let ty = Option.map (check_type ctx) ty in - let tm = lazy ("term: " ^ (Unchecked.tm_to_string t)) in + let tm = lazy ("term: " ^ Unchecked.tm_to_string t) in check (fun () -> Tm.check ctx ?ty t) tm let check_coh ps ty pp_data = - let c = lazy ("coherence: "^(Unchecked.coh_pp_data_to_string pp_data)) in + let c = lazy ("coherence: " ^ Unchecked.coh_pp_data_to_string pp_data) in check (fun () -> Coh.check ps ty pp_data) c diff --git a/lib/kernel.mli b/lib/kernel.mli index 6d85ff93..f12f39d9 100644 --- a/lib/kernel.mli +++ b/lib/kernel.mli @@ -3,20 +3,28 @@ open Unchecked_types module rec Coh : sig type t + val forget : t -> ps * Unchecked_types(Coh).ty * coh_pp_data val check_equal : t -> t -> unit val is_inv : t -> bool val to_string : t -> string val dim : t -> int + val check_noninv : ps -> Unchecked_types(Coh).tm -> Unchecked_types(Coh).tm -> coh_pp_data -> t + val check_inv : ps -> Unchecked_types(Coh).tm -> Unchecked_types(Coh).tm -> coh_pp_data -> t - val noninv_srctgt : t -> Unchecked_types(Coh).tm * Unchecked_types(Coh).tm * Unchecked_types(Coh).ty + + val noninv_srctgt : + t -> + Unchecked_types(Coh).tm * Unchecked_types(Coh).tm * Unchecked_types(Coh).ty + val func_data : t -> (Var.t * int) list end open Unchecked_types(Coh) + module Ctx : sig type t @@ -36,6 +44,8 @@ module Tm : sig end module PS : sig + exception Invalid + type t val mk : Ctx.t -> t @@ -43,8 +53,7 @@ module PS : sig end module Unchecked : sig - - type sub_ps_bp = {sub_ps : sub_ps; l : tm; r : tm} + type sub_ps_bp = { sub_ps : sub_ps; l : tm; r : tm } val ps_to_string : ps -> string val ty_to_string : ty -> string @@ -55,12 +64,10 @@ module Unchecked : sig val meta_ctx_to_string : meta_ctx -> string val coh_pp_data_to_string : ?print_func:bool -> coh_pp_data -> string val full_name : coh_pp_data -> string - val check_equal_ctx : ctx -> ctx -> unit val check_equal_ps : ps -> ps -> unit val check_equal_ty : ty -> ty -> unit val check_equal_tm : tm -> tm -> unit - val dim_ctx : ctx -> int val dim_ty : ty -> int val dim_ps : ps -> int @@ -71,13 +78,13 @@ module Unchecked : sig val sub_ps_apply_sub : sub_ps -> sub -> sub_ps val ty_apply_sub_ps : ty -> sub_ps -> ty val tm_apply_sub_ps : tm -> sub_ps -> tm - val sub_ps_apply_sub_ps: sub_ps -> sub_ps -> sub_ps + val sub_ps_apply_sub_ps : sub_ps -> sub_ps -> sub_ps val ty_sub_preimage : ty -> sub -> ty val db_levels : ctx -> ctx * (Var.t * int) list * int val db_level_sub : ctx -> sub val db_level_sub_inv : ctx -> sub - val rename_ty : ty -> (Var.t * int) list -> ty - val rename_tm : tm -> (Var.t * int) list -> tm + val rename_ty : ty -> (Var.t * int) list -> ty + val rename_tm : tm -> (Var.t * int) list -> tm val tm_contains_var : tm -> Var.t -> bool val ty_contains_var : ty -> Var.t -> bool val tm_contains_vars : tm -> Var.t list -> bool @@ -105,6 +112,5 @@ module Unchecked : sig val list_to_db_level_sub : tm list -> sub end - val check_term : Ctx.t -> ?ty:ty -> tm -> Tm.t val check_coh : ps -> ty -> coh_pp_data -> Coh.t diff --git a/lib/meta.ml b/lib/meta.ml index 33d9e11a..ac12cde6 100644 --- a/lib/meta.ml +++ b/lib/meta.ml @@ -1,5 +1,5 @@ open Kernel -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) let meta_namer_ty = ref 0 let meta_namer_tm = ref 0 @@ -13,4 +13,4 @@ let new_tm () = let i = !meta_namer_tm in let meta = i in meta_namer_tm := !meta_namer_tm + 1; - Meta_tm meta, (i, new_ty()) + (Meta_tm meta, (i, new_ty ())) diff --git a/lib/opposite.ml b/lib/opposite.ml index f81d20c2..7b6cc0ea 100644 --- a/lib/opposite.ml +++ b/lib/opposite.ml @@ -1,37 +1,34 @@ open Common open Kernel -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) type op_data = int list let rec op_data_to_string = function | [] -> "" - | [i] -> Printf.sprintf "%i" i - | i::l -> Printf.sprintf "%i,%s" i (op_data_to_string l) + | [ i ] -> Printf.sprintf "%i" i + | i :: l -> Printf.sprintf "%i,%s" i (op_data_to_string l) let ps ps op_data = let rec level i ps = match ps with | Br [] -> Br [] - | Br l when List.mem (i+1) op_data -> - let l = List.map (level (i+1)) l in - Br (List.rev l) - | Br l -> Br (List.map (level (i+1)) l) + | Br l when List.mem (i + 1) op_data -> + let l = List.map (level (i + 1)) l in + Br (List.rev l) + | Br l -> Br (List.map (level (i + 1)) l) in level 0 ps let equiv_op_ps ps op_data = let rec level i ps = match ps with - | Br [] -> [Var (Var.Db 0), true] + | Br [] -> [ (Var (Var.Db 0), true) ] | Br l -> - let components = List.map - (fun p -> (level (i+1) p)) - l in - if List.mem (i+1) op_data then - Unchecked.opsuspwedge_subs_ps components l - else - Unchecked.suspwedge_subs_ps components l + let components = List.map (fun p -> level (i + 1) p) l in + if List.mem (i + 1) op_data then + Unchecked.opsuspwedge_subs_ps components l + else Unchecked.suspwedge_subs_ps components l in level 0 ps @@ -39,42 +36,39 @@ let rec ty typ op_data = let d = Unchecked.dim_ty typ in match typ with | Obj -> Obj - | Arr(a,t,u) -> - let a = ty a op_data in - let t = tm t op_data in - let u = tm u op_data in - if List.mem d op_data then Arr(a,u,t) else Arr(a,t,u) + | Arr (a, t, u) -> + let a = ty a op_data in + let t = tm t op_data in + let u = tm u op_data in + if List.mem d op_data then Arr (a, u, t) else Arr (a, t, u) | Meta_ty m -> Meta_ty m + and tm t op_data = match t with | Var x -> Var x - | Coh(c,s) -> - let p,_,_ = Coh.forget c in - let equiv = equiv_op_ps p op_data in - let c = coh c op_data equiv in - let op_s = sub (Unchecked.sub_ps_to_sub s) op_data in - let s' = Unchecked.sub_ps_apply_sub equiv op_s in - Coh(c, s') + | Coh (c, s) -> + let p, _, _ = Coh.forget c in + let equiv = equiv_op_ps p op_data in + let c = coh c op_data equiv in + let op_s = sub (Unchecked.sub_ps_to_sub s) op_data in + let s' = Unchecked.sub_ps_apply_sub equiv op_s in + Coh (c, s') | Meta_tm m -> Meta_tm m + and sub (s : sub) op_data : sub = - match s with - | [] -> [] - | (x,t)::s -> (x,tm t op_data)::(sub s op_data) + match s with [] -> [] | (x, t) :: s -> (x, tm t op_data) :: sub s op_data + and coh c op_data equiv = - let p,t,name = Coh.forget c in + let p, t, name = Coh.forget c in let name = Unchecked.full_name name in let op_p = ps p op_data in let op_t = ty t op_data in - let - t' = Unchecked.ty_sub_preimage - op_t - (Unchecked.sub_ps_to_sub equiv) - in + let t' = Unchecked.ty_sub_preimage op_t (Unchecked.sub_ps_to_sub equiv) in let name = Printf.sprintf "%s_op{%s}" name (op_data_to_string op_data) in - check_coh op_p t' (name,0,[]) + check_coh op_p t' (name, 0, []) let coh c op_data = - let ps,_,_ = Coh.forget c in + let ps, _, _ = Coh.forget c in let equiv = equiv_op_ps ps op_data in coh c op_data equiv @@ -82,14 +76,13 @@ let coh c op_data = let rec _ctx c op_data = match c with | [] -> [] - | (x,t)::c -> - let t = ty t op_data in - let c = _ctx c op_data in - (x,t)::c + | (x, t) :: c -> + let t = ty t op_data in + let c = _ctx c op_data in + (x, t) :: c let tm t op_data = - Io.info ~v:3 - (lazy ("computing opposite of term " ^ (Unchecked.tm_to_string t))); + Io.info ~v:3 (lazy ("computing opposite of term " ^ Unchecked.tm_to_string t)); let t = tm t op_data in - Io.info ~v:4 (lazy ("opposite computed: " ^ (Unchecked.tm_to_string t))); + Io.info ~v:4 (lazy ("opposite computed: " ^ Unchecked.tm_to_string t)); t diff --git a/lib/prover.ml b/lib/prover.ml index 3b4e8e92..d81a4e1c 100644 --- a/lib/prover.ml +++ b/lib/prover.ml @@ -1,48 +1,43 @@ (** Parse a string. *) let parse s = let lexbuf = Lexing.from_string s in - try - Parser.prog Lexer.token lexbuf - with + try Ok (Parser.prog Lexer.token lexbuf) with | Failure s when s = "lexing: empty token" -> - let pos = Lexing.lexeme_end_p lexbuf in - failwith - (Printf.sprintf - "lexing error in file %s at line %d, character %d" - pos.Lexing.pos_fname - pos.Lexing.pos_lnum - (pos.Lexing.pos_cnum - pos.Lexing.pos_bol)) - | Parsing.Parse_error -> - let pos = (Lexing.lexeme_end_p lexbuf) in - failwith - (Printf.sprintf - "parsing error in file %s at word \"%s\", line %d, character %d" - pos.Lexing.pos_fname - (Lexing.lexeme lexbuf) - pos.Lexing.pos_lnum - (pos.Lexing.pos_cnum - pos.Lexing.pos_bol - 1)) - | Error.ReservedName(x) -> - Io.printf - "Could not parse the input because the name %s is a built-in.\n\ - You can change the name of the term or coherence, or add the \ - option '--no-builtins' to deactivate the use of built-ins" x; - exit 1 + let pos = Lexing.lexeme_end_p lexbuf in + Error + (Io.error "lexing error in file %s at line %d, character %d" + pos.Lexing.pos_fname pos.Lexing.pos_lnum + (pos.Lexing.pos_cnum - pos.Lexing.pos_bol)) + | Parser.Error -> + let pos = Lexing.lexeme_end_p lexbuf in + Error + (Io.error + "parsing error in file %s at word \"%s\", line %d, character %d" + pos.Lexing.pos_fname (Lexing.lexeme lexbuf) pos.Lexing.pos_lnum + (pos.Lexing.pos_cnum - pos.Lexing.pos_bol - 1)) + | Error.ReservedName x -> + Error + (Io.error + "Could not parse the input because the name %s is a built-in.\n\ + You can change the name of the term or coherence, or add the \ + option '--no-builtins' to deactivate the use of built-ins" + x) (** Initialize the prover. *) -let init () = - print_string "=^.^= " +let init () = Printf.printf "=^.^= " (** Execute a command. *) -let rec exec s = - if s = "exit" then - exit 0 +let rec exec s parse_error_fn = + if s = "exit" then exit 0 else - Command.exec ~loop_fn:loop (parse s) + match parse s with + | Ok cmd -> Command.exec ~loop_fn:loop cmd + | Error _ -> parse_error_fn () (** Interactive loop. *) and loop () = while true do init (); let s = read_line () in - exec s + exec s (fun () -> ()) done diff --git a/lib/prover.mli b/lib/prover.mli index 5a6cdb18..ebdcdd8a 100644 --- a/lib/prover.mli +++ b/lib/prover.mli @@ -1,4 +1,4 @@ -val parse : string -> Command.prog +val parse : string -> (Command.prog, unit) result val init : unit -> unit -val exec : string -> unit +val exec : string -> (unit -> unit) -> unit val loop : unit -> unit diff --git a/lib/ps_reduction.ml b/lib/ps_reduction.ml index 8db72331..b560d1cb 100644 --- a/lib/ps_reduction.ml +++ b/lib/ps_reduction.ml @@ -1,35 +1,36 @@ open Common open Kernel -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) let tdb i = Var (Var.Db i) let rec reduce i ps = - match i,ps with + match (i, ps) with | _, Br [] -> Br [] - | 0, _ -> Br [Br []] - | i, Br l -> Br (List.map (reduce (i-1)) l) + | 0, _ -> Br [ Br [] ] + | i, Br l -> Br (List.map (reduce (i - 1)) l) let reduction_sub ps = let rec aux i ps = - match i,ps with - | _, Br[] -> [tdb 0, true] - | 0, Br [Br[]] -> [tdb 2, true; tdb 1, false; tdb 0, false] + match (i, ps) with + | _, Br [] -> [ (tdb 0, true) ] + | 0, Br [ Br [] ] -> [ (tdb 2, true); (tdb 1, false); (tdb 0, false) ] | 0, Br l -> - let k = List.length l in - [Coh(Builtin.comp_n k,(Unchecked.(identity_ps (Br l)))), true ; - tdb (2*k-1), false; - tdb 0, false] - | i, Br l -> Unchecked.suspwedge_subs_ps (List.map (aux (i-1)) l) l + let k = List.length l in + [ + (Coh (Builtin.comp_n k, Unchecked.(identity_ps (Br l))), true); + (tdb ((2 * k) - 1), false); + (tdb 0, false); + ] + | i, Br l -> Unchecked.suspwedge_subs_ps (List.map (aux (i - 1)) l) l in aux (Unchecked.dim_ps ps - 1) ps let coh c = - let ps,_,name = Coh.forget c in + let ps, _, name = Coh.forget c in let name = Unchecked.full_name name in let ps = reduce (Unchecked.dim_ps ps - 1) ps in - if Coh.is_inv c then - Error.fatal "cannot reduce invertible coherences" + if Coh.is_inv c then Error.fatal "cannot reduce invertible coherences" else - let src,tgt,_ = Coh.noninv_srctgt c in - Coh.check_noninv ps src tgt (name^"_red", 0, []) + let src, tgt, _ = Coh.noninv_srctgt c in + Coh.check_noninv ps src tgt (name ^ "_red", 0, []) diff --git a/lib/raw.ml b/lib/raw.ml index 0f2ae46e..5c3989bb 100644 --- a/lib/raw.ml +++ b/lib/raw.ml @@ -2,184 +2,155 @@ open Std open Common open Raw_types -let string_of_builtin = function - | Comp -> "comp" - | Id -> "id" +let string_of_builtin = function Comp -> "comp" | Id -> "id" let rec string_of_ty e = match e with - | Letin_ty (v,e,ty) -> - Printf.sprintf "let %s = %s in %s" - (Var.to_string v) - (string_of_tm e) - (string_of_ty ty) + | Letin_ty (v, e, ty) -> + Printf.sprintf "let %s = %s in %s" (Var.to_string v) (string_of_tm e) + (string_of_ty ty) | ObjR -> "*" - | ArrR (u,v) -> Printf.sprintf "%s -> %s" (string_of_tm u) (string_of_tm v) + | ArrR (u, v) -> Printf.sprintf "%s -> %s" (string_of_tm u) (string_of_tm v) + and string_of_tm e = match e with - | Letin_tm (v,e,tm) -> - Printf.sprintf "let %s = %s in %s" - (Var.to_string v) - (string_of_tm e) - (string_of_tm tm) + | Letin_tm (v, e, tm) -> + Printf.sprintf "let %s = %s in %s" (Var.to_string v) (string_of_tm e) + (string_of_tm tm) | VarR x -> Var.to_string x - | Sub (t,s,None,b) -> - Printf.sprintf "(%s%s %s)" - (if b then "@" else "") - (string_of_tm t) - (string_of_sub s) - | Sub (t,s,Some susp,b) -> - Printf.sprintf "(%s!%i %s %s)" - (if b then "@" else "") - susp - (string_of_tm t) - (string_of_sub s) - | BuiltinR b -> - Printf.sprintf "_builtin_%s" - (string_of_builtin b) - | Op (l,t) -> - Printf.sprintf "op_{%s}(%s)" - (Opposite.op_data_to_string l) - (string_of_tm t) - | Inverse t -> - Printf.sprintf "I(%s)" (string_of_tm t) - | Unit t -> - Printf.sprintf "U(%s)" (string_of_tm t) + | Sub (t, s, None, b) -> + Printf.sprintf "(%s%s %s)" + (if b then "@" else "") + (string_of_tm t) (string_of_sub s) + | Sub (t, s, Some susp, b) -> + Printf.sprintf "(%s!%i %s %s)" + (if b then "@" else "") + susp (string_of_tm t) (string_of_sub s) + | BuiltinR b -> Printf.sprintf "_builtin_%s" (string_of_builtin b) + | Op (l, t) -> + Printf.sprintf "op_{%s}(%s)" + (Opposite.op_data_to_string l) + (string_of_tm t) + | Inverse t -> Printf.sprintf "I(%s)" (string_of_tm t) + | Unit t -> Printf.sprintf "U(%s)" (string_of_tm t) | Meta -> "_" -and string_of_sub s= + +and string_of_sub s = match s with - | []-> "" - | (t, n)::s -> Printf.sprintf "%s %s" (string_of_sub s)(string_of_functed_tm t n) + | [] -> "" + | (t, n) :: s -> + Printf.sprintf "%s %s" (string_of_sub s) (string_of_functed_tm t n) + and string_of_functed_tm t n = - if n <= 0 then - Printf.sprintf "%s" (string_of_tm t) - else - Printf.sprintf "[%s]" (string_of_functed_tm t (n-1)) + if n <= 0 then Printf.sprintf "%s" (string_of_tm t) + else Printf.sprintf "[%s]" (string_of_functed_tm t (n - 1)) (** remove the let in in a term *) let rec replace_tm l e = match e with - | VarR a -> - begin - try replace_tm l (List.assoc a l) - with - Not_found -> VarR a - end - | Sub (e,s,susp,b) -> - Sub(replace_tm l e, replace_sub l s,susp,b) + | VarR a -> ( try replace_tm l (List.assoc a l) with Not_found -> VarR a) + | Sub (e, s, susp, b) -> Sub (replace_tm l e, replace_sub l s, susp, b) | BuiltinR _ -> e - | Op(op_data,t) -> Op(op_data, replace_tm l t) - | Inverse(t) -> Inverse (replace_tm l t) - | Unit(t) -> Unit (replace_tm l t) - | Letin_tm (v,t,tm) -> replace_tm ((v,t)::l) tm + | Op (op_data, t) -> Op (op_data, replace_tm l t) + | Inverse t -> Inverse (replace_tm l t) + | Unit t -> Unit (replace_tm l t) + | Letin_tm (v, t, tm) -> replace_tm ((v, t) :: l) tm | Meta -> Meta + and replace_sub l s = match s with | [] -> [] - | (t,f)::s -> (replace_tm l t, f)::(replace_sub l s) + | (t, f) :: s -> (replace_tm l t, f) :: replace_sub l s + and replace_ty l t = match t with | ObjR -> t - | ArrR(u,v) -> ArrR (replace_tm l u, replace_tm l v) - | Letin_ty (v,t,ty) -> replace_ty ((v,t)::l) ty + | ArrR (u, v) -> ArrR (replace_tm l u, replace_tm l v) + | Letin_ty (v, t, ty) -> replace_ty ((v, t) :: l) ty -let remove_let_tm e = - replace_tm [] e - -let remove_let_ty e = - replace_ty [] e +let remove_let_tm e = replace_tm [] e +let remove_let_ty e = replace_ty [] e let rec var_in_ty x ty = match ty with | ObjR -> false - | ArrR (u,v) -> - var_in_tm x u || var_in_tm x v - | Letin_ty _ -> Error.fatal("letin_ty constructors cannot appear here") + | ArrR (u, v) -> var_in_tm x u || var_in_tm x v + | Letin_ty _ -> Error.fatal "letin_ty constructors cannot appear here" + and var_in_tm x tm = match tm with | VarR v -> x = v - | Sub(_,s,_,_) -> List.exists (fun (t,_) -> var_in_tm x t) s + | Sub (_, s, _, _) -> List.exists (fun (t, _) -> var_in_tm x t) s | BuiltinR _ -> false | Inverse t -> var_in_tm x t | Unit t -> var_in_tm x t | Meta -> false - | Op(_,t) -> var_in_tm x t - | Letin_tm _ -> Error.fatal("letin_tm constructors cannot appear here") + | Op (_, t) -> var_in_tm x t + | Letin_tm _ -> Error.fatal "letin_tm constructors cannot appear here" let rec dim_ty ctx = function | ObjR -> 0 - | ArrR(u,_) -> 1 + dim_tm ctx u - | Letin_ty _ -> Error.fatal("letin_ty constructors cannot appear here") + | ArrR (u, _) -> 1 + dim_tm ctx u + | Letin_ty _ -> Error.fatal "letin_ty constructors cannot appear here" + and dim_tm ctx = function - | VarR v -> - begin + | VarR v -> ( try dim_ty ctx (List.assoc v ctx) - with Not_found -> Error.unknown_id(Var.to_string v) - end - | Sub(tmR,s,i,_) -> - let func = List.fold_left (fun i (_,j) -> max i j) 0 s in - let d = match tmR with - | VarR v -> Environment.dim_output v - | BuiltinR b -> dim_builtin b - | _ -> Error.fatal "ill-formed term" - in - let - susp = match i with - | None -> 0 - | Some i -> i - in - d+func+susp + with Not_found -> Error.unknown_id (Var.to_string v)) + | Sub (tmR, s, i, _) -> + let func = List.fold_left (fun i (_, j) -> max i j) 0 s in + let d = + match tmR with + | VarR v -> Environment.dim_output v + | BuiltinR b -> dim_builtin b + | _ -> Error.fatal "ill-formed term" + in + let susp = match i with None -> 0 | Some i -> i in + d + func + susp | BuiltinR b -> dim_builtin b | Meta -> 0 - | Op(_,tm) -> dim_tm ctx tm + | Op (_, tm) -> dim_tm ctx tm | Inverse t -> dim_tm ctx t | Unit t -> dim_tm ctx t + 1 - | Letin_tm _ -> Error.fatal("letin_tm constructors cannot appear here") -and dim_builtin = function - | Comp -> 1 - | Id -> 1 + | Letin_tm _ -> Error.fatal "letin_tm constructors cannot appear here" + +and dim_builtin = function Comp -> 1 | Id -> 1 let rec dim_sub ctx = function - | [] -> 0, 0 - | (t,f)::s -> - let (d1,f1) = dim_sub ctx s in - let d2 = dim_tm ctx t in - (max d1 d2, max f f1) + | [] -> 0 + | (t, f) :: s -> + let d1 = dim_sub ctx s in + let d2 = dim_tm ctx t - f in + max d1 d2 let rec infer_susp_tm ctx = function | VarR v -> VarR v - | Sub(tmR,s,i,b) -> - let s = infer_susp_sub ctx s in - begin + | Sub (tmR, s, i, b) -> ( + let s = infer_susp_sub ctx s in match i with | None -> - let inp = - match tmR with - | VarR v -> Environment.dim_input v - | BuiltinR b -> - begin - match b with - | Comp -> 1 - | Id -> 0 - end - | _ -> assert false - in - let d,func = dim_sub ctx s in - let newsusp = Some (d - inp - func) in - Sub(tmR, s, newsusp,b) - | Some _ -> Sub(tmR,s,i,b) - end + let inp = + match tmR with + | VarR v -> Environment.dim_input v + | BuiltinR b -> ( match b with Comp -> 1 | Id -> 0) + | _ -> assert false + in + let d = dim_sub ctx s in + let newsusp = Some (d - inp) in + Sub (tmR, s, newsusp, b) + | Some _ -> Sub (tmR, s, i, b)) | BuiltinR b -> BuiltinR b - | Op(l,tm) -> Op(l,infer_susp_tm ctx tm) + | Op (l, tm) -> Op (l, infer_susp_tm ctx tm) | Inverse t -> Inverse (infer_susp_tm ctx t) | Unit t -> Unit (infer_susp_tm ctx t) | Meta -> Meta | Letin_tm _ -> assert false + and infer_susp_sub ctx = function | [] -> [] - | (tm,i)::s -> (infer_susp_tm ctx tm, i)::(infer_susp_sub ctx s) + | (tm, i) :: s -> (infer_susp_tm ctx tm, i) :: infer_susp_sub ctx s let infer_susp_ty ctx = function | ObjR -> ObjR - | ArrR(u,v) -> ArrR(infer_susp_tm ctx u, infer_susp_tm ctx v) + | ArrR (u, v) -> ArrR (infer_susp_tm ctx u, infer_susp_tm ctx v) | Letin_ty _ -> assert false diff --git a/lib/raw.mli b/lib/raw.mli index 87ad681a..2996812b 100644 --- a/lib/raw.mli +++ b/lib/raw.mli @@ -6,7 +6,7 @@ val string_of_tm : tmR -> string val string_of_sub : subR -> string val remove_let_tm : tmR -> tmR val remove_let_ty : tyR -> tyR -val var_in_ty : Var.t -> tyR -> bool -val infer_susp_tm : (Var.t * tyR) list -> tmR -> tmR +val var_in_ty : Var.t -> tyR -> bool +val infer_susp_tm : (Var.t * tyR) list -> tmR -> tmR val infer_susp_ty : (Var.t * tyR) list -> tyR -> tyR -val dim_tm : (Var.t * tyR) list -> tmR -> int +val dim_tm : (Var.t * tyR) list -> tmR -> int diff --git a/lib/raw_types.mli b/lib/raw_types.mli index 58c1df99..06361caf 100644 --- a/lib/raw_types.mli +++ b/lib/raw_types.mli @@ -1,13 +1,9 @@ open Common -type builtin = - | Comp - | Id +type builtin = Comp | Id + +type tyR = Letin_ty of Var.t * tmR * tyR | ObjR | ArrR of tmR * tmR -type tyR = - | Letin_ty of Var.t * tmR * tyR - | ObjR - | ArrR of tmR * tmR and tmR = | Letin_tm of Var.t * tmR * tmR | VarR of Var.t @@ -17,4 +13,5 @@ and tmR = | Op of int list * tmR | Inverse of tmR | Unit of tmR + and subR = (tmR * int) list diff --git a/lib/settings.ml b/lib/settings.ml index 2ec9ceb4..6820b04f 100644 --- a/lib/settings.ml +++ b/lib/settings.ml @@ -3,7 +3,8 @@ let verbosity = ref 0 let use_builtins = ref true let pretty_printing = ref true let implicit_suspension = ref true -let debug = ref false +let debug = ref true +let keep_going = ref false let print_explicit_substitutions = ref false let unroll_coherences = ref false let postprocess = ref false diff --git a/lib/settings.mli b/lib/settings.mli index d682bdfc..cc5f0bbf 100644 --- a/lib/settings.mli +++ b/lib/settings.mli @@ -5,5 +5,6 @@ val verbosity : int ref val use_builtins : bool ref val pretty_printing : bool ref val implicit_suspension : bool ref +val keep_going : bool ref val debug : bool ref val postprocess : bool ref diff --git a/lib/std.ml b/lib/std.ml index 0c3412ba..06cb6d3a 100644 --- a/lib/std.ml +++ b/lib/std.ml @@ -1,52 +1,40 @@ module List = struct include List - let remove x l = - filter (fun y -> y <> x) l + let remove x l = filter (fun y -> y <> x) l let rec last = function | [] -> raise (Invalid_argument "last") - | [t] -> t - | _::l -> last l + | [ t ] -> t + | _ :: l -> last l let union l1 l2 = - fold_left (fun l x -> if not (mem x l) then x::l else l) l1 l2 + fold_left (fun l x -> if not (mem x l) then x :: l else l) l1 l2 - let unions l = - fold_left union [] l - - let included l1 l2 = - for_all (fun x -> mem x l2) l1 - - let set_equal l1 l2 = - included l1 l2 && included l2 l1 - - let diff l1 l2 = - filter (fun x -> not (mem x l2)) l1 + let unions l = fold_left union [] l + let included l1 l2 = for_all (fun x -> mem x l2) l1 + let set_equal l1 l2 = included l1 l2 && included l2 l1 + let diff l1 l2 = filter (fun x -> not (mem x l2)) l1 let rec get i l = - match l,i with - |[],_ -> raise (Not_found) - |t::_,0 -> t - |_::l,i -> get (i-1) l + match (l, i) with + | [], _ -> raise Not_found + | t :: _, 0 -> t + | _ :: l, i -> get (i - 1) l - let map_both fn = - List.map (fun (a,b) -> (fn a, fn b)) - - let map_right fn = - List.map (fun (a,b) -> (a, fn b)) + let map_both fn = List.map (fun (a, b) -> (fn a, fn b)) + let map_right fn = List.map (fun (a, b) -> (a, fn b)) let rec map3 fn l1 l2 l3 = - match l1,l2,l3 with - | [],[],[] -> [] - | a1::l1, a2::l2, a3::l3 -> (fn a1 a2 a3) :: (map3 fn l1 l2 l3) + match (l1, l2, l3) with + | [], [], [] -> [] + | a1 :: l1, a2 :: l2, a3 :: l3 -> fn a1 a2 a3 :: map3 fn l1 l2 l3 | _ -> raise (Invalid_argument "List.map3") let rec map4 fn l1 l2 l3 l4 = - match l1,l2,l3,l4 with - | [],[],[],[] -> [] - | a1::l1, a2::l2, a3::l3, a4::l4 -> - (fn a1 a2 a3 a4) :: (map4 fn l1 l2 l3 l4) + match (l1, l2, l3, l4) with + | [], [], [], [] -> [] + | a1 :: l1, a2 :: l2, a3 :: l3, a4 :: l4 -> + fn a1 a2 a3 a4 :: map4 fn l1 l2 l3 l4 | _ -> raise (Invalid_argument "List.map3") - end diff --git a/lib/std.mli b/lib/std.mli index b737125e..333132e7 100644 --- a/lib/std.mli +++ b/lib/std.mli @@ -1,17 +1,23 @@ module List : sig include module type of List - val remove : 'a -> ('a list) -> 'a list + val remove : 'a -> 'a list -> 'a list val last : 'a list -> 'a - val union : ('a list) -> ('a list) -> 'a list - val unions : ('a list) list -> 'a list - val included : ('a list) -> ('a list) -> bool - val set_equal : ('a list) -> ('a list) -> bool - val diff : ('a list) -> ('a list) -> 'a list - val get : int -> ('a list) -> 'a + val union : 'a list -> 'a list -> 'a list + val unions : 'a list list -> 'a list + val included : 'a list -> 'a list -> bool + val set_equal : 'a list -> 'a list -> bool + val diff : 'a list -> 'a list -> 'a list + val get : int -> 'a list -> 'a val map_both : ('a -> 'b) -> ('a * 'a) list -> ('b * 'b) list val map_right : ('b -> 'c) -> ('a * 'b) list -> ('a * 'c) list val map3 : ('a -> 'b -> 'c -> 'd) -> 'a list -> 'b list -> 'c list -> 'd list - val map4 : ('a -> 'b -> 'c -> 'd -> 'e) - -> 'a list -> 'b list -> 'c list -> 'd list -> 'e list + + val map4 : + ('a -> 'b -> 'c -> 'd -> 'e) -> + 'a list -> + 'b list -> + 'c list -> + 'd list -> + 'e list end diff --git a/lib/suspension.ml b/lib/suspension.ml index 1873c61e..9c05e8cb 100644 --- a/lib/suspension.ml +++ b/lib/suspension.ml @@ -1,21 +1,20 @@ open Kernel let rec iter_n_times n f base = - if n <= 0 then base else f (iter_n_times (n-1) f base) + if n <= 0 then base else f (iter_n_times (n - 1) f base) let iter_option f n base = - match n with - | None -> base - | Some n -> iter_n_times n f base + match n with None -> base | Some n -> iter_n_times n f base let ps = iter_option Unchecked.suspend_ps let ty = iter_option Unchecked.suspend_ty let tm = iter_option Unchecked.suspend_tm let sub_ps = iter_option Unchecked.suspend_sub_ps let ctx = iter_option Unchecked.suspend_ctx + let coh i coh = match i with | None | Some 0 -> coh | Some n -> - let p,t,(name,susp,f) = Coh.forget coh in - check_coh (ps i p) (ty i t) (name,susp+n,f) + let p, t, (name, susp, f) = Coh.forget coh in + check_coh (ps i p) (ty i t) (name, susp + n, f) diff --git a/lib/telescope.ml b/lib/telescope.ml index 238d5482..0f16b733 100644 --- a/lib/telescope.ml +++ b/lib/telescope.ml @@ -1,135 +1,149 @@ open Common open Kernel -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) (* returns the associator pairing up the middle two cells of a composite of (2*k) 1-cells. The argument is the integer k *) let middle_associator k = - let ps = Builtin.ps_comp (2*k) in - let src = Coh(Builtin.comp_n (2*k), Unchecked.(identity_ps ps)) in + let ps = Builtin.ps_comp (2 * k) in + let src = Coh (Builtin.comp_n (2 * k), Unchecked.(identity_ps ps)) in let tgt = let sub_assoc_middle = let rec compute_sub i = match i with - | i when i <= 0 -> [Var(Db 0), false] + | i when i <= 0 -> [ (Var (Db 0), false) ] | i when i < k -> - (Var (Db (2*i)), true):: - (Var (Db (2*i-1)), false):: - (compute_sub (i-1)) + (Var (Db (2 * i)), true) + :: (Var (Db ((2 * i) - 1)), false) + :: compute_sub (i - 1) | i when i = k -> let sub_comp = - [ Var (Db (2*k+2)),true; - Var (Db (2*k+1)), false; - Var (Db (2*k)), true; - Var (Db (2*k-1)), false; - Var (Db (2*k-3)), false] + [ + (Var (Db ((2 * k) + 2)), true); + (Var (Db ((2 * k) + 1)), false); + (Var (Db (2 * k)), true); + (Var (Db ((2 * k) - 1)), false); + (Var (Db ((2 * k) - 3)), false); + ] in - let comp = (Coh(Builtin.comp_n 2, sub_comp)) in - (comp, true)::(Var (Db (2*k+1)), false)::(compute_sub (k-1)) - | i -> (Var (Db (2*i+2)), true):: - (Var (Db (2*i+1)), false):: - (compute_sub (i-1)) + let comp = Coh (Builtin.comp_n 2, sub_comp) in + (comp, true) + :: (Var (Db ((2 * k) + 1)), false) + :: compute_sub (k - 1) + | i -> + (Var (Db ((2 * i) + 2)), true) + :: (Var (Db ((2 * i) + 1)), false) + :: compute_sub (i - 1) in - compute_sub (2*k-1) + compute_sub ((2 * k) - 1) in - Coh(Builtin.comp_n (2*k-1), sub_assoc_middle) + Coh (Builtin.comp_n ((2 * k) - 1), sub_assoc_middle) in Coh.check_inv ps src tgt ("focus", 0, []) (* returns the unitor cancelling the identity in the middle of a composite of -(2*k+1) 1-cells. The argument is the integer k *) + (2*k+1) 1-cells. The argument is the integer k *) let middle_unitor k = - let ps = Builtin.ps_comp (2*k) in + let ps = Builtin.ps_comp (2 * k) in let src = let sub_id_middle = let rec compute_sub i = match i with - | i when i <= 0 -> [Var (Db 0), false] + | i when i <= 0 -> [ (Var (Db 0), false) ] | i when i <= k -> - (Var (Db (2*i)), true):: - (Var (Db (2*i-1)), false):: - (compute_sub (i-1)) - | i when i = k+1 -> - let id = (Coh(Builtin.id, [Var (Db (2*k-1)), false])) in - (id, true)::(Var (Db (2*k-1)), false)::(compute_sub (k)) - | i -> (Var (Db (2*i-2)), true):: - (Var (Db (2*i-3)), false):: - (compute_sub (i-1)) + (Var (Db (2 * i)), true) + :: (Var (Db ((2 * i) - 1)), false) + :: compute_sub (i - 1) + | i when i = k + 1 -> + let id = Coh (Builtin.id, [ (Var (Db ((2 * k) - 1)), false) ]) in + (id, true) :: (Var (Db ((2 * k) - 1)), false) :: compute_sub k + | i -> + (Var (Db ((2 * i) - 2)), true) + :: (Var (Db ((2 * i) - 3)), false) + :: compute_sub (i - 1) in - compute_sub (2*k+1) + compute_sub ((2 * k) + 1) in - Coh(Builtin.comp_n (2*k+1), sub_id_middle) in - let tgt = Coh(Builtin.comp_n (2*k), Unchecked.(identity_ps ps)) in + Coh (Builtin.comp_n ((2 * k) + 1), sub_id_middle) + in + let tgt = Coh (Builtin.comp_n (2 * k), Unchecked.(identity_ps ps)) in Coh.check_inv ps src tgt ("unit", 0, []) - (* returns the whiskering rewriting the middle term of a composite of (2*k+1) 1-cells. The argument is the integer k *) let middle_rewrite k = - let comp = Builtin.comp_n (2*k+1) in - let func_data = [Var.Db (2*k+2)] in + let comp = Builtin.comp_n ((2 * k) + 1) in + let func_data = [ Var.Db ((2 * k) + 2) ] in Functorialisation.coh_depth0 comp func_data let tdb i = Var (Db i) +let cell_max k = Var.Db (4 * k) +let cell_forward k = Var.Db ((4 * k) - 2) +let cell_backward k = Var.Db ((4 * k) - 1) +let obj k = if k <= 0 then Var.Db 0 else Var.Db ((4 * k) - 3) +let type_cell_forward k = Arr (Obj, Var (obj (k - 1)), Var (obj k)) +let type_cell_backward k = Arr (Obj, Var (obj k), Var (obj (k - 1))) -let cell_max k = Var.Db (4*k) -let cell_forward k = Var.Db (4*k-2) -let cell_backward k = Var.Db (4*k-1) -let obj k = if k <= 0 then Var.Db 0 else Var.Db (4*k-3) -let type_cell_forward k = Arr(Obj, Var (obj(k-1)), Var (obj k)) -let type_cell_backward k = Arr(Obj, (Var (obj k)), Var (obj(k-1))) -let type_cell_max k = Arr - (Arr(Obj, Var (obj(k-1)), Var (obj(k-1))), - Coh(Builtin.comp_n 2, - [Var (cell_backward k),true; - Var (obj(k-1)), false; - Var (cell_forward k),true; - Var (obj k), false; - Var (obj(k-1)), false]), - Coh(Builtin.id, [Var (obj(k-1)), true]) - ) - +let type_cell_max k = + Arr + ( Arr (Obj, Var (obj (k - 1)), Var (obj (k - 1))), + Coh + ( Builtin.comp_n 2, + [ + (Var (cell_backward k), true); + (Var (obj (k - 1)), false); + (Var (cell_forward k), true); + (Var (obj k), false); + (Var (obj (k - 1)), false); + ] ), + Coh (Builtin.id, [ (Var (obj (k - 1)), true) ]) ) let rec ctx k = match k with | k when k < 0 -> Error.fatal "cannot build context for the telescope" - | k when k = 0 -> - [Var.Db 0, (Obj, false)] + | k when k = 0 -> [ (Var.Db 0, (Obj, false)) ] | k -> - (cell_max k, (type_cell_max k, true)):: - (cell_backward k, (type_cell_backward k, false)):: - (cell_forward k, (type_cell_forward k, false)):: - (obj k, (Obj, false)):: - (ctx (k-1)) + (cell_max k, (type_cell_max k, true)) + :: (cell_backward k, (type_cell_backward k, false)) + :: (cell_forward k, (type_cell_forward k, false)) + :: (obj k, (Obj, false)) + :: ctx (k - 1) -let rec subs_telescope_bdry ?(whisk=false) k = +let rec subs_telescope_bdry ?(whisk = false) k = match k with | k when k <= 0 -> Error.fatal "telescopes must have positive length" | k when k = 1 -> - [tdb 2, true; tdb 1, false; tdb 0, false], - [tdb 3, true; tdb 0, false] + ( [ (tdb 2, true); (tdb 1, false); (tdb 0, false) ], + [ (tdb 3, true); (tdb 0, false) ] ) | k -> - let right,left = subs_telescope_bdry ~whisk:false (k-1) in - if whisk then - let src_max_var = - Coh (Builtin.comp_n 2, - [Var (cell_backward k), true; - Var (obj (k-1)), false; - Var (cell_forward k), true; - Var (obj k), false ; - Var (obj (k-1)), false]) - in - right, - List.append left [Var (cell_max k), true; - Coh(Builtin.id, [Var (obj (k-1)), true]), false; - src_max_var, false; - Var (obj(k-1)), false] - else - (Var (cell_forward k), true)::(Var (obj k), false)::right, - List.append left [Var (cell_backward k), true; Var (obj(k-1)), false] + let right, left = subs_telescope_bdry ~whisk:false (k - 1) in + if whisk then + let src_max_var = + Coh + ( Builtin.comp_n 2, + [ + (Var (cell_backward k), true); + (Var (obj (k - 1)), false); + (Var (cell_forward k), true); + (Var (obj k), false); + (Var (obj (k - 1)), false); + ] ) + in + ( right, + List.append left + [ + (Var (cell_max k), true); + (Coh (Builtin.id, [ (Var (obj (k - 1)), true) ]), false); + (src_max_var, false); + (Var (obj (k - 1)), false); + ] ) + else + ( (Var (cell_forward k), true) :: (Var (obj k), false) :: right, + List.append left + [ (Var (cell_backward k), true); (Var (obj (k - 1)), false) ] ) -let sub_ps_telescope_bdry ?(whisk=false) k = - let right,left = subs_telescope_bdry ~whisk k in +let sub_ps_telescope_bdry ?(whisk = false) k = + let right, left = subs_telescope_bdry ~whisk k in List.append left right let rec telescope k = @@ -137,40 +151,40 @@ let rec telescope k = | k when k <= 0 -> Error.fatal "telescopes must have positive length" | k when k = 1 -> tdb 4 | k -> - let comp = Suspension.coh (Some 1) (Builtin.comp_n 4) in - let tm_src_tgt coh sub_ps = - match Coh.forget coh with - | _,Arr(_,t,u),_ -> - let sub = Unchecked.sub_ps_to_sub sub_ps in - Coh(coh,sub_ps), - Unchecked.tm_apply_sub t sub, - Unchecked.tm_apply_sub u sub - | _ -> Error.fatal "coherence must be of an arrow type" - in - let - m3,src_m3, tgt_m3 = - tm_src_tgt (middle_unitor (k-1)) (sub_ps_telescope_bdry (k-1)) - in - let - m2 = Coh(middle_rewrite (k-1), sub_ps_telescope_bdry ~whisk:true k) - in - let - m1,src_m1, tgt_m1 = - tm_src_tgt (middle_associator k) (sub_ps_telescope_bdry k) - in - let sub_telescope = - [telescope (k-1), true; - Coh(Builtin.id, [tdb 0, true]), false; - m3, true; - tgt_m3, false; - m2, true; - src_m3, false; - m1, true; - tgt_m1, false; - src_m1, false; - tdb 0, false; - tdb 0, false] - in - Coh (comp, sub_telescope) + let comp = Suspension.coh (Some 1) (Builtin.comp_n 4) in + let tm_src_tgt coh sub_ps = + match Coh.forget coh with + | _, Arr (_, t, u), _ -> + let sub = Unchecked.sub_ps_to_sub sub_ps in + ( Coh (coh, sub_ps), + Unchecked.tm_apply_sub t sub, + Unchecked.tm_apply_sub u sub ) + | _ -> Error.fatal "coherence must be of an arrow type" + in + let m3, src_m3, tgt_m3 = + tm_src_tgt (middle_unitor (k - 1)) (sub_ps_telescope_bdry (k - 1)) + in + let m2 = + Coh (middle_rewrite (k - 1), sub_ps_telescope_bdry ~whisk:true k) + in + let m1, src_m1, tgt_m1 = + tm_src_tgt (middle_associator k) (sub_ps_telescope_bdry k) + in + let sub_telescope = + [ + (telescope (k - 1), true); + (Coh (Builtin.id, [ (tdb 0, true) ]), false); + (m3, true); + (tgt_m3, false); + (m2, true); + (src_m3, false); + (m1, true); + (tgt_m1, false); + (src_m1, false); + (tdb 0, false); + (tdb 0, false); + ] + in + Coh (comp, sub_telescope) let checked k = check_term (Ctx.check (ctx k)) (telescope k) diff --git a/lib/translate_raw.ml b/lib/translate_raw.ml index fbe86dd1..62c6229e 100644 --- a/lib/translate_raw.ml +++ b/lib/translate_raw.ml @@ -1,5 +1,5 @@ open Kernel -open Unchecked_types.Unchecked_types(Coh) +open Unchecked_types.Unchecked_types (Coh) open Raw_types exception WrongNumberOfArguments @@ -8,122 +8,140 @@ exception WrongNumberOfArguments let rec tm t = let make_coh coh s susp expl = let coh = Suspension.coh susp coh in - let ps,_,_ = Coh.forget coh in + let ps, _, _ = Coh.forget coh in let func = find_functorialisation s (Unchecked.ps_to_ctx ps) expl in - let coh,ctx = Functorialisation.coh_successively coh func in + let coh, ctx = Functorialisation.coh_successively coh func in let s, meta_types = sub s ctx expl in - Unchecked.tm_apply_sub coh s, meta_types + (Unchecked.tm_apply_sub coh s, meta_types) in match t with - | VarR v -> Var v, [] - | Sub(VarR v, s, susp,expl) -> - begin + | VarR v -> (Var v, []) + | Sub (VarR v, s, susp, expl) -> ( match Environment.val_var v with | Coh coh -> make_coh coh s susp expl - | Tm(c,t) -> - let c = Suspension.ctx susp c in - let t = Suspension.tm susp t in - let func = find_functorialisation s c expl in - let t,c = Functorialisation.tm c t func in - let s, meta_types = sub s c expl in - Unchecked.tm_apply_sub t s, meta_types - end; - | Sub (BuiltinR b,s,susp,expl) -> - let builtin_coh = - match b with - | Comp -> Builtin.comp s expl - | Id -> Builtin.id - in make_coh builtin_coh s susp expl - | Op(l,t) -> let t,meta = tm t in Opposite.tm t l, meta + | Tm (c, t) -> + let c = Suspension.ctx susp c in + let t = Suspension.tm susp t in + let func = find_functorialisation s c expl in + let t, c = Functorialisation.tm c t func in + let s, meta_types = sub s c expl in + (Unchecked.tm_apply_sub t s, meta_types)) + | Sub (BuiltinR b, s, susp, expl) -> + let builtin_coh = + match b with Comp -> Builtin.comp s expl | Id -> Builtin.id + in + make_coh builtin_coh s susp expl + | Op (l, t) -> + let t, meta = tm t in + (Opposite.tm t l, meta) | Inverse t -> - let t,meta_ctx = tm t in - Inverse.compute_inverse t,meta_ctx + let t, meta_ctx = tm t in + (Inverse.compute_inverse t, meta_ctx) | Unit t -> - let t,meta_ctx = tm t in - Inverse.compute_witness t, meta_ctx - | Meta -> let m,meta_type = Meta.new_tm() in (m,[meta_type]) - | Sub (Letin_tm _,_,_,_) | Sub(Sub _,_,_,_) | Sub(Meta,_,_,_) - | Sub(Op _,_,_,_) | Sub (Inverse _,_,_,_) | Sub(Unit _,_,_,_) - | BuiltinR _ | Letin_tm _ -> Error.fatal("ill-formed term") + let t, meta_ctx = tm t in + (Inverse.compute_witness t, meta_ctx) + | Meta -> + let m, meta_type = Meta.new_tm () in + (m, [ meta_type ]) + | Sub (Letin_tm _, _, _, _) + | Sub (Sub _, _, _, _) + | Sub (Meta, _, _, _) + | Sub (Op _, _, _, _) + | Sub (Inverse _, _, _, _) + | Sub (Unit _, _, _, _) + | BuiltinR _ | Letin_tm _ -> + Error.fatal "ill-formed term" + and sub s tgt expl = - match s,tgt with - | [],[] -> [],[] - | (t,i)::s, (x,(_, e))::tgt when e || expl || !Settings.explicit_substitutions -> - let t, meta_types_t = tm t in - let fmetas, meta_types_f,tgt = meta_functed_arg i tgt in - let s, meta_types_s = sub s tgt expl in - let meta_types = List.concat [meta_types_t; meta_types_f; meta_types_s] in - (x,t)::(List.append fmetas s), meta_types - | (_::_) as s , (x,(_,_))::tgt -> - let t, meta_type = Meta.new_tm() in - let s, meta_types_s = sub s tgt expl in - (x, t)::s, meta_type::meta_types_s - | [], (x,(_,false))::tgt -> - let t, meta_type = Meta.new_tm() in - let s, meta_types_s = sub [] tgt expl in - (x, t)::s, meta_type::meta_types_s - | _::_, [] |[],_::_ -> raise WrongNumberOfArguments + match (s, tgt) with + | [], [] -> ([], []) + | (t, i) :: s, (x, (_, e)) :: tgt + when e || expl || !Settings.explicit_substitutions -> + let t, meta_types_t = tm t in + let fmetas, meta_types_f, tgt = meta_functed_arg i tgt in + let s, meta_types_s = sub s tgt expl in + let meta_types = + List.concat [ meta_types_t; meta_types_f; meta_types_s ] + in + ((x, t) :: List.append fmetas s, meta_types) + | (_ :: _ as s), (x, (_, _)) :: tgt -> + let t, meta_type = Meta.new_tm () in + let s, meta_types_s = sub s tgt expl in + ((x, t) :: s, meta_type :: meta_types_s) + | [], (x, (_, false)) :: tgt -> + let t, meta_type = Meta.new_tm () in + let s, meta_types_s = sub [] tgt expl in + ((x, t) :: s, meta_type :: meta_types_s) + | _ :: _, [] | [], _ :: _ -> raise WrongNumberOfArguments + and find_functorialisation s tgt expl = - match s,tgt with - | [],[] -> [] - | (_,i)::s, (x,(_, e))::tgt when e || expl || !Settings.explicit_substitutions -> - (x,i)::(find_functorialisation s tgt expl) - | (_::_) as s , (_,(_,_))::tgt -> find_functorialisation s tgt expl - | [], (_,(_,false))::_ -> [] - | _::_, [] |[],_::_ -> raise WrongNumberOfArguments + match (s, tgt) with + | [], [] -> [] + | (_, i) :: s, (x, (_, e)) :: tgt + when e || expl || !Settings.explicit_substitutions -> + (x, i) :: find_functorialisation s tgt expl + | (_ :: _ as s), (_, (_, _)) :: tgt -> find_functorialisation s tgt expl + | [], (_, (_, false)) :: _ -> [] + | _ :: _, [] | [], _ :: _ -> raise WrongNumberOfArguments + and meta_functed_arg i ctx = - match i,ctx with - | 0,tgt -> [],[],tgt - | _,(y,_)::(x,_)::ctx -> - let src, meta_types_src = Meta.new_tm () in - let tgt, meta_types_tgt = Meta.new_tm () in - let fmetas, meta_types,_ = meta_functed_arg (i-1) ctx in - (y,tgt)::(x,src)::fmetas, meta_types_tgt::meta_types_src::meta_types, ctx - | _,_ -> raise WrongNumberOfArguments + match (i, ctx) with + | 0, tgt -> ([], [], tgt) + | _, (y, _) :: (x, _) :: ctx -> + let src, meta_types_src = Meta.new_tm () in + let tgt, meta_types_tgt = Meta.new_tm () in + let fmetas, meta_types, _ = meta_functed_arg (i - 1) ctx in + ( (y, tgt) :: (x, src) :: fmetas, + meta_types_tgt :: meta_types_src :: meta_types, + ctx ) + | _, _ -> raise WrongNumberOfArguments let tm t = - try tm t with - | WrongNumberOfArguments -> + try tm t + with WrongNumberOfArguments -> Error.parsing_error - ("term: " ^ (Raw.string_of_tm t)) + ("term: " ^ Raw.string_of_tm t) "wrong number of arguments provided" let ty ty = match ty with - | ObjR -> Obj,[] - | ArrR(u,v) -> - let (tu, meta_types_tu), (tv, meta_types_tv) = tm u, tm v in - Arr(Meta.new_ty(),tu, tv), List.append meta_types_tu meta_types_tv - | Letin_ty _ -> Error.fatal ("letin_ty constructor cannot appear here") + | ObjR -> (Obj, []) + | ArrR (u, v) -> + let (tu, meta_types_tu), (tv, meta_types_tv) = (tm u, tm v) in + (Arr (Meta.new_ty (), tu, tv), List.append meta_types_tu meta_types_tv) + | Letin_ty _ -> Error.fatal "letin_ty constructor cannot appear here" let ty t = - try ty t with - | WrongNumberOfArguments -> + try ty t + with WrongNumberOfArguments -> Error.parsing_error - ("type: " ^ (Raw.string_of_ty t)) + ("type: " ^ Raw.string_of_ty t) "wrong number of arguments provided" let ctx c = let rec mark_explicit c after = - match c with + match c with | [] -> [] - | (v,t) :: c -> - let - expl = not (List.exists (fun (_,ty) -> Raw.var_in_ty v ty) after) - in - (v,(t,expl)) :: mark_explicit c ((v,t)::after) + | (v, t) :: c -> + let expl = + not (List.exists (fun (_, ty) -> Raw.var_in_ty v ty) after) + in + (v, (t, expl)) :: mark_explicit c ((v, t) :: after) in let rec list c = match c with - | [] -> [],[] - | (v,(t,expl)) :: c -> - let c, meta_c = list c in - let t, meta_ty = ty t in - (v, (t,expl)) :: c, List.append meta_ty meta_c - in list (mark_explicit c []) + | [] -> ([], []) + | (v, (t, expl)) :: c -> + let c, meta_c = list c in + let t, meta_ty = ty t in + ((v, (t, expl)) :: c, List.append meta_ty meta_c) + in + list (mark_explicit c []) let rec sub_to_suspended = function | [] -> - let (m1,mc1),(m0,mc0) = Meta.new_tm(), Meta.new_tm() in - [ m1, false; m0, false], [mc1; mc0] - | t::s -> let s,m = sub_to_suspended s in t::s, m + let (m1, mc1), (m0, mc0) = (Meta.new_tm (), Meta.new_tm ()) in + ([ (m1, false); (m0, false) ], [ mc1; mc0 ]) + | t :: s -> + let s, m = sub_to_suspended s in + (t :: s, m) diff --git a/lib/unchecked.ml b/lib/unchecked.ml index b0f8286d..3f74d629 100644 --- a/lib/unchecked.ml +++ b/lib/unchecked.ml @@ -2,224 +2,219 @@ open Std open Common open Unchecked_types -module Unchecked (Coh : sig type t end) = +module Unchecked (Coh : sig + type t +end) = struct - open Unchecked_types(Coh) - - module Make - (Coh : sig - val forget : Coh.t -> ps * Unchecked_types(Coh).ty * coh_pp_data - val to_string : Coh.t -> string - val func_data : Coh.t -> (Var.t * int) list - val check_equal : Coh.t -> Coh.t -> unit - val check : ps -> ty -> coh_pp_data -> Coh.t - end) - = struct - - exception NotInImage - + open Unchecked_types (Coh) + + module Make (Coh : sig + val forget : Coh.t -> ps * Unchecked_types(Coh).ty * coh_pp_data + val to_string : Coh.t -> string + val func_data : Coh.t -> (Var.t * int) list + val check_equal : Coh.t -> Coh.t -> unit + val check : ps -> ty -> coh_pp_data -> Coh.t + end) = + struct let sub_ps_to_sub s = let rec aux s = match s with - | [] -> [],0 - | (t,_)::s -> - let s,i = aux s in - (Var.Db i,t)::s, i+1 - in fst (aux s) + | [] -> ([], 0) + | (t, _) :: s -> + let s, i = aux s in + ((Var.Db i, t) :: s, i + 1) + in + fst (aux s) let rec func_to_string = function | [] -> "" - | (_,i)::func -> Printf.sprintf "%s%d" (func_to_string func) i + | (_, i) :: func -> Printf.sprintf "%s%d" (func_to_string func) i let rec ps_to_string = function - | Br l -> Printf.sprintf "[%s]" - (List.fold_left - (fun s ps -> Printf.sprintf "%s%s" (ps_to_string ps) s) - "" - l) + | Br l -> + Printf.sprintf "[%s]" + (List.fold_left + (fun s ps -> Printf.sprintf "%s%s" (ps_to_string ps) s) + "" l) let rec ty_to_string = function | Meta_ty i -> Printf.sprintf "_ty%i" i | Obj -> "*" - | Arr (a,u,v) -> - if !Settings.verbosity >= 3 then - Printf.sprintf "%s | %s -> %s" - (ty_to_string a) - (tm_to_string u) - (tm_to_string v) - else - Printf.sprintf "%s -> %s" - (tm_to_string u) - (tm_to_string v) + | Arr (a, u, v) -> + if !Settings.verbosity >= 3 then + Printf.sprintf "%s | %s -> %s" (ty_to_string a) (tm_to_string u) + (tm_to_string v) + else Printf.sprintf "%s -> %s" (tm_to_string u) (tm_to_string v) + and tm_to_string = function | Var v -> Var.to_string v | Meta_tm i -> Printf.sprintf "_tm%i" i - | Coh (c,s) -> - if not (!Settings.unroll_coherences) then - let func = Coh.func_data c in - Printf.sprintf "(%s%s)" - (Coh.to_string c) - (sub_ps_to_string_func s func) - else - Printf.sprintf "%s[%s]" - (Coh.to_string c) - (sub_ps_to_string s) + | Coh (c, s) -> + if not !Settings.unroll_coherences then + let func = Coh.func_data c in + Printf.sprintf "(%s%s)" (Coh.to_string c) + (sub_ps_to_string_func s func) + else Printf.sprintf "%s[%s]" (Coh.to_string c) (sub_ps_to_string s) + and sub_ps_to_string s = match s with | [] -> "" - | (t,expl)::s -> - if(expl || !Settings.print_explicit_substitutions) then - Printf.sprintf "%s %s" (sub_ps_to_string s) (tm_to_string t) - else sub_ps_to_string s + | (t, expl) :: s -> + if expl || !Settings.print_explicit_substitutions then + Printf.sprintf "%s %s" (sub_ps_to_string s) (tm_to_string t) + else sub_ps_to_string s + and sub_ps_to_string_func s func = let rec print s = match s with - | (t,true)::s -> - let str,x = print s in - let i = - match List.assoc_opt (Var.Db x) func with - | None -> 0 - | Some i -> i - in - Printf.sprintf "%s %s" - str - (bracket i (tm_to_string t)),x+1 - | (t,false)::s -> - let str,x = print s in - let str = if !Settings.print_explicit_substitutions then - Printf.sprintf "%s %s" str (tm_to_string t) - else str - in - str,x+1 - | [] -> "",0 - in fst(print s) - and coh_pp_data_to_string ?(print_func=false) (name, susp, func) = + | (t, true) :: s -> + let str, x = print s in + let i = + match List.assoc_opt (Var.Db x) func with + | None -> 0 + | Some i -> i + in + (Printf.sprintf "%s %s" str (bracket i (tm_to_string t)), x + 1) + | (t, false) :: s -> + let str, x = print s in + let str = + if !Settings.print_explicit_substitutions then + Printf.sprintf "%s %s" str (tm_to_string t) + else str + in + (str, x + 1) + | [] -> ("", 0) + in + fst (print s) + + and coh_pp_data_to_string ?(print_func = false) (name, susp, func) = let susp_name = if susp > 0 then Printf.sprintf "!%i%s" susp name else name in - if print_func - then susp_name^"/"^(func_to_string func) - else susp_name + if print_func then susp_name ^ "/" ^ func_to_string func else susp_name + and bracket i s = - if i <= 0 then s else Printf.sprintf "[%s]" (bracket (i-1) s) + if i <= 0 then s else Printf.sprintf "[%s]" (bracket (i - 1) s) let rec ctx_to_string = function | [] -> "" - | (x,(t,true))::c -> - Printf.sprintf "%s (%s: %s)" - (ctx_to_string c) - (Var.to_string x) - (ty_to_string t) - | (x,(t,false))::c -> - Printf.sprintf "%s {%s: %s}" - (ctx_to_string c) - (Var.to_string x) - (ty_to_string t) + | (x, (t, true)) :: c -> + Printf.sprintf "%s (%s: %s)" (ctx_to_string c) (Var.to_string x) + (ty_to_string t) + | (x, (t, false)) :: c -> + Printf.sprintf "%s {%s: %s}" (ctx_to_string c) (Var.to_string x) + (ty_to_string t) + let rec sub_to_string = function | [] -> "" - | (x,t)::s -> - Printf.sprintf "%s (%s: %s)" - (sub_to_string s) - (Var.to_string x) - (tm_to_string t) + | (x, t) :: s -> + Printf.sprintf "%s (%s: %s)" (sub_to_string s) (Var.to_string x) + (tm_to_string t) let rec meta_ctx_to_string = function | [] -> "" - | (i,t)::c -> - Printf.sprintf "%s (_tm%i: %s)" - (meta_ctx_to_string c) - i - (ty_to_string t) + | (i, t) :: c -> + Printf.sprintf "%s (_tm%i: %s)" (meta_ctx_to_string c) i + (ty_to_string t) let full_name name = let print_func_data func = let rec aux = function | [] -> "" - | [_,i] -> Printf.sprintf "%d" i - | (_,i)::l -> Printf.sprintf "%s %d" (aux l) i + | [ (_, i) ] -> Printf.sprintf "%d" i + | (_, i) :: l -> Printf.sprintf "%s %d" (aux l) i in - match func with - | [] -> "" - | _ -> Printf.sprintf "_func[%s]" (aux func) - in - let print_susp s = - match s with - | 0 -> "" - | k -> Printf.sprintf "!%i" k + match func with [] -> "" | _ -> Printf.sprintf "_func[%s]" (aux func) in - let(name,susp,func) = name in + let print_susp s = match s with 0 -> "" | k -> Printf.sprintf "!%i" k in + let name, susp, func = name in Printf.sprintf "%s%s%s" (print_susp susp) name (print_func_data func) let rec check_equal_ps ps1 ps2 = - match ps1, ps2 with - | Br [], Br[] -> () - | Br (ps1::l1), Br(ps2::l2) -> - check_equal_ps ps1 ps2; - List.iter2 check_equal_ps l1 l2 - | Br[], Br (_::_) | Br(_::_), Br[] -> - raise (NotEqual (ps_to_string ps1, ps_to_string ps2)) + match (ps1, ps2) with + | Br [], Br [] -> () + | Br (ps1 :: l1), Br (ps2 :: l2) -> + check_equal_ps ps1 ps2; + List.iter2 check_equal_ps l1 l2 + | Br [], Br (_ :: _) | Br (_ :: _), Br [] -> + raise (NotEqual (ps_to_string ps1, ps_to_string ps2)) let rec check_equal_ty ty1 ty2 = - match ty1, ty2 with + match (ty1, ty2) with | Meta_ty i, Meta_ty j -> - if i <> j then raise (NotEqual(string_of_int i, string_of_int j)) + if i <> j then raise (NotEqual (string_of_int i, string_of_int j)) | Obj, Obj -> () - | Arr(ty1, u1, v1), Arr(ty2, u2, v2) -> - check_equal_ty ty1 ty2; - check_equal_tm u1 u2; - check_equal_tm v1 v2 - | Obj, Arr _ | Arr _, Obj - | Meta_ty _, Obj | Meta_ty _, Arr _ - | Obj, Meta_ty _ | Arr _, Meta_ty _ -> - raise (NotEqual (ty_to_string ty1, ty_to_string ty2)) + | Arr (ty1, u1, v1), Arr (ty2, u2, v2) -> + check_equal_ty ty1 ty2; + check_equal_tm u1 u2; + check_equal_tm v1 v2 + | Obj, Arr _ + | Arr _, Obj + | Meta_ty _, Obj + | Meta_ty _, Arr _ + | Obj, Meta_ty _ + | Arr _, Meta_ty _ -> + raise (NotEqual (ty_to_string ty1, ty_to_string ty2)) + and check_equal_tm tm1 tm2 = - match tm1, tm2 with + match (tm1, tm2) with | Var v1, Var v2 -> Var.check_equal v1 v2 | Meta_tm i, Meta_tm j -> - if i <> j then raise (NotEqual(string_of_int i, string_of_int j)) - | Coh(coh1, s1), Coh(coh2, s2) -> - Coh.check_equal coh1 coh2; - check_equal_sub_ps s1 s2 - | Var _, Coh _ | Coh _, Var _ - | Meta_tm _, Var _| Meta_tm _, Coh _ - | Var _, Meta_tm _ | Coh _, Meta_tm _ -> - raise (NotEqual (tm_to_string tm1, tm_to_string tm2)) + if i <> j then raise (NotEqual (string_of_int i, string_of_int j)) + | Coh (coh1, s1), Coh (coh2, s2) -> + Coh.check_equal coh1 coh2; + check_equal_sub_ps s1 s2 + | Var _, Coh _ + | Coh _, Var _ + | Meta_tm _, Var _ + | Meta_tm _, Coh _ + | Var _, Meta_tm _ + | Coh _, Meta_tm _ -> + raise (NotEqual (tm_to_string tm1, tm_to_string tm2)) + and check_equal_sub_ps s1 s2 = - List.iter2 (fun (t1,_) (t2,_) -> check_equal_tm t1 t2) s1 s2 + List.iter2 (fun (t1, _) (t2, _) -> check_equal_tm t1 t2) s1 s2 let rec check_equal_ctx ctx1 ctx2 = - match ctx1, ctx2 with + match (ctx1, ctx2) with | [], [] -> () - | (v1,(t1,_))::c1, (v2,(t2,_))::c2 -> - Var.check_equal v1 v2; - check_equal_ty t1 t2; - check_equal_ctx c1 c2 - | _::_,[] | [],_::_ -> - raise (NotEqual (ctx_to_string ctx1, ctx_to_string ctx2)) + | (v1, (t1, _)) :: c1, (v2, (t2, _)) :: c2 -> + Var.check_equal v1 v2; + check_equal_ty t1 t2; + check_equal_ctx c1 c2 + | _ :: _, [] | [], _ :: _ -> + raise (NotEqual (ctx_to_string ctx1, ctx_to_string ctx2)) let rec tm_do_on_variables tm f = match tm with - | Var v -> (f v) + | Var v -> f v | Meta_tm i -> Meta_tm i - | Coh(c,s) -> Coh (c, sub_ps_do_on_variables s f) - and sub_ps_do_on_variables s f = List.map (fun (t,expl) -> tm_do_on_variables t f, expl) s + | Coh (c, s) -> Coh (c, sub_ps_do_on_variables s f) + + and sub_ps_do_on_variables s f = + List.map (fun (t, expl) -> (tm_do_on_variables t f, expl)) s let rec ty_do_on_variables ty f = match ty with | Meta_ty i -> Meta_ty i | Obj -> Obj - | Arr(a,u,v) -> - Arr(ty_do_on_variables a f, tm_do_on_variables u f, tm_do_on_variables v f) + | Arr (a, u, v) -> + Arr + ( ty_do_on_variables a f, + tm_do_on_variables u f, + tm_do_on_variables v f ) let var_apply_sub v s = - match List.assoc_opt v s with - | Some t -> t - | None -> Var v + match List.assoc_opt v s with Some t -> t | None -> Var v + let tm_apply_sub tm s = tm_do_on_variables tm (fun v -> var_apply_sub v s) let ty_apply_sub ty s = ty_do_on_variables ty (fun v -> var_apply_sub v s) + let sub_ps_apply_sub s1 s2 = sub_ps_do_on_variables s1 (fun v -> var_apply_sub v s2) - let _sub_apply_sub s1 s2 = List.map (fun (v,t) -> (v,tm_apply_sub t s2)) s1 + + let _sub_apply_sub s1 s2 = + List.map (fun (v, t) -> (v, tm_apply_sub t s2)) s1 let ty_apply_sub_ps ty s = ty_apply_sub ty (sub_ps_to_sub s) let tm_apply_sub_ps tm s = tm_apply_sub tm (sub_ps_to_sub s) @@ -228,59 +223,62 @@ struct let rec var_sub_preimage v s = match s with | [] -> raise NotInImage - | (w, Var v')::_ when v = v' -> Var w - | _::s -> var_sub_preimage v s + | (w, Var v') :: _ when v = v' -> Var w + | _ :: s -> var_sub_preimage v s + let tm_sub_preimage tm s = tm_do_on_variables tm (fun v -> var_sub_preimage v s) + let ty_sub_preimage ty s = ty_do_on_variables ty (fun v -> var_sub_preimage v s) (* rename is applying a variable to de Bruijn levels substitutions *) - let rename_var v l = try - Var (Db (List.assoc v l)) + let rename_var v l = + try Var (Db (List.assoc v l)) with Not_found -> - Error.fatal (Printf.sprintf - "variable %s not found in context" - (Var.to_string v)) + Error.fatal + (Printf.sprintf "variable %s not found in context" (Var.to_string v)) + let rename_ty ty l = ty_do_on_variables ty (fun v -> rename_var v l) let rename_tm tm l = tm_do_on_variables tm (fun v -> rename_var v l) let rec db_levels c = match c with - | [] -> [], [], -1 - | (x,(t,expl))::c -> - let c,l,max = db_levels c in - if List.mem_assoc x l then - raise (DoubledVar(Var.to_string x)) - else - let lvl = max + 1 in - (Var.Db lvl, (rename_ty t l, expl)) ::c, (x, lvl)::l, lvl + | [] -> ([], [], -1) + | (x, (t, expl)) :: c -> + let c, l, max = db_levels c in + if List.mem_assoc x l then raise (DoubledVar (Var.to_string x)) + else + let lvl = max + 1 in + ((Var.Db lvl, (rename_ty t l, expl)) :: c, (x, lvl) :: l, lvl) let db_level_sub c = - let _,names,_ = db_levels c in - List.map (fun (t,n) -> (Var.Db n,Var(t))) names + let _, names, _ = db_levels c in + List.map (fun (t, n) -> (Var.Db n, Var t)) names let db_level_sub_inv c = - let _,names,_ = db_levels c in - List.map (fun (t,n) -> (t,Var(Var.Db n))) names + let _, names, _ = db_levels c in + List.map (fun (t, n) -> (t, Var (Var.Db n))) names - let suspend_ps ps = Br [ps] + let suspend_ps ps = Br [ ps ] let rec suspend_ty = function - | Obj -> Arr(Obj, Var (Db 0), Var (Db 1)) - | Arr(a,v,u) -> Arr(suspend_ty a, suspend_tm v, suspend_tm u) + | Obj -> Arr (Obj, Var (Db 0), Var (Db 1)) + | Arr (a, v, u) -> Arr (suspend_ty a, suspend_tm v, suspend_tm u) | Meta_ty _ -> Error.fatal "meta-variables should be resolved" + and suspend_tm = function | Var v -> Var (Var.suspend v) - | Coh (c,s) -> Coh(suspend_coh c, suspend_sub_ps s) + | Coh (c, s) -> Coh (suspend_coh c, suspend_sub_ps s) | Meta_tm _ -> Error.fatal "meta-variables should be resolved" + and suspend_coh c = - let p,t,(name,susp,f) = Coh.forget c in - Coh.check (suspend_ps p) (suspend_ty t) (name, susp+1, f) - and suspend_sub_ps = function - | [] -> [Var (Var.Db 1), false; Var (Var.Db 0), false] - | (t,expl)::s -> (suspend_tm t, expl) :: (suspend_sub_ps s) + let p, t, (name, susp, f) = Coh.forget c in + Coh.check (suspend_ps p) (suspend_ty t) (name, susp + 1, f) + and suspend_sub_ps = function + | [] -> [ (Var (Var.Db 1), false); (Var (Var.Db 0), false) ] + | (t, expl) :: s -> (suspend_tm t, expl) :: suspend_sub_ps s (* Definition of FreePos(B): - in the paper, we define the bipointed verison with suspension and wedge @@ -292,251 +290,270 @@ struct maximal variable. *) - type ctx_bp = {ctx: ctx; max: int; rp: int} - type sub_ps_bp = {sub_ps: sub_ps; l: tm; r: tm} + type ctx_bp = { ctx : ctx; max : int; rp : int } + type sub_ps_bp = { sub_ps : sub_ps; l : tm; r : tm } let rec suspend_ctx_rp ctx = match ctx with | [] -> - let ctx = (Var.Db 1, (Obj, false))::(Var.Db 0, (Obj, false))::[] in - {ctx; max = 1; rp = 1} - | (v,(t,expl))::c -> - let c = suspend_ctx_rp c in - let v = Var.suspend v in - match v with - | Var.Db i -> - {ctx = (v, (suspend_ty t, expl))::c.ctx; max = max i c.max; rp = c.rp} - | _ -> - {ctx = (v, (suspend_ty t, expl))::c.ctx; max = c.max; rp = c.rp} - - let suspend_ctx ctx = - (suspend_ctx_rp ctx).ctx - - let rec dim_ps = function - | Br [] -> 0 - | Br l -> 1 + max_list_ps l + let ctx = [ (Var.Db 1, (Obj, false)); (Var.Db 0, (Obj, false)) ] in + { ctx; max = 1; rp = 1 } + | (v, (t, expl)) :: c -> ( + let c = suspend_ctx_rp c in + let v = Var.suspend v in + match v with + | Var.Db i -> + { + ctx = (v, (suspend_ty t, expl)) :: c.ctx; + max = max i c.max; + rp = c.rp; + } + | _ -> + { + ctx = (v, (suspend_ty t, expl)) :: c.ctx; + max = c.max; + rp = c.rp; + }) + + let suspend_ctx ctx = (suspend_ctx_rp ctx).ctx + + let rec dim_ps = function Br [] -> 0 | Br l -> 1 + max_list_ps l + and max_list_ps = function | [] -> 0 - | p::l -> max (dim_ps p) (max_list_ps l) + | p :: l -> max (dim_ps p) (max_list_ps l) let var_inr_wedge v ctx_bp = match v with - | Var.Db j -> - if j = 0 then (Var.Db ctx_bp.rp) - else Var.Db (j + ctx_bp.max) + | Var.Db j -> if j = 0 then Var.Db ctx_bp.rp else Var.Db (j + ctx_bp.max) | _ -> Error.fatal "expecting a de-bruijn level" let ty_inr_wedge ty ctx_bp = ty_do_on_variables ty (fun v -> Var (var_inr_wedge v ctx_bp)) + let tm_inr_wedge tm ctx_bp = tm_do_on_variables tm (fun v -> Var (var_inr_wedge v ctx_bp)) let rec ps_to_ctx_rp ps = match ps with - | Br [] -> {ctx = [(Var.Db 0), (Obj, true)]; rp = 0; max = 0} - | Br l -> let _,ctx = canonical_inclusions l in - ctx + | Br [] -> { ctx = [ (Var.Db 0, (Obj, true)) ]; rp = 0; max = 0 } + | Br l -> + let _, ctx = canonical_inclusions l in + ctx + and canonical_inclusions l = match l with | [] -> Error.fatal "empty inclusions" - | [ps] -> - [suspend_sub_ps (identity_ps ps)], suspend_ctx_rp (ps_to_ctx_rp ps).ctx - | ps::l -> - let id = suspend_sub_ps (identity_ps ps) in - let ctx_ps = suspend_ctx_rp (ps_to_ctx_rp ps).ctx in - let incls,ctx_base = canonical_inclusions l in - let ctx_bp = - {ctx = append_onto_ctx ctx_ps ctx_base; - rp = ctx_ps.rp + ctx_base.max; - max = ctx_ps.max + ctx_base.max} - in - let incl = List.map (fun (t,e) -> tm_inr_wedge t ctx_base,e) id in - incl::incls, ctx_bp + | [ ps ] -> + ( [ suspend_sub_ps (identity_ps ps) ], + suspend_ctx_rp (ps_to_ctx_rp ps).ctx ) + | ps :: l -> + let id = suspend_sub_ps (identity_ps ps) in + let ctx_ps = suspend_ctx_rp (ps_to_ctx_rp ps).ctx in + let incls, ctx_base = canonical_inclusions l in + let ctx_bp = + { + ctx = append_onto_ctx ctx_ps ctx_base; + rp = ctx_ps.rp + ctx_base.max; + max = ctx_ps.max + ctx_base.max; + } + in + let incl = List.map (fun (t, e) -> (tm_inr_wedge t ctx_base, e)) id in + (incl :: incls, ctx_bp) + and append_onto_ctx ctx base = let rec aux = function | [] -> Error.fatal "empty context in wedge" - | [_] -> base.ctx - | (v,(t,expl))::ctx -> - let t = ty_inr_wedge t base in - let v = var_inr_wedge v base in - (v,(t,expl))::(aux ctx) - in aux ctx.ctx + | [ _ ] -> base.ctx + | (v, (t, expl)) :: ctx -> + let t = ty_inr_wedge t base in + let v = var_inr_wedge v base in + (v, (t, expl)) :: aux ctx + in + aux ctx.ctx + and identity_ps ps = match ps with - | Br [] -> [Var (Var.Db 0), true] + | Br [] -> [ (Var (Var.Db 0), true) ] | Br l -> - let incls,_ = canonical_inclusions l in - wedge_sub_ps incls + let incls, _ = canonical_inclusions l in + wedge_sub_ps incls + and wedge_sub_ps l = wedge_sub_ps_bp (List.map sub_ps_to_sub_ps_bp l) + and wedge_sub_ps_bp l = let lp = (List.last l).l in List.fold_right - (fun s sub -> List.append s.sub_ps((s.r,false)::sub)) + (fun s sub -> List.append s.sub_ps ((s.r, false) :: sub)) l - [lp,false] + [ (lp, false) ] + and sub_ps_to_sub_ps_bp sub_ps = match sub_ps with - | [] | [_] -> Error.fatal "bipointed substitution need at least two points" - | [(r,_);(l,_)] -> {sub_ps = []; l; r} - | t::s -> - let s = sub_ps_to_sub_ps_bp s in - {sub_ps = t::s.sub_ps; l = s.l; r = s.r} + | [] | [ _ ] -> + Error.fatal "bipointed substitution need at least two points" + | [ (r, _); (l, _) ] -> { sub_ps = []; l; r } + | t :: s -> + let s = sub_ps_to_sub_ps_bp s in + { sub_ps = t :: s.sub_ps; l = s.l; r = s.r } + + let canonical_inclusions l = + let incls, _ = canonical_inclusions l in + incls - let canonical_inclusions l = let incls,_ = canonical_inclusions l in incls let ps_to_ctx ps = (ps_to_ctx_rp ps).ctx let suspwedge_subs_ps list_subs list_ps = let incls = canonical_inclusions list_ps in wedge_sub_ps (List.map2 - (fun s i -> - sub_ps_apply_sub - (suspend_sub_ps s) - (sub_ps_to_sub i)) + (fun s i -> sub_ps_apply_sub (suspend_sub_ps s) (sub_ps_to_sub i)) list_subs incls) let opsuspwedge_subs_ps list_subs list_ps = let rec swap_bp sub = match sub with - | [] | [_] -> Error.fatal "wedge without two basepoints" - | [r;l] -> [l;r] - | t::sub -> t::(swap_bp sub) + | [] | [ _ ] -> Error.fatal "wedge without two basepoints" + | [ r; l ] -> [ l; r ] + | t :: sub -> t :: swap_bp sub in let incls = canonical_inclusions list_ps in wedge_sub_ps (List.map2 (fun s i -> - sub_ps_apply_sub - (swap_bp (suspend_sub_ps s)) - (sub_ps_to_sub i)) + sub_ps_apply_sub (swap_bp (suspend_sub_ps s)) (sub_ps_to_sub i)) (List.rev list_subs) (List.rev incls)) let rec ps_bdry i ps = match ps with | Br [] -> Br [] | Br _ when i <= 0 -> Br [] - | Br l -> Br (List.map (ps_bdry (i-1)) l) + | Br l -> Br (List.map (ps_bdry (i - 1)) l) let rec ps_src i ps = - match i,ps with - | 0,_ -> [Var (Var.Db 0), true] - | _, Br [] -> [Var (Var.Db 0), true] - | i, Br l -> suspwedge_subs_ps (List.map (ps_src (i-1)) l) l + match (i, ps) with + | 0, _ -> [ (Var (Var.Db 0), true) ] + | _, Br [] -> [ (Var (Var.Db 0), true) ] + | i, Br l -> suspwedge_subs_ps (List.map (ps_src (i - 1)) l) l let rec ps_tgt i ps = - match i,ps with - | 0, ps -> let c = ps_to_ctx_rp ps in [Var (Var.Db c.rp), true] - | _, Br[] -> [Var (Var.Db 0), true] - | i, Br l -> suspwedge_subs_ps (List.map (ps_tgt (i-1)) l) l + match (i, ps) with + | 0, ps -> + let c = ps_to_ctx_rp ps in + [ (Var (Var.Db c.rp), true) ] + | _, Br [] -> [ (Var (Var.Db 0), true) ] + | i, Br l -> suspwedge_subs_ps (List.map (ps_tgt (i - 1)) l) l let ps_bdry ps = ps_bdry (dim_ps ps - 1) ps let ps_src ps = ps_src (dim_ps ps - 1) ps let ps_tgt ps = ps_tgt (dim_ps ps - 1) ps let rec ps_compose i ps1 ps2 = - match i, ps1, ps2 with + match (i, ps1, ps2) with | 0, Br l1, Br l2 -> - let i1 = identity_ps (Br l1) in - let i2 = identity_ps (Br l2) in - let ctx_bp = ps_to_ctx_rp ps1 in - let i2 = List.map (fun (x,e) -> tm_inr_wedge x ctx_bp, e) i2 in - Br (List.append l2 l1), - i1, - i2 - | _, Br [], Br [] -> let s = identity_ps ps1 in ps1, s, s - | i, Br l1, Br l2 -> - try - let list = List.map2 (ps_compose (i-1)) l1 l2 in - let lps = List.map (fun (x,_,_) -> x) list in - let li1 = List.map (fun (_,x,_) -> x) list in - let li2 = List.map (fun (_,_,x) -> x) list in - Br lps, suspwedge_subs_ps li1 lps, suspwedge_subs_ps li2 lps - with Invalid_argument _ -> - Error.fatal "composition of pasting schemes only allowed when their\ - boundaries match up" + let i1 = identity_ps (Br l1) in + let i2 = identity_ps (Br l2) in + let ctx_bp = ps_to_ctx_rp ps1 in + let i2 = List.map (fun (x, e) -> (tm_inr_wedge x ctx_bp, e)) i2 in + (Br (List.append l2 l1), i1, i2) + | _, Br [], Br [] -> + let s = identity_ps ps1 in + (ps1, s, s) + | i, Br l1, Br l2 -> ( + try + let list = List.map2 (ps_compose (i - 1)) l1 l2 in + let lps = List.map (fun (x, _, _) -> x) list in + let li1 = List.map (fun (_, x, _) -> x) list in + let li2 = List.map (fun (_, _, x) -> x) list in + (Br lps, suspwedge_subs_ps li1 lps, suspwedge_subs_ps li2 lps) + with Invalid_argument _ -> + Error.fatal + "composition of pasting schemes only allowed when \ + theirboundaries match up") let rec pullback_up i ps1 ps2 s1 s2 = - match i, ps1, ps2, s1, s2 with - | 0,_,_,s1,s2 -> - let rec append s2 = - match s2 with - | [] -> Error.fatal "substitution to pasting scheme cannot be empty" - | [_] -> s1 - | t::s2 -> t::(append s2) - in append s2 + match (i, ps1, ps2, s1, s2) with + | 0, _, _, s1, s2 -> + let rec append s2 = + match s2 with + | [] -> Error.fatal "substitution to pasting scheme cannot be empty" + | [ _ ] -> s1 + | t :: s2 -> t :: append s2 + in + append s2 | _, Br [], Br [], _, _ -> s1 | i, Br l1, Br l2, s1, s2 -> - let incls1 = canonical_inclusions l1 in - let incls2 = canonical_inclusions l2 in - let s1 = sub_ps_to_sub s1 in - let s2 = sub_ps_to_sub s2 in - let ls = - List.map4 (fun ps1 ps2 i1 i2 -> - let s1 = sub_ps_to_sub_ps_bp (sub_ps_apply_sub i1 s1) in - let s2 = sub_ps_to_sub_ps_bp (sub_ps_apply_sub i2 s2) in - let hom_sub = pullback_up (i-1) ps1 ps2 s1.sub_ps s2.sub_ps in - {sub_ps = hom_sub; l = s1.l; r = s1.r}) - l1 l2 incls1 incls2 - in - wedge_sub_ps_bp ls + let incls1 = canonical_inclusions l1 in + let incls2 = canonical_inclusions l2 in + let s1 = sub_ps_to_sub s1 in + let s2 = sub_ps_to_sub s2 in + let ls = + List.map4 + (fun ps1 ps2 i1 i2 -> + let s1 = sub_ps_to_sub_ps_bp (sub_ps_apply_sub i1 s1) in + let s2 = sub_ps_to_sub_ps_bp (sub_ps_apply_sub i2 s2) in + let hom_sub = pullback_up (i - 1) ps1 ps2 s1.sub_ps s2.sub_ps in + { sub_ps = hom_sub; l = s1.l; r = s1.r }) + l1 l2 incls1 incls2 + in + wedge_sub_ps_bp ls let rec tm_contains_var t x = match t with | Var v -> v = x - | Coh(_,s) -> List.exists (fun (t,_) -> tm_contains_var t x) s + | Coh (_, s) -> List.exists (fun (t, _) -> tm_contains_var t x) s | Meta_tm _ -> Error.fatal "meta-variables should be resolved" - let rec ty_contains_var a x = - match a with - | Obj -> false - | Arr(a,t,u) -> tm_contains_var t x - || tm_contains_var u x - || ty_contains_var a x - | Meta_ty _ -> Error.fatal "meta-variables should be resolved" + let rec ty_contains_var a x = + match a with + | Obj -> false + | Arr (a, t, u) -> + tm_contains_var t x || tm_contains_var u x || ty_contains_var a x + | Meta_ty _ -> Error.fatal "meta-variables should be resolved" - let tm_contains_vars t l = - List.exists (tm_contains_var t) l + let tm_contains_vars t l = List.exists (tm_contains_var t) l let rec list_to_sub s ctx = - match s,ctx with - | t::s, (x,_)::ctx -> (x,t)::(list_to_sub s ctx) - | [],[] -> [] + match (s, ctx) with + | t :: s, (x, _) :: ctx -> (x, t) :: list_to_sub s ctx + | [], [] -> [] | _ -> raise WrongNumberOfArguments let list_to_db_level_sub l = - let rec aux l = match l with - | [] -> [],0 - | t::l -> - let s,n = aux l in (Var.Db n,t)::s,n+1 - in fst (aux l) + let rec aux l = + match l with + | [] -> ([], 0) + | t :: l -> + let s, n = aux l in + ((Var.Db n, t) :: s, n + 1) + in + fst (aux l) let rec dim_ty = function | Obj -> 0 - | Arr(a,_,_) -> 1 + dim_ty a + | Arr (a, _, _) -> 1 + dim_ty a | Meta_ty _ -> Error.fatal "meta-variables should be resolved" let rec dim_ctx = function | [] -> 0 - | (_,(t,_))::c -> max (dim_ctx c) (dim_ty t) + | (_, (t, _)) :: c -> max (dim_ctx c) (dim_ty t) let rec ty_to_sub_ps a = match a with | Obj -> [] - | Arr(a,u,v) -> (v,false)::(u,false)::(ty_to_sub_ps a) - | Meta_ty _ -> Error.fatal "substitution can only be computed after\ - resolving the type" + | Arr (a, u, v) -> (v, false) :: (u, false) :: ty_to_sub_ps a + | Meta_ty _ -> + Error.fatal + "substitution can only be computed afterresolving the type" let coh_to_sub_ps t = match t with - | Coh(coh,s) -> - begin - let _,ty,_ = Coh.forget coh in + | Coh (coh, s) -> + let _, ty, _ = Coh.forget coh in let sub = sub_ps_to_sub s in - (t,true)::(ty_to_sub_ps (ty_apply_sub ty sub)) - end + (t, true) :: ty_to_sub_ps (ty_apply_sub ty sub) | _ -> Error.fatal "can only convert coh to sub ps" - let sub_to_sub_ps ps s = - sub_ps_apply_sub (identity_ps ps) s + let sub_to_sub_ps ps s = sub_ps_apply_sub (identity_ps ps) s end end diff --git a/lib/unchecked.mli b/lib/unchecked.mli index 0e372311..77caf8e2 100644 --- a/lib/unchecked.mli +++ b/lib/unchecked.mli @@ -1,19 +1,19 @@ open Common open Unchecked_types -module Unchecked (Coh : sig type t end) : sig - open Unchecked_types (Coh) +module Unchecked (Coh : sig + type t +end) : sig + open Unchecked_types(Coh) - module Make - (_ : sig - val forget : Coh.t -> ps * Unchecked_types(Coh).ty * coh_pp_data - val to_string : Coh.t -> string - val func_data : Coh.t -> (Var.t * int) list - val check_equal : Coh.t -> Coh.t -> unit - val check : ps -> ty -> coh_pp_data -> Coh.t - end) : sig - - type sub_ps_bp = {sub_ps : sub_ps; l : tm; r : tm} + module Make (_ : sig + val forget : Coh.t -> ps * Unchecked_types(Coh).ty * coh_pp_data + val to_string : Coh.t -> string + val func_data : Coh.t -> (Var.t * int) list + val check_equal : Coh.t -> Coh.t -> unit + val check : ps -> ty -> coh_pp_data -> Coh.t + end) : sig + type sub_ps_bp = { sub_ps : sub_ps; l : tm; r : tm } val ps_to_string : ps -> string val ty_to_string : ty -> string @@ -24,12 +24,10 @@ module Unchecked (Coh : sig type t end) : sig val meta_ctx_to_string : meta_ctx -> string val coh_pp_data_to_string : ?print_func:bool -> coh_pp_data -> string val full_name : coh_pp_data -> string - val check_equal_ctx : ctx -> ctx -> unit val check_equal_ps : ps -> ps -> unit val check_equal_ty : ty -> ty -> unit val check_equal_tm : tm -> tm -> unit - val dim_ctx : ctx -> int val dim_ty : ty -> int val dim_ps : ps -> int @@ -40,7 +38,7 @@ module Unchecked (Coh : sig type t end) : sig val sub_ps_apply_sub : sub_ps -> sub -> sub_ps val ty_apply_sub_ps : ty -> sub_ps -> ty val tm_apply_sub_ps : tm -> sub_ps -> tm - val sub_ps_apply_sub_ps: sub_ps -> sub_ps -> sub_ps + val sub_ps_apply_sub_ps : sub_ps -> sub_ps -> sub_ps val ty_sub_preimage : ty -> sub -> ty val db_levels : ctx -> ctx * (Var.t * int) list * int val db_level_sub : ctx -> sub @@ -60,7 +58,6 @@ module Unchecked (Coh : sig type t end) : sig val ps_bdry : ps -> ps val ps_src : ps -> sub_ps val ps_tgt : ps -> sub_ps - val tm_sub_preimage : tm -> sub -> tm val suspwedge_subs_ps : sub_ps list -> ps list -> sub_ps val opsuspwedge_subs_ps : sub_ps list -> ps list -> sub_ps diff --git a/lib/unchecked_types.ml b/lib/unchecked_types.ml index bbb6ece8..dac3a5f6 100644 --- a/lib/unchecked_types.ml +++ b/lib/unchecked_types.ml @@ -1,41 +1,28 @@ open Common -module type Unchecked_types_sig = functor (Coh : sig type t end) -> -sig - type ty = - | Meta_ty of int - | Obj - | Arr of ty * tm * tm - and tm = - | Var of Var.t - | Meta_tm of int - | Coh of Coh.t * sub_ps - +module type Unchecked_types_sig = functor + (Coh : sig + type t + end) + -> sig + type ty = Meta_ty of int | Obj | Arr of ty * tm * tm + and tm = Var of Var.t | Meta_tm of int | Coh of Coh.t * sub_ps and sub_ps = (tm * bool) list type ctx = (Var.t * (ty * bool)) list - type sub = (Var.t * tm) list - - type meta_ctx = ((int * ty) list) + type meta_ctx = (int * ty) list end -module Unchecked_types (Coh : sig type t end) -= struct - type ty = - | Meta_ty of int - | Obj - | Arr of ty * tm * tm - and tm = - | Var of Var.t - | Meta_tm of int - | Coh of Coh.t * sub_ps - +module Unchecked_types (Coh : sig + type t +end) = +struct + type ty = Meta_ty of int | Obj | Arr of ty * tm * tm + and tm = Var of Var.t | Meta_tm of int | Coh of Coh.t * sub_ps and sub_ps = (tm * bool) list type ctx = (Var.t * (ty * bool)) list - type sub = (Var.t * tm) list - - type meta_ctx = ((int * ty) list) + type meta_ctx = (int * ty) list end diff --git a/lib/unchecked_types.mli b/lib/unchecked_types.mli index 56703a77..de1226ec 100644 --- a/lib/unchecked_types.mli +++ b/lib/unchecked_types.mli @@ -1,23 +1,17 @@ open Common -module type Unchecked_types_sig = functor (Coh : sig type t end) -> -sig - type ty = - | Meta_ty of int - | Obj - | Arr of ty * tm * tm - and tm = - | Var of Var.t - | Meta_tm of int - | Coh of Coh.t * sub_ps - +module type Unchecked_types_sig = functor + (Coh : sig + type t + end) + -> sig + type ty = Meta_ty of int | Obj | Arr of ty * tm * tm + and tm = Var of Var.t | Meta_tm of int | Coh of Coh.t * sub_ps and sub_ps = (tm * bool) list type ctx = (Var.t * (ty * bool)) list - type sub = (Var.t * tm) list - - type meta_ctx = ((int * ty) list) + type meta_ctx = (int * ty) list end module Unchecked_types : Unchecked_types_sig diff --git a/pages/catt.css b/pages/catt.css deleted file mode 100644 index 1ed3a503..00000000 --- a/pages/catt.css +++ /dev/null @@ -1,43 +0,0 @@ -body { - margin: 2% 10%; - font-family: sans-serif; - font-size: 11pt; -} - -a { - color: darkblue; - text-decoration: none; -} - -a:hover { - text-decoration: underline; -} - -h1 { - text-align: center; -} - -#send { - visibility: hidden; -} - -#toplevel { - text-align: center; -} - -textarea { - color: lightgreen; - background-color: black; - width: 100%; - font-size: 11pt; - font-weight: bold; -} - -pre { - color: darkred; - background: whitesmoke; - font-size: 11pt; - width: 100%; - overflow-x: scroll; - overflow-y: visible; -} diff --git a/pages/catt.html b/pages/catt.html deleted file mode 100644 index 991cd638..00000000 --- a/pages/catt.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - CATT - - - - - -

CATT
=^.^=

-

- Coherences for weak ω-categories. -

- -
- - - - diff --git a/pages/test.catt b/pages/test.catt deleted file mode 100644 index a136fd6d..00000000 --- a/pages/test.catt +++ /dev/null @@ -1,191 +0,0 @@ -coh id (x : *) : x -> x. - -coh comp (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) ( f2 : x2 -> x3) : x1 -> x3. - -coh comp3 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) : x1 -> x4. - -coh comp4 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) : -x1 -> x5. - -coh comp5 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6): -x1 -> x6. - -coh comp6 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7): -x1 -> x7. - -coh comp7 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8): -x1 -> x8. - -coh comp8 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8) (x9 : *) (f8 : x8 -> x9): -x1 -> x9. - -coh comp9 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8) (x9 : *) (f8 : x8 -> x9) (x10 : *) (f9 : x9 -> x10): -x1 -> x10. - -coh comp10 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8) (x9 : *) (f8 : x8 -> x9) (x10 : *) (f9 : x9 -> x10) (x11 : *) (f10 : x10 -> x11): -x1 -> x11. - -coh comp11 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8) (x9 : *) (f8 : x8 -> x9) (x10 : *) (f9 : x9 -> x10) (x11 : *) (f10 : x10 -> x11) (x12 : *) (f11 : x11 -> x12): -x1 -> x12. - -coh whiskl (x : *) (y : *) (f : x -> y) (z : *) (g1 : y -> z) (g2 : y -> z) (a : g1 -> g2) : -comp f g1 -> comp f g2. - -coh whiskr (x : *) (y : *) (f1 : x -> y) (f2 : x -> y) (a : f1 -> f2) (z : *) (g : y -> z) : -comp f1 g -> comp f2 g. - -coh hcomp (x : *) (y : *) (f1 : x -> y) (f2 : x -> y) (a : f1 -> f2) (z : *) (g1 : y -> z) (g2 : y -> z) (b : g1 -> g2) : -comp f1 g1 -> comp f2 g2. - -coh unitl (x : *) (y : *) (f : x -> y) : comp (id x) f -> f. -coh unitl- (x : *) (y : *) (f : x -> y) : f -> comp (id x) f. - -coh unitr (x : *) (y : *) (f : x -> y) : comp f (id y) -> f. -coh unitr- (x : *) (y : *) (f : x -> y) : f -> comp f (id y). - -coh hunitl- (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g): a -> comp3 (unitl- f) (hcomp (id (id x)) a) (unitl g). -coh hunitr- (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g): a -> comp3 (unitr- f) (hcomp a (id (id y))) (unitr g). - -coh hunitl (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g): comp3 (unitl- f) (hcomp (id (id x)) a) (unitl g) -> a. -coh hunitr (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g): comp3 (unitr- f) (hcomp a (id (id y))) (unitr g) -> a. - - -coh exch (x : *) - (y : *) (f1 : x -> y) - (f2 : x -> y) (a1 : f1 -> f2) - (f3 : x -> y) (a2 : f2 -> f3) - (z : *) (g1 : y -> z) - (g2 : y -> z) (b1 : g1 -> g2) - (g3 : y -> z) (b2 : g2 -> g3) : -comp (hcomp a1 b1) (hcomp a2 b2) -> hcomp (comp a1 a2) (comp b1 b2). - -coh exch- (x : *) - (y : *) (f1 : x -> y) - (f2 : x -> y) (a1 : f1 -> f2) - (f3 : x -> y) (a2 : f2 -> f3) - (z : *) (g1 : y -> z) - (g2 : y -> z) (b1 : g1 -> g2) - (g3 : y -> z) (b2 : g2 -> g3) : -hcomp (comp a1 a2) (comp b1 b2) -> comp (hcomp a1 b1) (hcomp a2 b2). - - -check (x : *) (y : *) (z : *) (t : *) (f1 : x -> y) (f2 : x -> y) (g1 : y -> z) (g2 : y -> z) (h1 : z -> t) (h2 : z -> t) (a : f1 -> f2) (b : g1 -> g2) (c : h1 -> h2) = hcomp a (hcomp b c). - -check (x : *) (alpha : id (id x) -> id (id x)) (beta: id (id x) -> id (id x)) = hcomp alpha beta. - -coh assoc6 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) - (x5 : *) (f5 : x4 -> x5) - (x6 : *) (f6 : x5 -> x6) : - comp (comp3 f1 f2 f3) (comp3 f4 f5 f6) -> comp5 f1 f2 (comp f3 f4) f5 f6. - -coh assoc6- (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) - (x5 : *) (f5 : x4 -> x5) - (x6 : *) (f6 : x5 -> x6) : - comp5 f1 f2 (comp f3 f4) f5 f6 -> comp (comp3 f1 f2 f3) (comp3 f4 f5 f6). - - -check (x : *) (a : id x -> id x) (b : id x -> id x) = assoc6 (unitl- (id x)) (hcomp (id (id x)) a) (unitl (id x)) (unitr- (id x)) (hcomp b (id (id x))) (unitr (id x)). - -coh hinv (x : *) : comp (unitl (id x)) (unitr- (id x)) -> id (comp (id x) (id x)). -coh hinv- (x : *) : id (comp (id x) (id x)) -> comp (unitr (id x)) (unitl- (id x)). - -coh equivlr- (x : *) : unitl- (id x) -> unitr- (id x). -coh equivrl (x : *) : unitr (id x) -> unitl (id x). - -coh rew5 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) (g3 : x2 -> x3) (a : f3 -> g3) - (x4 : *) (f4 : x3 -> x4) - (x5 : *) (f5 : x4 -> x5) : - comp5 f1 f2 f3 f4 f5 -> comp5 f1 f2 g3 f4 f5. - -coh cancel5 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) : - comp5 f1 f2 (id x2) f3 f4 -> comp4 f1 f2 f3 f4. - -coh cancel5- (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) : - comp4 f1 f2 f3 f4 -> comp5 f1 f2 (id x2) f3 f4. - -coh assoc4 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) : - comp4 f1 f2 f3 f4 -> comp3 f1 (comp f2 f3) f4. - -coh assoc4- (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) : - comp3 f1 (comp f2 f3) f4 -> comp4 f1 f2 f3 f4. - - - -coh rew3 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) (g2 : x1 -> x2) (a : f2 -> g2) - (x3 : *) (f3 : x2 -> x3) : - comp3 f1 f2 f3 -> comp3 f1 g2 f3. - -coh rew1-3 (x0 : *) (x1 : *) (f1 : x0 -> x1) (g1 : x0 -> x1) (a : f1 -> g1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) (g3 : x2 -> x3) (b : f3 -> g3) : - comp3 f1 f2 f3 -> comp3 g1 f2 g3. - -check (x : *) (a : id x -> id x) (b : id x -> id x) = - rew3 (unitl- (id x)) (exch (id (id x)) b a (id (id x))) (unitr (id x)). - -coh hrew (x : *) (y : *) (f : x -> y) (g : x -> y) (a0 : f -> g) (a1 : f -> g) (al : a0 -> a1) - (z : *) (h : y -> z) (k : y -> z) (b0 : h -> k) (b1 : h -> k) (bet : b0 -> b1) - : - hcomp a0 b0 -> hcomp a1 b1. - -check (x : *) (a : id x -> id x) (b : id x -> id x) = - rew3 (unitl- (id x)) (hrew (unitl b) (unitr a)) (unitr (id x)). - - -let half-eh1 (x : *) (a : id x -> id x) (b : id x -> id x) = -comp6 (hcomp (hunitl- a) (hunitr- b)) - (assoc6 (unitl- (id x)) (hcomp (id (id x)) a) (unitl (id x)) (unitr- (id x)) (hcomp b (id (id x))) (unitr (id x))) - (rew5 (unitl- (id x)) (hcomp (id (id x)) a) (hinv x) (hcomp b (id (id x))) (unitr (id x))) - (cancel5 (unitl- (id x)) (hcomp (id (id x)) a) (hcomp b (id (id x))) (unitr (id x))) - (assoc4 (unitl- (id x)) (hcomp (id (id x)) a) (hcomp b (id (id x))) (unitr (id x))) - (rew3 (unitl- (id x)) (comp (exch (id (id x)) b a (id (id x))) (hrew (unitl b) (unitr a))) (unitr (id x))). - - - -check (x : *) (a : id x -> id x) (b : id x -> id x) = -(rew3 (unitl- (id x)) (exch- b (id (id x)) (id (id x)) a) (unitr (id x))). - -check (x : *) (a : id x -> id x) (b : id x -> id x) = -(assoc4- (unitl- (id x)) (hcomp b (id (id x))) (hcomp (id (id x)) a) (unitr (id x))). - -check (x : *) (a : id x -> id x) (b : id x -> id x) = -(cancel5- (unitl- (id x)) (hcomp b (id (id x))) (hcomp (id (id x)) a) (unitr (id x))). - -check (x : *) (a : id x -> id x) (b : id x -> id x) = -(hcomp (hunitr b) (hunitl a)). - - -let half-eh2 (x : *) (a : id x -> id x) (b : id x -> id x) = -comp6 (rew3 (unitr- (id x)) (comp (hrew (unitr- b) (unitl- a)) (exch- b (id (id x)) (id (id x)) a)) (unitl (id x))) -(assoc4- (unitr- (id x)) (hcomp b (id (id x))) (hcomp (id (id x)) a) (unitl (id x))) -(cancel5- (unitr- (id x)) (hcomp b (id (id x))) (hcomp (id (id x)) a) (unitl (id x))) -(rew5 (unitr- (id x)) (hcomp b (id (id x))) (hinv- x) (hcomp (id (id x)) a) (unitl (id x))) -(assoc6- (unitr- (id x)) (hcomp b (id (id x))) (unitr (id x)) (unitl- (id x)) (hcomp (id (id x)) a) (unitl (id x))) -(hcomp (hunitr b) (hunitl a)). - - -let eckmann-hilton (x : *) (a : id x -> id x) (b : id x -> id x) = -comp3 (half-eh1 x a b) - (rew1-3 (equivlr- x) (hcomp b a) (equivrl x)) - (half-eh2 x a b). \ No newline at end of file diff --git a/share/site-lisp/catt-mode.el b/share/site-lisp/catt-mode.el new file mode 100644 index 00000000..57f66f61 --- /dev/null +++ b/share/site-lisp/catt-mode.el @@ -0,0 +1,64 @@ +;; catt-mode.el -- CATT major emacs mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2017 Thibaut Benjamin + +;; Author: Thibaut Benjamin +;; Version: 0.1 +;; Package-Requires: ((emacs "27.1")) +;; Keywords: convenience +;; Homepage: https://github.com/thibautbenjamin/catt + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;;; Code: + +(defvar catt-font-lock-keywords + '( + ("#.*" . 'font-lock-comment-face) + ("\\<\\(let\\|check\\|set\\|coh\\|fcoh\\|hyp\\|eval\\|env\\)\\>\\|:\\|=" . font-lock-keyword-face) + ("\\<\\(Hom\\|Type\\)\\>\\|->" . font-lock-builtin-face) + ;; ("\\<\\(\\)\\>" . font-lock-constant-face) + ("\\" st) + st) + "Syntax table for CATT major mode.") + +(defvar catt-tab-width 4) + +(define-derived-mode catt-mode prog-mode + "CATT" "Major mode for CATT files." + :syntax-table catt-mode-syntax-table + (set (make-local-variable 'comment-start) "#") + (set (make-local-variable 'comment-start-skip) "#+\\s-*") + (set (make-local-variable 'font-lock-defaults) '(catt-font-lock-keywords)) + (setq mode-name "CATT") + ) + + +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.catt\\'" . catt-mode)) + +(provide 'catt-mode) +;;; catt-mode.el ends here diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 71e7def5..00000000 --- a/shell.nix +++ /dev/null @@ -1,6 +0,0 @@ -(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock); -in fetchTarball { - url = - lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; -}) { src = ./.; }).shellNix diff --git a/test.t/coverage/eckmann-hilton-optimized.catt b/test.t/coverage/eckmann-hilton-optimized.catt new file mode 100644 index 00000000..84eadbf4 --- /dev/null +++ b/test.t/coverage/eckmann-hilton-optimized.catt @@ -0,0 +1,19 @@ +coh unitl (x(f)y) : comp (id _) f -> f +coh unit (x) : comp (id x) (id x) -> id x +coh lsimp (x) : (unitl (id x)) -> unit x +coh Ilsimp (x) : I (unitl (id x)) -> I (unit x) +coh exch (x(f(a)g)y(h(b)k)z) : comp (comp _ [b]) (id (comp f k)) (comp [a] _) -> comp [a] [b] + +coh eh1 (x(f(a)g(b)h)y) : +comp a b -> comp (I (unitl f)) + (comp (comp _ [a]) (comp (unitl g) (I (op { 1 } (unitl g)))) (comp [b] _)) + (op { 1 } (unitl h)) + +let eh2 (x : *) (a : id x -> id x) (b : id x -> id x) = +comp [Ilsimp _] + [comp (comp _ [comp (comp [lsimp _] [op { 1 } (Ilsimp _)]) (U (unit _))] _) + (exch b a)] + [op { 1 } (lsimp _)] + +let eh (x : *) (a : id x -> id x) (b : id x -> id x) = +comp (eh1 a b) (eh2 a b) (I (op { 1 } (eh2 b a))) (I (op { 1 } (eh1 b a))) diff --git a/test/ps-syntax.catt b/test.t/coverage/eckmann-hilton-unoptimized.catt similarity index 100% rename from test/ps-syntax.catt rename to test.t/coverage/eckmann-hilton-unoptimized.catt diff --git a/test.t/fails/doubledvars.catt b/test.t/fails/doubledvars.catt new file mode 100644 index 00000000..2fc32c99 --- /dev/null +++ b/test.t/fails/doubledvars.catt @@ -0,0 +1,2 @@ +let fail1 (x : *) (x : *) = id x +coh fail2 (x(f)x) : x -> x diff --git a/test.t/fails/invalidcoherences.catt b/test.t/fails/invalidcoherences.catt new file mode 100644 index 00000000..c5879504 --- /dev/null +++ b/test.t/fails/invalidcoherences.catt @@ -0,0 +1,3 @@ +coh fail1 (x(f)y) : x -> x +coh fail2 (x(f(a)g)y(h(b)k)z) : x -> z +coh fail3 (x(f(a)g)y(h(b)k)z) : f -> g diff --git a/test.t/fails/invalidnaturality.catt b/test.t/fails/invalidnaturality.catt new file mode 100644 index 00000000..5884dfb0 --- /dev/null +++ b/test.t/fails/invalidnaturality.catt @@ -0,0 +1,2 @@ +let fail1 (x : *) (f : x -> x) = @comp x [f] f x f +coh whisk (x(f(a(m)b)g)y(h)z) : comp [a] h -> comp [b] h diff --git a/test.t/fails/invalidtypes.catt b/test.t/fails/invalidtypes.catt new file mode 100644 index 00000000..e58edae1 --- /dev/null +++ b/test.t/fails/invalidtypes.catt @@ -0,0 +1,4 @@ +coh fail1 (x(f)y) : x -> f +let fail2 (x : *) (y : *) (f : x -> y) (g : x -> f) = id x +coh fail3 (x : *) (y : *) (f : x -> y) (g : x -> f) : x -> y +let fail4 (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) : x -> f = comp f g diff --git a/test.t/fails/notps.catt b/test.t/fails/notps.catt new file mode 100644 index 00000000..96e2d798 --- /dev/null +++ b/test.t/fails/notps.catt @@ -0,0 +1,5 @@ +coh fail1 (x : *) (f : x -> x) : x -> x +coh fail2 (x : *) (y : *) (f : x -> y) (z : *) (g : z -> y) : x -> z +coh fail3 (x : *) (y : *) (f : x -> y) (z : *) (w : *) (g : z -> w) : x -> w +coh fail4 (x : *) (y : *) (z : *) (f : x -> y) (g : y -> z) : x -> z +coh fail5 (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) (a : comp f g -> comp f g) : x -> z diff --git a/test.t/fails/uninferrable.catt b/test.t/fails/uninferrable.catt new file mode 100644 index 00000000..b0d7d30c --- /dev/null +++ b/test.t/fails/uninferrable.catt @@ -0,0 +1,2 @@ +let fail1 (x : *) (y : *) = comp (id _) (id _) +coh fail2 (x(f)y) : comp (id _) _ -> f diff --git a/test.t/fails/wrongapplication.catt b/test.t/fails/wrongapplication.catt new file mode 100644 index 00000000..09f1d748 --- /dev/null +++ b/test.t/fails/wrongapplication.catt @@ -0,0 +1,8 @@ +let fail1 (x : *) (y : *) (f : x -> y) (g : x -> y) = comp f g +coh whisk (x(f(a)g)y(h)z) : comp f h -> comp g h +let fail2 (x : *) (y : *) (f : x -> y) + (z : *) (g : y -> z) (h : y -> z) (b : g -> h) = whisk f b +let fail3 (x : *) (y : *) (f : x -> y) + (z : *) (g : y -> z) (h : y -> z) (b : g -> h) = comp [f] b +let fail4 (x : *) (y : *) (f : x -> y) + (z : *) (g : y -> z) = comp [f] g diff --git a/test/builtin-comp.catt b/test.t/features/builtins.catt similarity index 99% rename from test/builtin-comp.catt rename to test.t/features/builtins.catt index 1b1b331d..757a17ce 100644 --- a/test/builtin-comp.catt +++ b/test.t/features/builtins.catt @@ -1,4 +1,3 @@ - coh unit (x(f)y) : comp f (id _) -> f coh unbiase (x(f)y(g)z(h)w) : comp (comp f g) h -> comp f g h diff --git a/test/functorialisation.catt b/test.t/features/functorialisation.catt similarity index 80% rename from test/functorialisation.catt rename to test.t/features/functorialisation.catt index 802e2268..1f2bdbdb 100644 --- a/test/functorialisation.catt +++ b/test.t/features/functorialisation.catt @@ -1,7 +1,3 @@ -set explicit_substitutions = f -# set unroll_coherences = t -# set print_explicit_substitutions = t - let whiskl (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g) (z : *) (h : y -> z) = comp [a] h let whiskr (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) (h : y -> z) (a : g -> h) = comp f [a] @@ -11,3 +7,6 @@ let comp302 (x : *) (y : *) (z : *) (f : x -> y) (g : x -> y ) (a : f -> g) (b : let comp303 (x : *) (y : *) (z : *) (f : x -> y) (g : x -> y ) (a : f -> g) (b : f -> g) (m : a -> b) (h : y -> z) (k : y -> z) (c : h -> k) (d : h -> k) (n : c -> d) = comp [[m]] [[n]] let comp504 (x : *) (y : *) (z : *) (f : x -> y) (g : x -> y ) (a : f -> g) (b : f -> g) (m : a -> b) (n : a -> b) (A : m -> n) (B : m -> n) (F : A -> B) (h : y -> z) (k : y -> z) (c : h -> k) (d : h -> k) (p : c -> d) (q : c -> d) (C : p -> q) = comp303 [[F]] [C] + +let comp-biased (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) (w : *) (h : z -> w) = comp (comp f g) h +check (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) (g' : y -> z) (a : g -> g') (w : *) (h : z -> w) = comp-biased f [a] h diff --git a/test/inverses.catt b/test.t/features/inverses.catt similarity index 100% rename from test/inverses.catt rename to test.t/features/inverses.catt diff --git a/test/bug.catt b/test.t/features/let-in.catt similarity index 55% rename from test/bug.catt rename to test.t/features/let-in.catt index a6b3a7b3..aafd4835 100644 --- a/test/bug.catt +++ b/test.t/features/let-in.catt @@ -1,5 +1,9 @@ - let id2 (x : *) = id (id x) let a (x : *) = let i = id2 x in i + +let f (x : *) = + let i = id x in + let j = id i in + j diff --git a/test/naturality.catt b/test.t/features/naturality.catt similarity index 98% rename from test/naturality.catt rename to test.t/features/naturality.catt index 0c714f41..0821ffcf 100644 --- a/test/naturality.catt +++ b/test.t/features/naturality.catt @@ -1,6 +1,3 @@ -# set verbosity = 5 -# set unroll_coherences = t - let idf (x : *) (y : *) (f : x -> y) : (comp (id x) f) -> (comp f (id y)) = id [f] coh whiskl (x(f)y(g(a)h)z) : comp f g -> comp f h diff --git a/test/opposites.catt b/test.t/features/opposites.catt similarity index 100% rename from test/opposites.catt rename to test.t/features/opposites.catt diff --git a/test.t/features/ps-syntax.catt b/test.t/features/ps-syntax.catt new file mode 100644 index 00000000..ba341e7a --- /dev/null +++ b/test.t/features/ps-syntax.catt @@ -0,0 +1,16 @@ +set implicit_suspension = f + +coh id (x) : x -> x +coh comp (x(f)y(g)z) : x -> z + +coh whiskr (x(f(a)f')y(g)z): comp f g -> comp f' g +coh whiskl (x(f)y(g(a)g')z): comp f g -> comp f g' +coh horiz (x(f(a)f')y(g(b)g')z): comp f g -> comp f' g' + +let sq (x : *) (f : x -> x) = comp f f + +let cbd (x : *) (f : x -> x) : x -> x = comp f (comp f f) + +coh simpl (x) : sq (id x) -> id x + +check (x : *) (f : x -> x) = comp (sq f) (cbd f) diff --git a/test/suspension.catt b/test.t/features/suspension.catt similarity index 94% rename from test/suspension.catt rename to test.t/features/suspension.catt index 33db1851..eaf05b16 100644 --- a/test/suspension.catt +++ b/test.t/features/suspension.catt @@ -1,6 +1,4 @@ -set explicit_substitutions = f set implicit_suspension = f - let comp2 (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g) (h : x -> y) (b : g -> h) = !comp a b let id3 (x : *) = !!id (!id (id x)) diff --git a/test/implicit_subs.catt b/test.t/features/unification.catt similarity index 64% rename from test/implicit_subs.catt rename to test.t/features/unification.catt index df8d0760..e1704c2e 100644 --- a/test/implicit_subs.catt +++ b/test.t/features/unification.catt @@ -1,12 +1,18 @@ -set explicit_substitutions = f +set implicit_suspension = f + +coh id (x : *) : x -> x + +coh comp (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) : x -> z coh whiskr (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) : comp f g -> comp f' g + (z : *) (g : y -> z) : + comp f g -> comp f' g coh whiskl (x : *) (y : *) (f : x -> y) - (z : *) (g : y -> z) (g' : y -> z) (a : g -> g') : comp f g -> comp f g' + (z : *) (g : y -> z) (g' : y -> z) (a : g -> g') : + comp f g -> comp f g' coh horiz (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') (z : *) (g : y -> z) (g' : y -> z) (b : g -> g') : - comp f g -> comp f' g' + comp f g -> comp f' g' let sq (x : *) (f : x -> x) = comp f f diff --git a/test/vanilla.catt b/test.t/features/vanilla.catt similarity index 64% rename from test/vanilla.catt rename to test.t/features/vanilla.catt index eb3c28e6..780227cc 100644 --- a/test/vanilla.catt +++ b/test.t/features/vanilla.catt @@ -1,12 +1,19 @@ set explicit_substitutions = t +set implicit_suspension = f + +coh id (x : *) : x -> x + +coh comp (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) : x -> z coh whiskr (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) : comp x y f z g -> comp x y f' z g + (z : *) (g : y -> z) : + comp x y f z g -> comp x y f' z g coh whiskl (x : *) (y : *) (f : x -> y) - (z : *) (g : y -> z) (g' : y -> z) (a : g -> g') : comp x y f z g -> comp x y f z g' + (z : *) (g : y -> z) (g' : y -> z) (a : g -> g') : + comp x y f z g -> comp x y f z g' coh horiz (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') (z : *) (g : y -> z) (g' : y -> z) (b : g -> g') : - comp x y f z g -> comp x y f' z g' + comp x y f z g -> comp x y f' z g' let sq (x : *) (f : x -> x) = comp x x f x f diff --git a/test.t/features/verbosity.catt b/test.t/features/verbosity.catt new file mode 100644 index 00000000..02606b30 --- /dev/null +++ b/test.t/features/verbosity.catt @@ -0,0 +1,8 @@ +set verbosity = 3 +coh comp3 (x(f)y(g)z(h)w) : x -> w + +let sq (x : *) (f : x -> x) = comp f f +let cbd (x : *) (f : x -> x) : x -> x = comp f (comp f f) + +coh simpl (x : *) : sq (id x) -> id x +check (x : *) (f : x -> x) = comp (sq f) (cbd f) diff --git a/test.t/features/wildcards.catt b/test.t/features/wildcards.catt new file mode 100644 index 00000000..b49989db --- /dev/null +++ b/test.t/features/wildcards.catt @@ -0,0 +1,4 @@ +coh id (x : *) : x -> x +coh comp (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) : x -> z +coh unitr (x : *) (y : *) (f : x -> y) : comp f (id _) -> f +coh unitl (x : *) (y : *) (f : x -> y) : comp (id _) f -> f diff --git a/test.t/run.t b/test.t/run.t new file mode 100644 index 00000000..88367239 --- /dev/null +++ b/test.t/run.t @@ -0,0 +1,626 @@ + $ catt --no-builtins features/vanilla.catt + [=^.^=] coh id = x -> x + [=I.I=] successfully defined id. + [=^.^=] coh comp = x -> z + [=I.I=] successfully defined comp. + [=^.^=] coh whiskr = (comp x y f z g) -> (comp x y f' z g) + [=I.I=] successfully defined whiskr. + [=^.^=] coh whiskl = (comp x y f z g) -> (comp x y f z g') + [=I.I=] successfully defined whiskl. + [=^.^=] coh horiz = (comp x y f z g) -> (comp x y f' z g') + [=I.I=] successfully defined horiz. + [=^.^=] let sq = (comp x x f x f) + [=I.I=] successfully defined term (comp f f) of type x -> x. + [=^.^=] let cbd = (comp x x f x (comp x x f x f)) + [=I.I=] successfully defined term (comp f (comp f f)) of type x -> x. + [=^.^=] coh simpl = (sq x (id x)) -> (id x) + [=I.I=] successfully defined simpl. + [=^.^=] check (comp x x (sq x f) x (cbd x f)) + [=I.I=] valid term (comp (comp f f) (comp f (comp f f))) of type x -> x. + + $ catt --no-builtins features/unification.catt + [=^.^=] coh id = x -> x + [=I.I=] successfully defined id. + [=^.^=] coh comp = x -> z + [=I.I=] successfully defined comp. + [=^.^=] coh whiskr = (comp f g) -> (comp f' g) + [=I.I=] successfully defined whiskr. + [=^.^=] coh whiskl = (comp f g) -> (comp f g') + [=I.I=] successfully defined whiskl. + [=^.^=] coh horiz = (comp f g) -> (comp f' g') + [=I.I=] successfully defined horiz. + [=^.^=] let sq = (comp f f) + [=I.I=] successfully defined term (comp f f) of type x -> x. + [=^.^=] let cbd = (comp f (comp f f)) + [=I.I=] successfully defined term (comp f (comp f f)) of type x -> x. + [=^.^=] coh simpl = (sq (id x)) -> (id x) + [=I.I=] successfully defined simpl. + [=^.^=] check (comp (sq f) (cbd f)) + [=I.I=] valid term (comp (comp f f) (comp f (comp f f))) of type x -> x. + + $ catt --no-builtins features/wildcards.catt + [=^.^=] coh id = x -> x + [=I.I=] successfully defined id. + [=^.^=] coh comp = x -> z + [=I.I=] successfully defined comp. + [=^.^=] coh unitr = (comp f (id _)) -> f + [=I.I=] successfully defined unitr. + [=^.^=] coh unitl = (comp (id _) f) -> f + [=I.I=] successfully defined unitl. + + $ catt --no-builtins features/ps-syntax.catt + [=^.^=] coh id = x -> x + [=I.I=] successfully defined id. + [=^.^=] coh comp = x -> z + [=I.I=] successfully defined comp. + [=^.^=] coh whiskr = (comp f g) -> (comp f' g) + [=I.I=] successfully defined whiskr. + [=^.^=] coh whiskl = (comp f g) -> (comp f g') + [=I.I=] successfully defined whiskl. + [=^.^=] coh horiz = (comp f g) -> (comp f' g') + [=I.I=] successfully defined horiz. + [=^.^=] let sq = (comp f f) + [=I.I=] successfully defined term (comp f f) of type x -> x. + [=^.^=] let cbd = (comp f (comp f f)) + [=I.I=] successfully defined term (comp f (comp f f)) of type x -> x. + [=^.^=] coh simpl = (sq (id x)) -> (id x) + [=I.I=] successfully defined simpl. + [=^.^=] check (comp (sq f) (cbd f)) + [=I.I=] valid term (comp (comp f f) (comp f (comp f f))) of type x -> x. + + $ catt features/builtins.catt + [=^.^=] coh unit = (_builtin_comp f (_builtin_id _)) -> f + [=I.I=] successfully defined unit. + [=^.^=] coh unbiase = (_builtin_comp (_builtin_comp f g) h) -> (_builtin_comp f g h) + [=I.I=] successfully defined unbiase. + [=^.^=] coh unit_bis = (_builtin_comp x y f y (_builtin_id y)) -> f + [=I.I=] successfully defined unit_bis. + [=^.^=] coh unbiase = (_builtin_comp _ _ (_builtin_comp _ _ f _ g) _ h) -> (_builtin_comp _ _ f _ g _ h) + [=I.I=] successfully defined unbiase. + + $ catt features/suspension.catt + [=^.^=] let comp2 = (!1 _builtin_comp a b) + [=I.I=] successfully defined term (!1builtin_comp2 a b) of type f -> h. + [=^.^=] let id3 = (!2 _builtin_id (!1 _builtin_id (_builtin_id x))) + [=I.I=] successfully defined term (!2builtin_id (!1builtin_id (builtin_id x))) of type (!1builtin_id (builtin_id x)) -> (!1builtin_id (builtin_id x)). + [=^.^=] let c = (_builtin_comp a b) + [=I.I=] successfully defined term (!1builtin_comp2 a b) of type f -> h. + [=^.^=] coh whisk = (_builtin_comp f h) -> (_builtin_comp g h) + [=I.I=] successfully defined whisk. + [=^.^=] let test = (whisk (_builtin_comp a b) k) + [=I.I=] successfully defined term (whisk (!1builtin_comp2 a b) k) of type (builtin_comp2 f k) -> (builtin_comp2 h k). + + $ catt features/verbosity.catt + [=^.^=] coh comp3 = x -> w + [=I.I=] inferring constraints for context: {x: *} {y: *} (f: _ty0 | x -> y) {z: *} (g: _ty1 | y -> z) {w: *} (h: _ty2 | z -> w). + [=I.I=] context elaborated to {x: *} {y: *} (f: * | x -> y) {z: *} (g: * | y -> z) {w: *} (h: * | z -> w). + [=I.I=] inferring constraints for type: _ty3 | x -> w. + [=I.I=] type elaborated to * | x -> w. + [=I.I=] checking coherence: comp3. + [=I.I=] successfully defined comp3. + [=^.^=] let sq = (_builtin_comp f f) + [=I.I=] inferring constraints for context: {x: *} (f: _ty4 | x -> x). + [=I.I=] context elaborated to {x: *} (f: * | x -> x). + [=I.I=] inferring constraints for term: (builtin_comp2 f f). + [=I.I=] term elaborated to (builtin_comp2 f f). + [=I.I=] checking term: (builtin_comp2 f f). + [=I.I=] successfully defined term (builtin_comp2 f f) of type * | x -> x. + [=^.^=] let cbd = (_builtin_comp f (_builtin_comp f f)) + [=I.I=] inferring constraints for context: {x: *} (f: _ty8 | x -> x). + [=I.I=] context elaborated to {x: *} (f: * | x -> x). + [=I.I=] inferring constraints for term: (builtin_comp2 f (builtin_comp2 f f)). + [=I.I=] term elaborated to (builtin_comp2 f (builtin_comp2 f f)). + [=I.I=] inferring constraints for context: {x: *} (f: _ty15 | x -> x). + [=I.I=] context elaborated to {x: *} (f: * | x -> x). + [=I.I=] inferring constraints for type: _ty16 | x -> x. + [=I.I=] type elaborated to * | x -> x. + [=I.I=] checking type: * | x -> x. + [=I.I=] checking term: (builtin_comp2 f (builtin_comp2 f f)). + [=I.I=] successfully defined term (builtin_comp2 f (builtin_comp2 f f)) of type * | x -> x. + [=^.^=] coh simpl = (sq (_builtin_id x)) -> (_builtin_id x) + [=I.I=] inferring constraints for context: (x: *). + [=I.I=] context elaborated to (x: *). + [=I.I=] inferring constraints for type: _ty18 | (builtin_comp2 (builtin_id x) (builtin_id x)) -> (builtin_id x). + [=I.I=] type elaborated to * | x -> x | (builtin_comp2 (builtin_id x) (builtin_id x)) -> (builtin_id x). + [=I.I=] checking coherence: simpl. + [=I.I=] successfully defined simpl. + [=^.^=] check (_builtin_comp (sq f) (cbd f)) + [=I.I=] inferring constraints for context: {x: *} (f: _ty19 | x -> x). + [=I.I=] context elaborated to {x: *} (f: * | x -> x). + [=I.I=] inferring constraints for term: (builtin_comp2 (builtin_comp2 f f) (builtin_comp2 f (builtin_comp2 f f))). + [=I.I=] term elaborated to (builtin_comp2 (builtin_comp2 f f) (builtin_comp2 f (builtin_comp2 f f))). + [=I.I=] checking term: (builtin_comp2 (builtin_comp2 f f) (builtin_comp2 f (builtin_comp2 f f))). + [=I.I=] valid term (builtin_comp2 (builtin_comp2 f f) (builtin_comp2 f (builtin_comp2 f f))) of type * | x -> x. + + $ catt features/let-in.catt + [=^.^=] let id2 = (_builtin_id (_builtin_id x)) + [=I.I=] successfully defined term (!1builtin_id (builtin_id x)) of type (builtin_id x) -> (builtin_id x). + [=^.^=] let a = let i = (id2 x) in i + [=I.I=] successfully defined term (!1builtin_id (builtin_id x)) of type (builtin_id x) -> (builtin_id x). + [=^.^=] let f = let i = (_builtin_id x) in let j = (_builtin_id i) in j + [=I.I=] successfully defined term (!1builtin_id (builtin_id x)) of type (builtin_id x) -> (builtin_id x). + + $ catt features/functorialisation.catt + [=^.^=] let whiskl = (_builtin_comp [a] h) + [=I.I=] successfully defined term (builtin_comp2 [a] h) of type (builtin_comp2 f h) -> (builtin_comp2 g h). + [=^.^=] let whiskr = (_builtin_comp f [a]) + [=I.I=] successfully defined term (builtin_comp2 f [a]) of type (builtin_comp2 f g) -> (builtin_comp2 f h). + [=^.^=] let whiskl2 = (whiskl [m] h) + [=I.I=] successfully defined term (builtin_comp2 [[m]] h) of type (builtin_comp2 [a] h) -> (builtin_comp2 [a'] h). + [=^.^=] let comp302 = (_builtin_comp [[m]] [c]) + [=I.I=] successfully defined term (builtin_comp2 [[m]] [c]) of type (builtin_comp2 [a] [c]) -> (builtin_comp2 [b] [c]). + [=^.^=] let comp303 = (_builtin_comp [[m]] [[n]]) + [=I.I=] successfully defined term (builtin_comp2 [[m]] [[n]]) of type (builtin_comp2 [a] [c]) -> (builtin_comp2 [b] [d]). + [=^.^=] let comp504 = (comp303 [[F]] [C]) + [=I.I=] successfully defined term (builtin_comp2 [[[[F]]]] [[[C]]]) of type (builtin_comp2 [[[A]]] [[[C]]]) -> (builtin_comp2 [[[B]]] [[[C]]]). + [=^.^=] let comp-biased = (_builtin_comp (_builtin_comp f g) h) + [=I.I=] successfully defined term (builtin_comp2 (builtin_comp2 f g) h) of type x -> w. + [=^.^=] check (comp-biased f [a] h) + [=I.I=] valid term (builtin_comp2 [(builtin_comp2 f [a])] h) of type (builtin_comp2 (builtin_comp2 f g) h) -> (builtin_comp2 (builtin_comp2 f g') h). + + $ catt features/opposites.catt + [=^.^=] let opcomp = op_{1}((_builtin_comp g f)) + [=I.I=] successfully defined term (builtin_comp2_op{1} x y f z g) of type x -> z. + [=^.^=] let opwhisk = op_{1}((_builtin_comp g [a])) + [=I.I=] successfully defined term (builtin_comp2_func[1]_op{1} x y f f' a z g) of type (builtin_comp2_op{1} x y f z g) -> (builtin_comp2_op{1} x y f' z g). + [=^.^=] coh test = (_builtin_comp f g) -> (_builtin_comp f'' g'') + [=I.I=] successfully defined test. + [=^.^=] let optest1 = op_{1}((test c d a b)) + [=I.I=] successfully defined term (test_op{1} x y f f' a f'' b z g g' c g'' d) of type (builtin_comp2_op{1} x y f z g) -> (builtin_comp2_op{1} x y f'' z g''). + [=^.^=] let optest2 = op_{2}((test b a d c)) + [=I.I=] successfully defined term (test_op{2} x y f f' a f'' b z g g' c g'' d) of type (builtin_comp2_op{2} x y f z g) -> (builtin_comp2_op{2} x y f'' z g''). + [=^.^=] let optest12 = op_{1,2}((test d c b a)) + [=I.I=] successfully defined term (test_op{1,2} x y f f' a f'' b z g g' c g'' d) of type (builtin_comp2_op{1,2} x y f z g) -> (builtin_comp2_op{1,2} x y f'' z g''). + [=^.^=] let nested1 = op_{1}((_builtin_comp [(_builtin_comp c d)] [(_builtin_comp a b)])) + [=I.I=] successfully defined term (builtin_comp2_func[1 1]_op{1} x y f f'' (!1builtin_comp2_op{1} x y f f' a f'' b) z g g'' (!1builtin_comp2_op{1} y z g g' c g'' d)) of type (builtin_comp2_op{1} x y f z g) -> (builtin_comp2_op{1} x y f'' z g''). + [=^.^=] let nested2 = op_{2}((_builtin_comp [(_builtin_comp b a)] [(_builtin_comp d c)])) + [=I.I=] successfully defined term (builtin_comp2_func[1 1]_op{2} x y f f'' (!1builtin_comp2_op{2} x y f f' a f'' b) z g g'' (!1builtin_comp2_op{2} y z g g' c g'' d)) of type (builtin_comp2_op{2} x y f z g) -> (builtin_comp2_op{2} x y f'' z g''). + [=^.^=] let nested12 = op_{1,2}((_builtin_comp [(_builtin_comp d c)] [(_builtin_comp b a)])) + [=I.I=] successfully defined term (builtin_comp2_func[1 1]_op{1,2} x y f f'' (!1builtin_comp2_op{1,2} x y f f' a f'' b) z g g'' (!1builtin_comp2_op{1,2} y z g g' c g'' d)) of type (builtin_comp2_op{1,2} x y f z g) -> (builtin_comp2_op{1,2} x y f'' z g''). + + $ catt features/inverses.catt + [=^.^=] let id_inv = I((_builtin_id x)) + [=I.I=] successfully defined term (builtin_id^-1 x) of type x -> x. + [=^.^=] coh assoc = (_builtin_comp (_builtin_comp f g) h) -> (_builtin_comp f (_builtin_comp g h)) + [=I.I=] successfully defined assoc. + [=^.^=] coh unbiase = (_builtin_comp f (_builtin_comp g h)) -> (_builtin_comp f g h) + [=I.I=] successfully defined unbiase. + [=^.^=] coh unitl = (_builtin_comp (_builtin_id x) f) -> f + [=I.I=] successfully defined unitl. + [=^.^=] coh 21comp = (_builtin_comp f k) -> (_builtin_comp h l) + [=I.I=] successfully defined 21comp. + [=^.^=] coh 2whisk = (_builtin_comp f k) -> (_builtin_comp h k) + [=I.I=] successfully defined 2whisk. + [=^.^=] let assoc_inv = I((assoc f g h)) + [=I.I=] successfully defined term (assoc^-1 f g h) of type (builtin_comp2 f (builtin_comp2 g h)) -> (builtin_comp2 (builtin_comp2 f g) h). + [=^.^=] let unbiase_inv = I((unbiase f g h)) + [=I.I=] successfully defined term (unbiase^-1 f g h) of type (builtin_comp3 f g h) -> (builtin_comp2 f (builtin_comp2 g h)). + [=^.^=] let unitl_inv = I((unitl f)) + [=I.I=] successfully defined term (unitl^-1 f) of type f -> (builtin_comp2 (builtin_id x) f). + [=^.^=] let assoc_unbiase_inv = I((_builtin_comp (assoc f f f) (unbiase f f f))) + [=I.I=] successfully defined term (!1builtin_comp2_op{2} (unbiase^-1 f f f) (assoc^-1 f f f)) of type (builtin_comp3 f f f) -> (builtin_comp2 (builtin_comp2 f f) f). + [=^.^=] let id_id_inv = I((_builtin_comp (_builtin_id x) (_builtin_id x))) + [=I.I=] successfully defined term (builtin_comp2_op{1} (builtin_id^-1 x) (builtin_id^-1 x)) of type x -> x. + [=^.^=] check I((_builtin_comp (_builtin_id x) [(_builtin_comp (assoc f f f) (unbiase f f f))] (_builtin_id x))) + [=I.I=] valid term (builtin_comp3_func[1]_op{2} (builtin_id x) (!1builtin_comp2_op{2} (unbiase^-1 f f f) (assoc^-1 f f f)) (builtin_id x)) of type (builtin_comp3_op{2} (builtin_id x) (builtin_comp3 f f f) (builtin_id x)) -> (builtin_comp3_op{2} (builtin_id x) (builtin_comp2 (builtin_comp2 f f) f) (builtin_id x)). + [=^.^=] check I((21comp (assoc f f f) (unbiase f f f) (assoc f f f))) + [=I.I=] valid term (21comp_op{2} (unbiase^-1 f f f) (assoc^-1 f f f) (assoc^-1 f f f)) of type (builtin_comp2_op{2} (builtin_comp3 f f f) (builtin_comp2 f (builtin_comp2 f f))) -> (builtin_comp2_op{2} (builtin_comp2 (builtin_comp2 f f) f) (builtin_comp2 (builtin_comp2 f f) f)). + [=^.^=] check I((2whisk (_builtin_id f) (_builtin_id f) f)) + [=I.I=] valid term (2whisk_op{2} (!1builtin_id^-1 f) (!1builtin_id^-1 f) f) of type (builtin_comp2_op{2} f f) -> (builtin_comp2_op{2} f f). + [=^.^=] check I((_builtin_comp [(_builtin_comp (assoc (_builtin_id f) (_builtin_id f) (_builtin_id f)) (unbiase (_builtin_id f) (_builtin_id f) (_builtin_id f)))] (_builtin_id f))) + [=I.I=] valid term (!1builtin_comp2_func[1]_op{3} (!2builtin_comp2_op{3} (!1unbiase^-1 (!1builtin_id f) (!1builtin_id f) (!1builtin_id f)) (!1assoc^-1 (!1builtin_id f) (!1builtin_id f) (!1builtin_id f))) (!1builtin_id f)) of type (!1builtin_comp2_op{3} (!1builtin_comp3 (!1builtin_id f) (!1builtin_id f) (!1builtin_id f)) (!1builtin_id f)) -> (!1builtin_comp2_op{3} (!1builtin_comp2 (!1builtin_comp2 (!1builtin_id f) (!1builtin_id f)) (!1builtin_id f)) (!1builtin_id f)). + [=^.^=] check I((_builtin_comp [(_builtin_comp (assoc f f f) (unbiase f f f))] (_builtin_comp (_builtin_id x) I((_builtin_id x))) [I((_builtin_comp (_builtin_id g) (_builtin_id g)))] (_builtin_id y))) + [=I.I=] valid term (builtin_comp4_func[1 1]_op{2} (!1builtin_comp2_op{2} (unbiase^-1 f f f) (assoc^-1 f f f)) (builtin_comp2 (builtin_id x) (builtin_id^-1 x)) (!1builtin_comp2_op{2}_op{2} (!1builtin_id^-1^-1 g) (!1builtin_id^-1^-1 g)) (builtin_id y)) of type (builtin_comp4_op{2} (builtin_comp3 f f f) (builtin_comp2 (builtin_id x) (builtin_id^-1 x)) g (builtin_id y)) -> (builtin_comp4_op{2} (builtin_comp2 (builtin_comp2 f f) f) (builtin_comp2 (builtin_id x) (builtin_id^-1 x)) g (builtin_id y)). + [=^.^=] check I((assoc x y f z g w h)) + [=I.I=] valid term (assoc^-1 f g h) of type (builtin_comp2 f (builtin_comp2 g h)) -> (builtin_comp2 (builtin_comp2 f g) h). + [=^.^=] check U((assoc f g h)) + [=I.I=] valid term (assoc_Unit f g h) of type (!1builtin_comp2 (builtin_comp2 (builtin_comp2 f g) h) (builtin_comp2 f (builtin_comp2 g h)) (assoc f g h) (assoc^-1 f g h)) -> (!1builtin_id (builtin_comp2 (builtin_comp2 f g) h)). + [=^.^=] check U((_builtin_comp (_builtin_id f) (_builtin_id f))) + [=I.I=] valid term (!2builtin_comp3 (vertical_grouping (!1builtin_id f) (!1builtin_id f) (!1builtin_id^-1 f) (!1builtin_id^-1 f)) (unbiased_comp_red [(!2builtin_comp4 (!1focus (!1builtin_id f) (!1builtin_id f) (!1builtin_id^-1 f) (!1builtin_id^-1 f)) (!1builtin_comp3 (!1builtin_id f) (!1builtin_id_Unit f) (!1builtin_id^-1 f)) (!1unit (!1builtin_id f) (!1builtin_id^-1 f)) (!1builtin_id_Unit f))]) (unbiased_unitor f)) of type (!1builtin_comp2 (!1builtin_comp2 (!1builtin_id f) (!1builtin_id f)) (!1builtin_comp2_op{2} (!1builtin_id^-1 f) (!1builtin_id^-1 f))) -> (!1builtin_id f). + [=^.^=] check U((_builtin_comp [(_builtin_id f)] [(_builtin_id g)])) + [=I.I=] valid term (!2builtin_comp3 (vertical_grouping (!1builtin_id f) (!1builtin_id^-1 f) (!1builtin_id g) (!1builtin_id^-1 g)) (unbiased_comp_red [(!1builtin_id_Unit f)] [(!1builtin_id_Unit g)]) (unbiased_unitor f g)) of type (!1builtin_comp2 (builtin_comp2 [(!1builtin_id f)] [(!1builtin_id g)]) (builtin_comp2_func[1 1]_op{2} (!1builtin_id^-1 f) (!1builtin_id^-1 g))) -> (!1builtin_id (builtin_comp2 f g)). + [=^.^=] check U((_builtin_comp (assoc f f f) (unbiase f f f))) + [=I.I=] valid term (!2builtin_comp3 (vertical_grouping (assoc f f f) (unbiase f f f) (unbiase^-1 f f f) (assoc^-1 f f f)) (unbiased_comp_red [(!2builtin_comp4 (!1focus (assoc f f f) (unbiase f f f) (unbiase^-1 f f f) (assoc^-1 f f f)) (!1builtin_comp3 (assoc f f f) (unbiase_Unit f f f) (assoc^-1 f f f)) (!1unit (assoc f f f) (assoc^-1 f f f)) (assoc_Unit f f f))]) (unbiased_unitor (builtin_comp2 (builtin_comp2 f f) f))) of type (!1builtin_comp2 (!1builtin_comp2 (assoc f f f) (unbiase f f f)) (!1builtin_comp2_op{2} (unbiase^-1 f f f) (assoc^-1 f f f))) -> (!1builtin_id (builtin_comp2 (builtin_comp2 f f) f)). + [=^.^=] check U((_builtin_comp (assoc f f g) (_builtin_id (_builtin_comp f (_builtin_comp f g))) (unbiase f f g) I((unbiase f f g)))) + [=I.I=] valid term (!2builtin_comp3 (vertical_grouping (assoc f f g) (!1builtin_id (builtin_comp2 f (builtin_comp2 f g))) (unbiase f f g) (unbiase^-1 f f g) (unbiase^-1^-1 f f g) (unbiase^-1 f f g) (!1builtin_id^-1 (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g)) (unbiased_comp_red [(!2builtin_comp4 (!1focus (assoc f f g) (!1builtin_id (builtin_comp2 f (builtin_comp2 f g))) (unbiase f f g) (unbiase^-1 f f g) (unbiase^-1^-1 f f g) (unbiase^-1 f f g) (!1builtin_id^-1 (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g)) (!1builtin_comp7 (assoc f f g) (!1builtin_id (builtin_comp2 f (builtin_comp2 f g))) (unbiase f f g) (unbiase^-1_Unit f f g) (unbiase^-1 f f g) (!1builtin_id^-1 (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g)) (!1unit (assoc f f g) (!1builtin_id (builtin_comp2 f (builtin_comp2 f g))) (unbiase f f g) (unbiase^-1 f f g) (!1builtin_id^-1 (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g)) (!2builtin_comp4 (!1focus (assoc f f g) (!1builtin_id (builtin_comp2 f (builtin_comp2 f g))) (unbiase f f g) (unbiase^-1 f f g) (!1builtin_id^-1 (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g)) (!1builtin_comp5 (assoc f f g) (!1builtin_id (builtin_comp2 f (builtin_comp2 f g))) (unbiase_Unit f f g) (!1builtin_id^-1 (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g)) (!1unit (assoc f f g) (!1builtin_id (builtin_comp2 f (builtin_comp2 f g))) (!1builtin_id^-1 (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g)) (!2builtin_comp4 (!1focus (assoc f f g) (!1builtin_id (builtin_comp2 f (builtin_comp2 f g))) (!1builtin_id^-1 (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g)) (!1builtin_comp3 (assoc f f g) (!1builtin_id_Unit (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g)) (!1unit (assoc f f g) (assoc^-1 f f g)) (assoc_Unit f f g))))]) (unbiased_unitor (builtin_comp2 (builtin_comp2 f f) g))) of type (!1builtin_comp2 (!1builtin_comp4 (assoc f f g) (!1builtin_id (builtin_comp2 f (builtin_comp2 f g))) (unbiase f f g) (unbiase^-1 f f g)) (!1builtin_comp4_op{2} (unbiase^-1^-1 f f g) (unbiase^-1 f f g) (!1builtin_id^-1 (builtin_comp2 f (builtin_comp2 f g))) (assoc^-1 f f g))) -> (!1builtin_id (builtin_comp2 (builtin_comp2 f f) g)). + [=^.^=] check U((21comp (assoc f f f) (unbiase f f f) (assoc g g g))) + [=I.I=] valid term (!2builtin_comp3 (vertical_grouping (assoc f f f) (unbiase f f f) (unbiase^-1 f f f) (assoc^-1 f f f) (assoc g g g) (assoc^-1 g g g)) (unbiased_comp_red [(!2builtin_comp4 (!1focus (assoc f f f) (unbiase f f f) (unbiase^-1 f f f) (assoc^-1 f f f)) (!1builtin_comp3 (assoc f f f) (unbiase_Unit f f f) (assoc^-1 f f f)) (!1unit (assoc f f f) (assoc^-1 f f f)) (assoc_Unit f f f))] [(assoc_Unit g g g)]) (unbiased_unitor (builtin_comp2 (builtin_comp2 f f) f) (builtin_comp2 (builtin_comp2 g g) g))) of type (!1builtin_comp2 (21comp (assoc f f f) (unbiase f f f) (assoc g g g)) (21comp_op{2} (unbiase^-1 f f f) (assoc^-1 f f f) (assoc^-1 g g g))) -> (!1builtin_id (builtin_comp2 (builtin_comp2 (builtin_comp2 f f) f) (builtin_comp2 (builtin_comp2 g g) g))). + + $ catt features/naturality.catt + [=^.^=] let idf = (_builtin_id [f]) + [=I.I=] successfully defined term (builtin_id [f]) of type (builtin_comp2 (builtin_id x) f) -> (builtin_comp2 f (builtin_id y)). + [=^.^=] coh whiskl = (_builtin_comp f g) -> (_builtin_comp f h) + [=I.I=] successfully defined whiskl. + [=^.^=] let whisklf = (whiskl [a] b) + [=I.I=] successfully defined term (whiskl [a] b) of type (!1builtin_comp2 (whiskl f b) (builtin_comp2 [a] k)) -> (!1builtin_comp2 (builtin_comp2 [a] h) (whiskl g b)). + [=^.^=] let whisklf = (whiskl f [m]) + [=I.I=] successfully defined term (whiskl f [m]) of type (whiskl f b) -> (whiskl f c). + [=^.^=] coh assoc = (_builtin_comp (_builtin_comp f g) h) -> (_builtin_comp f (_builtin_comp g h)) + [=I.I=] successfully defined assoc. + [=^.^=] let nat_assoc = (assoc [a] [b] [c]) + [=I.I=] successfully defined term (assoc [a] [b] [c]) of type (!1builtin_comp2 (assoc f g h) (builtin_comp2 [a] [(builtin_comp2 [b] [c])])) -> (!1builtin_comp2 (builtin_comp2 [(builtin_comp2 [a] [b])] [c]) (assoc f' g' h')). + [=^.^=] let whiskL = (_builtin_comp f [a]) + [=I.I=] successfully defined term (builtin_comp2 f [a]) of type (builtin_comp2 f g) -> (builtin_comp2 f h). + [=^.^=] let nat_assoc = (assoc [a] [[B]] [c]) + [=I.I=] successfully defined term (assoc [a] [[B]] [c]) of type (!2builtin_comp2 (assoc [a] [b] [c]) (!1builtin_comp2 [(builtin_comp2 [[(builtin_comp2 [a] [[B]])]] [c])] (assoc f' g' h'))) -> (!2builtin_comp2 (!1builtin_comp2 (assoc f g h) [(builtin_comp2 [a] [[(builtin_comp2 [[B]] [c])]])]) (assoc [a] [b'] [c])). + [=^.^=] let exch = (whiskl [a] b) + [=I.I=] successfully defined term (whiskl [a] b) of type (!1builtin_comp2 (whiskl f b) (builtin_comp2 [a] g')) -> (!1builtin_comp2 (builtin_comp2 [a] g) (whiskl f' b)). + [=^.^=] coh whiskl3 = (_builtin_comp f [a]) -> (_builtin_comp f [b]) + [=I.I=] successfully defined whiskl3. + [=^.^=] let nat_whiskl3 = (whiskl3 [c] m) + [=I.I=] successfully defined term (whiskl3 [c] m) of type (!2builtin_comp2 (!1builtin_comp2 (whiskl3 f m) (builtin_comp2 [c] h)) (builtin_comp2 [c] [b])) -> (!2builtin_comp2 (builtin_comp2 [c] [a]) (!1builtin_comp2 (builtin_comp2 [c] g) (whiskl3 f' m))). + [=^.^=] coh whiskl4 = (_builtin_comp f [[[p]]]) -> (_builtin_comp f [[[p]]]) + [=I.I=] successfully defined whiskl4. + [=^.^=] coh id2 = (_builtin_comp (_builtin_id x) (_builtin_id x) (_builtin_id x)) -> (_builtin_comp (_builtin_id x)) + [=I.I=] successfully defined id2. + [=^.^=] let nat_id2 = (id2 [f]) + [=I.I=] successfully defined term (id2 [f]) of type (!1builtin_comp2 (builtin_comp2 [(id2 x)] f) (!1builtin_comp3 (intch_src (builtin_id x) f) (builtin_comp1_red [(builtin_id [f])]) (intch_tgt f (builtin_id y)))) -> (!1builtin_comp2 (!1builtin_comp3 (intch_src (builtin_id x) (builtin_id x) (builtin_id x) f) (builtin_comp3_red [(!1builtin_comp7 (builtin_assc (builtin_id x) (builtin_id x) (builtin_id x) f) (builtin_comp3 (builtin_id x) (builtin_id x) [(builtin_id [f])]) (builtin_assc (builtin_id x) (builtin_id x) f (builtin_id y)) (builtin_comp3 (builtin_id x) [(builtin_id [f])] (builtin_id y)) (builtin_assc (builtin_id x) f (builtin_id y) (builtin_id y)) (builtin_comp3 [(builtin_id [f])] (builtin_id y) (builtin_id y)) (builtin_assc f (builtin_id y) (builtin_id y) (builtin_id y)))]) (intch_tgt f (builtin_id y) (builtin_id y) (builtin_id y))) (builtin_comp2 f [(id2 y)])). + [=^.^=] coh vcompwhisk = (_builtin_comp (_builtin_id x) f g) -> (_builtin_comp f (_builtin_id y) k) + [=I.I=] successfully defined vcompwhisk. + [=^.^=] let vcompwhisk2 = (vcompwhisk f (_builtin_id g) (_builtin_id g)) + [=I.I=] successfully defined term (vcompwhisk f (!1builtin_id g) (!1builtin_id g)) of type (builtin_comp3 (builtin_id x) f g) -> (builtin_comp3 f (builtin_id y) g). + [=^.^=] let nat_vcompwhisk = (vcompwhisk2 [a] [c]) + [=I.I=] successfully defined term (!2builtin_comp3 (intch_src f a (!1builtin_id g) (!1builtin_id g) c) (vcompwhisk_red a [(!2builtin_comp5 (!1builtin_assc (!1builtin_id g) (!1builtin_id g) c) (!1builtin_comp2 (!1builtin_id g) (!1builtin_id [c])) (!1builtin_assc (!1builtin_id g) c (!1builtin_id g')) (!1builtin_comp2 (!1builtin_id [c]) (!1builtin_id g')) (!1builtin_assc c (!1builtin_id g') (!1builtin_id g')))]) (intch_tgt a c (!1builtin_id g') (!1builtin_id g'))) of type (!1builtin_comp2 (vcompwhisk f (!1builtin_id g) (!1builtin_id g)) (builtin_comp3 [a] (builtin_id y) [c])) -> (!1builtin_comp2 (builtin_comp3 (builtin_id x) [a] [c]) (vcompwhisk f' (!1builtin_id g') (!1builtin_id g'))). + [=^.^=] let triangle1 = (_builtin_comp x [ym] [fm] z [gm]) + [=I.I=] successfully defined term (!1builtin_comp3 (intch_src f g) (builtin_comp2_red [(!1builtin_comp3 (builtin_comp2 f [gm]) (builtin_assc f ym g') (builtin_comp2 [fm] g'))]) (intch_tgt x f' g')) of type (builtin_comp2 f g) -> (builtin_comp2 f' g'). + [=^.^=] let triangle2 = (_builtin_comp [xm] y [fm] [zm] [gm]) + [=I.I=] successfully defined term (!1builtin_comp3 (intch_src f g zm) (builtin_comp2_red [(!1builtin_comp4 (builtin_assc f g zm) (builtin_comp2 f [gm]) (builtin_comp2 [fm] g') (builtin_assc xm f' g'))]) (intch_tgt xm f' g')) of type (builtin_comp2 (builtin_comp2 f g) zm) -> (builtin_comp2 xm (builtin_comp2 f' g')). + [=^.^=] let triangle1_bis = (@_builtin_comp _ [_] [fm] _ [gm]) + [=I.I=] successfully defined term (!1builtin_comp3 (intch_src f g) (builtin_comp2_red [(!1builtin_comp3 (builtin_comp2 f [gm]) (builtin_assc f ym g') (builtin_comp2 [fm] g'))]) (intch_tgt x f' g')) of type (builtin_comp2 f g) -> (builtin_comp2 f' g'). + [=^.^=] let triangle2_bis = (@_builtin_comp [_] _ [fm] [_] [gm]) + [=I.I=] successfully defined term (!1builtin_comp3 (intch_src f g zm) (builtin_comp2_red [(!1builtin_comp4 (builtin_assc f g zm) (builtin_comp2 f [gm]) (builtin_comp2 [fm] g') (builtin_assc xm f' g'))]) (intch_tgt xm f' g')) of type (builtin_comp2 (builtin_comp2 f g) zm) -> (builtin_comp2 xm (builtin_comp2 f' g')). + [=^.^=] coh example = (_builtin_comp f k (_builtin_id z)) -> (_builtin_comp h l) + [=I.I=] successfully defined example. + [=^.^=] let ex1 = (@example _ _ _ [_] [am] [_] [bm] _ _ [_] [cm]) + [=I.I=] successfully defined term (!2builtin_comp3 (intch_src a b hm c lm) (example_red [(!2builtin_comp4 (!1builtin_assc a b hm) (!1builtin_comp2 a bm) (!1builtin_assc a gm b+) (!1builtin_comp2 am b+))] [cm]) (intch_tgt f a+ b+ k c+)) of type (!1builtin_comp2 (example a b c) (builtin_comp2 [hm] [lm])) -> (example a+ b+ c+). + [=^.^=] let ex2 = (@example _ _ _ [_] [am] [_] [bm] _ [_] _ [cm]) + [=I.I=] successfully defined term (!2builtin_comp3 (intch_src a b hm c) (example_red [(!2builtin_comp4 (!1builtin_assc a b hm) (!1builtin_comp2 a bm) (!1builtin_assc a gm b+) (!1builtin_comp2 am b+))] [cm]) (intch_tgt f a+ b+ km c+)) of type (!1builtin_comp2 (example a b c) (builtin_comp2 [hm] l)) -> (!1builtin_comp2 (builtin_comp3 f [km] (builtin_id z)) (example a+ b+ c+)). + [=^.^=] let ex3 = (@example _ _ _ [_] [am] [_] [bm] _ [_] [_] [cm]) + [=I.I=] successfully defined term (!2builtin_comp3 (intch_src a b hm c lm) (example_red [(!2builtin_comp4 (!1builtin_assc a b hm) (!1builtin_comp2 a bm) (!1builtin_assc a gm b+) (!1builtin_comp2 am b+))] [cm]) (intch_tgt f a+ b+ km c+)) of type (!1builtin_comp2 (example a b c) (builtin_comp2 [hm] [lm])) -> (!1builtin_comp2 (builtin_comp3 f [km] (builtin_id z)) (example a+ b+ c+)). + + $ catt --keep-going fails/notps.catt + [=^.^=] coh fail1 = x -> x + [=X.X=] The following context is not a pasting scheme: + {x: *} (f: x -> x) + [=^.^=] coh fail2 = x -> z + [=X.X=] The following context is not a pasting scheme: + {x: *} {y: *} (f: x -> y) {z: *} (g: z -> y) + [=^.^=] coh fail3 = x -> w + [=X.X=] The following context is not a pasting scheme: + {x: *} {y: *} (f: x -> y) {z: *} {w: *} (g: z -> w) + [=^.^=] coh fail4 = x -> z + [=X.X=] The following context is not a pasting scheme: + {x: *} {y: *} {z: *} (f: x -> y) (g: y -> z) + [=^.^=] coh fail5 = x -> z + [=X.X=] The following context is not a pasting scheme: + {x: *} {y: *} {f: x -> y} {z: *} {g: y -> z} (a: (builtin_comp2 f g) -> (builtin_comp2 f g)) + + $ catt --keep-going fails/doubledvars.catt + [=^.^=] let fail1 = (_builtin_id x) + [=X.X=] The following context is invalid because variable x is repeated: + (x: *) (x: *) + [=^.^=] coh fail2 = x -> x + [=X.X=] The following context is invalid because variable x is repeated: + {x: *} {x: *} (f: x -> x) + + $ catt --keep-going fails/invalidcoherences.catt + [=^.^=] coh fail1 = x -> x + [=X.X=] The coherence fail1 is not valid for the following reason: + type .0 -> .0 not full in pasting scheme {.0: *} {.1: *} (.2: .0 -> .1) + [=^.^=] coh fail2 = x -> z + [=X.X=] The coherence fail2 is not valid for the following reason: + type .0 -> .5 not full in pasting scheme {.0: *} {.1: *} {.2: .0 -> .1} {.3: .0 -> .1} (.4: .2 -> .3) {.5: *} {.6: .1 -> .5} {.7: .1 -> .5} (.8: .6 -> .7) + [=^.^=] coh fail3 = f -> g + [=X.X=] The coherence fail3 is not valid for the following reason: + type .2 -> .3 not full in pasting scheme {.0: *} {.1: *} {.2: .0 -> .1} {.3: .0 -> .1} (.4: .2 -> .3) {.5: *} {.6: .1 -> .5} {.7: .1 -> .5} (.8: .6 -> .7) + + $ catt --keep-going fails/invalidtypes.catt + [=^.^=] coh fail1 = x -> f + [=X.X=] The constraints generated for the type: x -> f could not be solved for the following reason: + could not unify * and x -> y + [=^.^=] let fail2 = (_builtin_id x) + [=X.X=] The constraints generated for the context: {x: *} {y: *} {f: x -> y} (g: x -> f) could not be solved for the following reason: + could not unify * and x -> y + [=^.^=] coh fail3 = x -> y + [=X.X=] The constraints generated for the context: {x: *} {y: *} {f: x -> y} (g: x -> f) could not be solved for the following reason: + could not unify * and x -> y + [=^.^=] let fail4 = (_builtin_comp f g) + [=X.X=] The constraints generated for the type: x -> f could not be solved for the following reason: + could not unify * and x -> y + + $ catt --keep-going fails/wrongapplication.catt + [=^.^=] let fail1 = (_builtin_comp f g) + [=X.X=] The constraints generated for the term: (builtin_comp2 f g) could not be solved for the following reason: + could not unify x and y + [=^.^=] coh whisk = (_builtin_comp f h) -> (_builtin_comp g h) + [=I.I=] successfully defined whisk. + [=^.^=] let fail2 = (whisk f b) + [=X.X=] The constraints generated for the term: (whisk f b) could not be solved for the following reason: + could not unify * and _tm13 -> _tm12 + [=^.^=] let fail3 = (_builtin_comp [f] b) + [=X.X=] The constraints generated for the term: (!1builtin_comp2 [f] b) could not be solved for the following reason: + could not unify * and _tm18 -> _tm17 + [=^.^=] let fail4 = (_builtin_comp [f] g) + [=X.X=] The constraints generated for the term: (builtin_comp2 [f] g) could not be solved for the following reason: + could not unify * and _tm25 -> _tm24 + + $ catt --keep-going fails/invalidnaturality.catt + [=^.^=] let fail1 = (@_builtin_comp x [f] f x f) + [=X.X=] The constraints generated for the term: (!1builtin_comp3 (intch_src f f) (builtin_comp2_red [(!1builtin_comp1 (builtin_assc f f f))]) (intch_tgt x f f)) could not be solved for the following reason: + could not unify (builtin_comp2 f f) and f + [=^.^=] coh whisk = (_builtin_comp [a] h) -> (_builtin_comp [b] h) + [=I.I=] successfully defined whisk. + + $ catt --keep-going fails/uninferrable.catt + [=^.^=] let fail1 = (_builtin_comp (_builtin_id _) (_builtin_id _)) + [=X.X=] Incomplete constraints: some of the meta-variable could not be resolved in the following term: (builtin_comp2 (builtin_id _tm1) (builtin_id _tm1)) + [=^.^=] coh fail2 = (_builtin_comp (_builtin_id _) _) -> f + [=X.X=] Incomplete constraints: some of the meta-variable could not be resolved in the following coherence: fail2 + + $ catt coverage/eckmann-hilton-unoptimized.catt + [=^.^=] coh comp3 = x1 -> x4 + [=I.I=] successfully defined comp3. + [=^.^=] coh comp4 = x1 -> x5 + [=I.I=] successfully defined comp4. + [=^.^=] coh comp5 = x1 -> x6 + [=I.I=] successfully defined comp5. + [=^.^=] coh comp6 = x1 -> x7 + [=I.I=] successfully defined comp6. + [=^.^=] coh comp7 = x1 -> x8 + [=I.I=] successfully defined comp7. + [=^.^=] coh comp8 = x1 -> x9 + [=I.I=] successfully defined comp8. + [=^.^=] coh comp9 = x1 -> x10 + [=I.I=] successfully defined comp9. + [=^.^=] coh comp10 = x1 -> x11 + [=I.I=] successfully defined comp10. + [=^.^=] coh comp11 = x1 -> x12 + [=I.I=] successfully defined comp11. + [=^.^=] coh comp12 = x1 -> x13 + [=I.I=] successfully defined comp12. + [=^.^=] coh comp13 = x1 -> x14 + [=I.I=] successfully defined comp13. + [=^.^=] coh focus2 = (_builtin_comp (_builtin_comp f1 f2) (_builtin_comp f3 f4)) -> (comp3 f1 (_builtin_comp f2 f3) f4) + [=I.I=] successfully defined focus2. + [=^.^=] coh focus3 = (_builtin_comp (comp3 f1 f2 f3) (comp3 f4 f5 f6)) -> (comp5 f1 f2 (_builtin_comp f3 f4) f5 f6) + [=I.I=] successfully defined focus3. + [=^.^=] coh focus5 = (_builtin_comp (comp5 f1 f2 f3 f4 f5) (comp5 f6 f7 f8 f9 f10)) -> (comp9 f1 f2 f3 f4 (_builtin_comp f5 f6) f7 f8 f9 f10) + [=I.I=] successfully defined focus5. + [=^.^=] coh focus6 = (_builtin_comp (comp6 f1 f2 f3 f4 f5 f6) (comp6 f7 f8 f9 f10 f11 f12)) -> (comp11 f1 f2 f3 f4 f5 (_builtin_comp f6 f7) f8 f9 f10 f11 f12) + [=I.I=] successfully defined focus6. + [=^.^=] coh focus7 = (_builtin_comp (comp7 f1 f2 f3 f4 f5 f6 f7) (comp7 f8 f9 f10 f11 f12 f13 f14)) -> (comp13 f1 f2 f3 f4 f5 f6 (_builtin_comp f7 f8) f9 f10 f11 f12 f13 f14) + [=I.I=] successfully defined focus7. + [=^.^=] coh focus2- = (comp3 f1 (_builtin_comp f2 f3) f4) -> (_builtin_comp (_builtin_comp f1 f2) (_builtin_comp f3 f4)) + [=I.I=] successfully defined focus2-. + [=^.^=] coh focus3- = (comp5 f1 f2 (_builtin_comp f3 f4) f5 f6) -> (_builtin_comp (comp3 f1 f2 f3) (comp3 f4 f5 f6)) + [=I.I=] successfully defined focus3-. + [=^.^=] coh focus3U = (_builtin_comp (focus3 f1 f2 f3 f4 f5 f6) (focus3- f1 f2 f3 f4 f5 f6)) -> (_builtin_id (_builtin_comp (comp3 f1 f2 f3) (comp3 f4 f5 f6))) + [=I.I=] successfully defined focus3U. + [=^.^=] coh focus3CU = (_builtin_comp (focus3- f1 f2 f3 f4 f5 f6) (focus3 f1 f2 f3 f4 f5 f6)) -> (_builtin_id (comp5 f1 f2 (_builtin_comp f3 f4) f5 f6)) + [=I.I=] successfully defined focus3CU. + [=^.^=] coh id2@1 = (_builtin_comp (_builtin_id x) f) -> f + [=I.I=] successfully defined id2@1. + [=^.^=] coh id2@1- = f -> (_builtin_comp (_builtin_id x) f) + [=I.I=] successfully defined id2@1-. + [=^.^=] coh id2@2 = (_builtin_comp f (_builtin_id y)) -> f + [=I.I=] successfully defined id2@2. + [=^.^=] coh id2@2- = f -> (_builtin_comp f (_builtin_id y)) + [=I.I=] successfully defined id2@2-. + [=^.^=] coh id3@2 = (comp3 f1 (_builtin_id x2) f2) -> (_builtin_comp f1 f2) + [=I.I=] successfully defined id3@2. + [=^.^=] coh id3@2- = (_builtin_comp f1 f2) -> (comp3 f1 (_builtin_id x2) f2) + [=I.I=] successfully defined id3@2-. + [=^.^=] coh id5@3 = (comp5 f1 f2 (_builtin_id x3) f3 f4) -> (comp4 f1 f2 f3 f4) + [=I.I=] successfully defined id5@3. + [=^.^=] coh id5@3- = (comp4 f1 f2 f3 f4) -> (comp5 f1 f2 (_builtin_id x3) f3 f4) + [=I.I=] successfully defined id5@3-. + [=^.^=] coh id5@3U = (_builtin_comp (id5@3 f1 f2 f3 f4) (id5@3- f1 f2 f3 f4)) -> (_builtin_id (comp5 f1 f2 (_builtin_id x3) f3 f4)) + [=I.I=] successfully defined id5@3U. + [=^.^=] coh rew2@1 = (_builtin_comp f1 g) -> (_builtin_comp f2 g) + [=I.I=] successfully defined rew2@1. + [=^.^=] coh rew2@2 = (_builtin_comp f g1) -> (_builtin_comp f g2) + [=I.I=] successfully defined rew2@2. + [=^.^=] coh rew2A = (_builtin_comp f1 g1) -> (_builtin_comp f2 g2) + [=I.I=] successfully defined rew2A. + [=^.^=] coh rew3@2 = (comp3 f1 f2 f3) -> (comp3 f1 g2 f3) + [=I.I=] successfully defined rew3@2. + [=^.^=] coh rew3A = (comp3 f1 f2 f3) -> (comp3 g1 g2 g3) + [=I.I=] successfully defined rew3A. + [=^.^=] coh rew5@3 = (comp5 f1 f2 f3 f4 f5) -> (comp5 f1 f2 g3 f4 f5) + [=I.I=] successfully defined rew5@3. + [=^.^=] coh rew7@4 = (comp7 f1 f2 f3 f4 f5 f6 f7) -> (comp7 f1 f2 f3 g4 f5 f6 f7) + [=I.I=] successfully defined rew7@4. + [=^.^=] coh rew9@5 = (comp9 f1 f2 f3 f4 f5 f6 f7 f8 f9) -> (comp9 f1 f2 f3 f4 g5 f6 f7 f8 f9) + [=I.I=] successfully defined rew9@5. + [=^.^=] coh rew11@6 = (comp11 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11) -> (comp11 f1 f2 f3 f4 f5 g6 f7 f8 f9 f10 f11) + [=I.I=] successfully defined rew11@6. + [=^.^=] coh rew13@7 = (comp13 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13) -> (comp13 f1 f2 f3 f4 f5 f6 g7 f8 f9 f10 f11 f12 f13) + [=I.I=] successfully defined rew13@7. + [=^.^=] coh rew2compA = (_builtin_comp (rew2A a1 b1) (rew2A a2 b2)) -> (rew2A (_builtin_comp a1 a2) (_builtin_comp b1 b2)) + [=I.I=] successfully defined rew2compA. + [=^.^=] coh rew2compA- = (rew2A (_builtin_comp a1 a2) (_builtin_comp b1 b2)) -> (_builtin_comp (rew2A a1 b1) (rew2A a2 b2)) + [=I.I=] successfully defined rew2compA-. + [=^.^=] coh rew3comp@2 = (_builtin_comp (rew3@2 f1 a f3) (rew3@2 f1 b f3)) -> (rew3@2 f1 (_builtin_comp a b) f3) + [=I.I=] successfully defined rew3comp@2. + [=^.^=] coh rew3comp@2- = (rew3@2 f1 (_builtin_comp a b) f3) -> (_builtin_comp (rew3@2 f1 a f3) (rew3@2 f1 b f3)) + [=I.I=] successfully defined rew3comp@2-. + [=^.^=] coh rew3compA = (_builtin_comp (rew3A a1 b1 c1) (rew3A a2 b2 c2)) -> (rew3A (_builtin_comp a1 a2) (_builtin_comp b1 b2) (_builtin_comp c1 c2)) + [=I.I=] successfully defined rew3compA. + [=^.^=] coh rew5comp@3 = (_builtin_comp (rew5@3 f1 f2 a f4 f5) (rew5@3 f1 f2 b f4 f5)) -> (rew5@3 f1 f2 (_builtin_comp a b) f4 f5) + [=I.I=] successfully defined rew5comp@3. + [=^.^=] coh rew7comp@4 = (_builtin_comp (rew7@4 f1 f2 f3 a f5 f6 f7) (rew7@4 f1 f2 f3 b f5 f6 f7)) -> (rew7@4 f1 f2 f3 (_builtin_comp a b) f5 f6 f7) + [=I.I=] successfully defined rew7comp@4. + [=^.^=] coh rew2idA = (rew2A (_builtin_id f) (_builtin_id g)) -> (_builtin_id (_builtin_comp f g)) + [=I.I=] successfully defined rew2idA. + [=^.^=] coh rew3id@2 = (rew3@2 f1 (_builtin_id f2) f3) -> (_builtin_id (comp3 f1 f2 f3)) + [=I.I=] successfully defined rew3id@2. + [=^.^=] coh rew3id@2- = (_builtin_id (comp3 f1 f2 f3)) -> (rew3@2 f1 (_builtin_id f2) f3) + [=I.I=] successfully defined rew3id@2-. + [=^.^=] coh rew3idA = (rew3A (_builtin_id f1) (_builtin_id f2) (_builtin_id f3)) -> (_builtin_id (comp3 f1 f2 f3)) + [=I.I=] successfully defined rew3idA. + [=^.^=] coh rew5id@3 = (rew5@3 f1 f2 (_builtin_id f3) f4 f5) -> (_builtin_id (comp5 f1 f2 f3 f4 f5)) + [=I.I=] successfully defined rew5id@3. + [=^.^=] coh rew7id@4 = (rew7@4 f1 f2 f3 (_builtin_id f4) f5 f6 f7) -> (_builtin_id (comp7 f1 f2 f3 f4 f5 f6 f7)) + [=I.I=] successfully defined rew7id@4. + [=^.^=] coh rew2Aid@1 = (comp3 (id2@1- f) (rew2A (_builtin_id (_builtin_id x)) a) (id2@1 g)) -> a + [=I.I=] successfully defined rew2Aid@1. + [=^.^=] coh rew2Aid@1- = a -> (comp3 (id2@1- f) (rew2A (_builtin_id (_builtin_id x)) a) (id2@1 g)) + [=I.I=] successfully defined rew2Aid@1-. + [=^.^=] coh rew2Aid@2 = (comp3 (id2@2- f) (rew2A a (_builtin_id (_builtin_id y))) (id2@2 g)) -> a + [=I.I=] successfully defined rew2Aid@2. + [=^.^=] coh rew2Aid@2- = a -> (comp3 (id2@2- f) (rew2A a (_builtin_id (_builtin_id y))) (id2@2 g)) + [=I.I=] successfully defined rew2Aid@2-. + [=^.^=] coh rrew2A = (rew2A a0 b0) -> (rew2A a1 b1) + [=I.I=] successfully defined rrew2A. + [=^.^=] coh rrew3@2 = (rew3@2 f1 a f3) -> (rew3@2 f1 b f3) + [=I.I=] successfully defined rrew3@2. + [=^.^=] coh rrew3A = (rew3A a1 b1 c1) -> (rew3A a2 b2 c2) + [=I.I=] successfully defined rrew3A. + [=^.^=] coh rrew5@3 = (rew5@3 f1 f2 a f4 f5) -> (rew5@3 f1 f2 b f4 f5) + [=I.I=] successfully defined rrew5@3. + [=^.^=] coh rrew7@4 = (rew7@4 f1 f2 f3 a f5 f6 f7) -> (rew7@4 f1 f2 f3 b f5 f6 f7) + [=I.I=] successfully defined rrew7@4. + [=^.^=] coh rrew2compA = (_builtin_comp (rrew2A al1 bet1) (rrew2A al2 bet2)) -> (rrew2A (_builtin_comp al1 al2) (_builtin_comp bet1 bet2)) + [=I.I=] successfully defined rrew2compA. + [=^.^=] coh rrew2idA = (rrew2A (_builtin_id a0) (_builtin_id b0)) -> (_builtin_id (rew2A a0 b0)) + [=I.I=] successfully defined rrew2idA. + [=^.^=] coh rrrew2A = (rrew2A al0 bet0) -> (rrew2A al1 bet1) + [=I.I=] successfully defined rrrew2A. + [=^.^=] coh id2@/1-,2-/ = (id2@1- (_builtin_id x)) -> (id2@2- (_builtin_id x)) + [=I.I=] successfully defined id2@/1-,2-/. + [=^.^=] coh id2@/1-,2-/- = (id2@2- (_builtin_id x)) -> (id2@1- (_builtin_id x)) + [=I.I=] successfully defined id2@/1-,2-/-. + [=^.^=] coh id2@/1,2/ = (id2@1 (_builtin_id x)) -> (id2@2 (_builtin_id x)) + [=I.I=] successfully defined id2@/1,2/. + [=^.^=] coh id2@/1,2/- = (id2@2 (_builtin_id x)) -> (id2@1 (_builtin_id x)) + [=I.I=] successfully defined id2@/1,2/-. + [=^.^=] coh id2@2@1U = (_builtin_comp (id2@2 (_builtin_id x)) (id2@1- (_builtin_id x))) -> (_builtin_id (_builtin_comp (_builtin_id x) (_builtin_id x))) + [=I.I=] successfully defined id2@2@1U. + [=^.^=] coh id2@2@1U- = (_builtin_id (_builtin_comp (_builtin_id x) (_builtin_id x))) -> (_builtin_comp (id2@2 (_builtin_id x)) (id2@1- (_builtin_id x))) + [=I.I=] successfully defined id2@2@1U-. + [=^.^=] coh id2@1@2U = (_builtin_comp (id2@1 (_builtin_id x)) (id2@2- (_builtin_id x))) -> (_builtin_id (_builtin_comp (_builtin_id x) (_builtin_id x))) + [=I.I=] successfully defined id2@1@2U. + [=^.^=] coh id2@1@2U- = (_builtin_id (_builtin_comp (_builtin_id x) (_builtin_id x))) -> (_builtin_comp (id2@1 (_builtin_id x)) (id2@2- (_builtin_id x))) + [=I.I=] successfully defined id2@1@2U-. + [=^.^=] coh id5@3F = (comp5 f1 f2 (_builtin_id x3) f3 f4) -> (comp3 f1 (_builtin_comp f2 f3) f4) + [=I.I=] successfully defined id5@3F. + [=^.^=] coh id5@3F- = (comp3 f1 (_builtin_comp f2 f3) f4) -> (comp5 f1 f2 (_builtin_id x3) f3 f4) + [=I.I=] successfully defined id5@3F-. + [=^.^=] coh id5@3FU = (_builtin_comp (id5@3F f1 f2 f3 f4) (id5@3F- f1 f2 f3 f4)) -> (_builtin_id (comp5 f1 f2 (_builtin_id x3) f3 f4)) + [=I.I=] successfully defined id5@3FU. + [=^.^=] coh id5@3FCU = (_builtin_comp (id5@3F- f1 f2 f3 f4) (id5@3F f1 f2 f3 f4)) -> (_builtin_id (comp3 f1 (_builtin_comp f2 f3) f4)) + [=I.I=] successfully defined id5@3FCU. + [=^.^=] coh id7@4F = (comp7 f1 f2 f3 (_builtin_id x4) f4 f5 f6) -> (comp5 f1 f2 (_builtin_comp f3 f4) f5 f6) + [=I.I=] successfully defined id7@4F. + [=^.^=] coh id9@5F = (comp9 f1 f2 f3 f4 (_builtin_id x5) f5 f6 f7 f8) -> (comp7 f1 f2 f3 (_builtin_comp f4 f5) f6 f7 f8) + [=I.I=] successfully defined id9@5F. + [=^.^=] coh id11@6F = (comp11 f1 f2 f3 f4 f5 (_builtin_id x6) f6 f7 f8 f9 f10) -> (comp9 f1 f2 f3 f4 (_builtin_comp f5 f6) f7 f8 f9 f10) + [=I.I=] successfully defined id11@6F. + [=^.^=] coh id13@7F = (comp13 f1 f2 f3 f4 f5 f6 (_builtin_id x7) f7 f8 f9 f10 f11 f12) -> (comp11 f1 f2 f3 f4 f5 (_builtin_comp f6 f7) f8 f9 f10 f11 f12) + [=I.I=] successfully defined id13@7F. + [=^.^=] let simpl2 = (comp3 (rew3@2 f1 s2 f4) (id3@2 f1 f4) s1) + [=I.I=] successfully defined term (!1comp3 (rew3@2 f1 s2 f4) (id3@2 f1 f4) s1) of type (comp3 f1 (builtin_comp2 f2 f3) f4) -> (builtin_id x0). + [=^.^=] let simpl2- = (comp3 s1- (id3@2- f1 f4) (rew3@2 f1 s2- f4)) + [=I.I=] successfully defined term (!1comp3 s1- (id3@2- f1 f4) (rew3@2 f1 s2- f4)) of type (builtin_id x0) -> (comp3 f1 (builtin_comp2 f2 f3) f4). + [=^.^=] let simpl2F = (_builtin_comp (focus2 f1 f2 f3 f4) (simpl2 s1 s2)) + [=I.I=] successfully defined term (!1builtin_comp2 (focus2 f1 f2 f3 f4) (!1comp3 (rew3@2 f1 s2 f4) (id3@2 f1 f4) s1)) of type (builtin_comp2 (builtin_comp2 f1 f2) (builtin_comp2 f3 f4)) -> (builtin_id x0). + [=^.^=] let simpl2F- = (_builtin_comp (simpl2- s1- s2-) (focus2- f1 f2 f3 f4)) + [=I.I=] successfully defined term (!1builtin_comp2 (!1comp3 s1- (id3@2- f1 f4) (rew3@2 f1 s2- f4)) (focus2- f1 f2 f3 f4)) of type (builtin_id x0) -> (builtin_comp2 (builtin_comp2 f1 f2) (builtin_comp2 f3 f4)). + [=^.^=] let simpl3 = (comp3 (rew5@3 f1 f2 s3 f5 f6) (id5@3F f1 f2 f5 f6) (simpl2 s1 s2)) + [=I.I=] successfully defined term (!1comp3 (rew5@3 f1 f2 s3 f5 f6) (id5@3F f1 f2 f5 f6) (!1comp3 (rew3@2 f1 s2 f6) (id3@2 f1 f6) s1)) of type (comp5 f1 f2 (builtin_comp2 f3 f4) f5 f6) -> (builtin_id x0). + [=^.^=] let simpl3- = (comp3 (simpl2- s1- s2-) (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s3- f5 f6)) + [=I.I=] successfully defined term (!1comp3 (!1comp3 s1- (id3@2- f1 f6) (rew3@2 f1 s2- f6)) (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s3- f5 f6)) of type (builtin_id x0) -> (comp5 f1 f2 (builtin_comp2 f3 f4) f5 f6). + [=^.^=] let simpl3F = (_builtin_comp (focus3 f1 f2 f3 f4 f5 f6) (simpl3 s1 s2 s3)) + [=I.I=] successfully defined term (!1builtin_comp2 (focus3 f1 f2 f3 f4 f5 f6) (!1comp3 (rew5@3 f1 f2 s3 f5 f6) (id5@3F f1 f2 f5 f6) (!1comp3 (rew3@2 f1 s2 f6) (id3@2 f1 f6) s1))) of type (builtin_comp2 (comp3 f1 f2 f3) (comp3 f4 f5 f6)) -> (builtin_id x0). + [=^.^=] let simpl3F- = (_builtin_comp (simpl3- s1- s2- s3-) (focus3- f1 f2 f3 f4 f5 f6)) + [=I.I=] successfully defined term (!1builtin_comp2 (!1comp3 (!1comp3 s1- (id3@2- f1 f6) (rew3@2 f1 s2- f6)) (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s3- f5 f6)) (focus3- f1 f2 f3 f4 f5 f6)) of type (builtin_id x0) -> (builtin_comp2 (comp3 f1 f2 f3) (comp3 f4 f5 f6)). + [=^.^=] let simpl4 = (comp3 (rew7@4 f1 f2 f3 s4 f6 f7 f8) (id7@4F f1 f2 f3 f6 f7 f8) (simpl3 s1 s2 s3)) + [=I.I=] successfully defined term (!1comp3 (rew7@4 f1 f2 f3 s4 f6 f7 f8) (id7@4F f1 f2 f3 f6 f7 f8) (!1comp3 (rew5@3 f1 f2 s3 f7 f8) (id5@3F f1 f2 f7 f8) (!1comp3 (rew3@2 f1 s2 f8) (id3@2 f1 f8) s1))) of type (comp7 f1 f2 f3 (builtin_comp2 f4 f5) f6 f7 f8) -> (builtin_id x0). + [=^.^=] let simpl5 = (comp3 (rew9@5 f1 f2 f3 f4 s5 f7 f8 f9 f10) (id9@5F f1 f2 f3 f4 f7 f8 f9 f10) (simpl4 s1 s2 s3 s4)) + [=I.I=] successfully defined term (!1comp3 (rew9@5 f1 f2 f3 f4 s5 f7 f8 f9 f10) (id9@5F f1 f2 f3 f4 f7 f8 f9 f10) (!1comp3 (rew7@4 f1 f2 f3 s4 f8 f9 f10) (id7@4F f1 f2 f3 f8 f9 f10) (!1comp3 (rew5@3 f1 f2 s3 f9 f10) (id5@3F f1 f2 f9 f10) (!1comp3 (rew3@2 f1 s2 f10) (id3@2 f1 f10) s1)))) of type (comp9 f1 f2 f3 f4 (builtin_comp2 f5 f6) f7 f8 f9 f10) -> (builtin_id x0). + [=^.^=] let simpl5F = (_builtin_comp (focus5 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10) (simpl5 s1 s2 s3 s4 s5)) + [=I.I=] successfully defined term (!1builtin_comp2 (focus5 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10) (!1comp3 (rew9@5 f1 f2 f3 f4 s5 f7 f8 f9 f10) (id9@5F f1 f2 f3 f4 f7 f8 f9 f10) (!1comp3 (rew7@4 f1 f2 f3 s4 f8 f9 f10) (id7@4F f1 f2 f3 f8 f9 f10) (!1comp3 (rew5@3 f1 f2 s3 f9 f10) (id5@3F f1 f2 f9 f10) (!1comp3 (rew3@2 f1 s2 f10) (id3@2 f1 f10) s1))))) of type (builtin_comp2 (comp5 f1 f2 f3 f4 f5) (comp5 f6 f7 f8 f9 f10)) -> (builtin_id x0). + [=^.^=] let simpl6 = (comp3 (rew11@6 f1 f2 f3 f4 f5 s6 f8 f9 f10 f11 f12) (id11@6F f1 f2 f3 f4 f5 f8 f9 f10 f11 f12) (simpl5 s1 s2 s3 s4 s5)) + [=I.I=] successfully defined term (!1comp3 (rew11@6 f1 f2 f3 f4 f5 s6 f8 f9 f10 f11 f12) (id11@6F f1 f2 f3 f4 f5 f8 f9 f10 f11 f12) (!1comp3 (rew9@5 f1 f2 f3 f4 s5 f9 f10 f11 f12) (id9@5F f1 f2 f3 f4 f9 f10 f11 f12) (!1comp3 (rew7@4 f1 f2 f3 s4 f10 f11 f12) (id7@4F f1 f2 f3 f10 f11 f12) (!1comp3 (rew5@3 f1 f2 s3 f11 f12) (id5@3F f1 f2 f11 f12) (!1comp3 (rew3@2 f1 s2 f12) (id3@2 f1 f12) s1))))) of type (comp11 f1 f2 f3 f4 f5 (builtin_comp2 f6 f7) f8 f9 f10 f11 f12) -> (builtin_id x0). + [=^.^=] let simpl6F = (_builtin_comp (focus6 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12) (simpl6 s1 s2 s3 s4 s5 s6)) + [=I.I=] successfully defined term (!1builtin_comp2 (focus6 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12) (!1comp3 (rew11@6 f1 f2 f3 f4 f5 s6 f8 f9 f10 f11 f12) (id11@6F f1 f2 f3 f4 f5 f8 f9 f10 f11 f12) (!1comp3 (rew9@5 f1 f2 f3 f4 s5 f9 f10 f11 f12) (id9@5F f1 f2 f3 f4 f9 f10 f11 f12) (!1comp3 (rew7@4 f1 f2 f3 s4 f10 f11 f12) (id7@4F f1 f2 f3 f10 f11 f12) (!1comp3 (rew5@3 f1 f2 s3 f11 f12) (id5@3F f1 f2 f11 f12) (!1comp3 (rew3@2 f1 s2 f12) (id3@2 f1 f12) s1)))))) of type (builtin_comp2 (comp6 f1 f2 f3 f4 f5 f6) (comp6 f7 f8 f9 f10 f11 f12)) -> (builtin_id x0). + [=^.^=] let simpl7 = (comp3 (rew13@7 f1 f2 f3 f4 f5 f6 s7 f9 f10 f11 f12 f13 f14) (id13@7F f1 f2 f3 f4 f5 f6 f9 f10 f11 f12 f13 f14) (simpl6 s1 s2 s3 s4 s5 s6)) + [=I.I=] successfully defined term (!1comp3 (rew13@7 f1 f2 f3 f4 f5 f6 s7 f9 f10 f11 f12 f13 f14) (id13@7F f1 f2 f3 f4 f5 f6 f9 f10 f11 f12 f13 f14) (!1comp3 (rew11@6 f1 f2 f3 f4 f5 s6 f10 f11 f12 f13 f14) (id11@6F f1 f2 f3 f4 f5 f10 f11 f12 f13 f14) (!1comp3 (rew9@5 f1 f2 f3 f4 s5 f11 f12 f13 f14) (id9@5F f1 f2 f3 f4 f11 f12 f13 f14) (!1comp3 (rew7@4 f1 f2 f3 s4 f12 f13 f14) (id7@4F f1 f2 f3 f12 f13 f14) (!1comp3 (rew5@3 f1 f2 s3 f13 f14) (id5@3F f1 f2 f13 f14) (!1comp3 (rew3@2 f1 s2 f14) (id3@2 f1 f14) s1)))))) of type (comp13 f1 f2 f3 f4 f5 f6 (builtin_comp2 f7 f8) f9 f10 f11 f12 f13 f14) -> (builtin_id x0). + [=^.^=] let simpl7F = (_builtin_comp (focus7 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14) (simpl7 s1 s2 s3 s4 s5 s6 s7)) + [=I.I=] successfully defined term (!1builtin_comp2 (focus7 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14) (!1comp3 (rew13@7 f1 f2 f3 f4 f5 f6 s7 f9 f10 f11 f12 f13 f14) (id13@7F f1 f2 f3 f4 f5 f6 f9 f10 f11 f12 f13 f14) (!1comp3 (rew11@6 f1 f2 f3 f4 f5 s6 f10 f11 f12 f13 f14) (id11@6F f1 f2 f3 f4 f5 f10 f11 f12 f13 f14) (!1comp3 (rew9@5 f1 f2 f3 f4 s5 f11 f12 f13 f14) (id9@5F f1 f2 f3 f4 f11 f12 f13 f14) (!1comp3 (rew7@4 f1 f2 f3 s4 f12 f13 f14) (id7@4F f1 f2 f3 f12 f13 f14) (!1comp3 (rew5@3 f1 f2 s3 f13 f14) (id5@3F f1 f2 f13 f14) (!1comp3 (rew3@2 f1 s2 f14) (id3@2 f1 f14) s1))))))) of type (builtin_comp2 (comp7 f1 f2 f3 f4 f5 f6 f7) (comp7 f8 f9 f10 f11 f12 f13 f14)) -> (builtin_id x0). + [=^.^=] let simplrew2A = (comp3 (rew2compA a1 a2 b1 b2) (rrew2A aU bU) (rew2idA f1 g1)) + [=I.I=] successfully defined term (!2comp3 (rew2compA a1 a2 b1 b2) (rrew2A aU bU) (rew2idA f1 g1)) of type (!1builtin_comp2 (rew2A a1 b1) (rew2A a2 b2)) -> (!1builtin_id (builtin_comp2 f1 g1)). + [=^.^=] let simplrew3 = (comp3 (rew3comp@2 f1 a b f3) (rrew3@2 f1 abU f3) (rew3id@2 f1 f2 f3)) + [=I.I=] successfully defined term (!2comp3 (rew3comp@2 f1 a b f3) (rrew3@2 f1 abU f3) (rew3id@2 f1 f2 f3)) of type (!1builtin_comp2 (rew3@2 f1 a f3) (rew3@2 f1 b f3)) -> (!1builtin_id (comp3 f1 f2 f3)). + [=^.^=] let simplrew3-@2 = (comp3 (rew3id@2- f1 f2 f3) (rrew3@2 f1 abU- f3) (rew3comp@2- f1 a b f3)) + [=I.I=] successfully defined term (!2comp3 (rew3id@2- f1 f2 f3) (rrew3@2 f1 abU- f3) (rew3comp@2- f1 a b f3)) of type (!1builtin_id (comp3 f1 f2 f3)) -> (!1builtin_comp2 (rew3@2 f1 a f3) (rew3@2 f1 b f3)). + [=^.^=] let simplrew3A = (comp3 (rew3compA a1 a2 b1 b2 c1 c2) (rrew3A aU bU cU) (rew3idA f1 f2 f3)) + [=I.I=] successfully defined term (!2comp3 (rew3compA a1 a2 b1 b2 c1 c2) (rrew3A aU bU cU) (rew3idA f1 f2 f3)) of type (!1builtin_comp2 (rew3A a1 b1 c1) (rew3A a2 b2 c2)) -> (!1builtin_id (comp3 f1 f2 f3)). + [=^.^=] let simplrew5 = (comp3 (rew5comp@3 f1 f2 a b f4 f5) (rrew5@3 f1 f2 abU f4 f5) (rew5id@3 f1 f2 f3 f4 f5)) + [=I.I=] successfully defined term (!2comp3 (rew5comp@3 f1 f2 a b f4 f5) (rrew5@3 f1 f2 abU f4 f5) (rew5id@3 f1 f2 f3 f4 f5)) of type (!1builtin_comp2 (rew5@3 f1 f2 a f4 f5) (rew5@3 f1 f2 b f4 f5)) -> (!1builtin_id (comp5 f1 f2 f3 f4 f5)). + [=^.^=] let simplrew7 = (comp3 (rew7comp@4 f1 f2 f3 a b f5 f6 f7) (rrew7@4 f1 f2 f3 abU f5 f6 f7) (rew7id@4 f1 f2 f3 f4 f5 f6 f7)) + [=I.I=] successfully defined term (!2comp3 (rew7comp@4 f1 f2 f3 a b f5 f6 f7) (rrew7@4 f1 f2 f3 abU f5 f6 f7) (rew7id@4 f1 f2 f3 f4 f5 f6 f7)) of type (!1builtin_comp2 (rew7@4 f1 f2 f3 a f5 f6 f7) (rew7@4 f1 f2 f3 b f5 f6 f7)) -> (!1builtin_id (comp7 f1 f2 f3 f4 f5 f6 f7)). + [=^.^=] let simplrrew = (comp3 (rrew2compA s1 s2 r1 r2) (rrrew2A sU rU) (rrew2idA a1 b1)) + [=I.I=] successfully defined term (!3comp3 (rrew2compA s1 s2 r1 r2) (rrrew2A sU rU) (rrew2idA a1 b1)) of type (!2builtin_comp2 (rrew2A s1 r1) (rrew2A s2 r2)) -> (!2builtin_id (rew2A a1 b1)). + [=^.^=] let red3 = (_builtin_comp (rew5@3 f1 f2 s f5 f6) (id5@3F f1 f2 f5 f6)) + [=I.I=] successfully defined term (!1builtin_comp2 (rew5@3 f1 f2 s f5 f6) (id5@3F f1 f2 f5 f6)) of type (comp5 f1 f2 (builtin_comp2 f3 f4) f5 f6) -> (comp3 f1 (builtin_comp2 f2 f5) f6). + [=^.^=] let red3- = (_builtin_comp (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s f5 f6)) + [=I.I=] successfully defined term (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s f5 f6)) of type (comp3 f1 (builtin_comp2 f2 f5) f6) -> (comp5 f1 f2 (builtin_comp2 f3 f4) f5 f6). + [=^.^=] let red3F = (_builtin_comp (focus3 f1 f2 f3 f4 f5 f6) (red3 f1 f2 s f5 f6)) + [=I.I=] successfully defined term (!1builtin_comp2 (focus3 f1 f2 f3 f4 f5 f6) (!1builtin_comp2 (rew5@3 f1 f2 s f5 f6) (id5@3F f1 f2 f5 f6))) of type (builtin_comp2 (comp3 f1 f2 f3) (comp3 f4 f5 f6)) -> (comp3 f1 (builtin_comp2 f2 f5) f6). + [=^.^=] let red3F- = (_builtin_comp (red3- f1 f2 s f5 f6) (focus3- f1 f2 f3 f4 f5 f6)) + [=I.I=] successfully defined term (!1builtin_comp2 (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s f5 f6)) (focus3- f1 f2 f3 f4 f5 f6)) of type (comp3 f1 (builtin_comp2 f2 f5) f6) -> (builtin_comp2 (comp3 f1 f2 f3) (comp3 f4 f5 f6)). + [=^.^=] let red3U = (simpl2F (simplrew5 f1 f2 f5 f6 sU) (id5@3FU f1 f2 f5 f6)) + [=I.I=] successfully defined term (!2builtin_comp2 (!1focus2 (rew5@3 f1 f2 s1 f5 f6) (id5@3F f1 f2 f5 f6) (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s2 f5 f6)) (!2comp3 (!1rew3@2 (rew5@3 f1 f2 s1 f5 f6) (id5@3FU f1 f2 f5 f6) (rew5@3 f1 f2 s2 f5 f6)) (!1id3@2 (rew5@3 f1 f2 s1 f5 f6) (rew5@3 f1 f2 s2 f5 f6)) (!2comp3 (rew5comp@3 f1 f2 s1 s2 f5 f6) (rrew5@3 f1 f2 sU f5 f6) (rew5id@3 f1 f2 (builtin_comp2 f3 f4) f5 f6)))) of type (!1builtin_comp2 (!1builtin_comp2 (rew5@3 f1 f2 s1 f5 f6) (id5@3F f1 f2 f5 f6)) (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s2 f5 f6))) -> (!1builtin_id (comp5 f1 f2 (builtin_comp2 f3 f4) f5 f6)). + [=^.^=] let red3FU = (simpl2F (focus3U f1 f2 f3 f4 f5 f6) (red3U f1 f2 sU f5 f6)) + [=I.I=] successfully defined term (!2builtin_comp2 (!1focus2 (focus3 f1 f2 f3 f4 f5 f6) (!1builtin_comp2 (rew5@3 f1 f2 s1 f5 f6) (id5@3F f1 f2 f5 f6)) (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s2 f5 f6)) (focus3- f1 f2 f3 f4 f5 f6)) (!2comp3 (!1rew3@2 (focus3 f1 f2 f3 f4 f5 f6) (!2builtin_comp2 (!1focus2 (rew5@3 f1 f2 s1 f5 f6) (id5@3F f1 f2 f5 f6) (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s2 f5 f6)) (!2comp3 (!1rew3@2 (rew5@3 f1 f2 s1 f5 f6) (id5@3FU f1 f2 f5 f6) (rew5@3 f1 f2 s2 f5 f6)) (!1id3@2 (rew5@3 f1 f2 s1 f5 f6) (rew5@3 f1 f2 s2 f5 f6)) (!2comp3 (rew5comp@3 f1 f2 s1 s2 f5 f6) (rrew5@3 f1 f2 sU f5 f6) (rew5id@3 f1 f2 (builtin_comp2 f3 f4) f5 f6)))) (focus3- f1 f2 f3 f4 f5 f6)) (!1id3@2 (focus3 f1 f2 f3 f4 f5 f6) (focus3- f1 f2 f3 f4 f5 f6)) (focus3U f1 f2 f3 f4 f5 f6))) of type (!1builtin_comp2 (!1builtin_comp2 (focus3 f1 f2 f3 f4 f5 f6) (!1builtin_comp2 (rew5@3 f1 f2 s1 f5 f6) (id5@3F f1 f2 f5 f6))) (!1builtin_comp2 (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s2 f5 f6)) (focus3- f1 f2 f3 f4 f5 f6))) -> (!1builtin_id (builtin_comp2 (comp3 f1 f2 f3) (comp3 f4 f5 f6))). + [=^.^=] let red3CU = (simpl2F (id5@3FCU f1 f2 f5 f6) (simplrew5 f1 f2 f5 f6 sU)) + [=I.I=] successfully defined term (!2builtin_comp2 (!1focus2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s1 f5 f6) (rew5@3 f1 f2 s2 f5 f6) (id5@3F f1 f2 f5 f6)) (!2comp3 (!1rew3@2 (id5@3F- f1 f2 f5 f6) (!2comp3 (rew5comp@3 f1 f2 s1 s2 f5 f6) (rrew5@3 f1 f2 sU f5 f6) (rew5id@3 f1 f2 (builtin_id x2) f5 f6)) (id5@3F f1 f2 f5 f6)) (!1id3@2 (id5@3F- f1 f2 f5 f6) (id5@3F f1 f2 f5 f6)) (id5@3FCU f1 f2 f5 f6))) of type (!1builtin_comp2 (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s1 f5 f6)) (!1builtin_comp2 (rew5@3 f1 f2 s2 f5 f6) (id5@3F f1 f2 f5 f6))) -> (!1builtin_id (comp3 f1 (builtin_comp2 f2 f5) f6)). + [=^.^=] let red3FCU = (simpl2F (red3CU f1 f2 sU f5 f6) (focus3CU f1 f2 f3 f4 f5 f6)) + [=I.I=] successfully defined term (!2builtin_comp2 (!1focus2 (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s1 f5 f6)) (focus3- f1 f2 f3 f4 f5 f6) (focus3 f1 f2 f3 f4 f5 f6) (!1builtin_comp2 (rew5@3 f1 f2 s2 f5 f6) (id5@3F f1 f2 f5 f6))) (!2comp3 (!1rew3@2 (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s1 f5 f6)) (focus3CU f1 f2 f3 f4 f5 f6) (!1builtin_comp2 (rew5@3 f1 f2 s2 f5 f6) (id5@3F f1 f2 f5 f6))) (!1id3@2 (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s1 f5 f6)) (!1builtin_comp2 (rew5@3 f1 f2 s2 f5 f6) (id5@3F f1 f2 f5 f6))) (!2builtin_comp2 (!1focus2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s1 f5 f6) (rew5@3 f1 f2 s2 f5 f6) (id5@3F f1 f2 f5 f6)) (!2comp3 (!1rew3@2 (id5@3F- f1 f2 f5 f6) (!2comp3 (rew5comp@3 f1 f2 s1 s2 f5 f6) (rrew5@3 f1 f2 sU f5 f6) (rew5id@3 f1 f2 (builtin_id x2) f5 f6)) (id5@3F f1 f2 f5 f6)) (!1id3@2 (id5@3F- f1 f2 f5 f6) (id5@3F f1 f2 f5 f6)) (id5@3FCU f1 f2 f5 f6))))) of type (!1builtin_comp2 (!1builtin_comp2 (!1builtin_comp2 (id5@3F- f1 f2 f5 f6) (rew5@3 f1 f2 s1 f5 f6)) (focus3- f1 f2 f3 f4 f5 f6)) (!1builtin_comp2 (focus3 f1 f2 f3 f4 f5 f6) (!1builtin_comp2 (rew5@3 f1 f2 s2 f5 f6) (id5@3F f1 f2 f5 f6)))) -> (!1builtin_id (comp3 f1 (builtin_comp2 f2 f5) f6)). + [=^.^=] let rew2@2id@1R = (comp3 (id2@1- f) (rew2@2 (_builtin_id x) a) (id2@1 g)) + [=I.I=] successfully defined term (!1comp3 (id2@1- f) (rew2@2 (builtin_id x) a) (id2@1 g)) of type f -> g. + [=^.^=] coh rew2@2id@1 = (rew2@2id@1R a) -> a + [=I.I=] successfully defined rew2@2id@1. + [=^.^=] coh rew2@2id@1- = a -> (rew2@2id@1R a) + [=I.I=] successfully defined rew2@2id@1-. + [=^.^=] coh rew@2id@1U = (_builtin_comp (rew2@2id@1 a) (rew2@2id@1- a)) -> (_builtin_id (rew2@2id@1R a)) + [=I.I=] successfully defined rew@2id@1U. + [=^.^=] coh rew2id@1CU = (_builtin_comp (rew2@2id@1- a) (rew2@2id@1 a)) -> (_builtin_id a) + [=I.I=] successfully defined rew2id@1CU. + [=^.^=] let rew2@1id@2R = (comp3 (id2@2- f) (rew2@1 a (_builtin_id y)) (id2@2 g)) + [=I.I=] successfully defined term (!1comp3 (id2@2- f) (rew2@1 a (builtin_id y)) (id2@2 g)) of type f -> g. + [=^.^=] coh rew2@1id@2 = (rew2@1id@2R a) -> a + [=I.I=] successfully defined rew2@1id@2. + [=^.^=] coh rew2@1id@2- = a -> (rew2@1id@2R a) + [=I.I=] successfully defined rew2@1id@2-. + [=^.^=] coh rew2@1id@2U = (_builtin_comp (rew2@1id@2 a) (rew2@1id@2- a)) -> (_builtin_id (rew2@1id@2R a)) + [=I.I=] successfully defined rew2@1id@2U. + [=^.^=] coh rew2@1id@2CU = (_builtin_comp (rew2@1id@2- a) (rew2@1id@2 a)) -> (_builtin_id a) + [=I.I=] successfully defined rew2@1id@2CU. + [=^.^=] coh exch = (_builtin_comp (rew2@1 a h) (rew2@2 g b)) -> (_builtin_comp (rew2@2 f b) (rew2@1 a k)) + [=I.I=] successfully defined exch. + [=^.^=] coh exch- = (_builtin_comp (rew2@2 f b) (rew2@1 a k)) -> (_builtin_comp (rew2@1 a h) (rew2@2 g b)) + [=I.I=] successfully defined exch-. + [=^.^=] coh exchU = (_builtin_comp (exch a b) (exch- a b)) -> (_builtin_id (_builtin_comp (rew2@1 a h) (rew2@2 g b))) + [=I.I=] successfully defined exchU. + [=^.^=] let eh = (comp5 (rew2A (rew2@1id@2- a) (rew2@2id@1- b)) (red3F (id2@2- (_builtin_id x)) (rew2@1 a (_builtin_id x)) (id2@2@1U x) (rew2@2 (_builtin_id x) b) (id2@1 (_builtin_id x))) (rew3A (id2@/1-,2-/- x) (exch a b) (id2@/1,2/ x)) (red3F- (id2@1- (_builtin_id x)) (rew2@2 (_builtin_id x) b) (id2@1@2U- x) (rew2@1 a (_builtin_id x)) (id2@2 (_builtin_id x))) (rew2A (rew2@2id@1 b) (rew2@1id@2 a))) + [=I.I=] successfully defined term (!2comp5 (!1rew2A (rew2@1id@2- a) (rew2@2id@1- b)) (!2builtin_comp2 (!1focus3 (id2@2- (builtin_id x)) (rew2@1 a (builtin_id x)) (id2@2 (builtin_id x)) (id2@1- (builtin_id x)) (rew2@2 (builtin_id x) b) (id2@1 (builtin_id x))) (!2builtin_comp2 (!1rew5@3 (id2@2- (builtin_id x)) (rew2@1 a (builtin_id x)) (id2@2@1U x) (rew2@2 (builtin_id x) b) (id2@1 (builtin_id x))) (!1id5@3F (id2@2- (builtin_id x)) (rew2@1 a (builtin_id x)) (rew2@2 (builtin_id x) b) (id2@1 (builtin_id x))))) (!1rew3A (id2@/1-,2-/- x) (exch a b) (id2@/1,2/ x)) (!2builtin_comp2 (!2builtin_comp2 (!1id5@3F- (id2@1- (builtin_id x)) (rew2@2 (builtin_id x) b) (rew2@1 a (builtin_id x)) (id2@2 (builtin_id x))) (!1rew5@3 (id2@1- (builtin_id x)) (rew2@2 (builtin_id x) b) (id2@1@2U- x) (rew2@1 a (builtin_id x)) (id2@2 (builtin_id x)))) (!1focus3- (id2@1- (builtin_id x)) (rew2@2 (builtin_id x) b) (id2@1 (builtin_id x)) (id2@2- (builtin_id x)) (rew2@1 a (builtin_id x)) (id2@2 (builtin_id x)))) (!1rew2A (rew2@2id@1 b) (rew2@1id@2 a))) of type (!1builtin_comp2 a b) -> (!1builtin_comp2 b a). + + $ catt coverage/eckmann-hilton-optimized.catt + [=^.^=] coh unitl = (_builtin_comp (_builtin_id _) f) -> f + [=I.I=] successfully defined unitl. + [=^.^=] coh unit = (_builtin_comp (_builtin_id x) (_builtin_id x)) -> (_builtin_id x) + [=I.I=] successfully defined unit. + [=^.^=] coh lsimp = (unitl (_builtin_id x)) -> (unit x) + [=I.I=] successfully defined lsimp. + [=^.^=] coh Ilsimp = I((unitl (_builtin_id x))) -> I((unit x)) + [=I.I=] successfully defined Ilsimp. + [=^.^=] coh exch = (_builtin_comp (_builtin_comp _ [b]) (_builtin_id (_builtin_comp f k)) (_builtin_comp [a] _)) -> (_builtin_comp [a] [b]) + [=I.I=] successfully defined exch. + [=^.^=] coh eh1 = (_builtin_comp a b) -> (_builtin_comp I((unitl f)) (_builtin_comp (_builtin_comp _ [a]) (_builtin_comp (unitl g) I(op_{1}((unitl g)))) (_builtin_comp [b] _)) op_{1}((unitl h))) + [=I.I=] successfully defined eh1. + [=^.^=] let eh2 = (_builtin_comp [(Ilsimp _)] [(_builtin_comp (_builtin_comp _ [(_builtin_comp (_builtin_comp [(lsimp _)] [op_{1}((Ilsimp _))]) U((unit _)))] _) (exch b a))] [op_{1}((lsimp _))]) + [=I.I=] successfully defined term (!1builtin_comp3 [(Ilsimp x)] [(!2builtin_comp2 (!1builtin_comp3 (builtin_comp2 (builtin_id x) [a]) [(!2builtin_comp2 (!1builtin_comp2 [(lsimp x)] [(Ilsimp_op{1} x)]) (unit_Unit x))] (builtin_comp2 [b] (builtin_id x))) (exch b a))] [(lsimp_op{1} x)]) of type (!1builtin_comp3 (unitl^-1 (builtin_id x)) (!1builtin_comp3 (builtin_comp2 (builtin_id x) [a]) (!1builtin_comp2 (unitl (builtin_id x)) (unitl^-1_op{1} (builtin_id_op{1} x))) (builtin_comp2 [b] (builtin_id x))) (unitl_op{1} (builtin_id_op{1} x))) -> (!1builtin_comp3 (unit^-1 x) (builtin_comp2 [b] [a]) (unit_op{1} x)). + [=^.^=] let eh = (_builtin_comp (eh1 a b) (eh2 a b) I(op_{1}((eh2 b a))) I(op_{1}((eh1 b a)))) + [=I.I=] successfully defined term (!2builtin_comp4 (eh1 a b) (!1builtin_comp3 [(Ilsimp x)] [(!2builtin_comp2 (!1builtin_comp3 (builtin_comp2 (builtin_id x) [a]) [(!2builtin_comp2 (!1builtin_comp2 [(lsimp x)] [(Ilsimp_op{1} x)]) (unit_Unit x))] (builtin_comp2 [b] (builtin_id x))) (exch b a))] [(lsimp_op{1} x)]) (!1builtin_comp3_func[1 1 1]_op{1}_op{3} (Ilsimp_op{1}^-1 x) (!2builtin_comp2_op{1}_op{3} (exch_op{1}^-1 b a) (!1builtin_comp3_func[1]_op{1}_op{3} (builtin_comp2_func[1]_op{1} b (builtin_id_op{1} x)) (!2builtin_comp2_op{1}_op{3} (unit_Unit_op{1}^-1 x) (!1builtin_comp2_func[1 1]_op{1}_op{3} (lsimp_op{1}^-1 x) (Ilsimp_op{1}_op{1}^-1 x))) (builtin_comp2_func[1]_op{1} (builtin_id_op{1} x) a))) (lsimp_op{1}_op{1}^-1 x)) (eh1_op{1}^-1 b a)) of type (!1builtin_comp2 a b) -> (!1builtin_comp2_op{1} b a). diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 3c02fdf4..00000000 --- a/test/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - for i in $(wildcard *.catt); do echo "\n* Testing $$i.\n"; ../src/catt $$i; done diff --git a/test/functoriality.catt b/test/functoriality.catt deleted file mode 100644 index a5185152..00000000 --- a/test/functoriality.catt +++ /dev/null @@ -1,123 +0,0 @@ -### Functoriality does not support the second coherence rule yet - -# let transport (x : *) (y : *) (f : x -> y) = id [f] -let whiskl (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) = - comp [a] g -let whiskr (x : *) (y : *) (f : x -> y) - (z : *) (g : y -> z) (g' : y -> z) (a : g -> g') = - comp f [a] -let horiz (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) (g' : y -> z) (b : g -> g') = - comp [a] [b] - -let compbis (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) = -comp f g - -let whisklbis (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) = - compbis [a] g -let whiskrbis (x : *) (y : *) (f : x -> y) - (z : *) (g : y -> z) (g' : y -> z) (a : g -> g') = - compbis f [a] -let horizbis (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) (g' : y -> z) (b : g -> g') = - compbis [a] [b] - -coh comp3 (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) (w : *) (h : z -> w) : x -> w -let test1 (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) - (w : *) (h : z -> w) (h' : z -> w) (c : h -> h') = - comp3 [a] g [c] -let test2 (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) (g' : y -> z) (b : g -> g') - (w : *) (h : z -> w) (h' : z -> w) (c : h -> h') = - comp3 [a] [b] [c] - -let sq (x : *) (f : x -> x) = - comp f f -let testsq (x : *) (f : x -> x) (g : x -> x) (a : f -> g) = - sq [a] - -let double-whiskl (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') (a' : f -> f') (b : a -> a') - (z : *) (g : y -> z) = - whiskl [b] g - - -coh id3@2 (x : *) (y : *) (f : x -> y) (z : *) (g : y -> z) : - comp3 f (id y) g -> comp f g - - -### Test bug in naming -coh comp5 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6): -x1 -> x6 - -coh focus2 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) : - comp (comp f1 f2) (comp f3 f4) -> comp3 f1 (comp f2 f3) f4 - - -let simpl2 (x0 : *) (x1 : *) (x2 : *) - (f1 : x0 -> x1) (f2 : x1 -> x2) (f3 : x2 -> x1) (f4 : x1 -> x0) - (s1 : comp f1 f4 -> id x0) (s2 : comp f2 f3 -> id x1) = - comp3 (comp3 f1 [s2] f4) - (id3@2 f1 f4) - s1 - -let simpl2F (x0 : *) (x1 : *) (x2 : *) - (f1 : x0 -> x1) (f2 : x1 -> x2) (f3 : x2 -> x1) (f4 : x1 -> x0) - (s1 : comp f1 f4 -> id x0) (s2 : comp f2 f3 -> id x1) = - comp (focus2 f1 f2 f3 f4) - (simpl2 s1 s2) - -coh id5@3F (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) : -comp5 f1 f2 (id x3) f3 f4 -> comp3 f1 (comp f2 f3) f4 - -coh id5@3F- (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) : -comp3 f1 (comp f2 f3) f4 -> comp5 f1 f2 (id x3) f3 f4 - -coh id5@3FU (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) : -comp (id5@3F f1 f2 f3 f4) (id5@3F- f1 f2 f3 f4) -> id (comp5 f1 f2 (id x3) f3 f4) - -coh rew5comp@3 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) (g3 : x2 -> x3) (a : f3 -> g3) - (h3 : x2 -> x3) (b : g3 -> h3) - (x4 : *) (f4 : x3 -> x4) - (x5 : *) (f5 : x4 -> x5) : - comp (comp5 f1 f2 [a] f4 f5) (comp5 f1 f2 [b] f4 f5) -> comp5 f1 f2 [comp a b] f4 f5 - -coh rew5id@3 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) - (x5 : *) (f5 : x4 -> x5) : - comp5 f1 f2 [id f3] f4 f5 -> id (comp5 f1 f2 f3 f4 f5) - -coh rrew5@3 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) (g3 : x2 -> x3) (a : f3 -> g3) - (b : f3 -> g3) (c : a -> b) - (x4 : *) (f4 : x3 -> x4) - (x5 : *) (f5 : x4 -> x5) : - comp5 f1 f2 [a] f4 f5 -> comp5 f1 f2 [b] f4 f5 - - -let simplrew5 (x0 : *) (x1 : *) (x2 : *) (x3 : *) (x4 : *) (x5 : *) - (f1 : x0 -> x1) (f2 : x1 -> x2) - (f3 : x2 -> x3) (g3 : x2 -> x3) (a : f3 -> g3) (b : g3 -> f3) (abU : comp a b -> id f3) - (f4 : x3 -> x4) (f5 : x4 -> x5) = -comp3 (rew5comp@3 f1 f2 a b f4 f5) - (rrew5@3 f1 f2 abU f4 f5) - (rew5id@3 f1 f2 f3 f4 f5) - -let red3U (x0 : *) (x1 : *) (x2 : *) (x2m : *) (x3 : *) (x4 : *) - (f1 : x0 -> x1) (f2 : x1 -> x2) - (f3 : x2 -> x2m) (f4 : x2m -> x2) (s1 : comp f3 f4 -> id x2) (s2 : id x2 -> comp f3 f4) - (sU : comp s1 s2 -> id (comp f3 f4)) - (f5 : x2 -> x3) (f6 : x3 -> x4) -# : comp (red3 f1 f2 s1 f5 f6) (red3- f1 f2 s2 f5 f6) -> id (comp5 f1 f2 (comp f3 f4) f5 f6) = - = simpl2F (simplrew5 f1 f2 sU f5 f6) - (id5@3FU f1 f2 f5 f6) diff --git a/test/issue7.catt b/test/issue7.catt deleted file mode 100644 index dbfcb608..00000000 --- a/test/issue7.catt +++ /dev/null @@ -1,5 +0,0 @@ - -let f (x : *) = - let i = id x in - let j = id i in - j diff --git a/test/pretty-print.catt b/test/pretty-print.catt deleted file mode 100644 index 19364b8c..00000000 --- a/test/pretty-print.catt +++ /dev/null @@ -1,31 +0,0 @@ -set explicit_substitutions = t - -coh whiskr (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) : comp x y f z g -> comp x y f' z g -coh whiskl (x : *) (y : *) (f : x -> y) - (z : *) (g : y -> z) (g' : y -> z) (a : g -> g') : comp x y f z g -> comp x y f z g' -coh horiz (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) (g' : y -> z) (b : g -> g') : - comp x y f z g -> comp x y f' z g' - -let sq (x : *) (f : x -> x) = comp x x f x f - -let cbd (x : *) (f : x -> x) : x -> x = comp x x f x (comp x x f x f) - - -set explicit_substitutions=f -set verbosity = 2 - -coh simpl (x : *) : sq (id x) -> id x - -coh test (x(f(a)g)y) : comp [a] [id (id y)] -> comp [a] (id y) -let comp302 (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g) (b : f -> g) (F : a -> b) (z : *) (h : y -> z) (k : y -> z) (c : h -> k) = comp [[F]] [c] -let comp202 (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g) (z : *) (h : y -> z) (k : y -> z) (c : h -> k) = comp [a] [c] -let comp302bis (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g) (b : f -> g) (F : a -> b) (z : *) (h : y -> z) (k : y -> z) (c : h -> k) = comp202 [F] c - - -set unroll_coherences = t -check (x : *) (f : x -> x) = comp (sq f) (cbd f) - -set unroll_coherences = f -check (x : *) (f : x -> x) = test [id (id f)] diff --git a/test/test.catt b/test/test.catt deleted file mode 100644 index 711f162e..00000000 --- a/test/test.catt +++ /dev/null @@ -1,26 +0,0 @@ -set explicit_substitutions = t - -coh whiskr (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) : comp x y f z g -> comp x y f' z g -coh whiskl (x : *) (y : *) (f : x -> y) - (z : *) (g : y -> z) (g' : y -> z) (a : g -> g') : comp x y f z g -> comp x y f z g' -coh horiz (x : *) (y : *) (f : x -> y) (f' : x -> y) (a : f -> f') - (z : *) (g : y -> z) (g' : y -> z) (b : g -> g') : - comp x y f z g -> comp x y f' z g' - -let sq (x : *) (f : x -> x) = comp x x f x f - -let cbd (x : *) (f : x -> x) : x -> x = comp x x f x (comp x x f x f) - -set verbosity = 3 - -coh simpl (x : *) : sq x (id x) -> id x - -check (x : *) (f : x -> x) = comp x x (sq x f) x (cbd x f) - -#coh failure (x(f)y(g)z) : x -> y - -#set explicit_substitutions = f -#let failure2 (x : *) (y : *) (f : x -> y) = comp f f - -coh test (x(f)y(g)z(h)w) : x -> w diff --git a/test/wildcards.catt b/test/wildcards.catt deleted file mode 100644 index 902fb189..00000000 --- a/test/wildcards.catt +++ /dev/null @@ -1,2 +0,0 @@ - -coh unit (x : *) (y : *) (f : x -> y) : comp f (id _) -> f diff --git a/web/catt.css b/web/catt.css index 1ed3a503..51a0ce48 100644 --- a/web/catt.css +++ b/web/catt.css @@ -1,5 +1,10 @@ +html { + height: 100%; +} + body { - margin: 2% 10%; + height: 96%; + margin: 2%; font-family: sans-serif; font-size: 11pt; } @@ -17,27 +22,36 @@ h1 { text-align: center; } -#send { - visibility: hidden; +input{ + margin: 0% .5%; } +textarea { + resize: none; + height: 100%; + width: 45%; + margin: 2%; +} #toplevel { + height: 80%; text-align: center; } - -textarea { - color: lightgreen; - background-color: black; +#editorArea{ + height: 80%; width: 100%; - font-size: 11pt; - font-weight: bold; } - -pre { - color: darkred; - background: whitesmoke; - font-size: 11pt; - width: 100%; - overflow-x: scroll; - overflow-y: visible; +#buttonBar{ + overflow: hidden; +} +#leftBar{ + text-align: left; + margin-left: 2%; + width: 20%; + float: left; +} +#rightBar{ + text-align: right; + margin-right: 2%; + width: 20%; + float: right; } diff --git a/web/dune b/web/dune index 3ef74b77..237a4070 100644 --- a/web/dune +++ b/web/dune @@ -1,9 +1,14 @@ -(install - (files index.html catt.css (web.bc.js as catt.js) test.catt) - (section share_root)) - (executable (name web) (modes js) (libraries catt) - (preprocess (pps js_of_ocaml-ppx))) \ No newline at end of file + (preprocess + (pps js_of_ocaml-ppx))) + +(install + (package catt-web) + (files + index.html + catt.css + (web.bc.js as catt.js)) + (section share_root)) diff --git a/web/index.html b/web/index.html index 5636e63a..762b99d4 100644 --- a/web/index.html +++ b/web/index.html @@ -1,29 +1,18 @@ - + - CATT + CaTT - - -

CATT
=^.^=

+ +

=^.^= CaTT Online Editor =^.^=

Coherences for weak ω-categories.

- -
@@ -35,7 +24,7 @@

More details

-

Examples can be found here

+

Examples can be found here

- diff --git a/web/test.catt b/web/test.catt deleted file mode 100644 index a136fd6d..00000000 --- a/web/test.catt +++ /dev/null @@ -1,191 +0,0 @@ -coh id (x : *) : x -> x. - -coh comp (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) ( f2 : x2 -> x3) : x1 -> x3. - -coh comp3 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) : x1 -> x4. - -coh comp4 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) : -x1 -> x5. - -coh comp5 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6): -x1 -> x6. - -coh comp6 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7): -x1 -> x7. - -coh comp7 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8): -x1 -> x8. - -coh comp8 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8) (x9 : *) (f8 : x8 -> x9): -x1 -> x9. - -coh comp9 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8) (x9 : *) (f8 : x8 -> x9) (x10 : *) (f9 : x9 -> x10): -x1 -> x10. - -coh comp10 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8) (x9 : *) (f8 : x8 -> x9) (x10 : *) (f9 : x9 -> x10) (x11 : *) (f10 : x10 -> x11): -x1 -> x11. - -coh comp11 (x1 : *) (x2 : *) (f1 : x1 -> x2) (x3 : *) (f2 : x2 -> x3) (x4 : *) (f3 : x3 -> x4) (x5 : *) (f4 : x4 -> x5) (x6 : *) (f5 : x5 -> x6) (x7 : *) (f6 : x6 -> x7) (x8 : *) (f7 : x7 -> x8) (x9 : *) (f8 : x8 -> x9) (x10 : *) (f9 : x9 -> x10) (x11 : *) (f10 : x10 -> x11) (x12 : *) (f11 : x11 -> x12): -x1 -> x12. - -coh whiskl (x : *) (y : *) (f : x -> y) (z : *) (g1 : y -> z) (g2 : y -> z) (a : g1 -> g2) : -comp f g1 -> comp f g2. - -coh whiskr (x : *) (y : *) (f1 : x -> y) (f2 : x -> y) (a : f1 -> f2) (z : *) (g : y -> z) : -comp f1 g -> comp f2 g. - -coh hcomp (x : *) (y : *) (f1 : x -> y) (f2 : x -> y) (a : f1 -> f2) (z : *) (g1 : y -> z) (g2 : y -> z) (b : g1 -> g2) : -comp f1 g1 -> comp f2 g2. - -coh unitl (x : *) (y : *) (f : x -> y) : comp (id x) f -> f. -coh unitl- (x : *) (y : *) (f : x -> y) : f -> comp (id x) f. - -coh unitr (x : *) (y : *) (f : x -> y) : comp f (id y) -> f. -coh unitr- (x : *) (y : *) (f : x -> y) : f -> comp f (id y). - -coh hunitl- (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g): a -> comp3 (unitl- f) (hcomp (id (id x)) a) (unitl g). -coh hunitr- (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g): a -> comp3 (unitr- f) (hcomp a (id (id y))) (unitr g). - -coh hunitl (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g): comp3 (unitl- f) (hcomp (id (id x)) a) (unitl g) -> a. -coh hunitr (x : *) (y : *) (f : x -> y) (g : x -> y) (a : f -> g): comp3 (unitr- f) (hcomp a (id (id y))) (unitr g) -> a. - - -coh exch (x : *) - (y : *) (f1 : x -> y) - (f2 : x -> y) (a1 : f1 -> f2) - (f3 : x -> y) (a2 : f2 -> f3) - (z : *) (g1 : y -> z) - (g2 : y -> z) (b1 : g1 -> g2) - (g3 : y -> z) (b2 : g2 -> g3) : -comp (hcomp a1 b1) (hcomp a2 b2) -> hcomp (comp a1 a2) (comp b1 b2). - -coh exch- (x : *) - (y : *) (f1 : x -> y) - (f2 : x -> y) (a1 : f1 -> f2) - (f3 : x -> y) (a2 : f2 -> f3) - (z : *) (g1 : y -> z) - (g2 : y -> z) (b1 : g1 -> g2) - (g3 : y -> z) (b2 : g2 -> g3) : -hcomp (comp a1 a2) (comp b1 b2) -> comp (hcomp a1 b1) (hcomp a2 b2). - - -check (x : *) (y : *) (z : *) (t : *) (f1 : x -> y) (f2 : x -> y) (g1 : y -> z) (g2 : y -> z) (h1 : z -> t) (h2 : z -> t) (a : f1 -> f2) (b : g1 -> g2) (c : h1 -> h2) = hcomp a (hcomp b c). - -check (x : *) (alpha : id (id x) -> id (id x)) (beta: id (id x) -> id (id x)) = hcomp alpha beta. - -coh assoc6 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) - (x5 : *) (f5 : x4 -> x5) - (x6 : *) (f6 : x5 -> x6) : - comp (comp3 f1 f2 f3) (comp3 f4 f5 f6) -> comp5 f1 f2 (comp f3 f4) f5 f6. - -coh assoc6- (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) - (x5 : *) (f5 : x4 -> x5) - (x6 : *) (f6 : x5 -> x6) : - comp5 f1 f2 (comp f3 f4) f5 f6 -> comp (comp3 f1 f2 f3) (comp3 f4 f5 f6). - - -check (x : *) (a : id x -> id x) (b : id x -> id x) = assoc6 (unitl- (id x)) (hcomp (id (id x)) a) (unitl (id x)) (unitr- (id x)) (hcomp b (id (id x))) (unitr (id x)). - -coh hinv (x : *) : comp (unitl (id x)) (unitr- (id x)) -> id (comp (id x) (id x)). -coh hinv- (x : *) : id (comp (id x) (id x)) -> comp (unitr (id x)) (unitl- (id x)). - -coh equivlr- (x : *) : unitl- (id x) -> unitr- (id x). -coh equivrl (x : *) : unitr (id x) -> unitl (id x). - -coh rew5 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) (g3 : x2 -> x3) (a : f3 -> g3) - (x4 : *) (f4 : x3 -> x4) - (x5 : *) (f5 : x4 -> x5) : - comp5 f1 f2 f3 f4 f5 -> comp5 f1 f2 g3 f4 f5. - -coh cancel5 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) : - comp5 f1 f2 (id x2) f3 f4 -> comp4 f1 f2 f3 f4. - -coh cancel5- (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) : - comp4 f1 f2 f3 f4 -> comp5 f1 f2 (id x2) f3 f4. - -coh assoc4 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) : - comp4 f1 f2 f3 f4 -> comp3 f1 (comp f2 f3) f4. - -coh assoc4- (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) - (x4 : *) (f4 : x3 -> x4) : - comp3 f1 (comp f2 f3) f4 -> comp4 f1 f2 f3 f4. - - - -coh rew3 (x0 : *) (x1 : *) (f1 : x0 -> x1) - (x2 : *) (f2 : x1 -> x2) (g2 : x1 -> x2) (a : f2 -> g2) - (x3 : *) (f3 : x2 -> x3) : - comp3 f1 f2 f3 -> comp3 f1 g2 f3. - -coh rew1-3 (x0 : *) (x1 : *) (f1 : x0 -> x1) (g1 : x0 -> x1) (a : f1 -> g1) - (x2 : *) (f2 : x1 -> x2) - (x3 : *) (f3 : x2 -> x3) (g3 : x2 -> x3) (b : f3 -> g3) : - comp3 f1 f2 f3 -> comp3 g1 f2 g3. - -check (x : *) (a : id x -> id x) (b : id x -> id x) = - rew3 (unitl- (id x)) (exch (id (id x)) b a (id (id x))) (unitr (id x)). - -coh hrew (x : *) (y : *) (f : x -> y) (g : x -> y) (a0 : f -> g) (a1 : f -> g) (al : a0 -> a1) - (z : *) (h : y -> z) (k : y -> z) (b0 : h -> k) (b1 : h -> k) (bet : b0 -> b1) - : - hcomp a0 b0 -> hcomp a1 b1. - -check (x : *) (a : id x -> id x) (b : id x -> id x) = - rew3 (unitl- (id x)) (hrew (unitl b) (unitr a)) (unitr (id x)). - - -let half-eh1 (x : *) (a : id x -> id x) (b : id x -> id x) = -comp6 (hcomp (hunitl- a) (hunitr- b)) - (assoc6 (unitl- (id x)) (hcomp (id (id x)) a) (unitl (id x)) (unitr- (id x)) (hcomp b (id (id x))) (unitr (id x))) - (rew5 (unitl- (id x)) (hcomp (id (id x)) a) (hinv x) (hcomp b (id (id x))) (unitr (id x))) - (cancel5 (unitl- (id x)) (hcomp (id (id x)) a) (hcomp b (id (id x))) (unitr (id x))) - (assoc4 (unitl- (id x)) (hcomp (id (id x)) a) (hcomp b (id (id x))) (unitr (id x))) - (rew3 (unitl- (id x)) (comp (exch (id (id x)) b a (id (id x))) (hrew (unitl b) (unitr a))) (unitr (id x))). - - - -check (x : *) (a : id x -> id x) (b : id x -> id x) = -(rew3 (unitl- (id x)) (exch- b (id (id x)) (id (id x)) a) (unitr (id x))). - -check (x : *) (a : id x -> id x) (b : id x -> id x) = -(assoc4- (unitl- (id x)) (hcomp b (id (id x))) (hcomp (id (id x)) a) (unitr (id x))). - -check (x : *) (a : id x -> id x) (b : id x -> id x) = -(cancel5- (unitl- (id x)) (hcomp b (id (id x))) (hcomp (id (id x)) a) (unitr (id x))). - -check (x : *) (a : id x -> id x) (b : id x -> id x) = -(hcomp (hunitr b) (hunitl a)). - - -let half-eh2 (x : *) (a : id x -> id x) (b : id x -> id x) = -comp6 (rew3 (unitr- (id x)) (comp (hrew (unitr- b) (unitl- a)) (exch- b (id (id x)) (id (id x)) a)) (unitl (id x))) -(assoc4- (unitr- (id x)) (hcomp b (id (id x))) (hcomp (id (id x)) a) (unitl (id x))) -(cancel5- (unitr- (id x)) (hcomp b (id (id x))) (hcomp (id (id x)) a) (unitl (id x))) -(rew5 (unitr- (id x)) (hcomp b (id (id x))) (hinv- x) (hcomp (id (id x)) a) (unitl (id x))) -(assoc6- (unitr- (id x)) (hcomp b (id (id x))) (unitr (id x)) (unitl- (id x)) (hcomp (id (id x)) a) (unitl (id x))) -(hcomp (hunitr b) (hunitl a)). - - -let eckmann-hilton (x : *) (a : id x -> id x) (b : id x -> id x) = -comp3 (half-eh1 x a b) - (rew1-3 (equivlr- x) (hcomp b a) (equivrl x)) - (half-eh2 x a b). \ No newline at end of file diff --git a/web/web.ml b/web/web.ml index 7e4d17b0..321ba0b3 100644 --- a/web/web.ml +++ b/web/web.ml @@ -1,27 +1,32 @@ +module Dom = Js_of_ocaml.Dom (** Interaction with a webpage. *) -module Dom = Js_of_ocaml.Dom +module Sys_js = Js_of_ocaml.Sys_js module Html = Js_of_ocaml.Dom_html module Js = Js_of_ocaml.Js module Firebug = Js_of_ocaml.Firebug -(* let envs = ref Lang.Envs.empty *) - let doc = Html.document -let button txt action = + +let button ~id txt action = let button_type = Js.string "button" in let b = Html.createInput ~_type:button_type doc in b##.value := Js.string txt; - b##.onclick := Html.handler (fun _ -> action (); Js._true); + b##.onclick := + Html.handler (fun _ -> + action (); + Js._true); + b##.id := Js.string id; b -let _debug s = - Firebug.console##debug (Js.string s) +let _debug s = Firebug.console##debug (Js.string s) -let loop s = - Catt.Prover.exec s; - (* envs := Prover.exec !envs s; *) - Catt.Prover.init () +let run_action s = + try + match Catt.Prover.parse s with + | Ok cmds -> Catt.Command.exec ~loop_fn:Catt.Prover.loop cmds + | Error () -> () + with _ -> Catt.Io.error "Uncaught exception" let run _ = let top = @@ -30,68 +35,68 @@ let run _ = (fun () -> assert false) in - let output = Html.createDiv doc in - output##.id := Js.string "output"; - output##.style##.whiteSpace := Js.string "pre"; - Dom.appendChild top output; - - let textbox = Html.createTextarea doc in - textbox##.id := Js.string "input"; - textbox##.cols := 80; - textbox##.rows := 25; - (* textbox##value <- Js.string "# "; *) - Dom.appendChild top textbox; - Dom.appendChild top (Html.createBr doc); - textbox##focus; - textbox##select; - - (* Current offset in textbox. *) - let tb_off = ref 0 in + let button_bar = Html.createDiv doc in + button_bar##.id := Js.string "buttonBar"; + let left_bar = Html.createDiv doc in + left_bar##.id := Js.string "leftBar"; + let right_bar = Html.createDiv doc in + right_bar##.id := Js.string "rightBar"; + + let editor_area = Html.createDiv doc in + editor_area##.id := Js.string "editorArea"; + + let input_area = Html.createTextarea doc in + input_area##.id := Js.string "inputArea"; + input_area##.placeholder := Js.string "Input CaTT code here"; + + let output_area = Html.createTextarea doc in + output_area##.id := Js.string "outputArea"; + output_area##.placeholder := Js.string "Output..."; + output_area##.readOnly := Js.bool true; + let print s = - let s = Js.to_string textbox##.value ^ s in - tb_off := String.length s; - textbox##.value := Js.string s; - (* Scroll down. *) - Js.Unsafe.set textbox (Js.string "scrollTop") (Js.Unsafe.get textbox (Js.string "scrollHeight")) + let text = Js.to_string output_area##.value in + output_area##.style##.color := Js.string "black"; + output_area##.value := Js.string (text ^ s) in - let read () = - let s = Js.to_string textbox##.value in - let cmd = String.sub s !tb_off (String.length s - !tb_off) in - tb_off := String.length s; - cmd + let clear_output () = output_area##.value := Js.string "" in + + let print_error s = + let s = + if String.starts_with ~prefix:"\027[1;91m" s then + String.sub s 7 (String.length s - 7) + else s + in + let s = + if String.ends_with ~suffix:"\027[0m" s then + String.sub s 0 (String.length s - 4) + else s + in + let text = Js.to_string output_area##.value in + output_area##.style##.color := Js.string "red"; + output_area##.value := Js.string (text ^ s) in - Catt.Io.print_string_fun := print; - Catt.Prover.init (); - - let b = - button - "Send" - (fun () -> - let s = read () in - let s = - let s = ref s in - let remove_last () = - if !s = "" then false else - let c = !s.[String.length !s - 1] in - c = '\n' || c = '\r' - in - while remove_last () do - (* remove trailing \n *) - s := String.sub !s 0 (String.length !s - 1) - done; - !s - in - loop s; - textbox##focus; - doc##.documentElement##.scrollTop := doc##.body##.scrollHeight) + let run_action () = + clear_output (); + let s = Js.to_string input_area##.value in + run_action s in - b##.id := Js.string "send"; - Dom.appendChild top b; + let run_button = button ~id:"runButton" "Run" run_action in + + Dom.appendChild top button_bar; + Dom.appendChild button_bar left_bar; + Dom.appendChild left_bar run_button; + Dom.appendChild button_bar right_bar; - ignore (Js.Unsafe.eval_string "init();"); + Dom.appendChild top editor_area; + Dom.appendChild editor_area input_area; + Dom.appendChild editor_area output_area; + input_area##focus; + input_area##select; + Sys_js.set_channel_flusher stdout print; + Sys_js.set_channel_flusher stderr print_error; Js._false -let () = - Html.window##.onload := Html.handler run +let () = Html.window##.onload := Html.handler run