Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
0617bf0
Add Lean 4 backend
septract Mar 6, 2026
9e4f4eb
Add Inhabited instance generation and fix Typ_with_sort handling
septract Mar 6, 2026
b2ddb32
Add Lean 4 backend documentation and fix missing library declarations
septract Mar 6, 2026
6b09220
Fix Lean library gaps and add test/build infrastructure
septract Mar 6, 2026
c515e6d
Fix UTF-8 double-encoding, constructor scoping, and whitespace in Lea…
septract Mar 6, 2026
da334b3
Fix all 7 test files: target filtering, BEq deriving, mutual inductives
septract Mar 6, 2026
2ec11ab
Audit cleanup: error handling, docs, inline annotations, bug fixes
septract Mar 6, 2026
e3053d4
WIP: test suite infrastructure and assert emission fix
septract Mar 6, 2026
01b8260
Add comprehensive test suite with 25 test files and 103 runtime asser…
septract Mar 6, 2026
0e00490
Fix test suite: all 25 comprehensive tests pass, gitignore cleanup
septract Mar 6, 2026
f0f5eef
Fix audit findings: typ args, set order, error handling, build integr…
septract Mar 6, 2026
85d75e7
Implement missing Lean backend features: do-notation, vectors, numeri…
septract Mar 6, 2026
1b18c07
Fix audit findings: string escaping, Nvar types, LemLib correctness, …
septract Mar 6, 2026
2345f24
Fix cross-module constant resolution, orderingEqual, Inhabited instan…
septract Mar 7, 2026
01b1bbb
Fix n+k patterns, bitwise stubs, namespace collisions, expand backend…
septract Mar 7, 2026
f8019f5
Update Lean backend documentation for accuracy and completeness
septract Mar 7, 2026
4005440
Clean up Lean backend: remove dead code, fix silent errors, simplify
septract Mar 7, 2026
ff75a8c
Add LemLib.* module hierarchy and fix class name renaming
septract Mar 7, 2026
e370cc0
Fix Lean library generation: imports, exports, class bridges, target …
septract Mar 7, 2026
0216238
Fix Lean backend: universe inference, mutual naming, namespace scopin…
septract Mar 9, 2026
1cfdd48
Add Lean target to cpp concurrency model example
septract Mar 9, 2026
3f60d05
Fix Lean backend: tabs, export constructors, match parens, indreln ty…
septract Mar 9, 2026
d014bc8
Harden LemLib: panic on unimplemented ops instead of bogus defaults
septract Mar 9, 2026
c7f6159
Fix Lean backend: class methods, BEq instances, termination, library …
septract Mar 9, 2026
d32d97d
Fix Lean backend: ppcmem-model 10/10, indreln equality, deriving BEq/Ord
septract Mar 9, 2026
5c0b595
Fix heterogeneous mutual universe mismatch; expand comprehensive tests
septract Mar 9, 2026
4d3d0ac
Update TODO.md: comprehensive list of all remaining issues
septract Mar 9, 2026
8329737
Fix propositional equality in both AST paths; add {lean} termination …
septract Mar 9, 2026
2682b1c
Eliminate partial defs: total LemLib wrappers for stringFromNat/least…
septract Mar 9, 2026
caa2592
Fix broken string comparison; update TODO with audit results
septract Mar 9, 2026
b5a890d
Audit termination annotations: all correct, no issues found
septract Mar 9, 2026
b397dba
Map rational/real/float64/float32 to distinct panic types instead of Int
septract Mar 9, 2026
fd178ed
Map int32/int64 to distinct LemInt32/LemInt64 newtype wrappers
septract Mar 9, 2026
196d631
Implement mword → BitVec mapping with 57 runtime-verified tests
septract Mar 9, 2026
96ebd6e
Skip instance generation for opaque (phantom) types
septract Mar 9, 2026
cde5752
Code quality audit: unify patterns, fix mutual indreln, add 4 tests
septract Mar 10, 2026
3d832af
Update Lean backend documentation to reflect current state
septract Mar 10, 2026
fcf0fe4
Emit default_instance as low-priority Lean instances with correct con…
septract Mar 10, 2026
cbded03
Add coverage tests and fix VectorAcc spacing + \0 escape
septract Mar 10, 2026
a76beb0
Fix top-level destructuring let and polymorphic indreln params
septract Mar 10, 2026
f0d1048
Implement Vector.slice in LemLib for VectorSub support
septract Mar 10, 2026
b0e94bf
Add indreln coverage tests for higher-order predicates and tuples
septract Mar 10, 2026
7b4cfc6
Remove dead code from lean_backend.ml
septract Mar 10, 2026
6af514a
Replace dead tyexp branches with error guards
septract Mar 10, 2026
0aaa8d5
Harden List.nth and Hashtbl.find in lean_backend.ml
septract Mar 10, 2026
f2d69fb
Clean up PR hygiene: remove scratch files, add ppcmem Lake infra, upd…
septract Mar 10, 2026
21a1c43
Add cross-user-module import test
septract Mar 10, 2026
cb5d2f6
Fix duplicate open Lem_Pervasives_extra in generated preambles
septract Mar 10, 2026
73ea5b4
Guard shared code changes to only affect Lean backend
septract Mar 10, 2026
3718c12
Fix minor review items: silent emp, setChoose sorry, variable shadowing
septract Mar 10, 2026
22b8f26
Add documentation comments for reviewer navigation
septract Mar 10, 2026
5e65381
Rename run_tests.sh to run_tests_lean.sh for clarity
septract Mar 10, 2026
865d1f9
Add Cerberus compatibility: local modules, mutual records, keyword es…
septract Apr 4, 2026
bdd0b9e
Fix multiline comments in flattened match arms
septract Apr 4, 2026
8126f9a
Fix infix parens, begin/end, class type args, abbrev ordering, keywor…
septract Apr 4, 2026
82254e7
Audit fixes, typed sorry, theorem prop equality, Cerberus test cases
septract Apr 4, 2026
bcee0f5
Fix monadic let, SetType constraints, Function.const; deduplicate tes…
septract Apr 4, 2026
22260f5
Add Ord/SetType Unit, fix cross-file Recup, skip unparseable theorems
septract Apr 4, 2026
648ebef
Fix let typed binding, multiline records, renamed mutual records, app…
septract Apr 4, 2026
6cbbd5e
Harden mutual record detection and keyword escaping
septract Apr 5, 2026
980474a
Track generated LemLib files for Lake git dependency
septract Apr 5, 2026
cb47e46
Fix deriving BEq/Ord on types with function-typed abbreviations
septract Apr 6, 2026
a8e75ca
Fix nested abbreviation expansion in deriving check, add comprehensiv…
septract Apr 6, 2026
011c8bc
Audit fixes: hetero records, field/vector parens, keyword escaping gaps
septract Apr 6, 2026
3a4da9d
Fix degenerate mutual block instances, dead code cleanup
septract Apr 6, 2026
7a694d4
Reorganize comprehensive test suite: 74 files → 36
septract Apr 6, 2026
da293cd
Fix type target_reps, per-file imports, low-priority sorry instances
septract Apr 8, 2026
29166af
Fix Inhabited on mutual types, stale opens, nested modules, abbreviat…
septract Apr 8, 2026
711e390
Use mutual def for Inhabited instances on mutual type blocks
septract Apr 9, 2026
6ff237d
Use nullary constructors for Inhabited on parameterized types
septract Apr 9, 2026
0b59281
Support declare rename for classes; add Eq/Eq0 and Ord/Ord0 renames
septract Apr 9, 2026
c8ffabd
Add fallback keyword escaping for Lean reserved names
septract Apr 9, 2026
172733f
Remove redundant keyword escaping fallback and explicit class renames
septract Apr 9, 2026
ae310d9
Tidy comprehensive test suite: merge cerberus files, fix lakefile
septract Apr 10, 2026
b8561e5
Add explicit lambda args to sorry Ord/SetType/Ord0 instance methods
septract Apr 10, 2026
f1a6509
Add 'declare {lean} skip_instances type T' to suppress auto-generated…
septract Apr 10, 2026
4889502
Document skip_instances declaration in Lean backend manual
septract Apr 10, 2026
aaf7a64
Simplify parametric Inhabited: nullary ctors only, sorry as fallback
septract Apr 10, 2026
efa53af
Unify default_value_inhabited and render_ctor_default with optional m…
septract Apr 10, 2026
e9553e9
Add 'declare {lean} inhabited type T = `expr`' for Inhabited overrides
septract Apr 10, 2026
706b658
Fix inhabited override suppressed by skip_instances
septract Apr 10, 2026
e8dadf7
Replace sorry with DAEMON for monomorphic Inhabited fallback; remove …
septract Apr 10, 2026
89cb334
Use DAEMON uniformly for all Inhabited fallbacks; add DAEMON1 for Type 1
septract Apr 10, 2026
9f6581b
Audit cleanup: fix stale comments, assert false, orphaned files, docs
septract Apr 10, 2026
8648411
Make DAEMON computable via axiom + @[implemented_by]; remove noncompu…
septract Apr 10, 2026
fc4d40b
Allow deriving BEq/Ord for all-nullary enums in mutual blocks
septract Apr 11, 2026
dff2062
Code quality audit fixes
septract Apr 11, 2026
fdcbd3a
Eliminate silent error masking and boolean blindness in Lean backend
septract Apr 11, 2026
3628a02
Replace exception swallowing, dead catch-alls, and boolean blindness
septract Apr 12, 2026
260a136
Extract tnvar_kind helper; replace try/with in src_t_has_fn
septract Apr 12, 2026
389a370
Add 'declare {lean} extra_import' to inject imports into generated files
septract Apr 12, 2026
4e42785
Add 'declare {lean} effectful val' for side-effecting target_reps
septract Apr 12, 2026
a8ea7de
Document effectful declaration in Lean backend manual
septract Apr 12, 2026
c10548f
Use thunk-based runEffectful to prevent CSE (no C needed)
septract Apr 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,44 @@ ocaml-lib/_build_zarith
tex-lib/lem-libs*.tex


# Lean backend build artifacts
.lake/
library/*.lean
!library/gen_lean_constants.lean
# Generated LemLib files are now tracked (needed for Lake git dependency).
# Regenerate with: make lean-libs
# lean-lib/LemLib/[A-Z]*.lean
tests/backends/*.lean
tests/backends/*_auxiliary.lean
tests/backends/*.ml
tests/backends/*.v
tests/backends/*.tex
tests/backends/*.html
tests/backends/*.thy
tests/backends/*Script.sml
tests/backends/lean-test/[A-Z]*.lean
tests/backends/lean-test/*_auxiliary.lean
tests/comprehensive/Test_*.lean
tests/comprehensive/*_auxiliary.lean
tests/comprehensive/lean-test/Test_*.lean
tests/comprehensive/lean-test/*_auxiliary.lean
examples/cpp/Cmm.lean
examples/cpp/Cmm_auxiliary.lean
examples/ppcmem-model/*.lean
examples/ppcmem-model/*_auxiliary.lean
!examples/ppcmem-model/lakefile.lean

# Build artifacts
_build/
main.native

# Coverage
coverage-report/
.coverage-switch/

# Local files
TODO.md

# Tool directories
.claude/
_opam/
44 changes: 41 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ install:
cp -R hol-lib "$(INSTALL_DIR)/share/lem"
# cp -R html-lib "$(INSTALL_DIR)/share/lem"
cp -R isabelle-lib "$(INSTALL_DIR)/share/lem"
cp -R lean-lib "$(INSTALL_DIR)/share/lem"
# cp -R tex-lib "$(INSTALL_DIR)/share/lem"

uninstall:
Expand All @@ -46,7 +47,7 @@ lem_dep.pdf: lem_dep.tex
pdflatex lem_dep.tex

# this runs Lem on the Lem library (library/*.lem), leaving the
# generated OCaml, Coq, HOL4, and Isabelle files to ocaml-libs,
# generated OCaml, Coq, HOL4, Isabelle, and Lean 4 files to ocaml-libs,
# hol-libs, etc.
libs_phase_1:
$(MAKE) -C library
Expand All @@ -62,6 +63,7 @@ libs_phase_2:
$(MAKE) hol-libs
$(MAKE) coq-libs
$(MAKE) isa-libs
$(MAKE) lean-libs

hol-libs:
# $(MAKE) -C library hol-libs
Expand All @@ -77,13 +79,44 @@ isa-libs:
# $(MAKE) -C library isa-libs
isabelle build -d isabelle-lib -b LEM

coq-libs:
coq-libs:
# $(MAKE) -C library coq-libs
cd coq-lib; coqc -R . Lem coqharness.v
cd coq-lib; coq_makefile -f coq_makefile.in > Makefile
$(MAKE) -C coq-lib

tex-libs:
lean-libs:
$(MAKE) -C library lean-libs

# Run the full Lean backend test suite:
# 1. Build the compiler
# 2. Regenerate and compile the Lean library (lean-lib/)
# 3. Backend tests (tests/backends/ — 12 .lem files)
# 4. Comprehensive tests (tests/comprehensive/ — 48 .lem files, 300+ assertions)
# 5. ppcmem-model example (examples/ppcmem-model/ — 10 .lem files)
# 6. cpp example (examples/cpp/ — 1 large .lem file, ~1930 lines generated)
lean-tests: bin/lem lean-libs
cd lean-lib && lake build
$(MAKE) -C tests/backends leantests
$(MAKE) -C tests/comprehensive lean
cd examples/ppcmem-model && \
../../lem -wl ign -lean \
bitwiseCompatibility.lem \
machineDefUtils.lem \
machineDefFreshIds.lem \
machineDefValue.lem \
machineDefTypes.lem \
machineDefInstructionSemantics.lem \
machineDefStorageSubsystem.lem \
machineDefThreadSubsystem.lem \
machineDefSystem.lem \
machineDefAxiomaticCore.lem && \
lake build
cd examples/cpp && \
../../lem -wl ign -lean cmm.lem && \
lake build

tex-libs:
# $(MAKE) -C library tex-libs
cd tex-lib; pdflatex lem-libs.tex
cd tex-lib; pdflatex lem-libs.tex
Expand Down Expand Up @@ -261,6 +294,7 @@ distrib: src/ast.ml version
mkdir $(DDIR)/library/isabelle
mkdir $(DDIR)/library/ocaml
cp library/*.lem $(DDIR)/library/
cp library/*_constants $(DDIR)/library/
cp library/isabelle/constants $(DDIR)/library/isabelle/
cp library/isabelle/*.lem $(DDIR)/library/isabelle/
cp library/hol/constants $(DDIR)/library/hol/
Expand All @@ -271,6 +305,9 @@ distrib: src/ast.ml version
cp ocaml-lib/*.mli $(DDIR)/ocaml-lib
cp ocaml-lib/*.mllib $(DDIR)/ocaml-lib
cp ocaml-lib/Makefile $(DDIR)/ocaml-lib
mkdir $(DDIR)/lean-lib
cp lean-lib/*.lean $(DDIR)/lean-lib
-cp lean-lib/lean-toolchain $(DDIR)/lean-lib
mkdir $(DDIR)/tex-lib
cp tex-lib/lem.sty $(DDIR)/tex-lib
cp Makefile-distrib $(DDIR)/Makefile
Expand Down Expand Up @@ -299,6 +336,7 @@ clean:
-rm -f coq-lib/Makefile
-rm -f coq-lib/coqharness.vo
-rm -f coq-lib/coqharness.glob
-rm -rf lean-lib/.lake lean-lib/build
-rm -rf src/version.ml lem library/lib_cache src/share_directory.ml
#-rm -rf lem_dep.tex lem_dep.pdf lem_dep.aux lem_dep.log

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Lem is a tool for lightweight executable mathematics, for writing,
managing, and publishing large-scale portable semantic definitions,
with export to LaTeX, executable code (currently OCaml) and
interactive theorem provers (currently Coq, HOL4, and Isabelle/HOL,
though the generated Coq is not necessarily idiomatic). It is also
interactive theorem provers (currently Coq, HOL4, Isabelle/HOL, and
Lean 4). It is also
intended as an intermediate language for generating definitions from
domain-specific tools, and for porting definitions between interactive
theorem proving systems.
Expand Down Expand Up @@ -86,6 +86,7 @@ Running `make` only generates Lem. It not generate the libraries needed to use L
- for HOL4 : `make hol-libs`
- for Isabelle: `make isa-libs`
- for Coq : `make coq-libs`
- for Lean 4 : `make lean-libs`

These targets depend on the corresponding tool being installed. If you
just want to generate the input that Lem gives to these tools, please
Expand Down Expand Up @@ -113,6 +114,7 @@ Lem has been tested against the following versions of the backend software:
* Coq: 8.16.0
* Isabelle 2022
* HOL: HOL4 Kananaskis 14
* Lean: 4.28.0 (via Lake build system)

## Examples

Expand Down
1 change: 1 addition & 0 deletions doc/manual/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ INPUT_FILES := \
backend_hol.md \
backend_isa.md \
backend_coq.md \
backend_lean.md \
backend_tex.md \
backend_html.md \
library.md \
Expand Down
81 changes: 81 additions & 0 deletions doc/manual/backend_lean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
## Lean 4

The command line option `-lean` instructs Lem to generate Lean 4 output. A module with name `Mymodule` generates a file `Mymodule.lean` and possibly `Mymodule_auxiliary.lean`.

### Compilation
Lem-generated Lean code depends on a Lem-specific Lean library found in the `lean-lib/` directory. This library (`LemLib`) provides helper definitions used by the generated output, such as set and map operations, comparison functions, and numeric utilities. Running `make lean-libs` in Lem's main directory generates Lean versions of the Lem library files into the `lean-lib/LemLib/` subdirectory. The generated library modules live under the `LemLib` namespace (e.g. `LemLib.Bool`, `LemLib.Pervasives`), and imports in generated code use this qualified form.

To compile the generated code, set up a [Lake](https://lean-lang.org/lean4/doc/setup.html) project that depends on `LemLib`. A minimal `lakefile.lean` looks like:

import Lake
open Lake DSL

package MyProject where
version := v!"0.1.0"

require LemLib from "path/to/lem/lean-lib"

@[default_target]
lean_lib MyLib where
roots := #[`MyModule]

Then run `lake build` to compile. Lem has been tested against Lean 4.28.0.

### Auxiliary Files
Lean auxiliary files contain executable tests generated from *assertions* in the input files, as well as proof obligations from *lemmata* and *theorems*. They are compiled alongside the main files by `lake build`. Assertions generate `#eval` commands that check the boolean expression at build time, printing PASS/FAIL results. Lemmata and theorems generate `theorem` declarations with `by decide`, which succeeds for decidable propositions. The command line option `-auxiliary_level auto` allows generating only the executable assertion tests.

### Recursive Definitions
Recursive function definitions are marked `partial` in the generated Lean output by default, since Lean 4 requires termination proofs for non-partial definitions. This is conservative but correct: the generated code will compile without requiring termination proofs. For functions that are structurally recursive (and therefore trivially terminating), using `declare {lean} termination_argument` with `automatic` avoids the `partial` annotation, allowing Lean to verify termination automatically.

### Inductive Relations
Lem inductive relation definitions are translated to Lean `inductive` types with a `Prop`-valued conclusion. For example, a Lem relation `indreln add : nat -> nat -> nat -> bool` generates `inductive add : Nat → Nat → Nat → Prop where`. Mutually recursive inductive relations (defined with `and`) are wrapped in Lean's `mutual`/`end` blocks.

### Machine Words
Lem's `mword` type (machine words parameterised by bit width) is mapped to Lean's `BitVec` type. All standard machine word operations (arithmetic, bitwise, comparison, conversion) have Lean target representations in the library. The `int32` and `int64` types are mapped to distinct newtype wrappers (`LemInt32`, `LemInt64`) around `Int`.

### Automatic Derivation
The Lean backend automatically derives `BEq` and `Ord` instances for generated inductive types and records, provided none of their constructor arguments have function types and the type is not part of a mutual block. This allows equality testing and comparison on most generated types without manual instance declarations. Types that cannot use `deriving` (e.g. those with function-typed fields or mutual definitions) get `sorry`-based stub instances at low priority instead.

### Inhabited Instances
The backend generates `Inhabited` instances for all types. When a safe constructor is available (nullary, or non-self-referential), it provides a real default value. When no safe constructor exists, the backend generates a `noncomputable instance` using the `DAEMON` axiom from LemLib. This satisfies Lean's `Inhabited` requirement for `partial def` without causing init-time panics, and without requiring typeclass constraints or `unsafe` code.

Types containing `DAEMON`-backed types as direct constructor arguments may trigger compile errors ("depends on noncomputable definition"). This is intentional: these types genuinely have no computable default. The fix is `skip_instances` (see below) or marking downstream code as `noncomputable`.

### Skipping Instance Generation
The `skip_instances` declaration suppresses all auto-generated typeclass instances for a type:

declare {lean} skip_instances type my_type

This skips generation of `Inhabited`, `BEq`, `Ord`, `SetType`, `Eq0`, and `Ord0` instances. The user provides these instances in a hand-written Lean file included in their Lake project. This is useful for types where the user needs full control over instance implementations (e.g. real BEq/Ord for mutual types, or computable Inhabited for types that would otherwise get DAEMON).

The declaration is scoped to the Lean backend (`{lean}`) and has no effect on other backends.

### Effectful Target Representations
Functions mapped via `target_rep` to side-effecting implementations (mutable counters, global state) should be marked with the `effectful` declaration. This prevents Lean's compiler from merging multiple calls to the same function:

declare lean target_rep function fresh_int u = `CerberusFresh.freshIntIO`
declare {lean} effectful val fresh_int

The target function should return `BaseIO α`. The backend wraps each call site in `runEffectful(...)` to extract the result. Arguments must be passed through in the target_rep body — see the general `target_rep` documentation in `backend_linking.md`.

### Extra Imports
The `extra_import` declaration injects an import into the generated Lean file:

declare {lean} extra_import `MyHandwrittenInstances`

This causes the generated `.lean` file to include `import MyHandwrittenInstances` in its import list. Use this when a generated module needs to see typeclass instances (e.g. BEq, Ord) from a hand-written Lean file. Place the declaration in the consuming `.lem` file, not the file that defines the types, to avoid circular imports.

### Automatic Renaming
Lean 4 types and values share a single namespace, unlike many other backends. The Lean backend automatically renames constants that would collide with type names in the same module or in imported modules. Additionally, certain names that clash with Lean 4 standard library type classes (such as `Add`, `Sub`, `Neg`, `Mul`, `Div`, `Mod`, `Pow`, `Min`, `Max`, `Abs`, `Not`, `Append`) are automatically renamed to avoid ambiguity.

### Relationship to Coq Backend
The Lean backend is structurally modelled on the Coq backend, as Lean 4 and Coq are similar in many respects. Key differences in the generated output include:

- Lean 4 syntax: `structure`/`where` for records, `inductive` for datatypes, `def` for definitions
- Unicode operators: `→`, `×`, `∀`, `∃` instead of ASCII equivalents
- Native record update syntax: `{ r with field := value }`
- Constructors brought into scope via `export TypeName` after each `inductive` definition
- `Inhabited` typeclass instances generated for all types (uses `noncomputable` DAEMON axiom for types without safe constructors)
- `BEq` and `Ord` derivation for types without function-typed arguments
- `sorry` for undefined/opaque terms instead of Coq's `DAEMON`
- `partial` for recursive definitions by default (can be overridden with `termination_argument`)
7 changes: 5 additions & 2 deletions doc/manual/backend_linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ A `target_rep` declaration allows specifing which _existing_ target function sho
declare hol target_rep function not x = `~` x
declare isabelle target_rep function not x = `\<not>` x
declare coq target_rep function not = `negb`
declare lean target_rep function not = `not`

declare html target_rep function not = `&not;`
declare tex target_rep function not b = `$\neg$` b
Expand All @@ -39,10 +40,11 @@ A `target_rep` declaration allows specifing which _existing_ target function sho
## Target Representations of Types

type map 'k 'v
declare ocaml target_rep type map = `Pmap.map`
declare isabelle target_rep type map = `Map.map`
declare ocaml target_rep type map = `Pmap.map`
declare isabelle target_rep type map = `Map.map`
declare hol target_rep type map = `fmap`
declare coq target_rep type map = `fmap`
declare lean target_rep type map = `Fmap`


## Infix Operations
Expand All @@ -57,6 +59,7 @@ A `target_rep` declaration allows specifing which _existing_ target function sho
declare ocaml target_rep function (&&) = infix `&&`
declare isabelle target_rep function (&&) = infix `\<and>`
declare coq target_rep function (&&) = infix `&&`
declare lean target_rep function (&&) = infix `&&`
declare html target_rep function (&&) = infix `&and;`
declare tex target_rep function (&&) = infix `$\wedge$`

Expand Down
5 changes: 3 additions & 2 deletions doc/manual/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Lem is a lightweight tool for writing, managing, and publishing large scale
semantic definitions. It is also intended as an intermediate language for
generating definitions from domain-specific tools, and for porting definitions
between interactive theorem proving systems (such as Coq, HOL4, and Isabelle).
between interactive theorem proving systems (such as Coq, HOL4, Isabelle, and Lean 4).

The language combines features familiar from functional programming languages with logical constructs.
From functional programming languages we take
Expand All @@ -30,7 +30,7 @@ inductive relations, and for assertions.

Lem typechecks its input and can
generate executable OCaml,
theorem prover definitions in Coq, HOL4 and Isabelle/HOL,
theorem prover definitions in Coq, HOL4, Isabelle/HOL, and Lean 4,
typeset definitions in LaTeX, and simple HTML.

## Supported software
Expand All @@ -41,6 +41,7 @@ Lem is tested against the following versions of the backend software:
* Coq: 8.4pl3 and 8.4pl2
* Isabelle: Isabelle-2013-2
* HOL: HOL4 Kananaskis 9
* Lean: 4.28.0

Older or newer versions of this software may work correctly with Lem, but are unsupported.

Expand Down
8 changes: 5 additions & 3 deletions doc/manual/invocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ The most basic usage of Lem is running a command like

This command loads the lem files `input1.lem` through `inputn.lem` and outputs their translation to target `target` in the same directory as the input files. Multiple target arguments are possible. For example

lem name1.lem name2.lem -ocaml -hol -isa -coq
lem name1.lem name2.lem -ocaml -hol -isa -coq -lean

creates the following files (assuming there are no type errors, and no explicit renaming in the source files):

- `name1.ml` and `name2.ml` for target `ocaml`
- `name1Script.sml`, `name2Script.sml` for target `hol`
- `Name1.thy`, `Name2.thy` for target `isa`
- `name1.v`, `name2.v` for target `coq`
- `Name1.lean`, `Name2.lean` for target `lean`

There are auxiliary files generated as well, which are discussed later.

Expand All @@ -27,6 +28,7 @@ The following command line options tell Lem to generate output for certain backe
- `-hol` generate HOL4 output
- `-isa` generate Isabelle/HOL output
- `-coq` generate Coq output
- `-lean` generate Lean 4 output

- `-tex` generate LaTeX output for each module separately. This means that for each input file, a separate output `.tex` file is created. These files contain the pretty-printed input.

Expand Down Expand Up @@ -59,7 +61,7 @@ By default Lem generates all available auxiliary output. The command-line option
`-auxiliary_level auto` causes only automatically processable output like testing code of assertions to be generated. `-auxiliary_level none` turns off the generation of auxiliary files. One can also turn off the generation of the main files and only generate the auxiliary ones using `-only_auxiliary`.

## Updating Existing Output
When using multi-file Lem developments, it might be handy to only update the output files that really changed. This allows the build-tools of backends like OCaml, HOL, Isabelle or Coq to only recompile files that really need to. Lem supports this via the command line option `-only_changed_output`.
When using multi-file Lem developments, it might be handy to only update the output files that really changed. This allows the build-tools of backends like OCaml, HOL, Isabelle, Coq or Lean to only recompile files that really need to. Lem supports this via the command line option `-only_changed_output`.

## Warnings
Lem can print warning messages about various things. Common warnings are about unused variables, name clashes that required automatic renaming of some entities or the need for pattern compilation, but there are many more. Warning options start with the prefix `wl`. They can be set to 4 different values
Expand Down
15 changes: 8 additions & 7 deletions doc/manual/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,14 @@
## Target Descriptions

target ::= {{ Backend target names }}
| hol
| isabelle
| ocaml
| coq
| tex
| html
| lem
| hol
| isabelle
| ocaml
| coq
| lean
| tex
| html
| lem

targets ::= {{ Backend target name lists }}
| { target1 ; .. ; targetn }
Expand Down
Loading