Commit graph

350 commits

Author SHA1 Message Date
Leonardo de Moura
f2df67053f feat(library/init/data/dlist): add dlist back without tactic framework dependency 2018-05-02 12:36:31 -07:00
Leonardo de Moura
45694ae44a fix(library/init/data/nat/basic): performance problem
Before this commit, given `x n : nat` the expression
```
to_bool (n <= x)
```
where `n` is a numeral <= 1024 was being elaborated as
```
@decidable.to_bool (@has_le.le.{0} nat nat.has_le n x) (nat.decidable_lt n' x)
```
where `n'` denotes the numeral `n-1`
Example:
```
to_bool (800 <= x)
```
was elaborated as
```
@decidable.to_bool (@has_le.le.{0} nat nat.has_le 800 x) (nat.decidable_lt 799 x)
```

Reason: `nat.lt` and `nat.le` were reducible. The module `type_context`
has support for solving "offset constraints" for small numerals.
These constraints include:
- `succ ?x =?= n`  ===> `?x := n - 1`

For elaborating `to_bool (800 <= x)`, we need to synthesize
```
decidable (@has_le.le.{0} nat nat.has_le 800 x)
```
using type class resolution.

The instance `nat.decidable_lt` is tried before `nat.decidable_le`. For
this instance, we need to solve the unification problem.
```
decidable (@has_lt.lt.{0} nat nat.has_lt ?n ?x) =?= decidable (@has_le.le.{0} nat nat.has_le 800 x)
```
which reduces to:
```
nat.less_than_or_equal (succ ?n) ?x =?= nat.less_than_or_equal 800 x
```
because `nat.le` and `nat.lt` are marked as `[reducible]`.
This constraint reduces to
```
succ ?n =?= 800
```
which is solved using the offset constraint support as
```
?n := 799
```

The kernel does not have support for offset constraints, and may take
a considerable amount of time to check that `succ 799` is definitionally
equal to `800`. This is particularly expensive when trust level 0 is
used.
It was taking almost 1 minute to execute the leanchecker test before
this commit because we add the new predicates for checking which
characters can be used in a Lean identifier.

This commit fixes the problem by removing the annotation `[reducible]`
from `nat.lt` and `nat.le`. This performance issue may be triggered
by any reducible instance that may create offset constraints during
type class resolution.

cc @kha
2018-05-01 11:50:54 -07:00
Leonardo de Moura
5a560b6d43 feat(library/init/data): add hashmap
We use the same approach used to define rbtree:
1- Structure with minimal number of invariants, AND
2- well_formed inductive predicate

We can use the well_formed predicate to prove auxiliary invariants later.
Example: the keys stored in every bucket have the correct hash code.

This implementation does not depend on the tactic framework,
and it is not a mess like the one in mathlib.
2018-04-30 18:28:29 -07:00
Leonardo de Moura
50b7efe00d refactor(library/init/data/array/basic): make sure init/data/array/basic does not depend on init.meta 2018-04-30 17:16:45 -07:00
Leonardo de Moura
f20f50254c feat(library/init/data/string/basic): add string.line_column 2018-04-30 15:55:34 -07:00
Leonardo de Moura
62d425073e feat(library/init/data/string/basic): add string.iterator.offset 2018-04-30 15:43:51 -07:00
Leonardo de Moura
4fa43f18dd chore(library/init/data/rbtree,library/init/data/rbmap): remove auto_param dependency
The problem is that `auto_param` is defined in the old `init/meta/name` module,
and we don't want to have `init/meta` dependencies in the `init/lean` modules.
2018-04-30 13:24:13 -07:00
Leonardo de Moura
2cb6af9769 refactor(library/init/control): remove init.meta.name spurious dependency 2018-04-30 11:36:07 -07:00
Leonardo de Moura
75a67ceb29 refactor(library/init): move option.lt 2018-04-30 11:19:38 -07:00
Leonardo de Moura
5787f17138 chore(library/init): merge sigma/lex.lean with wf.lean 2018-04-30 10:04:03 -07:00
Leonardo de Moura
1ab1b07aec chore(library/init/data/sigma/lex): remove tactic framework dependency 2018-04-30 09:55:37 -07:00
Leonardo de Moura
65e3c96b28 chore(library/init): remove sum micro module 2018-04-30 09:25:26 -07:00
Leonardo de Moura
9f18d6545c chore(library/init): remove funext and quot modules
The spaghetti initialization is almost over.
2018-04-30 09:25:26 -07:00
Leonardo de Moura
98a7aab3ac chore(library/init): remove propext micro module 2018-04-30 09:25:26 -07:00
Leonardo de Moura
eae4483d2a chore(library/init): remove setoid micro module 2018-04-30 09:25:26 -07:00
Leonardo de Moura
e2abb4ab25 chore(library/init): remove punit micro module 2018-04-30 09:25:26 -07:00
Leonardo de Moura
2503d6026e chore(library/init): remove prod micro module 2018-04-30 09:25:25 -07:00
Leonardo de Moura
e9d4780ccb chore(library/init): remove subtype micro module 2018-04-30 09:25:25 -07:00
Leonardo de Moura
9efd07d18c chore(library/init): move logic.lean => core.lean 2018-04-30 09:25:25 -07:00
Leonardo de Moura
1289037e56 chore(library/init): cleanup 2018-04-30 09:25:25 -07:00
Leonardo de Moura
6ef4806fca feat(library/init/lean/format): add lean.format 2018-04-29 14:36:49 -07:00
Leonardo de Moura
c9e4c89d9c chore(library/init/meta): remove mk_dec_eq_instance
The tactic mk_dec_eq_instance constructs a function using the brec_on
recursor. The compiler generates horrible code for this kind of
definition. It creates a closure for each recursive call.
Moreover, `brec_on` accumulates all intermediate results.

To generate efficient code, we need to generate a collection of
recursive equations, and then invoke the equation compiler.

cc @kha
2018-04-27 16:13:10 -07:00
Leonardo de Moura
21d9409629 feat(library/init/data): modify unit has_to_string and has_repr instances 2018-04-27 13:39:19 -07:00
Leonardo de Moura
ba633df7e7 chore(library/init/data): add missing instances 2018-04-27 13:39:19 -07:00
Leonardo de Moura
77d3a788e8 refactor(init): init/category ==> init.control 2018-04-27 08:33:08 -07:00
Leonardo de Moura
0af913c99f refactor(library/init/data/string): define decidable_eq string instance earlier 2018-04-27 08:16:14 -07:00
Leonardo de Moura
9e9a0d103f feat(library/vm/vm_string): add fast string.iterator.remaining 2018-04-26 18:03:41 -07:00
Leonardo de Moura
3091ca3441 feat(library/init/data/char): use bool instead of Prop for basic char predicates 2018-04-26 13:46:59 -07:00
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
Leonardo de Moura
cd4f196842 chore(library/init/data/option/basic): dead code 2018-04-25 17:19:11 -07:00
Leonardo de Moura
51e0987af2 feat(library/init/data/rbtree): add rbtree.seteq 2018-04-25 16:13:38 -07:00
Leonardo de Moura
50328d62e1 feat(library/init/data): add uint16 and make sure uint* - uses wraparound semantics like most programming languages 2018-04-20 18:27:13 -07:00
Leonardo de Moura
1ad1080f11 refactor(library): keep only basic nat theorems
All theorems are proved without using the tactic framework.
Thus, we can define `fin/uint32/uint64` types and their operations
before we define the tactic framework.
2018-04-11 16:47:54 -07:00
Leonardo de Moura
75f91df707 chore(library/init/data/fin/ops): remove unnecessary ops 2018-04-10 16:41:18 -07:00
Leonardo de Moura
ce0467638e chore(*): remove unification hints 2018-04-10 16:29:04 -07:00
Leonardo de Moura
0bcf5c8f5d chore(*): remove algebra 2018-04-10 15:53:14 -07:00
Leonardo de Moura
7aaac31e35 chore(library/init/data/nat): remove dependency 2018-04-10 15:48:13 -07:00
Leonardo de Moura
b0e49535fa chore(*): remove transfer and coinductive predicates 2018-04-10 13:38:18 -07:00
Leonardo de Moura
c03d351744 chore(library/init/data/int): keep only definitions 2018-04-10 13:29:06 -07:00
Leonardo de Moura
a023128738 chore(*): reduce corelib 2018-04-10 13:11:40 -07:00
Leonardo de Moura
a2f0bf7c1b chore(*): disable SMT tactic framework and backward chaining 2018-04-10 12:05:51 -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
0f7a8907c7 fix(init/data/default): add missing files 2018-03-22 00:15:56 +01:00
Sebastian Ullrich
23884d2863 refactor(init/data/option_t): move to init/category and adapt style 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
bcbe5ec9f4 refactor(init/category/functor): merge has_map into functor 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
97496509d7 feat(init/data/option_t): add has_monad_lift instance 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
afe3078b4b chore(init/category): final touches 2018-03-20 14:58:36 -07:00
Sebastian Ullrich
f4c2499063 chore(init/category/transformers): remove now-unused monad_transformer class, rename to lift.lean 2018-03-20 14:58:36 -07:00