Copyright | Copyright (c) 2016 the Hakaru team |
---|---|
License | BSD3 |
Maintainer | wren@community.haskell.org |
Stability | experimental |
Portability | GHC-only |
Safe Haskell | None |
Language | Haskell2010 |
A replacement for Haskell's Prelude, using the familiar symbols
in order to construct AST
s and ABT
s. This is only necessary
if we want to use Hakaru as an embedded language in Haskell, but
it also provides some examples of how to use the infrastructure.
TODO: is there a way to get rid of the need to specify '[]
everywhere in here? Some sort of distinction between the Var vs the Open parts of View?
- ann_ :: ABT Term abt => Sing a -> abt '[] a -> abt '[] a
- triv :: TrivialABT Term '[] a -> TrivialABT Term '[] a
- memo :: MemoizedABT Term '[] a -> MemoizedABT Term '[] a
- coerceTo_ :: ABT Term abt => Coercion a b -> abt '[] a -> abt '[] b
- fromProb :: ABT Term abt => abt '[] HProb -> abt '[] HReal
- nat2int :: ABT Term abt => abt '[] HNat -> abt '[] HInt
- nat2prob :: ABT Term abt => abt '[] HNat -> abt '[] HProb
- fromInt :: ABT Term abt => abt '[] HInt -> abt '[] HReal
- nat2real :: ABT Term abt => abt '[] HNat -> abt '[] HReal
- unsafeFrom_ :: ABT Term abt => Coercion a b -> abt '[] b -> abt '[] a
- unsafeProb :: ABT Term abt => abt '[] HReal -> abt '[] HProb
- unsafeProbFraction :: forall abt a. (ABT Term abt, HFractional_ a) => abt '[] a -> abt '[] HProb
- unsafeProbFraction_ :: ABT Term abt => HFractional a -> abt '[] a -> abt '[] HProb
- unsafeProbSemiring :: forall abt a. (ABT Term abt, HSemiring_ a) => abt '[] a -> abt '[] HProb
- unsafeProbSemiring_ :: ABT Term abt => HSemiring a -> abt '[] a -> abt '[] HProb
- literal_ :: ABT Term abt => Literal a -> abt '[] a
- nat_ :: ABT Term abt => Natural -> abt '[] HNat
- int_ :: ABT Term abt => Integer -> abt '[] HInt
- prob_ :: ABT Term abt => NonNegativeRational -> abt '[] HProb
- real_ :: ABT Term abt => Rational -> abt '[] HReal
- fromRational :: forall abt a. (ABT Term abt, HFractional_ a) => Rational -> abt '[] a
- half :: forall abt a. (ABT Term abt, HFractional_ a) => abt '[] a
- third :: (ABT Term abt, HFractional_ a) => abt '[] a
- true :: ABT Term abt => abt '[] HBool
- false :: ABT Term abt => abt '[] HBool
- bool_ :: ABT Term abt => Bool -> abt '[] HBool
- if_ :: ABT Term abt => abt '[] HBool -> abt '[] a -> abt '[] a -> abt '[] a
- not :: ABT Term abt => abt '[] HBool -> abt '[] HBool
- (&&) :: ABT Term abt => abt '[] HBool -> abt '[] HBool -> abt '[] HBool
- and :: ABT Term abt => [abt '[] HBool] -> abt '[] HBool
- (||) :: ABT Term abt => abt '[] HBool -> abt '[] HBool -> abt '[] HBool
- or :: ABT Term abt => [abt '[] HBool] -> abt '[] HBool
- nand :: ABT Term abt => abt '[] HBool -> abt '[] HBool -> abt '[] HBool
- nor :: ABT Term abt => abt '[] HBool -> abt '[] HBool -> abt '[] HBool
- (==) :: (ABT Term abt, HEq_ a) => abt '[] a -> abt '[] a -> abt '[] HBool
- (/=) :: (ABT Term abt, HEq_ a) => abt '[] a -> abt '[] a -> abt '[] HBool
- (<) :: (ABT Term abt, HOrd_ a) => abt '[] a -> abt '[] a -> abt '[] HBool
- (<=) :: (ABT Term abt, HOrd_ a) => abt '[] a -> abt '[] a -> abt '[] HBool
- (>) :: (ABT Term abt, HOrd_ a) => abt '[] a -> abt '[] a -> abt '[] HBool
- (>=) :: (ABT Term abt, HOrd_ a) => abt '[] a -> abt '[] a -> abt '[] HBool
- min :: (ABT Term abt, HOrd_ a) => abt '[] a -> abt '[] a -> abt '[] a
- minimum :: (ABT Term abt, HOrd_ a) => [abt '[] a] -> abt '[] a
- max :: (ABT Term abt, HOrd_ a) => abt '[] a -> abt '[] a -> abt '[] a
- maximum :: (ABT Term abt, HOrd_ a) => [abt '[] a] -> abt '[] a
- zero :: forall abt a. (ABT Term abt, HSemiring_ a) => abt '[] a
- zero_ :: ABT Term abt => HSemiring a -> abt '[] a
- one :: forall abt a. (ABT Term abt, HSemiring_ a) => abt '[] a
- one_ :: ABT Term abt => HSemiring a -> abt '[] a
- (+) :: (ABT Term abt, HSemiring_ a) => abt '[] a -> abt '[] a -> abt '[] a
- sum :: (ABT Term abt, HSemiring_ a) => [abt '[] a] -> abt '[] a
- (*) :: (ABT Term abt, HSemiring_ a) => abt '[] a -> abt '[] a -> abt '[] a
- prod :: (ABT Term abt, HSemiring_ a) => [abt '[] a] -> abt '[] a
- (^) :: (ABT Term abt, HSemiring_ a) => abt '[] a -> abt '[] HNat -> abt '[] a
- square :: (ABT Term abt, HRing_ a) => abt '[] a -> abt '[] (NonNegative a)
- unsafeMinusNat :: ABT Term abt => abt '[] HNat -> abt '[] HNat -> abt '[] HNat
- unsafeMinusProb :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] HProb
- unsafeMinus :: (ABT Term abt, HSemiring_ a) => abt '[] a -> abt '[] a -> abt '[] a
- unsafeMinus_ :: ABT Term abt => HSemiring a -> abt '[] a -> abt '[] a -> abt '[] a
- unsafeDiv :: (ABT Term abt, HSemiring_ a) => abt '[] a -> abt '[] a -> abt '[] a
- unsafeDiv_ :: ABT Term abt => HSemiring a -> abt '[] a -> abt '[] a -> abt '[] a
- (-) :: (ABT Term abt, HRing_ a) => abt '[] a -> abt '[] a -> abt '[] a
- negate :: (ABT Term abt, HRing_ a) => abt '[] a -> abt '[] a
- negative :: (ABT Term abt, HRing_ a) => abt '[] (NonNegative a) -> abt '[] a
- abs :: (ABT Term abt, HRing_ a) => abt '[] a -> abt '[] a
- abs_ :: (ABT Term abt, HRing_ a) => abt '[] a -> abt '[] (NonNegative a)
- signum :: (ABT Term abt, HRing_ a) => abt '[] a -> abt '[] a
- (/) :: (ABT Term abt, HFractional_ a) => abt '[] a -> abt '[] a -> abt '[] a
- recip :: (ABT Term abt, HFractional_ a) => abt '[] a -> abt '[] a
- (^^) :: (ABT Term abt, HFractional_ a) => abt '[] a -> abt '[] HInt -> abt '[] a
- sqrt :: (ABT Term abt, HRadical_ a) => abt '[] a -> abt '[] a
- thRootOf :: (ABT Term abt, HRadical_ a) => abt '[] HNat -> abt '[] a -> abt '[] a
- integrate :: ABT Term abt => abt '[] HReal -> abt '[] HReal -> (abt '[] HReal -> abt '[] HProb) -> abt '[] HProb
- summate :: (ABT Term abt, HDiscrete_ a, HSemiring_ b, SingI a) => abt '[] a -> abt '[] a -> (abt '[] a -> abt '[] b) -> abt '[] b
- product :: (ABT Term abt, HDiscrete_ a, HSemiring_ b, SingI a) => abt '[] a -> abt '[] a -> (abt '[] a -> abt '[] b) -> abt '[] b
- class RealProb a where
- class Integrable a where
- betaFunc :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] HProb
- log :: ABT Term abt => abt '[] HProb -> abt '[] HReal
- logBase :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] HReal
- negativeInfinity :: (ABT Term abt, HRing_ a, Integrable a) => abt '[] a
- sin :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- cos :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- tan :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- asin :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- acos :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- atan :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- sinh :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- cosh :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- tanh :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- asinh :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- acosh :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- atanh :: ABT Term abt => abt '[] HReal -> abt '[] HReal
- dirac :: ABT Term abt => abt '[] a -> abt '[] (HMeasure a)
- (<$>) :: (ABT Term abt, SingI a) => (abt '[] a -> abt '[] b) -> abt '[] (HMeasure a) -> abt '[] (HMeasure b)
- (<*>) :: (ABT Term abt, SingI a, SingI b) => abt '[] (HMeasure (a :-> b)) -> abt '[] (HMeasure a) -> abt '[] (HMeasure b)
- (<*) :: (ABT Term abt, SingI a, SingI b) => abt '[] (HMeasure a) -> abt '[] (HMeasure b) -> abt '[] (HMeasure a)
- (*>) :: (ABT Term abt, SingI a) => abt '[] (HMeasure a) -> abt '[] (HMeasure b) -> abt '[] (HMeasure b)
- (>>=) :: ABT Term abt => abt '[] (HMeasure a) -> (abt '[] a -> abt '[] (HMeasure b)) -> abt '[] (HMeasure b)
- (>>) :: (ABT Term abt, SingI a) => abt '[] (HMeasure a) -> abt '[] (HMeasure b) -> abt '[] (HMeasure b)
- bindx :: (ABT Term abt, SingI a, SingI b) => abt '[] (HMeasure a) -> (abt '[] a -> abt '[] (HMeasure b)) -> abt '[] (HMeasure (HPair a b))
- liftM2 :: (ABT Term abt, SingI a, SingI b) => (abt '[] a -> abt '[] b -> abt '[] c) -> abt '[] (HMeasure a) -> abt '[] (HMeasure b) -> abt '[] (HMeasure c)
- superpose :: ABT Term abt => NonEmpty (abt '[] HProb, abt '[] (HMeasure a)) -> abt '[] (HMeasure a)
- (<|>) :: ABT Term abt => abt '[] (HMeasure a) -> abt '[] (HMeasure a) -> abt '[] (HMeasure a)
- weight :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure HUnit)
- withWeight :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure w) -> abt '[] (HMeasure w)
- weightedDirac :: (ABT Term abt, SingI a) => abt '[] a -> abt '[] HProb -> abt '[] (HMeasure a)
- reject :: ABT Term abt => Sing (HMeasure a) -> abt '[] (HMeasure a)
- guard :: ABT Term abt => abt '[] HBool -> abt '[] (HMeasure HUnit)
- withGuard :: ABT Term abt => abt '[] HBool -> abt '[] (HMeasure a) -> abt '[] (HMeasure a)
- lebesgue :: ABT Term abt => abt '[] (HMeasure HReal)
- counting :: ABT Term abt => abt '[] (HMeasure HInt)
- densityCategorical :: ABT Term abt => abt '[] (HArray HProb) -> abt '[] HNat -> abt '[] HProb
- categorical :: ABT Term abt => abt '[] (HArray HProb) -> abt '[] (HMeasure HNat)
- categorical' :: ABT Term abt => abt '[] (HArray HProb) -> abt '[] (HMeasure HNat)
- densityUniform :: ABT Term abt => abt '[] HReal -> abt '[] HReal -> abt '[] HReal -> abt '[] HProb
- uniform :: ABT Term abt => abt '[] HReal -> abt '[] HReal -> abt '[] (HMeasure HReal)
- uniform' :: ABT Term abt => abt '[] HReal -> abt '[] HReal -> abt '[] (HMeasure HReal)
- densityNormal :: ABT Term abt => abt '[] HReal -> abt '[] HProb -> abt '[] HReal -> abt '[] HProb
- normal :: ABT Term abt => abt '[] HReal -> abt '[] HProb -> abt '[] (HMeasure HReal)
- normal' :: ABT Term abt => abt '[] HReal -> abt '[] HProb -> abt '[] (HMeasure HReal)
- densityPoisson :: ABT Term abt => abt '[] HProb -> abt '[] HNat -> abt '[] HProb
- poisson :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure HNat)
- poisson' :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure HNat)
- densityGamma :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] HProb -> abt '[] HProb
- gamma :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] (HMeasure HProb)
- gamma' :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] (HMeasure HProb)
- densityBeta :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] HProb -> abt '[] HProb
- beta :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] (HMeasure HProb)
- beta' :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] (HMeasure HProb)
- beta'' :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] (HMeasure HProb)
- plateWithVar :: ABT Term abt => abt '[] HNat -> Variable HNat -> abt '[] (HMeasure a) -> abt '[] (HMeasure (HArray a))
- plate :: ABT Term abt => abt '[] HNat -> (abt '[] HNat -> abt '[] (HMeasure a)) -> abt '[] (HMeasure (HArray a))
- plate' :: (ABT Term abt, SingI a) => abt '[] (HArray (HMeasure a)) -> abt '[] (HMeasure (HArray a))
- chain :: (ABT Term abt, SingI s) => abt '[] HNat -> abt '[] s -> (abt '[] s -> abt '[] (HMeasure (HPair a s))) -> abt '[] (HMeasure (HPair (HArray a) s))
- chain' :: (ABT Term abt, SingI s, SingI a) => abt '[] (HArray (s :-> HMeasure (HPair a s))) -> abt '[] s -> abt '[] (HMeasure (HPair (HArray a) s))
- invgamma :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] (HMeasure HProb)
- exponential :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure HProb)
- chi2 :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure HProb)
- cauchy :: ABT Term abt => abt '[] HReal -> abt '[] HProb -> abt '[] (HMeasure HReal)
- laplace :: ABT Term abt => abt '[] HReal -> abt '[] HProb -> abt '[] (HMeasure HReal)
- studentT :: ABT Term abt => abt '[] HReal -> abt '[] HProb -> abt '[] HProb -> abt '[] (HMeasure HReal)
- weibull :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] (HMeasure HProb)
- bern :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure HBool)
- mix :: ABT Term abt => abt '[] (HArray HProb) -> abt '[] (HMeasure HNat)
- binomial :: ABT Term abt => abt '[] HNat -> abt '[] HProb -> abt '[] (HMeasure HInt)
- negativeBinomial :: ABT Term abt => abt '[] HNat -> abt '[] HProb -> abt '[] (HMeasure HNat)
- geometric :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure HNat)
- multinomial :: ABT Term abt => abt '[] HNat -> abt '[] (HArray HProb) -> abt '[] (HMeasure (HArray HProb))
- dirichlet :: ABT Term abt => abt '[] (HArray HProb) -> abt '[] (HMeasure (HArray HProb))
- datum_ :: ABT Term abt => Datum (abt '[]) (HData' t) -> abt '[] (HData' t)
- case_ :: ABT Term abt => abt '[] a -> [Branch a abt b] -> abt '[] b
- branch :: ABT Term abt => Pattern xs a -> abt xs b -> Branch a abt b
- unit :: ABT Term abt => abt '[] HUnit
- pair :: (ABT Term abt, SingI a, SingI b) => abt '[] a -> abt '[] b -> abt '[] (HPair a b)
- pair_ :: ABT Term abt => Sing a -> Sing b -> abt '[] a -> abt '[] b -> abt '[] (HPair a b)
- unpair :: forall abt a b c. ABT Term abt => abt '[] (HPair a b) -> (abt '[] a -> abt '[] b -> abt '[] c) -> abt '[] c
- fst :: ABT Term abt => abt '[] (HPair a b) -> abt '[] a
- snd :: ABT Term abt => abt '[] (HPair a b) -> abt '[] b
- swap :: (ABT Term abt, SingI a, SingI b) => abt '[] (HPair a b) -> abt '[] (HPair b a)
- left :: (ABT Term abt, SingI a, SingI b) => abt '[] a -> abt '[] (HEither a b)
- right :: (ABT Term abt, SingI a, SingI b) => abt '[] b -> abt '[] (HEither a b)
- uneither :: ABT Term abt => abt '[] (HEither a b) -> (abt '[] a -> abt '[] c) -> (abt '[] b -> abt '[] c) -> abt '[] c
- nothing :: (ABT Term abt, SingI a) => abt '[] (HMaybe a)
- just :: (ABT Term abt, SingI a) => abt '[] a -> abt '[] (HMaybe a)
- maybe :: (ABT Term abt, SingI a) => Maybe (abt '[] a) -> abt '[] (HMaybe a)
- unmaybe :: ABT Term abt => abt '[] (HMaybe a) -> abt '[] b -> (abt '[] a -> abt '[] b) -> abt '[] b
- nil :: (ABT Term abt, SingI a) => abt '[] (HList a)
- cons :: (ABT Term abt, SingI a) => abt '[] a -> abt '[] (HList a) -> abt '[] (HList a)
- list :: (ABT Term abt, SingI a) => [abt '[] a] -> abt '[] (HList a)
- lam :: (ABT Term abt, SingI a) => (abt '[] a -> abt '[] b) -> abt '[] (a :-> b)
- lamWithVar :: ABT Term abt => Text -> Sing a -> (abt '[] a -> abt '[] b) -> abt '[] (a :-> b)
- let_ :: ABT Term abt => abt '[] a -> (abt '[] a -> abt '[] b) -> abt '[] b
- app :: ABT Term abt => abt '[] (a :-> b) -> abt '[] a -> abt '[] b
- app2 :: ABT Term abt => abt '[] (a :-> (b :-> c)) -> abt '[] a -> abt '[] b -> abt '[] c
- app3 :: ABT Term abt => abt '[] (a :-> (b :-> (c :-> d))) -> abt '[] a -> abt '[] b -> abt '[] c -> abt '[] d
- empty :: (ABT Term abt, SingI a) => abt '[] (HArray a)
- arrayWithVar :: ABT Term abt => abt '[] HNat -> Variable HNat -> abt '[] a -> abt '[] (HArray a)
- array :: ABT Term abt => abt '[] HNat -> (abt '[] HNat -> abt '[] a) -> abt '[] (HArray a)
- (!) :: ABT Term abt => abt '[] (HArray a) -> abt '[] HNat -> abt '[] a
- size :: ABT Term abt => abt '[] (HArray a) -> abt '[] HNat
- reduce :: ABT Term abt => (abt '[] a -> abt '[] a -> abt '[] a) -> abt '[] a -> abt '[] (HArray a) -> abt '[] a
- sumV :: (ABT Term abt, HSemiring_ a) => abt '[] (HArray a) -> abt '[] a
- summateV :: ABT Term abt => abt '[] (HArray HProb) -> abt '[] HProb
- appendV :: ABT Term abt => abt '[] (HArray a) -> abt '[] (HArray a) -> abt '[] (HArray a)
- mapV :: ABT Term abt => (abt '[] a -> abt '[] b) -> abt '[] (HArray a) -> abt '[] (HArray b)
- mapWithIndex :: ABT Term abt => (abt '[] HNat -> abt '[] a -> abt '[] b) -> abt '[] (HArray a) -> abt '[] (HArray b)
- normalizeV :: ABT Term abt => abt '[] (HArray HProb) -> abt '[] (HArray HProb)
- constV :: ABT Term abt => abt '[] HNat -> abt '[] b -> abt '[] (HArray b)
- unitV :: ABT Term abt => abt '[] HNat -> abt '[] HNat -> abt '[] (HArray HProb)
- zipWithV :: ABT Term abt => (abt '[] a -> abt '[] b -> abt '[] c) -> abt '[] (HArray a) -> abt '[] (HArray b) -> abt '[] (HArray c)
- primOp0_ :: ABT Term abt => PrimOp '[] a -> abt '[] a
- primOp1_ :: ABT Term abt => PrimOp '[a] b -> abt '[] a -> abt '[] b
- primOp2_ :: ABT Term abt => PrimOp '[a, b] c -> abt '[] a -> abt '[] b -> abt '[] c
- primOp3_ :: ABT Term abt => PrimOp '[a, b, c] d -> abt '[] a -> abt '[] b -> abt '[] c -> abt '[] d
- arrayOp0_ :: ABT Term abt => ArrayOp '[] a -> abt '[] a
- arrayOp1_ :: ABT Term abt => ArrayOp '[a] b -> abt '[] a -> abt '[] b
- arrayOp2_ :: ABT Term abt => ArrayOp '[a, b] c -> abt '[] a -> abt '[] b -> abt '[] c
- arrayOp3_ :: ABT Term abt => ArrayOp '[a, b, c] d -> abt '[] a -> abt '[] b -> abt '[] c -> abt '[] d
- measure0_ :: ABT Term abt => MeasureOp '[] a -> abt '[] (HMeasure a)
- measure1_ :: ABT Term abt => MeasureOp '[a] b -> abt '[] a -> abt '[] (HMeasure b)
- measure2_ :: ABT Term abt => MeasureOp '[a, b] c -> abt '[] a -> abt '[] b -> abt '[] (HMeasure c)
- unsafeNaryOp_ :: ABT Term abt => NaryOp a -> [abt '[] a] -> abt '[] a
- naryOp_withIdentity :: ABT Term abt => NaryOp a -> abt '[] a -> [abt '[] a] -> abt '[] a
- naryOp2_ :: ABT Term abt => NaryOp a -> abt '[] a -> abt '[] a -> abt '[] a
Basic syntax
Types and coercions
triv :: TrivialABT Term '[] a -> TrivialABT Term '[] a Source #
memo :: MemoizedABT Term '[] a -> MemoizedABT Term '[] a Source #
unsafeProbFraction :: forall abt a. (ABT Term abt, HFractional_ a) => abt '[] a -> abt '[] HProb Source #
unsafeProbFraction_ :: ABT Term abt => HFractional a -> abt '[] a -> abt '[] HProb Source #
unsafeProbSemiring :: forall abt a. (ABT Term abt, HSemiring_ a) => abt '[] a -> abt '[] HProb Source #
Numeric literals
fromRational :: forall abt a. (ABT Term abt, HFractional_ a) => Rational -> abt '[] a Source #
Booleans
Equality and ordering
Semirings
unsafeMinus :: (ABT Term abt, HSemiring_ a) => abt '[] a -> abt '[] a -> abt '[] a Source #
For any semiring we can attempt subtraction by lifting to a ring, subtracting there, and then lowering back to the semiring. Of course, the lowering step may well fail.
unsafeMinus_ :: ABT Term abt => HSemiring a -> abt '[] a -> abt '[] a -> abt '[] a Source #
A variant of unsafeMinus
for explicitly passing the semiring
instance.
unsafeDiv :: (ABT Term abt, HSemiring_ a) => abt '[] a -> abt '[] a -> abt '[] a Source #
For any semiring we can attempt division by lifting to a semifield, dividing there, and then lowering back to the semiring. Of course, the lowering step may well fail.
unsafeDiv_ :: ABT Term abt => HSemiring a -> abt '[] a -> abt '[] a -> abt '[] a Source #
A variant of unsafeDiv
for explicitly passing the semiring
instance.
Rings
negative :: (ABT Term abt, HRing_ a) => abt '[] (NonNegative a) -> abt '[] a Source #
An occasionally helpful variant of negate
.
Fractional
Radical
Integration
integrate :: ABT Term abt => abt '[] HReal -> abt '[] HReal -> (abt '[] HReal -> abt '[] HProb) -> abt '[] HProb Source #
summate :: (ABT Term abt, HDiscrete_ a, HSemiring_ b, SingI a) => abt '[] a -> abt '[] a -> (abt '[] a -> abt '[] b) -> abt '[] b Source #
product :: (ABT Term abt, HDiscrete_ a, HSemiring_ b, SingI a) => abt '[] a -> abt '[] a -> (abt '[] a -> abt '[] b) -> abt '[] b Source #
Continuous
class RealProb a where Source #
(**) :: ABT Term abt => abt '[] HProb -> abt '[] a -> abt '[] HProb infixr 8 Source #
exp :: ABT Term abt => abt '[] a -> abt '[] HProb Source #
erf :: ABT Term abt => abt '[] a -> abt '[] a Source #
pi :: ABT Term abt => abt '[] a Source #
gammaFunc :: ABT Term abt => abt '[] a -> abt '[] HProb Source #
class Integrable a where Source #
negativeInfinity :: (ABT Term abt, HRing_ a, Integrable a) => abt '[] a Source #
Trig
Measures
Abstract nonsense
(<$>) :: (ABT Term abt, SingI a) => (abt '[] a -> abt '[] b) -> abt '[] (HMeasure a) -> abt '[] (HMeasure b) infixl 4 Source #
(<*>) :: (ABT Term abt, SingI a, SingI b) => abt '[] (HMeasure (a :-> b)) -> abt '[] (HMeasure a) -> abt '[] (HMeasure b) infixl 4 Source #
N.B, this function may introduce administrative redexes.
Moreover, it's not clear that we should even allow the type
'HMeasure (a ':-> b)
!
(<*) :: (ABT Term abt, SingI a, SingI b) => abt '[] (HMeasure a) -> abt '[] (HMeasure b) -> abt '[] (HMeasure a) infixl 4 Source #
(*>) :: (ABT Term abt, SingI a) => abt '[] (HMeasure a) -> abt '[] (HMeasure b) -> abt '[] (HMeasure b) infixl 4 Source #
(>>=) :: ABT Term abt => abt '[] (HMeasure a) -> (abt '[] a -> abt '[] (HMeasure b)) -> abt '[] (HMeasure b) infixl 1 Source #
(>>) :: (ABT Term abt, SingI a) => abt '[] (HMeasure a) -> abt '[] (HMeasure b) -> abt '[] (HMeasure b) infixl 1 Source #
bindx :: (ABT Term abt, SingI a, SingI b) => abt '[] (HMeasure a) -> (abt '[] a -> abt '[] (HMeasure b)) -> abt '[] (HMeasure (HPair a b)) Source #
liftM2 :: (ABT Term abt, SingI a, SingI b) => (abt '[] a -> abt '[] b -> abt '[] c) -> abt '[] (HMeasure a) -> abt '[] (HMeasure b) -> abt '[] (HMeasure c) Source #
Linear operators
superpose :: ABT Term abt => NonEmpty (abt '[] HProb, abt '[] (HMeasure a)) -> abt '[] (HMeasure a) Source #
(<|>) :: ABT Term abt => abt '[] (HMeasure a) -> abt '[] (HMeasure a) -> abt '[] (HMeasure a) Source #
The sum of two measures. Is called mplus
in the Core Hakaru paper.
weight :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure HUnit) Source #
Adjust the weight of the current measure.
N.B., the name for this function is terribly inconsistent
across the literature, even just the Hakaru literature, let alone
the Hakaru code base. It is variously called "factor" or
"weight"; though "factor" is also used to mean the function
factor
or the function observe
, and "weight" is also used
to mean the weight
function.
withWeight :: ABT Term abt => abt '[] HProb -> abt '[] (HMeasure w) -> abt '[] (HMeasure w) Source #
weightedDirac :: (ABT Term abt, SingI a) => abt '[] a -> abt '[] HProb -> abt '[] (HMeasure a) Source #
A particularly common use case of weight
:
weightedDirac e p == weight p (dirac e) == weight p *> dirac e == dirac e <* weight p
reject :: ABT Term abt => Sing (HMeasure a) -> abt '[] (HMeasure a) Source #
The empty measure. Is called fail
in the Core Hakaru paper.
guard :: ABT Term abt => abt '[] HBool -> abt '[] (HMeasure HUnit) Source #
Assert that a condition is true.
N.B., the name for this function is terribly inconsistent
across the literature, even just the Hakaru literature, let alone
the Hakaru code base. It is variously called "factor" or
"observe"; though "factor" is also used to mean the function
pose
, and "observe" is also used to mean the backwards part
of Lazy.hs.
Measure operators
When two versions of the same operator are given, the one without the prime builds an AST using the built-in operator, whereas the one with the prime is a default definition in terms of more primitive measure operators.
densityCategorical :: ABT Term abt => abt '[] (HArray HProb) -> abt '[] HNat -> abt '[] HProb Source #
densityUniform :: ABT Term abt => abt '[] HReal -> abt '[] HReal -> abt '[] HReal -> abt '[] HProb Source #
densityNormal :: ABT Term abt => abt '[] HReal -> abt '[] HProb -> abt '[] HReal -> abt '[] HProb Source #
densityGamma :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] HProb -> abt '[] HProb Source #
densityBeta :: ABT Term abt => abt '[] HProb -> abt '[] HProb -> abt '[] HProb -> abt '[] HProb Source #
plateWithVar :: ABT Term abt => abt '[] HNat -> Variable HNat -> abt '[] (HMeasure a) -> abt '[] (HMeasure (HArray a)) Source #
plate :: ABT Term abt => abt '[] HNat -> (abt '[] HNat -> abt '[] (HMeasure a)) -> abt '[] (HMeasure (HArray a)) Source #
plate' :: (ABT Term abt, SingI a) => abt '[] (HArray (HMeasure a)) -> abt '[] (HMeasure (HArray a)) Source #
chain :: (ABT Term abt, SingI s) => abt '[] HNat -> abt '[] s -> (abt '[] s -> abt '[] (HMeasure (HPair a s))) -> abt '[] (HMeasure (HPair (HArray a) s)) Source #
chain' :: (ABT Term abt, SingI s, SingI a) => abt '[] (HArray (s :-> HMeasure (HPair a s))) -> abt '[] s -> abt '[] (HMeasure (HPair (HArray a) s)) Source #
studentT :: ABT Term abt => abt '[] HReal -> abt '[] HProb -> abt '[] HProb -> abt '[] (HMeasure HReal) Source #
negativeBinomial :: ABT Term abt => abt '[] HNat -> abt '[] HProb -> abt '[] (HMeasure HNat) Source #
multinomial :: ABT Term abt => abt '[] HNat -> abt '[] (HArray HProb) -> abt '[] (HMeasure (HArray HProb)) Source #
Data types (other than booleans)
Case and Branch
HUnit
HPair
unpair :: forall abt a b c. ABT Term abt => abt '[] (HPair a b) -> (abt '[] a -> abt '[] b -> abt '[] c) -> abt '[] c Source #
HEither
uneither :: ABT Term abt => abt '[] (HEither a b) -> (abt '[] a -> abt '[] c) -> (abt '[] b -> abt '[] c) -> abt '[] c Source #
HMaybe
unmaybe :: ABT Term abt => abt '[] (HMaybe a) -> abt '[] b -> (abt '[] a -> abt '[] b) -> abt '[] b Source #
HList
Lambda calculus
lam :: (ABT Term abt, SingI a) => (abt '[] a -> abt '[] b) -> abt '[] (a :-> b) Source #
A variant of lamWithVar
for automatically computing the type
via sing
.
lamWithVar :: ABT Term abt => Text -> Sing a -> (abt '[] a -> abt '[] b) -> abt '[] (a :-> b) Source #
Create a lambda abstraction. The first two arguments give the
hint and type of the lambda-bound variable in the result. If you
want to automatically fill those in, then see lam
.
app3 :: ABT Term abt => abt '[] (a :-> (b :-> (c :-> d))) -> abt '[] a -> abt '[] b -> abt '[] c -> abt '[] d Source #
Arrays
arrayWithVar :: ABT Term abt => abt '[] HNat -> Variable HNat -> abt '[] a -> abt '[] (HArray a) Source #
reduce :: ABT Term abt => (abt '[] a -> abt '[] a -> abt '[] a) -> abt '[] a -> abt '[] (HArray a) -> abt '[] a Source #
mapV :: ABT Term abt => (abt '[] a -> abt '[] b) -> abt '[] (HArray a) -> abt '[] (HArray b) Source #
mapWithIndex :: ABT Term abt => (abt '[] HNat -> abt '[] a -> abt '[] b) -> abt '[] (HArray a) -> abt '[] (HArray b) Source #
zipWithV :: ABT Term abt => (abt '[] a -> abt '[] b -> abt '[] c) -> abt '[] (HArray a) -> abt '[] (HArray b) -> abt '[] (HArray c) Source #
Implementation details
primOp3_ :: ABT Term abt => PrimOp '[a, b, c] d -> abt '[] a -> abt '[] b -> abt '[] c -> abt '[] d Source #
arrayOp3_ :: ABT Term abt => ArrayOp '[a, b, c] d -> abt '[] a -> abt '[] b -> abt '[] c -> abt '[] d Source #
measure2_ :: ABT Term abt => MeasureOp '[a, b] c -> abt '[] a -> abt '[] b -> abt '[] (HMeasure c) Source #
unsafeNaryOp_ :: ABT Term abt => NaryOp a -> [abt '[] a] -> abt '[] a Source #
Apply an n-ary operator to a list. This smart constructor will
flatten nested calls to the same operator. And if there is exactly
one element in the flattened sequence, then it will remove the
NaryOp_
node from the AST.
N.B., if the flattened sequence is empty, this smart constructor will return an AST which applies the operator to the empty sequence; which may or may not be unsafe. If the operator has an identity element, then it's fine (operating on the empty sequence evaluates to the identity element). However, if the operator doesn't have an identity, then the generated code will error whenever we attempt to run it.
naryOp_withIdentity :: ABT Term abt => NaryOp a -> abt '[] a -> [abt '[] a] -> abt '[] a Source #
A variant of unsafeNaryOp_
which will replace operating over
the empty sequence with a specified identity element. The produced
AST has the same semantics, we're just preemptively
evaluating/simplifying the NaryOp_
node of the AST.
N.B., this function does not simplify away the identity element if it exists in the flattened sequence! We should add that in the future.