Troll quick reference

For a full description, see the Troll manual

Using the web interface

You can choose a dice roll from one of the two drop-down lists. This will bring the roll definition into the text area below the lists. I make no guarantee about the correctness of user-contributed rolls, so use these with caution.

Alternatively, you can modify the dice definition in the text area (or replace it with something entirely different).

When you press the "Make random rolls" button, Troll will make a number of random dice rolls. You can change the number of rolls by entering a new number in the box.

When you press the "Calculate probabilities" button, Troll will produce a probability distribution that for each possible outcome shows its probability as well as an accumulated probability. The latter can be one of >=, <=, > or <. The probabilities of individual outcomes is also shown as a bar chart.

If the results are single numbers, an average, spread and mean deviation is also calculated and shown below the table of probabilities.

You can change the number of digits of precision shown in the table and you can change the bound on the number of iterations of the accumulate loop and recursive calls (see below).

If you have made a dice-roll definition that you want to reuse later or want to share with others, write a short description in the text box below the buttons and press one of the buttons. Your roll is now added to the list of user-contributed rolls using the description as label. The description is also added as a comment to the dice-roll definition, so you shouldn't do that yourself. If you use a description that is already in the list, the entry will be overwritten. This way, you can save a roll and edit it later. Please only change your own entries.

I will from time to time remove junk from the list. If you see offensive text in this list, please email me at, and I will remove it.

There are some restrictions for probability calculation:

Summary of dice-roll notation

dn    or    Dn roll one dn (a die labeled 1 - n)
mdn    or    mDn roll m dn
zn    or    Zn roll one zn (a die labeled 0 - n)
mzn    or    mZn roll m zn
+, -, *, /, mod arithmetic on single values
sgn sign of number (as -1, 0 or 1)
sum add up values in collection
count count values in collection
U    or    @ union of collections
{e1,...,en} union of e1,...,en
min, max minimum or maximum value in collection
minimal, maximal all minimum or maximum values in collection
median the median value in a collection
least n, largest n n least or n largest values in collection
m # e m samples of e
.. range of values
choose choose value from collection
e pick n pick (without replacement) n values from collection e
<, <=, >, >= , =, =/= filters: Keep values from 2nd argument that compare to 1st argument
drop elements found in 1st argument and not in 2nd
keep elements found in 1st argument that are also found in 2nd
-- multiset difference
different remove duplicates
if-then-else conditional. Any non-empty is considered true
?p return 1 with probability p and {} otherwise
& substitute for logical and
! substitute for logical not
x := e1; e2 bind x to value of e1 in e2.
foreach x in e1 do e2 evaluate e2 for each value in e1 and union the results.
repeat x := e1 while/until e2 repeatedly evaluate e1 while or until e2 becomes true (non-empty). Return last value
accumulate x := e1 while/until e2 repeatedly evaluate e1 while or until e2 becomes true (non-empty). Return union of all values
function define function
compositional define compositional function
call call function
' make text box of single sample
n ' make text box of n samples (right-aligned)
|| Combine text boxes horisontally
|> Combine text boxes vertically, left-aligned
<| Combine text boxes vertically, right-aligned
<> Combine text boxes vertically, centre-aligned
[e1,e2] Pair of e1,e2
%1 First component of pair
%2 Second component of pair
~ x~v returns the value of x if x is defined and otherwise returns v

The text-box features are not available in the probability calculator.

Variables, spaces and comments

Variable names are sequences of letters (both upper and lower case), so they can not contain digits. Nor can variable names be identical to operators (e.g., d, z or sum). Names are case-sensitive.

Spaces are optional in most places, but space is required between two adjacent numbers and between two adjacent alphabetical operators or variables. For example, "dX" is a variable called "dX", while "d X" is a die with X sides. Similarly, "Nd6" is a variable called "Nd" followed by the number 6, while "N d6" is a collection of N d6s.

Comments can be added to die-roll definitions. Comments begin with a backslash ("\") and extend until the end of the line.

Operator precedences

Operator precedences from highest to lowest are:

Grouping Operators
n/a prefix D     prefix d      prefix Z      prefix z
right infix D      infix d      infix Z      infix z      #      ~
right =      <      >      <=      >=      =/=
n/a choose      count      sum      sgn      min      max      least      largest     different     minimal     maximal     median      '      %1     %2      ! 
n/a prefix -
left *      /      mod
left +      infix -
right @      U      &     
left drop      keep      pick      --
none ..
right |>      <|      <>      ||
n/a else      while      until     do
right ;

When the left column in the table says "left", "right" or "none", the operators in the right column are infix operators, otherwise (i.e, if the left column says "n/a") they are prefix or multi-operand operators. The text prefix or infix is not part of the operator name, it just indicates whether the operator is used as an infix operator or a prefix operator.

When two operators from the same group can be combined, they are grouped left or right according to the left column of the table above, so for example 3<6>x is equivalent to 3<(6>x) while d6+d8-3 is equivalent to (d6+d8)-3. Parentheses can be used to override the precedences.

There are two cases of minus: A prefix minus binds more tightly than *, but infix minus binds like +. Similarly, prefix d binds tighter than infix d.

Note that you can not group several occurrences of .., i.e., 2..3..4 is not valid syntax. Hence, the grouping is "none".