Automatically generated documentation

From Church Wiki
Jump to: navigation, search
NOTE: This documentation is for Bher, an older Church compiler. The newest compiler is WebChurch; for WebChurch documentation, see https://probmods.org/webchurch/refs.html

Contents

Syntactic Sugar

(let ((var val) ...) expr ...)

  • Let binds variables in the scope of the body of the let.
  • assignments: An expression '((var val) ...)
  • exprs: Body expressions that are evaluated within the environment where variables are assigned.
  • Returns: the result of evaluating the last body expr

(let* ((var val) ...) expr ...)

  • Let* binds variables in the scope of the body of the let. Each assignment has access to the variables bound earlier on in the same let*.
  • assignments: An expression '((var val) ...)
  • exprs: Body expressions that are evaluated within the environment where variables are assigned.
  • Returns: the result of evaluating the last body expr


Compound Procedures

(all lst)

  • Checks where everything in a list is true.
  • lst: the list
  • Returns: Returns false if everything in the list is false and otherwise returns the last element of the list.

(any lst)

  • Checks whether anything in the list is true.
  • lst: the list
  • Returns: Returns false if everything in the list is false and otherwise returns the first non-false element.

(beta a b)

  • Draw from the beta distribution.
  • alpha:
  • beta:
  • Returns: a list of two numbers that sum to 1, each in the range [0, 1]

(fifth lst)

  • Returns the fifth element of a list.
  • lst: the list
  • Returns: the fifth element of the list

(filter pred lst)

  • Return a list with only the elements that satisfy the predicate.
  • pred: The predicate to filter with.
  • lst: The list to filter.
  • Returns: list

(flatten lst)

  • Recursively flatten a list of lists.
  • lst: the list of lists
  • Returns: a list where every element is is not a list

(fold proc init lst)

  • Fold. (You know you want to....)
  • proc: The procedure to apply, which should take two arguments: the next value and the accumulated value.
  • init: The value to start with (initial value for the accumulated value argument of proc).
  • lst: The list to fold over.
  • Returns: list

(for-each proc lst)

  • Applies a procedure to each element of a list. Don't use this in an actual model. It's for debugging, etc.
  • proc:: procedure to apply
  • lst:: the list
  • Returns: void.

(fourth lst)

  • Returns the fourth element of a list
  • lst: the list
  • Returns: the fourth element of the list

(list? form)

  • Test to see if a form is a list
  • form: form to test
  • Returns: true/false

(map proc . lsts)

  • Apply a procedure to each element of some lists. proc should accept as many arguments as there are lists.
  • proc: The procedure to apply.
  • lst ...: The lists to map over.
  • Returns: list

(mean lst)

  • Compute the mean of a list of numbers.
  • lst: The list.
  • Returns: number

(multinomial vals probs)

  • Draw from a multinomial. Assumes probabilities are already normalized.
  • vals: The list of values to draw from
  • probs: The probabilities of the values
  • Returns: a draw from the list of values

(noisy-lev-list-equal? list1 list2 coupling)

  • Noisy list comparison using Levenshtein distance. Returns true when (flip coupling^lev-distance). When coupling is 0 then perfect match is required. When coupling is 1, then it always returns true.
  • list1: The first list.
  • list2: The second list
  • coupling: The coupling parameter in [0,1] which states how serious you are about equality. If it is 0 then this is just (equal? list1 list2), when it is 1 always retrurn true.
  • Returns: true/false

(procedure? form)

  • Test to see if a form is a procedure or memoized procedure.
  • form: The form to test
  • Returns: true/false

(product lst)

  • Gives the product of elements in a list.
  • lst: the list
  • Returns: The product of the list

(rejection-query defines query-exp condition-exp env)

  • Rejection query: slow but sound.
  • defines ...: Definitions to evaluate -- set up bindings for the query. Must be quoted.
  • query-exp: The expression you want to know about. Must be quoted.
  • condition-exp: The expression to condition on. Must be quoted.
  • env: The environment for the query.
  • Returns: A conditional sample.

(repeat N proc)

  • Repeats a procedure a given number of times.
  • N: number of times to repeat
  • proc: the procedure to repeat
  • Returns: a list where each element is the result of a call of proc. Returns the empty list if N=0.

(reverse lst)

  • Returns the reverse of a list.
  • lst: the list
  • Returns: the reverse of the list

(second lst)

  • Returns the second element of a list.
  • lst: the list
  • Returns: the second element of the list

(seventh lst)

  • Returns the seventh element of a list
  • lst: the list
  • Returns: the second element of the list

(sixth lst)

  • Returns the sixth element of a list.
  • lst: the list
  • Returns: the sixth element of the list

(sticky-DPmem alpha proc)

  • Stochastically memoize a procedure. Uses stick-breaking representation.
  • alpha: Concentration parameter.
  • proc: The procedure to memoize. (I.e. the "base measure".)
  • Returns: A procedure that is a stochastically memoized version of proc.

(sum lst)

  • Calculates the sum of elements in a list.
  • lst: the list
  • Returns: The sum of the list.

(third lst)

  • Returns the third element of a list.
  • lst: the list The list to return an element from.
  • Returns: the third element of the list

(uniform-draw lst)

  • Draw from a list uniformly at random (could do this with multinomial instead).
  • lst: the list to draw from
  • Returns: a randomly chosen element from the list (or null, if the list is empty)

(variance lst)

  • Compute the variance of a list of numbers.
  • lst: The list.
  • Returns: number

(zip . lists)

  • Make a list of lists using the elements of the input lists. For example (zip '(1 2 3) '(4 5 6)) returns the list '((1 4) (2 5) (3 6)).
  • lst ...: The lists to zip together.
  • Returns: list


Primitive Procedures

(* val ...)

  • Multiply.
  • val ...: A bunch of numbers.
  • Returns: number

(+ val ...)

  • Plus
  • val ...: A bunch of numbers.
  • Returns: number

(- val ...)

  • Minus
  • val ...: A bunch of numbers.
  • Returns: number

(/ val ...)

  • Divide
  • val ...: A bunch of numbers.
  • Returns: number

(< val ...)

  • Less than
  • val ...: A bunch of numbers.
  • Returns: boolean

(<= val ...)

  • Less than or equal to
  • val ...: A bunch of numbers.
  • Returns: boolean

(= val ...)

  • Equals
  • val ...: A bunch of numbers.
  • Returns: number

(> val ...)

  • Greater than
  • val ...: A bunch of numbers.
  • Returns: boolean

(>= val ...)

  • Greater than or equal to
  • val ...: A bunch of numbers.
  • Returns: boolean

(abs val)

  • Absolute value function
  • val: A number
  • Returns: number

(and val ...)

  • And.
  • val ...: Each argument is a boolean.
  • Returns: boolean

(append lst ...)

  • Append some lists together.
  • lst ...: The lists.
  • Returns: A list.

(canonicalize-symbol-list lst)

  • Take a list of arbitrary objects, and return a list of integers, where each object has been assigned an integer in canonical order. Useful for converting lists of gensyms into something pleasant to look at.
  • lst: The list.
  • Returns: list

(char-lower-case? char)

  • Test if a character is lower case
  • char: A single character
  • Returns: boolean

(command-line-arguments)

  • Get the command line arguments that the host scheme was called with.
  • Returns: arguments

(cos val)

  • Compute the cosine of a number
  • val: A number
  • Returns: number

(debug-mode flag val)

  • Set the debug mode.
  • flag: Which mode to set. Must be one of 'global 'trace-eval 'importance-eval 'trace-update 'init 'mh-steps 'mh-statistics 'verbosity 'pretty-pictures 'safe-mode.
  • val: true or false
  • Returns: void

(display v)

  • Displays a value (including numbers, strings, lists, etc). Note: this is mostly for debugging, not for modeling.
  • v: The value to display
  • Returns: void

(drop N lst)

  • Removes initial N elements of lst
  • N: an integer
  • lst: a list
  • Returns: list

(eq? a b)

  • Check if two things are the exact same object in memory. Note that (eq? (list 'a) (list 'a)) is false.
  • a:
  • b:
  • Returns: boolean

(equal? a b)

  • Check if two things are equivalent. (Recursive on lists, vectors, etc.)
  • a:
  • b:
  • Returns: boolean

(exact->inexact val)

  • Convert exact (rational) numbers to inexact numbers (floating point)
  • val: A number
  • Returns: number

(exp val)

  • Exponential
  • val: A number
  • Returns: number

(expt val1 val2)

  • Raise a number to a power (val1 ^ val2)
  • val1: A number
  • val2: A number
  • Returns: boolean

(first Lst)

  • Get the first element of a list.
  • Lst: The list.
  • Returns: First element of the list.

(format)

  • TODO: PLEASE ADD DOCUMENTATION
  • Returns: number

(gensym)

  • Get a new symbol. (Note that probabilities are only defined up to identity of gensym.)
  • Returns: symbol

(inexact->exact val)

  • Convert inexact (floating point) numbers to exact numbers (rationals)
  • val: A number
  • Returns: number

(inverse-permute-list Lst I)

  • Apply the inverse of an index permutation to a list.
  • Lst: The list to permute.
  • I: The index permutation (to invert).
  • Returns: list

(iota size start step)

  • Build a list with a sequence of integers.
  • size: The length of the resulting list.
  • start: The starting value of the list. (This param is optional.)
  • step: The spacing between elements of the list. (This param is optional.)
  • Returns: A list.

(last lst)

  • Get the last element from a list.
  • lst: The list.
  • Returns: An element.

(length lst)

  • Get the length of a list
  • lst: The list.
  • Returns: The length (and integer).

(list A ...)

  • Build a list.
  • A ...: Things to make into a list.
  • Returns: A list.

(list->vector lst)

  • Turn a list into a vector.
  • lst: The list.
  • Returns: vector

(list-elt lst index)

  • Get an element from a list. (This is one-indexed: 1 is the first element.)
  • lst: The list.
  • index: The index of the element to get (starting with 1).
  • Returns: An element.

(list-ref lst index)

  • Get an element from a list. (This is zero-indexed: 0 is the first element.)
  • lst: The list.
  • index: The index of the element to get (starting with 0).
  • Returns: An element.

(log val)

  • Log (base e)
  • val: A number
  • Returns: number

(logistic val)

  • Logistic function
  • val: A number
  • Returns: number

(make-list lngth fill)

  • Make a list filled with some value.
  • lngth: The length of the list.
  • fill: The fill value.
  • Returns: A list.

(max val)

  • Returns the max of a list of numbers
  • val: A bunch of numbers.
  • Returns: number

(min val)

  • Returns the min of a list of numbers
  • val: A bunch of numbers.
  • Returns: number

(modulo x y)

  • Returns x mod y
  • x: A number
  • y: A number
  • Returns: number

(not val)

  • Not. Returns true if the argument is not false.
  • val:
  • Returns: boolean

(null? Lst)

  • Check if a list is null. Returns true when the list is equal to '().
  • Lst: The list.
  • Returns: boolean

(number->string n radix)

  • Converts a number to a string. Radix must be either 2, 8, 10, or 16. If the radix is omitted it defaults to 10
  • n: A number
  • radix: a number
  • Returns: string

(number? val)

  • Check if the argument is a number.
  • val:
  • Returns: boolean

(or val ...)

  • Or.
  • val ...: Each argument is a boolean.
  • Returns: boolean

(pair A B)

  • Build a pair.
  • A: The first element.
  • B: The second element.
  • Returns: A pair.

(pair? x)

  • Returns true if x is a pair (or list)
  • x:
  • Returns: boolean

(permute-list Lst I)

  • Apply an index permutation to a list. (Use this to apply the result of sample-index-permutation.)
  • Lst: The list to permute.
  • I: The index permutation.
  • Returns: list

(pretty-print val)

  • Pretty prints.
  • val: Something to make pretty then print to screen.
  • Returns: void

(range from to)

  • Build a list with a range of integers.
  • from: Starting value.
  • to: Ending value.
  • Returns: A list (includes from and to values).

(rest Lst)

  • Get the tail of a list (all but the first element).
  • Lst: The list.
  • Returns: Tail of list.

(scheme-list? Lst)

  • Check if something is a list in the underlying Scheme.
  • Lst: The list.
  • Returns: boolean

(sin val)

  • Compute the sine of a number
  • val: A number
  • Returns: number

(string chars ...)

  • Concatenates characters into a string
  • chars ...: A bunch of characters
  • Returns: string

(string->number s radix)

  • Converts a string to a number. Radix must be either 2, 8, 10, or 16. If the radix is omitted the default is 10.
  • s: A string
  • radix: A number
  • Returns: number

(string-append strings ...)

  • Concatenates strings together
  • strings ...: A bunch of strings
  • Returns: string

(string-ref string n)

  • Return the n'th character of string (0 indexed)
  • string: A string
  • n: A number
  • Returns: character

(symbol->string s)

  • Converts a symbol to a string.
  • s: A symbol
  • Returns: string

(symbol? x)

  • Returns true if x is a symbol
  • x:
  • Returns: boolean

(take)

  • TODO: PLEASE ADD DOCUMENTATION
  • Returns: number

(tan val)

  • Compute the tangent of a number
  • val: A number
  • Returns: number

(vector val ...)

  • Build a vector.
  • val ...: The entries of the vector.
  • Returns: vector

(vector->list vect)

  • Turn a vector into a list.
  • vect: The vector.
  • Returns: list

(vector-ref vect ind)

  • Get an element from a vector. (Zero indexed.)
  • vect: The vector.
  • ind: The index.
  • Returns: An element.

(void)

  • Void.
  • Returns: void

(xor val ...)

  • Xor.
  • val ...: Each argument is a boolean.
  • Returns: boolean


Elementary Random Procedures

(binomial p n)

  • A random ERP for binomial distributions
  • p: number of independent trials
  • n: probability of success
  • Returns: number

(dirichlet alpha)

  • A random ERP for dirichlet distributions
  • alpha: a list of positive real numbers (pseudocounts)
  • Returns: a discrete probability distribution (represented by a list of numbers in [0, 1]) with dimension equal to the length of the input list

(exponential inv-mean)

  • A random ERP for exponential distributions
  • inv-mean: rate parameter
  • Returns: number

(flip weight)

  • Flip a fair or weighted coin.
  • weight: If given, the coin is biased with this weight.
  • Returns: true or false

(gamma k theta)

  • An ERP for gamma distributions
  • k: shape parameter
  • theta: scale parameter
  • Returns: number

(gaussian mean standard)

  • A random ERP for Gaussian distributions
  • mean:
  • standard: deviation
  • Returns: number

(log-flip weight)

  • Flip a fair or weighted coin with weights from log space.
  • weight: If given, the coin is biased with (exp weight).
  • Returns: true or false

(poisson lambda)

  • A random ERP for Poisson distributions
  • lambda: expected number of occurrences, a positive real number
  • Returns: number

(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.
  • weights: a list of weights
  • Returns: an integer between 0 and (length weights)-1

(sample-index-permutation size)

  • Sample a permutation of indices for a list.
  • size: of list to permute.
  • Returns: number

(sample-integer n)

  • Return a random integer between 0 and n-1.
  • n: the number of values possible
  • Returns: an integer between 0 and n-1

(uniform a b)

  • Draw a uniform random number from the range [a, b].
  • a: lower bound
  • b: upper bound
  • Returns: number


Queries

(mh-query samples lag defines query-expr cond-expr)

  • Do inference using the Metropolis-Hastings algorithm (as described in Goodman, et al., 2008).
  • samples: The number of samples to take.
  • lag: The number of iterations in between samples.
  • defines ...: A sequence of definitions (usually setting up the generative model).
  • query-expr: The query expression.
  • cond-expr: The condition expression.
  • Returns: A list of samples from the conditional distribution.


Primitive Constants

Personal tools