Work in progress: email probmods@gmail.com with corrections (or send a pull request on Github)

(abs x)
Absolute value
xreal
(acos x)
Arccosine
xreal
(all lst)
Test whether all of the values in a list are true
lstlistList of boolean values
(and [b ...])
Logical conjunction
[b ...]booleanBoolean values
(append [lst ...])
Merge an arbitrary number of lists
[lst ...]list
(apply fn lst)
If lst is (x1 x2 x3 ...), returns the function call (fn x1 x2 x3 ...)
fnfunction
lstlist
(asin x)
Arcsine
xreal
(assoc x alist)
Lookup a value in an association list
x
alistlist
(atan x)
Arctangent
xreal
(atan2 y x)
Arctangent (quotient version)
yreal
xreal
(bang-bang x)
Coerce an object to a boolean
x
(beta a b [conditionedValue])
Sample from the beta distribution B(a,b). Returns only the first element.
apositive real
bpositive real
[conditionedValue]
(boolean->number b)
Convert a boolean to a number
bboolean
(bootstrap fn fileName n)
fnfunction
fileNamestring
nnat
(but-last lst)
 Aliases: initial
Get everything except the last item in a list
lstlist
(ceil x)
 Aliases: ceiling
Ceiling of a number
xreal
(compose [f ...])
 Aliases: o
compose functions: ((o f g) a) == (f (g a))
[f ...]function
(condition-equal comp value)
comp
value
(condition-repeat-equal comp values)
comp
values
(conditional comp params)
compfunction
paramslistList where the first element is the sampling strategy, one of ("enumeration", "rejection, "mh"), if "mh", second element is the lag
(console-log [s ...])
Print arguments to Javascript console
[s ...]
(cos x)
Cosine
xreal
(curry f)
 Aliases: c
curry function: (f::a)::b -> f::a,b
ffunction
(difference lst [lst ...])
difference of sets
lstlist
[lst ...]list
(dirichlet alpha [conditionedValue])
Sample from the Dirichlet distribution Dir(alpha).
alphalist
[conditionedValue]
(display [s ...])
 Aliases: print,pn
[s ...]
(div [x] [y ...])
 Aliases: /
Divide numbers. Returns x / (y1 * y2 * ... )
[x]realNumerator
[y ...]realDenominator values
(DPmem alpha f)
Stochastic memoization using the Dirichlet Process
alphapositive realConcentration parameter of the DP
ffunctionFunction to stochastically memoize
(drop lst n)
Drop the first n items from a list. If there are fewer than n items in the list, return the empty list.
lstlist
nnat
(enumeration-query comp)
Do enumeration query on a model
comp
(eq [x ...])
 Aliases: =
Test whether all (numeric) arguments are equal
[x ...]real
(eq? x y)
Type-strict and reference-based equality check (e.g., (eq? '(1 2) '(1 2)) returns #f)
x
y
(equal? x y)
Less strict and value-based equality check (e.g., (equal? '(1 2) '(1 2)) returns #f)
x
y
(eval lst)
Evaluate a list representing a Church s-expression, e.g., (eval (list + 1 2)) returns 3
lst
(exp x)
Exponential
xreal
(exponential rate [conditionedValue])
Sample from the exponential distribution with parameter rate
ratepositive real
[conditionedValue]
(expt x y)
 Aliases: pow
Compute x raised to the power y
xreal
yreal
(fifth lst)
Get the fifth item of a list
lstlist
(filter pred lst)
Select subset of elements of a list that satisfy a predicate pred
predfunction
lstlist
(first lst)
 Aliases: car
Get the first item of a list (or pair)
lstpair
(flatten lst)
lstlist
(flip [p] [conditionedValue])
Flip a weighted coin. Returns true or false
[p]real
[conditionedValue]
(floor x)
Floor of a number
xreal
(fold f init [lst ...])
Accumulate the result of applying a function to a list
ffunctionFunction to apply
initSeed value for function
[lst ...]listList to apply the fold over
(foldl f init lst)
Accumulate the result of applying a function to a list left to right
ffunctionFunction to apply
initSeed value for function
lstlistList to apply the fold over
(foldr f init lst)
Accumulate the result of applying a function to a list right to left
ffunctionFunction to apply
initSeed value for function
lstlistList to apply the fold over
(for-each fn lst)
Apply a function to every member of a list, but don't return anything
fnfunction
lstlist
(fourth lst)
Get the fourth item of a list
lstlist
(gamma a b [conditionedValue])
Sample from the gamma distribution G(a,b)
areal
breal
[conditionedValue]
(gaussian [mu] [sigma] [isStructural] [conditionedValue])
Sample from the Gaussian distribution N(mu, sigma)
[mu]real
[sigma]real
[isStructural]
[conditionedValue]
(gensym )
A default gensym (prefix is g)
(geq x [y ...])
 Aliases: >=
Test whether x is greater than or equal to all y's
xreal
[y ...]real
(get-time )
(greater x [y ...])
 Aliases: >
Test whether x is greater than all y's
xreal
[y ...]real
(identity v)
 Aliases: id
The Identity function
v
(intersection [lst ...])
intersection of sets
[lst ...]list
(iota count [start] [step])
Create list based on arithmetic progressions
countnatNumber of items
[start]realFirst item in list
[step]realDifference between successive items in the list
(js-debug )
Trigger the javascript debugger
(last lst)
Get the last item in a list
lstlist
(length lst)
Get the length of a list
lstlist
(leq x [y ...])
 Aliases: <=
Test whether x is less than or equal to all y's
xreal
[y ...]real
(less x [y ...])
 Aliases: <
Test whether x is less than all y's
xreal
[y ...]real
(list [...])
List constructor
[...]
(list-elt lst n)
Get the nth item of a list (1-indexed)
lstlist
nnat
(list-index lst x)
 Aliases: position
lstlist
x
(list-ref lst n)
Get the nth item of a list (0-indexed)
lstlist
nnat
(list? x)
Test whether x is a list
x
(load-url path)
Load a remote url
pathstring
(log x)
Natural logarithm
xreal
(make-gensym [prefix])
Returns a gensym, which is a function that returns a new string value every time you call it (i.e., you're guaranteed to never get the same return value twice). You can specify an optional prefix for these values (default is 'g')
[prefix]string
(make-list n x)
Make a list of length n where all elements are x
nnat
x
(map fn [lst ...])
Apply a function to every element of a list
fnfunction
[lst ...]list
(map-at lst i f)
 Aliases: f-at
lstlist
inat
ffunction
(max [x ...])
Maximum of arguments
[x ...]real
(mean lst)
Mean of a list
lstlist
(member x list [cmp])
Test whether x is in a list according to some optional comparator function cmp
x
listlist
[cmp]function
(mh-query comp samples lag)
comp
samplesnat
lagnat
(mh-query-scored comp samples lag)
comp
samplesnat
lagnat
(min [x ...])
Minimum of arguments
[x ...]real
(minus [x ...])
 Aliases: -
Subtract numbers
[x ...]realNumbers to subtract
(mod x y)
 Aliases: modulo
Modulo. Returns x mod y
xreal
yreal
(mult [x ...])
 Aliases: *
Multiply numbers
[x ...]realNumbers to multiply
(multi-equals-condition fn n value)
fnfunction
nnat
valuelist
(multinomial lst probs [conditionedValue])
Sample an element from lst with the probability specified in probs
lstlist
probslist
[conditionedValue]
(none lst)
Test whether none of the values in a list are true
lstlistList of boolean values
(not b)
Logical negation
bbooleanBoolean value
(nub lst)
Remove duplicates with equality as ===
lstlist
(null? x)
Test whether x is null
x
(number->boolean x)
Convert a number to a boolean
xreal
(number->string x)
Convert a number to a string
xreal
(or [b ...])
Logical disjunction
[b ...]booleanBoolean values
(pair head tail)
 Aliases: cons
Pair constructor
head
tail
(pair? x)
Test whether x is a pair
x
(partition pred lst)
Partition elements of a list into those that satisfy a predicate and those that don't
predfunction
lstlist
(plus [x ...])
 Aliases: +
Add numbers
[x ...]realNumbers to add
(prod lst)
Multiply a list of numbers
lstlistList of numbers to multiply
(pw-geq x [y ...])
 Aliases: .>=.
Test whether greater than or equal to applies transitively
xreal
[y ...]real
(pw-greater x [y ...])
 Aliases: .>.
Test whether greater applies transitively
xreal
[y ...]real
(pw-leq x [y ...])
 Aliases: .<=.
Test whether less than or equal to applies transitively
xreal
[y ...]real
(pw-less x [y ...])
 Aliases: .<.
Test whether less than applies transitively
xreal
[y ...]real
(random-integer n [conditionedValue])
 Aliases: sample-integer
nnat
[conditionedValue]
(range start end)
Create list based on a range
startinteger
endinteger
(read-csv fileName [sep])
fileNamestring
[sep]string
(read-file fileName)
fileNamestring
(regexp-split s sep)
 Aliases: string-split
Split a string into a list of substrings based on a separator
sstring
sepstring
(rejection-query comp)
comp
(repeat n f)
Repeat a function n times
nnatNumber of times to repeat
ffunctionFunction to repeat
(rest x)
 Aliases: cdr
Get everything after the first item in a pair or list
xpair
(reverse lst)
Reverse a list
lstlist
(round x)
Round a number
xreal
(sample thunk)
apply a thunk
thunkfunction
(sample-discrete weights)
Takes a list of weights and samples an index between 0 and (number of weights - 1) with probability proportional to the weights.
weightslist
(second lst)
Get the second item of a list
lstlist
(set-seed seed)
Seed a seed for the PRNG
seedstring
(seventh lst)
Get the seventh item of a list
lstlist
(sin x)
Sine
xreal
(sixth lst)
Get the sixth item of a list
lstlist
(soft-equal y x tol)
 Aliases: soft=
Check whether y is in the interval [x - tol, x + tol]
yreal
xreal
tolreal
(some lst)
 Aliases: any
Test whether some of the values in a list are true
lstlistList of boolean values
(sort lst [cmp])
Sort a list according to a comparator function cmp(a,b) that returns a number greater than 0 if a > b, 0 if a == b, and a number less than 0 if a < b
lstlist
[cmp]function
(sqrt x)
Square root
xreal
(string->number s)
Convert a string to a number
sstring
(string->symbol s)
Convert a string to a symbol
sstring
(string-append [x ...])
Concatenates the given strings
[x ...]stringStrings to concatenate
(string-append [s ...])
Append an arbitrary number of strings
[s ...]string
(string-length string)
Get the length of string
stringstring
(string-slice string start [end])
Extract a substring from a string
stringstring
startnat
[end]nat
(stringify x)
Convert an object to a string
x
(sum lst)
Sum a list of numbers
lstlistList of numbers to sum
(symbol->string sym)
symstring
(take lst n)
Get the first n items in a list. If there are fewer than n items in the list, returns just the list.
lstlist
nnat
(tan x)
Tangent
xreal
(third lst)
Get the third item of a list
lstlist
(transpose mat)
Transpose list of lists
matlist
(uncurry f)
 Aliases: uc
uncurry function: f::a,b -> (f::a)::b
ffunction
(uniform a b [conditionedValue])
Sample a random real uniformly from the interval [a,b]
areal
breal
[conditionedValue]
(uniform-draw items [conditionedValue])
Uniformly sample an element from a list
itemslist
[conditionedValue]
(union [lst ...])
union of sets
[lst ...]list
(unique lst [eq])
Get the unique items in a list
lstlist
[eq]functionOptional equality comparison function
(update-list lst n value)
lstlist
nnat
value
(variance lst)
 Aliases: var
Population variance
lstlistList of numbers
(write-csv data fileName [sep])
datalist
fileNamestring
[sep]string
(zip [lst ...])
Zip together lists using longest list as base -- is invertable
[lst ...]list
(zipT [lst ...])
Zip together lists using shortest list as base -- not invertable as it truncates
[lst ...]list