Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- Tactic `#print` to print a symbol or the current goal.
- Export to Lean.
- Tactic `all_hyps t` calls parameterized tactic term t on all hypotheses ignoring failing calls.
- Conditional rules `l when t1 ≡ t2 ↪ r`

### Changed

Expand Down
4 changes: 4 additions & 0 deletions doc/lambdapi.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<constructor> ::= <uid> <param_list>* ":" <term>

<rule> ::= <term> "↪" <term>
| <term> when <condition> "↪" <term>

<condition> ::= <term> ≡ <term>
| <term> «[<term>] <term>

<unif_rule> ::= <equation> "↪" "[" <equation> (";" <equation>)* "]"

Expand Down
9 changes: 6 additions & 3 deletions editors/emacs/lambdapi-smie.el
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"rule"
"symbol"
"unif_rule"
"verbose")
"verbose"
"when")
lambdapi--queries)
"Commands at top level.")

Expand Down Expand Up @@ -142,7 +143,9 @@ Indent by `lambdapi-indent-basic' in proofs, and 0 otherwise."
(symdec ("symbol" args ":" sterm))
(indcons (args ":" sterm) ("|" args ":" sterm))
(inddec (inddec "with" args ":" sterm "≔" indcons))
(rules (rules "with" sterm "↪" sterm))
(rules (rules "with" sterm "↪" sterm)
(rules "with" sterm "when" condition "↪" sterm))
(condition (sterm "«[" sterm "]" sterm) (sterm "≡" sterm))
(command
("begin" prfcontent "abort" ";")
("begin" prfcontent "admitted" ";")
Expand Down Expand Up @@ -240,7 +243,7 @@ The default lexer is used because the syntax is primarily made of sexps."
"print" "proofterm" "search" "type"))
(lambdapi--query-indent))

(`(,_ . ,(or "," "↪" "→" "≡")) (smie-rule-separator kind))
(`(,_ . ,(or "«" "," "↪" "→" "≡")) (smie-rule-separator kind))

(`(,(or :before :list-intro) . ,(or "≔" ":")) (smie-rule-separator kind))
(`(:after . ,(or "≔" ":")) lambdapi-indent-basic)
Expand Down
2 changes: 2 additions & 0 deletions editors/emacs/lambdapi-vars.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"rule"
"symbol"
"unif_rule"
"when"
"with")
"Commands that enrich the signature.")

Expand Down Expand Up @@ -106,6 +107,7 @@
(modify-syntax-entry ?→ "." table)
(modify-syntax-entry ?↪ "." table)
(modify-syntax-entry ?≔ "." table)
(modify-syntax-entry ?« "." table)
(modify-syntax-entry ?$ "." table)
(modify-syntax-entry ?? "." table)
(modify-syntax-entry ?: "." table)
Expand Down
4 changes: 4 additions & 0 deletions editors/vim/syntax/lambdapi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ syntax keyword KeywordOK contained type
syntax keyword KeywordOK contained TYPE
syntax keyword KeywordOK contained unif_rule
syntax keyword KeywordOK contained verbose
syntax keyword KeywordOK contained when
syntax keyword KeywordOK contained why3
syntax keyword KeywordOK contained with
highlight link KeywordOK Keyword
Expand Down Expand Up @@ -172,6 +173,7 @@ syntax keyword KeywordKO contained type
syntax keyword KeywordKO contained TYPE
syntax keyword KeywordKO contained unif_rule
syntax keyword KeywordKO contained verbose
syntax keyword KeywordKO contained when
syntax keyword KeywordKO contained why3
syntax keyword KeywordKO contained with
highlight link KeywordKO Error
Expand Down Expand Up @@ -207,6 +209,7 @@ syntax match Keyword ","
syntax match Keyword ";"
syntax match Keyword "_"
syntax match Keyword "≡"
syntax match Keyword "«"

" Other special classes.
syntax match Type "\u\w*"
Expand All @@ -215,6 +218,7 @@ syntax match PreProc "?\(\<\h\w*\>\|\({|\([^|]\|\(|[^}]\)\)*|*|}\)\)"

" Abbreviations.
abbreviate --> ↪
abbreviate << «
abbreviate -> →
abbreviate => ⇒
abbreviate ! Π
Expand Down
2 changes: 1 addition & 1 deletion editors/vscode/syntaxes/lp.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},

"signature-commands": {
"match": "(coerce_rule|inductive|rule|symbol|unif_rule|with)\\s+([^\\s+]*)",
"match": "(coerce_rule|inductive|rule|symbol|unif_rule|with|when)\\s+([^\\s+]*)",
"captures": {
"1": {"name": "storage.type.lp"},
"2": {"name": "entity.name.function.theorem.lp"}
Expand Down
3 changes: 2 additions & 1 deletion misc/lambdapi.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
tabsize=2,
basicstyle={\ttfamily\small\upshape},
backgroundcolor=\color{lightgrey},
keywords={abort,admit,admitted,all_hyps,apply,as,assert,assertnot,associative,assume,assumption,begin,builtin,change,commutative,compute,constant,debug,end,eval,fail,flag,first_hyp,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},
keywords={abort,admit,admitted,all_hyps,apply,as,assert,assertnot,associative,assume,assumption,begin,builtin,change,commutative,compute,constant,debug,end,eval,fail,flag,first_hyp,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,when},
sensitive=true,
keywordstyle=\color{blue},
morecomment=[l]{//},
Expand All @@ -26,6 +26,7 @@
{≔}{$\coloneqq$}1
{⊢}{$\vdash$}1
{≡}{$\equiv$}1
{«}{$\ll$}1
{𝔹}{$\mathbb{B}$}1
{𝕃}{$\mathbb{L}$}1
{ℕ}{$\mathbb{N}$}1
Expand Down
2 changes: 1 addition & 1 deletion src/core/coercion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ let _ =
and t = mk_Patt (Some 1, "t", [||]) in
let lhs = [a;a;t] and arities = [|0;0|] and names = [|"A";"t"|] in
{ lhs; names; rhs=t; arity=3; arities; vars_nb=2; xvars_nb = 0;
rule_pos = None }
rule_pos = None; r_when = R_None }
in
Sign.add_rule Ghost.sign (coerce, rule)
27 changes: 27 additions & 0 deletions src/core/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,33 @@ and tree_walk : config -> sym -> stack -> (term * stack) option =
let vi = Array.map (fun id -> mk_Vari (var id)) vi in
let tj = msubst bj vi in
if eq_modulo whnf cfg vars.(i) tj then ok else fail
| CondEQ(((p1,o1) as op1,a1), ((p2,o2) as op2,a2)) ->
let v1 = List.map (fun (i,_) -> vars.(i)) a1 in
let v2 = List.map (fun (i,_) -> vars.(i)) a2 in
if Logger.log_enabled() then
log_rew "%aCondEQ(%s[%a],%s[%a]) : %s(%a) == %s(%a)"
D.depth !depth
(snd op1) (List.pp D.int ",") (List.map fst a1)
(snd op2) (List.pp D.int ",") (List.map fst a2)
(snd op1) (List.pp Raw.term ",") v1
(snd op2) (List.pp Raw.term ",") v2;
let s1 = Sign.find_qualified p1 o1 in
let s2 = Sign.find_qualified p2 o2 in
let t1 = add_args (mk_Symb s1) v1 in
let t2 = add_args (mk_Symb s2) v2 in
if eq_modulo whnf cfg t1 t2 then ok else fail
| CondST((pth,op), p1, p2) ->
let v1 = vars.(fst p1) and v2 = vars.(fst p2) in
if Logger.log_enabled() then
log_rew "%aCondST(%s,%d,%d) : %a <<[%s] %a"
D.depth !depth
op (fst p1) (fst p2) Raw.term v1 op Raw.term v2;
let rec find (p: term -> bool) (t: term) =
match unfold t with
| Appl(Appl(Symb s,a1), a2)
when s.sym_path=pth && s.sym_name=op -> p a1 || find p a2
| t -> p t in
if find (eq_modulo whnf cfg v1) v2 then ok else fail
| CondFV(i,xs) ->
let allowed =
(* Variables that are allowed in the term. *)
Expand Down
9 changes: 9 additions & 0 deletions src/core/term.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ and sym =

(** {3 Representation of rewriting rules} *)

(** optional rule constraints *)
and r_constraint =
(* equality constraint f p1 ... pn == g q1 ... qm *)
| R_EQ of (sym * int list) * (sym * int list)
(* subterm constraint p <<[op] q *)
| R_ST of sym * int * int
| R_None (* no constraint *)

(** Representation of a rewriting rule. A rewriting rule is mainly formed of a
LHS (left hand side), which is the pattern that should be matched for the
rule to apply, and a RHS (right hand side) giving the action to perform if
Expand All @@ -214,6 +222,7 @@ and sym =
{ lhs : term list (** Left hand side (LHS). *)
; names : string array (** Names of pattern variables. *)
; rhs : term (** Right hand side (RHS). *)
; r_when : r_constraint (** conditional rule constraint. *)
; arity : int (** Required number of arguments to be applicable. *)
; arities : int array
(** Arities of the pattern variables bound in the RHS. *)
Expand Down
13 changes: 11 additions & 2 deletions src/core/term.mli
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ and sym =

(** {3 Representation of rewriting rules} *)

(** optional rule constraints *)
and r_constraint =
(* equality constraint f p1 ... pn == g q1 ... qm *)
| R_EQ of (sym * int list) * (sym * int list)
(* subterm constraint p <<[op] q *)
| R_ST of sym * int * int
| R_None (* no constraint *)

(** Representation of a rewriting rule. A rewriting rule is mainly formed of a
LHS (left hand side), which is the pattern that should be matched for the
rule to apply, and a RHS (right hand side) giving the action to perform if
Expand All @@ -146,6 +154,7 @@ and rule =
{ lhs : term list (** Left hand side (LHS). *)
; names : string array (** Names of pattern variables. *)
; rhs : term (** Right hand side (RHS). *)
; r_when : r_constraint (** conditional rule constraint. *)
; arity : int (** Required number of arguments to be applicable. *)
; arities : int array
(** Arities of the pattern variables bound in the RHS. *)
Expand Down Expand Up @@ -175,8 +184,8 @@ and rule =
concrete syntax) are represented in the same way, and with a unique
name (in the rule) that is generated automatically.

Then, the term [f t u v w] matches the LHS with a substitution represented
by an array of terms [a] of length 3 if we
Then, the term [f t u v w] matches the LHS with a substitution
represented by an array of terms [a] of length 3 if we
have [a.(0) = t], [a.(1) = u], [a.(1) = v] and [a.(2) = w].

{b TODO} memorising [w] in the substitution is sub-optimal. In practice,
Expand Down
Loading
Loading