Commit graph

84 commits

Author SHA1 Message Date
Leonardo de Moura
91e1d30cf8 feat(frontends/lean/builtin_exprs): use ; in do-notation 2019-06-27 18:00:43 -07:00
Leonardo de Moura
ab487ea4ac feat(frontends/lean): allow ; instead of in in let-decls 2019-06-27 17:12:03 -07:00
Leonardo de Moura
af2d6dbd45 chore(library/init): avoid local attribute 2019-06-24 15:48:11 -07:00
Leonardo de Moura
0f43c2e2d9 feat(library/init/data/array/basic): efficient heterogeneous Array.map
This commit also removes Array.hmap.
Motivation: I wanted to use Array.hmap as an example in the paper, but
I found it would be too distracting to explain why we had `Array.hmap`
and `Array.map`.

cc @kha
2019-05-25 16:32:59 -07:00
Leonardo de Moura
40ecbb7cbc feat(library/init/control/monad): mark monadInhabited as an instance 2019-05-20 09:33:17 -07:00
Leonardo de Moura
8ab15536a7 perf(library/init/data/array/binsearch): add binSearchContains 2019-05-14 20:52:57 -07:00
Leonardo de Moura
dc71fafac1 feat(library/init/data/array): add Array.binSearch 2019-05-14 18:25:54 -07:00
Leonardo de Moura
2e4f5951e3 feat(library/init/data/array/qsort): simple quicksort
@kha I added `qsort` for sorting environment extension entries, but I am
wondering if we could use it as a benchmark in our paper. It is a pure implementation; it is
fast; it implements the real quick sort algorithm with in-place updates if the
input array is not shared. If the array is shared it performs
a single copy and then switches to in-place updates.
2019-05-14 17:46:34 -07:00
Leonardo de Moura
b717177a1a chore(library/init/data/array/basic): make sure Array.*foldl and List.*foldl have similar signatures 2019-05-07 15:23:03 -07:00
Leonardo de Moura
4e5121fb5b chore(library/init/data/array/basic): more general miterate2 mfold2 iterate2 fold2 2019-05-07 15:06:11 -07:00
Leonardo de Moura
4b4ff9bf69 feat(library/init/data/array/basic): add Array.mfor 2019-05-06 18:21:29 -07:00
Leonardo de Moura
c1fecc8939 feat(library/init/data/array/basic): add anyM and allM 2019-05-06 13:47:36 -07:00
Sebastian Ullrich
c77970a00f refactor(library): remove now-redundant parentheses 2019-05-03 13:57:21 +02:00
Leonardo de Moura
3628b39cb6 feat(library/init/lean/compiler): add simpcase transformation 2019-05-02 12:40:37 -07:00
Leonardo de Moura
81d11db5d2 chore(runtime/object): rename runtime primitives 2019-05-02 10:55:29 -07:00
Leonardo de Moura
4c9a488446 chore(library/init/data/array): naming convention
@kha Trying again :)
I started using the prefix `f` for the `Fin` version (e.g., `fswap` and
`fswapAt`). So, it seemed natural to use the prefix `f` for the `Fin`
versions of `get` and `set`.
BTW, is it too crazy to use `a[i]` (without spaces) as notation for
`a.get i`? The constraint is to make sure `f a [i]` is not ambiguous.
That is, `f a[i]` is `f (a.get i)` and `f a [i]` is `f a (i::nil)`.
This is doable with the new parser.

Then, we could have `a[i]` as notation for `a.fget i` if `i` is a `Fin`,
and `a.get i` if `i` is `Nat`.
Similarly, `a[i := v]` would be notation for `a.fset i v` if `i` is
`Fin`, and `a.set i` if `i` is `Nat`.

It would also be awesome to have
```
let a[i] := v in
e
```
as notation for
```
let a := a[i := v] in
```
2019-05-02 10:23:53 -07:00
Leonardo de Moura
970941db2c feat(library/init/data/array/basic): add Array.filter 2019-05-02 09:51:08 -07:00
Leonardo de Moura
5a83a2d7bb feat(library/init/data/array/basic): add swapAt 2019-05-02 07:46:11 -07:00
Leonardo de Moura
e52e787ad5 fix(library/init/lean/compiler/pushproj): bug and cleanup 2019-05-01 21:01:03 -07:00
Leonardo de Moura
2991b966e5 featg(library/init/lean/compiler): add pushproj 2019-05-01 17:38:44 -07:00
Leonardo de Moura
1707628b6b feat(library/init/data/array/basic): Array.reverse 2019-05-01 17:38:44 -07:00
Leonardo de Moura
af1d521706 feat(library/init/data/array/basic): add Array.swap 2019-05-01 17:38:44 -07:00
Leonardo de Moura
711fab451b refactor(library/init/data/array): Array.foldl argument order 2019-04-29 10:48:33 -07:00
Leonardo de Moura
63442ebde7 feat(library/init/data/array/basic): add iterate₂ and foldl₂ 2019-04-29 10:48:33 -07:00
Leonardo de Moura
df84868ab4 feat(library/init/data/array/basic): array helper functions 2019-04-28 10:10:24 -07:00
Leonardo de Moura
c6d0083456 fear(library/init/data/array/basic): add Array.modify 2019-04-26 14:41:17 -07:00
Leonardo de Moura
b1503f2c56 perf(library/init/data/array/basic): remove inefficient mforeachAux and add new hmmap and hmap
The `mforeachAux` function was keeping two references to the array
because it was implemented using `miterate a ⟨a, rfl⟩ ...`
Thus, we would have to allocate a new array even if `a` was not shared.

Another issue is that when invoking `x ← f i v`, the array would still
have a reference to `v`, and consequently `RC(v) > 1`, and `f` would not
be able to perform destructive updates to `v` or reuse its memory cell.

Thus, I removed `mforeach` (we only used it to implement `hmap`: the
homogeneous map), and implemented a new `hmap` which makes sure
destructive updates can be performed modulo the issue with float `let`
inwards I described in the previous commit.

@kha I found the problem described in the previous commit when I was
using `Array.hmap`. If we use `Array`s to implement `Syntax` as we discussed,
then a `hmap` that does not prevent destructive updates from happening is
a must-have. Otherwise, any benefit we get from using `Array`s instead
of `List`s is gone.
2019-04-19 14:52:52 -07:00
Leonardo de Moura
549b07a815 chore(library/init/data/array/basic): missing [inline] 2019-04-19 14:52:52 -07:00
Leonardo de Moura
62b8954ec4 chore(library/init/data/array/basic): heterogeneous Array.mmap 2019-04-19 14:52:52 -07:00
Leonardo de Moura
52b72c85bf fix(library/init/data/array/basic): typo 2019-04-12 09:03:20 -07:00
Leonardo de Moura
804ff74350 feat(library/init/data/array/basic): add Array.back 2019-04-10 08:56:42 -07:00
Leonardo de Moura
9c81cd7f1d feat(library/init/data/array/basic): add Array.extract 2019-04-07 13:08:23 -07:00
Leonardo de Moura
8d2d43beb2 feat(library/init/data/array/basic): add shrink 2019-04-07 12:42:56 -07:00
Leonardo de Moura
4d3689ea33 feat(library/init/data/array/basic): add new array functions
@kha I renamed the homogeneous `map` to `hmap`, and added the
heterogeneous one as `map`. As soon as we add user-defined rewriting
rules, we will be able to replace `map` with `hmap` whenever the types
are the same.
2019-04-06 19:25:32 -07:00
Leonardo de Moura
273a0775d6 perf(library/init/data/array): mkArray in Lean doesn't seem to buy us anything
The primitive implementation combines all `inc`'s into a single one.
2019-04-03 10:27:58 -07:00
Leonardo de Moura
568b598729 fix(library/init/data/array/basic): incorrect borrow annotation 2019-04-03 05:50:53 -07:00
Leonardo de Moura
5e1a3a7e6a feat(library/init/data/array/basic): make sure we reduce List.length too at List.toArray 2019-04-01 10:54:45 -07:00
Leonardo de Moura
e58949e938 chore(library/init/control/id): rename id monad to Id 2019-03-29 16:45:52 -07:00
Leonardo de Moura
c134617ee3 fix(library/init/data/array/basic): mkEmpty 2019-03-29 11:20:45 -07:00
Leonardo de Moura
49551036ed refactor(library/init): minor changes
Old `Nat.repeat` => `Nat.for`
Old `Nat.mrepeat` => `Nat.mfor`
New `Nat.repeat` has type
```
def repeat {α : Type u} (f : α → α) (n : Nat) (a : α) : α :=
``
`List.repeat` => `List.replicate` (like in Haskell)
Avoid weird `ℕ` in List library
2019-03-29 10:39:00 -07:00
Leonardo de Moura
229e4a25b3 refactor(library/init/array): implement mkArray in Lean, add allow mkEmpty to set initial capacity 2019-03-29 10:19:21 -07:00
Sebastian Ullrich
c8e11d289f feat(library/init/data/array/basic): new Array operations from syntax-array experiment 2019-03-29 16:02:08 +01:00
Sebastian Ullrich
a86b852d1c chore(library/init/data/array/basic): use same foldl signature as other types 2019-03-29 14:34:42 +01:00
Leonardo de Moura
895bf2c91d feat(library/equations_compiler/partial_rec): try assumption if inhabitant could not be found 2019-03-27 12:24:24 -07:00
Leonardo de Moura
87b066b87e refactor(library/init): move function.lean definitions to core.lean 2019-03-22 09:33:10 -07:00
Leonardo de Moura
452d5107ac chore(library/init/data/array): naming convention
The array read and write operations are now called:

- "Comfortable" version (with runtime bound checks):
  `Array.get` and `Array.set` like OCaml.
   It is also consistent with `Ref.get` and `Ref.put`,
   and `get` and `set` for `MonadState`.

- `Fin` version (without runtime bound checks):
  `Array.index` and `Array.update` like in F*.

- `USize` version (without runtime bound checks and unboxing):
  `Array.idx` and `Array.updt`.

cc @kha
2019-03-21 18:03:29 -07:00
Leonardo de Moura
4a08d6715a chore(library/init/data/array): add HasEmptyc instance 2019-03-21 17:06:56 -07:00
Leonardo de Moura
3befc219c9 chore(library/init): Empty => empty when it is a function 2019-03-21 17:03:15 -07:00
Leonardo de Moura
1fe3f14ad0 chore(*): Uint => UInt, Usize => USize 2019-03-21 15:06:44 -07:00
Leonardo de Moura
f8113a01eb chore(library): unit => Unit 2019-03-21 15:06:44 -07:00