Clojure functions with Lean signatures.
(leanfran.typed/defn insert-sorted [x Int xs (List Int)] (List Int) ...)
The function is an ordinary Clojure function. Its signature and body are
kept in the var's :lean/sig metadata, from which (clojure insert-sorted)
in a deflean block renders a Lean model of the function to prove things
about.
Clojure functions with Lean signatures.
(leanfran.typed/defn insert-sorted [x Int xs (List Int)] (List Int)
...)
The function is an ordinary Clojure function. Its signature and body are
kept in the var's `:lean/sig` metadata, from which `(clojure insert-sorted)`
in a `deflean` block renders a Lean model of the function to prove things
about.(attach-verification! v sig)Attach a signature without changing the root of the Var.
Attach a signature without changing the root of the Var.
(check v)(check v opts)Compare the leanfran.typed/defn function v with the Lean functions of
its verification marks on inputs generated from the signature: the results
equal those of :refines, and :ensures hold, in the order that they are
written in, on the inputs that satisfy :requires. A function that throws
fails. It runs the code that leanfran --lang clojure sync generated for the
blocks of the specifications.
Options: :num-tests, the number of inputs that satisfy :requires
(LEANFRAN_RUNS, or 200), :seed (LEANFRAN_SEED, or 1), :gens, a map from
parameter names to generators that replace the ones of their types,
:big-ints?, to generate integers on the bounds of Long and beyond (which recursion on a Nat
would take that many steps to finish), and :max-size, the largest size of
generated collections (200).
The result has :pass?, :num-tests and :seed. A failure carries
:counterexample, with the label and the shrunk arguments, and :message,
which says what failed with the seed and the number of the input.
Compare the `leanfran.typed/defn` function `v` with the Lean functions of its verification marks on inputs generated from the signature: the results equal those of `:refines`, and `:ensures` hold, in the order that they are written in, on the inputs that satisfy `:requires`. A function that throws fails. It runs the code that `leanfran --lang clojure sync` generated for the blocks of the specifications. Options: `:num-tests`, the number of inputs that satisfy `:requires` (`LEANFRAN_RUNS`, or 200), `:seed` (`LEANFRAN_SEED`, or 1), `:gens`, a map from parameter names to generators that replace the ones of their types, `:big-ints?`, to generate integers on the bounds of `Long` and beyond (which recursion on a `Nat` would take that many steps to finish), and `:max-size`, the largest size of generated collections (200). The result has `:pass?`, `:num-tests` and `:seed`. A failure carries `:counterexample`, with the label and the shrunk arguments, and `:message`, which says what failed with the seed and the number of the input.
(check-commands v)The leanfran.dsl commands of the functions that check-translation calls
for the function v: its model at the types of the check, and its inline
postcondition when present.
The `leanfran.dsl` commands of the functions that `check-translation` calls for the function `v`: its model at the types of the check, and its inline postcondition when present.
(check-translation v)(check-translation v opts)Compare the leanfran.typed/defn function v with its Lean model on
inputs generated from the signature, as clojure.test.check/quick-check,
arity by arity. The model is the one that leanfran --lang clojure sync
generated, for a function with verification marks, one that a deflean block
names in (clojure f ...), or one that such a function calls. A call where Long
arithmetic of the Clojure function overflows is outside what the model describes
and passes; one that throws another exception, and a result that is not a value of
the return type, fail. The result is that of the
first arity that fails, or of the last.
Options: those of check, and :at, the types of the type variables of a
polymorphic function ({α Int}, Int for the ones it leaves out; the
function lists other ones in its :at metadata).
A failure carries :counterexample: the arity, the shrunk arguments, and the
values of the function and of the model on them, and :message, which says
the same with the seed and the run.
Compare the `leanfran.typed/defn` function `v` with its Lean model on
inputs generated from the signature, as `clojure.test.check/quick-check`,
arity by arity. The model is the one that `leanfran --lang clojure sync`
generated, for a function with verification marks, one that a `deflean` block
names in `(clojure f ...)`, or one that such a function calls. A call where `Long`
arithmetic of the Clojure function overflows is outside what the model describes
and passes; one that throws another exception, and a result that is not a value of
the return type, fail. The result is that of the
first arity that fails, or of the last.
Options: those of `check`, and `:at`, the types of the type variables of a
polymorphic function (`{α Int}`, `Int` for the ones it leaves out; the
function lists other ones in its `:at` metadata).
A failure carries `:counterexample`: the arity, the shrunk arguments, and the
values of the function and of the model on them, and `:message`, which says
the same with the seed and the run.(defcheck name f)(defcheck name f opts)A clojure.test test that runs check on the leanfran.typed/defn
function f and reports the message of a failure.
(defcheck sort-ints-agrees sort-ints {:num-tests 200})
A `clojure.test` test that runs `check` on the `leanfran.typed/defn`
function `f` and reports the message of a failure.
(defcheck sort-ints-agrees sort-ints {:num-tests 200})(defn nm & more)Define a function with a Lean signature: [x T y U] R as in deflean.
(defn name docstring? attr-map? [x T ...] R body) (defn name docstring? attr-map? ([x T] R body) ([x T y U] R body) ...)
Binders take (implicit α Type) and (inst (BEq α)) for a polymorphic
function, and & xs (List T) last for the rest arguments.
The attribute map, or the metadata of the name, takes the verification marks
:refines spec, :requires spec and :ensures {label spec}, where a spec
names a function of a deflean block or is a single inline Bool
postcondition with % bound to the result. It also takes :termination-by and
:decreasing-by, which give Lean the termination argument of a recursive
function, and :at, the types, besides Int, at which check-translation
runs a polymorphic function: [{α String}].
Define a function with a Lean signature: `[x T y U] R` as in `deflean`.
(defn name docstring? attr-map? [x T ...] R body)
(defn name docstring? attr-map? ([x T] R body) ([x T y U] R body) ...)
Binders take `(implicit α Type)` and `(inst (BEq α))` for a polymorphic
function, and `& xs (List T)` last for the rest arguments.
The attribute map, or the metadata of the name, takes the verification marks
`:refines spec`, `:requires spec` and `:ensures {label spec}`, where a spec
names a function of a `deflean` block or is a single inline Bool
postcondition with `%` bound to the result. It also takes `:termination-by` and
`:decreasing-by`, which give Lean the termination argument of a recursive
function, and `:at`, the types, besides `Int`, at which `check-translation`
runs a polymorphic function: `[{α String}]`.(letfn fns & body)clojure.core/letfn whose functions carry Lean signatures:
[(f [x T ...] R body) ...]. A function may call the ones before it, and
itself through recur or by name.
`clojure.core/letfn` whose functions carry Lean signatures: `[(f [x T ...] R body) ...]`. A function may call the ones before it, and itself through `recur` or by name.
(loop bindings & body)clojure.core/loop whose bindings carry Lean types: [i T init ...].
:termination-by and :decreasing-by metadata on the vector give Lean the
termination argument.
`clojure.core/loop` whose bindings carry Lean types: `[i T init ...]`. `:termination-by` and `:decreasing-by` metadata on the vector give Lean the termination argument.
(rejected-commands v)The leanfran.dsl commands that stand for check-commands when Lean rejects
the models of the function v.
The `leanfran.dsl` commands that stand for `check-commands` when Lean rejects the models of the function `v`.
(verified-root? v)Whether the Var still has the root that verify annotated.
Whether the Var still has the root that verify annotated.
(verify nm attrs)Give an ordinary defn in the same source file a Lean signature and marks. Use (verify f {:sig [[T1 T2 ...] R] :ensures {label spec}}) after the defn.
Give an ordinary defn in the same source file a Lean signature and marks.
Use (verify f {:sig [[T1 T2 ...] R] :ensures {label spec}}) after the defn.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |