Commit graph

45 commits

Author SHA1 Message Date
Leonardo de Moura
8a93d2770e feat(library/equations_compiler): add new cache support to equation compiler 2018-02-21 15:04:20 -08:00
Leonardo de Moura
3535b0f870 refactor(library/equations_compiler/structural_rec): do no use mk_fresh_name 2018-02-21 15:04:19 -08:00
Leonardo de Moura
d428eca8a7 fix(library/equations_compiler,frontends/lean): private name support and alias generation for auxialiary declarations
fixes #1804

Remark: now, all auxiliary definitions in a private declaration share
the same "private" prefix.
2017-09-11 16:46:56 -07:00
Gabriel Ebner
246d71f3ff feat(library/equations_compiler): error recovery 2017-07-16 05:17:38 -07:00
Gabriel Ebner
50821c9fac feat(library/equations_compiler): unpack counter-examples in wf recursion 2017-07-06 22:04:58 -07:00
Leonardo de Moura
9cb94847cb fix(library/equations_compiler): propagate m_ignore_if_unused flag 2017-06-22 17:01:31 -07:00
Gabriel Ebner
40bf75cbff fix(library/equations_compiler/structural_rec): fix indices 2017-05-07 15:52:39 +02:00
Leonardo de Moura
cabb4350d9 feat(library): instances are not reducible by default anymore
Motivation: see "Other goodies" section at
https://github.com/leanprover/lean/wiki/Refactoring-structures

We had to add a new transparency mode: Instances at type_context.
In this mode, instances and reducible definitions are considered
transparent.

The new mode is used in the defeq_canonizer, code generator,
and sizeof lemma generation at inductive_compiler.

We also use the new mode in the unfold tactics.
2017-04-26 14:10:11 -07:00
Leonardo de Moura
959fa737eb fix(library/equations_compiler/structural_rec): motive for brec_on 2017-03-05 09:50:38 -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
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
Leonardo de Moura
707cf45a26 refactor(library/type_context): rename whnf_pred => whnf_head_pred 2017-02-15 20:20:27 -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
0e3a8758dc fix(library/equations_compiler/structural_rec): bug when synthesizing equational lemmas 2017-01-30 11:51:07 -08:00
Leonardo de Moura
aa0abd5cef fix(library/equations_compiler/structural_rec): bug in decoder 2016-12-18 22:51:02 -08:00
Leonardo de Moura
b75e8b99f5 fix(library/equations_compiler/structural_rec): missing case: reflexive inductive type eliminating into Prop
see #1199
2016-11-23 13:56:01 -08:00
Leonardo de Moura
823357462e feat(library/equations_compiler/structural_rec): validation 2016-09-23 13:50:55 -07:00
Leonardo de Moura
c8e13cd391 feat(frontends/lean): minimize errors being reported 2016-09-23 09:20:31 -07:00
Leonardo de Moura
5e5285ee67 refactor(library): rename pr1/pr2 ==> fst/snd 2016-09-21 09:48:39 -07:00
Leonardo de Moura
89f62edaf0 refactor(library): reduce dependecies on old code, simplify normalize module 2016-09-19 22:12:34 -07:00
Leonardo de Moura
9d9f2b2636 fix(library/equations_compiler/structural_rec): bug at check_arg_type 2016-09-18 18:36:20 -07:00
Leonardo de Moura
194d1be0dd fix(library/equations_compiler/structural_rec): reflexive type support 2016-09-18 16:15:31 -07:00
Leonardo de Moura
7fb407d2fd fix(library/equations_compiler/structural_rec): typo 2016-09-16 07:56:28 -07:00
Leonardo de Moura
e6dd5242fc feat(library/equations_compiler): add option eqn_compiler.zeta 2016-09-10 14:00:16 -07:00
Leonardo de Moura
50ef0185d9 fix(library/equations_compiler/structural_rec): missing relaxed_whnf 2016-09-10 12:14:00 -07:00
Leonardo de Moura
96fa8856bc feat(library/equations_compiler): add mk_nonrec 2016-09-08 14:09:05 -07:00
Leonardo de Moura
14d009ce92 refactor(library/equations_compiler): improve mk_equation_lemma 2016-09-08 11:50:58 -07:00
Leonardo de Moura
bedb508a8f feat(library/equations_compiler): do not generate bytecode for lemmas 2016-09-06 15:14:47 -07:00
Leonardo de Moura
c9cee9a702 feat(library/equations_compiler): add flag indicating whether we are compiling a lemma or not 2016-09-06 15:09:54 -07:00
Leonardo de Moura
01107f7aae feat(library/equations_compiler): generate bytecode for auxiliary definitions 2016-09-06 13:29:12 -07:00
Leonardo de Moura
d8caecff49 refactor(library/exception): avoid throw_generic_exception functions 2016-09-06 12:37:56 -07:00
Leonardo de Moura
cfbffb41ef feat(library/equations_compiler): prove equation lemmas that use if-then-else 2016-09-03 13:23:09 -07:00
Leonardo de Moura
13f0d4e09a refactor(library/equations_compiler): new equation lemma generation
The idea is to generate a lemma based on the left-hand-side provided by
the user. This feature is essential for supporting the derived inductive
datatype constructors.
2016-09-02 14:04:09 -07:00
Leonardo de Moura
bf096eb292 chore(library/equations_compiler/structural_rec): "lemmas" ==> "equations" 2016-09-02 11:17:38 -07:00
Leonardo de Moura
54fd9adb47 feat(library/equations_compiler): use defeq simplifier to cleanup types of automatically synthesized lemmas 2016-08-31 15:54:03 -07:00
Leonardo de Moura
51a338d9a1 fix(library/equations_compiler/structural_rec): support for reflexive inductive datatypes 2016-08-31 10:46:32 -07:00
Leonardo de Moura
924c98832b feat(library/equations_compiler/structural_rec): generate eqn lemmas at structural_rec 2016-08-31 09:07:17 -07:00
Leonardo de Moura
33514dd6ea feat(library/equations_compiler/structural_rec): process aux lemmas 2016-08-30 20:09:57 -07:00
Leonardo de Moura
2fc0e5fa05 feat(library/equations_compiler/structural_rec): add aux definition 2016-08-30 18:33:24 -07:00
Leonardo de Moura
230db1bc92 feat(library/equations_compiler/structural_rec): generate brec_on-based function
We still need to generate lemmas and induction principle.
2016-08-29 15:58:13 -07:00
Leonardo de Moura
f1f45cc2b7 feat(library/equations_compiler/structural_rec): better support for structural recursion (based on brec_on)
For example, before this commit, structural_rec would not support the
function to_nat defined below.

```
set_option new_elaborator true

inductive foo : bool → Type
| Z  : foo ff
| O  : foo ff → foo tt
| E  : foo tt → foo ff

definition to_nat : ∀ {b}, foo b → nat
| .ff Z     := 0
| .tt (O n) := to_nat n + 1
| .ff (E n) := to_nat n + 1
```
2016-08-29 10:51:09 -07:00
Leonardo de Moura
b08af16d5f refactor(library/equations_compiler): remove unnecessary abstraction
We changed how we are going to process derived inductive datatypes.
2016-08-29 09:25:01 -07:00
Leonardo de Moura
7669e18c77 feat(library/equations_compiler): add unbounded_rec 2016-08-16 12:54:54 -07:00
Leonardo de Moura
532a38befa feat(library/equations_compiler/structural_rec): finish structural recursion step 2016-08-16 08:08:51 -07:00
Leonardo de Moura
8b67480cee feat(library/equations_compiler): add step for handling structural recursion 2016-08-15 18:00:25 -07:00