Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data PPositive (s :: S)
- data Positive
- 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
- ptryPositive :: forall (s :: S). Term s (PInteger :--> PPositive)
- ppositive :: Term s (PInteger :--> PMaybe PPositive)
- pbySquaringDefault :: forall (a :: S -> Type) (s :: S). (forall (s' :: S). Term s' a -> Term s' a -> Term s' a) -> Term s (a :--> (PPositive :--> 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 WIP
Instances
@since WIP
Instances
Arbitrary Positive Source # | @since WIP |
CoArbitrary Positive Source # | @since WIP |
Defined in Plutarch.Internal.Numeric coarbitrary :: Positive -> Gen b -> Gen b | |
Function Positive Source # | @since WIP |
Defined in Plutarch.Internal.Numeric | |
Show Positive Source # | @since WIP |
Eq Positive Source # | @since WIP |
Ord Positive Source # | @since WIP |
Defined in Plutarch.Internal.Numeric | |
Pretty Positive Source # | @since WIP |
Defined in Plutarch.Internal.Numeric prettyList :: [Positive] -> Doc ann |
Type classes
class PAdditiveSemigroup (a :: S -> Type) where Source #
The addition operation.
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 WIP
Nothing
(#+) :: 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 :--> (PPositive :--> 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 WIP |
Defined in Plutarch.Internal.Numeric (#+) :: 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 :--> (PPositive :--> PBuiltinBLS12_381_G1_Element)) Source # | |
PAdditiveSemigroup PBuiltinBLS12_381_G2_Element Source # | @since WIP |
Defined in Plutarch.Internal.Numeric (#+) :: 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 :--> (PPositive :--> PBuiltinBLS12_381_G2_Element)) Source # | |
PAdditiveSemigroup PInteger Source # | @since WIP |
PAdditiveSemigroup PPositive Source # | @since WIP @since WIP |
PAdditiveSemigroup PRational Source # | @since WIP |
class PAdditiveSemigroup a => PAdditiveMonoid (a :: S -> Type) where Source #
The notion of zero, as well as a (kind of) reversal of pscalePositive
,
similar to floor division by positive integers.
Laws
pzero #+ x
=
x
(pzero
is the identity of#+
)pscalePositive # pzero # n
=
pzero
(pzero
does not scale up)
@since WIP
Instances
PAdditiveMonoid PBuiltinBLS12_381_G1_Element Source # | @since WIP |
Defined in Plutarch.Internal.Numeric | |
PAdditiveMonoid PBuiltinBLS12_381_G2_Element Source # | @since WIP |
Defined in Plutarch.Internal.Numeric | |
PAdditiveMonoid PInteger Source # | @since WIP |
PAdditiveMonoid PRational Source # | @since WIP |
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
(pnegate
is an additive inverse)pnegate #$ pnegate # x
=
x
(pnegate
is 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 #- x
x #- y
=
x #+ (pnegate # y)
Lastly, if you define a custom pscaleInteger
, the following laws
must hold:
pscaleInteger # x # pzero
=
pzero
pscaleInteger # x #$ pnegate y
=
pnegate #$ pscaleInteger # x # y
@since WIP
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 :--> (PInteger :--> a)) Source #
Instances
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)
=
pscalePositive # x # (n #+ m)
ppowPositive # (ppowPositive # x # n) # m
=
pscalePositive # 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 WIP
Nothing
(#*) :: 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 :--> (PPositive :--> a)) Source #
Instances
PMultiplicativeSemigroup PInteger Source # | @since WIP |
PMultiplicativeSemigroup PPositive Source # | @since WIP @since WIP |
PMultiplicativeSemigroup PRational Source # | @since WIP |
class PMultiplicativeSemigroup a => PMultiplicativeMonoid (a :: S -> Type) where Source #
The notion of one (multiplicative identity).
Laws
pone #* x
=
x
(pone
is the left identity of#*
)x #* pone
=
x
(pone
is the right identity of#*
)
@since WIP
Instances
PMultiplicativeMonoid PInteger Source # | @since WIP |
PMultiplicativeMonoid PPositive Source # | @since WIP |
PMultiplicativeMonoid PRational Source # | @since WIP |
class (PAdditiveGroup a, PMultiplicativeMonoid a) => PRing (a :: S -> Type) where Source #
Laws
pfromInteger 0
=
pzero
pfromInteger 1
=
pone
pfromInteger (x + y)
=
pfromInteger x #+ pfromInteger y
pfromInteger (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 WIP
Nothing
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 WIP
Nothing
Instances
PIntegralDomain PInteger Source # | @since WIP |
PIntegralDomain PRational Source # | @since WIP |
Functions
ptryPositive :: forall (s :: S). Term s (PInteger :--> PPositive) Source #
Partial version of PPositive
. Errors if argument is zero.
@since WIP
pbySquaringDefault :: forall (a :: S -> Type) (s :: S). (forall (s' :: S). Term s' a -> Term s' a -> Term s' a) -> Term s (a :--> (PPositive :--> 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 WIP
Orphan instances
PIntegralDomain a => Num (Term s a) Source # | |
(+) :: 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 # |