The interactive interpreter provides a read-eval-loop for IBAL. Programs can be entered and loaded, observations made, and queries asked. The interpreter maintains a set of IBAL libraries and defined entities that can be queried.
Three types of things can be entered at the IBAL prompt:
queries, declarations and commands.
Entries can take multiple lines. If a line ends with a backslash
\, it is continued on to the next line. No space is inserted.
A query is just an IBAL expression entered on the IBAL command line. When the query is evaluated, a probability distribution over the outcome of the expression is returned. The distribution is presented as a table. The table has a column for each simple component of the outcome. Each row of the table represents a possible value of the outcome, by designating an atomic value for each simple component. At the end of the row is the probability of the value. There may also be a utility, if there is a non-zero utility associated with the value. This is the expected utility associated with the evaluation, given that the outcome has the value in the row.
One may also query the type or the support of an expression.
To query the type, use the command :t, followed by the
expression.
To query the support, use the command :r, followed by the
expression.
IBAL maintains a current context of declarations.
Each time a declaration is entered at the IBAL prompt, it is added to
the context.
The context affects the evaluation of all future queries.
You can view the current context with the :p command, clear
it with the :c command, and save it as an IBAL program with the
:s command.
Asserting evidence is the same as making an observation, as in an IBAL
program.
Any of the standard forms may be used:
obs c, obs ~c and obs c = p,
where c is a chain and p is a pattern.
Future queries are conditioned on the evidence being true.
It is an error to assert evidence that has 0 probability of being
true.
Evidence is cumulative. If multiple items of evidence are asserted about a variable, future queries are conditioned on all of them. It is an error to assert contradictory evidence.
Evidence can be retracted, by issuing the command
retract c, where c is a chain, at the command line.
This has the effect of retracting the last item of evidence asserted
about c, so that future queries are no longer conditioned on it.
If multiple items were asserted about c, only the last one is
retracted.
The item retracted is the last item asserted directly about c,
not about an embedded component of c, and not indirectly about
c as an embedded component of another chain.
For example,
x = <a : <h : flip 0.5, j : flip 0.5, k : flip 0.5, l : flip 0.5>> obs x.a = <true,_,_,_> obs x.a = <_,false,_,_> obs x = <_,_,false,_> obs x.a.l retract x.aOnly the second observation is retracted. After the retraction,
x.a is known to match the pattern <true,_,false,true>.
Each subsequent retraction will retract one additional item of
evidence.
In the above example, another
retract x.a will retract the first observation.
A variable can be defined at the IBAL prompt, using the standard
declaration syntax x = e where x is a name and e
is an expression. As usual, one may use the form
f(x_1,...,x_n) = e to define a function with name f that
takes arguments x_1 to x_n and has body e.
The newly defined name is available for use in future queries.
One can also introduce other declarations at the IBAL prompt, such as new type definitions, decision variables, utilities, and learnable parameters. These affect the evaluation of a future query, in the same way as if they had been specified as part of the query itself. One can think of the IBAL top level as a block which is refined incrementally.
IBAL programs can be loaded into the interpreter using the :l
command, followed by the name of the file. If the file ends in the
suffix .ibl, the suffix can be omitted from the load command.
IBAL will search for the file in the current IBAL path.
Loading a file x.ibl is equivalent to defining a variable
x to be the block described in the the file.
The following is a summary of the commands available at the IBAL prompt:
:q |
Exit IBAL (CTRL-D may also work) |
:? |
Print a help message |
:l file |
Load an IBAL library |
:s file |
Save the current context as an IBAL library |
:c |
Empty the current context |
:p |
Show the current context |
:r expr |
Show the support of an expression |
:t expr |
Show the type of an expression |
:i dir |
Add a directory to the IBAL path |
IBAL uses the ledit command line editor, developed by Daniel
de Rauglaudre at INRIA Rocquencourt. ledit provides command line
history and editing features. The following information
is taken from the ledit man page.
Here is the list of editing commands
(where ^ stands for CTRL and M- for
the Meta key (usually ESC))
^a |
: | beginning of line |
^e |
: | end of line |
^f |
: | forward char |
^b |
: | backward char |
M-f |
: | forward word |
M-b |
: | backard word |
^p |
: | previous line in history |
^n |
: | next line in history |
M-< |
: | first line in history |
M-> |
: | last line in history |
^r |
: | reverse search in history (see below) |
^d |
: | delete char (or EOF if the line is empty) |
^h |
: | (or BACKSPACE) backward delete char |
^t |
: | transpose chars |
M-c |
: | capitalize word |
M-u |
: | upcase word |
M-l |
: | downcase word |
M-d |
: | kill word |
M-^h |
: | (or M-DEL or M-BACKSPACE) backward kill word |
^q |
: | insert next char (useful for control characters) |
^k |
: | cut until end of line |
^y |
: | paste |
^u |
: | line discard |
^l |
: | refresh line |
^g |
: | abort prefix |
^c |
: | interrupt |
^z |
: | suspend |
RETURN : |
send line | |
^x |
: | send line and show next history line |
| other | : | insert char |
The arrow keys can be used, providing your keyword returns standard key sequences:
| up arrow | : | previous line in history |
| down arrow | : | next line in history |
| right arrow | : | forward char |
| left arrow | : | backward char |
The reverse search in incremental, i.e. ledit backward searches in the history for a line holding the characters typed. If you type "a", it finds the first line before the current line holding an "a" and displays it. If you then type a "b", its finds a line holding "ab", and so on. If you type h (or backspace), it returns to the previous line found. To cancel the search, type g. To find another line before holding the same string, type r. Normal editing commands, other than h, g, and r stop the search.
Summary of reverse search commands:
^g |
: | abort search |
^r |
: | search previous same pattern |
^h |
: | (or BACKSPACE) search without the last char |
DEL |
: | search without the last char |
| any other command | : | stop search and show the line found |