Symbolic outcomes
Thanks to optype, dyce offers typing support for arbitrary number-like outcomes, including primitives from symbolic expression packages such as SymPy.
1 2 3 4 5 6 7 | |
Note
Be aware that, depending on implementation, performance can suffer quite a bit when using symbolic primitives, especially with large histograms or pools.
For histograms and pools, dyce remains opinionated about ordering.
For non-critical contexts where relative values are indeterminate, dyce will attempt a “natural” ordering based on the string representation of each outcome.
This is to accommodate symbolic expressions whose relative values are often unknowable.
1 2 3 4 5 6 7 | |
In practice, that means that certain operations won’t work with symbolic expressions where correctness depends on ordering outcomes according to relative value (e.g., dice selection from pools).
Flattening pools (e.g., via P.h) works.
1 2 3 4 5 6 7 8 | |
Enumerating rolls works.
1 2 | |
P.sample works.
1 2 | |
Selection (e.g., via P.at) “works” (i.e., falls back to natural ordering of outcomes), but that is a deliberate compromise of convenience.
1 2 | |
P.apply_to_each_h can help pave the way back to concrete outcomes.
1 2 3 | |
