WebCHURCH - CheatSheet
last revision 2015/03/14 - feedback is welcome: claus.moebus(at)uni-oldenburg.de -
When working through the WebCHURCH-Tutorial Probabilistic Models of Cognition my
impression is that the official documentation is only partial compatible with the tutorial.
Furthermore, some WebCHURCH-procedures are not compatible with the SCHEME R6RS-Standard (e.g. 'apply', 'case').
Most expressions are evaluated according applicative-order.
When expressions are evaluated according normal-order (= delayed or lazy evaluation) this is mentioned explicitly.
My doc is based on:
1. the WebCHURCH doc
2. the Revised6 Report on the Algorithmic Language Scheme - R6RS
3. Dybvig, The Scheme Programming Language, MIT Press, 2009, 4/e
4. Scott, Programming Language Pragmatics, Morgan Kaufman, 2009, 3/e
5. Lunn et al., The BUGS Book - A Practical Introduction to Bayesian Analysis - , CRC Press, 2013
Math Ops
(+ val …)
- + is the name of the built-in operation for addition.
- val …: A bunch of numeric operands.
- Returns: sum of the numeric operands.
(- val …)
- - is the name of the built-in operation for subtraction.
- val …: A bunch of numeric operands.
- Returns: With two or more arguments, this procedures returns the difference of its arguments, associating to the left.
- Returns: With one argument, however, it returns the additive inverse of its argument.
(* val …)
- * is the name of the built-in operation for multiplication.
- val …: A bunch of numeric operands.
- Returns: product of the numeric operands.
(/ val …)
- / is the name of the built-in operation for division.
- val …: A bunch of numeric operands.
- Returns: With two or more arguments, this procedure returns the quotient of its arguments, associating to the left.
- Returns: With one argument, however, it returns the multiplicative inverse of its argument.
(< val1 val2 …)
- Less than ?
- val1 val2…: A bunch of two ore more numbers.
- Returns: boolean
(<= val1 val2 …)
- Less or equal ?
- val1 val2…: A bunch of two ore more numbers.
- Returns: boolean
(= val1 val2 …)
- equal ?
- val1 val2…: A bunch of two ore more numbers.
- Returns: boolean
(> val1 val2 …)
- greater than ?
- val1 val2…: A bunch of two ore more numbers.
- Returns: boolean
(>= val1 val2 …)
- greater or equal ?
- val1 val2…: A bunch of two ore more numbers.
- Returns: boolean
A
(and expr …)
- normal-order evaluation
- and is a sequential and. If there are no expr s, #t is returned. Otherwise, the expr s are evaluated from left to right until an expr returns #f or the last expr is reached. In the former case, the and expression returns a #f value without evaluating the remaining expressions. In the latter case, the last expression is evaluated and its value should be returned. In fact, WebChurch returns #t in this case.(2013/11/20)
- expr …: a sequence of expressions with a boolean value
- Returns: a boolean value
(append lst1 lst2 …)
- Append some lists together.
- lsti …: A list.
- Returns: A concatenated list.
(apply proc obj …)
- Proc: procedure
- obj : object or value
- Returns: the values of applying proc to obj
B
(binomial p n)
- is not implemented (2013/11/23) though it appears in the documentation
- A random ERP for binomial distributions
- p: probability of success
- n: number of independent trials
- Returns: number
C
(case key case-clause …)
- key: expression
- case-clause: (lst expr)
- Returns: the value of expr if the value of key is equal? to a member of lst
D
(define variable expression)
- normal-order evaluation
- The definition form describes a definition used to create variable bindings and may appear anywhere other definitions may appear.
- variable: a symbol which is bound to the value of expression.
- expression: a constant.
- expression: the value of a simple or compound procedure (e.g. a lambda-expression).
(define (variable parameter …) body )
- normal-order evaluation
- is equivalent to: (define variable (lambda (parameter …) body )).
- is the definition of a function with name variable and zero or more parameters parameter.
(density list {string})
- Displays the graph of a probability density function.
- lst: a list of samples drawn from a continous probability distribution.
- string: optional string which is used as the title of the density diagram.
(display expr)
- Displays the value of expr (including numbers, strings, lists, etc). Note: this is mostly for debugging, not for modeling (not implemented in WebChurch, 2013/11/25)
- expr: a Church expression
- Returns: void
E
(equal? obj1 obj2)
- Check if two things are equivalent. (Recursive on lists, vectors, etc.)
- obj1: Scheme object or value
- obj2: Scheme object or value
- Returns: boolean (#t or #f)
(expt val1 val2)
- Raise a number to a power val1val2
- val1: A number
- val2: A number
- Returns: the value of val1val2
F
“false” or “#f”
- boolean constant (must be written without “”)
(fifth lst)
- Returns the fifth element of a list.
- lst: the list
- Returns: the fifth element of the list
(first lst)
- Get the first element of a list or a pair.
- lst: The list or pair.
- Returns: First element of the list or pair.
(flip {weight})
- Flip a fair or weighted coin (= Bernouilli trial).
- weight: If given, the coin is biased with this weight.
- Returns: true or false
(flatten nlst)
- flattens a nested list (removes the inner parenthesis of nlst)
- nlst: a nested list
- Returns: a list of the elements of the nested list
(fold proc init lst)
- Fold. (You know you want to….)
- proc: The procedure to apply, which should take two arguments: the next value from lst 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: the accumulated value
- Example: (fold * 1 '(1 2 3)) => 6
- Example: (fold + 0 '(1 2 3)) => 6
(fourth lst)
- Returns the fourth element of a list.
- lst: the list
- Returns: the fourth element of the list
G
(gaussian mean stdev)
- A random ERP for Gaussian distributions
- : mean of the Gaussian
- stdev: standard deviation of the Gaussian
- Returns: a number sampled from the Normal (Gaussian) Distribution
(geometric weight)
- is not implemented but defined in chapter 01 of the tutorial
- The distribution of the number of failures y = x-1 where x is the number of Bernoulli trials (flips of a fair or weighted coin) required for one success to occur.
- weight: the success probability for each Bernoulli trial
- Returns: x-1 the number of failures before the success occurs
H
(hist list {string})
- displays a histogram.
- lst: a list of samples drawn from a discrete probability distribution
- string: optional string which is used as the title of the histogram.
I
(if test consequent {alternate})
- normal-order evaluation
- test, consequent, and alternate must be expressions.
- Returns: first, test is evaluated. If it yields a true value, then consequent is evaluated and its values are returned. Otherwise alternate is evaluated and its values are returned.
- Returns: If test yields #f and no alternate is specified, then the result of the expression is unspecified.
J
K
L
(lambda formals body)
- normal-order evaluation
- A lambda expression evaluates to a procedure. The environment in effect when the lambda expression is evaluated is remembered as part of the procedure.
- formals must be a formal parameter list.
- body consists of one expression (e.g. a lambda expression).
(length lst)
- Get the length of a list
- lst: The list.
- Returns: The length (an integer).
(let ((var val) …) expr …)
- Let binds variables in the scope of the body of the let.
- assignments: An expression '((var val) …)
- expr …: Body expressions that are evaluated within the environment where variables are assigned.
- Returns: the result of evaluating the last body expr
(list obj …)
- Builds a list of the values of a bunch of obj
obj …: Things to make into a list
Returns: A list of the values of the obj …
M
(map proc list …)
- Apply a procedure to each element of some lists.
- proc: The procedure to apply.
- list …: The lists to map over.
- Returns: a list of values of procedure applications.
(mem procedure)
- normal-order evaluation
- generates a memoized version of procedure.
- procedure: variable name of a procedure.
- Returns: a memoized version of procedure.
(mh-query samples lag defines query-expr condition-expr)
- normal-order evaluation
- 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.
- condition-expr = (condition boolean-expr) | boolean-expr.
- boolean-expr: Church-expression with a boolean value.
- Returns: A list of samples from the conditional distribution.
N
(null? lst)
- Check if a list is null or empty.
- lst: The list.
- Returns: boolean (#t or #f)
- Returns #t when the list is equal to '().
O
(or expr …)
- normal-order evaluation
- Or is a sequential or. If there are no expr s, #f is returned. Otherwise, the expr s are evaluated from left to right until a expr returns a #t value or the last expr is reached. In the former case, the or expression returns a #t without evaluating the remaining expressions. In the latter case, the last expression is evaluated and its value is returned. In fact, WebChurch returns the value of expr in all cases.(2013/11/20)
- expr …: a sequence of expressions with a boolean value.
- Returns: a boolean value.
P
(pair obj1 obj2)
- Build a pair (obj1 . obj2)
- obj1: The first element (can be selected by “first”)
- obj2: The second element (can be selected by “rest”)
- Returns: A pair
(pair? obj)
- Returns #t if obj is a pair (or list)
- obj: Church object
- Returns: boolean
Q
(quote datum)
- normal-order evaluation
- evaluates to datum
- datum is any valid Church-expression
- Returns: datum
'datum is equivalent to (quote datum)
- normal-order evaluation
- datum is any valid Church-expression.
R
(rejection-query defines query-expr condition-expr)
- normal-order evaluation
- implements rejection sampling, which is slow but sound.
- defines …: Definitions to evaluate – set up bindings for the query
- query-expr: The expression you want to know about
- condition-expr = (condition boolean-expr) | boolean-expr.
- Returns: A conditional sample (a value of query-expr, if the value of condition-expr is true)
(repeat N procedure)
- Repeats a procedure a given number of times.
- N: number of times to repeat.
- procedure: the procedure to repeat.
- Returns: a list where each element is the result of a call of proc. If N=0 the list is empty.
(rest lst)
- Get the tail of a list (all but the first element) or the second element of a pair
- lst: a list or a pair
- Returns: tail of list or second element of pair
S
(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 seventh element of the list
(sixth lst)
- Returns the sixth element of a list.
- lst: the list
- Returns: the sixth element of the list
(sum lst)
- Calculates the sum of elements in a list.
- lst: the list
- Returns: The sum of the list
T
(third lst)
- Returns the third element of a list.
- lst: the list
- Returns: the third element of the list
“true” or “#t”
- boolean constant (must be written without “”)
U
(uniform-draw list)
- Samples a random element from list according to a uniform pdf
- list: a list of objects
- Returns: object
V
W
X
Y
Z