Commit graph

1575 commits

Author SHA1 Message Date
Leonardo de Moura
98b2eb893d chore(tests/lean/run): fix tests 2017-02-17 19:55:49 -08:00
Leonardo de Moura
d3c340a30c feat(library/init/meta): improve induction tactic interface
It uses .rec recursor when it is not specified
2017-02-17 10:58:51 -08:00
Sebastian Ullrich
d15591a2d8 feat(library,frontends/lean): expose parser to Lean and use for parsing tactic parameters 2017-02-17 13:45:56 +01:00
Sebastian Ullrich
5ed1ac924c feat(frontends/lean/elaborator): support partially applied eval_expr 2017-02-17 13:03:47 +01:00
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
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
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
1306e56381 feat(library/vm): check heartbeat in function calls 2017-02-12 12:29:32 -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
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
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
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
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
Leonardo de Moura
30a1876fc8 feat(library/init/meta): add add_aux_decl and abstract tactics 2017-02-05 16:00:47 -08:00
Gabriel Ebner
95068e4e79 feat(library/sorry): make sorry a macro 2017-02-05 14:01:03 +01:00
Leonardo de Moura
dbb36f5412 feat(library/type_context): improve offset trick in the unifier 2017-02-04 17:15:05 -08:00
Leonardo de Moura
45eb64add0 chore(tests/lean/run/listex3): we don't need the unit trick anymore 2017-02-04 13:55:51 -08:00
Leonardo de Moura
9e42f7ea30 test(tests/lean/run): add test for meta recursive definition wo recursive equation 2017-02-04 13:53:12 -08:00
Leonardo de Moura
2640d3085b fix(library/init/meta/interactive): name resolution problems in parametric sections 2017-02-03 14:04:59 -08:00
Leonardo de Moura
ab94e71e37 feat(library/type_context): do not fail on universe constraints of the form ?u =?= max ?u v
We solve them by creating a fresh metavariable ?w

         ?u := max ?w v

Remark: this is a precise solution.
2017-02-02 22:30:30 -08:00
Leonardo de Moura
b2968f450c fix(frontends/lean/elaborator): use expected type when elaborating application for the form (c^.fn a)
For example, the following definition did not work before this commit:

  protected meta def map {α β} (f : α → β) : lazy_tactic α → lazy_tactic β
  | t s := (t s)^.for (λ ⟨a, new_s⟩, (f a, new_s))
2017-02-02 19:56:50 -08:00
Leonardo de Moura
9bee8ce36d fix(frontends/lean/elaborator): thunk gadget should not be considered in patterns
The new test demonstrates the problem.
2017-02-02 17:28:03 -08:00
Johannes Hölzl
3be8deb2d2 fix(library/tactic/generalize_tactic): instantiate mvars before calling kabstract 2017-02-01 18:48:10 -08:00
Leonardo de Moura
a9821f6437 fix(library/type_context): bug in revert method
We should not assume that the arguments at to_revert are sorted by idx.
This commit fixes the bug reported at:
https://groups.google.com/forum/#!topic/lean-user/x4Zwpou3le0
2017-02-01 10:51:24 -08:00
Leonardo de Moura
6e7929252f feat(frontends/lean, library/init): add 'thunk' gadget
We can now write
   trace "hello" t
instead of
   trace "hello" (fun _, t)
2017-01-31 18:41:59 -08:00
Leonardo de Moura
7cc31835e4 refactor(library/init/meta/fun_info): cleanup fun_info API 2017-01-31 18:01:54 -08:00
Leonardo de Moura
49a0d13c50 feat(library/init/coe): add coercion from A to (option A)
A little hack is used to make sure type class resolution will not enter
in an infinite loop.
2017-01-31 17:45:41 -08:00
Leonardo de Moura
920e845b84 refactor(library/init/meta/congr_lemma): cleanup congr_lemma API 2017-01-31 16:46:13 -08:00
Leonardo de Moura
2874a783e0 test(tests/lean/run/defaul_param3): more tests for default param values 2017-01-31 15:28:06 -08:00