Commit Graph

117 Commits

Author SHA1 Message Date
Mathew Polzin
6ca03acd71
Add replaceWhen for lists. (#755) 2020-11-27 19:10:08 +00:00
Matus Tejiscak
f64163de1f Merge branch 'unscheme' into master 2020-10-11 08:20:01 +02:00
Ohad Kammar
0c1a124704
Division theorem (#695)
Division Theorem. For every natural number `x` and positive natural
number `n`, there is a unique decomposition:
`x = q*n + r`
with `q`,`r` natural and `r` < `n`.

`q` is the quotient when dividing `x` by `n`
`r` is the remainder when dividing `x` by `n`.

This commit adds a proof for this fact, in case
we want to reason about modular arithmetic (for example, when dealing
with binary representations). A future, more systematic, development could
perhaps follow: @clayrat 's (idris1) port of Coq's binary arithmetics:

    https://github.com/sbp/idris-bi/blob/master/src/Data/Bin/DivMod.idr
    https://github.com/sbp/idris-bi/blob/master/src/Data/Biz/DivMod.idr
    https://github.com/sbp/idris-bi/blob/master/src/Data/BizMod2/DivMod.idr

In the process, it bulks up the stdlib with:
+ a generic PreorderReasoning module for arbitrary preorders,
analogous for the equational reasoning module
+ some missing facts about Nat operations.
+ Refactor some Nat order properties using a 'reflect' function

Co-authored-by: Ohad Kammar <ohad.kammar@ed.ac.uk>
Co-authored-by: G. Allais <guillaume.allais@ens-lyon.org>
2020-10-06 13:09:02 +01:00
G. Allais
4a61146ba0
[ fix #705 ] Normalise primitives in mkPat (#718)
[ log ] prettier log for pats & clauses
[ re #650 ] Even lazier
[ fix #705 ] normalise primitives in mkPat
[ refactor ] introduce getPrimitiveNames
2020-10-02 12:22:57 +01:00
Arnaud Bailly
85f5d00054 fix totality annotation on some Nat functions 2020-09-30 10:51:51 +01:00
Ruslan Feizerahmanov
1d99a28176
Add Bifunctor interface (#701) 2020-09-30 10:51:07 +01:00
G. Allais
3df1f9c476
[ fix #63 ] interleaving let binders and local declarations (#691) 2020-09-28 13:15:22 +01:00
G. Allais
d105dd11a7
[ breaking ] remove List1 related ambiguities (#690) 2020-09-22 15:07:40 +01:00
Ohad Kammar
e77b9b4631
[minor] Make base/Data.Nat.divNatNZ compile-time reducible (#689)
Co-authored-by: Ohad Kammar <ohad.kammar@ed.ac.uk>
2020-09-22 09:53:05 +01:00
Matus Tejiscak
e73c6ae3c6 Add comments to fastUnpack and fastConcat. 2020-09-19 19:19:09 +02:00
Matus Tejiscak
63c3ebf124 Remove ambiguities. 2020-09-19 14:46:12 +02:00
Matus Tejiscak
5f9c94a4e1 Fix access modifiers of fastUnpack and fastConcat. 2020-09-19 14:43:08 +02:00
Matus Tejiscak
5360adcc23 String-related stdlib tweaks. 2020-09-19 14:22:54 +02:00
Guillaume ALLAIS
65e194e9bb [ re #660 ] Positivity checking for empty types 2020-09-14 18:37:47 +01:00
Ohad Kammar
2ae330785b
[contrib] Add misc libraries to contrib (#667)
* [contrib] Add misc libraries to contrib

Expose some `private` function in libs/base that I needed, and seem like
their visibility was forgotten

I'd appreciate a code review, especially to tell me I'm
re-implementing something that's already elsewhere in the library

Mostly extending existing functionality:
* `Data/Void.idr`: add some utility functions for manipulating absurdity.
* `Decidable/Decidable/Extra.idr`: add support for double negation elimination in decidable relations
* `Data/Fun/Extra.idr`:
  + add `application` (total and partil) for n-ary functions
  + add (slightly) dependent versions of these operations
* `Decidable/Order/Strict.idr`: a strict preorder is what you get when
  you remove the diagonal from a pre-order. For example, `<` is the
  associated preorder for `<=` over `Nat`.
  Analogous to `Decidable.Order`. The proof search mechanism struggled
  a bit, so I had to hack it --- sorry.

Eventually we should move `Data.Fun.Extra.Pointwise` to `Data.Vect.Quantifiers` in base
but we don't have any interesting uses for it at the moment so it's not
urgent.

Co-authored by @gallais
2020-09-14 16:22:46 +01:00
Shay Lewis
53c2bf5885 make constructor injectivity proofs use arguments at 0 multiplicity 2020-09-09 19:57:12 +01:00
G. Allais
937aa8fc43
[ refactor ] introducing Namespace (#638)
Until now namespaces were stored as (reversed) lists of strings.
It led to:

* confusing code where we work on the underlying representation of
  namespaces rather than say what we mean (using `isSuffixOf` to mean
  `isParentOf`)

* potentially introducing errors by not respecting the invariant cf.
  bug report #616 (but also name generation in the scheme backend
  although that did not lead to bugs as it was self-consistent AFAICT)

* ad-hoc code to circumvent overlapping interface implementation when
  showing / pretty-printing namespaces

This PR introduces a `Namespace` newtype containing a list of strings.
Nested namespaces are still stored in reverse order but the exposed
interface aims to support programming by saying what we mean
(`isParentOf`, `isApproximationOf`, `X <.> Y` computes to `X.Y`, etc.)
irrespective of the underlying representation.
2020-09-05 09:41:31 +01:00
Guillaume ALLAIS
529944267b Revert "[ refactor ] Introducing Namespace and ModuleIdent (#631)"
This reverts commit 481dc431e7.
2020-09-04 09:16:06 +01:00
G. Allais
481dc431e7
[ refactor ] Introducing Namespace and ModuleIdent (#631)
Until now namespaces were stored as (reversed) lists of strings.
It led to:

* confusing code where we work on the representation rather than say
  what we mean (e.g. using `isSuffixOf` to mean `isParentOf`)

* potentially introducing errors by not respecting the invariant cf.
  bug report #616 (but also name generation in the scheme backend
  although that did not lead to bugs as it was self-consistent AFAICT)

* ad-hoc code to circumvent overlapping interface implementations when
  showing / pretty-printing namespaces

This introduces a Namespace newtype containing non-empty lists of
strings. Nested namespaces are still stored in reverse order but the
exposed interface aims to support programming by saying what we mean
(`isParentOf`, `isApproximationOf`, `X <.> Y` computes to `X.Y`, etc.)
irrespective of the underlying representation.
2020-09-02 20:05:33 +01:00
0xd34df00d
7dbafae052 Port Idris 1's Data.Vect.Quantifiers 2020-08-31 12:34:13 +01:00
Guillaume ALLAIS
1d4c84171d [ refactor ] suggested during SPLV
Main change
===========

The main change is to the type of function dealing with an untouched
segment of the local scope. e.g.

```
weak : {outer, vars : _} -> (ns : List Name) ->
       tm (outer ++ inner) -> tm (outer ++ ns ++ inner)
```

Instead we now write

```
weak : SizeOf ns -> tm (outer ++ inner) -> tm (outer ++ ns ++ inner)
```

meaning that we do not need the values of `outer`, `inner` and `ns`
at runtime. Instead we only demand a `SizeOf ns` which is a `Nat`
together with an (erased) proof that `ns` is of that length.

Other modifications
===================

Quadratic behaviour
-------------------

A side effect of this refactor is the removal of two sources of
quadratic behaviour. They typically arise in a situation where
work is done on a scope of the form

```
outer ++ done ++ ns ++ inner
```

When `ns` is non-empty, some work is performed and then the variable
is moved to the pile of things we are `done` with. This leads to
recursive calls of the form `f done` -> `f (done ++ [v])` leading
to a cost quadratic in the size of `ns`.

Now that we only care about `SizeOf done`, the recursive call is
(once all the runtime irrelevant content is erased) for the form
`f n` -> `f (S n)`!

More runtime irrelevance
------------------------

In some places we used to rely on a list of names `vars` being
available. However once we only care about the length of `vars`,
the fact it is not available is not a limitation.

For instance a `SizeOf vars` can be reconstructed from an environment
assigning values to `vars` even if `vars` is irrelevant. Indeed the
size of the environment is the same as that of `vars`.
2020-08-27 10:14:55 +01:00
Guillaume ALLAIS
d9c0e5938e [ fix ] succInjective does not use its arguments 2020-08-27 10:14:55 +01:00
Matus Tejiscak
f69443985b Revert addition to ES preamble. 2020-08-25 10:25:45 +02:00
Matus Tejiscak
e9e5ef3d6a Fix FFI specifier. 2020-08-25 10:23:07 +02:00
Matus Tejiscak
1eaecc5d66 Implement stringConcat in Node. 2020-08-25 09:46:35 +02:00
Matus Tejiscak
969a6e1a45 Make fastAppend a deprecated alias of fastConcat. 2020-08-24 19:51:23 +02:00
Matus Tejiscak
362d2204ab Make fastAppend a foreign call. 2020-08-24 19:51:22 +02:00
Arnaud Bailly
8ecf664ff6
Port Decidable.Order from Idris1 (#543) 2020-08-18 22:26:56 +01:00
G. Allais
0a7ea69df5
[ refactor ] introduce List1 to remove impossible case (#520) 2020-08-04 20:03:18 +01:00
Edwin Brady
2761a27357
Merge pull request #476 from nickdrozd/algebra-implementations
Add some algebra implementations
2020-08-04 13:21:12 +01:00
Ohad Kammar
5cfbac4a51 Add irrelevance annotations to Data.List functions taking NonEmpty 2020-07-30 06:01:42 +01:00
Alex Gryzlov
69612bf6bf
Add list lemmas (#491) 2020-07-29 10:51:07 +01:00
Ohad Kammar
915b7bea38 Add various instances from stdlib interfaces (Eq, Ord, DecEq)
For Void and Either

This is because I ended up using them elsewhere, so why not include them in the stdlib.

Also expose left/rightInjective functions, as are used in the DecEq proofs.
2020-07-26 10:47:38 +01:00
Niklas Larsson
8a210d536e
Merge pull request #408 from melted/buffer_api
Add concatBuffers and splitBuffer to Data.Buffer
2020-07-21 10:43:17 +02:00
Jonathan Chan
dab2b0d146 Export (~>) publicly.
If `(~>)` isn't publicly exported, the type checker doesn't know that `Mor` constructs something of type `~>`.
2020-07-20 15:55:24 +01:00
Nick Drozd
a2bdf8e6d7 Add some algebra implementations 2020-07-17 08:25:20 -05:00
G. Allais
0908e76515
[ fix #346 ] Pull List.length into prelude (#450) 2020-07-14 12:15:57 +01:00
Nicolas Biri
aba76206c9 Remove dependency to Vector length in deleteAt 2020-07-14 09:45:33 +01:00
Nick Drozd
6519b5608d Further simplify List 2020-07-12 21:00:33 -05:00
Nick Drozd
718da3d7e6 Simplify Vect 2020-07-12 20:59:00 -05:00
Edwin Brady
b3bb73cfd6
Merge pull request #455 from edwinb/export-nat-prfs
Data.Nat proofs should be exported
2020-07-10 23:30:09 +01:00
Edwin Brady
58e28170ac Data.Nat proofs should be exported
I assumed these were copied directly from the Idris 1 libraries, where
there was an %access directive that we don't have any more.
2020-07-10 22:59:46 +01:00
Jan de Muijnck-Hughes
fcbfcf6fe2 Added take to Vect. 2020-07-10 21:00:38 +01:00
Ohad Kammar
eceaf98007 Generalise cons-specialised linear zipWith to linear zipWith (lzipWith) 2020-07-10 17:17:19 +01:00
Ohad Kammar
8f09ef9b93 Include a (non-linear) definition for transpose that uses zipWith,
as it might be easier to reason about, since users may already have proved
stuff about zipWith that they want to reuse
2020-07-10 12:47:05 +01:00
Rui Barreiro
2feb4b8299 Merge branch 'master' of github.com:idris-lang/Idris2 into javascript 2020-07-07 14:18:00 +01:00
Nick Drozd
2ae6e06565 Simplify Fin 2020-07-07 10:48:23 +01:00
Nick Drozd
7d1ee9dd08 Simplify Equality 2020-07-07 10:48:23 +01:00
Nick Drozd
48fe4382eb Simplify List 2020-07-07 10:48:23 +01:00
Nick Drozd
877f3702ad Simplify Maybe 2020-07-07 10:48:23 +01:00