├── .dir-locals.el ├── .github ├── dependabot.yml └── workflows │ └── main.yml ├── .gitignore ├── .readthedocs.yaml ├── AUTHORS.md ├── CHANGES.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── Makefile ├── README.md ├── RELEASE.md ├── TODO.md ├── doc ├── Makefile ├── Makefile.bnf ├── README.md ├── about.rst ├── commands.rst ├── conf.py ├── dedukti.rst ├── dtrees.rst ├── emacs.rst ├── equality.rst ├── getting_started.rst ├── implementation.rst ├── index.rst ├── lambdapi.bnf ├── latex.rst ├── module.rst ├── options.rst ├── profiling.rst ├── proof.rst ├── queries.rst ├── query_language.rst ├── structure.rst ├── tacticals.rst ├── tactics.rst ├── terms.rst ├── testing.rst ├── ui.rst ├── vim.rst └── vscode.rst ├── dune ├── dune-project ├── editors ├── emacs │ ├── .gitignore │ ├── CHANGES.md │ ├── Makefile │ ├── README.md │ ├── THANKS.md │ ├── TODO │ ├── lambdapi-abbrev.el │ ├── lambdapi-capf.el │ ├── lambdapi-input.el │ ├── lambdapi-layout.el │ ├── lambdapi-mode.el │ ├── lambdapi-proofs.el │ ├── lambdapi-smie.el │ ├── lambdapi-vars.el │ └── test.sh ├── vim │ ├── dune │ ├── ftdetect │ │ ├── dedukti.vim │ │ └── lambdapi.vim │ └── syntax │ │ ├── dedukti.vim │ │ └── lambdapi.vim └── vscode │ ├── .gitignore │ ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json │ ├── .vscodeignore │ ├── CHANGES.md │ ├── CONTRIBUTING.md │ ├── INSTALL.md │ ├── LICENSE.txt │ ├── Makefile │ ├── README.md │ ├── RELEASE.md │ ├── THANKS.md │ ├── TODO │ ├── lp.configuration.json │ ├── media │ └── styles.css │ ├── package-lock.json │ ├── package.json │ ├── snippets │ └── unicode.json │ ├── src │ ├── browser.ts │ ├── client.ts │ ├── config.ts │ └── tsconfig.json │ ├── syntaxes │ └── lp.tmLanguage.json │ ├── tsconfig-base.json │ └── tsconfig.json ├── lambdapi.opam ├── libraries ├── README.md ├── coq.v ├── dk2coq.mk ├── dk2rawcoq.sh ├── dk2sttcoq.sh ├── dklib.sh ├── encoding.lp ├── focalide.sh ├── holide.sh ├── iprover.sh ├── mapping.lp ├── matita.awk ├── matita.sh ├── matita │ └── LPSearch.lp ├── patch-filenames.sh ├── renaming.lp ├── sttfa.v ├── verine.sh └── zenon_modulo.sh ├── misc ├── .gitignore ├── deps.ml ├── example.tex ├── gen_version.ml ├── generate_tests.ml ├── git_hook_helper.sh ├── lambdapi.tex ├── rec_to_lp │ ├── Makefile │ ├── README.md │ ├── rec_hs_to_lp.awk │ ├── rec_time.py │ └── tests │ │ ├── ex.hs │ │ └── langton6.hs └── sanity_check.sh ├── src ├── .dir-locals.el ├── cli │ ├── config.ml │ ├── dune │ ├── init.ml │ ├── install.ml │ └── lambdapi.ml ├── common │ ├── console.ml │ ├── debug.ml │ ├── dune │ ├── error.ml │ ├── escape.ml │ ├── library.ml │ ├── logger.ml │ ├── logger.mli │ ├── path.ml │ └── pos.ml ├── core │ ├── builtin.ml │ ├── coercion.ml │ ├── coercion.mli │ ├── ctxt.ml │ ├── dune │ ├── env.ml │ ├── eval.ml │ ├── eval.mli │ ├── ghost.ml │ ├── infer.ml │ ├── infer.mli │ ├── inverse.ml │ ├── libMeta.ml │ ├── libTerm.ml │ ├── print.ml │ ├── sig_state.ml │ ├── sign.ml │ ├── term.ml │ ├── term.mli │ ├── tree.ml │ ├── tree_type.ml │ ├── unif.ml │ ├── unif.mli │ └── unif_rule.ml ├── export │ ├── coq.ml │ ├── dk.ml │ ├── dune │ ├── hrs.ml │ ├── rawdk.ml │ └── xtc.ml ├── handle │ ├── command.ml │ ├── command.mli │ ├── compile.ml │ ├── compile.mli │ ├── dune │ ├── fol.ml │ ├── inductive.ml │ ├── proof.ml │ ├── query.ml │ ├── query.mli │ ├── rewrite.ml │ ├── tactic.ml │ ├── why3_tactic.ml │ └── why3_tactic.mli ├── lplib │ ├── array.ml │ ├── base.ml │ ├── bytes.ml │ ├── color.ml │ ├── dune │ ├── extra.ml │ ├── filename.ml │ ├── list.ml │ ├── option.ml │ ├── range.ml │ ├── range.mli │ ├── rangeMap.ml │ ├── rangeMap.mli │ ├── rangeMap_intf.ml │ ├── range_intf.ml │ ├── realpath.c │ ├── string.ml │ └── uchar.ml ├── lsp │ ├── CHANGES.md │ ├── README.md │ ├── dune │ ├── lp_doc.ml │ ├── lp_lsp.ml │ ├── lp_lsp.mli │ ├── lsp_base.ml │ ├── lsp_base.mli │ └── lsp_io.ml ├── parsing │ ├── dkBasic.ml │ ├── dkLexer.mll │ ├── dkParser.mly │ ├── dkRule.ml │ ├── dkTokens.ml │ ├── dune │ ├── lpLexer.ml │ ├── lpParser.mly │ ├── package.ml │ ├── parser.ml │ ├── pratt.ml │ ├── pretty.ml │ ├── scope.ml │ ├── scope.mli │ ├── searchQuerySyntax.ml │ └── syntax.ml ├── pure │ ├── dune │ ├── pure.ml │ └── pure.mli └── tool │ ├── dune │ ├── external.ml │ ├── indexing.ml │ ├── indexing.mli │ ├── lcr.ml │ ├── sr.ml │ ├── sr.mli │ ├── tree_graphviz.ml │ ├── websearch.eml.ml │ └── websearch.mli └── tests ├── .gitignore ├── KO ├── 1041.lp ├── 1103.lp ├── 1103b.lp ├── 1217.lp ├── 246.lp ├── 246b.lp ├── 262_localuse.lp ├── 262_prv_in_rhs.lp ├── 262_prv_lhs_head.lp ├── 262_prvdef_in_rhs.lp ├── 262_pub_prv_defn.lp ├── 262_pub_prv_type.lp ├── 262_pub_prvlhs_rule.lp ├── 262_pub_prvrhs_rule.lp ├── 272.lp ├── 378.lp ├── 536.lp ├── 59.lp ├── 655.lp ├── 655b.lp ├── 656.lp ├── 71.dk ├── 713.lp ├── 845.lp ├── 912.lp ├── 913.lp ├── 922.lp ├── anonymous.lp ├── bug2.dk ├── bug3.dk ├── church.dk ├── circular_a.dk ├── circular_b.dk ├── circular_c.dk ├── context_var_not_occuring.dk ├── def.dk ├── double_decl.dk ├── francois.dk ├── incompatible.lp ├── inductive_type_KO.lp ├── infix.lp ├── invalid_pat.dk ├── lexing_id.dk ├── missing_brackets.lp ├── nomodule.dk ├── notinj.dk ├── notvarinenv.lp ├── parsing_eof.dk ├── pat_rhs.lp ├── remove.lp ├── req_without_root_path.lp ├── require_escape1.lp ├── require_escape2.lp ├── rule_var.dk ├── scoping_ext.dk ├── self_require_escape.lp ├── typing_abstraction.dk ├── typing_omega.dk ├── typing_pi.dk ├── typing_sort.dk ├── unclosed_comment.dk ├── unclosed_comment2.dk ├── unclosed_comment3.dk ├── unsound.dk └── vectDependant.dk ├── OK ├── 1001.lp ├── 1006.lp ├── 1026.lp ├── 1033.lp ├── 1035.lp ├── 1101.lp ├── 1120.lp ├── 1141.lp ├── 1190a.lp ├── 1190b.lp ├── 1190c.lp ├── 1217.lp ├── 1247.lp ├── 215.lp ├── 225.lp ├── 244.lp ├── 245.lp ├── 245b.lp ├── 262_legacy_parsing.dk ├── 262_pair_ex_1.lp ├── 262_pair_ex_2.lp ├── 262_parsing.lp ├── 262_private_in_lhs.lp ├── 273.lp ├── 292.lp ├── 298_lp.lp ├── 301.lp ├── 303.lp ├── 328.lp ├── 330.lp ├── 330b.lp ├── 341.lp ├── 359.lp ├── 430.lp ├── 547.lp ├── 55.dk ├── 565.lp ├── 573-2.lp ├── 573.lp ├── 579_long_no_duplicate.lp ├── 579_or_elim_long.lp ├── 584_c_slow.lp ├── 595_and_elim.lp ├── 61.dk ├── 62.dk ├── 621c.lp ├── 649_fo_27.lp ├── 65.dk ├── 650.lp ├── 655.lp ├── 655b.lp ├── 665.lp ├── 679.lp ├── 683.lp ├── 693.lp ├── 693_assume.lp ├── 698_abst_impl.lp ├── 706.lp ├── 72.dk ├── 725.lp ├── 729.lp ├── 767.lp ├── 77.dk ├── 813.lp ├── 830.lp ├── 861.lp ├── 878.lp ├── 904.lp ├── 922.lp ├── 989.lp ├── 991.lp ├── Bool.lp ├── Classic.lp ├── Eq.lp ├── Escaped.lp ├── FO.dk ├── FOL.lp ├── HOL.lp ├── Impred.lp ├── List.lp ├── Nat.lp ├── Option.lp ├── Prop.lp ├── PropExt.lp ├── Set.lp ├── String.lp ├── Tactic.lp ├── a b │ └── escape file.lp ├── abstractions.lp ├── ac.lp ├── admit.lp ├── andPoly.dk ├── append.lp ├── append_legacy.dk ├── apply.lp ├── arity_diff.lp ├── arity_var.lp ├── basic.dk ├── big_compute.dk ├── boolean.lp ├── bug.dk ├── bug0.dk ├── builtin_succ_zero.lp ├── check.dk ├── church.dk ├── cic.dk ├── coc.dk ├── coercions.lp ├── comment_in_qid.lp ├── compute.lp ├── compute_legacy.dk ├── cp0.lp ├── cp1.lp ├── cp2.lp ├── cp3.lp ├── cr_qu.lp ├── cupicef.dk ├── declared.lp ├── doc.lp ├── domainfree.dk ├── dotpat.dk ├── dummy1.dk ├── empty.lp ├── emptySet.dk ├── escape_path.lp ├── eta_equality.lp ├── file.with.dot.lp ├── firstOrder.dk ├── firstOrder_v2.dk ├── foo.lp ├── for_inductive.lp ├── freevars-constraints.lp ├── gaspard.dk ├── generalize.lp ├── group.lp ├── half.dk ├── have.lp ├── ho_bug1.dk ├── ho_bug2.dk ├── hott.dk ├── identifiers.lp ├── implicitArgs1.lp ├── implicitArgs2.lp ├── implicitArgs3.lp ├── implicitArgs4.lp ├── indind.lp ├── indrec.lp ├── inductive.lp ├── infer.lp ├── infix.lp ├── inj.dk ├── let.lp ├── logic.lp ├── lpparse.lp ├── lpparse2.lp ├── max-suc-alg.lp ├── michael.lp ├── miller.dk ├── miller2.dk ├── mini.dk ├── nat_id1.lp ├── nat_id2.lp ├── natproofs.lp ├── natural.lp ├── nested_comment.dk ├── nested_comment_lp.lp ├── nonLeftLinear.dk ├── nonLeftLinear2.lp ├── nonlin.dk ├── not-eager.lp ├── opaque.lp ├── parametricCoercions.lp ├── patt.lp ├── patterns.lp ├── perf_rw_engine.lp ├── perf_rw_fib-nonRightLin.lp ├── perf_rw_nl.lp ├── plus.dk ├── plus_ac.lp ├── postfix.lp ├── power-fact.lp ├── prefix.lp ├── print_notation_numbers.lp ├── private.lp ├── quant.lp ├── quant2.lp ├── raphael.dk ├── remove.lp ├── req.file.with.dot.lp ├── require_nondkmident.lp ├── require_symbol.lp ├── rewrite0.lp ├── rewrite1.lp ├── rewrite2.lp ├── rewrite3.lp ├── rule_order.lp ├── simp_beta.lp ├── strictly_positive_1.lp ├── strictly_positive_2.lp ├── subst.dk ├── surjective.dk ├── sym_decl.lp ├── symbol.lp ├── tail.lp ├── tautologies.lp ├── test.dk ├── tptp.dk ├── triangular.lp ├── try.lp ├── tuto.dk ├── tutorial.lp ├── type.lp ├── type_rewrite.dk ├── unif_hint.lp ├── uninst_meta_in_rhs.dk ├── varmatch.lp ├── vectDependant.dk ├── why3.lp ├── wildcards.dk ├── xor.lp └── zero.lp ├── dtrees.sh ├── dune ├── export_dk.sh ├── export_lp.sh ├── export_raw_dk.sh ├── kernel.ml ├── lambdapi.pkg ├── ok_ko.ml ├── purity.ml ├── regressions ├── dtrees.expected ├── dtrees.ml ├── dune ├── hrs.expected ├── hrs.ml ├── xtc.expected └── xtc.ml ├── rewriting.ml ├── runtests.sh └── test_lib.sh /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((nil . ((sort-fold-case . t) ; Ignore case when sorting 2 | )) 3 | (emacs-lisp-mode . ((indent-tabs-mode . nil)))) 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | updates: 4 | - package-ecosystem: github-actions 5 | directory: / 6 | schedule: 7 | interval: monthly 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | log-lp.txt 2 | log-lsp.txt 3 | *.dko 4 | *~ 5 | *.swp 6 | _build 7 | libraries/*.tar.gz 8 | libraries/*.tar 9 | libraries/*.zip 10 | libraries/dklib 11 | libraries/focalide 12 | libraries/holide 13 | libraries/iprover 14 | libraries/matita 15 | libraries/verine 16 | libraries/zenon_modulo 17 | .merlin 18 | *.install 19 | *.gv 20 | *.png 21 | .DS_Store 22 | *.map 23 | *.log 24 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file for Sphinx projects 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | # Required 5 | version: 2 6 | 7 | # Set the OS, Python version and other tools you might need 8 | build: 9 | os: ubuntu-22.04 10 | tools: 11 | python: "3.12" 12 | # You can also specify other tool versions: 13 | # nodejs: "20" 14 | # rust: "1.70" 15 | # golang: "1.20" 16 | jobs: 17 | post_create_environment: 18 | - python -m pip install sphinx_rtd_theme 19 | # Build documentation in the "docs/" directory with Sphinx 20 | sphinx: 21 | configuration: doc/conf.py 22 | # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs 23 | # builder: "dirhtml" 24 | # Fail on all warnings to avoid broken references 25 | # fail_on_warning: true 26 | 27 | # Optionally build your docs in additional formats such as PDF and ePub 28 | # formats: 29 | # - pdf 30 | # - epub 31 | 32 | # Optional but recommended, declare the Python requirements required 33 | # to build your documentation 34 | # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 35 | # python: 36 | # install: 37 | # - requirements: docs/requirements.txt -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | Active Contributors (in alphabetical order) 2 | =========================================== 3 | 4 | - Frédéric Blanqui (coordinator) 5 | - Alessio Coltellacci (2023-) 6 | - Claudio Sacerdoti Coen (2023-) 7 | - Abdelghani Alidra (2024-) 8 | - Bruno Barras (2025-) 9 | 10 | Past Contributors (in alphabetical order) 11 | ========================================= 12 | 13 | - Gabriel Hondet (2019-2022) 14 | - Ashish Kumar Barnawal (2020-2021) 15 | - Emilio Gallego (2018-2021) 16 | - Aurélien Castre (2021) 17 | - Yann Leray (2021) 18 | - Diego Riverio (2020) 19 | - Amélie Ledein (2020) 20 | - François Lefoulon (2020) 21 | - Rodolphe Lepigre (2017-2020) 22 | - Rehan Malak (2019-2020) 23 | - Yacine El Haddad (2019) 24 | - Guillaume Genestier (2019) 25 | - Houda Mouzoun (2019) 26 | - Aristomenis-Dionysios Papadopoulos (2019) 27 | - Franck Slama (2019) 28 | - Jui-Hsuan Wu (2019) 29 | - Christophe Raffalli (2017-2018) 30 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deducteam/lambdapi/3f6c848cffce384300bf2fd0745099a3c7303594/LICENSE.txt -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | TODO 2 | ==== 3 | 4 | Index and search 5 | ---------------- 6 | 7 | * Too many results found? 8 | 9 | anywhere >= (Π x: _, (= _ V# V#)) 10 | anywhere >= (Π x: _, (= _ x x)) 11 | 12 | * html tags in textual output :-( 13 | 14 | * would it be more reasonable to save the normalization rules 15 | when the index is created and apply them as default when searching, 16 | in particular when searching as a lambdapi command? 17 | 18 | * normalize queries when given as commands in lambdapi 19 | 20 | * alignments with same name ==> automatic preference? 21 | 22 | * better pagination 23 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SOURCEDIR = . 8 | BUILDDIR = _build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 20 | -------------------------------------------------------------------------------- /doc/dedukti.rst: -------------------------------------------------------------------------------- 1 | Compatibility with Dedukti 2 | ========================== 3 | 4 | Lambdapi can read `Dedukti 5 | `__ 6 | files with the extension ``.dk``, and translate Lambdapi files to 7 | Dedukti files, and vice versa, by using the ``export`` :doc:`command 8 | `. 9 | 10 | Moreover, a Lambdapi file can refer to a symbol declared in a Dedukti file. 11 | 12 | In case there are two files ``file.dk`` and ``file.lp``, ``file.lp`` is used. 13 | 14 | **Remarks on the export to Dedukti:** 15 | 16 | When a ``lp`` identifier or module/file name is not a valid ``dk`` 17 | identifier or module/file name (the ``lp`` and ``dk`` formats do not 18 | accept the same class of identifiers and module/file names), we try to 19 | rename them instead of failing: 20 | 21 | - ``lp`` identifiers that are not valid ``dk`` identifiers or that are 22 | ``dk`` keywords are enclosed between ``{|`` and ``|}``. 23 | 24 | - In module names, dots are replaced by underscores and, if a ``lp`` 25 | file requires the module ``mylib.logic.untyped.fol``, its 26 | translation will require the file 27 | ``mylib_logic_untyped_fol.dk``. Therefore, in a package whose 28 | ``root_path`` is ``mylib.logic``, the file ``untyped/fol.lp`` is 29 | translated into ``mylib_logic_untyped_fol.dk``. 30 | -------------------------------------------------------------------------------- /doc/implementation.rst: -------------------------------------------------------------------------------- 1 | Implementation choices 2 | ---------------------- 3 | 4 | - Back-tracking in interactive proofs is implemented using the “timed” 5 | references of the `Timed`_ library. 6 | 7 | - Bindings in terms are implemented using the `Bindlib`_ library. 8 | 9 | - Parsing uses the `Menhir`_ library. 10 | 11 | .. _Timed: https://github.com/rlepigre/ocaml-timed 12 | .. _Bindlib: https://rlepigre.github.io/ocaml-bindlib/ 13 | .. _Menhir: http://gallium.inria.fr/~fpottier/menhir/ 14 | -------------------------------------------------------------------------------- /doc/latex.rst: -------------------------------------------------------------------------------- 1 | Include Lambdapi code in a Latex document 2 | ============================================= 3 | 4 | With the `listings `__ package: 5 | 6 | You need to include `lambdapi.tex `__. 7 | 8 | See an example `here `__. 9 | -------------------------------------------------------------------------------- /doc/profiling.rst: -------------------------------------------------------------------------------- 1 | Profiling 2 | ========= 3 | 4 | This document explains the use of standard profiling tools for the 5 | development of ``lambdapi``. 6 | 7 | Using Linux ``perf`` 8 | -------------------- 9 | 10 | The quickest way to obtain a per-symbol execution time is ``perf``. It 11 | is simple to use, provided that you have the right privileges on your 12 | machine. No change is required in the build procedure, but ``lambdapi`` 13 | must be invoked as follows. 14 | 15 | .. code:: bash 16 | 17 | dune exec -- perf record lambdapi [LAMBDAPI_OPTIONS] 18 | 19 | The program behaves as usual, but a trace is recorded in file 20 | ``perf.data``. The data can then be displayed with the following 21 | command. 22 | 23 | .. code:: bash 24 | 25 | perf report 26 | 27 | Profiling using Gprof 28 | --------------------- 29 | 30 | The ``gprof`` tool can be used to obtain a more precise (and thorough) 31 | execution trace. However, it requires modifying the ``src/dune`` file by 32 | replacing 33 | 34 | :: 35 | 36 | (executable 37 | (name lambdapi) 38 | 39 | with the following. 40 | 41 | :: 42 | 43 | (executable 44 | (name lambdapi) 45 | (ocamlopt_flags (:standard -p)) 46 | 47 | This effectively adds the ``-p`` flag to every invocation of 48 | ``ocamlopt``. 49 | 50 | After doing that, ``lambdapi`` can be launched on the desired example, 51 | to record an execution trace. This has the (side-)effect of producing a 52 | ``gmon.out`` file. To retrieve the data, the following command can then 53 | be used. 54 | 55 | .. code:: bash 56 | 57 | gprof _build/install/default/lambdapi gmon.out > profile.txt 58 | 59 | It takes two arguments: the path to the ``lambdapi`` binary used to 60 | generate the profiling data, and the profiling data itself. 61 | -------------------------------------------------------------------------------- /doc/testing.rst: -------------------------------------------------------------------------------- 1 | Testing 2 | =================== 3 | 4 | You can run tests using the following commands. 5 | 6 | .. code:: bash 7 | 8 | make tests # Unit tests (not stopping on failure). 9 | make real_tests # Unit tests (stopping on first failure). 10 | 11 | make dklib # Checks files at https://github.com/rafoo/dklib/ 12 | make focalide # Checks files generated from the Focalize library 13 | make holide # Checks files generated from the OpenTheory library 14 | make matita # Checks the traduction of Matita's arithmetic library. 15 | make verine # Checks files generated by the VeriT prover. 16 | make iprover # Checks files generated by iProverModulo. 17 | make zenon_modulo # Checks files generated by ZenonModulo. 18 | 19 | -------------------------------------------------------------------------------- /doc/ui.rst: -------------------------------------------------------------------------------- 1 | User interfaces 2 | --------------- 3 | 4 | Lambdapi provides a language server for (an extension of) the `LSP 5 | protocol`_, which is supported by most editors. See below for setting 6 | up common editors. 7 | 8 | The server is run using the command ``lambdapi lsp``. The flag 9 | ``--standard-lsp`` can be used to enforce strict LSP protocol and, thus, 10 | currently, deactivate goal display. 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | 15 | emacs.rst 16 | vscode.rst 17 | vim.rst 18 | 19 | .. _LSP protocol: https://microsoft.github.io/language-server-protocol/ 20 | -------------------------------------------------------------------------------- /doc/vim.rst: -------------------------------------------------------------------------------- 1 | `Vim `__ (not maintained anymore) 2 | ======================================================= 3 | 4 | A minimal Vim mode is provided to edit Lambdapi files. It provides 5 | syntax highlighting and abbreviations to enter unicode characters. 6 | It does not provide support for the LSP server yet. 7 | 8 | Installation 9 | ------------ 10 | 11 | Installing from sources 12 | 13 | The Vim mode can be installed using the command 14 | ``make install_vim`` in the ``lambdapi`` repository. 15 | 16 | Installing with Opam 17 | 18 | If Lambdapi is installed with Opam or using ``dune build`` from the 19 | sources, then the line 20 | 21 | .. code:: vim 22 | 23 | set rtp+=~/.opam/$OPAM_SWITCH_PREFIX/share/vim 24 | 25 | must be added to the Vim configuration file (``~/.vimrc`` for Vim, 26 | ``~/.config/nvim/init.vim`` for NeoVim). 27 | -------------------------------------------------------------------------------- /dune: -------------------------------------------------------------------------------- 1 | ; Add project-wide flags here. 2 | (env 3 | (dev (flags :standard)) 4 | (release (flags :standard))) 5 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | 3 | (generate_opam_files false) 4 | 5 | (name lambdapi) 6 | (source (github Deducteam/lambdapi)) 7 | (authors "Deducteam") 8 | (maintainers "dedukti-dev@inria.fr") 9 | (license CECILL-2.1) 10 | 11 | (using menhir 2.0) 12 | 13 | (package 14 | (name lambdapi) 15 | (synopsis "Proof assistant for the λΠ-calculus modulo rewriting") 16 | (description 17 | 18 | "Lambdapi is an interactive proof assistant for the λΠ-calculus modulo 19 | rewriting. It can call external automated theorem provers via Why3. 20 | The user manual is on https://lambdapi.readthedocs.io/. 21 | A standard library and other developments are available on 22 | https://github.com/Deducteam/opam-lambdapi-repository/. An extension 23 | for Emacs is available on MELPA. An extension for VSCode is available 24 | on the VSCode Marketplace. Lambdapi can read Dedukti files. It 25 | includes checkers for local confluence and subject reduction. It also 26 | provides commands to export Lambdapi files to other formats or 27 | systems: Dedukti, Coq, HRS, CPF.") 28 | 29 | (depends 30 | (ocaml (>= 4.09.0)) 31 | (menhir (>= 20200624)) 32 | (sedlex (>= 3.2)) 33 | (alcotest :with-test) 34 | (alt-ergo :with-test) 35 | (dedukti (and :with-test (>= 2.7))) 36 | (bindlib (>= 5.0.1)) 37 | (timed (>= 1.0)) 38 | (pratter (and (>= 3.0.0) (< 4))) 39 | (camlp-streams (>= 5.0)) 40 | (why3 (>= 1.8.0)) 41 | (yojson (>= 1.6.0)) 42 | (cmdliner (>= 1.1.0)) 43 | (stdlib-shims (>= 0.1.0)) 44 | (lwt_ppx (>= 1.0.0)) 45 | (dream (>= 1.0.0~alpha3)) 46 | (uri (>= 1.1)) 47 | ) 48 | ) 49 | -------------------------------------------------------------------------------- /editors/emacs/.gitignore: -------------------------------------------------------------------------------- 1 | *.elc 2 | *.tar 3 | -------------------------------------------------------------------------------- /editors/emacs/CHANGES.md: -------------------------------------------------------------------------------- 1 | All notable changes to this project will be documented in this file. 2 | 3 | The format is based on [Keep a Changelog](https://keepachangelog.com/), 4 | and this project adheres to [Semantic Versioning](https://semver.org/). 5 | 6 | ## 01/02/2025 7 | 8 | ### Added 9 | - Auto scroll to the first goal in the `Goals` buffer in case of many hypothesis 10 | - Check that the Goals and Logs buffers are displayed before displaying logs and goals 11 | 12 | ### Fixed 13 | - Show the error at the end of file if any. That was not working because navigation stoped at the location of last command and not further (see issue #1111) -------------------------------------------------------------------------------- /editors/emacs/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | VERSION = $(shell awk '/^;; Version: /{print $$3;exit}' lambdapi-mode.el) 3 | NAME = lambdapi-mode 4 | # The path to lambdapi built by dune 5 | LAMBDAPI = ../../_build/install/default/bin/lambdapi 6 | 7 | EMACS = emacs 8 | 9 | SRC = 10 | SRC += lambdapi-abbrev.el 11 | SRC += lambdapi-capf.el 12 | SRC += lambdapi-input.el 13 | SRC += lambdapi-layout.el 14 | SRC += lambdapi-mode.el 15 | SRC += lambdapi-mode-pkg.el 16 | SRC += lambdapi-proofs.el 17 | SRC += lambdapi-smie.el 18 | SRC += lambdapi-vars.el 19 | 20 | $(NAME)-$(VERSION).tar: $(SRC) 21 | mkdir -p "$(NAME)-$(VERSION)" 22 | cp *.el "$(NAME)-$(VERSION)" 23 | tar -cf "$(NAME)-$(VERSION)".tar "$(NAME)-$(VERSION)" 24 | 25 | lambdapi-mode-pkg.el: lambdapi-mode.el 26 | $(eval description := "A major mode for editing Lambdapi source code.") 27 | $(eval requirements := $(shell grep ";; Package-Requires: " lambdapi-mode.el | sed 's/"/\\"/g' | cut -d' ' -f5-)) 28 | @echo "(define-package \"$(NAME)\" \"$(VERSION)\"" > $@ 29 | @echo " \"$(description)\"" >> $@ 30 | @echo " '($(requirements))" >> $@ 31 | 32 | .PHONY: dist 33 | dist: $(NAME)-$(VERSION).tar 34 | 35 | .PHONY: check 36 | check: dist 37 | # This rule depends on the layout of dune. It builds the lambdapi 38 | # binary so that the "sandboxed" emacs can access it. 39 | cd ../.. && $(MAKE) lambdapi 40 | ./test.sh "$(NAME)" "$(VERSION)" "$(LAMBDAPI)" 41 | 42 | .PHONY: clean 43 | clean: 44 | rm -fr "$(NAME)-$(VERSION)".tar "$(NAME)-$(VERSION)" lambdapi-mode-pkg.el -------------------------------------------------------------------------------- /editors/emacs/README.md: -------------------------------------------------------------------------------- 1 | For instructions on how to install the lambdapi mode for Emacs please see https://lambdapi.readthedocs.io/en/latest/emacs.html. 2 | 3 | To install the devellopment version of lambdapi mode for Emacs please run on the current directory, `make dist`. This will generate a `$(NAME)-$(VERSION).tar` file. 4 | Then, in emacs run `M-x package-install-file RET /PATH/TO/TAR/FILE/$(NAME)-$(VERSION).tar RET` -------------------------------------------------------------------------------- /editors/emacs/THANKS.md: -------------------------------------------------------------------------------- 1 | 2 | The icons used are from the Emacs repository. 3 | 4 | See [Emacs](http://cvs.savannah.gnu.org/viewvc/emacs/emacs/etc/images/README?view=markup) 5 | for license info 6 | 7 | -------------------------------------------------------------------------------- /editors/emacs/TODO: -------------------------------------------------------------------------------- 1 | - Do not change the green zone and the goals when editing or adding a comment in the green zone. 2 | 3 | - Instead of printing the type on the bottom line of emacs, would it be possible to print it in a hover like it is done when there is an error? 4 | -------------------------------------------------------------------------------- /editors/emacs/lambdapi-abbrev.el: -------------------------------------------------------------------------------- 1 | ;;; lambdapi-abbrev.el --- Abbrevs for lambdapi -*- lexical-binding: t; -*- 2 | ;; SPDX-License-Identifier: CECILL-2.1 3 | ;;; Commentary: 4 | ;; 5 | ;; Abbreviations can be used to enter UTF-8 characters. 6 | ;; 7 | ;;; Code: 8 | (require 'lambdapi-vars) 9 | (defun lambdapi-local-abbrev (expansion) 10 | "Add abbreviation expanding word at point to EXPANSION. 11 | The abbreviation is added into the `local-abbrev-table', so it is available in 12 | all `lambdapi-mode' buffers. The `local-abbrev-table' is rewritten to directory 13 | local variables at each new definition." 14 | (interactive "sExpands to:") 15 | (let ((bufname (buffer-name)) 16 | (name (buffer-substring-no-properties 17 | (point) 18 | (save-excursion (forward-word (- 1)) (point))))) 19 | (define-abbrev local-abbrev-table name expansion nil :system t) 20 | (add-dir-local-variable 21 | 'lambdapi-mode 'eval 22 | `(define-abbrev local-abbrev-table ,name ,expansion nil :system t)) 23 | (save-buffer) 24 | (switch-to-buffer bufname))) 25 | 26 | (defun lambdapi-abbrev-setup () 27 | "Set up lambdapi abbreviation." 28 | (abbrev-mode 1) 29 | (define-key lambdapi-mode-map (kbd "C-c C-a") #'lambdapi-local-abbrev)) 30 | 31 | (provide 'lambdapi-abbrev) 32 | ;;; lambdapi-abbrev.el ends here 33 | -------------------------------------------------------------------------------- /editors/emacs/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Test the lambdapi-mode. 3 | # The script 4 | # - downloads a fresh and basic configuration, 5 | # - creates a temporary directory 6 | # - copies the lambdapi binary in the directory 7 | # - and launches emacs in it. 8 | # You can create a new 'foo.lp' to try the mode. 9 | 10 | # Usage: tests.sh NAME VERSION LAMBDAPI 11 | 12 | set -eu 13 | NAME="$1" 14 | VERSION="$2" 15 | BIN="$3" 16 | tmp="$(mktemp -d)" 17 | make dist 18 | cp "${NAME}-${VERSION}.tar" "${tmp}" 19 | mkdir -p "${tmp}"/bin 20 | cp ${BIN} "${tmp}"/bin/lambdapi 21 | (cd "${tmp}" || exit 1 22 | curl https://sanemacs.com/sanemacs.el > sanemacs.el 23 | { 24 | echo '(setq package-check-signature nil)'; 25 | echo '(use-package eglot)'; 26 | echo '(use-package math-symbol-lists)'; 27 | echo '(use-package highlight)'; 28 | } >> sanemacs.el 29 | PATH="bin:$PATH" emacs --quick -l sanemacs.el \ 30 | --eval "(package-install-file \"${NAME}-${VERSION}.tar\")") 31 | rm -rf "${tmp}" 32 | -------------------------------------------------------------------------------- /editors/vim/dune: -------------------------------------------------------------------------------- 1 | (install 2 | (section share_root) 3 | (package lambdapi) 4 | (files 5 | (ftdetect/lambdapi.vim as vim/ftdetect/lambdapi.vim) 6 | (ftdetect/dedukti.vim as vim/ftdetect/dedukti.vim) 7 | (syntax/lambdapi.vim as vim/syntax/lambdapi.vim) 8 | (syntax/dedukti.vim as vim/syntax/dedukti.vim))) 9 | -------------------------------------------------------------------------------- /editors/vim/ftdetect/dedukti.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.dk set filetype=dedukti 2 | -------------------------------------------------------------------------------- /editors/vim/ftdetect/lambdapi.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.lp set filetype=lambdapi 2 | -------------------------------------------------------------------------------- /editors/vim/syntax/dedukti.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Dedukti 3 | " Maintainer: Rodolphe Lepigre 4 | " Last Change: 24/10/2017 5 | " Version: 1.0 6 | " Original Author: Rodolphe Lepigre 7 | 8 | if exists("b:current_syntax") 9 | finish 10 | endif 11 | 12 | " Keywords 13 | syntax keyword Type Type 14 | syntax keyword Keyword def inj thm 15 | syntax match Keyword "\[" 16 | syntax match Keyword "\]" 17 | syntax match Keyword "(" 18 | syntax match Keyword ")" 19 | syntax match Keyword ":" 20 | syntax match Keyword "=>" 21 | syntax match Keyword ":=" 22 | syntax match Keyword "->" 23 | syntax match Keyword "-->" 24 | syntax match Keyword "," 25 | syntax match Keyword "\." 26 | 27 | " Commands 28 | syntax match Include "#EVAL" 29 | syntax match Include "#INFER" 30 | syntax match Include "#CHECK" 31 | syntax match Include "#CHECKNOT" 32 | syntax match Include "#ASSERT" 33 | syntax match Include "#ASSERTNOT" 34 | syntax match Include "#REQUIRE" 35 | syntax match Include "#PROOF" 36 | syntax match Include "#REFINE" 37 | syntax match Include "#REWRITE" 38 | syntax match Include "#QED" 39 | syntax match Include "#FOCUS" 40 | syntax match Include "#SIMPL" 41 | syntax match Include "#PRINT" 42 | 43 | " Comments 44 | syn keyword Todo contained TODO FIXME NOTE 45 | syn region Comment start="(;" end=";)" contains=Todo,Comment 46 | 47 | 48 | -------------------------------------------------------------------------------- /editors/vscode/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | out 3 | npm-debug.log 4 | -------------------------------------------------------------------------------- /editors/vscode/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "ms-vscode.vscode-typescript-tslint-plugin", 6 | "guidotapia2.unicode-math-vscode" 7 | ] 8 | } -------------------------------------------------------------------------------- /editors/vscode/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ], 16 | "outFiles": [ 17 | "${workspaceFolder}/out/**/*.js" 18 | ], 19 | "preLaunchTask": "${defaultBuildTask}" 20 | }, 21 | { 22 | "name": "Extension Tests", 23 | "type": "extensionHost", 24 | "request": "launch", 25 | "runtimeExecutable": "${execPath}", 26 | "args": [ 27 | "--extensionDevelopmentPath=${workspaceFolder}", 28 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" 29 | ], 30 | "outFiles": [ 31 | "${workspaceFolder}/out/test/**/*.js" 32 | ], 33 | "preLaunchTask": "${defaultBuildTask}" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /editors/vscode/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false // set this to true to hide the "out" folder with the compiled JS files 5 | }, 6 | "search.exclude": { 7 | "out": true // set this to false to include "out" folder in search results 8 | }, 9 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 10 | "typescript.tsc.autoDetect": "off" 11 | } -------------------------------------------------------------------------------- /editors/vscode/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /editors/vscode/.vscodeignore: -------------------------------------------------------------------------------- 1 | **/*.ts 2 | **/tsconfig.json 3 | -------------------------------------------------------------------------------- /editors/vscode/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | - to test a new extension, you first need to uninstall the current one 2 | before installing the new one following INSTALL.md. 3 | 4 | - update docs/ui/vscode.rst if you change README.md: 5 | vscode.rst indeed includes README.md after conversion to rst 6 | using for instance https://cloudconvert.com/md-to-rst 7 | -------------------------------------------------------------------------------- /editors/vscode/LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deducteam/lambdapi/3f6c848cffce384300bf2fd0745099a3c7303594/editors/vscode/LICENSE.txt -------------------------------------------------------------------------------- /editors/vscode/Makefile: -------------------------------------------------------------------------------- 1 | default: compile 2 | 3 | compile: node_modules 4 | npm run compile 5 | 6 | node_modules: 7 | npm install 8 | 9 | clean: 10 | rm -rf node_modules out 11 | 12 | VSCE = $(shell which vsce) 13 | JQ = $(shell which jq) 14 | ifneq ($(VSCE),) 15 | ifneq ($(JQ),) 16 | VERSION = $(shell cat package.json | jq '.version') 17 | endif 18 | 19 | .PHONY: install_local 20 | install_local: compile 21 | ifeq ($(VERSION),) 22 | @echo 'jq not found. Please install with sudo apt install jq or export version before calling install_local (PLEASE use same as in package.json): VERSION=X.Y.Z make install_local' 23 | else 24 | vsce package 25 | code --install-extension lambdapi-$(VERSION).vsix 26 | endif 27 | 28 | else 29 | install_local: 30 | @echo 'vsce not found. Please install with npm install -g @vscode/vsce or export in the PATH. Details can be found in INSTALL.md' 31 | endif 32 | -------------------------------------------------------------------------------- /editors/vscode/THANKS.md: -------------------------------------------------------------------------------- 1 | This plugin was initially inspired from Christian J. Bell's [VSCoq](https://github.com/coq-community/vscoq/) plugin. 2 | -------------------------------------------------------------------------------- /editors/vscode/TODO: -------------------------------------------------------------------------------- 1 | - Add an electric mode in VSCode. 2 | 3 | - Do not change the green zone and the goals when editing or adding a comment in the green zone. 4 | -------------------------------------------------------------------------------- /editors/vscode/lp.configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "comments": { 3 | "lineComment": "//", 4 | "blockComment": [ "/*", "*/" ] 5 | }, 6 | "brackets": [ 7 | ["{", "}"], 8 | ["[", "]"], 9 | ["(", ")"] 10 | ], 11 | "indentationRules": { 12 | "increaseIndentPattern": "begin\\s*$", 13 | "decreaseIndentPattern": "(? { 7 | let serverOptions = { 8 | command: lpLaunchCommand, 9 | args: lspLaunchArgs 10 | }; 11 | return new LanguageClient( 12 | "lambdapi", 13 | "lambdapi language server", 14 | serverOptions, 15 | clientOptions); 16 | }; 17 | activateClientLSP(context, cf); 18 | } 19 | 20 | export function deactivate() { 21 | deactivateClientLSP(); 22 | } 23 | -------------------------------------------------------------------------------- /editors/vscode/src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // "extends": "../tsconfig-base.json", 3 | "compilerOptions": { 4 | "module": "CommonJS", 5 | "target": "ESNext" 6 | }, 7 | 8 | "files": [ 9 | "client.ts", 10 | "browser.ts" 11 | ], 12 | // "include": ["**/*.ts", "../lib/**/*.ts"] 13 | } 14 | -------------------------------------------------------------------------------- /editors/vscode/tsconfig-base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "sourceMap": true, 4 | "strict": true, 5 | "rootDir": ".", 6 | "outDir": "out", 7 | // "composite": true, 8 | // "noEmit": true, 9 | "skipLibCheck": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /editors/vscode/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es2020", 5 | "outDir": "out", 6 | "sourceMap": true, 7 | "strict": true, 8 | "rootDir": ".", 9 | "skipLibCheck": true 10 | }, 11 | "files": [ 12 | "src/client.ts", 13 | "src/browser.ts" 14 | ], 15 | // Default if not specified is node_modules, out, etc... 16 | "exclude": [ 17 | "node_modules", 18 | "out", 19 | ".vscode-test" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /libraries/README.md: -------------------------------------------------------------------------------- 1 | How to translate the Holide Dedukti library to Coq? 2 | ------------------------------------------- 3 | 4 | Extracting and patching the Holide library: 5 | ``` 6 | make holide 7 | cd libraries/holide 8 | ../patch-filenames.sh 9 | cp . ../holide-bak 10 | ``` 11 | 12 | Checking the Holide dk files (optional): 13 | ``` 14 | make -j 7 -f ../coq2dk dko 15 | ``` 16 | 17 | To translate Holide dk files to Coq, we need to patch those dk files a little bit. See the sources of the following scripts for details. 18 | 19 | Convert the Holide dk files to raw Coq files, and check them: 20 | ``` 21 | ../dk2rawcoq.sh 22 | ``` 23 | 24 | Convert the Holide dk files to Coq files using the fact that the Holide dk files use an encoding of simple type theory, and check them: 25 | ``` 26 | ../dk2sttcoq.sh 27 | ``` 28 | -------------------------------------------------------------------------------- /libraries/coq.v: -------------------------------------------------------------------------------- 1 | Definition arr (A:Type) (B:Type) := A -> B. 2 | Definition imp (P Q: Prop) := P -> Q. 3 | Definition all (A:Type) (P:A->Prop) := forall x:A, P x. 4 | -------------------------------------------------------------------------------- /libraries/dk2coq.mk: -------------------------------------------------------------------------------- 1 | SRC := $(wildcard *.dk) 2 | 3 | default: $(SRC:%.dk=%.v) 4 | 5 | LAMBDAPI = lambdapi export -o stt_coq --encoding ../encoding.lp --mapping ../mapping.lp --renaming ../renaming.lp --requiring coq.v --no-implicits 6 | 7 | %.v: %.dk 8 | $(LAMBDAPI) $< > $@ 9 | 10 | .PHONY: dko 11 | dko: $(SRC:%.dk=%.dko) 12 | 13 | hol.dko: hol.dk 14 | dk check -e $@ 15 | 16 | %.dko: %.dk hol.dko 17 | dk check $*.dk 18 | -------------------------------------------------------------------------------- /libraries/dk2rawcoq.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo get back original dk files ... 4 | cp -f ../holide-bak/*.dk . 5 | rm -f coq.v 6 | 7 | #../patch-filenames.sh 8 | 9 | # patch dk files 10 | echo patch hol.dk ... 11 | # remove require's, rewriting rules, and the definitions of the encoding symbols since they are already defined in sttfa.v 12 | sed -i -e '/^#REQUIRE /d' -e '/^type /d' -e '/^bool /d' -e '/^ind /d' -e '/^arr /d' -e '/^def term /d' -e '/ --> /d' -e '/^def proof /d' -e '/^imp /d' -e '/^forall /d' hol.dk 13 | # require sttfa, qualify encoding symbols, and rename symbols that are Coq keywords 14 | sed -i -e '1i #REQUIRE sttfa.' -e 's/type/sttfa._Set/g' -e 's/bool/sttfa.prop/g' -e 's/arr/sttfa.arr/g' -e 's/term/sttfa.El/g' -e 's/proof/sttfa.Prf/g' -e 's/imp/sttfa.imp/g' -e 's/forall/sttfa.all/g' -e 's/exists/_exists/g' hol.dk 15 | 16 | echo rename the symbols of the encoding in all the dk files ... 17 | sed -i -e 's/hol.type/sttfa._Set/g' -e 's/hol.bool/sttfa.prop/g' -e 's/hol.ind/sttfa.ind/g' -e 's/hol.arr/sttfa.arr/g' -e 's/hol.term/sttfa.El/g' -e 's/hol.proof/sttfa.Prf/g' -e 's/hol.imp/sttfa.imp/g' -e 's/hol.forall/sttfa.all/g' -e 's/hol.exists/hol._exists/g' *.dk 18 | 19 | # check dk files (optional) 20 | # make -j 7 -f ../dk2coq.mk dko 21 | 22 | # translate dk files to v files 23 | cp -f ../sttfa.v . 24 | make LAMBDAPI='lambdapi export -o raw_coq --no-implicits' -j 7 -f ../dk2coq.mk 25 | 26 | # post-processing for checking files in Emacs 27 | echo replace \"Require\" by \"From Holide Require\" in all v files ... 28 | sed -i -e 's/^Require /From Holide Require /' *.v 29 | 30 | # check generated v files 31 | echo -R . Holide `ls *.v` > _CoqProject 32 | coq_makefile -f _CoqProject -o coq.mk 33 | rm -f *.vo 34 | make -j 7 -f coq.mk 35 | -------------------------------------------------------------------------------- /libraries/dk2sttcoq.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo get back original dk files ... 4 | cp -f ../holide-bak/*.dk . 5 | rm -f sttfa.v 6 | 7 | #../patch-filenames.sh 8 | 9 | # patch dk files 10 | echo qualify encoding symbols in hol.dk ... 11 | # symbols defined in hol.dk 12 | for n in `awk '/^def /{print$2;next}/^[a-zA-Z0-9_]+ /{print$1}' hol.dk` 13 | do 14 | sed -i -e "s/ $n / hol.$n /g" -e "s/ $n\./ hol.$n./g" -e "s/($n /(hol.$n /g" -e "s/ $n)/ hol.$n)/g" -e "s/ $n$/ hol.$n/g" hol.dk 15 | done 16 | sed -i -e 's/^hol.//' -e 's/def hol./def /' -e 's/thm hol./thm /' hol.dk 17 | 18 | # because "type" is not accepted in mapping.lp 19 | echo replace \"hol.type\" by \"hol.typ\" in all dk files ... 20 | sed -i -e 's/^type /typ /' hol.dk 21 | sed -i -e 's/hol.type/hol.typ/g' *.dk 22 | 23 | # check dk files (optional) 24 | # make -j 7 -f ../dk2coq.mk dko 25 | 26 | # translate dk files to v files 27 | cp ../coq.v . 28 | make -j 7 -f ../dk2coq.mk 29 | 30 | # post-processing for checking files in Emacs 31 | echo replace \"Require\" by \"From Holide Require\" in all v files ... 32 | sed -i -e 's/^Require /From Holide Require /' *.v 33 | 34 | # check generated v files 35 | echo -R . Holide `ls *.v` > _CoqProject 36 | coq_makefile -f _CoqProject -o coq.mk 37 | rm -f *.vo 38 | make -j 7 -f coq.mk 39 | -------------------------------------------------------------------------------- /libraries/encoding.lp: -------------------------------------------------------------------------------- 1 | // dk/lp symbols used for encoding simple type theory 2 | 3 | builtin "Set" ≔ hol.typ; 4 | builtin "prop" ≔ hol.bool; 5 | builtin "arr" ≔ hol.arr; 6 | builtin "El" ≔ hol.term; 7 | builtin "Prf" ≔ hol.proof; 8 | builtin "eq" ≔ hol.eq; 9 | builtin "not" ≔ hol.not; 10 | builtin "imp" ≔ hol.imp; 11 | builtin "and" ≔ hol.and; 12 | builtin "or" ≔ hol.or; 13 | builtin "all" ≔ hol.forall; 14 | builtin "ex" ≔ hol.exists; 15 | -------------------------------------------------------------------------------- /libraries/mapping.lp: -------------------------------------------------------------------------------- 1 | // dk/lp symbols (on the right) the declarations of which are removed 2 | // and whose uses are replaced by the given Coq expressions (on the left) 3 | 4 | builtin "Type" ≔ hol.typ; 5 | builtin "Prop" ≔ hol.bool; 6 | builtin "coq.arr" ≔ hol.arr; 7 | builtin "coq.imp" ≔ hol.imp; 8 | builtin "coq.all" ≔ hol.forall; 9 | builtin "@eq" ≔ hol.eq; 10 | builtin "@eq_refl" ≔ hol.REFL; 11 | -------------------------------------------------------------------------------- /libraries/matita.awk: -------------------------------------------------------------------------------- 1 | BEGIN{r=0} 2 | /def le_fact_1z :/{r=1;print"le_fact_1z :";next} 3 | /:=/{if(r==1){print".\n(; :=";r=0;next}else{print;next}} 4 | /def ab_times_cd :/{print";)\n",$0;next} 5 | {print;next} 6 | -------------------------------------------------------------------------------- /libraries/matita/LPSearch.lp: -------------------------------------------------------------------------------- 1 | rule cic.Term _ $x ↪ $x; 2 | rule cic.lift _ _ $x ↪ $x; 3 | -------------------------------------------------------------------------------- /libraries/patch-filenames.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo replace dashes by underscores in filenames ... 4 | for f in *.dk 5 | do 6 | g=`echo $f | sed -e 's/-/_/g'` 7 | if test "$f" != "$g" 8 | then 9 | echo rename $f into $g 10 | mv $f $g 11 | fi 12 | done 13 | -------------------------------------------------------------------------------- /libraries/renaming.lp: -------------------------------------------------------------------------------- 1 | // map for renaming dk/lp identifiers (on the right) 2 | // to Coq expressions (on the left) 3 | 4 | builtin "Exists" ≔ exists; 5 | -------------------------------------------------------------------------------- /libraries/sttfa.v: -------------------------------------------------------------------------------- 1 | Inductive _Set : Type := 2 | | prop : _Set 3 | | ind : _Set 4 | | arr : _Set -> _Set -> _Set. 5 | 6 | Axiom Ind : Type. 7 | 8 | Fixpoint _El B (t:_Set): Type := 9 | match t with 10 | | prop => B 11 | | ind => Ind 12 | | arr u v => _El B u -> _El B v 13 | end. 14 | 15 | #[bypass_check(positivity)] 16 | Inductive _Prop : Type := 17 | | imp : _Prop -> _Prop -> _Prop 18 | | all : forall a, (_El _Prop a -> _Prop) -> _Prop. 19 | 20 | Definition El := _El _Prop. 21 | 22 | Fixpoint Prf (p:El prop) : Type := 23 | match p with 24 | | imp x y => Prf x -> Prf y 25 | | all a q => forall x : El a, Prf (q x) 26 | end. 27 | -------------------------------------------------------------------------------- /misc/.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.log 3 | example.pdf 4 | -------------------------------------------------------------------------------- /misc/example.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{listings} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{amssymb} 6 | \usepackage{mathtools} 7 | \usepackage{xcolor} 8 | 9 | \input{lambdapi} 10 | \lstset{language=Lambdapi} 11 | %\lstMakeShortInline{"} 12 | %\renewcommand\v[2][]{\lstinline[#1]{#2}} 13 | 14 | \title{Setup of the {\tt listings} package for including {\tt lambdapi} code} 15 | \author{Lambdapi development team} 16 | \date{7 December 2019} 17 | 18 | \begin{document} 19 | 20 | \maketitle 21 | 22 | The command \verb|\lstinputlisting{../tests/OK/nat.lp}| gives:\\ 23 | 24 | \lstinputlisting{../tests/OK/nat.lp} 25 | 26 | \end{document} 27 | -------------------------------------------------------------------------------- /misc/gen_version.ml: -------------------------------------------------------------------------------- 1 | let version = 2 | (* Trick to check whether the watermark has been substituted. *) 3 | if "%%VERSION%%" <> "%%" ^ "VERSION%%" then "%%VERSION%%" else 4 | (* If not, we fallback to git version. *) 5 | let cmd = "git describe --dirty --always" in 6 | let (oc, ic, ec) = Unix.open_process_full cmd (Unix.environment ()) in 7 | let version = 8 | try Printf.sprintf "dev-%s" (input_line oc) 9 | with End_of_file -> "unknown" 10 | in 11 | match Unix.close_process_full (oc, ic, ec) with 12 | | Unix.WEXITED(0) -> version 13 | | _ -> "unknown" 14 | 15 | let _ = 16 | let line fmt = Format.printf (fmt ^^ "@.") in 17 | line "(** Version informations. *)"; 18 | line ""; 19 | line "(** [version] gives a version description. *)"; 20 | line "let version : string = %S" version 21 | -------------------------------------------------------------------------------- /misc/git_hook_helper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -euf -o noclobber 4 | 5 | dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) 6 | usage="Usage: $(basename "$0") [-b] 7 | Set up git pre-commit hook. 8 | 9 | Arguments: 10 | -b Include compilation in hook. 11 | " 12 | sanity_only=true 13 | while getopts 'bh' arg; do 14 | case "${arg}" in 15 | b) sanity_only='';; 16 | h) printf '%s' "${usage}" 17 | exit 0 18 | ;; 19 | *) printf 'Invalid option\\n' 20 | printf '%s' "${usage}" 21 | exit 1 22 | ;; 23 | esac 24 | done 25 | 26 | git_root="$(realpath "${dir}/../.git")" 27 | 28 | hook_path="${git_root}/hooks/pre-commit" 29 | hook_cmd='' 30 | ## Set hook command depending on cli arguments 31 | if [ -n "${sanity_only}" ]; then 32 | hook_cmd='if [ ! -z "$(make sanity_check)" ]; then 33 | echo "Sanity check failed." 34 | exit 1 35 | fi' 36 | else 37 | hook_cmd='if [ ! -z "$(make sanity_check)" ] || ! make bin; then 38 | echo "Sanity check or compilation failed." 39 | exit 1 40 | fi' 41 | fi 42 | 43 | if [ -f "${hook_path}" ]; then 44 | printf 'Pre-commit hook [%s] found. 45 | Remove it or add the command 46 | %s 47 | ' "${hook_path}" "${hook_cmd}" 48 | exit 1 49 | fi 50 | 51 | printf '#!/bin/sh\n%s\n' "${hook_cmd}" > "${hook_path}" 52 | chmod 755 "${hook_path}" 53 | -------------------------------------------------------------------------------- /misc/lambdapi.tex: -------------------------------------------------------------------------------- 1 | \definecolor{lightgrey}{RGB}{240,240,240} 2 | 3 | \lstdefinelanguage{Lambdapi} 4 | { 5 | inputencoding=utf8, 6 | extendedchars=true, 7 | numbers=none, 8 | numberstyle={}, 9 | tabsize=2, 10 | basicstyle={\ttfamily\small\upshape}, 11 | backgroundcolor=\color{lightgrey}, 12 | keywords={abort,admit,admitted,apply,as,assert,assertnot,associative,assume,begin,builtin,commutative,compute,constant,debug,end,eval,fail,flag,focus,generalize,have,in,induction,inductive,infix,injective,left,let,notation,off,on,opaque,open,orelse,prefix,print,private,proofterm,protected,prover,prover_timeout,quantifier,refine,reflexivity,repeat,require,rewrite,right,rule,sequential,set,simplify,solve,symbol,symmetry,type,TYPE,unif_rule,verbose,why3,with}, 13 | sensitive=true, 14 | keywordstyle=\color{blue}, 15 | morecomment=[l]{//}, 16 | morecomment=[n]{/*}{*/}, 17 | commentstyle={\itshape\color{red}}, 18 | string=[b]{"}, 19 | stringstyle=\color{orange}, 20 | showstringspaces=false, 21 | literate= 22 | {λ}{$\lambda$}1 23 | {↪}{$\hookrightarrow$}1 24 | {→}{$\rightarrow$}1 25 | {Π}{$\Pi$}1 26 | {≔}{$\coloneqq$}1 27 | {⊢}{$\vdash$}1 28 | {≡}{$\equiv$}1 29 | {𝔹}{$\mathbb{B}$}1 30 | {𝕃}{$\mathbb{L}$}1 31 | {ℕ}{$\mathbb{N}$}1 32 | {α}{$\alpha$}1 33 | {β}{$\beta$}1 34 | {η}{$\eta$}1 35 | {π}{$\pi$}1 36 | {τ}{$\tau$}1 37 | {ω}{$\omega$}1 38 | {∧}{$\wedge$}1 39 | {≤}{$\le$}1 40 | {≠}{$\neq$}1 41 | {∉}{$\notin$}1 42 | {×}{$\times$}1 43 | {⋅}{$\cdot$}1 44 | } 45 | -------------------------------------------------------------------------------- /misc/rec_to_lp/Makefile: -------------------------------------------------------------------------------- 1 | AWK ?= awk 2 | SRC = rec_hs_to_lp.awk 3 | 4 | .PHONY: tests 5 | tests: 6 | $(AWK) -f $(SRC) tests/ex.hs 7 | 8 | .PHONY: clean 9 | clean: 10 | $(RM) -r DEDUKTI/ HASKELL/ CAFEOBJ-B/ MAUDE/ OCAML/ 11 | -------------------------------------------------------------------------------- /misc/rec_to_lp/README.md: -------------------------------------------------------------------------------- 1 | # Translating from REC to lambdapi 2 | 3 | This directory contains tools to translate files from the 4 | [REC](http://rec.gforge.inria.fr) file format to lp files. What we do 5 | for the moment is to use the translations from REC to Haskell and then 6 | translate files from haskell to lambdapi. 7 | 8 | ## Usage 9 | 10 | REC files can be retrieved from 11 | . The haskell files are 12 | in `rec/2019-CONVECS/HASKELL/`. Then use the awk script, 13 | 14 | ```bash 15 | ./rec_hs_to_lp.awk .hs > .lp 16 | lambdapi out.lp 17 | ``` 18 | 19 | -------------------------------------------------------------------------------- /misc/rec_to_lp/tests/ex.hs: -------------------------------------------------------------------------------- 1 | data Nat = D0 | S Nat 2 | deriving (Show, Eq, Ord) 3 | 4 | data Xbool = Xfalse | Xtrue 5 | deriving (Show, Eq, Ord) 6 | 7 | data Bit = X0 | X1 8 | deriving (Show, Eq, Ord) 9 | 10 | data Octet = BuildOctet Bit Bit Bit Bit Bit Bit Bit Bit 11 | deriving (Show, Eq, Ord) 12 | 13 | notBool :: Xbool -> Xbool 14 | andBool :: Xbool -> Xbool -> Xbool 15 | xorBool :: Xbool -> Xbool -> Xbool 16 | 17 | notBool Xfalse = Xtrue 18 | andBool Xfalse l = Xfalse 19 | xorBool Xtrue l = (notBool l) 20 | 21 | main = do 22 | print (andBool Xtrue Xtrue) 23 | print (andBool (xorBool Xfalse Xtrue) Xtrue) 24 | -------------------------------------------------------------------------------- /misc/sanity_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -eu 3 | 4 | files=`find src -name \*.ml -o -name \*.ml[iy]` 5 | 6 | # Check for long lines. 7 | gawk '/@see/{next}length>78 {print "In " FILENAME ", line " FNR " more than 78 characters..."}' $files 8 | 9 | # Check for trailing spaces. 10 | gawk '/.*\s$/ {print "In " FILENAME ", line " FNR " has trailing spaces..."}' $files 11 | 12 | # Check for tabulations. 13 | gawk '/.*\t.*/ {print "In " FILENAME ", line " FNR " contains tabulations..."}' `echo $files | sed -e 's|src/cli/init.ml||'` 14 | 15 | # Check for [Pervasives]. 16 | gawk '/Pervasives/ {print "In " FILENAME ", line " FNR " use of [Pervasives] should be replaced by [Stdlib]..."}' $files 17 | -------------------------------------------------------------------------------- /src/.dir-locals.el: -------------------------------------------------------------------------------- 1 | ;;; Directory Local Variables 2 | ;;; For more information see (info "(emacs) Directory Variables") 3 | 4 | ((tuareg-mode 5 | (tuareg-match-clause-indent . 2) 6 | (tuareg-match-patterns-aligned . t) 7 | (fill-column . 78))) 8 | -------------------------------------------------------------------------------- /src/cli/dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (name lambdapi) 3 | (public_name lambdapi) 4 | (modes byte native) 5 | (modules :standard) 6 | (libraries cmdliner lambdapi.lsp lambdapi.tool lambdapi.handle 7 | lambdapi.export unix)) 8 | -------------------------------------------------------------------------------- /src/common/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name common) 3 | (public_name lambdapi.common) 4 | (modules :standard) 5 | (libraries camlp-streams timed lambdapi.lplib) 6 | (flags -w +3)) 7 | -------------------------------------------------------------------------------- /src/common/escape.ml: -------------------------------------------------------------------------------- 1 | (** Escaped identifiers ["{|...|}"]. *) 2 | let escape : string -> string = fun s -> "{|" ^ s ^ "|}" 3 | 4 | (** [is_escaped s] tells if [s] begins with ["{|"] and ends with ["|}"] 5 | without overlapping. For efficiency, we just test that it starts with 6 | ['{']. *) 7 | let is_escaped : string -> bool = fun s -> s <> "" && s.[0] = '{' 8 | 9 | (** [unescape s] removes ["{|"] and ["|}"] if [s] is an escaped identifier. *) 10 | let unescape : string -> string = fun s -> 11 | if is_escaped s then String.(sub s 2 (length s - 4)) else s 12 | 13 | (** [p] is assumed to be a regular identifier. If [n] is a regular identifier 14 | too, then [add_prefix p n] is just [p ^ n]. Otherwise, it is ["{|" ^ p ^ 15 | unescape n ^ "|}"]. *) 16 | let add_prefix : string -> string -> string = fun p n -> 17 | if is_escaped n then escape (p ^ unescape n) else p ^ n 18 | 19 | (** [s] is assumed to be a regular identifier. If [n] is a regular identifier 20 | too, then [add_suffix n s] is just [n ^ s]. Otherwise, it is ["{" ^ 21 | unescape n ^ s ^ "|}"]. *) 22 | let add_suffix : string -> string -> string = fun n s -> 23 | if is_escaped n then escape (unescape n ^ s) else n ^ s 24 | -------------------------------------------------------------------------------- /src/common/logger.mli: -------------------------------------------------------------------------------- 1 | (** Functions for creating loggers. **) 2 | 3 | open Lplib open Base 4 | 5 | (** [log_enabled] is the cached result of whether there exists an enabled 6 | logging function. Its main use is to guard logging operations to avoid 7 | performing unnecessary computations.*) 8 | val log_enabled : unit -> bool 9 | 10 | (** Type of a logging function. It needs to be boxed for higher-rank 11 | polymorphism reasons *) 12 | type logger_pp = { pp: 'a. 'a outfmt -> 'a } 13 | 14 | (** [make key name desc] registers a new logger and returns its pp. *) 15 | val make : char -> string -> string -> logger_pp 16 | 17 | (** [set_debug value key] enables or disables the loggers corresponding to 18 | every character of [str] according to [value]. *) 19 | val set_debug : bool -> string -> unit 20 | 21 | (** [set_default_debug str] declares the debug flags of [str] to be enabled by 22 | default. *) 23 | val set_default_debug : string -> unit 24 | 25 | (** [get_activated_loggers ()] fetches the list of activated loggers, listed 26 | in a string *) 27 | val get_activated_loggers : unit -> string 28 | 29 | (** [reset_loggers ()] resets the debug flags to those by default. *) 30 | val reset_loggers : ?default:string -> unit -> unit 31 | 32 | (** [log_summary ()] gives the keys and descriptions for logging options. *) 33 | val log_summary : unit -> (char * string) list 34 | 35 | (** [set_debug_in b c f x] sets [c] logger to [b] for evaluating [f x]. *) 36 | val set_debug_in : bool -> char -> ('a -> 'b) -> 'a -> 'b 37 | -------------------------------------------------------------------------------- /src/common/path.ml: -------------------------------------------------------------------------------- 1 | (** Module paths in the Lambdapi library. *) 2 | 3 | open Lplib open Base 4 | 5 | module Path = 6 | struct 7 | (** Representation of a module name (roughly, a file path). *) 8 | type t = string list 9 | 10 | (** [pp ppf p] prints path [p] on the formatter [ppf]. Remark: to be used 11 | in Common only as it does not escape identifiers that need to be 12 | escaped. *) 13 | let pp : t pp = Lplib.List.pp string "." 14 | 15 | (** [compare] is a standard comparison function on paths. *) 16 | let compare : t cmp = Stdlib.compare 17 | 18 | end 19 | 20 | include Path 21 | 22 | module Set = Set.Make(Path) 23 | module Map = Map.Make(Path) 24 | 25 | (** [ghost s] creates a module path that cannot be entered by a user. *) 26 | let ghost : string -> Path.t = fun s -> [""; s] 27 | 28 | (** [default_dbpath] returns the default path of the index. *) 29 | let default_dbpath : string = 30 | match Sys.getenv_opt "HOME" with 31 | | Some s -> Filename.concat s ".LPSearch.db" 32 | | None -> ".LPSearch.db" 33 | -------------------------------------------------------------------------------- /src/core/coercion.ml: -------------------------------------------------------------------------------- 1 | open Common 2 | open Term 3 | 4 | let coerce : sym = 5 | let id = Pos.none "coerce" in 6 | Sign.add_symbol Ghost.sign Public Defin Eager false id None mk_Kind [] 7 | 8 | let apply a b t : term = add_args (mk_Symb coerce) [a; b; t] 9 | 10 | let _ = 11 | (* Add the rule [coerce $A $A $t ↪ $t] (but we don't have access to 12 | the parser here) *) 13 | let rule = 14 | let a = mk_Patt (Some 0, "A", [||]) 15 | and t = mk_Patt (Some 1, "t", [||]) in 16 | let lhs = [a;a;t] and arities = [|0;0|] and names = [|"A";"t"|] in 17 | { lhs; names; rhs=t; arity=3; arities; vars_nb=2; xvars_nb = 0; 18 | rule_pos = None } 19 | in 20 | Sign.add_rule Ghost.sign (coerce, rule) 21 | -------------------------------------------------------------------------------- /src/core/coercion.mli: -------------------------------------------------------------------------------- 1 | open Term 2 | 3 | val coerce : sym 4 | (** Symbol of the function that computes coercions. Coercion rules are added 5 | on that symbol. *) 6 | 7 | val apply : term -> term -> term -> term 8 | (** [apply a b t] creates the coercion of term [t] from type [a] to type 9 | [b]. *) 10 | -------------------------------------------------------------------------------- /src/core/dune: -------------------------------------------------------------------------------- 1 | (rule 2 | (targets version.ml) 3 | (action 4 | (with-stdout-to version.ml 5 | (run ocaml -I +unix unix.cma %{dep:../../misc/gen_version.ml}))) 6 | (mode fallback)) 7 | 8 | (library 9 | (name core) 10 | (public_name lambdapi.core) 11 | (synopsis "LambdaPi interactive theorem prover [core]") 12 | (modules :standard) 13 | (libraries lambdapi.common lambdapi.lplib pratter why3 unix)) 14 | -------------------------------------------------------------------------------- /src/core/ghost.ml: -------------------------------------------------------------------------------- 1 | (** Define a ghost signature that contain symbols used by the kernel 2 | but not defined by the user. *) 3 | 4 | open Timed 5 | open Term 6 | open Lplib 7 | open Extra 8 | open Common 9 | 10 | (** The signature holding ghost symbols. *) 11 | let sign = 12 | (* a path that's not in the image of the parser *) 13 | let path = Path.ghost "ghost" in 14 | let sign = { (Sign.dummy ()) with sign_path = path } in 15 | Sign.loaded := Path.Map.add path sign !(Sign.loaded); 16 | sign 17 | 18 | (** The path of the ghost signature *) 19 | let path = sign.sign_path 20 | 21 | (** [mem s] returns [true] if [s] is a ghost symbol. *) 22 | let mem s = StrMap.mem s.sym_name !(sign.sign_symbols) 23 | 24 | (** [iter f] iters function [f] on ghost symbols. *) 25 | let iter : (sym -> unit) -> unit = fun f -> 26 | StrMap.iter (fun _ s -> f s) !(sign.sign_symbols) 27 | -------------------------------------------------------------------------------- /src/core/infer.mli: -------------------------------------------------------------------------------- 1 | (** Type inference and checking *) 2 | 3 | open Term 4 | 5 | (** [infer_noexn p ctx t] returns [[Some(t',a)] where [t'] is a refinement of 6 | [t] and [a] is some type for [t'] in the context [ctx], and [None] 7 | otherwise, possibly adding new constraints in [p]. The metavariables of [p] 8 | are updated when a metavariable is instantiated or created. [ctx] must be 9 | well sorted. *) 10 | val infer_noexn : problem -> ctxt -> term -> (term * term) option 11 | 12 | (** [check_noexn p ctx t a] returns [Some t'] if [t] can be refined to [t'] of 13 | type [a] in context [ctx], and [None] otherwise, possibly adding new 14 | constraints in [p]. The metavariables of [p] are updated when a 15 | metavariable is instantiated or created. The context [ctx] and the type [a] 16 | must be well sorted. *) 17 | val check_noexn : problem -> ctxt -> term -> term -> term option 18 | 19 | val check_sort_noexn : problem -> ctxt -> term -> (term * term) option 20 | -------------------------------------------------------------------------------- /src/core/unif.mli: -------------------------------------------------------------------------------- 1 | (** Solving unification constraints. *) 2 | 3 | open Term 4 | 5 | (** [solve_noexn ~type_check p] tries to simplify the constraints of [p]. It 6 | returns [false] if it finds a constraint that cannot be 7 | satisfied. Otherwise, [p.to_solve] is empty but [p.unsolved] may still 8 | contain constraints that could not be simplified. Metavariable 9 | instantiations are type-checked only if [~type_check] is [true]. If 10 | [~type_check] is not specified, it defaults to [true]. *) 11 | val solve_noexn : ?type_check:bool -> problem -> bool 12 | -------------------------------------------------------------------------------- /src/core/unif_rule.ml: -------------------------------------------------------------------------------- 1 | (** Symbols and signature for unification rules. 2 | 3 | This module provides a signature to be used to handle unification rules. 4 | The signature is not attached to any real lambdapi file and is henceforth 5 | qualified to be a "ghost" signature. *) 6 | 7 | open Common 8 | open Term 9 | 10 | (** Symbol "≡". *) 11 | let equiv : sym = 12 | let id = Pos.none "≡" in 13 | let s = 14 | Sign.add_symbol Ghost.sign Public Defin Eager false id None mk_Kind [] in 15 | Timed.(s.sym_not := Infix(Pratter.Neither, 2.0)); 16 | s 17 | 18 | (** Symbol ";". *) 19 | let cons : sym = 20 | let id = Pos.none ";" in 21 | let s = 22 | Sign.add_symbol Ghost.sign Public Const Eager true id None mk_Kind [] in 23 | Timed.(s.sym_not := Infix(Pratter.Right, 1.0)); 24 | s 25 | 26 | (** [unpack eqs] transforms a term of the form 27 | [cons (equiv t u) (cons (equiv v w) ...)] 28 | into a list [[(t,u); (v,w); ...]]. *) 29 | let rec unpack : term -> (term * term) list = fun eqs -> 30 | match get_args eqs with 31 | | (Symb(s), [v; w]) -> 32 | if s == cons then 33 | match get_args v with 34 | | (Symb(e), [t; u]) when e == equiv -> (t, u) :: unpack w 35 | | _ -> assert false 36 | else if s == equiv then [(v, w)] 37 | else assert false 38 | | _ -> assert false 39 | 40 | (** [mem s] is true iff [s] belongs to [sign]. *) 41 | let mem : sym -> bool = fun s -> s == equiv || s == cons 42 | -------------------------------------------------------------------------------- /src/export/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name export) 3 | (public_name lambdapi.export) 4 | (modules :standard) 5 | (libraries lambdapi.core lambdapi.parsing lambdapi.lplib)) 6 | -------------------------------------------------------------------------------- /src/handle/compile.mli: -------------------------------------------------------------------------------- 1 | (** High-level compilation functions. *) 2 | 3 | open Common 4 | open Core 5 | 6 | val gen_obj : bool Stdlib.ref 7 | (** [gen_obj] indicates whether we should generate object files when compiling 8 | source files. The default behaviour is not to generate them. *) 9 | 10 | val compile : ?force:bool -> Path.t -> Sign.t 11 | (** [compile force mp] compiles module path [mp], forcing 12 | recompilation of up-to-date files if [force] is true. *) 13 | 14 | val compile_file : ?force:bool -> string -> Sign.t 15 | (** [compile_file force fname] looks for a package configuration file for 16 | [fname] and compiles [fname], forcing recompilation of up-to-date files if 17 | [force] is true. It is the main compiling function. It is called from the 18 | main program exclusively. *) 19 | 20 | (** The functions provided in this module perform the same computations as the 21 | ones defined earlier, but restore the console state and the library 22 | mappings when they have finished. An optional library mapping or console 23 | state can be passed as argument to change the settings. *) 24 | module PureUpToSign : sig 25 | val compile : 26 | ?lm:Path.t*string -> ?st:Console.State.t -> ?force:bool -> Path.t -> Sign.t 27 | val compile_file : 28 | ?lm:Path.t*string -> ?st:Console.State.t -> ?force:bool -> string -> Sign.t 29 | end 30 | -------------------------------------------------------------------------------- /src/handle/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name handle) 3 | (public_name lambdapi.handle) 4 | (modules :standard) 5 | (libraries lambdapi.core lambdapi.parsing lambdapi.tool)) 6 | -------------------------------------------------------------------------------- /src/handle/query.mli: -------------------------------------------------------------------------------- 1 | (** Handling of queries. *) 2 | 3 | open Core open Term 4 | open Parsing open Syntax 5 | open Common open Pos 6 | open Proof 7 | 8 | (** [infer pos p c t] returns a couple [(t',a)] where [a] is the type of [t] 9 | in context [c] and under constraints of problem [p]; and [t'] is the 10 | refinement of [t]. Note that [p] gets modified. Context [c] must well 11 | sorted. 12 | @raise Fatal if [t] cannot be typed. *) 13 | val infer : popt -> problem -> ctxt -> term -> term * term 14 | 15 | (** [check pos p c t a] checks that the term [t] has type [a] in context [c] 16 | and under the constraints of [p], and returns [t] refined. Context [c] 17 | must be well-sorted. Note that [p] is modified. 18 | @raise Fatal if [t] is not of type [a]. *) 19 | val check : popt -> problem -> ctxt -> term -> term -> term 20 | 21 | (** [check_sort pos p c t] checks that the term [t] has type [Type] or [Kind] 22 | in context [c] and under the constraints of [p]. Context [c] must be well 23 | sorted. 24 | @raise Fatal if [t] cannot be typed by a sort (Type or Kind). *) 25 | val check_sort : popt -> problem -> ctxt -> term -> term * term 26 | 27 | (** Result of query displayed on hover in the editor. *) 28 | type result = (unit -> string) option 29 | 30 | (** [handle_query ss ps q] *) 31 | val handle : Sig_state.t -> proof_state option -> p_query -> result 32 | -------------------------------------------------------------------------------- /src/handle/why3_tactic.mli: -------------------------------------------------------------------------------- 1 | (** Calling a prover using Why3. *) 2 | 3 | open Common 4 | open Core 5 | open Timed 6 | 7 | (** [default_prover] contains the name of the current prover. Note that it can 8 | be changed by using the "set prover " command. *) 9 | val default_prover : string ref 10 | 11 | (** [timeout] is the current time limit (in seconds) for a Why3 prover to find 12 | a proof. It can be changed with "set prover ". *) 13 | val timeout : int ref 14 | 15 | (** [handle ss pos ps prover_name gt] runs the Why3 prover corresponding to 16 | [prover_name] (if given or a default one otherwise) on the goal type [gt], 17 | and fails if no proof is found. *) 18 | val handle: Sig_state.t -> Pos.popt -> string option -> Proof.goal_typ -> unit 19 | -------------------------------------------------------------------------------- /src/lplib/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name lplib) 3 | (public_name lambdapi.lplib) 4 | (modules :standard) 5 | (foreign_stubs 6 | (language c) 7 | (names realpath)) 8 | (libraries stdlib-shims str unix)) 9 | -------------------------------------------------------------------------------- /src/lplib/filename.ml: -------------------------------------------------------------------------------- 1 | include Stdlib.Filename 2 | 3 | (** [realpath path] returns the absolute canonical path to file [path]. If 4 | [path] is invalid (i.e., it does not describe an existing file), then the 5 | exception [Invalid_argument] is raised. *) 6 | external realpath : string -> string = "c_realpath" 7 | 8 | let rec normalize fname = 9 | if Sys.file_exists fname then 10 | realpath fname 11 | else 12 | let dirnm = dirname fname in 13 | let basenm = basename fname in 14 | concat (normalize dirnm) basenm 15 | 16 | (** [current_dir ()] returns the canonical running path of the program. *) 17 | let current_dir : unit -> string = fun _ -> realpath "." 18 | -------------------------------------------------------------------------------- /src/lplib/option.ml: -------------------------------------------------------------------------------- 1 | open Base 2 | 3 | include Stdlib.Option 4 | 5 | type 'a t = 'a option 6 | 7 | let is_None : 'a t -> bool = fun o -> 8 | match o with None -> true | Some _ -> false 9 | 10 | let get : 'a -> 'a option -> 'a = fun d o -> 11 | match o with None -> d | Some e -> e 12 | 13 | let map_default : ('a -> 'b) -> 'b -> 'a option -> 'b = fun f d o -> 14 | match o with None -> d | Some e -> f e 15 | 16 | let fold : ('a -> 'b -> 'a) -> 'a -> 'b option -> 'a = fun f a o -> 17 | match o with None -> a | Some b -> f a b 18 | 19 | let cmp : 'a cmp -> 'a option cmp = fun cmp_elt o o' -> 20 | match o, o' with 21 | | None, None -> 0 22 | | None, Some _ -> -1 23 | | Some _, None -> 1 24 | | Some x, Some x' -> cmp_elt x x' 25 | 26 | let eq : 'a eq -> 'a option eq = fun eq_elt o1 o2 -> 27 | match o1, o2 with 28 | | None, None -> true 29 | | Some e1, Some e2 -> eq_elt e1 e2 30 | | _ -> false 31 | 32 | let pp : 'a pp -> 'a option pp = fun elt ppf o -> 33 | match o with None -> () | Some e -> elt ppf e 34 | 35 | module Monad = struct 36 | let ( let* ) = Stdlib.Option.bind 37 | 38 | (** Monadic [let*] allows to replace 39 | {[ 40 | match e1 with 41 | | Some e2 -> Some (f e2) 42 | | None -> None 43 | ]} 44 | with 45 | {[ 46 | let* x = e1 in 47 | f x 48 | ]} *) 49 | 50 | let return x = Some x 51 | end 52 | 53 | module Applicative = struct 54 | let pure x = Some x 55 | let ( <*> ) : ('a -> 'b) option -> 'a option -> 'b option = fun o x -> 56 | match o with 57 | | Some f -> map f x 58 | | None -> None 59 | end 60 | -------------------------------------------------------------------------------- /src/lplib/range.mli: -------------------------------------------------------------------------------- 1 | (************************************************************************) 2 | (* The λΠ-modulo Interactive Proof Assistant *) 3 | (************************************************************************) 4 | 5 | (************************************************************************) 6 | (* λΠ-modulo serialization Toplevel *) 7 | (* Copyright Inria -- Dual License LGPL 2.1 / GPL3+ *) 8 | (* Written by: F. Blanqui, E. J. Gallego Arias, F. Lefoulon *) 9 | (************************************************************************) 10 | (* Status: Experimental *) 11 | (************************************************************************) 12 | 13 | include Range_intf.S 14 | -------------------------------------------------------------------------------- /src/lplib/rangeMap.ml: -------------------------------------------------------------------------------- 1 | (************************************************************************) 2 | (* The λΠ-modulo Interactive Proof Assistant *) 3 | (************************************************************************) 4 | 5 | (************************************************************************) 6 | (* λΠ-modulo serialization Toplevel *) 7 | (* Copyright Inria -- Dual License LGPL 2.1 / GPL3+ *) 8 | (* Written by: F. Blanqui, E. J. Gallego Arias, F. Lefoulon *) 9 | (************************************************************************) 10 | (* Status: Experimental *) 11 | (************************************************************************) 12 | 13 | (* The functor for cursor maps. *) 14 | module Make (Range : Range_intf.S) = struct 15 | (* A map of which keys are intervals. *) 16 | module Range = Range 17 | module RangeMap = Map.Make (Range) 18 | 19 | (* Now we need to transform the map so that : - the keys for "add" are 20 | intervals - the keys for "find" are points. *) 21 | type 'a t = (Range.t * 'a) RangeMap.t 22 | 23 | let point_to_interval pt = Range.make_interval pt pt 24 | 25 | let find cursor map = 26 | let interv = point_to_interval cursor in 27 | RangeMap.find_opt interv map 28 | 29 | let empty = RangeMap.empty 30 | let add interv elt map = RangeMap.add interv (interv, elt) map 31 | 32 | let to_string elt_to_string (map : 'a t) = 33 | let f key elt str = 34 | let _, e = elt in 35 | Range.interval_to_string key 36 | ^ "Token : " ^ elt_to_string e ^ "\n\n" ^ str 37 | in 38 | RangeMap.fold f map "" 39 | end 40 | 41 | (* The implementation of CursorMap using a functor. *) 42 | include Make (Range) 43 | -------------------------------------------------------------------------------- /src/lplib/rangeMap.mli: -------------------------------------------------------------------------------- 1 | (************************************************************************) 2 | (* The λΠ-modulo Interactive Proof Assistant *) 3 | (************************************************************************) 4 | 5 | (************************************************************************) 6 | (* λΠ-modulo serialization Toplevel *) 7 | (* Copyright Inria -- Dual License LGPL 2.1 / GPL3+ *) 8 | (* Written by: F. Blanqui, E. J. Gallego Arias, F. Lefoulon *) 9 | (************************************************************************) 10 | (* Status: Experimental *) 11 | (************************************************************************) 12 | 13 | module Make : Range_intf.S -> RangeMap_intf.S 14 | include RangeMap_intf.S with module Range = Range 15 | -------------------------------------------------------------------------------- /src/lplib/realpath.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | CAMLprim value c_realpath(value v) { 8 | // Conversion of the argument to a C value, and performing the C call. 9 | const char *input_path = String_val(v); 10 | char *output_path = realpath(input_path, NULL); 11 | 12 | // Checking for error. 13 | if (output_path == NULL) 14 | caml_invalid_argument("Filename.realpath\0"); 15 | 16 | // Preparing the result value. 17 | value res = caml_copy_string(output_path); 18 | 19 | // Free the memory allocated by [realpath] before returning. 20 | free(output_path); 21 | return res; 22 | } 23 | -------------------------------------------------------------------------------- /src/lplib/string.ml: -------------------------------------------------------------------------------- 1 | module S = Stdlib.String 2 | include S 3 | 4 | let to_list : string -> char list = 5 | fun s -> 6 | let l = ref [] in 7 | S.iter (fun c -> l := c :: !l) s; 8 | List.rev !l 9 | 10 | let of_list : char list -> string = 11 | fun l -> 12 | let b = Buffer.create 37 in 13 | List.iter (Buffer.add_char b) l; 14 | Buffer.contents b 15 | 16 | let is_substring : string -> string -> bool = 17 | fun e s -> 18 | let len_e = S.length e in 19 | let len_s = S.length s in 20 | let rec is_sub i = 21 | if len_s - i < len_e then false 22 | else if S.sub s i len_e = e then true 23 | else is_sub (i + 1) 24 | in 25 | is_sub 0 26 | 27 | let is_prefix : string -> string -> bool = 28 | fun p s -> 29 | let len_p = S.length p in 30 | let len_s = S.length s in 31 | len_p <= len_s && S.sub s 0 len_p = p 32 | 33 | let for_all : (char -> bool) -> string -> bool = 34 | fun p s -> 35 | let len_s = S.length s in 36 | let rec for_all i = i >= len_s || (p (S.get s i) && for_all (i + 1)) in 37 | for_all 0 38 | 39 | (* Taken from string.ml in OCaml 4.14.1. *) 40 | module B = Bytes 41 | let bos = B.unsafe_of_string 42 | let get_utf_8_uchar s i = B.get_utf_8_uchar (bos s) i 43 | let is_valid_utf_8 s = B.is_valid_utf_8 (bos s) 44 | 45 | (* [string_of_file f] puts the contents of file [f] in a string. *) 46 | let string_of_file f = 47 | let ic = open_in f in 48 | let n = in_channel_length ic in 49 | let s = Bytes.create n in 50 | really_input ic s 0 n; 51 | close_in ic; 52 | Bytes.to_string s 53 | 54 | let is_string_literal (s:string): bool = 55 | let n = S.length s in n >= 2 && S.get s 0 = '"' && S.get s (n-1) = '"' 56 | 57 | let remove_quotes (n:string): string = S.sub n 1 (S.length n - 2) 58 | -------------------------------------------------------------------------------- /src/lsp/README.md: -------------------------------------------------------------------------------- 1 | ## Protocol For Logical Formalizations 2 | 3 | This directory contains a prototype language server for the λΠ logical 4 | framework. At this stage, this is a very experimental prototype, use 5 | with care. 6 | 7 | ## Development TODO 8 | 9 | ### Phase 1: Basic document checking. 10 | 11 | + Re-implement document traversal. 12 | + Incremental checking. 13 | 14 | ### Phase 2: Basic interactive proofs 15 | 16 | The goal of this phase is to add support for basic interaction with 17 | λΠ, this will done by means of a query language that will support 18 | goals, search, typeof, etc... 19 | 20 | ### Phase 3: Advanced UI support 21 | 22 | In this phase we will provide some more advanced features for large 23 | scale proof editing. In particular: 24 | 25 | + holes / incomplete proofs 26 | + diff management 27 | 28 | ## Structure of the server. 29 | 30 | The server is split in 3 components: 31 | 32 | - `Lsp_*`: Files dealing with LSP structures. 33 | - `Lp_doc`: Document model for LP documents. 34 | - `Lp_lsp`: Main server, command handlers. 35 | -------------------------------------------------------------------------------- /src/lsp/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name lsp) 3 | (public_name lambdapi.lsp) 4 | (modules lsp_base lsp_io lp_doc lp_lsp) 5 | (libraries yojson lambdapi.pure)) 6 | -------------------------------------------------------------------------------- /src/lsp/lp_lsp.mli: -------------------------------------------------------------------------------- 1 | (************************************************************************) 2 | (* The λΠ-modulo Interactive Proof Assistant *) 3 | (************************************************************************) 4 | 5 | (************************************************************************) 6 | (* λΠ-modulo serialization Toplevel *) 7 | (* Copyright 2018 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *) 8 | (* Written by: Emilio J. Gallego Arias *) 9 | (************************************************************************) 10 | (* Status: Very Experimental *) 11 | (************************************************************************) 12 | 13 | val default_log_file : string 14 | 15 | val main : bool -> string -> unit 16 | -------------------------------------------------------------------------------- /src/lsp/lsp_base.mli: -------------------------------------------------------------------------------- 1 | (************************************************************************) 2 | (* The λΠ-modulo Interactive Proof Assistant *) 3 | (************************************************************************) 4 | 5 | (************************************************************************) 6 | (* λΠ-modulo serialization Toplevel *) 7 | (* Copyright 2018 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *) 8 | (* Written by: Emilio J. Gallego Arias *) 9 | (************************************************************************) 10 | (* Status: Very Experimental *) 11 | (************************************************************************) 12 | 13 | open Common 14 | 15 | module J = Yojson.Basic 16 | 17 | val std_protocol : bool ref 18 | 19 | val mk_range : Pos.pos -> J.t 20 | 21 | val mk_reply : id:int -> result:J.t -> J.t 22 | 23 | val mk_diagnostics 24 | : uri:string 25 | -> version: int 26 | -> (Pos.pos * int * string * Pure.goal list option) list 27 | -> J.t 28 | 29 | val json_of_goals : ?logs:string -> Pure.goal list option -> J.t 30 | -------------------------------------------------------------------------------- /src/parsing/dkBasic.ml: -------------------------------------------------------------------------------- 1 | (** Part of the Dedukti source file kernel/basic.ml. *) 2 | 3 | type ident = string 4 | 5 | let ident_eq s1 s2 = s1 == s2 || s1 = s2 6 | 7 | type mident = string 8 | 9 | module WS = Weak.Make (struct 10 | type t = ident 11 | let equal = ident_eq 12 | let hash = Hashtbl.hash 13 | end) 14 | 15 | let hash_ident = WS.create 251 16 | 17 | let mk_ident = WS.merge hash_ident 18 | 19 | let underscore = mk_ident "_" 20 | 21 | let hash_mident = WS.create 251 22 | 23 | let mk_mident md = WS.merge hash_mident md 24 | -------------------------------------------------------------------------------- /src/parsing/dkTokens.ml: -------------------------------------------------------------------------------- 1 | (** Dedukti source file parsing/tokens.ml. *) 2 | 3 | open DkBasic 4 | 5 | type loc = Lexing.position * Lexing.position 6 | 7 | type token = 8 | | UNDERSCORE of loc 9 | | TYPE of loc 10 | | KW_DEF of loc 11 | | KW_DEFAC of loc 12 | | KW_DEFACU of loc 13 | | KW_THM of loc 14 | | KW_INJ of loc 15 | | KW_PRV of loc 16 | | RIGHTSQU 17 | | RIGHTPAR 18 | | RIGHTBRA 19 | | QID of (loc * mident * ident) 20 | | NAME of (loc * mident) 21 | | REQUIRE of (loc * mident) 22 | | LONGARROW 23 | | LEFTSQU 24 | | LEFTPAR 25 | | LEFTBRA 26 | | ID of (loc * ident) 27 | | FATARROW 28 | | EOF 29 | | DOT 30 | | DEF 31 | | COMMA 32 | | COLON 33 | | EQUAL 34 | | ARROW 35 | | EVAL of loc 36 | | INFER of loc 37 | | CHECK of loc 38 | | ASSERT of loc 39 | | CHECKNOT of loc 40 | | ASSERTNOT of loc 41 | | PRINT of loc 42 | | GDT of loc 43 | | STRING of string 44 | -------------------------------------------------------------------------------- /src/parsing/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name parsing) 3 | (public_name lambdapi.parsing) 4 | (modules :standard) 5 | (preprocess (pps sedlex.ppx)) 6 | (libraries camlp-streams lambdapi.core menhirLib pratter sedlex sedlex.ppx lambdapi.common) 7 | (flags -w +3)) 8 | 9 | (menhir (flags --explain --external-tokens LpLexer) (modules lpParser)) 10 | 11 | (ocamllex dkLexer) 12 | 13 | (menhir (flags --explain --external-tokens DkTokens) (modules dkParser)) 14 | -------------------------------------------------------------------------------- /src/parsing/searchQuerySyntax.ml: -------------------------------------------------------------------------------- 1 | (* query language *) 2 | type side = Lhs | Rhs 3 | type inside = Exact | Inside 4 | type 'inside where = 5 | | Spine of 'inside 6 | | Conclusion of 'inside 7 | | Hypothesis of 'inside 8 | type constr = 9 | | QType of (inside option) where option 10 | | QXhs of inside option * side option 11 | type base_query = 12 | | QName of string 13 | | QSearch of Syntax.p_term * (*generalize:*)bool * constr option 14 | type op = 15 | | Intersect 16 | | Union 17 | type filter = 18 | | Path of string 19 | type query = 20 | | QBase of base_query 21 | | QOpp of query * op * query 22 | | QFilter of query * filter 23 | -------------------------------------------------------------------------------- /src/pure/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name pure) 3 | (public_name lambdapi.pure) 4 | (modules :standard) 5 | (libraries camlp-streams lambdapi.handle lambdapi.core) 6 | (flags -w +3)) 7 | -------------------------------------------------------------------------------- /src/tool/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name tool) 3 | (public_name lambdapi.tool) 4 | (modules :standard) 5 | (libraries lambdapi.parsing lambdapi.core dream unix) 6 | (preprocess (pps lwt_ppx))) 7 | 8 | (rule 9 | (targets websearch.ml) 10 | (deps websearch.eml.ml) 11 | (action (run dream_eml %{deps} --workspace %{workspace_root}))) 12 | -------------------------------------------------------------------------------- /src/tool/indexing.mli: -------------------------------------------------------------------------------- 1 | open Core 2 | 3 | (* indexing *) 4 | val empty : unit -> unit 5 | val load_rewriting_rules: string list -> unit 6 | val index_sign : Sign.t -> unit 7 | val dump : dbpath:string -> unit -> unit 8 | 9 | (* search command used by cli *) 10 | val search_cmd_txt: Sig_state.sig_state -> string -> dbpath:string -> string 11 | 12 | (* search command used by websearch *) 13 | val search_cmd_html: 14 | Sig_state.sig_state 15 | -> from:int -> how_many:int -> string -> dbpath:string -> string 16 | -------------------------------------------------------------------------------- /src/tool/sr.mli: -------------------------------------------------------------------------------- 1 | (** Checking that a rule preserves typing (subject reduction property). *) 2 | 3 | open Core open Term 4 | open Common 5 | 6 | (** [check_rule r] checks whether the pre-rule [r] is well-typed in 7 | signature state [ss] and then construct the corresponding rule. Note that 8 | [Fatal] is raised in case of error. *) 9 | val check_rule : Pos.popt -> sym_rule -> sym_rule 10 | -------------------------------------------------------------------------------- /src/tool/websearch.mli: -------------------------------------------------------------------------------- 1 | val start : header:string -> Core.Sig_state.sig_state 2 | -> port:int -> dbpath:string -> path_in_url: string -> unit -> unit 3 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | .tmp 2 | -------------------------------------------------------------------------------- /tests/KO/1041.lp: -------------------------------------------------------------------------------- 1 | constant symbol Prop : TYPE; 2 | builtin "Prop" ≔ Prop; 3 | injective symbol π : Prop → TYPE; // `p 4 | builtin "P" ≔ π; 5 | 6 | constant symbol Set : TYPE; 7 | injective symbol τ : Set → TYPE; 8 | builtin "T" ≔ τ; 9 | 10 | constant symbol ⊥ : Prop; // \bot 11 | 12 | constant symbol ⇒ : Prop → Prop → Prop; notation ⇒ infix right 5; // => 13 | rule π ($p ⇒ $q) ↪ π $p → π $q; 14 | 15 | symbol ¬ p ≔ p ⇒ ⊥; // ~~ or \neg 16 | notation ¬ prefix 35; 17 | 18 | constant symbol ∀ [a] : (τ a → Prop) → Prop; notation ∀ quantifier; // !! or \forall 19 | rule π (∀ $f) ↪ Π x, π ($f x); 20 | 21 | injective symbol πᶜ p ≔ π (¬ ¬ p); 22 | 23 | flag "print_implicits" on; 24 | flag "print_domains" on; 25 | //flag "print_meta_types" on; 26 | 27 | symbol ∀ᶜ [a] p ≔ `∀ x : τ a, ¬ ¬ (p x); notation ∀ᶜ quantifier; 28 | 29 | //debug +hiuta; 30 | opaque symbol ∀ᶜᵢ p : (Π x, πᶜ (p x)) → πᶜ (∀ᶜ p) ≔ 31 | begin 32 | print; 33 | //debug -hiuta; 34 | assume p Hnnpx Hnnnpx; 35 | apply Hnnnpx; 36 | assume x Hnnp; 37 | apply Hnnpx x; 38 | assume Hnp; 39 | apply Hnnp; 40 | apply Hnp; 41 | end; 42 | 43 | print ∀ᶜᵢ; 44 | -------------------------------------------------------------------------------- /tests/KO/1103.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol 2:A; 3 | symbol -2:A; 4 | -------------------------------------------------------------------------------- /tests/KO/1103b.lp: -------------------------------------------------------------------------------- 1 | require tests.OK.1103; 2 | symbol a ≔ tests.OK.1103.2; 3 | symbol b ≔ tests.OK.1103.-2; 4 | -------------------------------------------------------------------------------- /tests/KO/1217.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.Set tests.OK.Prop tests.OK.FOL tests.OK.Eq tests.OK.HOL tests.OK.Impred tests.OK.PropExt; 2 | 3 | symbol forallSimp (t : Set) (p : τ o) : π ((`∀ (x : τ t), p) = p) ≔ 4 | begin 5 | assume t p; 6 | refine propExt (`∀ x, p) p _ _ 7 | {assume h; refine h (el t)} 8 | {assume h a; refine h} 9 | end; 10 | 11 | symbol a : τ o; 12 | symbol b : τ ι → τ o; 13 | 14 | symbol example : π ((`∀ x : τ ι, b x) ⇒ a) ≔ 15 | begin 16 | debug +r; 17 | rewrite forallSimp; 18 | assume h; refine h 19 | end; 20 | -------------------------------------------------------------------------------- /tests/KO/246.lp: -------------------------------------------------------------------------------- 1 | constant symbol Type : TYPE; 2 | injective symbol eta : Type → TYPE; 3 | 4 | // function type 5 | constant symbol > : Type → Type → Type; 6 | notation > infix right 6; 7 | rule eta ($a > $b) ↪ eta $a → eta $b; 8 | 9 | symbol fst : Π (A B : Type), eta (A > B > A) ≔ 10 | λ A B a b, a; 11 | 12 | symbol snd : Π (A B : Type), eta (A > B > B) ≔ 13 | λ A B a b, a; 14 | -------------------------------------------------------------------------------- /tests/KO/246b.lp: -------------------------------------------------------------------------------- 1 | constant symbol Type : TYPE; 2 | injective symbol eta : Type → TYPE; 3 | 4 | symbol o : Type; 5 | 6 | constant symbol neg : eta o → eta o; 7 | type neg o; 8 | -------------------------------------------------------------------------------- /tests/KO/262_localuse.lp: -------------------------------------------------------------------------------- 1 | require tests.OK.{|262_parsing|} as D; 2 | 3 | rule D.f $x ↪ $x; 4 | -------------------------------------------------------------------------------- /tests/KO/262_prv_in_rhs.lp: -------------------------------------------------------------------------------- 1 | require tests.OK.{|262_parsing|} as D; 2 | 3 | symbol g : D.A → D.A; 4 | 5 | // Foreign protected symbols are forbidden in right-hand-sides 6 | rule g $X ↪ D.g $X; 7 | -------------------------------------------------------------------------------- /tests/KO/262_prv_lhs_head.lp: -------------------------------------------------------------------------------- 1 | require tests.OK.{|262_parsing|} as D; 2 | 3 | // Defining a rule with a foreign private symbol as head is forbidden 4 | rule D.f $X ↪ $X; 5 | -------------------------------------------------------------------------------- /tests/KO/262_prvdef_in_rhs.lp: -------------------------------------------------------------------------------- 1 | require tests.OK.{|262_parsing|} as D; 2 | 3 | symbol g : D.A → D.A; 4 | 5 | // Foreign private symbols are forbidden in right-hand-sides 6 | rule g $X ↪ D.gdouble $X; 7 | -------------------------------------------------------------------------------- /tests/KO/262_pub_prv_defn.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | 3 | private symbol f : A → A; 4 | symbol g : A → A; 5 | 6 | // The private [f] would become public with fog 7 | symbol fog x ≔ f (g x); 8 | -------------------------------------------------------------------------------- /tests/KO/262_pub_prv_type.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | private constant symbol B : TYPE; 3 | 4 | // Private type B would escape its privacy and be exposed 5 | symbol f : A → B; 6 | -------------------------------------------------------------------------------- /tests/KO/262_pub_prvlhs_rule.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | 3 | symbol f : A → A; 4 | private symbol a : A; 5 | symbol z : A; 6 | 7 | rule f a ↪ z; 8 | -------------------------------------------------------------------------------- /tests/KO/262_pub_prvrhs_rule.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | 3 | symbol f : A → A; 4 | private symbol z : A; 5 | 6 | // z would escape its scope 7 | rule f _ ↪ z; 8 | -------------------------------------------------------------------------------- /tests/KO/272.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | constant symbol a : A; 3 | constant symbol B : A → TYPE; 4 | constant symbol C : A → TYPE; 5 | 6 | symbol f : A → A; 7 | symbol g : A → A; 8 | 9 | constant symbol consB : Πa, B (g a); 10 | constant symbol consC : Πa, C (f a); 11 | 12 | symbol calc : 13 | Π a : A, 14 | Π b : B a, 15 | Π c : C a, 16 | A; 17 | 18 | rule calc _ (consB _) (consC _) ↪ A; 19 | 20 | rule f $x ↪ $x; 21 | rule g $x ↪ $x; 22 | 23 | rule calc _ (consB _) (consC _) ↪ A; 24 | -------------------------------------------------------------------------------- /tests/KO/378.lp: -------------------------------------------------------------------------------- 1 | // a module alias cannot be opened 2 | require tests.OK.bool as B; 3 | open B; 4 | -------------------------------------------------------------------------------- /tests/KO/536.lp: -------------------------------------------------------------------------------- 1 | require /*tests.KO.*/bool; 2 | -------------------------------------------------------------------------------- /tests/KO/59.lp: -------------------------------------------------------------------------------- 1 | symbol A : TYPE; 2 | symbol a : A; 3 | symbol f : (A → A) → A; 4 | 5 | rule f (λ x, $y[x,x]) ↪ a; 6 | 7 | -------------------------------------------------------------------------------- /tests/KO/655.lp: -------------------------------------------------------------------------------- 1 | constant symbol Typ: TYPE; 2 | constant symbol int: Typ; 3 | 4 | constant symbol id : Typ → Typ → Typ; 5 | notation id infix 2; 6 | 7 | symbol should_fail ≔ int @id int; 8 | -------------------------------------------------------------------------------- /tests/KO/655b.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol a:A; 3 | symbol b:A; 4 | symbol c:A; 5 | 6 | symbol +:A → A → A; notation + infix right 10; 7 | 8 | type a + b @+ c; 9 | -------------------------------------------------------------------------------- /tests/KO/656.lp: -------------------------------------------------------------------------------- 1 | constant symbol Typ: TYPE; 2 | constant symbol int: Typ; 3 | symbol Fail ≔ int int; 4 | -------------------------------------------------------------------------------- /tests/KO/71.dk: -------------------------------------------------------------------------------- 1 | Nat : Type. 2 | 3 | 0 : Nat. 4 | 5 | def D : Nat -> Nat -> Nat. 6 | 7 | [] D 0 --> 0. 8 | -------------------------------------------------------------------------------- /tests/KO/713.lp: -------------------------------------------------------------------------------- 1 | symbol Type : TYPE; 2 | injective symbol ε : Type → TYPE; 3 | 4 | symbol = {T} (_ _ : ε T) : Type; 5 | notation = infix 22; 6 | symbol =_refl {T} (x : ε T) : ε (x = x); 7 | symbol =_ind {T} (x y : ε T) : ε (x = y) → Π P, ε (P y) → ε (P x); 8 | 9 | builtin "Prop" ≔ Type; 10 | builtin "P" ≔ ε; 11 | builtin "T" ≔ ε; 12 | builtin "eq" ≔ =; 13 | builtin "refl" ≔ =_refl; 14 | builtin "eqind" ≔ =_ind; 15 | 16 | inductive ℕ : TYPE ≔ 17 | | O : ℕ 18 | | S : ℕ → ℕ; 19 | 20 | symbol nat : Type; 21 | rule ε nat ↪ ℕ; 22 | 23 | symbol succ x ≔ S x; 24 | 25 | //flag "print_implicits" on; 26 | //flag "print_domains" on; 27 | 28 | symbol applyInd Q qO qS x : 29 | ε (ind_ℕ Q qO qS (succ x) = 30 | ind_ℕ Q qO qS (S x)) 31 | ≔ begin 32 | assume Q qO qS x; 33 | 34 | have equality : ε (succ x = S x); 35 | reflexivity; 36 | 37 | //debug +turh; 38 | rewrite equality; 39 | end; 40 | -------------------------------------------------------------------------------- /tests/KO/845.lp: -------------------------------------------------------------------------------- 1 | // test that a notation is compatible with the type 2 | symbol O : TYPE; 3 | symbol T : O; 4 | symbol p : O → TYPE; 5 | symbol ¬ : p T → p T → p T; 6 | symbol ⊥ : p T; 7 | symbol ⊤ : p T; 8 | notation ⊤ infix left 5; 9 | //rule _ ⊤ _ ↪ ¬ ⊥; 10 | -------------------------------------------------------------------------------- /tests/KO/912.lp: -------------------------------------------------------------------------------- 1 | symbol SortK : TYPE; 2 | 3 | symbol δ : SortK → TYPE; 4 | 5 | symbol SortInt : SortK; 6 | symbol zero : δ SortInt; 7 | symbol succ : δ SortInt → δ SortInt; 8 | 9 | builtin "0" ≔ zero; 10 | builtin "+1" ≔ succ; 11 | 12 | symbol A : δ SortInt; 13 | rule A ↪ 9223372036854775808; 14 | -------------------------------------------------------------------------------- /tests/KO/913.lp: -------------------------------------------------------------------------------- 1 | symbol E : TYPE; 2 | symbol e : E; 3 | rule $_ ↪ e ; 4 | -------------------------------------------------------------------------------- /tests/KO/922.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.922 tests.OK.for_bool; 2 | 3 | symbol is0 : ℕ → 𝔹; 4 | 5 | rule is0 (+1 _) ↪ false; 6 | -------------------------------------------------------------------------------- /tests/KO/anonymous.lp: -------------------------------------------------------------------------------- 1 | constant symbol T : TYPE; 2 | constant symbol U : TYPE; 3 | 4 | symbol fst : T → U → T ≔ λ x _, x; 5 | symbol snd : T → U → U ≔ λ _ x, x; 6 | 7 | opaque symbol trivial : T → T → T → T 8 | ≔ begin 9 | assume _ _ x; 10 | refine x 11 | end; 12 | -------------------------------------------------------------------------------- /tests/KO/bug2.dk: -------------------------------------------------------------------------------- 1 | N : Type. 2 | 3 | 0 : N. 4 | 5 | B : Type. 6 | 7 | T : B. 8 | 9 | def A : B -> Type. 10 | 11 | def f : A T -> Type. 12 | 13 | [] f B --> B. 14 | -------------------------------------------------------------------------------- /tests/KO/bug3.dk: -------------------------------------------------------------------------------- 1 | def A : Type. 2 | def eA : A -> Type. 3 | a : A. 4 | [] A --> eA a. 5 | 6 | B : Type. 7 | def eB : B -> Type. 8 | 9 | [] eB a --> eA a. 10 | 11 | #ASSERT a : eB a. 12 | -------------------------------------------------------------------------------- /tests/KO/church.dk: -------------------------------------------------------------------------------- 1 | type : Type. 2 | arr : type -> type -> type. 3 | def e : type -> Type. 4 | [a : type, b : type] e (arr a b) --> e a -> e b. 5 | 6 | def numeral : Type := A : type -> (e A -> e A) -> (e A -> e A). 7 | 8 | def zero : numeral := A : type => f : (e A -> e A) => x : e A => x. 9 | def one : numeral := A : type => f : (e A -> e A) => x : e A => f x. 10 | def two : numeral := A : type => f : (e A -> e A) => x : e A => f (f x). 11 | def three : numeral := A : type => f : (e A -> e A) => x : e A => f (f (f x)). 12 | def four : numeral := A : type => f : (e A -> e A) => x : e A => f (f (f (f x))). 13 | 14 | def plus : numeral -> numeral -> numeral := 15 | m : numeral => n : numeral => A : type => f : (e A -> e A) => x : e A => m A f (n A f x). 16 | 17 | def times : numeral -> numeral -> numeral := 18 | m : numeral => n : numeral => A : type => f : (e A -> e A) => x : e A => m A (n A f) x. 19 | 20 | def power : numeral -> numeral -> numeral := 21 | m : numeral => n : numeral => A : type => n (arr A A) (m A). 22 | 23 | def test0 : numeral := power two (plus one (times three four)). 24 | def test0_ : numeral := power two (plus (times four four) one). 25 | 26 | def test : numeral := power two (plus one (times two three)). 27 | def test_ : numeral := power two (plus (times three three) one). 28 | 29 | P : numeral -> Type. 30 | P2: n:numeral -> P n -> Type. 31 | 32 | y : P test_. 33 | 34 | (; should fail since test and test_ are not equivalent ;) 35 | z: P2 test y. 36 | 37 | #EVAL zero. 38 | #EVAL one. 39 | #EVAL two. 40 | #EVAL three. 41 | #EVAL four. 42 | 43 | #EVAL plus one (times three four). 44 | -------------------------------------------------------------------------------- /tests/KO/circular_a.dk: -------------------------------------------------------------------------------- 1 | #REQUIRE tests.KO.circular_b. 2 | 3 | TA : Type. 4 | 5 | b : tests.KO.circular_b.TB. 6 | -------------------------------------------------------------------------------- /tests/KO/circular_b.dk: -------------------------------------------------------------------------------- 1 | #REQUIRE tests.KO.circular_c. 2 | 3 | TB : Type. 4 | 5 | c : tests.KO.circular_c.TC. 6 | -------------------------------------------------------------------------------- /tests/KO/circular_c.dk: -------------------------------------------------------------------------------- 1 | #REQUIRE tests.KO.circular_a. 2 | 3 | TC : Type. 4 | 5 | a : tests.KO.circular_a.TA. 6 | -------------------------------------------------------------------------------- /tests/KO/context_var_not_occuring.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | 3 | def f : A -> A. 4 | 5 | [x] f _ --> x. 6 | -------------------------------------------------------------------------------- /tests/KO/def.dk: -------------------------------------------------------------------------------- 1 | A:Type. 2 | P:A->Type. 3 | def magic (a1:A) (a2:A) (H:P a1) : P a2 := H. 4 | 5 | -------------------------------------------------------------------------------- /tests/KO/double_decl.dk: -------------------------------------------------------------------------------- 1 | a:Type. 2 | f:a. 3 | f:a. 4 | -------------------------------------------------------------------------------- /tests/KO/francois.dk: -------------------------------------------------------------------------------- 1 | type : Type. 2 | def term : type -> Type. 3 | 4 | pi : A : type -> (term A -> type) -> type. 5 | [A,B] term (pi A B) --> a : term A -> term (B a). 6 | 7 | def i (A : type) (B : term A -> type) : term (pi A B) := z : term A => z. 8 | -------------------------------------------------------------------------------- /tests/KO/incompatible.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | left associative commutative symbol +:A → A → A; 3 | notation + infix right 10; 4 | -------------------------------------------------------------------------------- /tests/KO/inductive_type_KO.lp: -------------------------------------------------------------------------------- 1 | constant symbol Prop : TYPE; // Type of propositions 2 | injective symbol π : Prop → TYPE; // Interpretation of propositions in TYPE 3 | 4 | builtin "Prop" ≔ Prop; 5 | builtin "P" ≔ π; 6 | 7 | symbol Nat : TYPE; 8 | 9 | debug +g; 10 | 11 | symbol ind_plane : TYPE; 12 | inductive plane : TYPE ≔ 13 | | x0 : Nat → Nat → plane; 14 | 15 | assert ⊢ ind_plane : Π (p : plane → Prop), 16 | (Π z x1 : Nat, π (p (x0 z x1))) → Πx: plane, π (p x); 17 | 18 | symbol pplane : plane → Prop; 19 | symbol pix0 : Π z x1 : Nat, π (pplane (x0 z x1)); 20 | symbol n1 : Nat; 21 | symbol n2 : Nat; 22 | assert ⊢ ind_plane pplane pix0 (x0 n1 n2) ≡ pix0 n1 n2; 23 | -------------------------------------------------------------------------------- /tests/KO/infix.lp: -------------------------------------------------------------------------------- 1 | symbol N : TYPE; 2 | symbol z : N; 3 | 4 | symbol + : N → N → N; 5 | notation + infix 5; 6 | assert ⊢ z + z + z : N; 7 | -------------------------------------------------------------------------------- /tests/KO/invalid_pat.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | 3 | [] x => x --> x:A => x. 4 | -------------------------------------------------------------------------------- /tests/KO/lexing_id.dk: -------------------------------------------------------------------------------- 1 | karaté:Type. 2 | -------------------------------------------------------------------------------- /tests/KO/missing_brackets.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol a:A; 3 | symbol f:(A → A) → A; 4 | rule f (λ x, $M) ↪ a; 5 | // Error: Missing square brackets under binder. 6 | -------------------------------------------------------------------------------- /tests/KO/nomodule.dk: -------------------------------------------------------------------------------- 1 | S : Unknown.module. 2 | -------------------------------------------------------------------------------- /tests/KO/notinj.dk: -------------------------------------------------------------------------------- 1 | type : Type. 2 | 3 | def eta : type -> Type. 4 | (;inj eta : type -> Type.;) 5 | 6 | arr : type -> type -> type. 7 | 8 | [A,B] eta (arr A B) --> eta A -> eta B. 9 | 10 | lam : A : type -> B : type -> (eta A -> eta B) -> eta (arr A B). 11 | 12 | def app : A : type -> B : type -> eta (arr A B) -> eta A -> eta B. 13 | 14 | def get_context : A : type -> B : type -> eta A -> eta A -> eta B -> eta A. 15 | 16 | [A,AB,C,f,a,f',z] get_context _ C (app A AB f a) (app _ _ f' a) z --> 17 | (app A AB (get_context (arr A AB) C f f' z) a). 18 | -------------------------------------------------------------------------------- /tests/KO/notvarinenv.lp: -------------------------------------------------------------------------------- 1 | // From issue #70 2 | 3 | constant symbol Nat : TYPE; 4 | 5 | constant symbol z : Nat; 6 | constant symbol s : Nat → Nat; 7 | 8 | symbol f : (Nat → Nat) → Nat; 9 | 10 | rule f (λ x, $m[x,z]) ↪ z; 11 | -------------------------------------------------------------------------------- /tests/KO/parsing_eof.dk: -------------------------------------------------------------------------------- 1 | id:Type 2 | -------------------------------------------------------------------------------- /tests/KO/pat_rhs.lp: -------------------------------------------------------------------------------- 1 | symbol T: TYPE; 2 | symbol f: T → T; 3 | symbol x: T; 4 | rule f x ↪ $x; 5 | -------------------------------------------------------------------------------- /tests/KO/remove.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol B:A → TYPE; 3 | symbol C a:B a → TYPE; 4 | 5 | opaque symbol lemma a (b:B a) (c:C a b) : A ≔ 6 | begin 7 | assume a b c; 8 | remove a; 9 | abort; 10 | -------------------------------------------------------------------------------- /tests/KO/req_without_root_path.lp: -------------------------------------------------------------------------------- 1 | require bool; 2 | -------------------------------------------------------------------------------- /tests/KO/require_escape1.lp: -------------------------------------------------------------------------------- 1 | // tests that LP detects multiple requires when using escaped identifier 2 | require tests.OK.{|a b|}.{|escape file|}; 3 | require {|tests|}.OK.{|a b|}.{|escape file|}; 4 | -------------------------------------------------------------------------------- /tests/KO/require_escape2.lp: -------------------------------------------------------------------------------- 1 | // tests that LP detects multiple requires when using escaped identifier 2 | require tests.OK.apply; 3 | require tests.OK.{|apply|}; 4 | -------------------------------------------------------------------------------- /tests/KO/rule_var.dk: -------------------------------------------------------------------------------- 1 | A:Type. 2 | a:A. 3 | [x:A] x --> a. 4 | -------------------------------------------------------------------------------- /tests/KO/scoping_ext.dk: -------------------------------------------------------------------------------- 1 | id:toto.tata. 2 | -------------------------------------------------------------------------------- /tests/KO/self_require_escape.lp: -------------------------------------------------------------------------------- 1 | // test that require detects a circular dependency 2 | // when using escaped identifiers 3 | require tests.KO.{|self_require_escape|}; 4 | -------------------------------------------------------------------------------- /tests/KO/typing_abstraction.dk: -------------------------------------------------------------------------------- 1 | A:Type. 2 | y:A. 3 | P:A->Type. 4 | p:P y. 5 | id: x:A -> P x -> P x. 6 | def T: P y. 7 | (; [ ] T --> (z => id z p) y. ;) 8 | [ ] T --> (z:A => id z p) y. 9 | -------------------------------------------------------------------------------- /tests/KO/typing_omega.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | B : A -> Type. 3 | C : B ( (x => x x)(x => x x) ). 4 | -------------------------------------------------------------------------------- /tests/KO/typing_pi.dk: -------------------------------------------------------------------------------- 1 | T:Type. 2 | x:T. 3 | f:x->Type. 4 | -------------------------------------------------------------------------------- /tests/KO/typing_sort.dk: -------------------------------------------------------------------------------- 1 | nat : Type. 2 | 3 | x : nat. 4 | 5 | y : x. 6 | -------------------------------------------------------------------------------- /tests/KO/unclosed_comment.dk: -------------------------------------------------------------------------------- 1 | (; Hello, world! 2 | -------------------------------------------------------------------------------- /tests/KO/unclosed_comment2.dk: -------------------------------------------------------------------------------- 1 | (; Hello, (; world! 2 | -------------------------------------------------------------------------------- /tests/KO/unclosed_comment3.dk: -------------------------------------------------------------------------------- 1 | (; Hello, (; world! ;) 2 | -------------------------------------------------------------------------------- /tests/KO/unsound.dk: -------------------------------------------------------------------------------- 1 | X:Type. 2 | Nat:Type. 3 | Bool:Type. 4 | false:Bool. 5 | 6 | A:Type. 7 | [] A --> Bool. 8 | [] A --> Nat. 9 | 10 | 11 | g:X->Nat. 12 | f:Nat->X. 13 | 14 | def l1 := x:Nat => g (f x). 15 | def l2 := y:A => l1 y. 16 | def ap := l2 false. 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/KO/vectDependant.dk: -------------------------------------------------------------------------------- 1 | Nat : Type. 2 | 3 | 0 : Nat. 4 | S : Nat -> Nat. 5 | 6 | def 1 : Nat. 7 | def 2 : Nat. 8 | def 3 : Nat. 9 | def 4 : Nat. 10 | 11 | [] 1 --> S 0. 12 | [] 2 --> S 1. 13 | [] 3 --> S 2. 14 | [] 4 --> S 3. 15 | 16 | Vec : Nat -> Type. 17 | 18 | nil : Vec 0. 19 | cns : n : Nat -> Vec n -> Vec (S n). 20 | 21 | def f : Nat -> Nat. 22 | 23 | [] f 0 --> S (S 0). 24 | [] f (S 0) --> S (S 0). 25 | [n] f (S (S n)) --> S (S (f n)). 26 | 27 | cnsf : n:Nat -> Vec n -> Vec (f n). 28 | 29 | def tailf : n:Nat -> Vec (f n) -> Vec n. 30 | 31 | (; Should not be accepted since f is not injective 32 | and this breask subject reduction as shown below. ;) 33 | 34 | [n, v] tailf n (cnsf _ v) --> v. 35 | 36 | def left : Vec 3. 37 | 38 | [] left --> cns 2 (cns 1 (cns 0 nil)). 39 | 40 | def right : Vec 2. 41 | 42 | [] right --> tailf 2 (cnsf 3 left). 43 | 44 | #EVAL left. 45 | #EVAL right. 46 | #ASSERT left == right. 47 | 48 | (; Subject reduction is broken: left of type (Vec 3) reduces to right 49 | of type (Vec 2), and right is NOT of type (Vec 3). ;) 50 | -------------------------------------------------------------------------------- /tests/OK/1001.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | 3 | associative commutative symbol * : A → A → A; 4 | -------------------------------------------------------------------------------- /tests/OK/1006.lp: -------------------------------------------------------------------------------- 1 | constant symbol Set : TYPE; 2 | injective symbol τ : Set → TYPE; builtin "T" ≔ τ; 3 | 4 | symbol mys : TYPE; 5 | symbol myop : mys → mys → mys; 6 | 7 | symbol testfun : Π (Func : Set) (Hom : τ Func → Set) (Comp : Π [F : τ Func] , τ (Hom F)) , 8 | mys; 9 | 10 | rule (myop (@testfun $Func $Hom $Comp ) (@testfun $Func $Hom $Comp ) ) 11 | ↪ (@testfun $Func $Hom $Comp ) ; 12 | -------------------------------------------------------------------------------- /tests/OK/1026.lp: -------------------------------------------------------------------------------- 1 | symbol Prop: TYPE; 2 | symbol π: Prop → TYPE; 3 | symbol Set: TYPE; 4 | constant symbol τ: Set → TYPE; 5 | builtin "T" ≔ τ; 6 | builtin "P" ≔ π; 7 | 8 | symbol = [a:Set] : τ a → τ a → Prop; 9 | 10 | notation = infix 10; 11 | 12 | constant symbol eq_refl [a:Set] (x:τ a) : π (x = x); 13 | constant symbol ind_eq [a:Set] [x y:τ a] : π (x = y) → Π p, π (p y) → π (p x); 14 | 15 | builtin "eq" ≔ =; 16 | builtin "refl" ≔ eq_refl; 17 | builtin "eqind" ≔ ind_eq; 18 | 19 | symbol _set: Set; 20 | symbol cset [T]: (τ T → Prop) → τ _set; 21 | 22 | symbol T: Set; 23 | symbol P: τ T → Prop; 24 | symbol U: τ _set; 25 | symbol Q: τ _set → Prop; 26 | symbol th: π (cset (λ x, P x) = U) → π (Q U) → π (Q (cset (λ x, P x))) ≔ 27 | begin 28 | assume h1 h2; 29 | rewrite h1; 30 | apply h2; 31 | end; 32 | -------------------------------------------------------------------------------- /tests/OK/1033.lp: -------------------------------------------------------------------------------- 1 | // Test on the sequential reduction strategy 2 | constant symbol I: TYPE; 3 | constant symbol i: I; 4 | constant symbol j: I; 5 | sequential symbol k: I → I; 6 | rule k i ↪ i 7 | with k i ↪ j; 8 | 9 | assert ⊢ k i ≡ i; 10 | -------------------------------------------------------------------------------- /tests/OK/1035.lp: -------------------------------------------------------------------------------- 1 | symbol Set:TYPE; 2 | injective symbol τ:Set → TYPE; 3 | symbol ℕ:TYPE; 4 | symbol O:ℕ; 5 | symbol 𝑰 [a]: ℕ → τ a; 6 | 7 | symbol code_S' : Set; 8 | symbol S' ≔ τ code_S'; 9 | //print S'; 10 | //debug +uv; 11 | symbol a':S' ≔ 𝑰 O; 12 | //debug -uv; 13 | 14 | private symbol code_S : Set; 15 | private symbol S ≔ τ code_S; 16 | //print S; 17 | //debug +uv; 18 | private symbol a: S ≔ 𝑰 O; 19 | -------------------------------------------------------------------------------- /tests/OK/1120.lp: -------------------------------------------------------------------------------- 1 | symbol Prop: TYPE; 2 | symbol π: Prop → TYPE; 3 | symbol Set: TYPE; 4 | constant symbol τ: Set → TYPE; 5 | builtin "T" ≔ τ; 6 | builtin "P" ≔ π; 7 | 8 | symbol = [a:Set] : τ a → τ a → Prop; 9 | 10 | notation = infix 10; 11 | 12 | constant symbol eq_refl [a:Set] (x:τ a) : π (x = x); 13 | constant symbol ind_eq [a:Set] [x y:τ a] : π (x = y) → Π p, π (p y) → π (p x); 14 | 15 | builtin "eq" ≔ =; 16 | builtin "refl" ≔ eq_refl; 17 | builtin "eqind" ≔ ind_eq; 18 | 19 | injective symbol σℙ: Set → Set; 20 | symbol σBOOL: Set; 21 | symbol τℙ (T:Set) ≔ τ (σℙ T); 22 | 23 | 24 | constant symbol ∀ [a] : (τ a → Prop) → Prop; 25 | 26 | notation ∀ quantifier; 27 | 28 | rule π (∀ $f) ↪ Π x, π ($f x); 29 | symbol ∈ [T:Set] : τ T → τℙ T → Prop; 30 | notation ∈ infix 10; 31 | 32 | symbol T: Set; 33 | symbol S1: τℙ T; 34 | symbol S2: τℙ T; 35 | symbol h1: π (S1 = S2); 36 | 37 | symbol h2: π (`∀ x, x ∈ S1); 38 | 39 | symbol ok: π (`∀ x, x ∈ S2) ≔ 40 | begin 41 | assume x; 42 | rewrite left h1; 43 | refine (h2 x); 44 | end; 45 | 46 | symbol bug: π (`∀ x, x ∈ S2) ≔ 47 | begin 48 | rewrite left h1; 49 | refine h2; 50 | end; 51 | -------------------------------------------------------------------------------- /tests/OK/1141.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.Set tests.OK.Prop tests.OK.Nat tests.OK.List; 2 | 3 | symbol sample_1 (list : 𝕃 nat) : π ⊤ ≔ 4 | begin 5 | induction 6 | { apply ⊤ᵢ } 7 | { assume x l ih; apply ih } 8 | end; 9 | -------------------------------------------------------------------------------- /tests/OK/1190a.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol f:A → A → A; 3 | -------------------------------------------------------------------------------- /tests/OK/1190b.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.1190a; 2 | 3 | notation f infix right 10; 4 | -------------------------------------------------------------------------------- /tests/OK/1190c.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.1190a tests.OK.1190b; 2 | 3 | symbol a:A; 4 | 5 | type a f a; 6 | -------------------------------------------------------------------------------- /tests/OK/1217.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.Set tests.OK.Prop tests.OK.FOL tests.OK.Eq tests.OK.HOL tests.OK.Impred tests.OK.PropExt; 2 | 3 | symbol forallSimp (t : Set) (p : τ o) : π ((`∀ (x : τ t), p) = p) ≔ 4 | begin 5 | assume t p; 6 | refine propExt (`∀ x, p) p _ _ 7 | {assume h; refine h (el t)} 8 | {assume h a; refine h} 9 | end; 10 | 11 | symbol a : τ o; 12 | 13 | symbol example : π ((`∀ x : τ ι, a) ⇒ a) ≔ 14 | begin 15 | rewrite forallSimp; 16 | assume h; refine h 17 | end; 18 | -------------------------------------------------------------------------------- /tests/OK/1247.lp: -------------------------------------------------------------------------------- 1 | symbol Prop: TYPE; 2 | symbol π: Prop → TYPE; 3 | symbol Set: TYPE; 4 | constant symbol τ: Set → TYPE; 5 | builtin "T" ≔ τ; 6 | builtin "P" ≔ π; 7 | 8 | symbol = [a:Set] : τ a → τ a → Prop; 9 | 10 | notation = infix 10; 11 | 12 | constant symbol eq_refl [a:Set] (x:τ a) : π (x = x); 13 | constant symbol ind_eq [a:Set] [x y:τ a] : π (x = y) → Π p, π (p y) → π (p x); 14 | 15 | builtin "eq" ≔ =; 16 | builtin "refl" ≔ eq_refl; 17 | builtin "eqind" ≔ ind_eq; 18 | 19 | symbol S: Set; 20 | symbol a: τ S; 21 | symbol cset [T]: (τ T → Prop) → τ S; 22 | 23 | symbol th: π (a = a) ≔ 24 | begin 25 | flag "print_implicits" on; 26 | flag "print_domains" on; 27 | set E ≔ @cset S (λ x, @= S x x); 28 | have h:π (E = `cset x:τ S, x = x) { reflexivity }; 29 | reflexivity 30 | end; 31 | -------------------------------------------------------------------------------- /tests/OK/215.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.natural; 2 | 3 | symbol VectN : N → TYPE; 4 | symbol nil: VectN 0; 5 | symbol cons (n: N): N → VectN n → VectN (n + 1); 6 | 7 | // [n] requires to be 0 to type 8 | // Knowing that it is of type N is not enough 9 | type let n ≔ 0 in cons n 0 nil; 10 | -------------------------------------------------------------------------------- /tests/OK/225.lp: -------------------------------------------------------------------------------- 1 | symbol T:TYPE; 2 | symbol a:T; 3 | symbol f:(T → T) → T; 4 | rule f (λ x, $F.[x]) ↪ a; 5 | assert ⊢ λ (x:T), f(λ y, x) ≡ λ (x:T), a; 6 | assert ⊢ f (λ x, x) ≡ a; 7 | -------------------------------------------------------------------------------- /tests/OK/244.lp: -------------------------------------------------------------------------------- 1 | // Precedence for prefix operators 2 | symbol o : TYPE; 3 | symbol ~ : o → o; 4 | notation ~ prefix 5; 5 | type λ p x, ~(p x); 6 | type λ p x, ~ p x; 7 | assert ⊢ λ p x,~(p x) ≡ λ p x,~ p x; 8 | -------------------------------------------------------------------------------- /tests/OK/245.lp: -------------------------------------------------------------------------------- 1 | // Improve unification for injective symbols 2 | constant symbol Type : TYPE; 3 | injective symbol eta : Type → TYPE; 4 | 5 | // function type 6 | constant symbol > : Type → Type → Type; 7 | notation > infix right 6; 8 | 9 | rule eta ($a > $b) ↪ eta $a → eta $b; 10 | 11 | constant symbol i : Type; 12 | constant symbol o : Type; 13 | 14 | injective symbol eps : eta o → TYPE; 15 | 16 | constant symbol --> : eta (o > o > o); 17 | notation --> infix right 6; 18 | 19 | rule eps ($a --> $b) ↪ eps $a → eps $b; 20 | 21 | constant symbol all : Π [A : Type], eta ((A > o) > o); 22 | rule eps (@all $a $b) ↪ Π (x : eta $a), eps ($b x); 23 | 24 | // Leibniz equality 25 | symbol = : 26 | Π [A : Type], eta (A > A > o) ≔ 27 | λ A x y, all (λ p , p x 28 | --> p y); 29 | notation = infix right 7; 30 | 31 | // reflexivity of equality 32 | symbol eq_refl : 33 | Π [A : Type], eps (@all A (λ x, x = x)) ≔ 34 | λ A x q H, H; 35 | 36 | // symmetry of equality 37 | symbol eq_sym : 38 | Π [A : Type] (x y : eta A), 39 | eps (x = y --> y = x) ≔ 40 | λ A x y H, H (λ y, y = x) (eq_refl x); 41 | -------------------------------------------------------------------------------- /tests/OK/245b.lp: -------------------------------------------------------------------------------- 1 | constant symbol Type : TYPE; 2 | injective symbol eta : Type → TYPE; 3 | 4 | // function type 5 | constant symbol > : Type → Type → Type; 6 | notation > infix right 6; 7 | rule eta ($a > $b) ↪ eta $a → eta $b; 8 | 9 | constant symbol i : Type; 10 | constant symbol o : Type; 11 | 12 | injective symbol eps : eta o → TYPE; 13 | 14 | constant symbol --> : eta (o > o > o); 15 | notation --> infix right 6; 16 | rule eps ($a --> $b) ↪ eps $a → eps $b; 17 | 18 | constant symbol all : Π [A : Type], eta ((A > o) > o); 19 | rule eps (@all $a $b) ↪ Π (x : eta $a), eps ($b x); 20 | 21 | symbol id : Π [A : Type], eta (A > A) ≔ λ A x, x; 22 | 23 | constant symbol zero : eta i; 24 | constant symbol succ : eta (i > i); 25 | 26 | // works 27 | type id zero; 28 | type @id (i > i) succ; 29 | type id succ; 30 | 31 | symbol true : eta o ≔ all (λ p, p --> p); 32 | symbol trueI : eps true ≔ λ P p, p; 33 | symbol imp_refl : Π [P : eta o], eps (P --> P) ≔ λ P prf, prf; 34 | symbol true_imp_true : eps (true --> true) ≔ @imp_refl true; 35 | 36 | // works 37 | type @imp_refl true trueI; 38 | type @imp_refl (true --> true) true_imp_true; 39 | 40 | // does not work 41 | type imp_refl trueI; 42 | type imp_refl true_imp_true; 43 | -------------------------------------------------------------------------------- /tests/OK/262_legacy_parsing.dk: -------------------------------------------------------------------------------- 1 | def A : Type. 2 | 3 | a : A. 4 | b : A. 5 | 6 | private f : A -> A. 7 | -------------------------------------------------------------------------------- /tests/OK/262_pair_ex_1.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | symbol Pair : TYPE; 3 | 4 | symbol pair : A → A → Pair; 5 | 6 | // Use example: public [pair] reduces to protected [_pair] 7 | protected symbol _pair : A → Pair; 8 | 9 | rule pair $X _ ↪ _pair $X; 10 | -------------------------------------------------------------------------------- /tests/OK/262_pair_ex_2.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.{|262_pair_ex_1|}; 2 | 3 | symbol a : A; 4 | symbol b : A; 5 | 6 | symbol P ≔ pair a a; 7 | symbol Q ≔ pair a b; 8 | 9 | // Since pair reduces to _pair which forgets its second argument, 10 | // P and Q are equal 11 | assert ⊢ P ≡ Q; 12 | -------------------------------------------------------------------------------- /tests/OK/262_parsing.lp: -------------------------------------------------------------------------------- 1 | // Test parsing of protected and private keywords 2 | // Define several constants to be used by other tests 3 | constant symbol A : TYPE; 4 | 5 | private symbol f : A → A; 6 | protected symbol g : A → A; 7 | 8 | private symbol fdouble x ≔ f (f x); 9 | protected symbol gdouble x ≔ g (g x); 10 | 11 | // Mixing public, protected and private: if the head is private, so is the 12 | // rest 13 | private symbol fog x ≔ f (g x); // Private and protected 14 | symbol h : A → A; 15 | private symbol fogoh x ≔ f (g (h x)); // Public, private, protected 16 | 17 | // Rewriting rules from private symbols to private symbols are allowed 18 | private symbol a : A; 19 | rule f _ ↪ a; 20 | -------------------------------------------------------------------------------- /tests/OK/262_private_in_lhs.lp: -------------------------------------------------------------------------------- 1 | // Using private symbols in LHSs 2 | require tests.OK.{|262_parsing|} as D; 3 | 4 | symbol f : D.A → D.A; 5 | 6 | rule f (D.g $x) ↪ $x 7 | with f (D.gdouble $x) ↪ f $x; 8 | -------------------------------------------------------------------------------- /tests/OK/273.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | 3 | constant symbol f : A → A; 4 | 5 | constant symbol B : A → TYPE; 6 | constant symbol consB : Π x, B (f x); 7 | 8 | constant symbol C : A → A → TYPE; 9 | constant symbol consC : Π x, C x (f x); 10 | 11 | symbol k : Π a, B a → A; 12 | rule k _ (consB $b) ↪ $b; 13 | 14 | symbol calc : Π a b, C (f a) (k a b) → TYPE; 15 | 16 | constant symbol D : Π x, B (f (f x)) → TYPE; 17 | 18 | rule calc $a (consB $b) (consC _) ↪ D $b (consB $a); 19 | -------------------------------------------------------------------------------- /tests/OK/292.lp: -------------------------------------------------------------------------------- 1 | flag "print_domains" on; 2 | 3 | symbol R : TYPE; 4 | constant symbol zero : R; 5 | symbol d2_1 : (R → R → R) → (R → R → R); 6 | 7 | // The following are equivalent 8 | rule d2_1 (λ _ y, $F.[y]) ↪ λ _ _,zero; // warning 9 | rule d2_1 (λ _ y, $_.[y]) ↪ λ _ _,zero; // warning 10 | rule d2_1 (λ _ y, _ ) ↪ λ _ _,zero; // no warning 11 | 12 | // The following two are currently NOT the same 13 | // (see https://github.com/Deducteam/lambdapi/issues/294) 14 | rule d2_1 (λ x y, $_.[y]) ↪ λ _ _,zero; // no warning 15 | rule d2_1 (λ _ y, _ ) ↪ λ _ _,zero; // no warning 16 | // The difference is that in the former variable "x" may appear in the type 17 | // of the "y" variable. That is not the case in the second line. 18 | 19 | // New warnings for (unused) bound λ-variables. 20 | symbol fst1 : R → R → R ≔ λ x y , x; // warning since y not bound. 21 | symbol fst2 : R → R → R ≔ λ x _ , x; // no warning 22 | symbol fst3 : R → R → R ≔ λ x _y, x; // no warning either 23 | -------------------------------------------------------------------------------- /tests/OK/298_lp.lp: -------------------------------------------------------------------------------- 1 | // natural numbers 2 | constant symbol N : TYPE; 3 | constant symbol z : N; 4 | constant symbol s : N → N; 5 | 6 | // three parameters function 7 | constant symbol f : N → N → N → N; 8 | assert n m (o:N) ⊢ f n m o ≡ f n m o; 9 | assert n (m:N) ⊢ f n m : N → N; 10 | -------------------------------------------------------------------------------- /tests/OK/301.lp: -------------------------------------------------------------------------------- 1 | constant symbol U : TYPE; 2 | constant symbol u : U; 3 | symbol Ux : U → TYPE; 4 | rule Ux _ ↪ U; 5 | constant symbol hx : Π (x : U), (Ux x → U) → U; 6 | symbol g : U → U; 7 | rule g $i ↪ hx $i (λ _, u); 8 | -------------------------------------------------------------------------------- /tests/OK/303.lp: -------------------------------------------------------------------------------- 1 | constant symbol U : TYPE; 2 | 3 | constant symbol u : U; 4 | 5 | constant symbol f : (U → U) → TYPE; 6 | 7 | symbol G : U → TYPE; 8 | 9 | constant symbol H : U → TYPE; 10 | 11 | rule G $v ↪ Π (a : H $v), f (λ _, u); 12 | -------------------------------------------------------------------------------- /tests/OK/328.lp: -------------------------------------------------------------------------------- 1 | //flag "print_implicits" on 2 | //verbose 3 3 | 4 | // Type of set codes 5 | 6 | constant symbol Set : TYPE; 7 | 8 | // Interpretation of set codes in TYPE 9 | 10 | injective symbol τ : Set → TYPE; 11 | 12 | // Type of natural numbers 13 | 14 | constant symbol nat : Set; 15 | 16 | symbol N ≔ τ nat; 17 | 18 | constant symbol zero : N; 19 | constant symbol succ : N → N; 20 | 21 | // Type of polymorphic lists 22 | 23 | constant symbol list : Set → Set; 24 | 25 | symbol L a ≔ τ (list a); 26 | 27 | constant symbol □ [a] : L a; 28 | constant symbol ⸬ [a] : τ a → L a → L a; 29 | 30 | notation ⸬ infix right 4; 31 | 32 | // Length of a list 33 | 34 | symbol length [a] : L a → N; 35 | 36 | rule length □ ↪ zero 37 | with length (_ ⸬ $l) ↪ succ (length $l); 38 | 39 | // Concatenation of two lists 40 | 41 | symbol ⋅ [a] : L a → L a → L a; 42 | 43 | notation ⋅ infix right 5; 44 | 45 | rule □ ⋅ $m ↪ $m 46 | with ($x ⸬ $l) ⋅ $m ↪ $x ⸬ ($l ⋅ $m); 47 | -------------------------------------------------------------------------------- /tests/OK/330.lp: -------------------------------------------------------------------------------- 1 | constant symbol Term : TYPE; 2 | constant symbol Prop : TYPE; 3 | symbol prf : Prop → TYPE; 4 | symbol equals : Term → Term → Prop; 5 | rule prf (equals $x $y) ↪ Π p, prf (p $x) → prf (p $y); 6 | -------------------------------------------------------------------------------- /tests/OK/330b.lp: -------------------------------------------------------------------------------- 1 | constant symbol Term : TYPE; 2 | constant symbol Prop : TYPE; 3 | symbol prf : Prop → TYPE; 4 | symbol prop_and : Prop → Prop → Prop; 5 | rule prf (prop_and $A $B) ↪ Π C, (prf $A → prf $B → prf C) → prf C; 6 | 7 | symbol and_elim_1 : Π A B, prf (prop_and A B) → prf A 8 | ≔ λ A B h, h A (λ a _, a); 9 | -------------------------------------------------------------------------------- /tests/OK/341.lp: -------------------------------------------------------------------------------- 1 | // check warnings on unused parameters in symbol declarations 2 | 3 | symbol A : TYPE; 4 | symbol f x : A ≔ x; // should not generate a warning 5 | symbol B : A → TYPE; 6 | symbol a : A; 7 | symbol g (x:A) : A ≔ a; // should generate a warning 8 | symbol h x : Π y:A,A ≔ λ _,x; // should generate a warning 9 | symbol i x : (Π y:A, A) → A ≔ λ _,x; // should generate a warning 10 | symbol j (x:A) : (λ _, A) x ≔ a; // should not generate a warning 11 | 12 | symbol Set : TYPE; 13 | symbol τ : Set → TYPE; 14 | symbol Prop : TYPE; 15 | builtin "Prop" ≔ Prop; 16 | symbol π : Prop → TYPE; 17 | builtin "P" ≔ π; 18 | 19 | (a:Set) inductive L : TYPE ≔ 20 | | nil : L a 21 | | cons : τ a → L a → L a; // should not generate a warning 22 | -------------------------------------------------------------------------------- /tests/OK/359.lp: -------------------------------------------------------------------------------- 1 | // Test that infix operators are considered as terms by commands 2 | symbol A: TYPE; 3 | symbol +: A → A → A; 4 | notation + infix 5; 5 | type (+); 6 | -------------------------------------------------------------------------------- /tests/OK/430.lp: -------------------------------------------------------------------------------- 1 | symbol Prop:TYPE; 2 | symbol A:TYPE; 3 | symbol ∀:(A → Prop) → Prop; 4 | notation ∀ quantifier; 5 | symbol p:A → Prop; 6 | type `∀ x,p x; 7 | symbol a:A; 8 | symbol ⇒:Prop → Prop → Prop; 9 | notation ⇒ infix left 5; 10 | type p a ⇒ (`∀ x, p x); 11 | type p a ⇒ `∀ x, p x; 12 | -------------------------------------------------------------------------------- /tests/OK/547.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol a:A; 3 | opaque symbol b ≔ a; 4 | assertnot ⊢ a ≡ b; 5 | -------------------------------------------------------------------------------- /tests/OK/55.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | 3 | def h : (A -> A) -> (A -> A) -> A -> A. 4 | 5 | [aa] h aa (x => aa x) --> aa. 6 | 7 | [aa] h (x => aa x) aa --> aa. 8 | -------------------------------------------------------------------------------- /tests/OK/573-2.lp: -------------------------------------------------------------------------------- 1 | // test matching on type annotations 2 | symbol T:TYPE; 3 | symbol a:T; 4 | symbol b:T; 5 | injective symbol U:T → TYPE; 6 | symbol f:Π x:T,(U x → T) → T; 7 | rule f _ (λ _:U a, a) ↪ b; 8 | assert ⊢ f _ (λ _:U a, a) ≡ b; 9 | assertnot ⊢ f _ (λ _:U b, a) ≡ b; 10 | -------------------------------------------------------------------------------- /tests/OK/573.lp: -------------------------------------------------------------------------------- 1 | // test matching on type annotations in abstractions/products 2 | 3 | constant symbol Set : TYPE; 4 | injective symbol τ : Set → TYPE; 5 | 6 | constant symbol prop : Set; 7 | symbol Prop ≔ τ prop; 8 | injective symbol π : Prop → TYPE; 9 | 10 | constant symbol ∀ [a] : (τ a → Prop) → Prop; 11 | notation ∀ quantifier; 12 | 13 | unif_rule π $p ≡ Π x:$t, π $q.[x] ↪ [ $p ≡ `∀ x:$t, $q.[x] ]; 14 | -------------------------------------------------------------------------------- /tests/OK/61.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | 3 | a : A. 4 | 5 | def T : A -> Type. 6 | 7 | [] T a --> A -> A. 8 | 9 | True : Type. 10 | 11 | def eq : A -> A -> Type. 12 | [x] eq x x --> True. 13 | true : True. 14 | def f : x : A -> y : A -> eq x y -> T x -> A. 15 | 16 | (; OK ;) 17 | [] f a _ true (x => x) --> a. 18 | 19 | (; Not OK ;) 20 | [] f _ a true (x => x) --> a. 21 | -------------------------------------------------------------------------------- /tests/OK/62.dk: -------------------------------------------------------------------------------- 1 | def A : Type. 2 | def eA : A -> Type. 3 | a : A. 4 | [] A --> eA a. 5 | 6 | B : Type. 7 | def eB : B -> Type. 8 | 9 | [] eB a --> eA a. 10 | -------------------------------------------------------------------------------- /tests/OK/621c.lp: -------------------------------------------------------------------------------- 1 | // test that an escaped regular identifier is equal to its unescaped form 2 | 3 | symbol A:TYPE; 4 | symbol f (v0:A) ≔ {|v0|}; 5 | -------------------------------------------------------------------------------- /tests/OK/650.lp: -------------------------------------------------------------------------------- 1 | symbol Prop : TYPE; 2 | 3 | symbol P : Prop → TYPE; 4 | 5 | symbol ∀ : (Prop → Prop) → Prop; 6 | notation ∀ quantifier; 7 | 8 | symbol ⇒ : Prop → Prop → Prop; 9 | notation ⇒ infix right 14; 10 | 11 | symbol False : Prop ≔ `∀ C, C; 12 | 13 | symbol true : TYPE ≔ 14 | P (False ⇒ `∀ C, C); 15 | -------------------------------------------------------------------------------- /tests/OK/655.lp: -------------------------------------------------------------------------------- 1 | constant symbol Typ: TYPE; 2 | constant symbol int: Typ; 3 | 4 | constant symbol id : Typ → Typ → Typ; 5 | notation id infix 2; 6 | 7 | symbol normal ≔ @id int int; 8 | 9 | constant symbol id2 : Typ → Typ → Typ; 10 | notation id2 prefix 3; 11 | 12 | symbol should_not_fail ≔ @id2 int int; 13 | -------------------------------------------------------------------------------- /tests/OK/655b.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol a:A; 3 | 4 | symbol +:A → A → A; notation + infix right 10; 5 | 6 | assert ⊢ (+) : A → A → A; 7 | assert ⊢ (+) a : A → A; 8 | assert ⊢ @+ : A → A → A; 9 | assert ⊢ @+ a : A → A; 10 | assert ⊢ (@+ a a) + a : A; 11 | 12 | symbol * [_:A] : A → A → A; notation * infix right 10; 13 | 14 | assert ⊢ (*) : A → A → A; 15 | assert ⊢ (*) a : A → A; 16 | assert ⊢ @* : A → A → A → A; 17 | assert ⊢ @* a : A → A → A; 18 | assert ⊢ (@* _ a a) * a : A; 19 | 20 | symbol f : (A → A → A) → A; 21 | 22 | assert ⊢ f (+) : A; 23 | assert ⊢ f @+ : A; 24 | 25 | assert ⊢ f (*) : A; 26 | assert ⊢ f (@* _) : A; 27 | -------------------------------------------------------------------------------- /tests/OK/665.lp: -------------------------------------------------------------------------------- 1 | constant symbol Prop : TYPE; 2 | constant symbol true: Prop; 3 | 4 | constant symbol ⩵ : Prop → Prop → Prop; 5 | notation ⩵ infix 3.0; 6 | 7 | symbol Trivial : Prop ≔ @true ⩵ true; 8 | -------------------------------------------------------------------------------- /tests/OK/679.lp: -------------------------------------------------------------------------------- 1 | constant symbol Typ : TYPE; 2 | 3 | injective symbol η : Typ → TYPE; 4 | 5 | constant symbol ⇒ : Typ → Typ → Typ; 6 | notation ⇒ infix right 1.0; 7 | rule η ($a ⇒ $b) ↪ η $a → η $b; 8 | 9 | constant symbol + ['a : Typ] : η 'a → η 'a; 10 | constant symbol Int: Typ; 11 | 12 | symbol problem ≔ + (λ (x : η Int), + x); 13 | -------------------------------------------------------------------------------- /tests/OK/683.lp: -------------------------------------------------------------------------------- 1 | symbol Prop : TYPE; 2 | symbol Type : TYPE; 3 | 4 | symbol T : Type → TYPE; 5 | 6 | symbol prop : Type; 7 | rule T prop ↪ Prop; 8 | 9 | symbol ∀ [x : Type] : (T x → Prop) → Prop; 10 | notation ∀ quantifier; 11 | 12 | unif_rule Prop ≡ T $t ↪ [ $t ≡ prop ]; 13 | 14 | symbol ⊥ : Prop ≔ `∀ C : Prop, C; 15 | -------------------------------------------------------------------------------- /tests/OK/693.lp: -------------------------------------------------------------------------------- 1 | constant symbol Set: TYPE; 2 | 3 | injective symbol τ: Set → TYPE; 4 | 5 | builtin "T" ≔ τ; 6 | 7 | constant symbol Prop: TYPE; 8 | 9 | symbol π: Prop → TYPE; 10 | 11 | builtin "P" ≔ π; 12 | 13 | constant symbol ⇒: Prop → Prop → Prop; notation ⇒ infix right 10; 14 | 15 | rule π ($p ⇒ $q) ↪ π $p → π $q; 16 | 17 | constant symbol = [a] : τ a → τ a → Prop; notation = infix 20; 18 | 19 | constant symbol eq_refl [a] (x:τ a) : π (x = x); 20 | constant symbol ind_eq [a] [x y:τ a] : π (x = y) → Π p, π (p y) → π (p x); 21 | 22 | builtin "eq" ≔ =; 23 | builtin "refl" ≔ eq_refl; 24 | builtin "eqind" ≔ ind_eq; 25 | 26 | symbol fold_arrow [p1 p2 : Prop] : π (p1 ⇒ p2) → π p1 → π p2 27 | ≔ λ p1_p2 p1, p1_p2 p1; 28 | 29 | constant symbol nat: Set; 30 | 31 | symbol test_assume (a b : τ nat) f : π (a = b ⇒ f a ⇒ f b) ≔ 32 | begin 33 | assume a b f; assume eab; rewrite eab; assume fb; apply fb 34 | end; 35 | -------------------------------------------------------------------------------- /tests/OK/693_assume.lp: -------------------------------------------------------------------------------- 1 | symbol Prop : TYPE; 2 | symbol Type : TYPE; 3 | 4 | injective symbol π : Prop → TYPE; 5 | 6 | symbol ∀ [x : Prop] : (π x → Prop) → Prop; 7 | 8 | rule π (∀ $f) ↪ Π w, π ($f w); 9 | 10 | symbol ⊤ : Prop; 11 | symbol top : π ⊤; 12 | 13 | symbol ⊥ : Prop; 14 | 15 | symbol ⇒ A B ≔ @∀ A (λ _, B); notation ⇒ infix right 14; 16 | 17 | symbol bool : TYPE; 18 | symbol true : bool; 19 | symbol false : bool; 20 | 21 | symbol if : Prop → Prop → bool → Prop; 22 | 23 | rule if $vt _ true ↪ $vt 24 | with if _ $vf false ↪ $vf; 25 | 26 | symbol is_true ≔ if ⊤ ⊥; 27 | 28 | symbol test b : π (is_true b ⇒ ⊤) 29 | ≔ begin 30 | assume b H; 31 | refine top 32 | end; 33 | -------------------------------------------------------------------------------- /tests/OK/698_abst_impl.lp: -------------------------------------------------------------------------------- 1 | constant symbol Set:TYPE; 2 | constant symbol nat:Set; 3 | 4 | injective symbol τ:Set → TYPE; 5 | constant symbol z:τ nat; 6 | 7 | symbol f a:τ a → τ a; 8 | 9 | type (λ [a], λ x, f a x) z; 10 | 11 | type (λ [a], λ x, f a x) [nat] z; 12 | 13 | symbol id ≔ λ [a] (x:τ a), x; 14 | 15 | type id z; 16 | -------------------------------------------------------------------------------- /tests/OK/706.lp: -------------------------------------------------------------------------------- 1 | // Support for negative priorities. 2 | 3 | symbol E : TYPE; 4 | symbol o (_ _: E): E; 5 | notation o infix -3; 6 | -------------------------------------------------------------------------------- /tests/OK/72.dk: -------------------------------------------------------------------------------- 1 | typ : Type. 2 | 3 | injective eta : typ -> Type. 4 | 5 | prod : A : typ -> (eta A -> typ) -> typ. 6 | 7 | lam : A : typ -> B : (eta A -> typ) -> (x:eta A -> eta (B x)) -> eta (prod A B). 8 | 9 | def app : A : typ -> B : (eta A -> typ) -> eta (prod A B) -> x: eta A -> eta (B x). 10 | 11 | [f,a] app _ _ (lam _ _ f) a --> f a. 12 | 13 | [A,f] eta (prod A f) --> a:eta A -> eta (f a). 14 | -------------------------------------------------------------------------------- /tests/OK/725.lp: -------------------------------------------------------------------------------- 1 | // See https://github.com/Deducteam/lambdapi/issues/725 2 | // This file ensures that implicits arguments are correctly detected, even 3 | // when a let in declaration appears between arguments. 4 | 5 | symbol Prop: TYPE; 6 | symbol Set: TYPE; 7 | symbol El: Set → TYPE; 8 | symbol psub (t: Set) (_: El t → Prop): Set; 9 | 10 | symbol foo: Π [T: Set] [S_pred : El T → Prop], 11 | let S : Set ≔ psub T S_pred in // The let in between the arguments 12 | Π [e: El S], El S ≔ 13 | λ[T:Set] [S_pred: El T → Prop], 14 | let S : Set ≔ psub T S_pred in 15 | λ [e: El S], e; 16 | 17 | constant symbol i: Set; 18 | constant symbol i_pred: El i → Prop; 19 | symbol x : El (psub i i_pred); 20 | assert ⊢ foo [i] [i_pred] [x] ≡ x; 21 | -------------------------------------------------------------------------------- /tests/OK/729.lp: -------------------------------------------------------------------------------- 1 | require tests.OK.boolean as B; 2 | symbol T : (B.B → B.B) → TYPE; 3 | symbol bool_neg: B.B → B.B; 4 | symbol foo : T B.bool_neg; 5 | symbol bar : T bool_neg; 6 | assertnot ⊢ T B.bool_neg ≡ T bool_neg; 7 | -------------------------------------------------------------------------------- /tests/OK/767.lp: -------------------------------------------------------------------------------- 1 | constant symbol Set : TYPE; 2 | injective symbol τ : Set → TYPE; 3 | constant symbol B : Set; 4 | type λ (f : _ → τ B) (b: τ B), f b; 5 | // type λ (f : _ → _ → τ B) (g : τ B → τ B) b1 b2, f (g b1) (g b2); 6 | // The command above fails because the instantiation of the second placeholder 7 | // triggers a unification problem τ B == ?1[g b1], which fails because `g b1` 8 | // is not a variable. 9 | // "arguments are not distinct variables: g b1" 10 | // It worked before this PR because the arrow notation would specify that the 11 | // second meta-variable cannot depend on the first argument. 12 | -------------------------------------------------------------------------------- /tests/OK/813.lp: -------------------------------------------------------------------------------- 1 | constant symbol Set : TYPE; 2 | injective symbol El : Set → TYPE; 3 | sequential symbol η (A : Set) : El A → El A; 4 | rule η _ (η $A $x) ↪ η $A $x; 5 | 6 | constant symbol Σ (A : Set) (B : El A → Set) : Set; 7 | //constant symbol TypeΣ (A : Set) (B : El A → Set) : TYPE; 8 | //rule El (Σ $A $B) ↪ TypeΣ $A (λ x, $B (η $A x)); 9 | 10 | constant symbol intro-Σ (A : Set) (B : El A → Set) (a : El A) (b : El (B (η A a))) : El (Σ A (λ x, B (η A x))); 11 | symbol fst (A : Set) (B : El A → Set) (p : El (Σ A (λ x, B (η A x)))) : El A; 12 | symbol snd (A : Set) (B : El A → Set) (p : El (Σ A (λ x, B (η A x)))) : El (B (η A (fst A (λ x, B (η A x)) p))); 13 | 14 | //rule η (Σ $A $B) $p ↪ intro-Σ $A (λ x, $B (η $A x)) (η $A (fst $A (λ x, $B (η $A x)) $p)) (η ($B (η $A (fst $A (λ x, $B (η $A x)) $p))) (snd $A (λ x, $B (η $A x)) $p)); 15 | 16 | rule fst _ _ (intro-Σ $A _ $a _) ↪ η $A $a; 17 | 18 | rule snd _ _ (intro-Σ $A $B $a $b) ↪ η ($B (η $A $a)) $b; 19 | -------------------------------------------------------------------------------- /tests/OK/830.lp: -------------------------------------------------------------------------------- 1 | symbol A: TYPE; 2 | symbol a: A; 3 | 4 | opaque symbol foo: A ≔ 5 | let v ≔ _ in 6 | v 7 | begin 8 | admitted; 9 | -------------------------------------------------------------------------------- /tests/OK/861.lp: -------------------------------------------------------------------------------- 1 | // Define the CoC encoding 2 | symbol Prop : TYPE; 3 | symbol Type : TYPE; 4 | 5 | injective symbol π : Prop → TYPE; 6 | injective symbol ε : Type → TYPE; 7 | 8 | symbol dotProp : Type; 9 | rule ε dotProp ↪ Prop; 10 | 11 | symbol ∀ₚₚ [x : Prop] : (π x → Prop) → Prop; 12 | symbol ∀ₚₜ [x : Prop] : (π x → Type) → Type; 13 | symbol ∀ₜₚ [x : Type] : (ε x → Prop) → Prop; 14 | symbol ∀ₜₜ [x : Type] : (ε x → Type) → Type; 15 | 16 | rule π (∀ₚₚ $f) ↪ Π w, π ($f w) 17 | with ε (∀ₚₜ $f) ↪ Π w, ε ($f w) 18 | with π (∀ₜₚ $f) ↪ Π w, π ($f w) 19 | with ε (∀ₜₜ $f) ↪ Π w, ε ($f w); 20 | 21 | symbol ⇒ A B ≔ @∀ₚₚ A (λ _, B); 22 | notation ⇒ infix right 14; 23 | 24 | notation ∀ₜₚ quantifier; 25 | 26 | // Define the equality in this setting 27 | symbol = [T] (x y : π T) : Prop 28 | ≔ `∀ₜₚ P, P y ⇒ P x; 29 | notation = infix 20; 30 | 31 | symbol =_refl [T] (x : π T) : π (x = x) ≔ λ P px, px; 32 | symbol =_ind [T] (x y : π T) : π (x = y) → Π P, π (P y) → π (P x) 33 | ≔ λ eqxy, eqxy (λ t, t = y) (=_refl y); 34 | 35 | builtin "P" ≔ π; 36 | builtin "Prop" ≔ Prop; 37 | builtin "T" ≔ π; 38 | builtin "eq" ≔ =; 39 | builtin "refl" ≔ =_refl; 40 | builtin "eqind" ≔ =_ind; 41 | 42 | inductive ℕ : TYPE ≔ 43 | | zero : ℕ 44 | | s : ℕ → ℕ; 45 | 46 | symbol nat : Prop; 47 | rule π nat ↪ ℕ; 48 | 49 | 50 | symbol rewrite_test (x : ℕ) : π (x = x) 51 | ≔ begin 52 | 53 | induction 54 | { reflexivity } 55 | { reflexivity } 56 | 57 | end; 58 | -------------------------------------------------------------------------------- /tests/OK/878.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol a:A; 3 | symbol b ≔ a; 4 | -------------------------------------------------------------------------------- /tests/OK/904.lp: -------------------------------------------------------------------------------- 1 | /* test tactic generalize */ 2 | symbol A:TYPE; 3 | symbol B:TYPE; 4 | symbol C:TYPE; 5 | symbol F:A → B → C → TYPE; 6 | opaque symbol lemma (x:A) (y:B) (z:C) : F x y z ≔ 7 | begin 8 | assume x y z; generalize x; 9 | abort; 10 | -------------------------------------------------------------------------------- /tests/OK/922.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.Set tests.OK.Prop tests.OK.Eq tests.OK.Bool; 2 | 3 | inductive ℕ : TYPE ≔ 4 | | O : ℕ 5 | | +1 : ℕ → ℕ; 6 | 7 | constant symbol nat : Set; 8 | 9 | rule τ nat ↪ ℕ; 10 | 11 | notation +1 postfix 10; 12 | 13 | symbol isO : ℕ → 𝔹; 14 | 15 | rule isO O ↪ true 16 | with isO (_ +1) ↪ false; 17 | 18 | opaque symbol s≠O [n] : π (n +1 ≠ O) ≔ 19 | begin 20 | assume n h; refine ind_eq h (λ n, istrue(isO n)) ⊤ᵢ 21 | end; 22 | -------------------------------------------------------------------------------- /tests/OK/989.lp: -------------------------------------------------------------------------------- 1 | symbol Prop : TYPE; 2 | injective symbol Prf : Prop → TYPE; 3 | builtin "Prop" ≔ Prop; 4 | builtin "P" ≔ Prf; 5 | 6 | symbol Set : TYPE; 7 | injective symbol τ : Set → TYPE; 8 | injective symbol τ' : Prop → TYPE; 9 | 10 | (a:Set) inductive L:TYPE ≔ 11 | | nil : L a 12 | | cons : τ a → L a → L a; 13 | 14 | /* 15 | debug +sriu; 16 | verbose 3; 17 | flag "print_meta_types" on; 18 | flag "print_implicits" on; 19 | */ 20 | 21 | (a:Set) (b:Prop) inductive 𝕃:TYPE ≔ 22 | | □ : 𝕃 a b 23 | | ⸬ : τ a → τ' b → 𝕃 a b → 𝕃 a b; 24 | -------------------------------------------------------------------------------- /tests/OK/991.lp: -------------------------------------------------------------------------------- 1 | symbol Prop:TYPE; 2 | symbol -:Prop → Prop; notation - prefix 10; 3 | associative commutative symbol +: Prop → Prop → Prop; notation + infix right 5; 4 | injective symbol π:Prop → TYPE; 5 | symbol resolution x a b : π (x + a) → π (- x + b) → π (a + b); 6 | opaque symbol test a b c d e : 7 | π (e + a + b) → π (c + d + - e) → π (a + b + c + d) ≔ 8 | begin 9 | assume a b c d e h1 h2; 10 | apply resolution e (b + a) (d + c) h1 h2 11 | end; 12 | -------------------------------------------------------------------------------- /tests/OK/Classic.lp: -------------------------------------------------------------------------------- 1 | // classical logic 2 | 3 | require open tests.OK.Set tests.OK.Prop tests.OK.FOL; 4 | 5 | symbol em p : π (p ∨ ¬ p); // excluded middle 6 | 7 | opaque symbol ¬¬ₑ p : π (¬ ¬ p) → π p ≔ 8 | begin 9 | assume p nnp; apply ∨ₑ (em p) 10 | { assume h; refine h } 11 | { assume np; apply ⊥ₑ; refine nnp np } 12 | end; 13 | 14 | opaque symbol ∨¬ᵢ p q : π (p ⇒ q) → π (¬ p ∨ q) ≔ 15 | begin 16 | assume p q pq; apply ∨ₑ (em p) 17 | { assume hp; refine ∨ᵢ₂ _; refine pq hp } 18 | { assume np; refine ∨ᵢ₁ np } 19 | end; 20 | 21 | opaque symbol ∃¬ᵢ a p : π (¬ (∀ p)) → π (`∃ x : τ a, ¬ (p x)) ≔ 22 | begin 23 | assume a p not_all_p; apply ∨ₑ (em (`∃ x, ¬ (p x))) 24 | { assume h; apply h } 25 | { assume not_ex_not_p; apply ⊥ₑ; apply not_all_p; 26 | have h: π (`∀ x, ¬ ¬ (p x)) 27 | { refine ¬∃ (λ x, ¬ (p x)) _; refine not_ex_not_p}; 28 | assume x; apply ¬¬ₑ; refine h x 29 | } 30 | end; 31 | -------------------------------------------------------------------------------- /tests/OK/Eq.lp: -------------------------------------------------------------------------------- 1 | // polymorphic Leibniz equality 2 | 3 | require open tests.OK.Set tests.OK.Prop; 4 | 5 | constant symbol = [a] : τ a → τ a → Prop; 6 | 7 | notation = infix 10; 8 | 9 | constant symbol eq_refl [a] (x:τ a) : π (x = x); 10 | constant symbol ind_eq [a] [x y:τ a] : π (x = y) → Π p, π (p y) → π (p x); 11 | 12 | builtin "eq" ≔ =; 13 | builtin "refl" ≔ eq_refl; 14 | builtin "eqind" ≔ ind_eq; 15 | 16 | symbol ≠ [a] (x y : τ a) ≔ ¬ (x = y); notation ≠ infix 10; // \neq 17 | 18 | opaque symbol feq [a b] (f:τ a → τ b) [x x':τ a] : π(x = x') → π(f x = f x') ≔ 19 | begin 20 | assume a b f x x' xx'; rewrite xx'; reflexivity; 21 | end; 22 | 23 | opaque symbol feq2 [a b c] (f:τ a → τ b → τ c): 24 | Π [x x':τ a], π(x = x') → Π [y y':τ b], π(y = y') → π(f x y = f x' y') ≔ 25 | begin 26 | assume a b c f x x' xx' y y' yy'; rewrite xx'; rewrite yy'; reflexivity 27 | end; 28 | 29 | opaque symbol eq_sym [a] [x y:τ a] : π(x = y) → π(y = x) ≔ 30 | begin 31 | assume a x y h; symmetry; apply h 32 | end; 33 | -------------------------------------------------------------------------------- /tests/OK/Escaped.lp: -------------------------------------------------------------------------------- 1 | // The following is forbidden as [KIND] is reserved. 2 | //symbol KIND : TYPE; 3 | 4 | // The following is accepted. 5 | symbol {|KIND|} : TYPE; 6 | 7 | // Escaped with dots (used to test module resolution) 8 | symbol {|KIND.OF.BLUE|}: TYPE; 9 | 10 | // Escaped with some rules 11 | symbol {|_set|} : TYPE; 12 | rule {|_set|} ↪ {|KIND|}; 13 | -------------------------------------------------------------------------------- /tests/OK/FOL.lp: -------------------------------------------------------------------------------- 1 | // (multi-sorted) First-order logic 2 | 3 | require open tests.OK.Set tests.OK.Prop; 4 | 5 | // Universal quantification 6 | 7 | constant symbol ∀ [a] : (τ a → Prop) → Prop; // !! or \forall 8 | 9 | builtin "all" ≔ ∀; 10 | 11 | notation ∀ quantifier; 12 | 13 | rule π (∀ $f) ↪ Π x, π ($f x); 14 | 15 | // Existential quantification 16 | 17 | constant symbol ∃ [a] : (τ a → Prop) → Prop; // ?? or \exists 18 | 19 | builtin "ex" ≔ ∃; 20 | 21 | notation ∃ quantifier; 22 | 23 | constant symbol ∃ᵢ [a p] (x:τ a) : π (p x) → π (∃ p); 24 | 25 | symbol ∃ₑ [a p] : π (∃ p) → Π [q], (Π x:τ a, π (p x) → π q) → π q; 26 | 27 | rule ∃ₑ (∃ᵢ $x $px) $f ↪ $f $x $px; 28 | 29 | // properties 30 | 31 | opaque symbol ¬∃ [a] p : π (¬ (∃ p) ⇒ `∀ x : τ a, ¬ (p x)) ≔ 32 | begin 33 | assume a p not_ex_p x px; apply not_ex_p; apply ∃ᵢ x px 34 | end; 35 | -------------------------------------------------------------------------------- /tests/OK/HOL.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.Set; 2 | 3 | symbol ⤳ : Set → Set → Set; // \leadsto 4 | 5 | notation ⤳ infix right 20; 6 | 7 | rule τ ($x ⤳ $y) ↪ τ $x → τ $y; 8 | -------------------------------------------------------------------------------- /tests/OK/Impred.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.Set tests.OK.Prop; 2 | 3 | symbol o : Set; 4 | 5 | rule τ o ↪ Prop; 6 | -------------------------------------------------------------------------------- /tests/OK/Option.lp: -------------------------------------------------------------------------------- 1 | // option type 2 | 3 | require open tests.OK.Set; 4 | 5 | constant symbol option : Set → Set; 6 | 7 | constant symbol none [a] : τ (option a); 8 | constant symbol some [a] : τ a → τ (option a); 9 | -------------------------------------------------------------------------------- /tests/OK/Set.lp: -------------------------------------------------------------------------------- 1 | // Type of set codes for quantifying over sets (polymorphism) 2 | 3 | constant symbol Set : TYPE; 4 | 5 | constant symbol ι : Set; 6 | 7 | // Interpretation of set codes in TYPE 8 | 9 | injective symbol τ : Set → TYPE; // `t or \tau 10 | 11 | builtin "T" ≔ τ; 12 | 13 | // We assume that sets are non-empty 14 | 15 | symbol el a : τ a; 16 | 17 | // Cartesian product 18 | 19 | constant symbol × : Set → Set → Set; notation × infix right 10; // \times 20 | 21 | assert a b c ⊢ a × b × c ≡ a × (b × c); 22 | 23 | symbol & [a b] : τ a → τ b → τ (a × b); notation & infix right 30; 24 | 25 | assert a (x:τ a) b (y:τ b) c (z:τ c) ⊢ x & y & z : τ(a × b × c); 26 | assert x y z ⊢ x & y & z ≡ x & (y & z); 27 | 28 | symbol ₁ [a b] : τ(a × b) → τ a; notation ₁ postfix 10; 29 | 30 | rule ($x & _)₁ ↪ $x; 31 | 32 | symbol ₂ [a b] : τ(a × b) → τ b; notation ₂ postfix 10; 33 | 34 | rule (_ & $x)₂ ↪ $x; 35 | -------------------------------------------------------------------------------- /tests/OK/String.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.Set; 2 | 3 | constant symbol String : TYPE; 4 | builtin "String" ≔ String; 5 | 6 | constant symbol string : Set; 7 | rule τ string ↪ String; 8 | 9 | type "hello world!"; 10 | 11 | compute "hello world!"; 12 | 13 | assert ⊢ "a" : String; 14 | 15 | assert ⊢ "a" ≡ "a"; 16 | 17 | assertnot ⊢ "a" ≡ "b"; 18 | -------------------------------------------------------------------------------- /tests/OK/a b/escape file.lp: -------------------------------------------------------------------------------- 1 | // test escaped identifiers 2 | symbol {| |}:TYPE; 3 | symbol {|}|}:TYPE; 4 | symbol {|||}:TYPE; 5 | symbol {|a.}|_|_}}|||}:TYPE; 6 | symbol A:TYPE; 7 | assert ⊢ A ≡ {|A|}; 8 | -------------------------------------------------------------------------------- /tests/OK/abstractions.lp: -------------------------------------------------------------------------------- 1 | // A simple test on abstractions, taken from the [miller] tests. 2 | symbol R : TYPE; 3 | 4 | symbol flip : (R → R → R) → (R → R → R); 5 | rule flip (λ x, λ y, $f.[x; y]) ↪ λ (x:R), λ (y:R), $f.[y; x]; 6 | 7 | symbol f : R → R → R; 8 | symbol x : R; 9 | symbol y : R; 10 | 11 | compute flip (λ x, λ y, f x y); 12 | assert ⊢ flip (λ x, λ y, f x y) ≡ λ x, λ y, f y x; 13 | -------------------------------------------------------------------------------- /tests/OK/ac.lp: -------------------------------------------------------------------------------- 1 | // test commutative and associative-commutative symbols 2 | 3 | constant symbol A : TYPE; 4 | 5 | commutative symbol + : A → A → A; 6 | notation + infix 10; 7 | assert x y ⊢ x + y ≡ y + x; 8 | 9 | associative commutative symbol * : A → A → A; 10 | notation * infix 10; 11 | assert x y ⊢ x * y ≡ y * x; 12 | assert x y z ⊢ (x * y) * z ≡ x * (y * z); 13 | assert x y z ⊢ (x * y) * z ≡ (z * x) * y; 14 | 15 | left associative commutative symbol ^ : A → A → A; 16 | notation ^ infix 10; 17 | assert x y ⊢ x ^ y ≡ y ^ x; 18 | assert x y z ⊢ (x ^ y) ^ z ≡ x ^ (y ^ z); 19 | assert x y z ⊢ (x ^ y) ^ z ≡ (z ^ x) ^ y; 20 | 21 | // #642 22 | 23 | constant symbol z : A; 24 | constant symbol s : A → A; 25 | 26 | rule z + $y ↪ $y 27 | with (s $x) + $y ↪ s ($x + $y); 28 | 29 | // #644 30 | 31 | symbol Nat : TYPE; 32 | symbol plus_N : Nat → Nat → Nat; 33 | 34 | symbol Lvl : TYPE; 35 | symbol LvlSet : TYPE; 36 | 37 | symbol Max : Nat → LvlSet → Lvl; 38 | symbol Plus : Nat → Lvl → LvlSet; 39 | symbol mapPlus : Nat → LvlSet → LvlSet; 40 | 41 | associative commutative symbol Union : LvlSet → LvlSet → LvlSet; 42 | 43 | rule Max $i (Union (Plus $j (Max $k $l)) $tl) ↪ Max (plus_N $i (plus_N $j $k)) (Union (mapPlus $j $l) $tl); 44 | 45 | rule Max $i (Union $tl (Plus $j (Max $k $l))) ↪ Max (plus_N $i (plus_N $j $k)) (Union (mapPlus $j $l) $tl); 46 | 47 | assert a b c d ⊢ Max c (Union (Plus c (Max c b)) d) 48 | ≡ Max (plus_N c (plus_N c c)) (Union (mapPlus c b) d); 49 | -------------------------------------------------------------------------------- /tests/OK/admit.lp: -------------------------------------------------------------------------------- 1 | // Test the addition of axioms in the signature when metavariables remain 2 | 3 | constant symbol Type: TYPE; 4 | injective symbol El: Type → TYPE; 5 | 6 | constant symbol Prop: TYPE; 7 | injective symbol Prf: Prop → TYPE; 8 | 9 | constant symbol prop: Type; 10 | rule El prop ↪ Prop; 11 | 12 | constant symbol ι: Type; 13 | 14 | // A simple independant axiom 15 | symbol prop1: Prop; 16 | symbol f: Prf prop1 → Prop; 17 | symbol π_f: Prf (f _) 18 | begin 19 | admit 20 | // Adds an axiom [ax_?] 21 | end; 22 | 23 | // Two metas, one depending on the other 24 | symbol prop2: Prf prop1 → Prop; 25 | symbol g (π: Prf prop1) (_: Prf (prop2 π)): Prop; 26 | symbol π_g: Prf (g _ _) 27 | begin 28 | // Adds two axioms 29 | admitted; 30 | -------------------------------------------------------------------------------- /tests/OK/andPoly.dk: -------------------------------------------------------------------------------- 1 | Bool : Type. 2 | Nat : Type. 3 | 4 | True : Bool. 5 | False : Bool. 6 | 7 | 0 : Nat. 8 | S : Nat -> Nat. 9 | 10 | def Bool_ : Nat -> Type. 11 | [] Bool_ 0 --> Bool. 12 | [n] Bool_ (S n) --> Bool -> Bool_ n. 13 | 14 | def and : Bool -> Bool -> Bool. 15 | [] and False _ --> False. 16 | [x] and True x --> x. 17 | 18 | def and1_ : n : Nat -> Bool_ n. 19 | [] and1_ 0 --> True. 20 | [x] and1_ (S 0) x --> x. 21 | [x,y,n] and1_ (S (S n)) x y --> and1_ (S n) (and x y). 22 | 23 | (; Ici un and acceptant un nombre variable d'arguments qui type-check bien ;) 24 | def and2_ : n : Nat -> Bool_ n. 25 | [] and2_ 0 --> True. 26 | [] and2_ (S 0) --> x:Bool => x. 27 | [n] and2_ (S (S n)) --> x:Bool => y:Bool => (and2_ (S n) (and x y)). 28 | 29 | def e : n : Nat -> Bool_ n -> Bool_ n. 30 | def andb : n:Nat -> Bool_ n. 31 | [] e 0 (andb 0 ) --> True. 32 | [x] e 0 (andb (S 0) x ) --> x. 33 | [x,y,n] e n (andb (S (S _)) x y) --> andb (S n) (and x y). 34 | (;[x,y,n] e n (andb _ x y) --> andb (S n) (and x y).;) 35 | (;FIXME used to work.;) 36 | -------------------------------------------------------------------------------- /tests/OK/append.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | 3 | constant symbol Nat : TYPE; 4 | constant symbol zero : Nat; 5 | constant symbol succ : Nat → Nat; 6 | 7 | symbol plus : Nat → Nat → Nat; 8 | rule plus zero $m ↪ $m; 9 | rule plus (succ $n) $m ↪ succ (plus $n $m); 10 | 11 | constant symbol Vec : Nat → TYPE; 12 | constant symbol nil : Vec zero; 13 | constant symbol cns : Π (n:Nat), A → Vec n → Vec (succ n); 14 | 15 | symbol append : Π (n:Nat) (m:Nat), Vec n → Vec m → Vec (plus n m); 16 | rule append _ _ nil $l2 ↪ $l2; 17 | rule append _ $m (cns $n $e $l1) $l2 ↪ 18 | cns (plus $n $m) $e (append $n $m $l1 $l2); 19 | -------------------------------------------------------------------------------- /tests/OK/append_legacy.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | Nat: Type. 3 | Z : Nat. 4 | S : Nat -> Nat. 5 | 6 | def plus: Nat -> Nat -> Nat. 7 | [m] plus Z m --> m 8 | [n,m] plus (S n) m --> S (plus n m). 9 | 10 | Listn : Nat -> Type. 11 | nil : Listn Z. 12 | cons : n:Nat -> A -> Listn n -> Listn (S n). 13 | 14 | def append: n:Nat -> Listn n -> m:Nat -> Listn m -> Listn (plus n m). 15 | [l2] append _ nil _ l2 --> l2 16 | [n,l1,m,l2,a] 17 | append _ (cons n a l1) m l2 --> cons (plus n m) a (append n l1 m l2). 18 | -------------------------------------------------------------------------------- /tests/OK/apply.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | constant symbol B : TYPE; 3 | 4 | opaque symbol test1 : (A → B) → A → B 5 | ≔ begin 6 | assume h1 h2; 7 | apply h1; 8 | apply h2 9 | end; 10 | 11 | constant symbol C : TYPE; 12 | 13 | opaque symbol test2 : (A → B → C) → A → B → C 14 | ≔ begin 15 | assume h1 h2 h3; 16 | apply h1 17 | {apply h2} 18 | {apply h3} 19 | end; 20 | -------------------------------------------------------------------------------- /tests/OK/arity_diff.lp: -------------------------------------------------------------------------------- 1 | // Rules with different arities 2 | require open tests.OK.natural; 3 | 4 | symbol id : N → N; 5 | rule id $x ↪ $x; 6 | 7 | symbol add' : N → N → N; 8 | rule add' 0 ↪ id // arity 1 9 | with add' (s $x) $y ↪ $x + $y + 1; // arity 2 10 | 11 | assert ⊢ add' 0 0 ≡ 0; 12 | 13 | symbol g : N → N → N; 14 | symbol f : (N → N → N) → (N → N) → N; 15 | rule f g (g $x) ↪ $x; 16 | 17 | assert ⊢ f g (g 0) ≡ 0; 18 | 19 | -------------------------------------------------------------------------------- /tests/OK/arity_var.lp: -------------------------------------------------------------------------------- 1 | // Test on variable arity 2 | require open tests.OK.natural; 3 | 4 | symbol F : N → TYPE; 5 | rule F 0 ↪ N 6 | with F (s $n) ↪ N → F $n; 7 | 8 | symbol c : Π n, F n; 9 | 10 | constant symbol R : TYPE; 11 | constant symbol r : R; 12 | constant symbol s : R; 13 | 14 | symbol f : N → R; 15 | rule f (c 0) ↪ r 16 | with f (c 1 _) ↪ s; 17 | 18 | assert ⊢ f (c 0) : R; 19 | assert ⊢ f (c 1 2) : R; 20 | -------------------------------------------------------------------------------- /tests/OK/basic.dk: -------------------------------------------------------------------------------- 1 | X : Type. 2 | Y : Type. 3 | 4 | #ASSERT (x:X => x) : x:X -> X. 5 | #ASSERT (x:X => y:Y => x) : X -> Y -> X. 6 | 7 | Nat : Type. 8 | zero : Nat. 9 | succ : Nat -> Nat. 10 | 11 | Vec : Nat -> Type. 12 | nil : Vec zero. 13 | cons : n:Nat -> Nat -> Vec n -> Vec (succ n). 14 | 15 | #INFER nil. 16 | #INFER cons zero. 17 | #INFER cons zero zero nil. 18 | 19 | #ASSERT nil : Vec zero. 20 | #ASSERT cons zero (succ zero) nil : Vec (succ zero). 21 | 22 | def add : Nat -> Nat -> Nat. 23 | [n] add n zero --> n. 24 | [m] add zero m --> m. 25 | [m,n] add (succ n) m --> succ (add n m). 26 | [m,n] add n (succ m) --> succ (add n m). 27 | 28 | #EVAL (x:Nat => x) zero. 29 | #EVAL add zero zero. 30 | #EVAL add (succ (succ zero)) (succ zero). 31 | 32 | def id : (Nat -> Nat) -> Nat -> Nat. 33 | [n] id (x => x) n --> n. 34 | 35 | #EVAL id (y:Nat => y) (succ (succ zero)). 36 | -------------------------------------------------------------------------------- /tests/OK/big_compute.dk: -------------------------------------------------------------------------------- 1 | Nat : Type. 2 | Z : Nat. 3 | S : Nat -> Nat. 4 | 5 | def plus : Nat -> Nat -> Nat. 6 | [x] plus Z x --> x. 7 | [x,y] plus (S x) y --> plus x (S y). 8 | 9 | def mult : Nat -> Nat -> Nat. 10 | [] mult Z _ --> Z. 11 | [x,y] mult (S x) y --> plus y (mult x y). 12 | 13 | def fact : Nat -> Nat. 14 | [] fact Z --> S Z. 15 | [x] fact (S x) --> mult (S x) (fact x). 16 | 17 | def six : Nat. 18 | [] six --> (S (S (S (S (S (S Z)))))). 19 | 20 | def seven : Nat. 21 | [] seven --> (S (S (S (S (S (S (S Z))))))). 22 | 23 | def eight : Nat. 24 | [] eight --> (S (S (S (S (S (S (S (S Z)))))))). 25 | 26 | def 0 : Nat := Z. 27 | def 1 : Nat := S 0. 28 | def 2 : Nat := S 1. 29 | def 3 : Nat := S 2. 30 | def 4 : Nat := S 3. 31 | def 5 : Nat := S 4. 32 | def 6 : Nat := S 5. 33 | def 7 : Nat := S 6. 34 | 35 | #EVAL 0. 36 | #EVAL 1. 37 | #EVAL 2. 38 | #EVAL 3. 39 | #EVAL 4. 40 | #EVAL 5. 41 | #EVAL 6. 42 | #EVAL 7. 43 | 44 | #EVAL (fact 0). 45 | #EVAL (fact 1). 46 | #EVAL (fact 2). 47 | #EVAL (fact 3). 48 | 49 | #EVAL (plus (fact 3) (fact 2)). 50 | #EVAL (plus (fact 2) (fact 3)). 51 | 52 | #ASSERT (plus (fact 5) (fact 4)) == (plus (fact 4) (fact 5)). 53 | #ASSERT (plus (fact seven) (fact six)) == (plus (fact six) (fact seven)). 54 | #ASSERT (plus (fact seven) (fact eight)) == (plus (fact eight) (fact seven)). 55 | -------------------------------------------------------------------------------- /tests/OK/boolean.lp: -------------------------------------------------------------------------------- 1 | // Data type of booleans. 2 | 3 | constant symbol B : TYPE; 4 | 5 | constant symbol true : B; 6 | constant symbol false : B; 7 | 8 | // Boolean negation. 9 | 10 | symbol bool_neg : B → B; 11 | 12 | rule bool_neg true ↪ false 13 | with bool_neg false ↪ true; 14 | 15 | // Boolean disjunction. 16 | 17 | symbol bool_or : B → B → B; 18 | 19 | rule bool_or true _ ↪ true 20 | with bool_or false $b ↪ $b 21 | with bool_or _ true ↪ true 22 | with bool_or $b false ↪ $b; 23 | 24 | // Boolean conjunction. 25 | 26 | symbol bool_and : B → B → B; 27 | 28 | rule bool_and true $b ↪ $b 29 | with bool_and false _ ↪ false 30 | with bool_and $b true ↪ $b 31 | with bool_and _ false ↪ false; 32 | 33 | // More connectives. 34 | 35 | symbol bool_impl a b ≔ 36 | bool_or b (bool_neg a); 37 | 38 | symbol bool_xor a b ≔ 39 | let a_and_not_b ≔ bool_and a (bool_neg b) in 40 | let b_and_not_a ≔ bool_and b (bool_neg a) in 41 | bool_or a_and_not_b b_and_not_a; 42 | -------------------------------------------------------------------------------- /tests/OK/bug.dk: -------------------------------------------------------------------------------- 1 | Nat : Type. 2 | 0 : Nat. 3 | S : Nat -> Nat. 4 | 5 | def S_bis : Nat -> Nat. 6 | [] S_bis 0 --> S (S 0). 7 | [] S_bis (S 0) --> S (S 0). 8 | [n] S_bis (S (S n)) --> S (S (S_bis n)). 9 | 10 | def 1 := S 0. 11 | def 2 := S 1. 12 | def 3 := S 2. 13 | 14 | #EVAL S_bis 0. 15 | #EVAL S_bis 1. 16 | #EVAL S_bis 2. 17 | #EVAL S_bis 3. 18 | 19 | #ASSERT S_bis 0 == S_bis 1. 20 | #ASSERT S_bis 2 == S_bis 3. 21 | -------------------------------------------------------------------------------- /tests/OK/bug0.dk: -------------------------------------------------------------------------------- 1 | def A : Type. 2 | def eA : A -> Type. 3 | a : A. 4 | [] A --> eA a. 5 | 6 | B : Type. 7 | def eB : B -> Type. 8 | 9 | (; a has type (eA a) ;) 10 | (; eB has type (B -> Type) ;) 11 | #INFER a. 12 | #INFER eB. 13 | 14 | (; There is no reason for (eA a) and B to be convertible ;) 15 | (; and yet dedukti successfully typechecks the following rule. ;) 16 | [] eB a --> eA a. 17 | -------------------------------------------------------------------------------- /tests/OK/builtin_succ_zero.lp: -------------------------------------------------------------------------------- 1 | symbol N:TYPE; 2 | symbol z:N; 3 | symbol s:N → N; 4 | builtin "+1" ≔ s; 5 | builtin "0" ≔ z; 6 | -------------------------------------------------------------------------------- /tests/OK/check.dk: -------------------------------------------------------------------------------- 1 | N : Type. 2 | 0 : N. 3 | S : N -> N. 4 | 5 | #ASSERT 0 : N. 6 | #ASSERTNOT S : N. 7 | -------------------------------------------------------------------------------- /tests/OK/church.dk: -------------------------------------------------------------------------------- 1 | typ : Type. 2 | arr : typ -> typ -> typ. 3 | def e : typ -> Type. 4 | [a,b] e (arr a b) --> e a -> e b. 5 | 6 | N : typ. 7 | z : e N. 8 | s : e N -> e N. 9 | 10 | def numeral : Type := A : typ -> (e A -> e A) -> (e A -> e A). 11 | 12 | def zero : numeral := A : typ => f : (e A -> e A) => x : e A => x. 13 | def one : numeral := A : typ => f : (e A -> e A) => f. 14 | def two : numeral := A : typ => f : (e A -> e A) => x : e A => f (f x). 15 | def three : numeral := A : typ => f : (e A -> e A) => x : e A => f (f (f x)). 16 | 17 | def plus : numeral -> numeral -> numeral 18 | := m : numeral => n : numeral => A : typ => f : (e A -> e A) => x : e A => m A f (n A f x). 19 | 20 | def times : numeral -> numeral -> numeral 21 | := m : numeral => n : numeral => A : typ => f : (e A -> e A) => x : e A => m A (n A f) x. 22 | 23 | def power : numeral -> numeral -> numeral 24 | := m : numeral => n : numeral => A : typ => n (arr A A) (m A). 25 | 26 | def four : numeral := plus two two. 27 | def five : numeral := plus two three. 28 | 29 | #ASSERT power two (times four five) == power two (times five four). 30 | -------------------------------------------------------------------------------- /tests/OK/comment_in_qid.lp: -------------------------------------------------------------------------------- 1 | require tests.OK.boolean; 2 | assert ⊢ tests./*comment*/OK.boolean.true : tests.OK.boolean.B; 3 | symbol A:TYPE; 4 | symbol /:A → A → A; 5 | symbol *:A → A → A; 6 | -------------------------------------------------------------------------------- /tests/OK/compute.lp: -------------------------------------------------------------------------------- 1 | symbol N : TYPE; 2 | symbol z : N; 3 | symbol s : N → N; 4 | symbol add : N → N → N; 5 | rule add z $x ↪ $x 6 | with add (s $x) $y ↪ add $x (s $y); 7 | symbol one ≔ s z; 8 | symbol two ≔ s one; 9 | compute add two two; 10 | -------------------------------------------------------------------------------- /tests/OK/compute_legacy.dk: -------------------------------------------------------------------------------- 1 | (; Computational test. ;) 2 | Nat : Type. 3 | Z : Nat. 4 | S : Nat -> Nat. 5 | 6 | def plus : Nat -> Nat -> Nat. 7 | [x] plus Z x --> x 8 | [x,y] plus (S x) y --> plus x (S y). 9 | 10 | def mult : Nat -> Nat -> Nat. 11 | [] mult Z _ --> Z 12 | [x,y] mult (S x) y --> plus y (mult x y). 13 | 14 | def fact : Nat -> Nat. 15 | [] fact Z --> S Z 16 | [x] fact (S x) --> mult (S x) (fact x). 17 | 18 | def one : Nat := (S Z). 19 | def two : Nat := (S one). 20 | def three : Nat := (S two). 21 | def four : Nat := (S three). 22 | def five : Nat := (S four). 23 | def six : Nat := (S five). 24 | def seven : Nat := (S six). 25 | 26 | #ASSERT plus (fact seven) (fact six) == plus (fact six) (fact seven). 27 | -------------------------------------------------------------------------------- /tests/OK/cp0.lp: -------------------------------------------------------------------------------- 1 | // test computation of critical pairs 2 | 3 | symbol A:TYPE; 4 | 5 | constant symbol z:A; 6 | constant symbol s:A → A; 7 | symbol a:A → A → A; 8 | 9 | rule a z $x ↪ $x 10 | with a (s $x) $y ↪ s (a $x $y); 11 | -------------------------------------------------------------------------------- /tests/OK/cp1.lp: -------------------------------------------------------------------------------- 1 | // test computation of critical pairs 2 | 3 | require open tests.OK.cp0; 4 | 5 | rule a (a $x $y) $z ↪ a $x (a $y $z); 6 | // generates 3 joinable critical pairs 7 | -------------------------------------------------------------------------------- /tests/OK/cp2.lp: -------------------------------------------------------------------------------- 1 | // test computation of critical pairs 2 | 3 | require open tests.OK.cp0; 4 | 5 | rule a $x (a $y $z) ↪ a (a $x $y) $z; 6 | // generates 5 critical pairs, 2 of which are not joinable 7 | -------------------------------------------------------------------------------- /tests/OK/cp3.lp: -------------------------------------------------------------------------------- 1 | // test local confluence of group theory 2 | 3 | symbol G:TYPE; 4 | 5 | symbol *:G → G → G; notation * infix 10; 6 | symbol e:G; 7 | symbol inv:G → G; 8 | 9 | rule ($x * $y) * $z ↪ $x * ($y * $z) 10 | 11 | with $x * e ↪ $x 12 | with e * $x ↪ $x 13 | 14 | with inv $x * $x ↪ e 15 | with $x * inv $x ↪ e 16 | 17 | with inv $x * ($x * $y) ↪ $y 18 | with $x * (inv $x * $y) ↪ $y 19 | 20 | with inv e ↪ e 21 | with inv (inv $x) ↪ $x 22 | with inv ($x * $y) ↪ inv $y * inv $x; 23 | -------------------------------------------------------------------------------- /tests/OK/cr_qu.lp: -------------------------------------------------------------------------------- 1 | // confluent system 2 | constant symbol A:TYPE; 3 | symbol ? : A → A → A; notation ? infix 10; 4 | rule $x ? $x ↪ $x 5 | with ($u ? _) ? (_ ? $y) ↪ $u ? $y 6 | with $v ? (_ ? $y) ↪ $v ? $y 7 | with ($u ? _) ? $y ↪ $u ? $y; 8 | -------------------------------------------------------------------------------- /tests/OK/declared.lp: -------------------------------------------------------------------------------- 1 | symbol ℕ : TYPE; 2 | 3 | symbol fst : ℕ → ℕ → ℕ ≔ λ n₁ n₂, n₁; 4 | symbol snd : ℕ → ℕ → ℕ ≔ λ n₁ n₂, n₂; 5 | -------------------------------------------------------------------------------- /tests/OK/doc.lp: -------------------------------------------------------------------------------- 1 | symbol N:TYPE; 2 | 3 | // with no proof script 4 | symbol add : N → N → N; // a type but no definition (axiom) 5 | symbol double n ≔ add n n; // no type but a definition 6 | symbol triple n : N ≔ add n (double n); // a type and a definition 7 | 8 | // with a proof script (theorem or interactive definition) 9 | symbol F : N → TYPE; 10 | symbol idF n : F n → F n ≔ 11 | begin 12 | assume n x; 13 | apply x 14 | end; 15 | -------------------------------------------------------------------------------- /tests/OK/domainfree.dk: -------------------------------------------------------------------------------- 1 | A:Type. 2 | F:(A->A)->A. 3 | def f := F (x=>x). 4 | -------------------------------------------------------------------------------- /tests/OK/dotpat.dk: -------------------------------------------------------------------------------- 1 | N: Type. 2 | Z: N. 3 | S: N->N. 4 | 5 | def plus: N->N->N. 6 | [y] plus Z y --> y 7 | [x,y] plus (S x) y --> S (plus x y). 8 | 9 | 10 | V: N->Type. 11 | Nil: V Z. 12 | Con: n:N -> V n -> N -> V (S n). 13 | 14 | def hd: n:N -> V (S n) -> N. 15 | 16 | [m] hd _ (Con _ _ m) --> m. 17 | 18 | 19 | def app: n:N -> m:N -> V n -> V m -> V (plus n m). 20 | [y] app _ _ Nil y --> y 21 | [n,m,x,y,k] app _ m (Con n x k) y --> Con (plus n m) (app n m x y) k. 22 | -------------------------------------------------------------------------------- /tests/OK/dummy1.dk: -------------------------------------------------------------------------------- 1 | N : Type. 2 | z : N. 3 | s : N -> N. 4 | 5 | def plus : N -> N -> N. 6 | 7 | [n] plus z n --> n. 8 | -------------------------------------------------------------------------------- /tests/OK/empty.lp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Deducteam/lambdapi/3f6c848cffce384300bf2fd0745099a3c7303594/tests/OK/empty.lp -------------------------------------------------------------------------------- /tests/OK/emptySet.dk: -------------------------------------------------------------------------------- 1 | Set:Type. 2 | Prop:Type. 3 | 4 | def prf:Prop->Type. 5 | 6 | forall:(Set->Prop)->Prop. 7 | imp:Prop->Prop->Prop. 8 | [f] prf (forall f) --> x:Set -> prf (f x) 9 | 10 | [A,B] prf (imp A B) --> prf A -> prf B. 11 | 12 | False:Prop. 13 | def not (A:Prop) := imp A False. 14 | 15 | in : Set -> Set -> Prop. 16 | empty : Set. 17 | empty_ax : prf( forall ( x:Set => not (in x empty) ) ). 18 | 19 | leq : Set -> Set -> Prop. 20 | min: Set -> Set -> Prop. 21 | min_ax1 : prf ( 22 | forall (S:Set => 23 | forall (x:Set => 24 | forall (y:Set => 25 | imp (min x S) ( imp (in y S) (leq x y) ) 26 | ))) ). 27 | 28 | min_ax2 : prf ( 29 | forall (S:Set => 30 | forall (x:Set => 31 | imp (min x S) (in x S) 32 | )) ). 33 | 34 | def stmt := forall (x => not (min x empty)). 35 | 36 | def theorem: prf stmt := (x => p => (empty_ax x) (min_ax2 empty x p)). 37 | 38 | 39 | -------------------------------------------------------------------------------- /tests/OK/escape_path.lp: -------------------------------------------------------------------------------- 1 | // test escaped identifiers in paths 2 | require open {|tests|}.OK.{|a b|}.{|escape file|}; 3 | assert ⊢ {|tests|}.OK.{|a b|}.{|escape file|}.A 4 | ≡ tests.OK.{|a b|}.{|escape file|}.A; 5 | -------------------------------------------------------------------------------- /tests/OK/eta_equality.lp: -------------------------------------------------------------------------------- 1 | flag "eta_equality" on; 2 | 3 | constant symbol Type : TYPE; 4 | constant symbol f : Type → Type; 5 | constant symbol g : (Type → Type) → Type; 6 | assert ⊢ g (λ x, f x) ≡ g f; 7 | assert ⊢ (λ x, f x) ≡ f; 8 | assert ⊢ f ≡ (λ x, f x); 9 | -------------------------------------------------------------------------------- /tests/OK/file.with.dot.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | -------------------------------------------------------------------------------- /tests/OK/foo.lp: -------------------------------------------------------------------------------- 1 | constant symbol B : TYPE; 2 | 3 | constant symbol true : B; 4 | constant symbol false : B; 5 | 6 | symbol neg : B → B; 7 | 8 | rule neg true ↪ false; 9 | rule neg false ↪ true; 10 | 11 | constant symbol Prop : TYPE; 12 | 13 | injective symbol P : Prop → TYPE; 14 | 15 | constant symbol eq : B → B → Prop; 16 | constant symbol refl b : P (eq b b); 17 | 18 | constant symbol case (p : B → Prop) : P (p true) → P (p false) → Π b, P b; 19 | 20 | opaque symbol notK : Π b, P (eq (neg (neg b)) b) 21 | ≔ begin 22 | assume b; 23 | apply case (λ b, eq (neg (neg b)) b) 24 | {apply refl} 25 | {apply refl} 26 | end; 27 | -------------------------------------------------------------------------------- /tests/OK/for_inductive.lp: -------------------------------------------------------------------------------- 1 | constant symbol Prop : TYPE; // Type of propositions 2 | builtin "Prop" ≔ Prop; 3 | 4 | injective symbol π : Prop → TYPE; // Interpretation of propositions in TYPE 5 | builtin "P" ≔ π; 6 | 7 | constant symbol Set : TYPE; // Type of set codes 8 | injective symbol τ : Set → TYPE; // Interpretation of set codes in TYPE 9 | -------------------------------------------------------------------------------- /tests/OK/freevars-constraints.lp: -------------------------------------------------------------------------------- 1 | // Check correctness regarding free variables constraints 2 | symbol R : TYPE; 3 | symbol zr : R; 4 | 5 | symbol d : (R → R) → (R → R); 6 | 7 | symbol ch : R → R; 8 | symbol dx : (R → R → R) → (R → R → R); 9 | rule dx (λ x y, $F.[x]) ↪ λ (x y:R) , d (λ (x':R), $F.[x']) x 10 | with dx (λ x y, $F.[y]) ↪ λ (x y:R) , zr; 11 | 12 | assert ⊢ dx (λ x y, ch x) ≡ (λ (x' y:R) , d (λ x, ch x) x'); 13 | assert ⊢ dx (λ x y, ch y) ≡ λ (x y:R) , zr; 14 | 15 | -------------------------------------------------------------------------------- /tests/OK/gaspard.dk: -------------------------------------------------------------------------------- 1 | U : Type. 2 | foo : U. 3 | e : U -> Type. 4 | c : x : U -> e x. 5 | 6 | def aux : (x : U -> e x) -> U. 7 | 8 | (; The LHS is not typable. ;) 9 | [] aux (x => c _) --> foo. 10 | -------------------------------------------------------------------------------- /tests/OK/generalize.lp: -------------------------------------------------------------------------------- 1 | // test tactic generalize 2 | 3 | symbol A:TYPE; 4 | symbol B:A → TYPE; 5 | symbol C:Π x, B x → TYPE; 6 | symbol D:Π x, Π y, C x y → TYPE; 7 | symbol h x y z : D x y z; 8 | 9 | opaque symbol lem x y z: D x y z ≔ 10 | begin 11 | assume x y z; 12 | generalize y; 13 | assume y z; 14 | apply h x y z 15 | end; 16 | -------------------------------------------------------------------------------- /tests/OK/group.lp: -------------------------------------------------------------------------------- 1 | // decision procedure for group theory 2 | symbol G : TYPE; 3 | symbol e : G; 4 | symbol ⋅ : G → G → G; 5 | notation ⋅ infix 10; 6 | symbol inv : G → G; 7 | rule ($x ⋅ $y) ⋅ $z ↪ $x ⋅ ($y ⋅ $z) 8 | with e ⋅ $x ↪ $x 9 | with $x ⋅ e ↪ $x 10 | with inv $x ⋅ $x ↪ e 11 | with $x ⋅ inv $x ↪ e 12 | with inv $x ⋅ ($x ⋅ $y) ↪ $y 13 | with $x ⋅ (inv $x ⋅ $y) ↪ $y 14 | with inv e ↪ e 15 | with inv (inv $x) ↪ $x 16 | with inv ($x ⋅ $y) ↪ inv $y ⋅ inv $x; 17 | -------------------------------------------------------------------------------- /tests/OK/half.dk: -------------------------------------------------------------------------------- 1 | Nat : Type. 2 | 3 | 0 : Nat. 4 | S : Nat -> Nat. 5 | 6 | def half : Nat -> Nat. 7 | 8 | [] half 0 --> 0. 9 | [] half (S 0) --> 0. 10 | [n] half (S (S n)) --> half n. 11 | 12 | #ASSERT half 0 == half (S 0). 13 | -------------------------------------------------------------------------------- /tests/OK/have.lp: -------------------------------------------------------------------------------- 1 | // test tactic have 2 | 3 | symbol A:TYPE; 4 | symbol B:TYPE; 5 | symbol b:B; 6 | symbol h:B → A; 7 | 8 | opaque symbol lem:A ≔ 9 | begin 10 | have x:B {apply b}; 11 | apply h; 12 | apply x 13 | end; 14 | -------------------------------------------------------------------------------- /tests/OK/ho_bug1.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | 3 | def e0 : A -> A. 4 | 5 | i1 : (A -> A) -> A. 6 | def e1 : A -> A -> A. 7 | 8 | i2 : (A -> A) -> A. 9 | def e2 : A -> A -> A. 10 | 11 | def e3 : A -> A. 12 | 13 | [a] e0 (e1 _ a) --> a. 14 | [a,b] e1 (i1 a) b --> a b. 15 | [a,b] e2 (e0 a) b --> e0 a 16 | [a,b] e2 (i2 a) b --> a b. 17 | [b] e3 (i1 (a => e1 a b)) --> b. 18 | 19 | b : A. 20 | 21 | def f (x : A -> A -> A) := i2 (a => e3 (i1 (x a))). 22 | 23 | def pr1 (a : A) (c : A) := 24 | e1 25 | (i1 26 | (g => 27 | e1 28 | g 29 | (i2 30 | (__ => 31 | e0 32 | (e1 33 | (i1 34 | (d => 35 | e1 g 36 | (i2 (__ => d)))) b))))) 37 | (i1 38 | (e => e1 c (e2 e a))). 39 | 40 | (; pr2 is the normal form of pr1. ;) 41 | def pr2 (__ : A) (c : A) := e1 c b. 42 | 43 | #ASSERT pr1 == pr2. (; Answer must be YES ;) 44 | #ASSERT f pr1 == f pr2. (; Answer must be YES ;) 45 | -------------------------------------------------------------------------------- /tests/OK/ho_bug2.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | 3 | def F : (A -> A) -> A -> A. 4 | 5 | a : A. 6 | [f] F (x => f x) _ --> a. 7 | 8 | g : A -> A. 9 | def test (b : A) := F (x => g x) b. 10 | 11 | #EVAL test. 12 | #ASSERT test == b : A => a. (; Answer must be YES ;) 13 | -------------------------------------------------------------------------------- /tests/OK/hott.dk: -------------------------------------------------------------------------------- 1 | Nat: Type. 2 | Fin : Nat -> Type. 3 | 4 | type:Type. 5 | e: type -> Type. 6 | 7 | 8 | def Finm: Nat -> Nat -> Type 9 | := i:Nat => j:Nat => (Fin i -> Fin j). 10 | 11 | def comp := i:Nat => j:Nat => k:Nat => f:Finm i j => g:Finm j k => x:Fin i => g (f x). 12 | 13 | Sn1: Type. 14 | Bn: Sn1 -> Nat -> Type. 15 | def mapBn: Ln1:Sn1 -> i:Nat -> ip:Nat -> Finm i ip -> Bn Ln1 ip -> Bn Ln1 i. 16 | 17 | [Ln1,i,j,k,f,g,p] 18 | mapBn Ln1 i j f (mapBn _ _ k g p) --> mapBn Ln1 i k (comp i j k f g) p. 19 | 20 | n:Nat. 21 | 22 | Sn: Type. 23 | Ln1: Sn -> Sn1. 24 | Xn : Ln:Sn -> Bn (Ln1 Ln) n -> Type. 25 | 26 | Bsn: Sn -> Nat -> Type. 27 | def bn : Ln:Sn -> i:Nat -> Bsn Ln i -> Bn (Ln1 Ln) i. 28 | def bsn: Ln:Sn -> i:Nat -> p:Bsn Ln i -> f:Finm n i -> Xn Ln (mapBn (Ln1 Ln) n i f (bn Ln i p)). 29 | mkBsn: Ln:Sn -> i:Nat -> bn:Bn (Ln1 Ln) i 30 | -> bsn:(f:Finm n i -> Xn Ln (mapBn (Ln1 Ln) n i f bn)) -> Bsn Ln i. 31 | 32 | [bn2] bn _ _ (mkBsn _ _ bn2 _) --> bn2. 33 | 34 | [bsn2] bsn _ _ (mkBsn _ _ _ bsn2) --> bsn2. 35 | -------------------------------------------------------------------------------- /tests/OK/identifiers.lp: -------------------------------------------------------------------------------- 1 | symbol /:TYPE; 2 | symbol *:TYPE; 3 | symbol **:TYPE; 4 | -------------------------------------------------------------------------------- /tests/OK/implicitArgs1.lp: -------------------------------------------------------------------------------- 1 | constant symbol U : TYPE; 2 | 3 | // Mini nat 4 | constant symbol Nat : U; 5 | constant symbol N : TYPE; 6 | 7 | // Mini interpretation function 8 | injective symbol T : U → TYPE; 9 | rule T Nat ↪ N; 10 | 11 | constant symbol zero : T Nat; 12 | constant symbol s : N → N; 13 | 14 | 15 | 16 | // Mini polymorphic lists 17 | constant symbol List : U → U; 18 | 19 | constant symbol nil : Π[Typ:U], T(List Typ); 20 | // A version in full, without implicit arguments 21 | constant symbol nilF : Π(Typ:U), T(List Typ); 22 | 23 | constant symbol cons : Π[Typ:U], T Typ → T (List Typ) → T (List Typ); 24 | // A version in full, without implicit arguments 25 | constant symbol consF : Π(Typ:U), T Typ → T (List Typ) → T (List Typ); 26 | 27 | 28 | symbol l1F ≔ consF Nat zero (nilF Nat); 29 | 30 | // We would like to do : 31 | // symbol l1 ≔ cons zero nil 32 | 33 | // But it won't work for now because we need to find a Typ:U such that 34 | // T Typ = Tgiven 35 | // where Tgiven here is N 36 | // Obviously, we know that T Nat = N, but we don't have yet implemented a way to reverse the 37 | // rewrite rules for T (hoping that T really is injective, otherwise obviously we'll have to make a choice). 38 | // We will need to implement that to make implicit arguments useful for polymorphic symbols, 39 | // but it's beyong the usage of implicit arguments for now 40 | -------------------------------------------------------------------------------- /tests/OK/implicitArgs2.lp: -------------------------------------------------------------------------------- 1 | constant symbol U : TYPE; 2 | 3 | // Mini nat 4 | constant symbol Nat : U; 5 | constant symbol N : TYPE; 6 | 7 | // Mini interpretation function 8 | injective symbol T : U → TYPE; 9 | rule T Nat ↪ N; 10 | 11 | constant symbol zero : T Nat; 12 | constant symbol s : N → N; 13 | 14 | 15 | constant symbol id : Π[Typ:U], T Typ → T Typ; 16 | // A version in full, without implicit arguments 17 | constant symbol idF : Π(Typ:U), T Typ → T Typ; 18 | 19 | // We would like to do : 20 | // symbol zero2 ≔ id zero 21 | 22 | // But it won't work for now because we need to find a Typ:U such that 23 | // T Typ = Tgiven 24 | // where Tgiven here is N 25 | // Obviously, we know that T Nat = N, but we don't have yet implemented a way to reverse the 26 | // rewrite rules for T (hoping that T really is injective, otherwise obviously we'll have to make a choice). 27 | // We will need to implement that to make implicit arguments useful for polymorphic symbols, 28 | // but it's beyong the usage of implicit arguments for now 29 | 30 | // Question : 31 | // Why is it also failing to work if we declare zero to live in (T Nat) instead of N ? 32 | // Perhaps the unification can't even deal with (T x = T y). If that's the case then first we need to improve the 33 | // unification to make this work 34 | -------------------------------------------------------------------------------- /tests/OK/implicitArgs4.lp: -------------------------------------------------------------------------------- 1 | constant symbol U : TYPE; 2 | // Mini interpretation function from code of types to real types 3 | injective symbol T : U → TYPE; 4 | 5 | symbol RodolpheExample (A:U) (B:U) (C:U) (D:U) : T A → T B → T C → (T A → T B → T C → T D) → T D ≔ 6 | λ(x : T A) (y : T B) (z : T C) (f : Π(m:T A)(n:T B)(k:T C), T D), f x y z; 7 | -------------------------------------------------------------------------------- /tests/OK/indrec.lp: -------------------------------------------------------------------------------- 1 | // example of inductive-recursive type definition 2 | 3 | // assumptions 4 | 5 | constant symbol Prop : TYPE; 6 | builtin "Prop" ≔ Prop; 7 | 8 | injective symbol π : Prop → TYPE; 9 | builtin "P" ≔ π; 10 | 11 | constant symbol ⊤ : Prop; 12 | constant symbol top : π ⊤; 13 | 14 | constant symbol ∧ : Prop → Prop → Prop; notation ∧ infix right 10; 15 | constant symbol ∧ᵢ p q : π p → π q → π(p ∧ q); 16 | 17 | constant symbol ℕ : TYPE; 18 | 19 | symbol ≠ : ℕ → ℕ → Prop; notation ≠ infix 20; 20 | 21 | // lists without duplicated elements 22 | 23 | constant symbol L : TYPE; 24 | 25 | symbol ∉ : ℕ → L → Prop; notation ∉ infix 20; 26 | 27 | constant symbol nil : L; 28 | constant symbol cons x l : π(x ∉ l) → L; 29 | 30 | rule _ ∉ nil ↪ ⊤ 31 | with $x ∉ cons $y $l _ ↪ $x ≠ $y ∧ $x ∉ $l; 32 | 33 | symbol ind_L p : π(p nil) → (Π x l, π(p l) → Π h, π(p (cons x l h))) 34 | → Π l, π(p l); 35 | 36 | rule ind_L _ $a _ nil ↪ $a 37 | with ind_L $p $a $b (cons $x $l $h) ↪ $b $x $l (ind_L $p $a $b $l) $h; 38 | 39 | /* syntax ? 40 | 41 | inductive L : TYPE ≔ 42 | | nil : L 43 | | cons x l : π(x ∉ l) → L 44 | with infix 20 symbol ∉ : ℕ → L → Prop 45 | with _ ∉ nil ↪ ⊤ 46 | with $x ∉ cons $y $l _ ↪ $x ≠ $y ∧ $x ∉ $l; 47 | */ 48 | -------------------------------------------------------------------------------- /tests/OK/infer.lp: -------------------------------------------------------------------------------- 1 | // test type inference in the case of an application (t u) 2 | // where the type of t is not a product (yet) 3 | 4 | constant symbol Prop : TYPE; 5 | injective symbol π : Prop → TYPE; 6 | 7 | constant symbol ∧ : Prop → Prop → Prop; 8 | notation ∧ infix left 5; 9 | rule π ($A ∧ $B) ↪ Π P, (π $A → π $B → π P) → π P; 10 | 11 | constant symbol and_i A B : π A → π B → π (A ∧ B); 12 | constant symbol and_eg A B : π (A ∧ B) → π A; 13 | constant symbol and_ed A B : π (A ∧ B) → π B; 14 | 15 | constant symbol ⇒ : Prop → Prop → Prop; 16 | notation ⇒ infix right 6; 17 | rule π ($A ⇒ $B) ↪ π $A → π $B; 18 | 19 | constant symbol imp_e A B : π (A ⇒ B) → π A → π B; 20 | 21 | symbol P : Prop; 22 | symbol R : Prop; 23 | 24 | type λ H: π((P ⇒ R) ∧ (R ⇒ P)), λ Hr: π R, and_ed _ _ H Hr; 25 | -------------------------------------------------------------------------------- /tests/OK/infix.lp: -------------------------------------------------------------------------------- 1 | symbol N : TYPE; 2 | symbol z : N; 3 | symbol s : N → N; 4 | 5 | symbol + : N → N → N; 6 | notation + infix left 5; 7 | assert ⊢ z + z + z ≡ (z + z) + z; 8 | assert ⊢ z + s z ≡ z + (s z); 9 | assertnot ⊢ z + z + z ≡ z + (z + z); 10 | 11 | symbol × : N → N → N; 12 | notation × infix right 6; 13 | assertnot ⊢ z × z × z ≡ (z × z) × z; 14 | assert ⊢ z × z × z ≡ z × (z × z); 15 | -------------------------------------------------------------------------------- /tests/OK/inj.dk: -------------------------------------------------------------------------------- 1 | type : Type. 2 | 3 | injective eta : type -> Type. 4 | 5 | arr : type -> type -> type. 6 | 7 | [A,B] eta (arr A B) --> eta A -> eta B. 8 | 9 | lam : A : type -> B : type -> (eta A -> eta B) -> eta (arr A B). 10 | 11 | def app : A : type -> B : type -> eta (arr A B) -> eta A -> eta B. 12 | 13 | def get_context : A : type -> B : type -> eta A -> eta A -> eta B -> eta A. 14 | 15 | [A,AB,C,f,a,f',z] get_context _ C (app A AB f a) (app _ _ f' a) z --> 16 | (app A AB (get_context (arr A AB) C f f' z) a). 17 | -------------------------------------------------------------------------------- /tests/OK/let.lp: -------------------------------------------------------------------------------- 1 | // Let syntax 2 | constant symbol T : TYPE; 3 | constant symbol a : T; 4 | 5 | // Simple 6 | type let x ≔ a in x; 7 | 8 | // Nested 9 | type let x ≔ a in let y ≔ a in λ _, y; 10 | assert ⊢ let x ≔ a in let y ≔ a in λ _, y ≡ λ _, a; 11 | 12 | // With arguments 13 | type let f x ≔ x in f a; 14 | assert ⊢ let f x ≔ x in f a ≡ a; 15 | 16 | // In rewrite rules 17 | symbol f : T → T; 18 | rule f _ ↪ let x ≔ a in x; 19 | assert ⊢ f a ≡ a; 20 | 21 | // With type annotated arguments 22 | flag "print_domains" on; 23 | compute let x : T ≔ a in x; 24 | // Type annotation on products 25 | type let f x : T ≔ a in f; 26 | type let f (x : T) ≔ λ _, x in f a; 27 | assert ⊢ let f (x:T) : T → T ≔ λ(_:T), x in f a ≡ λ(_:T), a; 28 | // dependent type let 29 | symbol Dt : T → TYPE; 30 | symbol dt x : Dt x; 31 | type let f x : Dt x ≔ dt x in f; 32 | -------------------------------------------------------------------------------- /tests/OK/lpparse.lp: -------------------------------------------------------------------------------- 1 | symbol A : TYPE; 2 | symbol a: A; 3 | symbol f: A → A; 4 | 5 | symbol g: Π(x:A), A; 6 | 7 | symbol id : A → A ≔ λ(x: A), x; 8 | symbol id2 (x: A) ≔ x; 9 | 10 | rule g $x ↪ f $x; 11 | 12 | // A one line comment 13 | 14 | /* A multiline 15 | comment */ 16 | 17 | symbol B: TYPE; 18 | symbol b: B; 19 | symbol mob: B → B → A; 20 | notation mob infix left 6; 21 | type b mob b; 22 | assert ⊢ b mob b: A; 23 | -------------------------------------------------------------------------------- /tests/OK/lpparse2.lp: -------------------------------------------------------------------------------- 1 | require tests.OK.lpparse; 2 | open tests.OK.lpparse; 3 | 4 | symbol f2: A → A; 5 | -------------------------------------------------------------------------------- /tests/OK/max-suc-alg.lp: -------------------------------------------------------------------------------- 1 | // universe levels as in Agda syntax 2 | constant symbol L : TYPE; 3 | symbol Z : L; 4 | symbol S : L → L; 5 | symbol ∪ : L → L → L; notation ∪ infix right 10; 6 | symbol V : L → L; // to mark universe level variables 7 | 8 | // natural numbers 9 | constant symbol ℕ : TYPE; 10 | constant symbol Oₙ : ℕ; 11 | constant symbol sₙ : ℕ → ℕ; 12 | 13 | // max function on natural numbers 14 | symbol ⊕ₙ : ℕ → ℕ → ℕ; notation ⊕ₙ infix right 10; 15 | 16 | rule Oₙ ⊕ₙ $y ↪ $y 17 | with $x ⊕ₙ Oₙ ↪ $x 18 | with sₙ $x ⊕ₙ sₙ $y ↪ sₙ ($x ⊕ₙ $y); 19 | 20 | // addition on natural numbers 21 | symbol + : ℕ → ℕ → ℕ; notation + infix right 5; 22 | 23 | rule Oₙ + $y ↪ $y 24 | with $x + Oₙ ↪ $x 25 | with sₙ $x + $y ↪ sₙ ($x + $y) 26 | with $x + sₙ $y ↪ sₙ ($x + $y) 27 | with ($x + $y) + $z ↪ $x + ($y + $z); 28 | 29 | // s-max algebra: successor iterator and max operator on levels 30 | constant symbol z : L; 31 | symbol s : ℕ → L → L; 32 | associative commutative symbol ⊕ : L → L → L; // associative right by default 33 | notation ⊕ infix right 10; 34 | 35 | // Translation of Agda's levels to the s-max algebra 36 | rule Z ↪ s Oₙ z 37 | with S $x ↪ s (sₙ Oₙ) $x 38 | with $x ∪ $y ↪ $x ⊕ $y 39 | with V $x ↪ s Oₙ ($x ⊕ z); 40 | 41 | // rules for deciding the s-max algebra 42 | rule s $p (s $q $x) ↪ s ($p + $q) $x 43 | with s $p ($x ⊕ $y) ↪ s $p $x ⊕ s $p $y; 44 | 45 | rule s $p $x ⊕ s $q $x ↪ s ($p ⊕ₙ $q) $x 46 | with s $p $x ⊕ (s $q $x ⊕ $y) ↪ s ($p ⊕ₙ $q) $x ⊕ $y; 47 | 48 | // tests 49 | assert x y ⊢ ((S (S (V x))) ∪ (S (V y))) ∪ Z ≡ s (sₙ Oₙ) y ⊕ (s (sₙ(sₙ Oₙ)) x ⊕ s (sₙ(sₙ Oₙ)) z); 50 | assert a ⊢ s (sₙ Oₙ) (a ⊕ z) ⊕ s (sₙ(sₙ Oₙ)) (a ⊕ z) ≡ s (sₙ(sₙ Oₙ)) a ⊕ s (sₙ(sₙ Oₙ)) z; 51 | -------------------------------------------------------------------------------- /tests/OK/michael.lp: -------------------------------------------------------------------------------- 1 | constant symbol Type : TYPE; 2 | injective symbol eta : Type → TYPE; 3 | 4 | // function type 5 | constant symbol > : Type → Type → Type; 6 | notation > infix right 6; 7 | rule eta ($a > $b) ↪ eta $a → eta $b; 8 | 9 | constant symbol i : Type; 10 | constant symbol o : Type; 11 | 12 | symbol eps : eta o → TYPE; 13 | 14 | constant symbol --> : eta (o > o > o); 15 | notation --> infix right 6; 16 | rule eps ($a --> $b) ↪ eps $a → eps $b; 17 | 18 | constant symbol all : Π [A : Type], eta ((A > o) > o); 19 | rule eps (@all $a $b) ↪ Π (x : eta $a), eps ($b x); 20 | 21 | symbol false : eta o ≔ all (λ p, p); 22 | 23 | symbol ~ : eta (o > o) ≔ λ p, p --> false; 24 | notation ~ prefix 40; 25 | 26 | // these expressions typecheck 27 | type λ p, ~ p; 28 | type λ p, ~ (~ p); 29 | type λ p x, ~ (p x); 30 | 31 | // these expressions also typecheck. 32 | type λ p, ~ ~ p; 33 | type λ p x, ~ p x; 34 | -------------------------------------------------------------------------------- /tests/OK/miller.dk: -------------------------------------------------------------------------------- 1 | R : Type. 2 | 0 : R. 3 | 4 | sh : R -> R. 5 | ch : R -> R. 6 | def d : (R -> R) -> (R -> R). 7 | [] d sh --> ch. 8 | [] d ch --> sh. 9 | [] d (x => sh x) --> ch. 10 | [] d (x => ch x) --> sh. 11 | 12 | R2 : Type. 13 | pair : R -> R -> R2. 14 | 15 | def dx : (R -> R -> R) -> (R -> R -> R). 16 | (; 17 | [F] dx (x => y => F x) --> x => y => (d (x => F x)) x. 18 | [F] dx (x => y => F y) --> x => y => 0. 19 | ;) 20 | [F] dx (x => y => F x) --> x:R => y:R => (d (x:R => F x)) x. 21 | [F] dx (x => y => F y) --> x:R => y:R => 0. 22 | 23 | def dy : (R -> R -> R) -> (R -> R -> R). 24 | (; 25 | [F] dy (x => y => F x) --> x => y => 0. 26 | [F] dy (x => y => F y) --> x => y => (d (x => F x)) x. 27 | ;) 28 | [F] dy (x => y => F x) --> x:R => y:R => 0. 29 | [F] dy (x => y => F y) --> x:R => y:R => (d (x:R => F x)) x. 30 | 31 | def grad : (R -> R -> R) -> (R -> R -> R2). 32 | [F] grad F --> x:R => y:R => pair ((dx F) x y) ((dy F) x y). 33 | 34 | 35 | def trans : (R -> R -> R) -> (R -> R -> R). 36 | [F] trans (x => y => F x y) --> x:R => y:R => F y x. 37 | 38 | def flip : (R -> R -> R2) -> (R -> R -> R2). 39 | [F,G] flip (x => y => pair (F x y) (G x y)) --> x:R => y:R => pair (G x y) (F x y). 40 | 41 | 42 | def f : R -> R -> R := x : R => y : R => ch x. 43 | 44 | 45 | #EVAL grad (trans f). 46 | #EVAL flip (grad f). 47 | 48 | #EVAL g : (R -> R -> R) => grad (trans g). 49 | #EVAL g : (R -> R -> R) => flip (grad g). 50 | 51 | (; Expected: 52 | x => y => pair 0 (sh x) 53 | x => y => pair 0 (sh x) 54 | g:(R -> R -> R) => x => y => pair (dx (trans g) x y) (dy (trans g) x y) 55 | g:(R -> R -> R) => x => y => pair (dy g x y) (dx g x y) 56 | SUCCESS File 'miller.dk' was successfully checked. 57 | ;) 58 | -------------------------------------------------------------------------------- /tests/OK/miller2.dk: -------------------------------------------------------------------------------- 1 | R : Type. 2 | 0 : R. 3 | def p : R -> R -> R. 4 | [x] p 0 x --> x. 5 | [x] p x 0 --> x. 6 | 7 | sh : R -> R. 8 | ch : R -> R. 9 | def d : (R -> R) -> (R -> R). 10 | [] d sh --> ch. 11 | [] d ch --> sh. 12 | [] d (x => sh x) --> ch. 13 | [] d (x => ch x) --> sh. 14 | 15 | R2 : Type. 16 | pair : R -> R -> R2. 17 | 18 | def dx : (R -> R -> R) -> (R -> R -> R). 19 | [F] dx (x => y => F x) --> x:R => y:R => (d (x:R => F x)) x. 20 | [F] dx (x => y => F y) --> x:R => y:R => 0. 21 | 22 | def dy : (R -> R -> R) -> (R -> R -> R). 23 | [F] dy (x => y => F x) --> x:R => y:R => 0. 24 | [F] dy (x => y => F y) --> x:R => y:R => (d (x:R => F x)) x. 25 | 26 | def grad : (R -> R -> R) -> (R -> R -> R2). 27 | [F] grad F --> x:R => y:R => pair ((dx F) x y) ((dy F) x y). 28 | 29 | def plus : (R -> R -> R) -> (R -> R -> R) -> (R -> R -> R). 30 | [F,G] plus F G --> (x:R => y:R => p (F x y) (G x y)). 31 | [F,G] dx (x => y => p (F x y) (G x y)) --> 32 | x:R => y:R => p ((dx (x:R => y:R => F x y)) x y) 33 | ((dx (x:R => y:R => G x y)) x y). 34 | [F,G] dy (x => y => p (F x y) (G x y)) --> 35 | x:R => y:R => p ((dy (x:R => y:R => F x y)) x y) 36 | ((dy (x:R => y:R => G x y)) x y). 37 | 38 | def trans : (R -> R -> R) -> (R -> R -> R). 39 | [F] trans F --> x:R => y:R => F y x. 40 | 41 | def flip : (R -> R -> R2) -> (R -> R -> R2). 42 | [F,G] flip (x => y => pair (F x y) (G x y)) --> x:R => y:R => pair (G x y) (F x y). 43 | 44 | 45 | def f : R -> R -> R := plus (x : R => y : R => ch x) (x : R => y : R => sh y). 46 | 47 | 48 | #EVAL flip (grad f). 49 | #EVAL grad (trans f). 50 | 51 | #ASSERT grad (trans f) == flip (grad f). 52 | -------------------------------------------------------------------------------- /tests/OK/mini.dk: -------------------------------------------------------------------------------- 1 | N : Type. 2 | -------------------------------------------------------------------------------- /tests/OK/nat_id1.lp: -------------------------------------------------------------------------------- 1 | symbol G:TYPE; 2 | 3 | symbol e:G; 4 | 5 | compute e; 6 | 7 | symbol *:G → G → G; notation * infix 10; 8 | 9 | compute e * e; 10 | -------------------------------------------------------------------------------- /tests/OK/nat_id2.lp: -------------------------------------------------------------------------------- 1 | symbol N:TYPE; 2 | 3 | symbol O:N; 4 | symbol s:N → N; 5 | 6 | symbol G:TYPE; 7 | 8 | symbol e:G; 9 | symbol *:G → G → G; notation * infix 10; 10 | 11 | rule $x * e ↪ $x 12 | with e * $x ↪ $x; 13 | 14 | symbol ⋅:N → G → G; notation ⋅ infix 20; 15 | 16 | rule O ⋅ $x ↪ e 17 | with s $n ⋅ $x ↪ $x * $n ⋅ $x; 18 | 19 | compute λ x, O ⋅ x; 20 | compute λ x, (s(s(s O))) ⋅ x; 21 | -------------------------------------------------------------------------------- /tests/OK/nested_comment.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | 3 | (; dhdhdh (; dhdhd ;) ddd ;) 4 | 5 | B : Type. 6 | -------------------------------------------------------------------------------- /tests/OK/nested_comment_lp.lp: -------------------------------------------------------------------------------- 1 | /* bla /* bla bla */ bla */ 2 | -------------------------------------------------------------------------------- /tests/OK/nonLeftLinear.dk: -------------------------------------------------------------------------------- 1 | Nat : Type. 2 | 3 | 0 : Nat. 4 | S : Nat -> Nat. 5 | 6 | Elt : Type. 7 | 8 | Vec : Nat -> Type. 9 | 10 | nil : Vec 0. 11 | cns : n:Nat -> Elt -> Vec n -> Vec (S n). 12 | 13 | def tail : n:Nat -> Vec (S n) -> Vec n. 14 | [n,l] tail n (cns n _ l) --> l. 15 | 16 | (; 17 | tail2 : n:Nat -> Vec (S n) -> Vec n. 18 | [n,m,l] tail2 n (cns m _ l) --> l. 19 | ;) 20 | -------------------------------------------------------------------------------- /tests/OK/nonLeftLinear2.lp: -------------------------------------------------------------------------------- 1 | // Tests correctness of rewriting engine on left non linear rules 2 | require open tests.OK.natural; 3 | require open tests.OK.boolean; 4 | 5 | symbol eq_nl : N → N → B; 6 | 7 | rule eq_nl (s $x) (s $x) ↪ true 8 | with eq_nl 0 0 ↪ true 9 | with eq_nl (s _) 0 ↪ false 10 | with eq_nl 0 (s _) ↪ false; 11 | assert ⊢ eq_nl 3 3 ≡ true; 12 | 13 | symbol f : N → N → N → B; 14 | rule f $x $x _ ↪ true 15 | with f _ $x $x ↪ false; 16 | assert ⊢ f 4 4 11 ≡ true; 17 | assert ⊢ f 4 11 11 ≡ false; 18 | 19 | symbol g : N → N → B; 20 | rule g $x $x ↪ true; 21 | assert ⊢ g 4 4 ≡ true; 22 | 23 | symbol h : N → N → N → B; 24 | rule h $x $x $x ↪ true 25 | with h $x 0 (s $x) ↪ false; 26 | assert ⊢ h 3 3 3 ≡ true; 27 | assert ⊢ h 2 0 3 ≡ false; 28 | -------------------------------------------------------------------------------- /tests/OK/nonlin.dk: -------------------------------------------------------------------------------- 1 | Nat : Type. 2 | 3 | (; Constructeurs ;) 4 | 5 | 0 : Nat. 6 | S : Nat -> Nat. 7 | 8 | def plus : Nat -> Nat -> Nat. 9 | [n] plus 0 n --> n 10 | [m, n] plus (S m) n --> S (plus m n) 11 | [n] plus n 0--> n 12 | [m, n] plus m (S n) --> S (plus m n). 13 | 14 | def eq : (Nat -> Nat) -> (Nat -> Nat) -> Nat. 15 | [f] eq f f --> 0. 16 | 17 | #ASSERT eq (n:Nat => plus (S n) n) (n:Nat => plus n (S n)) == 0. 18 | -------------------------------------------------------------------------------- /tests/OK/not-eager.lp: -------------------------------------------------------------------------------- 1 | // Tests evaluation laziness. If too eager, 99! will be computed... 2 | require open tests.OK.natural; 3 | 4 | symbol l : N → N → N; 5 | rule l $x 0 ↪ l 0 $x 6 | with l 0 _ ↪ 0 7 | with l (s $x) (s $y) ↪ l $x $y; 8 | 9 | symbol fact : N → N; 10 | rule fact 0 ↪ 1 11 | with fact (s $x) ↪ (s $x) × (fact $x); 12 | 13 | compute l 0 (s (fact 99)); 14 | // Second 's' is discovered by rule 2 15 | compute l (s (s (fact 99))) 1; 16 | -------------------------------------------------------------------------------- /tests/OK/opaque.lp: -------------------------------------------------------------------------------- 1 | // Classical logic Gödel–Gentzen negative translation 2 | constant symbol Prop : TYPE; 3 | 4 | builtin "Prop" ≔ Prop; 5 | 6 | injective symbol π : Prop → TYPE; // `p 7 | builtin "P" ≔ π; 8 | 9 | symbol ⊥: Prop; 10 | symbol a: Prop; 11 | 12 | constant symbol ⇒ : Prop → Prop → Prop; notation ⇒ infix right 5; // => 13 | rule π ($p ⇒ $q) ↪ π $p → π $q; 14 | 15 | symbol ¬ p ≔ p ⇒ ⊥; notation ¬ prefix 35; 16 | 17 | constant symbol ∨ : Prop → Prop → Prop; notation ∨ infix left 6; // \/ or \vee 18 | constant symbol ∨ᵢ₁ [p q] : π p → π (p ∨ q); 19 | 20 | symbol πᶜ p ≔ π (¬ ¬ p); 21 | 22 | symbol ∨ᶜ p q ≔ (¬ ¬ p) ∨ (¬ ¬ q); notation ∨ᶜ infix right 20; 23 | 24 | opaque symbol ∨ᶜᵢ₁ [p q] : πᶜ p → πᶜ (p ∨ᶜ q) ≔ 25 | begin 26 | simplify; 27 | assume p q Hnnp; 28 | assume Hnnp_or_nnq; 29 | apply Hnnp_or_nnq; 30 | apply ∨ᵢ₁; 31 | refine Hnnp; 32 | end; 33 | 34 | opaque πᶜ; 35 | opaque ∨ᶜ; 36 | 37 | opaque symbol ∨ᶜᵢ₁' [p q] : πᶜ p → πᶜ (p ∨ᶜ q) ≔ 38 | begin 39 | assume p q Hp; 40 | simplify; 41 | apply ∨ᶜᵢ₁; 42 | apply Hp; 43 | end; 44 | -------------------------------------------------------------------------------- /tests/OK/parametricCoercions.lp: -------------------------------------------------------------------------------- 1 | constant symbol Set: TYPE; 2 | injective symbol El (_: Set): TYPE; 3 | 4 | // Pairs 5 | constant symbol * (_ _: Set): Set; 6 | notation * infix right 3; 7 | constant symbol pair [l: Set] [r: Set] (_: El l) (_: El r): El (l * r); 8 | symbol fst [l: Set] [r: Set] (_: El (l * r)): El l; 9 | symbol snd [l: Set] [r: Set] (_: El (l * r)): El r; 10 | rule fst (pair $x _) ↪ $x; 11 | rule snd (pair _ $y) ↪ $y; 12 | 13 | // Parametric coercion 14 | coerce_rule coerce (El ($l1 * $r1)) (El ($l2 * $r2)) $t ↪ 15 | pair (coerce (El $l1) (El $l2) (fst $t)) 16 | (coerce (El $r1) (El $r2) (snd $t)); 17 | 18 | // Ground types 19 | constant symbol nat: Set; 20 | constant symbol posnat: Set; 21 | 22 | constant symbol natOfPosnat (_: El posnat): El nat; 23 | coerce_rule coerce (El posnat) (El nat) $x ↪ natOfPosnat $x; 24 | 25 | constant symbol one: El posnat; 26 | // And a typing problem 27 | assert ⊢ one : El nat; // Non parametric 28 | assert ⊢ pair [posnat] [posnat] one one : El (nat * nat); 29 | //!\\ Arguments must be explicit for coercions to work 30 | 31 | type pair [nat] [nat] one one; 32 | assert ⊢ pair [nat] [nat] one one 33 | ≡ pair [nat] [nat] (natOfPosnat one) (natOfPosnat one); 34 | -------------------------------------------------------------------------------- /tests/OK/patt.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol f: A → A; 3 | 4 | // all these rules are equivalent 5 | rule f $x ↪ $x; 6 | rule f $x.[] ↪ $x; 7 | rule f $x ↪ $x.[]; 8 | rule f $x.[] ↪ $x.[]; 9 | 10 | symbol a:A; 11 | 12 | symbol g:(A → A) → A; 13 | rule g (λ x,$M.[x]) ↪ a; 14 | // Warning: Pattern variable [$M.[x]] can be replaced by a wildcard [_]. 15 | assert ⊢ g (λ x,x) ≡ a; 16 | 17 | symbol g2:(A → A) → A; 18 | rule g2 (λ x,_) ↪ a; // equivalent to g2 (λ x,$M.[x]) ↪ a 19 | assert ⊢ g2 (λ x,x) ≡ a; 20 | 21 | symbol h:(A → A) → A; 22 | rule h (λ x, $M.[]) ↪ a; 23 | // Warning: Pattern variable [$M] does not need to be named. 24 | // Warning: Variable [x] could be replaced by [_]. 25 | assertnot ⊢ h (λ x, x) ≡ a; 26 | assert ⊢ h (λ _, a) ≡ a; 27 | 28 | //symbol h2:(A → A) → A; 29 | //rule h2 (λ x, $M) ↪ a; // equivalent to h2 (λx,$M.[〉) ↪ a 30 | // Error: Missing square brackets under binder. 31 | //assertnot h2 (λ x, x) ≡ a; 32 | //assert h2 (λ _, a) ≡ a; 33 | 34 | symbol h3:(A → A) → A; 35 | rule h3 (λ _, _) ↪ a; // equivalent to h3 (λx,$M.[〉) ↪ a 36 | assertnot ⊢ h3 (λ x, x) ≡ a; 37 | assert ⊢ h3 (λ _, a) ≡ a; 38 | -------------------------------------------------------------------------------- /tests/OK/perf_rw_engine.lp: -------------------------------------------------------------------------------- 1 | // A simple loop to benchmark the rewriting engine 2 | require open tests.OK.natural; 3 | 4 | symbol upper ≔ 3000; 5 | 6 | symbol loop : N → N → N; 7 | rule loop (s $x) 0 ↪ loop $x upper 8 | with loop $x (s $y) ↪ loop $x $y; 9 | 10 | compute loop upper upper; 11 | -------------------------------------------------------------------------------- /tests/OK/perf_rw_fib-nonRightLin.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.natural; 2 | // Multiple recursions 3 | symbol fib : N → N; 4 | rule fib z ↪ 0 5 | with fib (s z) ↪ 1 6 | with fib (s (s $x)) ↪ (fib (s $x)) + (fib $x); 7 | 8 | symbol fib3 : N → N; 9 | rule fib3 0 ↪ 0 10 | with fib3 (s z) ↪ 1 11 | with fib3 (s (s z)) ↪ 1 12 | with fib3 (s (s (s $x))) ↪ (fib3 ($x + 2)) + (fib3 ($x + 1)) + (fib3 $x); 13 | 14 | assert ⊢ fib 15 ≡ 610; 15 | compute fib 24; // ≡ 46368; 16 | //compute fib3 21; 17 | -------------------------------------------------------------------------------- /tests/OK/perf_rw_nl.lp: -------------------------------------------------------------------------------- 1 | // Performance on non linear tests. 2 | require open tests.OK.natural; 3 | 4 | symbol upper ≔ 500; 5 | 6 | symbol loop : N → N → N → N; 7 | rule loop $x $x (s $y) ↪ loop $x $x $y 8 | with loop (s $x) _ 0 ↪ loop $x $x upper; 9 | 10 | compute loop upper (s upper) upper; // quick 11 | compute loop upper upper upper; // long 12 | -------------------------------------------------------------------------------- /tests/OK/plus.dk: -------------------------------------------------------------------------------- 1 | nat : Type. 2 | Z : nat. 3 | S : nat -> nat. 4 | 5 | def plus : nat -> nat -> nat. 6 | [m] plus Z (S m) --> S m 7 | [n] plus n Z --> n 8 | [n,m] plus (S n) (S m) --> S (S m). 9 | 10 | e: nat -> Type. 11 | def x: e Z. 12 | y: e (plus Z Z). 13 | [] x --> y. 14 | -------------------------------------------------------------------------------- /tests/OK/plus_ac.lp: -------------------------------------------------------------------------------- 1 | symbol N:TYPE; 2 | symbol O:N; 3 | symbol s:N → N; 4 | associative commutative symbol +:N → N → N; 5 | notation + infix 10; 6 | assert x y z ⊢ (x + s y) + s(s z) ≡ s(s z) + (x + s y); 7 | compute λ x y z, (x + s y) + s(s z); 8 | -------------------------------------------------------------------------------- /tests/OK/postfix.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.natural; 2 | symbol ! (_: N): N; 3 | notation ! postfix 9; 4 | 5 | rule (s $n) ! ↪ (s $n) × $n !; 6 | rule z ! ↪ (s z); 7 | 8 | assert ⊢ 3 ! ≡ 6; 9 | -------------------------------------------------------------------------------- /tests/OK/power-fact.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.natural; 2 | 3 | symbol power : N → N → N; 4 | rule power _ 0 ↪ 1 5 | with power $x (s $y) ↪ $x × (power $x $y); 6 | 7 | symbol fact : N → N; 8 | rule fact 0 ↪ 1 9 | with fact (s $x) ↪ (s $x) × (fact $x); 10 | 11 | compute power 5 5; 12 | compute fact 7; 13 | -------------------------------------------------------------------------------- /tests/OK/prefix.lp: -------------------------------------------------------------------------------- 1 | constant symbol B : TYPE; 2 | 3 | symbol ∧ : B → B → B; 4 | symbol ∨ : B → B → B; 5 | symbol ¬ : B → B; 6 | 7 | notation ∨ infix right 5; 8 | notation ∧ infix right 6; 9 | notation ¬ prefix 7; 10 | 11 | assert ⊢ λ x y z t, x ∨ ¬ y ∧ z ∨ t ≡ λ x y z t, x ∨ (((¬ y) ∧ z) ∨ t); 12 | 13 | assert ⊢ λ p, ¬ ¬ p ≡ λ p, ¬ (¬ p); 14 | 15 | assert ⊢ λ p x, ¬ p x ≡ λ p x, ¬ (p x); 16 | 17 | // Types and arrow 18 | 19 | symbol o : B → TYPE; 20 | notation o prefix 6; 21 | assert (n : B) ⊢ o n → B ≡ (o n) → B; 22 | -------------------------------------------------------------------------------- /tests/OK/print_notation_numbers.lp: -------------------------------------------------------------------------------- 1 | symbol N:TYPE; 2 | symbol z:N; 3 | symbol s:N → N; 4 | 5 | builtin "nat_zero" ≔ z; 6 | builtin "nat_succ" ≔ s; 7 | 8 | compute s(s z); 9 | 10 | symbol P:TYPE; 11 | symbol H:P; 12 | symbol O:P → P; 13 | symbol I:P → P; 14 | 15 | builtin "pos_one" ≔ H; 16 | builtin "pos_double" ≔ O; 17 | builtin "pos_succ_double" ≔ I; 18 | 19 | compute I(O(I H)); 20 | 21 | symbol double:N → N; 22 | rule double z ↪ z 23 | with double (s $x) ↪ s(s(double $x)); 24 | 25 | symbol val:P → N; 26 | rule val H ↪ s z 27 | with val (O $x) ↪ double(val $x) 28 | with val (I $x) ↪ s(double(val $x)); 29 | 30 | compute val(I(O(I H))); 31 | 32 | symbol Z:TYPE; 33 | symbol Z0:Z; 34 | symbol Zpos:P → Z; 35 | symbol Zneg:P → Z; 36 | 37 | builtin "int_zero" ≔ Z0; 38 | builtin "int_positive" ≔ Zpos; 39 | builtin "int_negative" ≔ Zneg; 40 | 41 | compute Zneg(I(O(I H))); 42 | -------------------------------------------------------------------------------- /tests/OK/private.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | private symbol a:A; 3 | opaque symbol b:A ≔ a; 4 | -------------------------------------------------------------------------------- /tests/OK/quant.lp: -------------------------------------------------------------------------------- 1 | constant symbol Set : TYPE; 2 | 3 | injective symbol τ : Set → TYPE; 4 | 5 | constant symbol prop : Set; 6 | 7 | symbol Prop ≔ τ prop; 8 | 9 | constant symbol ⊤ : Prop; 10 | 11 | constant symbol ∀ [a] : (τ a → Prop) → Prop; 12 | 13 | notation ∀ quantifier; 14 | 15 | constant symbol ⇒ : Prop → Prop → Prop; 16 | 17 | notation ⇒ infix right 5; 18 | 19 | compute λ p q, ∀ (λ x, p x ⇒ q x); 20 | // should print λ p, `∀ x, (p x ⇒ q x) 21 | 22 | compute λ p, `∀ x, p x; 23 | // should print λ p, `∀ x, p x 24 | 25 | compute λ p q, (`∀ x, p x) ⇒ q; 26 | // should print λp q, (`∀ x, p x) ⇒ q 27 | 28 | flag "print_domains" on; 29 | compute λ p, `∀ x, p x; 30 | // should print λ p : τ ?8 → τ prop, `∀ x : τ ?8 → τ prop, p x 31 | 32 | flag "print_domains" off; 33 | flag "print_implicits" on; 34 | compute λ p, `∀ x, p x; 35 | // should print λ p, @∀ ?8 (λ x, p x) 36 | 37 | flag "print_domains" on; 38 | compute λ p, `∀ x, p x; 39 | // should print λ p : τ ?8 → τ prop, @∀ ?8 (λ x:τ ?8, p x) 40 | -------------------------------------------------------------------------------- /tests/OK/quant2.lp: -------------------------------------------------------------------------------- 1 | // test parsing of quantifiers 2 | symbol A:TYPE; 3 | symbol f:(A → A) → A; 4 | compute `f x, x; 5 | symbol ⇒:A → A → A; notation ⇒ infix right 10; 6 | compute `f x, `f y, x ⇒ y; 7 | symbol a:A; 8 | compute a ⇒ `f x, x; 9 | compute a ⇒ `f x, a ⇒ `f y, x ⇒ y; 10 | -------------------------------------------------------------------------------- /tests/OK/remove.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol B:A → TYPE; 3 | symbol C a:B a → TYPE; 4 | 5 | opaque symbol lemma : A → A ≔ 6 | begin 7 | assume a; 8 | remove a; 9 | abort; 10 | 11 | opaque symbol lemma a (b:B a) (c:C a b) : A ≔ 12 | begin 13 | assume a b c; 14 | remove c; 15 | remove a b; 16 | abort; 17 | -------------------------------------------------------------------------------- /tests/OK/req.file.with.dot.lp: -------------------------------------------------------------------------------- 1 | require tests.OK.{|file.with.dot|}; 2 | symbol a:tests.OK.{|file.with.dot|}.A; 3 | -------------------------------------------------------------------------------- /tests/OK/require_nondkmident.lp: -------------------------------------------------------------------------------- 1 | // Module name suc-alg is not a valid Dedukti2 module name, the exporter must 2 | // brace-quote it. 3 | require tests.OK.max-suc-alg; 4 | 5 | symbol Z ≔ tests.OK.max-suc-alg.Z; 6 | -------------------------------------------------------------------------------- /tests/OK/require_symbol.lp: -------------------------------------------------------------------------------- 1 | // The following is invalid because [symbol] is a keyword. 2 | //require tests.OK.symbol 3 | 4 | // Here is a workaround with an escaped identifier. 5 | require tests.OK.{|symbol|}; 6 | -------------------------------------------------------------------------------- /tests/OK/rule_order.lp: -------------------------------------------------------------------------------- 1 | symbol E: TYPE; 2 | symbol e: E; 3 | symbol ListE: TYPE; 4 | symbol nil: ListE; 5 | symbol cons: E → ListE → ListE; 6 | 7 | symbol Bool: TYPE; 8 | symbol true: Bool; 9 | symbol false: Bool; 10 | 11 | sequential symbol mem: E → ListE → Bool; 12 | rule mem $e (cons $e _) ↪ true; 13 | rule mem $e (cons _ $l) ↪ mem $e $l; 14 | rule mem _ nil ↪ false; 15 | 16 | symbol mem2: E → ListE → Bool; 17 | rule mem2 $e (cons $e _) ↪ true; 18 | rule mem2 $e (cons _ $l) ↪ mem $e $l; 19 | rule mem2 _ nil ↪ false; 20 | 21 | assert ⊢ mem e (cons e nil) ≡ true; 22 | assert ⊢ mem2 e (cons e nil) ≡ false; 23 | -------------------------------------------------------------------------------- /tests/OK/simp_beta.lp: -------------------------------------------------------------------------------- 1 | symbol A:TYPE; 2 | symbol a:A; 3 | symbol P:A → TYPE; 4 | symbol id (x:A) ≔ x; 5 | opaque symbol l:P(id a) ≔ 6 | begin 7 | simplify id; simplify rule off; 8 | abort; 9 | -------------------------------------------------------------------------------- /tests/OK/strictly_positive_1.lp: -------------------------------------------------------------------------------- 1 | // test generation of inductive principle for a strictly-positive type 2 | // with a constructor taking a binary function as argument 3 | 4 | constant symbol Prop : TYPE; 5 | builtin "Prop" ≔ Prop; 6 | injective symbol π : Prop → TYPE; 7 | builtin "P" ≔ π; 8 | 9 | constant symbol ℕ:TYPE; 10 | 11 | inductive 𝕆:TYPE ≔ z:𝕆 | s:𝕆 → 𝕆 | l:(ℕ → ℕ → 𝕆) → 𝕆; 12 | 13 | assert ⊢ 𝕆:TYPE; 14 | assert ⊢ z:𝕆; 15 | assert ⊢ s:𝕆 → 𝕆; 16 | assert ⊢ l:(ℕ → ℕ → 𝕆) → 𝕆; 17 | 18 | assert ⊢ ind_𝕆: Π p, π (p z) → (Π x, π (p x) → π (p (s x))) 19 | → (Π x, (Π y z, π (p (x y z))) → π (p (l x))) → Π x, π (p x); 20 | 21 | assert p a b c ⊢ ind_𝕆 p a b c z ≡ a; 22 | assert p a b c x ⊢ ind_𝕆 p a b c (s x) ≡ b x (ind_𝕆 p a b c x); 23 | assert p a b c x y ⊢ ind_𝕆 p a b c (l x) ≡ c x (λ y z, ind_𝕆 p a b c (x y z)); 24 | -------------------------------------------------------------------------------- /tests/OK/subst.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | x : A. 3 | t : (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => (x : A => A) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x. 4 | -------------------------------------------------------------------------------- /tests/OK/surjective.dk: -------------------------------------------------------------------------------- 1 | T:Type. 2 | Pairs:Type. 3 | def p1:Pairs->T. 4 | def p2:Pairs->T. 5 | def mk:T->T->Pairs. 6 | 7 | [a] p1 (mk a _) --> a. 8 | [b] p2 (mk _ b) --> b. 9 | [p] mk (p1 p) (p2 p) --> p. 10 | -------------------------------------------------------------------------------- /tests/OK/sym_decl.lp: -------------------------------------------------------------------------------- 1 | // A type for the natural numbers. 2 | constant symbol Nat : TYPE; 3 | 4 | // Zero and successor symbols. 5 | constant symbol zero : Nat; 6 | constant symbol succ : Nat → Nat; 7 | //injective symbol succ : Nat → Nat 8 | 9 | // Addition and multiplication 10 | symbol add : Nat → Nat → Nat; 11 | symbol mul : Nat → Nat → Nat; 12 | -------------------------------------------------------------------------------- /tests/OK/symbol.lp: -------------------------------------------------------------------------------- 1 | // The module path of this file contains a keyword ident. 2 | -------------------------------------------------------------------------------- /tests/OK/tail.lp: -------------------------------------------------------------------------------- 1 | constant symbol N:TYPE; 2 | constant symbol o : N; 3 | constant symbol s : N → N; 4 | 5 | constant symbol A:TYPE; 6 | 7 | constant symbol V:N → TYPE; 8 | constant symbol nil:V o; 9 | constant symbol cons:A → Π n, V n → V(s n); 10 | 11 | symbol tail:Π n, V(s n) → V n; 12 | 13 | rule tail _ (cons _ _ $v) ↪ $v; 14 | -------------------------------------------------------------------------------- /tests/OK/tautologies.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.logic; 2 | require open tests.OK.boolean; 3 | 4 | rule T bool ↪ B; 5 | 6 | opaque symbol and_idempotent (a:B) : P (bool_and a a = a) 7 | ≔ begin 8 | assume a; 9 | refine bool_ind (λ a, bool_and a a = a) _ _ a 10 | {reflexivity} 11 | {reflexivity} 12 | end; 13 | 14 | // Same with a reduction rule. 15 | 16 | rule bool_and $a $a ↪ $a; 17 | 18 | opaque symbol and_idempotent_rw a : P (bool_and a a = a) 19 | ≔ begin 20 | assume a; 21 | reflexivity 22 | end; 23 | -------------------------------------------------------------------------------- /tests/OK/test.dk: -------------------------------------------------------------------------------- 1 | def Bool : Type. 2 | T : Bool. 3 | 4 | def Nat : Type. 5 | 0 : Nat. 6 | 7 | def S : Nat -> Nat. 8 | [] S T --> 0. 9 | 10 | -------------------------------------------------------------------------------- /tests/OK/triangular.lp: -------------------------------------------------------------------------------- 1 | // Triggers heavy memory consumption with trees 2 | require open tests.OK.natural; 3 | 4 | symbol triangle : N → N; 5 | rule triangle (s $n) ↪ (s $n) + (triangle $n) 6 | with triangle z ↪ z; 7 | 8 | compute triangle 300; // ≡ 45150; 9 | -------------------------------------------------------------------------------- /tests/OK/type.lp: -------------------------------------------------------------------------------- 1 | symbol N : TYPE; 2 | type N; 3 | -------------------------------------------------------------------------------- /tests/OK/type_rewrite.dk: -------------------------------------------------------------------------------- 1 | def A : Type. 2 | B : Type. 3 | def x : A. 4 | y : B. 5 | [] A --> B. 6 | [] x --> y. 7 | -------------------------------------------------------------------------------- /tests/OK/uninst_meta_in_rhs.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | 3 | def g : A -> A. 4 | 5 | [] g --> x => x. 6 | -------------------------------------------------------------------------------- /tests/OK/varmatch.lp: -------------------------------------------------------------------------------- 1 | constant symbol A : TYPE; 2 | 3 | constant symbol id : A → A; 4 | symbol f : (A → A) → (A → A); 5 | rule f (λ x, x) ↪ id; 6 | 7 | assert ⊢ f (λ x, x) ≡ id; 8 | -------------------------------------------------------------------------------- /tests/OK/vectDependant.dk: -------------------------------------------------------------------------------- 1 | Nat : Type. 2 | 3 | 0 : Nat. 4 | S : Nat -> Nat. 5 | 6 | def 1 : Nat := S 0. 7 | def 2 : Nat := S 1. 8 | def 3 : Nat := S 2. 9 | def 4 : Nat := S 3. 10 | 11 | Vec : Nat -> Type. 12 | 13 | nil : Vec 0. 14 | cns : n : Nat -> Vec n -> Vec (S n). 15 | 16 | def tail : n:Nat -> Vec (S n) -> Vec n. 17 | 18 | [n,v] tail n (cns _ v) --> v. 19 | 20 | def f : Nat -> Nat. 21 | 22 | [] f 0 --> S (S 0). 23 | [] f (S 0) --> S (S 0). 24 | [n] f (S (S n)) --> S (S (f n)). 25 | 26 | cnsf : n:Nat -> Vec n -> Vec (f n). 27 | 28 | def idf : n:Nat -> Vec (f n) -> Vec (f n). 29 | 30 | [n,v] idf _ (cnsf n v) --> cnsf n v. 31 | -------------------------------------------------------------------------------- /tests/OK/why3.lp: -------------------------------------------------------------------------------- 1 | require open tests.OK.Prop tests.OK.Set tests.OK.FOL; 2 | 3 | prover "Alt-Ergo"; 4 | prover_timeout 2; 5 | 6 | opaque symbol test1 p : π p → π p ≔ begin why3 end; 7 | 8 | opaque symbol test2 p q : π (p ∧ q) → π p ≔ begin why3 end; 9 | 10 | opaque symbol test3 : Π p q, π (p ∧ q) → π p ≔ begin why3 end; 11 | 12 | opaque symbol test4 p : π (p ∨ ¬ p) ≔ begin why3 end; 13 | 14 | opaque symbol test5 p q : π p → π (p ∨ q) ≔ begin why3 end; 15 | 16 | opaque symbol test6 p q : π (p ⇒ q) → π p → π q ≔ begin why3 end; 17 | 18 | constant symbol nat:Set; 19 | 20 | symbol even : τ nat → Prop; 21 | 22 | opaque symbol test7 : π (`∃ n, even n ⇒ even n) ≔ begin why3 end; 23 | 24 | opaque symbol test8 a p: π (`∃ x:τ a, p x ⇒ p x) ≔ begin why3 end; 25 | 26 | opaque symbol test9 a p : π (¬ (`∃ x:τ a, p x) ⇔ (`∀ x, ¬ (p x))) ≔ begin why3 end; 27 | 28 | opaque symbol test10 a p x q : π ((`∀ x:τ a, p x ⇒ q) ⇒ p x ⇒ q) ≔ begin why3 end; 29 | 30 | //opaque symbol test a p x q : π ((`∀ x:τ a, p x ⇒ (λ y, q y) x) ⇒ p x ⇒ (λ y, q y) x) ≔ begin why3 end; 31 | 32 | //opaque symbol test a p x q : π ((`∀ x:τ a, p x ⇒ q ((λ y,y)x)) ⇒ p x ⇒ q ((λ y,y)x)) ≔ begin why3 end; 33 | 34 | //constant symbol o:Set; 35 | //rule τ o ↪ Prop; 36 | 37 | //opaque symbol test a (p:τ(nat ⤳ o)) : π (¬ (`∃ x:τ a, p x) ⇔ (`∀ x, ¬ (p x))) ≔ begin why3 end; 38 | 39 | //opaque symbol test : π (`∃ p, p ⇒ p) ≔ begin why3 end; 40 | -------------------------------------------------------------------------------- /tests/OK/wildcards.dk: -------------------------------------------------------------------------------- 1 | A : Type. 2 | a : A. 3 | 4 | def f1 : (A -> A) -> A. 5 | [] f1 (_ => _) --> a. 6 | 7 | #ASSERT f1 (_ => a) == a. 8 | #ASSERTNOT f1 (x => x) == a. 9 | 10 | def f2 : (A -> A) -> A. 11 | [] f2 (x => _) --> a. 12 | 13 | #ASSERT f2 (_ => a) == a. 14 | #ASSERTNOT f2 (x => x) == a. 15 | 16 | def f3 : (A -> A) -> A. 17 | [] f3 (x => _ x) --> a. 18 | 19 | #ASSERT f3 (_ => a) == a. 20 | #ASSERT f3 (x => x) == a. 21 | 22 | def f4 : (A -> A) -> A. 23 | [X] f4 (x => X x) --> a. 24 | 25 | #ASSERT f4 (_ => a) == a. 26 | #ASSERT f4 (x => x) == a. 27 | -------------------------------------------------------------------------------- /tests/OK/xor.lp: -------------------------------------------------------------------------------- 1 | symbol B:TYPE; 2 | 3 | symbol O:B; 4 | associative commutative symbol +:B → B → B; notation + infix right 20; 5 | 6 | rule O + $x ↪ $x 7 | with $x + O ↪ $x 8 | with $x + $x ↪ O; 9 | 10 | compute λ x, (x + O) + (x + x + x); 11 | 12 | assert x ⊢ x + O ≡ x + x + x; 13 | -------------------------------------------------------------------------------- /tests/OK/zero.lp: -------------------------------------------------------------------------------- 1 | // test that builtin 0 can be used without defining buitin +1 2 | symbol N : TYPE; 3 | symbol zero : N; builtin "0" ≔ zero; 4 | print zero; 5 | -------------------------------------------------------------------------------- /tests/dtrees.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '############ test decision-tree ############' 4 | 5 | set -uf 6 | 7 | ko() { 8 | printf '\033[31mKO\033[0m %s\n' "$1" 9 | exit 1 10 | } 11 | 12 | ok() { 13 | printf '\033[32mOK\033[0m %s\n' "$1" 14 | } 15 | 16 | LAMBDAPI='dune exec -- lambdapi decision-tree -v 0 -w --map-dir=tests:tests' 17 | 18 | out="$(${LAMBDAPI} tests.OK.natural.+)" 19 | if [ -z "$out" ]; then 20 | ko 'tests.OK.nat.+' 21 | else 22 | ok 'tests.OK.nat.+' 23 | fi 24 | 25 | # Escaped identifier with no rule 26 | out="$(${LAMBDAPI} 'tests.OK.Escaped.{|KIND|}' 2>/dev/null)" 27 | if [ "$?" = 1 ]; then 28 | ko 'tests.OK.Escaped.{|KIND|}' 29 | fi 30 | if [ -z "$out" ]; then 31 | ok 'tests.OK.Escaped.{|KIND|}' 32 | fi 33 | 34 | # Escaped identifier with dots and no rule 35 | out="$(${LAMBDAPI} 'tests.OK.Escaped.{|KIND.OF.BLUE|}' 2>/dev/null)" 36 | if [ "$?" = 1 ]; then 37 | ko 'tests.OK.Escaped.{|KIND.OF.BLUE|}' 38 | fi 39 | if [ -z "$out" ]; then 40 | ok 'tests.OK.Escaped.{|KIND.OF.BLUE|}' 41 | fi 42 | 43 | # Escaped identifier with rules 44 | out="$(${LAMBDAPI} 'tests.OK.Escaped.{|_set|}' 2>/dev/null)" 45 | if [ "$?" = 1 ] || [ -z "$out" ]; then 46 | ko 'tests.OK.Escaped.{|_set|}' 47 | else 48 | ok 'tests.OK.Escaped.{|_set|}' 49 | fi 50 | 51 | # Ghost symbol 52 | out="$(${LAMBDAPI} --ghost 'tests.OK.unif_hint.≡' 2>/dev/null)" 53 | if [ "$?" = 1 ] || [ -z "$out" ]; then 54 | ko 'tests.OK.unif_hint.≡' 55 | else 56 | ok 'tests.OK.unif_hint.≡' 57 | fi 58 | 59 | exit 0 60 | -------------------------------------------------------------------------------- /tests/dune: -------------------------------------------------------------------------------- 1 | (tests 2 | (names ok_ko rewriting purity kernel) 3 | (deps 4 | (glob_files OK/*.lp) 5 | (glob_files OK/*.dk) 6 | (glob_files "OK/a b/*.lp") 7 | (glob_files KO/*.lp) 8 | (glob_files KO/*.dk) 9 | lambdapi.pkg) 10 | (libraries lambdapi.core lambdapi.parsing lambdapi.handle lambdapi.tool 11 | alcotest) 12 | (flags -w +3)) 13 | 14 | ;(rule 15 | ; (alias runtest) 16 | ; (action (run why3 config detect))) 17 | -------------------------------------------------------------------------------- /tests/export_lp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo '############ test export -o lp ############' 6 | 7 | lambdapi=${lambdapi:-_build/install/default/bin/lambdapi} 8 | 9 | TIMEFORMAT="%Es" 10 | 11 | rm -rf /tmp/tests 12 | mkdir -p "/tmp/tests/OK/a b" 13 | cp tests/lambdapi.pkg /tmp/tests/ 14 | 15 | # translate lp files 16 | translate() { 17 | echo translate lp files ... 18 | for f in tests/OK/*.lp 'tests/OK/a b/escape file.lp' 19 | do 20 | case $f in 21 | tests/OK/why3*.lp);; #FIXME 22 | *) out=/tmp/$f 23 | echo "$f --> $out ..." 24 | $lambdapi export -o lp -w -v 0 "$f" > "$out" 25 | if test $? -ne 0; then echo KO; exit 1; fi 26 | esac 27 | done 28 | } 29 | time translate 30 | 31 | # check lp files 32 | check() { 33 | echo check lp files ... 34 | for f in /tmp/tests/OK/*.lp '/tmp/tests/OK/a b/escape file.lp' 35 | do 36 | case $f in 37 | /tmp/tests/OK/why3*.lp);; #FIXME 38 | *) echo "lambdapi check $f ..." 39 | $lambdapi check -w -v 0 "$f" 40 | if test $? -ne 0; then echo KO; exit 1; fi 41 | esac 42 | done 43 | } 44 | time check 45 | 46 | #cd $root 47 | echo OK 48 | -------------------------------------------------------------------------------- /tests/kernel.ml: -------------------------------------------------------------------------------- 1 | open Common 2 | open Core 3 | 4 | let () = 5 | (* Set library root to avoid creating files out of the sandbox when opam runs 6 | tests. *) 7 | Library.set_lib_root (Some (Sys.getcwd ())) 8 | 9 | let open_sign_default () = 10 | (* Check that by default, [Sig_state.of_sign s] opens [s] *) 11 | let sign = Sig_state.create_sign [ "dummy" ] in 12 | let _ = 13 | Sign.add_symbol sign Term.Public Term.Defin Term.Eager false 14 | (Pos.none "foo") None Term.mk_Type [] 15 | in 16 | let ss = Sig_state.of_sign sign in 17 | Alcotest.(check unit) 18 | "find_sym succeeds" 19 | (ignore @@ Sig_state.find_sym ~prt:true ~prv:true ss (Pos.none ([], "foo"))) 20 | () 21 | 22 | let () = 23 | let open Alcotest in 24 | run "Kernel" 25 | [ ( "Signatures management" 26 | , [ test_case "Signature opened in sig state" `Quick open_sign_default ] 27 | ) 28 | ] 29 | -------------------------------------------------------------------------------- /tests/lambdapi.pkg: -------------------------------------------------------------------------------- 1 | package_name = tests 2 | root_path = tests 3 | -------------------------------------------------------------------------------- /tests/ok_ko.ml: -------------------------------------------------------------------------------- 1 | (** Compile files in "OK" and "KO". *) 2 | 3 | let compile = Timed.pure_apply Handle.Compile.compile_file 4 | 5 | let test_ok f () = 6 | (* Simply assert that there is no exception raised. *) 7 | Alcotest.(check unit) f (ignore (compile f)) () 8 | 9 | let test_ko f () = 10 | (* Succeed if compilation fails. *) 11 | let r = try ignore (compile f); true with _ -> false in 12 | Alcotest.(check bool) f r false 13 | 14 | let _ = 15 | (* Set library root to avoid creating files out of the sandbox when 16 | opam runs tests. *) 17 | Common.Library.set_lib_root (Some (Sys.getcwd ())); 18 | let open Alcotest in 19 | let files = Lplib.Extra.files Common.Library.is_valid_src_extension "OK" in 20 | (* Remove files using a prover. *) 21 | let does_not_use_prover = function 22 | | "OK/why3.lp" | "OK/why3_quantifiers.lp" -> false 23 | | _ -> true 24 | in 25 | let files = List.filter does_not_use_prover files in 26 | let tests_ok = List.map (fun f -> test_case f `Quick (test_ok f)) files in 27 | let files = Lplib.Extra.files Common.Library.is_valid_src_extension "KO" in 28 | let tests_ko = List.map (fun f -> test_case f `Quick (test_ko f)) files in 29 | run "Std" [("OK", tests_ok); ("KO", tests_ko)] 30 | -------------------------------------------------------------------------------- /tests/regressions/dtrees.ml: -------------------------------------------------------------------------------- 1 | (** Test decision trees to graph export *) 2 | 3 | open Common 4 | open Handle 5 | open Core 6 | 7 | let () = 8 | Library.set_lib_root (Some "/tmp"); 9 | Timed.(Console.verbose := 0); 10 | let sign = Compile.PureUpToSign.compile_file "../OK/boolean.lp" in 11 | let ss = Sig_state.of_sign sign in 12 | (* Regular symbol *) 13 | let sym = 14 | Sig_state.find_sym ~prt:true ~prv:true ss 15 | (Pos.none ([ "tests"; "OK"; "boolean" ], "bool_or")) 16 | in 17 | Format.printf "=> tests.OK.boolean.bool_or@\n"; 18 | Tool.Tree_graphviz.to_dot Format.std_formatter sym; 19 | (* Ghost symbol *) 20 | (* We don't use [Pure] to keep rules added to unif hint symbols *) 21 | ignore @@ Compile.compile_file "../OK/unif_hint.lp"; 22 | Format.printf "=> ghost symbol ≡ from tests.OK.unif_hint@\n"; 23 | Tool.Tree_graphviz.to_dot Format.std_formatter Unif_rule.equiv 24 | -------------------------------------------------------------------------------- /tests/regressions/dune: -------------------------------------------------------------------------------- 1 | (tests 2 | (names hrs xtc dtrees) 3 | (libraries timed lambdapi.export lambdapi.core lambdapi.common lambdapi.handle) 4 | (deps ../OK/group.lp ../OK/boolean.lp ../OK/unif_hint.lp ../lambdapi.pkg) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/regressions/hrs.expected: -------------------------------------------------------------------------------- 1 | (FUN 2 | A : t -> t -> t 3 | L : t -> (t -> t) -> t 4 | P : t -> (t -> t) -> t 5 | B : t -> t -> (t -> t) -> t 6 | tests_OK_group_e : t 7 | tests_OK_group_inv : t 8 | tests_OK_group_⋅ : t 9 | ) 10 | (VAR 11 | $x : t 12 | $y : t -> t 13 | $z : t 14 | $2_0 : t 15 | $3_0 : t 16 | $3_1 : t 17 | $4_0 : t 18 | $4_1 : t 19 | $4_2 : t 20 | $5_0 : t 21 | $6_0 : t 22 | $7_0 : t 23 | $8_0 : t 24 | $9_0 : t 25 | $9_1 : t 26 | $10_0 : t 27 | $10_1 : t 28 | ) 29 | (RULES 30 | A(L($x,$y),$z) -> $y($z), 31 | B($x,$z,$y) -> $y($z), 32 | A(tests_OK_group_inv,tests_OK_group_e) -> tests_OK_group_e, 33 | A(tests_OK_group_inv,A(tests_OK_group_inv,$2_0)) -> $2_0, 34 | A(tests_OK_group_inv,A(A(tests_OK_group_⋅,$3_0),$3_1)) -> A(A(tests_OK_group_⋅,A(tests_OK_group_inv,$3_1)),A(tests_OK_group_inv,$3_0)), 35 | A(A(tests_OK_group_⋅,A(A(tests_OK_group_⋅,$4_0),$4_1)),$4_2) -> A(A(tests_OK_group_⋅,$4_0),A(A(tests_OK_group_⋅,$4_1),$4_2)), 36 | A(A(tests_OK_group_⋅,tests_OK_group_e),$5_0) -> $5_0, 37 | A(A(tests_OK_group_⋅,$6_0),tests_OK_group_e) -> $6_0, 38 | A(A(tests_OK_group_⋅,A(tests_OK_group_inv,$7_0)),$7_0) -> tests_OK_group_e, 39 | A(A(tests_OK_group_⋅,$8_0),A(tests_OK_group_inv,$8_0)) -> tests_OK_group_e, 40 | A(A(tests_OK_group_⋅,A(tests_OK_group_inv,$9_0)),A(A(tests_OK_group_⋅,$9_0),$9_1)) -> $9_1, 41 | A(A(tests_OK_group_⋅,$10_0),A(A(tests_OK_group_⋅,A(tests_OK_group_inv,$10_0)),$10_1)) -> $10_1 42 | ) 43 | -------------------------------------------------------------------------------- /tests/regressions/hrs.ml: -------------------------------------------------------------------------------- 1 | (** HRS file generation *) 2 | 3 | open Common 4 | open Handle 5 | 6 | let () = 7 | Library.set_lib_root (Some "/tmp"); 8 | Timed.(Console.verbose := 0); 9 | let sign = Compile.PureUpToSign.compile_file "../OK/group.lp" in 10 | Export.Hrs.sign Format.std_formatter sign 11 | -------------------------------------------------------------------------------- /tests/regressions/xtc.ml: -------------------------------------------------------------------------------- 1 | open Common 2 | open Handle 3 | 4 | let () = 5 | Library.set_lib_root (Some "/tmp"); 6 | Timed.(Console.verbose := 0); 7 | let sign = Compile.PureUpToSign.compile_file "../OK/group.lp" in 8 | Export.Xtc.sign Format.std_formatter sign 9 | -------------------------------------------------------------------------------- /tests/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | lambdapi='dune exec -- lambdapi check' 6 | TIMEFORMAT="%Es" 7 | 8 | out=/tmp/lambdapi.output 9 | 10 | ok_tests() { 11 | for f in 'tests/OK/a b/escape file.lp' tests/OK/*.lp tests/OK/*.dk 12 | do 13 | case $f in 14 | tests/OK/why3*.lp);; #FIXME 15 | *) 16 | echo lambdapi check $options $f ... 17 | $lambdapi "$f" > $out 2>&1 || (cat $out; exit 1) 18 | esac 19 | done 20 | } 21 | 22 | rm -f 'tests/OK/a b/escape file.lpo' tests/OK/*.lpo 23 | 24 | echo "############ compile tests/OK files ############" 25 | options='-c -w' 26 | time ok_tests 27 | 28 | echo "############ load tests/OK files ############" 29 | options='-w' 30 | time ok_tests 31 | -------------------------------------------------------------------------------- /tests/test_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | lambdapi='dune exec -- lambdapi check' 6 | options='-w' 7 | TIMEFORMAT="%Es" 8 | 9 | out=/tmp/lambdapi.output 10 | 11 | checkout_lib() { 12 | IFS='/' read -ra ADDR <<< "$1" 13 | repo_path="${ADDR[-1]}" 14 | IFS='.' read -ra ADDR <<< "$repo_path" 15 | repo_path="/tmp/${ADDR[0]}" 16 | if [ -d "$repo_path" ] ; then 17 | rm -fr "$repo_path" 18 | fi 19 | git clone $1 $repo_path 20 | } 21 | 22 | test_lib() { 23 | for f in $(find $1 -name '*.lp' -o -name '*.dk') 24 | do 25 | echo lambdapi check $options $f ... 26 | $lambdapi "$f" > $out 2>&1 || (cat $out; exit 1) 27 | done 28 | } 29 | 30 | checkout_lib $1 31 | time test_lib $repo_path 32 | --------------------------------------------------------------------------------