Idris2Doc : Data.Prim.Integer.Extra

Data.Prim.Integer.Extra

(source)
Additional utilites for solving and deriving
(in)equalities in `Integer` arithmetics.

Reexports

importpublic Data.Prim.Integer

Definitions

0pairPlusCommutative : (w+x=x+w, y+z=z+y)
  Allows us to commute addition on both sides of an inequality.

Totality: total
Visibility: export
0pairMultCommutative : (w*x=x*w, y*z=z*y)
  Allows us to commute multiplication on both sides of an inequality.

Totality: total
Visibility: export
dataRel : (Integer->Integer->Type) ->Integer->Integer->Type
  Type describing a relation between two integers.

This is used to solve integer (in)equalities with
a syntax that is similar to the one used for preorder
reasoning.

Totality: total
Visibility: public export
Constructors:
(<) : (x : Integer) -> (y : Integer) ->Rel(<)xy
(<=) : (x : Integer) -> (y : Integer) ->Rel(<=)xy
(===) : (x : Integer) -> (y : Integer) ->Rel(===)xy
(>=) : (x : Integer) -> (y : Integer) ->Rel(>=)xy
(>) : (x : Integer) -> (y : Integer) ->Rel(>)xy
0rel : Relrxy-> (u : Integer) -> (v : Integer) ->Relruv
Totality: total
Visibility: public export
App : a-> (a->b) ->b
  Reversed function application.

Totality: total
Visibility: export
0(|>) : Relrxy->rxy->rxy
  The identity function for relations.

Totality: total
Visibility: export
Fixity Declarations:
infixl operator, level 0
prefix operator, level 1
0(<>) : (a->b) -> (b->c) ->a->c
  Reversed function composition.

Totality: total
Visibility: export
Fixity Declaration: infixl operator, level 0
0(...) : Relrxy-> (Relrxy->a->rxy) ->a->rxy
  Thought bubble similar to the one used in
`Syntax.PreorderReasoning`.

Totality: total
Visibility: export
Fixity Declarations:
infix operator, level 1
infix operator, level 1
0(..=) : Relrxz->y=z->rxy->rxz
  Replace the right hand side of an (in)equality.

Totality: total
Visibility: export
Fixity Declaration: infix operator, level 1
0(..~) : Relrxz->z=y->rxy->rxz
  Replace the right hand side of an (in)equality.

Totality: total
Visibility: export
Fixity Declaration: infix operator, level 1
0(=..) : Relrxz->y=x->ryz->rxz
  Replace the left hand side of an (in)equality.

Totality: total
Visibility: export
Fixity Declaration: infix operator, level 1
0(~..) : Relrxz->x=y->ryz->rxz
  Replace the left hand side of an (in)equality.

Totality: total
Visibility: export
Fixity Declaration: infix operator, level 1
0(=.=) : Relrwz-> (x=w, y=z) ->rxy->rwz
  Replace both sides of an (in)equality.

Totality: total
Visibility: export
Fixity Declaration: infix operator, level 1
0(~.~) : Relrwz-> (w=x, z=y) ->rxy->rwz
  Replace both sides of an (in)equality.

Totality: total
Visibility: export
Fixity Declaration: infix operator, level 1
0plusLeft : Relr (z+x) (z+y) ->rxy->r (z+x) (z+y)
  Adding a value on the left does not affect an inequality.

```idris example
|> x < y
<> z + x < z + y ... plusLeft
```

Totality: total
Visibility: export
0plusRight : Relr (x+z) (y+z) ->rxy->r (x+z) (y+z)
  Adding a value on the right does not affect an inequality.

```idris example
|> x < y
<> x + z < y + z ... plusRight
```

Totality: total
Visibility: export
0plusPosRight : 0<y->x< (x+y)
  The result of adding a positive value is greater than
the original.

Totality: total
Visibility: export
0plusPosLeft : 0<y->x< (y+x)
  The result of adding a positive value is greater than
the original.

Totality: total
Visibility: export
0plusNonNegRight : 0<=y->x<= (x+y)
  The result of adding a positive value is not less than
the original.

Totality: total
Visibility: export
0plusNonNegLeft : 0<=y->x<= (y+x)
  The result of adding a positive value is not less than
the original.

Totality: total
Visibility: export
0plusNegRight : y<0-> (x+y) <x
  The result of adding a negative value is greater than
the original.

Totality: total
Visibility: export
0plusNegLeft : y<0-> (y+x) <x
  The result of adding a negative value is greater than
the original.

Totality: total
Visibility: export
0plusNonPosRight : y<=0-> (x+y) <=x
  The result of adding a positive value is not less than
the original.

Totality: total
Visibility: export
0plusNonPosLeft : y<=0-> (y+x) <=x
  The result of adding a positive value is not less than
the original.

Totality: total
Visibility: export
0minus : Relr (x-z) (y-z) ->rxy->r (x-z) (y-z)
  Subtracting a value does not affect an inequality.

```idris example
|> x < y
<> x - z < y - z ... minus
```

Totality: total
Visibility: export
0minusLT : x<y->0< (y-x)
  Subtracting a value from a larger one
yields a positive result.

Totality: total
Visibility: export
0minusLTE : x<=y->0<= (y-x)
  Subtracting a value from a non-smaller one
yields a non-negative result.

Totality: total
Visibility: export
0minusGT : x<y-> (x-y) <0
  Subtracting a value from a smaller one
yields a negative result.

Totality: total
Visibility: export
0minusGTE : x<=y-> (x-y) <=0
  Subtracting a value from a non-greater one
yields a non-positive result.

Totality: total
Visibility: export
0solvePlusRight : Relrxy->r (x+z) (y+z) ->rxy
  We can solve (in)equalities, where the same value has
been added on both sides.

```idris example
|> x + z < y + z
<> x < y ... solvePlusRight
```

Totality: total
Visibility: export
0solvePlusLeft : Relrxy->r (z+x) (z+y) ->rxy
  We can solve (in)equalities, where the same value has
been added on both sides.

```idris example
|> z + x < z + x
<> x < y ... solvePlusLeft
```

Totality: total
Visibility: export
0solveMinus : Relrxy->r (x-z) (y-z) ->rxy
  We can solve (in)equalities, where the same value has
been subtracted from both sides.

```idris example
|> x - z < y - z
<> x < y ... solveMinus
```

Totality: total
Visibility: export
0solvePlusRightZero : Relr (negy) x->r0 (x+y) ->r (negy) x
  We can solve (in)equalities, with one side an addition
and the other equalling zero.

```idris example
|> 0 < x + y
<> neg y < x ... solvePlusRightZero
```

Totality: total
Visibility: export
0solvePlusRightSelf : Relr0x->ry (x+y) ->r0x
  We can solve (in)equalities, with one side an addition
and the other equalling the added value.

```idris example
|> y < x + y
<> 0 < x ... solvePlusRightSelf
```

Totality: total
Visibility: export
0solvePlusLeftZero : Relr (negx) y->r0 (x+y) ->r (negx) y
  We can solve (in)equalities, with one side an addition
and the other equalling zero.

```idris example
|> 0 < x + y
<> neg x < y ... solvePlusLeftZero
```

Totality: total
Visibility: export
0solvePlusLeftSelf : Relr0y->rx (x+y) ->r0y
  We can solve (in)equalities, with one side an addition
and the other equalling the added value.

```idris example
|> x < x + y
<> 0 < y ... solvePlusLeftSelf
```

Totality: total
Visibility: export
0solveMinusZero : Relryx->r0 (x-y) ->ryx
  We can solve (in)equalities, with one side a subtraction
and the other equalling zero.

```idris example
|> 0 < x - y
<> y < x ... solveMinusZero
```

Totality: total
Visibility: export
0plusOneLTE : x<y-> (x+1) <=y
Totality: total
Visibility: export
0negate : Relr (negy) (negx) ->rxy->r (negy) (negx)
  Negating both sides inverts an inequality.

```idris example
|> x <= y
<> neg y <= neg x ... negate
```

Totality: total
Visibility: export
Fixity Declaration: prefix operator, level 10
0negateNeg : Relryx->r (negx) (negy) ->ryx
  Negating both sides inverts an inequality.

```idris example
|> neg x <= neg y
<> y <= x ... negateNeg
```

Totality: total
Visibility: export
0negateZero : Relr (negx) 0->r0x->r (negx) 0
  `negate` specialized to where one side equals zero.

```idris example
|> x < 0
<> 0 < neg x ... negateZero
```

```idris example
|> x <= 0
<> 0 <= neg x ... negateZero
```

Totality: total
Visibility: export
0negateNegZero : Relrx0->r0 (negx) ->rx0
  `negate` specialized to where one side equals zero and the other
a negated value.

```idris example
|> neg x < 0
<> 0 < x ... negateNegZero
```

```idris example
|> neg x <= 0
<> 0 <= x ... negateNegZero
```

Totality: total
Visibility: export
0multPosLeft : 0<z->Relr (z*x) (z*y) ->rxy->r (z*x) (z*y)
  Multiplication with a positive number preserves an inequality.

```idris example
|> x < y
<> z * x < z * y ... multPosLeft zgt0
```

```idris example
|> x <= y
<> z * x <= z * y ... multPosLeft zgt0
```

Totality: total
Visibility: export
0multPosRight : 0<z->Relr (x*z) (y*z) ->rxy->r (x*z) (y*z)
  Multiplication with a positive number preserves an inequality.

```idris example
|> x < y
<> x * z < y * z ... multPosRight zgt0
```

```idris example
|> x <= y
<> x * z <= y * z ... multPosRight zgt0
```

Totality: total
Visibility: export
0multNegLeft : z<0->Relr (z*y) (z*x) ->rxy->r (z*y) (z*x)
  Multiplication with a negative number reverses an inequality.

```idris example
|> x < y
<> z * y < z * x ... multNegLeft zgt0
```

```idris example
|> x <= y
<> z * y <= z * x ... multNegLeft zgt0
```

Totality: total
Visibility: export
0multNegRight : z<0->Relr (y*z) (x*z) ->rxy->r (y*z) (x*z)
  Multiplication with a negative number reverses an inequality.

```idris example
|> x < y
<> y * z < x * z ... multNegRight zgt0
```

```idris example
|> x <= y
<> y * z <= x * z ... multNegRight zgt0
```

Totality: total
Visibility: export
0multNonNegRight : 0<=z->Rel(<=) (x*z) (y*z) ->x<y-> (x*z) <= (y*z)
  Multiplication with a non-negative number weakens an inequality.

```idris example
|> x < y
<> x * z <= y * z ... multNonNegRight zgte0
```

Totality: total
Visibility: export
0multNonNegLeft : 0<=z->Rel(<=) (z*x) (z*y) ->x<y-> (z*x) <= (z*y)
  Multiplication with a non-negative number weakens an inequality.

```idris example
|> x < y
<> z * x <= z * y ... multNonNegLeft zgte0
```

Totality: total
Visibility: export
0multNonPosRight : z<=0->Rel(<=) (y*z) (x*z) ->x<y-> (y*z) <= (x*z)
  Multiplication with a non-positive number weakens and
reverses an inequality.

```idris example
|> x < y
<> y * z <= x * z ... multNonPosRight zgte0
```

Totality: total
Visibility: export
0multNonPosLeft : z<=0->Rel(<=) (z*y) (z*x) ->x<y-> (z*y) <= (z*x)
  Multiplication with a non-positive number weakens and
reverses an inequality.

```idris example
|> x < y
<> z * y <= z * x ... multNonPosLeft zlte0
```

Totality: total
Visibility: export
0solveMultPosLeft : 0<d->Relrxy->r (d*x) (d*y) ->rxy
  We can solve (in)equalities, where both sides have
been multiplied with the same positive value.

```idris example
|> z * x < z * y
<> x < y ... solveMultPosLeft zgt0
```

Totality: total
Visibility: export
0solveMultPosRight : 0<d->Relrxy->r (x*d) (y*d) ->rxy
  We can solve (in)equalities, where both sides have
been multiplied with the same positive value.

```idris example
|> x * z < y * z
<> x < y ... solveMultPosRight zgt0
```

Totality: total
Visibility: export
0solveMultNegLeft : d<0->Relryx->r (d*x) (d*y) ->ryx
  We can solve (in)equalities, where both sides have
been multiplied with the same negative value.

```idris example
|> z * x < z * y
<> y < x ... solveMultNegLeft zlt0
```

Totality: total
Visibility: export
0solveMultNegRight : d<0->Relryx->r (x*d) (y*d) ->ryx
  We can solve (in)equalities, where both sides have
been multiplied with the same negative value.

```idris example
|> x * z < y * z
<> y < y ... solveMultNegLeft zlt0
```

Totality: total
Visibility: export
0solveMultPosRightZero : 0<y->Relr0x->r0 (x*y) ->r0x
  We can solve (in)equalities, with one side a multiplication
with a positive number and the other equalling zero.

```idris example
|> 0 < x * y
<> 0 < x ... solveMultPosRightZero ygt0
```

Totality: total
Visibility: export
0solveMultNegRightZero : y<0->Relrx0->r0 (x*y) ->rx0
  We can solve (in)equalities, with one side a multiplication
with a negative number and the other equalling zero.

```idris example
|> 0 < x * y
<> x < 0 ... solveMultNegRightZero ylt0
```

Totality: total
Visibility: export
0solveMultPosLeftZero : 0<x->Relr0y->r0 (x*y) ->r0y
  We can solve (in)equalities, with one side a multiplication
with a positive number and the other equalling zero.

```idris example
|> 0 < x * y
<> 0 < y ... solveMultPosLeftZero xgt0
```

Totality: total
Visibility: export
0solveMultNegLeftZero : x<0->Relry0->r0 (x*y) ->ry0
  We can solve (in)equalities, with one side a multiplication
with a negative number and the other equalling zero.

```idris example
|> 0 < x * y
<> y < 0 ... solveMultNegLeftZero xlt0
```

Totality: total
Visibility: export
0solveMultPosRightSelf : 0<y->Relr1x->ry (x*y) ->r1x
  We can solve (in)equalities, with one side a multiplication
with a positive number and the other equalling the positive
number.

```idris example
|> y < x * y
<> 1 < x ... solveMultPosRightSelf ygt0
```

Totality: total
Visibility: export
0solveMultPosLeftSelf : 0<x->Relr1y->rx (x*y) ->r1y
  We can solve (in)equalities, with one side a multiplication
with a positive number and the other equalling the positive
number.

```idris example
|> x < x * y
<> 1 < y ... solveMultPosLeftSelf xgt0
```

Totality: total
Visibility: export
0solveMultNegRightSelf : y<0->Relrx1->ry (x*y) ->rx1
  We can solve (in)equalities, with one side a multiplication
with a negative number and the other equalling the negative
number.

```idris example
|> y < x * y
<> x < 1 ... solveMultNegRightSelf ylt0
```

Totality: total
Visibility: export
0solveMultNegLeftSelf : x<0->Relry1->rx (x*y) ->ry1
  We can solve (in)equalities, with one side a multiplication
with a negative number and the other equalling the negative
number.

```idris example
|> x < x * y
<> y < 1 ... solveMultNegLeftSelf xlt0
```

Totality: total
Visibility: export
0multDivP1 : 0<d-> (d* ((n `div` d) +1)) >n
Totality: total
Visibility: export
0multDiv : 0<d-> (d* (n `div` d)) <=n
Totality: total
Visibility: export
0divNonNeg : 0<=n->0<d->0<= (n `div` d)
Totality: total
Visibility: export
0modLTE : 0<=n->0<d-> (n `mod` d) <=n
Totality: total
Visibility: export
0modOneIsZero : n `mod` 1=0
Totality: total
Visibility: export
0divOneSame : n `div` 1=n
Totality: total
Visibility: export
0divGreaterOneLT : 0<n->1<d-> (n `div` d) <n
Totality: total
Visibility: export
0divPos : d<=n->0<d->0< (n `div` d)
Totality: total
Visibility: export