Idris2/libs/contrib/Data/Nat/Exponentiation.idr
Mathew Polzin f078d5f5dc
clean up some deprecations (#2057)
* deprecate Data.Nat.Order.decideLTE

* Add properties for LTE/GTE that produce the difference.

* remove deprecated function now that it is available in the base library.

* remove two deprecated lines.

* remove module deprecated since v0.4.0

* fix prelude reference to renamed primitive.

* finish removing Data.Num.Implementations

* remove deprecated dirEntry function.

* remove deprecated fastAppend. Update CHANGELOG.

* replace fastAppend in test case

* replace fastAppend uses in compiler.

* remove new properties that weren't actually very new.
2021-10-24 12:06:57 +01:00

79 lines
1.9 KiB
Idris

module Data.Nat.Exponentiation
import Data.Nat as Nat
import Data.Nat.Properties
import Data.Monoid.Exponentiation as Mon
import Data.Nat.Views
import Data.Nat.Order
import Syntax.PreorderReasoning
import Syntax.PreorderReasoning.Generic
%default total
public export
pow : Nat -> Nat -> Nat
pow = Mon.(^)
public export
lpow : Nat -> Nat -> Nat
lpow = linear @{Monoid.Multiplicative}
public export
pow2 : Nat -> Nat
pow2 = (2 ^)
public export
lpow2 : Nat -> Nat
lpow2 = lpow 2
export
modularCorrect : (v : Nat) -> {n : Nat} ->
pow v n === lpow v n
modularCorrect
= Mon.modularCorrect
@{Monoid.Multiplicative}
(sym (multAssociative _ _ _))
(irrelevantEq $ multOneLeftNeutral _)
export
pow2Correct : {n : Nat} -> pow2 n === lpow2 n
pow2Correct = modularCorrect 2
export
unfoldLpow2 : lpow2 (S n) === (lpow2 n + lpow2 n)
unfoldLpow2 = unfoldDouble
export
unfoldPow2 : pow2 (S n) === (pow2 n + pow2 n)
unfoldPow2 = irrelevantEq $ Calc $
let mon : Monoid Nat; mon = Monoid.Multiplicative
lpow2 : Nat -> Nat; lpow2 = linear @{mon} 2 in
|~ pow2 (S n)
~~ lpow2 (S n) ...( pow2Correct )
~~ lpow2 n + lpow2 n ...( unfoldLpow2 )
~~ (pow2 n + pow2 n) ...( cong2 (+) (sym pow2Correct) (sym pow2Correct) )
export
lteLpow2 : {m : Nat} -> 1 `LTE` lpow2 m
lteLpow2 {m = Z} = reflexive {rel = LTE}
lteLpow2 {m = S m} = CalcWith $
let ih = lteLpow2 {m} in
|~ 1
<~ 2 ...( ltZero )
<~ lpow2 m + lpow2 m ...( plusLteMonotone ih ih )
~~ lpow2 (S m) ...( sym (unfoldLpow2) )
export
ltePow2 : {m : Nat} -> 1 `LTE` pow2 m
ltePow2 = CalcWith $
|~ 1
<~ lpow2 m ...( lteLpow2 )
~~ pow2 m ...( sym pow2Correct )
export
pow2Increasing : {m : Nat} -> pow2 m `LT` pow2 (S m)
pow2Increasing = CalcWith $
|~ S (pow2 m)
<~ pow2 m + pow2 m ...( plusLteMonotoneRight (pow2 m) 1 (pow2 m) ltePow2 )
~~ pow2 (S m) ...( sym unfoldPow2 )