| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Plutarch.Internal.Numeric
Synopsis
- data PPositive (s :: S)
- data Positive
- data PNatural (s :: S)
- class PAdditiveSemigroup (a :: S -> Type) where
- class PAdditiveSemigroup a => PAdditiveMonoid (a :: S -> Type) where
- class PAdditiveMonoid a => PAdditiveGroup (a :: S -> Type) where
- class PMultiplicativeSemigroup (a :: S -> Type) where
- class PMultiplicativeSemigroup a => PMultiplicativeMonoid (a :: S -> Type) where
- class (PAdditiveGroup a, PMultiplicativeMonoid a) => PRing (a :: S -> Type) where
- pfromInteger :: forall (s :: S). Integer -> Term s a
- class (PRing a, POrd a) => PIntegralDomain (a :: S -> Type) where
- positiveToInteger :: Positive -> Integer
- toPositiveAbs :: Integer -> Positive
- ptryPositive :: forall (s :: S). Term s (PInteger :--> PPositive)
- ppositive :: forall (s :: S). Term s (PInteger :--> PMaybe PPositive)
- ptryNatural :: forall (s :: S). Term s (PInteger :--> PNatural)
- pnatural :: forall (s :: S). Term s (PInteger :--> PMaybe PNatural)
- ppositiveToNatural :: forall (s :: S). Term s (PPositive :--> PNatural)
- pnaturalToPositiveCPS :: forall (a :: S -> Type) (s :: S). Term s a -> (Term s PPositive -> Term s a) -> Term s PNatural -> Term s a
- pbySquaringDefault :: forall (a :: S -> Type) (s :: S). (forall (s' :: S). Term s' a -> Term s' a -> Term s' a) -> Term s a -> Term s PPositive -> Term s a
- pdiv :: forall (s :: S). Term s (PInteger :--> (PInteger :--> PInteger))
- pmod :: forall (s :: S). Term s (PInteger :--> (PInteger :--> PInteger))
- pquot :: forall (s :: S). Term s (PInteger :--> (PInteger :--> PInteger))
- prem :: forall (s :: S). Term s (PInteger :--> (PInteger :--> PInteger))
Types
data PPositive (s :: S) Source #
Since: 1.10.0
Instances
Since: 1.10.0
Instances
| Arbitrary Positive Source # | Since: 1.10.0 |
| CoArbitrary Positive Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric Methods coarbitrary :: Positive -> Gen b -> Gen b | |
| Function Positive Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric | |
| Show Positive Source # | Since: 1.10.0 |
| Eq Positive Source # | Since: 1.10.0 |
| Ord Positive Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric | |
| Pretty Positive Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric | |
data PNatural (s :: S) Source #
Since: 1.10.0
Instances
| PEq PNatural Source # | Since: 1.10.0 | ||||||||
| PIsData PNatural Source # | Since: 1.10.0 | ||||||||
| PLiftable PNatural Source # | Since: 1.10.0 | ||||||||
Defined in Plutarch.Internal.Numeric Associated Types
Methods haskToRepr :: AsHaskell PNatural -> PlutusRepr PNatural Source # reprToHask :: PlutusRepr PNatural -> Either LiftError (AsHaskell PNatural) Source # reprToPlut :: forall (s :: S). PlutusRepr PNatural -> PLifted s PNatural Source # plutToRepr :: (forall (s :: S). PLifted s PNatural) -> Either LiftError (PlutusRepr PNatural) Source # | |||||||||
| PAdditiveMonoid PNatural Source # | Since: 1.10.0 | ||||||||
| PAdditiveSemigroup PNatural Source # | Since: 1.10.0 | ||||||||
| PMultiplicativeMonoid PNatural Source # | Since: 1.10.0 | ||||||||
| PMultiplicativeSemigroup PNatural Source # | Since: 1.10.0 | ||||||||
| POrd PNatural Source # | Since: 1.10.0 | ||||||||
Defined in Plutarch.Internal.Numeric Methods (#<=) :: forall (s :: S). Term s PNatural -> Term s PNatural -> Term s PBool Source # (#<) :: forall (s :: S). Term s PNatural -> Term s PNatural -> Term s PBool Source # pmax :: forall (s :: S). Term s PNatural -> Term s PNatural -> Term s PNatural Source # pmin :: forall (s :: S). Term s PNatural -> Term s PNatural -> Term s PNatural Source # | |||||||||
| PlutusType PNatural Source # | |||||||||
Defined in Plutarch.Internal.Numeric Associated Types
| |||||||||
| PShow PNatural Source # | Since: 1.13.0 | ||||||||
| PTryFrom PData (PAsData PNatural) Source # | Since: 3.4.0 | ||||||||
Defined in Plutarch.Internal.TryFrom Associated Types
| |||||||||
| Generic (PNatural s) Source # | |||||||||
Defined in Plutarch.Internal.Numeric Associated Types
| |||||||||
| Generic (PNatural s) Source # | |||||||||
| type AsHaskell PNatural Source # | |||||||||
Defined in Plutarch.Internal.Numeric | |||||||||
| type PlutusRepr PNatural Source # | |||||||||
Defined in Plutarch.Internal.Numeric | |||||||||
| type PInner PNatural Source # | Since: 1.10.0 | ||||||||
Defined in Plutarch.Internal.Numeric | |||||||||
| type PTryFromExcess PData (PAsData PNatural) Source # | |||||||||
Defined in Plutarch.Internal.TryFrom | |||||||||
| type Rep (PNatural s) Source # | Since: 1.10.0 | ||||||||
Defined in Plutarch.Internal.Numeric | |||||||||
| type Code (PNatural s) Source # | Since: 1.10.0 | ||||||||
Defined in Plutarch.Internal.Numeric | |||||||||
Type classes
class PAdditiveSemigroup (a :: S -> Type) where Source #
The addition operation, and the notion of scaling by a positive.
Laws
x #+ y=y #+ x(commutativity of#+)x #+ (y #+ z)=(x #+ y) #+ z(associativity of#+)
If you define a custom pscalePositive, ensure the following also hold:
pscalePositive x pone=x(pscalePositive x n) #+ (pscalePositive x m)=pscalePositive x (n #+ m)pscalePositive (pscalePositive x n) m=pscalePositive x (n #* m)
The default implementation ensures these laws are satisfied.
Since: 1.10.0
Minimal complete definition
Nothing
Methods
(#+) :: forall (s :: S). Term s a -> Term s a -> Term s a infix 6 Source #
default (#+) :: forall (s :: S). PAdditiveSemigroup (PInner a) => Term s a -> Term s a -> Term s a Source #
pscalePositive :: forall (s :: S). Term s a -> Term s PPositive -> Term s a Source #
This defaults to exponentiation-by-squaring, which in general is the best we can do.
Instances
| PAdditiveSemigroup PBuiltinBLS12_381_G1_Element Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric Methods (#+) :: forall (s :: S). Term s PBuiltinBLS12_381_G1_Element -> Term s PBuiltinBLS12_381_G1_Element -> Term s PBuiltinBLS12_381_G1_Element Source # pscalePositive :: forall (s :: S). Term s PBuiltinBLS12_381_G1_Element -> Term s PPositive -> Term s PBuiltinBLS12_381_G1_Element Source # | |
| PAdditiveSemigroup PBuiltinBLS12_381_G2_Element Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric Methods (#+) :: forall (s :: S). Term s PBuiltinBLS12_381_G2_Element -> Term s PBuiltinBLS12_381_G2_Element -> Term s PBuiltinBLS12_381_G2_Element Source # pscalePositive :: forall (s :: S). Term s PBuiltinBLS12_381_G2_Element -> Term s PPositive -> Term s PBuiltinBLS12_381_G2_Element Source # | |
| PAdditiveSemigroup PInteger Source # | Since: 1.10.0 |
| PAdditiveSemigroup PNatural Source # | Since: 1.10.0 |
| PAdditiveSemigroup PPositive Source # | Since: 1.10.0 |
| PAdditiveSemigroup PRational Source # | Since: 1.10.0 |
| PAdditiveSemigroup a => PAdditiveSemigroup (PPullArray a) Source # | Since: 1.12.0 |
Defined in Plutarch.Array Methods (#+) :: forall (s :: S). Term s (PPullArray a) -> Term s (PPullArray a) -> Term s (PPullArray a) Source # pscalePositive :: forall (s :: S). Term s (PPullArray a) -> Term s PPositive -> Term s (PPullArray a) Source # | |
class PAdditiveSemigroup a => PAdditiveMonoid (a :: S -> Type) where Source #
The notion of zero, as well as a way to scale by naturals.
Laws
pzero #+ x=x(pzerois the identity of#+)pscalePositive pzero n=pzero(pzerodoes not scale up)
If you define pscaleNatural, ensure the following as well:
pscaleNatural x (ppositiveToNatural # p)=pscalePositive x ppscaleNatural x pzero=pzero
The default implementation of pscaleNatural ensures these laws hold.
Since: 1.10.0
Minimal complete definition
Nothing
Methods
pzero :: forall (s :: S). Term s a Source #
pscaleNatural :: forall (s :: S). Term s a -> Term s PNatural -> Term s a Source #
Instances
| PAdditiveMonoid PBuiltinBLS12_381_G1_Element Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric Methods pzero :: forall (s :: S). Term s PBuiltinBLS12_381_G1_Element Source # pscaleNatural :: forall (s :: S). Term s PBuiltinBLS12_381_G1_Element -> Term s PNatural -> Term s PBuiltinBLS12_381_G1_Element Source # | |
| PAdditiveMonoid PBuiltinBLS12_381_G2_Element Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric Methods pzero :: forall (s :: S). Term s PBuiltinBLS12_381_G2_Element Source # pscaleNatural :: forall (s :: S). Term s PBuiltinBLS12_381_G2_Element -> Term s PNatural -> Term s PBuiltinBLS12_381_G2_Element Source # | |
| PAdditiveMonoid PInteger Source # | Since: 1.10.0 |
| PAdditiveMonoid PNatural Source # | Since: 1.10.0 |
| PAdditiveMonoid PRational Source # | Since: 1.10.0 |
class PAdditiveMonoid a => PAdditiveGroup (a :: S -> Type) where Source #
The notion of additive inverses, and the subtraction operation.
Laws
If you define pnegate, the following laws must hold:
(pnegate # x) #+ x=pzero(pnegateis an additive inverse)pnegate #$ pnegate # x=x(pnegateis self-inverting)
If you define #-, the following law must hold:
x #- x=pzero
Additionally, the following 'consistency laws' must hold. Default
implementations of both pnegate and #- uphold these.
pnegate # x=pzero #- xx #- y=x #+ (pnegate # y)
Lastly, if you define a custom pscaleInteger, the following laws
must hold:
pscaleInteger x pzero=pzeropscaleInteger x (pnegate # y)=pnegate # (pscaleInteger x y)
Since: 1.10.0
Methods
pnegate :: forall (s :: S). Term s (a :--> a) Source #
(#-) :: forall (s :: S). Term s a -> Term s a -> Term s a infix 6 Source #
pscaleInteger :: forall (s :: S). Term s a -> Term s PInteger -> Term s a Source #
Instances
| PAdditiveGroup PBuiltinBLS12_381_G1_Element Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric Methods pnegate :: forall (s :: S). Term s (PBuiltinBLS12_381_G1_Element :--> PBuiltinBLS12_381_G1_Element) Source # (#-) :: forall (s :: S). Term s PBuiltinBLS12_381_G1_Element -> Term s PBuiltinBLS12_381_G1_Element -> Term s PBuiltinBLS12_381_G1_Element Source # pscaleInteger :: forall (s :: S). Term s PBuiltinBLS12_381_G1_Element -> Term s PInteger -> Term s PBuiltinBLS12_381_G1_Element Source # | |
| PAdditiveGroup PBuiltinBLS12_381_G2_Element Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric Methods pnegate :: forall (s :: S). Term s (PBuiltinBLS12_381_G2_Element :--> PBuiltinBLS12_381_G2_Element) Source # (#-) :: forall (s :: S). Term s PBuiltinBLS12_381_G2_Element -> Term s PBuiltinBLS12_381_G2_Element -> Term s PBuiltinBLS12_381_G2_Element Source # pscaleInteger :: forall (s :: S). Term s PBuiltinBLS12_381_G2_Element -> Term s PInteger -> Term s PBuiltinBLS12_381_G2_Element Source # | |
| PAdditiveGroup PInteger Source # | Since: 1.10.0 |
| PAdditiveGroup PRational Source # | Since: 1.10.0 |
class PMultiplicativeSemigroup (a :: S -> Type) where Source #
The multiplication operation.
Laws
x #* (y #* z)=(x #* y) #* z(associativity of#*)
If you define a custom ppowPositive, ensure the following also hold:
ppowPositive x pone=x(ppowPositive x n) #* (ppowPositive x m)=ppowPositive x (n #+ m)ppowPositive (ppowPositive x n) m=ppowPositive x (n #* m)
The default implementation ensures these laws are satisfied.
Note
Unlike PAdditiveSemigroup, the multiplication operation doesn't need to be
commutative. Currently, all Plutarch-provided instances are, but this need
not be true for other instances.
Since: 1.10.0
Minimal complete definition
Nothing
Methods
(#*) :: forall (s :: S). Term s a -> Term s a -> Term s a infix 6 Source #
default (#*) :: forall (s :: S). PMultiplicativeSemigroup (PInner a) => Term s a -> Term s a -> Term s a Source #
ppowPositive :: forall (s :: S). Term s a -> Term s PPositive -> Term s a Source #
Instances
| PMultiplicativeSemigroup PBuiltinBLS12_381_MlResult Source # | Since: 1.10.0 |
Defined in Plutarch.Internal.Numeric Methods (#*) :: forall (s :: S). Term s PBuiltinBLS12_381_MlResult -> Term s PBuiltinBLS12_381_MlResult -> Term s PBuiltinBLS12_381_MlResult Source # ppowPositive :: forall (s :: S). Term s PBuiltinBLS12_381_MlResult -> Term s PPositive -> Term s PBuiltinBLS12_381_MlResult Source # | |
| PMultiplicativeSemigroup PInteger Source # | Since: 1.10.0 |
| PMultiplicativeSemigroup PNatural Source # | Since: 1.10.0 |
| PMultiplicativeSemigroup PPositive Source # | Since: 1.10.0 |
| PMultiplicativeSemigroup PRational Source # | Since: 1.10.0 |
| PMultiplicativeSemigroup a => PMultiplicativeSemigroup (PPullArray a) Source # | Since: 1.12.0 |
Defined in Plutarch.Array Methods (#*) :: forall (s :: S). Term s (PPullArray a) -> Term s (PPullArray a) -> Term s (PPullArray a) Source # ppowPositive :: forall (s :: S). Term s (PPullArray a) -> Term s PPositive -> Term s (PPullArray a) Source # | |
class PMultiplicativeSemigroup a => PMultiplicativeMonoid (a :: S -> Type) where Source #
The notion of one (multiplicative identity), and exponentiation by - naturals.
Laws
pone #* x=x(poneis the left identity of#*)x #* pone=x(poneis the right identity of#*)ppowPositive pone p=pone(ponedoes not scale up)
If you define ppowNatural, ensure the following as well:
ppowNatural x (ppositiveToNatural # p)=ppowPositive x pppowNatural x pzero=pone
Since: 1.10.0
Minimal complete definition
Nothing
Methods
pone :: forall (s :: S). Term s a Source #
ppowNatural :: forall (s :: S). Term s a -> Term s PNatural -> Term s a Source #
Instances
| PMultiplicativeMonoid PInteger Source # | Since: 1.10.0 |
| PMultiplicativeMonoid PNatural Source # | Since: 1.10.0 |
| PMultiplicativeMonoid PPositive Source # | Since: 1.10.0 |
| PMultiplicativeMonoid PRational Source # | Since: 1.10.0 |
class (PAdditiveGroup a, PMultiplicativeMonoid a) => PRing (a :: S -> Type) where Source #
Laws
pfromInteger 0=pzeropfromInteger 1=ponepfromInteger (x + y)=pfromInteger x #+ pfromInteger ypfromInteger (x * y)=pfromInteger x #* pfromInteger y
Additionally, the following 'interaction laws' must hold between the
instances of PAdditiveGroup and PMultiplicativeMonoid for a:
x #* (y #+ z)=(x #* y) #+ (x #* z)(#*left-distributes over#+)(y #+ z) #* x=(y #* x) #+ (z #* x)(#*right-distributes over#+)
Since: 1.10.0
Minimal complete definition
Nothing
Instances
class (PRing a, POrd a) => PIntegralDomain (a :: S -> Type) where Source #
Laws
Pedantry note
Technically, the requirements here are too strong: we demand an ordered ring, which integral domains don't necessarily have to be. However, in our case, our hand is forced by expected semantics: in abstract algebra, both the absolute value and the signum are real numbers (which are always totally ordered) but in our case, both must be elements of the integral domain itself. Thus, in order for the laws to make any sense, we have to ensure a total order on the integral domain. Since all of our integral domains are 'at least as big' as the integers, this doesn't pose a huge problem.
Since: 1.10.0
Minimal complete definition
Nothing
Instances
| PIntegralDomain PInteger Source # | Since: 1.10.0 |
| PIntegralDomain PRational Source # | Since: 1.10.0 |
Functions
positiveToInteger :: Positive -> Integer Source #
Since: 1.10.0
toPositiveAbs :: Integer -> Positive Source #
ptryPositive :: forall (s :: S). Term s (PInteger :--> PPositive) Source #
Partial version of ppositive. Errors if argument is not positive.
Since: 1.10.0
ptryNatural :: forall (s :: S). Term s (PInteger :--> PNatural) Source #
Partial version of pnatural. Errors if argument is negative.
Since: 1.10.0
ppositiveToNatural :: forall (s :: S). Term s (PPositive :--> PNatural) Source #
'Relax' a PPositive to PNatural. This uses punsafeCoerce
underneath, but because any positive is also a natural, is safe.
Since: 1.10.0
pnaturalToPositiveCPS :: forall (a :: S -> Type) (s :: S). Term s a -> (Term s PPositive -> Term s a) -> Term s PNatural -> Term s a Source #
pbySquaringDefault :: forall (a :: S -> Type) (s :: S). (forall (s' :: S). Term s' a -> Term s' a -> Term s' a) -> Term s a -> Term s PPositive -> Term s a Source #
A default implementation of exponentiation-by-squaring with a strictly-positive exponent.
Important note
This implementation assumes that the operation argument is associative.
Since: 1.10.0
Orphan instances
| PIntegralDomain a => Num (Term s a) Source # | |
Methods (+) :: Term s a -> Term s a -> Term s a Source # (-) :: Term s a -> Term s a -> Term s a Source # (*) :: Term s a -> Term s a -> Term s a Source # negate :: Term s a -> Term s a Source # abs :: Term s a -> Term s a Source # signum :: Term s a -> Term s a Source # fromInteger :: Integer -> Term s a Source # | |