Commit graph

3820 commits

Author SHA1 Message Date
Leonardo de Moura
bc89ebc19c feat(kernel/inductive): improve how induction hypotheses are named
See doc/changes.md
2017-12-05 15:58:09 -08:00
Leonardo de Moura
9dd382f649 chore(tests/lean): fix tests 2017-12-05 15:36:58 -08:00
Leonardo de Moura
a2f55e5d7b feat(library/tactic/induction_tactic): new name generator for induction and cases tactics 2017-12-05 14:57:36 -08:00
Leonardo de Moura
458958b9fc feat(kernel/inductive): use ih to name induction hypothesis (instead of ih_1) when there is only one 2017-12-05 13:50:24 -08:00
Leonardo de Moura
54004d4972 fix(library/tactic/cases_tactic): try to clear input hypothesis when performing dependent elimination
The `induction h` tactic tries to clear hypothesis `h` after it is
applied. But, before this commit, `cases h` would only try to clear `h`
when performing non-dependent elimination. This was problematic when
writing tactic scripts for automating proofs.
2017-12-05 11:03:46 -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
c943576e5a feat(library/init): add funext tactic 2017-12-04 14:54:39 -08:00
Leonardo de Moura
53c9737c70 feat(library/init): new repeat tactic 2017-12-04 12:55:53 -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
d9322b16ca feat(library): add has_equiv type class 2017-12-03 15:03:58 -08:00
Sebastian Ullrich
450ca5834c fix(frontends/lean/parser): fix debug build 2017-11-30 17:47:49 +01:00
Sebastian Ullrich
0ca9eb16c1 fix(library/type_context): preprocess_class: always solve universe mvars in inout 2017-11-29 17:21:02 -08:00
Leonardo de Moura
960832045f fix(library/type_context): failure condition 2017-11-29 14:35:58 -08:00
Leonardo de Moura
641a4548b6 fix(library/tactic/cases_tactic): use inj_arrow instead no_confusion when index is a nested and/or mutually recursive datatype
The `no_confusion` construction is only generated for inductive
datatypes supported in the kernel.
Before this commit, given `h : T`, `cases h` could leak the internal encoding
used by the inductive compiler WHEN a nested and/or mutual inductive
datatype is used to index the inductive datatype `T`.
The new test exposes the problem.

The solution implemented in this commit uses inj_arrow lemmas
generated by the inductive compiler. We only use the lemmas
if the target is a proposition. If it is not, we sign an error.
The reason for this limitation is documented in the source code.

cc @jroesch @dselsam

Jared: the information leakage has been fixed. So, students will not be
confused by the internal encoding used in the inductive compiler.
I added the example I posted on slack as a new test.
Note that, the workaround I used has been removed.
2017-11-27 21:56:35 -08:00
Sebastian Ullrich
7c63b2f046 fix(frontends/lean/parser): unicode pattern aliases 2017-11-27 12:43:15 +01:00
Sebastian Ullrich
18cf63e37f fix(frontends/lean/elaborator): avoid assertion error on delayed abstraction in structure notation 2017-11-24 21:27:55 +01:00
Leonardo de Moura
47994fe14e chore(library): remove id_locked 2017-11-22 16:29:04 -08:00
Leonardo de Moura
64f575a2d5 perf(library/equations_compiler): performance problem for definitions that produce many equational lemmas
The new test and comment at src/library/equations_compiler/util.cpp
explains the issue.
2017-11-22 16:16:11 -08:00
Leonardo de Moura
dd9d8e9552 chore(library/equations_compiler): improve comments 2017-11-22 14:55:40 -08:00
Leonardo de Moura
7d3133a845 fix(frontends/lean/structure_cmd): do not generate equation lemma for _default meta definitions 2017-11-22 12:24:51 -08:00
Sebastian Ullrich
30cfc6cf0b feat(frontends/lean/{parser,elaborator}): structure instance patterns 2017-11-22 12:16:28 -08:00
Sebastian Ullrich
511bf69dd4 chore(tests): forgot to commit structure instance test 2017-11-22 12:16:28 -08:00
Leonardo de Moura
0208755c82 fix(library/vm/vm_string): bug at VM string < 2017-11-21 16:26:36 -08:00
Sebastian Ullrich
06a316ad30 fix(frontends/lean/elaborator): type of '..' placeholders
Fixes #1870
2017-11-19 18:57:18 +01:00
Leonardo de Moura
9ea454af13 chore(tests/lean/notation2): fix test 2017-11-17 17:25:10 -08:00
Sebastian Ullrich
0aacccd8c9 feat(frontends/lean): change structure update notation
`{s with ...}` is now `{..., ..s}`, which more clearly expresses that the
result type is not necessarily equal to the type of `s` (in absence of an
expected type and a structure name, we still default to the type of `s`).

Multiple fallback sources can be given: `{..., ..s, ..t}` will fall back to
searching a field in `s`, then in `t`. The last component can also be `..`,
which will replace any missing fields with a placeholder.

The old notation will be removed in the future.
2017-11-17 16:40:47 -08:00
Sebastian Ullrich
e7e05a3ad0 feat(frontends/lean): add aliasing patterns id@pat 2017-11-17 16:35:21 -08:00
Sebastian Ullrich
aa8791a9ee fix(frontends/lean/structure_cmd): support dependent parents in new structure cmd 2017-11-17 16:31:30 -08:00
Leonardo de Moura
17172cbbdd fix(library/tactic/simplify): imp_congr was not preserving binder name 2017-11-17 12:45:04 -08:00
Leonardo de Moura
062ebf4344 fix(library/tactic/apply_tactic): when using elimator-like definitions
We found this problem when developing the red-black tree module.
2017-11-16 11:21:17 -08:00
Leonardo de Moura
7f80bf60d1 feat(library/init/data): start rbtree module 2017-11-15 16:17:39 -08:00
Leonardo de Moura
d88a6f663e fix(frontends/lean/elaborator): implicit arguments after auto_param arguments
Function applications `(f ...)` were not being elaborated correctly when
`f` has implicit parameters occurring after auto_params.
The new test exposes the problem.

This bug was found when developing the red black tree module.

This commit also fixes the following bugs:

- Invoke type class resolution again after tactic execution at
  synthesize method. Reason: metavariables occurring in type
  class instances may have been synthesized by tactics.

- mctx.assign optimization at invoke_tactic was incorrect
  when the metavariable was assigned by typing rules.
2017-11-14 17:22:12 -08:00
Leonardo de Moura
394e0d5f0a refactor(library/init): remove has_cmp and is_ordering type classes
Now, `cmp` is just a fixed helper function.
In the future, we will be able to use (more efficient) specialized
versions during code generation by defining simp rules.
2017-11-14 08:33:24 -08:00
Leonardo de Moura
49db6793f0 feat(library/init/data/ordering): cleanup ordering module, and add default cmp implementation 2017-11-13 21:55:41 -08:00
Leonardo de Moura
308bc8de4a chore(tests/lean): fix test suite 2017-11-10 16:59:09 -08:00
Leonardo de Moura
f2ef24696d perf(library/compiler/cse): make sure we eliminate common sub expressions in match-cases associated with 0-ary constructors
The new test exposes the problem. Before this commit, the common
subexpressions at

```
def tst : tree → nat
| (tree.leaf v) := v
| (tree.node v l r) :=
  match f v with
  | tt := tst l + tst l - tst l   -- <<< HERE
  | ff := tst r
  end
```

were not converted into a let-exprs.
2017-11-09 13:32:15 -08:00
Leonardo de Moura
fabf7f6380 perf(library/equations_compiler, library/compiler): expand auxiliary _match_idx definitions when generating byte code
We use the auxiliary procedure pull_nested_rec_fn to pull recursive
application in nested match expressions. This is needed because the
nested match expression is compiled before we process the recursive
procedure that contains it. This transformation may produce
performance problems if the recursive application does not depend on
the data being matched. Here is an example from the new test:

```
def tst : tree → nat
| (tree.leaf v) := v
| (tree.node v l r) :=
  match f v with
  | tt := tst l
  | ff := tst r
  end
```

pull_nested_rec_fn will convert it into

```
def tst : tree → nat
| (tree.leaf v)     := v
| (tree.node v l r) := tst._match_1 (f v) (tst l) (tst r)
```

Since our interpreter uses eager evaluation, both `(tst l)` and `(tst r)`
are executed. This commit fixes this issue by expanding `tst._match_1`
during code generation.
2017-11-09 11:14:57 -08:00
Leonardo de Moura
2c1f50cc04 fix(library/num): fixes #1862 2017-11-09 09:49:53 -08:00
Leonardo de Moura
b40f3af801 feat(library/init/meta): move rb_tree and rb_map to native namespace
cc @kha
2017-11-07 13:41:45 -08:00
Sebastian Ullrich
3930085865 fix(library/type_context): zeta-expand reflected quotations before trying to substitute local refs
Fixes #1860
2017-11-07 11:27:39 +01:00
Leonardo de Moura
426a9064bf feat(frontends/lean/builtin_cmds): display warning message if has_repr instance could not be synthesized
See issue #1861
2017-11-06 19:26:18 -08:00
Leonardo de Moura
8ffdef0b3a feat(library/vm/vm): add # when displaying simple VM objects.
See explanation at issue #1861.
2017-11-06 19:15:57 -08:00
Leonardo de Moura
e96026651b feat(library/init): add d_array type
@kha I added the `d_array` type that we discussed today.
However, the VM implemantion is still using persistent arrays.
If we remove the persistent array support, then code using
hash_map will only be efficient if the hash_map is used linearly.
This is not the case in the reader module because we are planning
to support backtracking.

On the other hand, it is awkward we currently don't have a vanilla
array implementation in the VM. I suspect this will be a problem in
the future.

So, I see the following possibilities:

1- We implement a map data-structure using red-black trees in Lean.
We use this new data-structure to implement all maps in the new reader and
macro expander.

2- We implement a very simple map as a list of pairs.
Then, we replace it in the VM with an efficient implementation.
The VM implementation may use our internal red-black trees.
We may also use a persistent hash table implemented in C++,
but it would be awkward to ask the user to provide a hash function in the reference
implementation (i.e., the one using list of pairs), but not use it
anywhere :)
In contrast, if we use the red-black tree implementation we
would have to ask the user to provide a total order.
It is overkill for the list of pair reference implementation because
we just need an equality test, but, at least, the comparison function
will be used in the implementation.

3- Add types `d_parray` (dependent persistent array) and
`parray` (persistent array). In Lean, they would just wrap the
`d_array` and `array` types. In the VM, `d_array` and `array` would
be implemented using vanilla arrays and `d_parray` and `parray` would
be implemented using persistent arrays. Then, we could have
`d_hash_map`, `hash_map`, `d_phash_map` and `phash_map`. Argh, so many
versions :(
We would use `phash_map` to implement our reader and macro expander.

4- Add a `(persistent : bool := ff)` parameter to `d_array` and
`array` types. The disadvantage of this approach is that it has
a performance impact. The VM implementation would have to check
the `persisent` flag at runtime. The value of this flag is known
at compilation time, but we currently don't have a mechanism
for specializing native builtin C++ implementations for VM functions.
2017-11-06 14:56:11 -08:00
Sebastian Ullrich
191065d963 fix(frontends/lean/elaborator): change assertion into type mismatch error
Fixes #1859
2017-11-06 10:51:37 +01:00
Floris van Doorn
1b4d2a850a test(focus): add test 2017-11-03 12:58:48 -07:00
Floris van Doorn
52ee29cb48 fix(interactive): fix focus tactic.
Previously it would fail if there was more than one goal.
2017-11-03 12:58:48 -07:00
Leonardo de Moura
91079faf97 fix(library/equations_compiler/compiler): problem introduced by recent changes
The problem was reported by @digama at slack.
2017-11-03 10:46:40 -07:00
Leonardo de Moura
cd8c154bcd feat(library/compiler/vm_compiler): clear runtime cost model
The equation compiler uses different strategies for processing
recursive equations. Some of them may produce unclear runtime cost
model. For example, the following fibonacci functions was running in
linear time instead of exponential time because the equation compiler
used the brec_on recursor.

def fib : nat → nat
| 0     := 1
| 1     := 1
| (n+2) := fib (n+1) + fib n

@dselsam and @jroesch have reported examples were the equation compiler
produces a negative performance impact. The new test (`eval` function)
captures the problem reported by @jroesch. In this example, the runtime
should not depend on the "amount of fuel".

This commit addresses this issue.
2017-11-01 14:11:09 -07:00
Leonardo de Moura
14301a7f9f feat(library/equations_compiler/compiler): generate meta auxiliary definitions for regular (recursive) definitions
Motivations:

- Clear execution cost semantics for recursive functions.

- Auxiliary meta definition may assist recursive definition unfolding in the type_context object.

Next step: use meta auxiliary definition at code generation.
2017-11-01 11:58:45 -07:00
Leonardo de Moura
482e06427b feat(library/equations_compiler): meta mutual definitions
closes #1622
2017-10-30 15:06:12 -07:00