Commit graph

65 commits

Author SHA1 Message Date
Leonardo de Moura
e602ac873a feat(library/init): modify && and || precedence
The idea is to match the precedence used in regular programming
languages, where `x = y || x = z` is parsed as `(x = y) || (x = z)`.

This commit also adds `!x` as notation for `bnot x`
2018-04-26 13:40:57 -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
Sebastian Ullrich
726a5547de fix(init/core): typed_expr should accept Props
Fixes #1954
2018-04-12 16:14:47 +02:00
Leonardo de Moura
ce0467638e chore(*): remove unification hints 2018-04-10 16:29:04 -07:00
Leonardo de Moura
bcaa0b2ad3 refactor(library/typed_expr): do not use macros for implementing typed_expr
Remark: in Lean4, we will not have macro_defs.
2018-04-09 15:16:46 -07:00
Sebastian Ullrich
8f55ec4c50 fix(init/core): remove out_param from has_pow
With the current elaboration scheme, out_params and coercions do not mix well,
as evidenced by the following example by @digama:

```
variables {α : Type*} [group α]
def gpow : α → ℤ → α := sorry
instance group.has_pow : has_pow α ℤ := ⟨gpow⟩

example (a : α) : a ^ 0 = 1 := sorry -- failed to synth ⊢ has_pow α ℕ
example (a : α) : a ^ (0:ℕ) = 1 := sorry -- ok, coerces
example (a : α) : a ^ (0:ℤ) = 1 := sorry -- ok
```

The issue is that
* we first try to solve `has_pow ?α ?β`, which is postponed
* then infer `?α = nat` from `a`
* then at some point call `elaborator::synthesize()` and default `β` to `nat`
* then try to solve `has_pow nat nat`, which fails at `int =?= nat`
2018-04-04 13:05:59 +02:00
Leonardo de Moura
d387103aa2 fix(library/init/core): closes #1951
- Add has_pow type class
- Make `^` notation right associative
2018-03-29 16:25:47 -07:00
Sebastian Ullrich
3fefe94757 refactor(library/init/core,library/init/unit): make unit an abbreviation of punit.{0} 2018-03-27 10:33:04 -07:00
Sebastian Ullrich
f487989470 feat(init/core): add infer_instance 2018-03-01 16:09:10 +01:00
Sebastian Ullrich
3f497b8d8e fix(library/constructions/projection): out_params should always be implicit in projections 2018-02-02 08:58:52 -08:00
Leonardo de Moura
587540f11b feat(frontends/lean): add abbreviation command
This command is not just a cosmetic feature.
We need it to defined `id_rhs` before the tactic framework is defined.
We want `id_rhs` to be used in all definitions generated by the equation
compiler. Right now, it is only used in definitions defined after the
tactic framework.
2018-01-05 15:40:59 -08:00
Leonardo de Moura
91ff183b3e chore(library): remove out notation for out_param 2017-12-15 15:47:58 -08:00
Leonardo de Moura
f0352d31a1 feat(library/type_context, library): inout ==> out modifier in type class declarations
@kha: I decided to implement this change before I start the
type_context modifications. The change did not affect the corelib and
test suite much. The only annoying problem is that `out` cannot be
used to name locals anymore.
2017-12-15 14:46:47 -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
d9322b16ca feat(library): add has_equiv type class 2017-12-03 15:03:58 -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
51bac2918f chore(library/init/core): declare and using structure
This change was requested by several users.
2017-09-05 15:08:20 -07:00
Leonardo de Moura
4faae27069 perf(frontends/lean): add notation #[...]
The new notation should be use to input long sequences.
Closes #1755
2017-07-21 04:20:48 -07:00
Mario Carneiro
89e860ac8b doc(init/core): Document init_quotient in lean
This way people can search for "constant quot" and find it in the lean source. Plus the init_quotient command only occurs once, so this way people know what it means.
2017-07-20 01:36:28 -07:00
Gabriel Ebner
1a81425098 chore(library): convert comments to docstrings 2017-06-12 15:17:00 +02:00
Leonardo de Moura
a8173c8194 feat(library/init): heterogeneous andthen type class, and tactic.seq_focus implementation 2017-06-02 10:38:27 -07:00
Mario Carneiro
0b4cecfc87 refactor(init/core): write std.priority.max in hex 2017-05-27 04:16:23 -04:00
Mario Carneiro
0441605861 feat(init/core): add heq.rfl 2017-05-27 04:13:58 -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
2fb77c3e40 feat(library/init/core): add has_sizeof instances for psum and psigma 2017-05-23 16:24:38 -07:00
Leonardo de Moura
ba5eccdca8 refactor(library/init/core): rename out_param => inout_param
It is really input/output.
2017-05-01 14:01:41 -07:00
Leonardo de Moura
74550fbebc feat(library/init/core): add notation for out_param 2017-05-01 13:52:17 -07:00
Leonardo de Moura
5cef84709f refactor(library): avoid auxiliary definitions such as add/mul/le/etc
See Section "Other goodies" at
https://github.com/leanprover/lean/wiki/Refactoring-structures

This commit also improves the support for projections in the
unifier/matcher.

Now, we consider the extra case-split for projections.
Given a projection `proj`, and the constraint `proj s =?= proj t`, we need to try first `s =?= t` and if it fails, then try to reduce.
This is needed in the standard library because we now have constraints such as:
```
@has_le.le ?A ?s ?a ?b  =?=  @has_le.le nat nat.has_add x y
```
If we reduce the right hand side, we get the unsolvable constraint
```
@has_le.le ?A ?s ?a ?b  =?=  nat.le x y
```
Before this change, the constraint was `@le ?A ?s ?a ?b  =?=  @le nat nat.has_add x y`, and we already perform a case-split in this case.
Moreover, projections were eagerly reduced whenever possible.
The extra case-split generates a performance problem in several tests. For example `fib 8 = 34` was timing out.
I worked around this issue by performing the case-split only when the constraint contains meta-variables.
There are also minor issues. Example. `<` is notation for `has_lt.lt`, but `>` is for `gt`.
2017-05-01 08:52:19 -07:00
Leonardo de Moura
f6556ecdcc fix(library/init): missing has_sizeof instances for subtype, char and string 2017-04-15 23:31:14 -07:00
Leonardo de Moura
e0e3f51c44 feat(library/init): add unification hint for add/succ 2017-03-12 13:45:30 -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
Leonardo de Moura
2f6c4d91e4 feat(library/init/core): simplify proofs 2017-03-10 22:42:21 -08:00
Daniel Selsam
538ac8d187 feat(inductive_compiler): generate injectivity lemmas 2017-03-10 22:27:18 -08:00
Leonardo de Moura
b6f6126075 feat(frontends/lean/pp): add attribute [pp_using_anonymous_constructor] for marking structures we should use the anonymous constructor notation when pretty printing instances 2017-03-09 15:17:18 -08:00
Jeremy Avigad
95f75bbbee refactor(library/init/data/subtype/basic): rename subtype constructor and projections 2017-03-08 19:31:27 -08:00
Daniel Selsam
1f6306d068 perf(library/inductive_compiler): simplification with sizeof lemmas 2017-03-01 21:13:20 -08:00
Leonardo de Moura
10c881266b refactor(frontends/lean): add parse_lparen 2017-02-17 21:46:39 -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
32e6442d0a feat(frontends/lean): no global universes in the frontend 2017-02-08 17:23:04 -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
d3db3661af refactor(library/init/core): simpler has_sep type class with out_param 2017-01-30 18:54:56 -08:00
Leonardo de Moura
04a8518104 refactor(library/init/core): simpler has_insert type class with out_param 2017-01-30 18:50:21 -08:00
Leonardo de Moura
f176c272b4 refactor(library/init/core): simpler has_mem type class with out_param 2017-01-30 18:43:05 -08:00
Leonardo de Moura
5da8b205b9 feat(library/type_context, frontends/lean/elaborator): type classes with output parameters 2017-01-30 18:32:54 -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
3b38f71f11 fix(library,tests/lean): fix run/interactive tests, and problems in the standard library due to the new interpretation for Type
We had to change subtype to use Sort since the axiom
strong_indefinite_description uses it.

see #1341
2017-01-30 11:54:00 -08:00
Leonardo de Moura
a6f26f0b74 chore(library): poly_unit ==> punit
psum, pprod and punit are used internally.

see #1341
2017-01-30 11:54:00 -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
9107439bce feat(frontends/lean/elaborator): default parameter prototype
See #1340
2017-01-27 16:32:22 -08:00