lean4-htt/library/init/data
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
..
array 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
bool feat(library/init): modify && and || precedence 2018-04-26 13:40:57 -07:00
char chore(library/init): move logic.lean => core.lean 2018-04-30 09:25:25 -07:00
fin 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
hashmap feat(library/init/data): add hashmap 2018-04-30 18:28:29 -07:00
int chore(library/init): cleanup 2018-04-30 09:25:25 -07:00
list chore(library/init): remove propext micro module 2018-04-30 09:25:26 -07:00
nat fix(library/init/data/nat/basic): performance problem 2018-05-01 11:50:54 -07:00
option refactor(library/init/control): remove init.meta.name spurious dependency 2018-04-30 11:36:07 -07:00
ordering chore(library/init): remove sum micro module 2018-04-30 09:25:26 -07:00
rbmap chore(library/init/data/rbtree,library/init/data/rbmap): remove auto_param dependency 2018-04-30 13:24:13 -07:00
rbtree chore(library/init/data/rbtree,library/init/data/rbmap): remove auto_param dependency 2018-04-30 13:24:13 -07:00
string feat(library/init/data/string/basic): add string.line_column 2018-04-30 15:55:34 -07:00
basic.lean chore(library/init): remove sum micro module 2018-04-30 09:25:26 -07:00
default.lean chore(library/init): merge sigma/lex.lean with wf.lean 2018-04-30 10:04:03 -07:00
repr.lean chore(library/init): remove sum micro module 2018-04-30 09:25:26 -07:00
set.lean refactor(init): init/category ==> init.control 2018-04-27 08:33:08 -07:00
to_string.lean chore(library/init): remove sum micro module 2018-04-30 09:25:26 -07:00
uint.lean 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