Examples (represented in MAUDE notation):
sorts elem list.
ops a b c d: -> elem list [ctor].
op nil: -> list [ctor].
op _,_ : elem list -> list [ctor].
eq swap(nil) = nil.
eq swap((a,nil)) = (a,nil).
eq swap((a, b, nil)) = (b, a, nil).
swap((a, b, c, nil)) = (c, b, a, nil).
swap((a, b, c, d, nil)) = (d, b, c, a, nil).
Program induced by IGOR2:
1. swap( nil ) = nil.
2. swap( (X, XS) ) = (last((X,XS)), sub((X,XS))).
3. last( (X, nil) ) = X.
4. last( (X, XS) ) = last(XS).
5. sub ( (X, nil) ) = nil.
6. sub ( (X,Y,XS) ) = swap((X , sub((Y,XS)))).
Best program induced by ADATE with empty seed:
fun f Xs =
case Xs of
nill => Xs
| cons( V144C, V144D) =>
case V144D of
nill => Xs
| cons( V63EC5, V63EC6 ) =>
case f( V63EC6 ) of
nill => cons( V63EC5, cons( V144C, V63EC6 ) )
| cons( V66B8B, V66B8C ) =>
cons( V66B8B, cons( V63EC5, f( cons( V144C, V66B8C ) ) ) )
Figure 1: The Swap Function.
rewriting system MAUDE. Therefore, all constructors
specified for the data types used in the given exam-
ples are available for program construction. IGOR2
specifications consist of: a small set of positive in-
put/output examples, presented as equations, which
have to be the first examples with respect to the un-
derlying data type and a specification of the input data
type. Furthermore, background knowledge for addi-
tional functions can (but must not) be provided.
IGOR2 can induce several dependent target func-
tions (i.e., mutual recursion) in one run. Auxiliary
functions are invented if needed. In general, a set of
rules is constructed by generalization of the input data
by introducing patterns and predicates to partition the
given examples and synthesis of expressions comput-
ing the specified outputs. Partitioning and search-
ing for expressions is done systematically and com-
pletely which is tractable even for relatively complex
examples because construction of hypotheses is data-
driven. An example of a problem specification and a
solution produced by IGOR2 is given in figure 1.
Considering hypotheses as equations and apply-
ing equational logic, the analytical method assures
that only hypotheses entailing the provided example
equations are generated. However, the intermediate
hypotheses may be unfinished in that the rules contain
unbound variables in the right-hand side (rhs), i.e., do
not represent functions. The search stops, if one of the
currently best hypotheses is finished, i.e., all variables
in the rhss are bound.
IGOR2’s built-in inductive bias is to prefer fewer
case distinctions, most specific patterns and fewer re-
cursive calls. Thus, the initial hypothesis is a sin-
gle rule per target function which is the least gen-
eral generalization of the example equations. If a rule
contains unbound variables, successor hypotheses are
computed using the following operations: (i) Parti-
tioning of the inputs by replacing one pattern by a
set of disjoint more specific patterns or by introduc-
ing a predicate to the righthand side of the rule; (ii)
replacing the righthand side of a rule by a (recursive)
call to a defined function (including the target func-
tion) where finding the argument of the function call
is treated as a new induction problem, that is, an aux-
iliary function is invented; (iii) replacing subterms in
the righthand side of a rule which contain unbound
variables by a call to new subprograms.
Refining a Pattern. Computing a set of more spe-
cific patterns, case (i), in order to introduce a case
distinction, is done as follows: A position in the pat-
tern p with a variable resulting from generalising the
corresponding subterms in the subsumed example in-
puts is identified. This implies that at least two of the
subsumed inputs have different constructor symbols
at this position. Now all subsumed inputs are parti-
tioned such that all of them with the same constructor
at this position belong to the same subset. Together
with the corresponding example outputs this yields a
partition of the example equations whose inputs are
subsumed by p. Now for each subset a new initial hy-
pothesis is computed, leading to one set of successor
rules. Since more than one position may be selected,
different partitions may be induced, leading to a set of
successor rule-sets.
For example, let
reverse([]) = []
reverse([X]) = [X]
reverse([X, Y ]) = [Y, X]
be some examples for the reverse-function. The pat-
tern of the initial rule is simply a variable Q, since
the example input terms have no common root sym-
bol. Hence, the unique position at which the pattern
contains a variable and the example inputs different
constructors is the root position. The first example in-
put consists of only the constant [] at the root position.
All remaining example inputs have the list constructor
cons as root. Put differently, two subsets are induced
by the root position, one containing the first example,
the other containing the two remaining examples. The
least general generalizations of the example inputs of
IJCCI 2009 - International Joint Conference on Computational Intelligence
200