Commit graph

3181 commits

Author SHA1 Message Date
Leonardo de Moura
efcebc60f7 feat(library/init/meta/contradiction_tactic): make it more robust 2017-02-16 21:43:34 -08:00
Leonardo de Moura
c4542d5987 chore(tests/lean): fix test 2017-02-16 21:42:51 -08:00
Leonardo de Moura
71950bdf01 fix(frontends/lean/elaborator): expression may not be an application due to error recovery
Issue described at https://groups.google.com/forum/#!topic/lean-user/uSSYhgVKKH0
2017-02-16 21:13:21 -08:00
Leonardo de Moura
54deb6362d feat(library/init/meta): add helper tactics 2017-02-16 20:49:55 -08:00
Leonardo de Moura
769220fa4e fix(library/equations_compiler): structural recursion and partial equations
The equational compiler was failing to generate equational lemmas for
equations such as:

   def f : nat → nat → nat
   | (x+1) (y+1) := f (x+10) y
   | _     _     := 1

It would fail when trying to prove the following equation:

   forall x, f 0 x = 1

using a "refl" proof. This equation does not hold definitionally.
It is not blocked by the internal pattern matching based on the
cases_on recursor, but it is blocked by the outer most brec_on
used to implement structural recursion. The solution is to
"complete" the set of equations. So, the structural_rec
module will replace the equation above with

   def f : nat → nat → nat
   | (x+1) (y+1) := f (x+10) y
   | _     0     := 1
   | _     (y+1) := 1

and then (as before)

   def f : Pi (x y : nat), below y → nat
   | (x+1) (y+1) F := F^.fst^.fst (x+10)
   | _     0     F := 1
   | _     (y+1) F := 1
2017-02-16 14:51:31 -08:00
Leonardo de Moura
7886a78967 fix(library/vm/vm): incorrect lean_vm_check 2017-02-16 11:39:23 -08:00
Leonardo de Moura
c1c1cd417a fix(frontends/lean/builtin_exprs): make sure we use internal names (i.e., names starting with _) when compiling do-blocks
@johoelzl This commit fixes the problem you reported at slack.
2017-02-15 22:45:59 -08:00
Leonardo de Moura
7ebf16ca26 fix(library/equations_compiler): performance issues at structural_rec module and equational lemma generator
There were two performance bottlenecks in the recursive equation
compiler. Both bottlenecks were due to conversion checking.

1- We allow patterns such as (x+1) in the left-hand-side of a
   recursive equation. This is kind of pattern has to be reduced
   since it is not a constructor. Moreover, when we are trying to
   compile using structural recursion, we need to find an element
   that is structurally smaller in recursive applications.
   Again, we need to use reduction since the pattern may be (x+2),
   and in the recursive application we have (x+1). Now, consider
   the following equation

         f (x+1) (y+1) := f complex_term y

   It will first check whether complex_term is structurally smaller
   than (x+1), and the compiler will timeout trying to reduce
   complex_term.

   This commit adds the following workaround. The structural
   recursion module from now on will only unfold reducible constants
   and constants marked as patterns. This is not a complete
   solution. It will timeout in the following equation:

         f (x+1) (y+1) := f (x+1000000000000) y

   For this one, we need to add a whnf "fuel" option to type_context

2- Equational lemma generation was producing lemmas that are too
   expensive to check. Suppose we the following two definitions

       | f x 0     := 1
       | f x (y+1) := f complex_term y

    and

       | g 0     y    := 1
       | g (x+1) y    := g x complex_term

    Before this commit, we would generate the following proofs for
    the second equation of each definition:

         eq.refl (f complex_term y)
         eq.refl (g x complex_term)

    This proof triggers the following definitionally equality test:

             f x     (y+1)  =?= f complex_term y
             g (x+1) y      =?= g x complex_term

    Since, we have f/g on both sides, the type checker will try
    first to unify the arguments, and may timeout trying to solve

               x  =?= complex_term
               y  =?= complex_term

    since it may take a long time to reduce `complex_term`.

    We workaround this problem by creating a slightly different
    proof.

          eq.refl (unfold_of(f x (y+1)))
          eq.refl (unfold_of(g (x+1) y))

    where unfold_of(t) is the result of applying one delta reduction
    step.
2017-02-15 21:31:28 -08:00
Gabriel Ebner
1d301b7813 feat(init/meta/smt/congruence_closure): add has_to_tactic_format instance 2017-02-15 13:38:30 -08:00
Leonardo de Moura
11d5773560 refactor(library/init/meta): remove whnf_core 2017-02-14 18:39:57 -08:00
Leonardo de Moura
1ab2bb7714 feat(frontends/lean/elaborator): eta-expand function applications until we consume all optional and auto parameters 2017-02-14 17:38:08 -08:00
Leonardo de Moura
304b5b6a20 fix(library/tactic/generalize_tactic): we must check whether the abstracted type is type correct or not 2017-02-14 13:41:49 -08:00
Leonardo de Moura
1b412b6cc0 feat(library/init/meta): new cases that reverts also composite terms
The previous `cases` tactic would only use the revert/intro idiom
for `cases h` when `h` is a hypothesis
2017-02-14 13:30:36 -08:00
Leonardo de Moura
3ced85d399 feat(library/init/meta/tactic): add kdepends_on tactic 2017-02-14 10:33:28 -08:00
Leonardo de Moura
f650a1b873 refactor(library/init/meta): avoid '_core' idiom using default parameters
I kept a few core methods (e.g., exact_core and apply_core). Reason:
if we use default parameters

    meta constant exact (e : expr) (md := semireducible) : tactic unit

then, we will not be able to write

    to_expr p >>= exact

The workaround is

    do t <- to_expr p, exact t

or
    to_expr p >>= (fun x, exact x)

One alternative is to change how we handle default parameters, and
eta-expand applications that involve default parameters.
We may also have an attribute [eta_expand]. Then

    attribute [eta_expand] foo

instructs the elaborator to automatically eta-expand foo-applications.
The attribute would give users more control, and avoid potential
performance problems. Without the attribute, then for every function
application the elaborator has to check the type and decide whether it
must be eta-expanded or not.

@gebner @kha What do you think?
2017-02-14 09:46:55 -08:00
Leonardo de Moura
8a34680916 fix(frontends/lean/elaborator): name resolution at tactic execution times with overloaded notation and aliased symbols
See https://groups.google.com/forum/#!topic/lean-user/Jja_lh28v3g
2017-02-13 21:06:49 -08:00
Rob Lewis
d6ec20304f fix(norm_num): handle embedded nat subtraction 2017-02-12 17:15:08 -08:00
Leonardo de Moura
ae0577d26e chore(tests/lean): fix tests 2017-02-12 16:50:42 -08:00
Leonardo de Moura
1306e56381 feat(library/vm): check heartbeat in function calls 2017-02-12 12:29:32 -08:00
Leonardo de Moura
e517316405 chore(tests/lean/try_for_heap): missing test output 2017-02-12 11:58:13 -08:00
Leonardo de Moura
7112f6d685 feat(library/tactic): add try_for tactic 2017-02-11 20:35:42 -08:00
Leonardo de Moura
73b1e927ff chore(tests/lean): fix tests 2017-02-11 18:37:15 -08:00
Leonardo de Moura
9210e45da0 feat(frontends/lean): add notation for ';' and '<|>' in the tactic interactive mode 2017-02-10 22:53:30 -08:00
Leonardo de Moura
8bd5a51db4 test(tests/lean/run/quote_base): add example from Bas' paper 2017-02-10 18:34:53 -08:00
Johannes Hölzl
9902a0d4d1 feat(src/library/tactic): apply_core returns list of all generated metavariables 2017-02-10 16:07:33 -08:00
Johannes Hölzl
bb136d63ab feat(src/library/tactic): tactic.cases_core returns for each new goal the used constructor, a list of introduced hypotheses, and substitutions for dependent hypotheses 2017-02-10 16:07:33 -08:00
Johannes Hölzl
d7af5515d2 feat(src/library/tactic): tactic.induction_core returns for each new goal the list of introduced hypotheses and substitutions for dependent hypotheses
Also add to_obj(buffer<vm_obj>) to construct a vm-list of vm objects.
2017-02-10 16:07:33 -08:00
Leonardo de Moura
c35108cf0d fix(library/tactic): fixes #1369
- `eval_expr` instantiate assigned metavariables occuring in the input
  expression.
- Rename pp.instantiate_goal_mvars to pp.instantiate_mvars
- `format_expr` also instantiates assigned metavariables before pretty printing
  when pp.instantiate_mvars is set to true.
2017-02-10 15:58:27 -08:00
Leonardo de Moura
7a58da1181 fix(library/tactic/user_attribute): nasty interaction between eval_expr and attribute_manager
eval_expr creates auxiliary definitions in the VM. These auxiliary
definitions are gone after the VM finishes.

We store vm_obj's in the attribute_manager.

Before this commit, Lean was crashing in the following scenario:

1- A new caching_user_attribute is defined, and the user data structure
contains closures.

2- The closures are created using eval_expr.

3- When reusing the cached values, the system crashes when trying
to apply a closure created using eval_expr. The closure points to
an auxiliary definition that has already been deleted.

The new test exposes the problem. This is not a hypothetical scenario,
the new test is based on the Lean - Mathematica integration being
developed by @rlewis1988.

The fix consists in making sure we do not cache anything if
the VM environment has been updated by eval_expr.

I believe this is acceptable behavior. eval_expr is a very low level
tactic, and I don't see a good motivation for invoking it when
constructing the cache.

BTW, the test can be relaxed if the vm_attr does not contain closures.
However, it doesn't seem to pay off.

Another potential fix would be to propagate the definitions created
by eval_expr to the main environment. However, I think this is not
acceptable.
We will be flooding the main environment with useless temporary definitions
created by `eval_expr`.

This commit also stores the environment at caching time, and make
sure the cache is only reused if the current environment is a descendant
of the the one at caching time. This is fixing a different potential
bug.
2017-02-10 15:24:01 -08:00
Leonardo de Moura
6334ff24eb fix(frontends/lean/tactic_notation): erase position information quoted terms occurring inside `[...]
See new test for understanding the problem.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2017-02-09 19:06:56 -08:00
Leonardo de Moura
c0e6314f14 fix(library/init/meta,library/tactic/elaborate): bad error position when to_expr is used outside of interactive mode 2017-02-09 18:44:50 -08:00
Leonardo de Moura
add5266df7 fix(frontends/lean, library/tactic): error position in auto quoted terms
This commit also gets rid of the redundant "elaborator failed" error
message.
2017-02-09 18:03:04 -08:00
Leonardo de Moura
898894ffaa feat(frontends/lean/parser): syntax sugar for auto_param gadget 2017-02-09 16:06:55 -08:00
Leonardo de Moura
c8bbb34e2a feat(frontends/lean): add auto_param gadget 2017-02-09 15:49:10 -08:00
Leonardo de Moura
5e397795cf fix(library/init/meta): focus tactic
This commit also add the interactive tactic 'focus'
2017-02-09 10:02:19 -08:00
Leonardo de Moura
e4b3dee526 feat(library/simplify): use custom matcher in the simplifier, and remove hack from type_context
@joehendrix This commit is implementing the matcher that postpones
implicit arguments. The lemma get_data_mk_byte can be proved without
using any hacks in the type_context unifier.

I also added the trace class: simplify.implicit_failure
If we use the command

   set_option trace.simplify.implicit_failure true

Then, the simplifier will generate a diagnostic message every time it
succeeds in the explicit part, but fails in the implicit one.

Please feel free to suggest a better name to his option.

BTW, we can now easily extend the matcher with additional features.
I'm wondering if we will eventually want to write some of these
extensions in Lean.
2017-02-08 22:24:13 -08:00
Leonardo de Moura
f5e0fc4876 fix(frontends/lean/elaborator): '{}' inside quotations 2017-02-08 17:50:17 -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
c5dc8e651a chore(library/init/meta): cleanup 2017-02-08 15:33:25 -08:00
Leonardo de Moura
7df64e6e7b feat(library/data): add lazy_list 2017-02-08 12:01:46 -08:00
Leonardo de Moura
2c0a5a5120 fix(library/compiler/erase_irrelevant): remove broken io monad optimization
It doesn't work when combined with inlining and common-subexpression-elimination
2017-02-07 21:24:31 -08:00
Leonardo de Moura
a8c91aa6fc fix(library/compiler/preprocess): expand eq.cases_on
The code generator was failing to erase eq.cases_on.
2017-02-07 21:19:01 -08:00
Leonardo de Moura
54f7bf9391 fix(frontends/lean, library/tactic): remove redundant error messages, and fix position of error messages
Summary:

We minimize the number of "'sorry' used warning messages".  We also
re-target the error to the main declaration. Example: foo._main ==> foo
We do not report for auxiliary declarations such as "_example" and
"foo.equations._eqn_1"

Get rid of the redundant error message "error : failed" for tactics.
We added "silent failures" in the tactic framework.

We do not store line/col information for tactics nested in notation
declarations.  Before this commit, we would have tactics such
as (tactic.save_info line col) nested inside of notation declarations.
2017-02-07 20:25:28 -08:00
Leonardo de Moura
a28d6a94fd feat(library/init/meta): add any_goals tactic 2017-02-06 16:23:29 -08:00
Gabriel Ebner
572c9a0de0 chore(tests/lean): fix tests after error-recovery 2017-02-06 15:15:47 +01:00
Gabriel Ebner
7946b15511 feat(frontends/lean/elaborator): recover from most errors using sorry 2017-02-06 15:15:44 +01:00
Gabriel Ebner
98f41d9b15 feat(interactive/test_single): colorized diff 2017-02-06 15:08:45 +01:00
Leonardo de Moura
55aa2023f4 feat(frontends/lean): add support for monad_fail type class in 'do' blocks 2017-02-05 20:09:08 -08:00
Leonardo de Moura
8b662d19ac feat(library/init/category/monad_fail): add monad_fail type class 2017-02-05 18:46:29 -08:00
Leonardo de Moura
797b26f402 fix(frontends/lean/tactic_notation): trace messages in nested blocks were not being displayed in the correct place 2017-02-05 18:20:10 -08:00