Work in progress: email probmods@gmail.com with corrections (or send a pull request on Github)
(all lst)
Test whether all of the values in a list are true
lst | list | List of boolean values |
(and [b ...])
Logical conjunction
[b ...] | boolean | Boolean values |
(append [lst ...])
Merge an arbitrary number of lists
(apply fn lst)
If lst is (x1 x2 x3 ...), returns the function call (fn x1 x2 x3 ...)
(assoc x alist)
Lookup a value in an association list
(atan2 y x)
Arctangent (quotient version)
(bang-bang x)
Coerce an object to a boolean
(beta a b [conditionedValue])
Sample from the beta distribution B(a,b). Returns only the first element.
a | positive real | |
b | positive real | |
[conditionedValue] | | |
(boolean->number b)
Convert a boolean to a number
(bootstrap fn fileName n)
fn | function | |
fileName | string | |
n | nat | |
(but-last lst)
Aliases: initial
Get everything except the last item in a list
(ceil x)
Aliases: ceiling
Ceiling of a number
(compose [f ...])
Aliases: o
compose functions: ((o f g) a) == (f (g a))
(condition-equal comp value)
(condition-repeat-equal comp values)
(conditional comp params)
comp | function | |
params | list | List 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
(curry f)
Aliases: c
curry function: (f::a)::b -> f::a,b
(difference lst [lst ...])
difference of sets
(dirichlet alpha [conditionedValue])
Sample from the Dirichlet distribution Dir(alpha).
alpha | list | |
[conditionedValue] | | |
(display [s ...])
Aliases: print,pn
(div [x] [y ...])
Aliases: /
Divide numbers. Returns x / (y1 * y2 * ... )
[x] | real | Numerator |
[y ...] | real | Denominator values |
(DPmem alpha f)
Stochastic memoization using the Dirichlet Process
alpha | positive real | Concentration parameter of the DP |
f | function | Function 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.
(enumeration-query comp)
Do enumeration query on a model
(eq [x ...])
Aliases: =
Test whether all (numeric) arguments are equal
(eq? x y)
Type-strict and reference-based equality check (e.g., (eq? '(1 2) '(1 2)) returns #f)
(equal? x y)
Less strict and value-based equality check (e.g., (equal? '(1 2) '(1 2)) returns #f)
(eval lst)
Evaluate a list representing a Church s-expression, e.g., (eval (list + 1 2))
returns 3
(exponential rate [conditionedValue])
Sample from the exponential distribution with parameter rate
rate | positive real | |
[conditionedValue] | | |
(expt x y)
Aliases: pow
Compute x raised to the power y
(fifth lst)
Get the fifth item of a list
(filter pred lst)
Select subset of elements of a list that satisfy a predicate pred
(first lst)
Aliases: car
Get the first item of a list (or pair)
(flip [p] [conditionedValue])
Flip a weighted coin. Returns true or false
[p] | real | |
[conditionedValue] | | |
(floor x)
Floor of a number
(fold f init [lst ...])
Accumulate the result of applying a function to a list
f | function | Function to apply |
init | | Seed value for function |
[lst ...] | list | List to apply the fold over |
(foldl f init lst)
Accumulate the result of applying a function to a list left to right
f | function | Function to apply |
init | | Seed value for function |
lst | list | List to apply the fold over |
(foldr f init lst)
Accumulate the result of applying a function to a list right to left
f | function | Function to apply |
init | | Seed value for function |
lst | list | List to apply the fold over |
(for-each fn lst)
Apply a function to every member of a list, but don't return anything
(fourth lst)
Get the fourth item of a list
(gamma a b [conditionedValue])
Sample from the gamma distribution G(a,b)
a | real | |
b | real | |
[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
(greater x [y ...])
Aliases: >
Test whether x is greater than all y's
(identity v)
Aliases: id
The Identity function
(intersection [lst ...])
intersection of sets
(iota count [start] [step])
Create list based on arithmetic progressions
count | nat | Number of items |
[start] | real | First item in list |
[step] | real | Difference between successive items in the list |
(js-debug )
Trigger the javascript debugger
(last lst)
Get the last item in a list
(length lst)
Get the length of a list
(leq x [y ...])
Aliases: <=
Test whether x is less than or equal to all y's
(less x [y ...])
Aliases: <
Test whether x is less than all y's
(list [...])
List constructor
(list-elt lst n)
Get the nth item of a list (1-indexed)
(list-index lst x)
Aliases: position
(list-ref lst n)
Get the nth item of a list (0-indexed)
(list? x)
Test whether x is a list
(load-url path)
Load a remote url
(log x)
Natural logarithm
(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')
(make-list n x)
Make a list of length n where all elements are x
(map fn [lst ...])
Apply a function to every element of a list
(map-at lst i f)
Aliases: f-at
(max [x ...])
Maximum of arguments
(mean lst)
Mean of a list
(member x list [cmp])
Test whether x is in a list according to some optional comparator function cmp
(mh-query comp samples lag)
(mh-query-scored comp samples lag)
(min [x ...])
Minimum of arguments
(minus [x ...])
Aliases: -
Subtract numbers
[x ...] | real | Numbers to subtract |
(mod x y)
Aliases: modulo
Modulo. Returns x mod y
(mult [x ...])
Aliases: *
Multiply numbers
[x ...] | real | Numbers to multiply |
(multi-equals-condition fn n value)
fn | function | |
n | nat | |
value | list | |
(multinomial lst probs [conditionedValue])
Sample an element from lst with the probability specified in probs
lst | list | |
probs | list | |
[conditionedValue] | | |
(none lst)
Test whether none of the values in a list are true
lst | list | List of boolean values |
(nub lst)
Remove duplicates with equality as ===
(null? x)
Test whether x is null
(number->boolean x)
Convert a number to a boolean
(number->string x)
Convert a number to a string
(or [b ...])
Logical disjunction
[b ...] | boolean | Boolean values |
(pair head tail)
Aliases: cons
Pair constructor
(pair? x)
Test whether x is a pair
(partition pred lst)
Partition elements of a list into those that satisfy a predicate and those that don't
(plus [x ...])
Aliases: +
Add numbers
[x ...] | real | Numbers to add |
(prod lst)
Multiply a list of numbers
lst | list | List of numbers to multiply |
(pw-geq x [y ...])
Aliases: .>=.
Test whether greater than or equal to applies transitively
(pw-greater x [y ...])
Aliases: .>.
Test whether greater applies transitively
(pw-leq x [y ...])
Aliases: .<=.
Test whether less than or equal to applies transitively
(pw-less x [y ...])
Aliases: .<.
Test whether less than applies transitively
(random-integer n [conditionedValue])
Aliases: sample-integer
(range start end)
Create list based on a range
(read-csv fileName [sep])
fileName | string | |
[sep] | string | |
(regexp-split s sep)
Aliases: string-split
Split a string into a list of substrings based on a separator
(repeat n f)
Repeat a function n times
n | nat | Number of times to repeat |
f | function | Function to repeat |
(rest x)
Aliases: cdr
Get everything after the first item in a pair or list
(reverse lst)
Reverse a list
(sample thunk)
apply a thunk
(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.
(second lst)
Get the second item of a list
(set-seed seed)
Seed a seed for the PRNG
(seventh lst)
Get the seventh item of a list
(sixth lst)
Get the sixth item of a list
(soft-equal y x tol)
Aliases: soft=
Check whether y is in the interval [x - tol, x + tol]
(some lst)
Aliases: any
Test whether some of the values in a list are true
lst | list | List 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
(string->number s)
Convert a string to a number
(string->symbol s)
Convert a string to a symbol
(string-append [x ...])
Concatenates the given strings
[x ...] | string | Strings to concatenate |
(string-append [s ...])
Append an arbitrary number of strings
(string-length string)
Get the length of string
(string-slice string start [end])
Extract a substring from a string
string | string | |
start | nat | |
[end] | nat | |
(stringify x)
Convert an object to a string
(sum lst)
Sum a list of numbers
lst | list | List of numbers to sum |
(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.
(third lst)
Get the third item of a list
(transpose mat)
Transpose list of lists
(uncurry f)
Aliases: uc
uncurry function: f::a,b -> (f::a)::b
(uniform a b [conditionedValue])
Sample a random real uniformly from the interval [a,b]
a | real | |
b | real | |
[conditionedValue] | | |
(uniform-draw items [conditionedValue])
Uniformly sample an element from a list
items | list | |
[conditionedValue] | | |
(union [lst ...])
union of sets
(unique lst [eq])
Get the unique items in a list
lst | list | |
[eq] | function | Optional equality comparison function |
(update-list lst n value)
(variance lst)
Aliases: var
Population variance
(write-csv data fileName [sep])
data | list
| |
fileName | string | |
[sep] | string | |
(zip [lst ...])
Zip together lists using longest list as base -- is invertable
(zipT [lst ...])
Zip together lists using shortest list as base -- not invertable as it truncates