Commit graph

200 commits

Author SHA1 Message Date
Leonardo de Moura
118c909504 feat(frontends/lean/elaborator,library/type_context): fine grain unifier approximation control
Now, the elaborator only uses the quasi-pattern unifier approximation
for inferring the implicit motive in recursor-like applications.

This change was motivated by counterintuitive behavior associated with
this approximation. For example, before this commit

```
variables {δ σ : Type}

def ex1 : state_t δ (state_t σ id) σ :=
monad_lift (get : state_t σ id σ) -- doesn't work

def ex2 : state_t δ (state_t σ id) σ :=
do s ← monad_lift (get : state_t σ id σ), -- works
   return s
```

The first one doesn't work because when we elaborate
`@monad_lift ?m ?n ?c ?α (get : state_t σ id σ) : ?n ?α`
with expected type `state_t δ (state_t σ id) σ`
It first produces the following unification problem by processing
matching the inferred type with the expected one.
```
?n ?α =?= state_t δ (state_t σ id) σ
==> (approximate using first-order unification)
?n := state_t δ (state_t σ id)
?α := σ
```

Then we try to solve
```
?m ?α =?= state_t σ id σ
==> instantiate metavars
?m σ =?= state_t σ id σ
==> (approximate since it is a quasi-pattern unification constraint)
?m := λ σ, state_t σ id σ
```

Remark: the constraint is not a Milner pattern because `σ` is in
the local context of `?m`. By assuming it is a Milner pattern,
we are ignoring the other possible solutions:
```
?m := λ σ', state_t σ id σ
?m := λ σ', state_t σ' id σ
?m := λ σ', state_t σ id σ'
```

We need the quasi-pattern approximation for elaborating recursors.
So, this commit enable this kind of approximation only when
elaborating recursors and executing induction-like tactics.

If we had used first-order unification, then we would have produced
the right answer: `?m := state_t σ id`

Haskell would solve this example since it always uses
first-order unification during elaboration.

The second one works because when we elaborate
`monad_lift (get : state_t σ id σ)`, the expected type is `state_t δ (state_t σ id) ?α`.
So, `?m ?α =?= state_t σ id σ` will not considered to be a quasi-pattern
since `?α` is not yet assigned to a local constant.

We are not fully confident this commit produces a better user
experience. We know that

- Full higher-order unification (used in Lean2) produces a combinatoric
explosion, and generates a lot of non-termination in complex type class
hierarchies (monad library, has_coe, etc). The problem is that
higher-order unification manages to create new solutions that we
cannot find using first-order unification.

- Lean3 is more reliable than Lean2 for elaborating monadic code because
 it does not use higher-order unification.

- For elaborating recursor-like applications, we need at least the
quasi-patterns. We need it when trying to infer the implicit
motive. First-order unification works poorly in this case.  Note that
the lack of higher-order unification in Lean3 forces us to provide the
motive explicitly for terms that Lean2 can elaborate.

- We need quasi-patterns for solving unification constraints in the
induction-like tactics. Similar to the previous item. We use it to infer
the motive. (edited) I will try to disable the quasi-pattern
approximation when elaborating regular applications. At least, we will
behave like Haskell for this kind of application.
2018-04-24 15:09:19 -07:00
Sebastian Ullrich
a7688a10b8 feat(frontends/lean/definition_cmds): elaborate a def's type separately when explicit return type is given 2018-04-20 09:59:09 -07:00
Leonardo de Moura
a2f0bf7c1b chore(*): disable SMT tactic framework and backward chaining 2018-04-10 12:05:51 -07:00
Leonardo de Moura
24d5a1592d fix(library/init): add simp lemmas for auto_param and opt_param 2017-12-09 09:59:00 -08:00
Leonardo de Moura
6d96741010 feat(library): provide names for constructor arguments
Motivation: `cases` and `induction` tactics use these names when the
user does not provide them.
2017-12-04 16:25:16 -08:00
Leonardo de Moura
b7322e28c1 feat(library): do not using simp lemmas for sorting arguments of AC operators by default 2017-12-03 15:03:58 -08:00
Leonardo de Moura
b6c8551753 feat(library): add to_bool lemmas 2017-12-03 15:03:58 -08:00
Leonardo de Moura
ae0f5642d3 feat(library/data/rbtree): find_insert_of_not_eqv lemmas
Remark: the balance2 case (dual of balance1) is still missing.
2017-11-20 21:27:19 -08:00
Leonardo de Moura
13b0070c20 feat(library/init/logic): double negation helper lemmas 2017-11-13 21:51:35 -08:00
Leonardo de Moura
d4f2bb77b8 feat(frontends/lean): recursive equation preprocessor
To make the equation compiler more convenient to use, we will add a
couple of preprocessing steps.
This commit adds the first one of them. In this step, we use
type inference to refine pattern variables, and we relax the
restrictions on inaccessible annotations.

We will also add a preprocessing step that implements the "complete
transition" step before we execute the elim_match step.
2017-08-18 15:06:11 -07:00
Mario Carneiro
97815e4eb3 feat(init/logic): false.elim eliminates to Sort 2017-08-17 11:42:55 +02:00
Mario Carneiro
cc81118892 refactor(init/data): move out some nat lemmas 2017-07-26 11:52:10 +01:00
Jeremy Avigad
5fd113f50f feat(library/init/logic): add simp rule for 'true implies p' 2017-07-05 14:26:04 -07:00
Mario Carneiro
8920d55f8d feat(init/logic): decidability of partial functions 2017-07-05 12:37:54 -07:00
Mario Carneiro
90fc8b1d45 feat(init/logic): mark dif_pos and dif_neg as @[simp]
This is needed for simplifying `dite` after a case split
2017-07-05 12:37:54 -07:00
Sebastian Ullrich
c8d6b40991 refactor(frontends/lean/builtin_exprs,library): suppose ~> assume : 2017-07-05 11:20:10 -07:00
Sebastian Ullrich
f024ccd75d refactor(frontends/lean/token_table,library): take ~> assume 2017-07-05 11:20:10 -07:00
Leonardo de Moura
b86847ec72 fix(library/init/logic): mark eq.substr with [elab_as_eliminator]
See issue #1718
2017-07-03 17:27:41 -07:00
Gabriel Ebner
1a81425098 chore(library): convert comments to docstrings 2017-06-12 15:17:00 +02:00
Mario Carneiro
f5aa07953b chore(init/logic): slightly more efficient decidability of iff, xor 2017-05-27 04:16:25 -04:00
Mario Carneiro
b827df8b49 refactor(init/logic): remove "contrapos" (which is a duplicate of "mt") 2017-05-27 04:14:03 -04:00
Mario Carneiro
20e630ad19 refactor(init/funext): shorten proof 2017-05-27 04:13:59 -04:00
Leonardo de Moura
62c24f9bb5 chore(*): remove pos_num and num from stdlib 2017-05-25 18:24:16 -07:00
Leonardo de Moura
290e7b9cff feat(library/init): use Sort instead of Type for defining acc and well_founded 2017-05-23 16:40:45 -07:00
Mario Carneiro
5d89a93fce feat(library/data/hash_map): verified hash_map 2017-05-16 14:38:43 -07:00
Johannes Hölzl
2c85bb5a4d feat(library/init/logic): generalize implies_true_iff
this generalizes the domain of implies_true_iff from `Prop` to all `Sort`.
With this there is no need for `intros; trivial` after `simp`.
2017-03-28 18:44:56 -07:00
Leonardo de Moura
71685e4dd6 feat(frontends/lean): add support for t.<id> and t.<idx> when t is a composite term
Replace `^.` with `.` in the stdlib
2017-03-28 17:47:49 -07:00
Leonardo de Moura
87932f1c56 feat(frontends/lean): change notation for inaccessible patterns
The following are accepted
 .(t)
 ._

We don't accept .t anymore because it will conflict with the field
access notation.
2017-03-28 16:09:15 -07:00
Leonardo de Moura
3a4cd38ba9 chore(library/init): remove reducible annotations for id, const, etc, and move $ notation to core.lean 2017-03-11 11:34:16 -08:00
Daniel Selsam
538ac8d187 feat(inductive_compiler): generate injectivity lemmas 2017-03-10 22:27:18 -08:00
Johannes Hölzl
4c88e2c5b0 feat(library/init/data/int): use relators for proof of int is a ring 2017-03-07 19:30:51 -08:00
Leonardo de Moura
0c6108ce7a chore(library/init/data/quot): use Sort instead of Type
Remark: The kernel was already using Sort. So, the limitation was
artificial. Moreover, it may seem unnecessary to have quotients of
proofs in a proof irrelevant system, but this is useful for proving
a more general funext lemma. This more general version is needed in
the new tested contributed by @digama0.
2017-03-07 14:29:57 -08:00
Mario Carneiro
793017b190 feat(library/init/logic.lean): add Sort -> Prop universe lift 2017-03-07 14:01:59 -08:00
Leonardo de Moura
4608782669 fix(init/logic): eq.mpr and eq.mp can be use for type casting
So, they should be `def`. Otherwise code generation will fail.
2017-03-06 09:13:39 -08:00
Leonardo de Moura
6134a4a70e feat(library/init): basic operations for (fin n) 2017-03-05 16:00:02 -08:00
Leonardo de Moura
7b0a18167b feat(library/constructions/drec): add drec_on and refactor 2017-03-01 14:12:10 -08:00
Leonardo de Moura
17556758cb feat(library/constructions,library/inductive_compiler): automatically generate dependent eliminator for inductive predicates
The dependent eliminator for an inductive predicate C is called C.drec

TODO: construct dcases_on and drec_on using C.drec

We need this recursor for implementing dependent elimination for
inductive predicates.

We don't need to define acc.drec and eq.drec in the standard library anymore.
2017-02-28 20:58:04 -08:00
Leonardo de Moura
32e6442d0a feat(frontends/lean): no global universes in the frontend 2017-02-08 17:23:04 -08:00
Leonardo de Moura
41bf46dbba chore(library/init): adjust Sort vs Type in definitions 2017-01-30 12:50:18 -08:00
Leonardo de Moura
77a9feaf70 refactor(frontends/lean): PType ==> Sort
see #1341
2017-01-30 11:54:00 -08:00
Leonardo de Moura
bf9f7560f7 feat(frontends/lean): (Type u) can't be a proposition
(Type u)  is the old (Type (u+1))
(PType u) is the old (Type u)
Type*     is the old (Type (_+1))
PType*    is the old Type*

The stdlib can be compiled, but we still have > 70 broken tests

See discussion at #1341
2017-01-30 11:54:00 -08:00
Leonardo de Moura
3f124f1a15 feat(library/init/logic): add decidable instance for ite and dite 2017-01-26 18:42:46 -08:00
Jeremy Avigad
2b6487065c feat(library/init/logic): make iff a structure 2017-01-22 14:19:00 -08:00
Leonardo de Moura
8e76d079d3 chore(tests/lean/run): fix tests 2017-01-17 15:50:54 -08:00
Leonardo de Moura
d2e393c779 feat(library/init/logic): allow exists.intro to be used in pattern matching 2017-01-12 16:03:01 -08:00
Leonardo de Moura
5e3f26ec95 feat(library/tactic/smt/congruence_closure): propagate not_exists 2017-01-06 14:00:36 -08:00
Leonardo de Moura
9b35adfc8c feat(library/tactic/congruence/congruence_closure): add support for constructor equalities 2016-12-25 12:47:17 -08:00
Leonardo de Moura
b1b694a532 fix(library/tactic/congruence/congruence_closure): bugs, and add basic cc tactic 2016-12-23 19:30:45 -08:00
Leonardo de Moura
48cd421852 feat(library/tactic/congruence): add congruence closure basics 2016-12-21 20:46:25 -08:00
Jeremy Avigad
da6dfa6fdd feat(library/init/logic): alternative theorem names, and make some arguments explicit 2016-12-08 07:19:38 -08:00