horse/prob: begin work on kfl statistics
This commit is contained in:
101
horse/prob/kfl.kk
Normal file
101
horse/prob/kfl.kk
Normal file
@@ -0,0 +1,101 @@
|
||||
module horse/prob/kfl
|
||||
|
||||
// kfl is a semiring of probabilities formed by vibes.
|
||||
pub type kfl
|
||||
// Effectively if not literally impossible events.
|
||||
Impossible
|
||||
// Not worth aiming for, but can technically still happen.
|
||||
Probably-Not
|
||||
// You expect it not to happen most of the time, but it might still be worth
|
||||
// trying for it if you're being forced to play to your outs.
|
||||
Doubtful
|
||||
// More likely that it won't happen, but a success isn't surprising.
|
||||
Unlikely
|
||||
// Either it does or it doesn't.
|
||||
Mayhapsibly
|
||||
// Decent chance it doesn't happen, but you still expect it to.
|
||||
Probably
|
||||
// You expect it to happen most of the time, but accept that there will be failures.
|
||||
Most-Likely
|
||||
// Very close to guaranteed, but technically with a small chance to fail.
|
||||
Cry-If-Not
|
||||
// Absolutely guaranteed events.
|
||||
Guaranteed
|
||||
|
||||
// Automatically generated.
|
||||
// Comparison of the `kfl` type.
|
||||
pub fun kfl/cmp(this : kfl, other : kfl) : e order
|
||||
match (this, other)
|
||||
(Impossible, Impossible) -> Eq
|
||||
(Impossible, _) -> Lt
|
||||
(_, Impossible) -> Gt
|
||||
(Probably-Not, Probably-Not) -> Eq
|
||||
(Probably-Not, _) -> Lt
|
||||
(_, Probably-Not) -> Gt
|
||||
(Doubtful, Doubtful) -> Eq
|
||||
(Doubtful, _) -> Lt
|
||||
(_, Doubtful) -> Gt
|
||||
(Unlikely, Unlikely) -> Eq
|
||||
(Unlikely, _) -> Lt
|
||||
(_, Unlikely) -> Gt
|
||||
(Mayhapsibly, Mayhapsibly) -> Eq
|
||||
(Mayhapsibly, _) -> Lt
|
||||
(_, Mayhapsibly) -> Gt
|
||||
(Probably, Probably) -> Eq
|
||||
(Probably, _) -> Lt
|
||||
(_, Probably) -> Gt
|
||||
(Most-Likely, Most-Likely) -> Eq
|
||||
(Most-Likely, _) -> Lt
|
||||
(_, Most-Likely) -> Gt
|
||||
(Cry-If-Not, Cry-If-Not) -> Eq
|
||||
(Cry-If-Not, _) -> Lt
|
||||
(_, Cry-If-Not) -> Gt
|
||||
(Guaranteed, Guaranteed) -> Eq
|
||||
|
||||
// Shows a string representation of the `kfl` type.
|
||||
pub fun kfl/show(this : kfl) : e string
|
||||
match this
|
||||
Impossible -> "impossible"
|
||||
Probably-Not -> "probably not"
|
||||
Doubtful -> "doubtful"
|
||||
Unlikely -> "unlikely"
|
||||
Mayhapsibly -> "mayhapsibly"
|
||||
Probably -> "probably"
|
||||
Most-Likely -> "most likely"
|
||||
Cry-If-Not -> "cry if not"
|
||||
Guaranteed -> "guaranteed"
|
||||
|
||||
// KFL multiplication, or the probability of cooccurrence of two independent events.
|
||||
pub fun kfl/(*)(a: kfl, b: kfl): e kfl
|
||||
val (l, h) = match a.cmp(b) // this operation is commutative
|
||||
Gt -> (b, a)
|
||||
_ -> (a, b)
|
||||
match (l, h)
|
||||
(Impossible, _) -> Impossible
|
||||
(Probably-Not, Guaranteed) -> Probably-Not
|
||||
(Probably-Not, _) -> Impossible
|
||||
(Doubtful, Guaranteed) -> Doubtful
|
||||
(Doubtful, Cry-If-Not) -> Doubtful
|
||||
(Doubtful, Most-Likely) -> Probably-Not
|
||||
(Doubtful, _) -> Impossible
|
||||
(Unlikely, Guaranteed) -> Unlikely
|
||||
(Unlikely, Cry-If-Not) -> Unlikely
|
||||
(Unlikely, Most-Likely) -> Doubtful
|
||||
(Unlikely, Probably) -> Doubtful
|
||||
(Unlikely, Mayhapsibly) -> Probably-Not
|
||||
(Unlikely, _) -> Probably-Not // (Unlikely, Unlikely) because commutative
|
||||
(Mayhapsibly, Guaranteed) -> Mayhapsibly
|
||||
(Mayhapsibly, Cry-If-Not) -> Mayhapsibly
|
||||
(Mayhapsibly, Most-Likely) -> Unlikely
|
||||
(Mayhapsibly, Probably) -> Unlikely
|
||||
(Mayhapsibly, _) -> Unlikely
|
||||
(Probably, Guaranteed) -> Probably
|
||||
(Probably, Cry-If-Not) -> Probably
|
||||
(Probably, Most-Likely) -> Mayhapsibly
|
||||
(Probably, _) -> Unlikely
|
||||
(Most-Likely, Guaranteed) -> Most-Likely
|
||||
(Most-Likely, Cry-If-Not) -> Most-Likely
|
||||
(Most-Likely, _) -> Probably
|
||||
(Cry-If-Not, Guaranteed) -> Guaranteed
|
||||
(Cry-If-Not, _) -> Cry-If-Not
|
||||
(Guaranteed, _) -> Guaranteed
|
||||
Reference in New Issue
Block a user