Knowledge Inversion

advertisement
From: AAAI-84 Proceedings. Copyright ©1984, AAAI (www.aaai.org). All rights reserved.
Knowledge
Yoav
Inversion
Shoham
Drew V. McDermott
Department
of Computer
Science
Yale University
Box 2158 Yale Station,
Abstract
We define
extend
we
the direction
that
direction.
three
give
case
performance on non-trivial
are demonstrated.
and what
is function
for
algorithms
function
problems
All algorithms
it means
inversion,
and
inversion.
and
their
to
Their
shortcomings
are implemented
can
given
while
it is trivial
arrange
syntax
of
Quicksort,
defined
by, say:
:-
split(H,T,A,B),!,
to disarrange
Rubik’s
have
the same
On
Cube
discovered
we
machine;
functions,
the
other
frustration.
[I, El>.
split(H.[A~X],[AIY],Z)
order(A,H),
hand
it is less trivial
to their
append(Al,[HlBll,S).
qsort(
to
We
:-
split(H,X,Y,Z).
split(H,[AIXl,Y,[AIZI)
order(H,A),
sp 1 itL,
:-
split(H,X,Y,Z).
[I, [I
, 111).
two questions:
automate
in those
In this
paper
partial
positive
answer
three
different
the
instances
ignore
to
the
the
of
first
order(A,B)
“easily
procedural
question,
second
algorithms
power
of
:- AcEI.
One would
the inversion
easy cases?
we mainly
their
a machine,
of algebraic
of functions.
characterize
knowledge?
Can
we
knowledge
demonstrate
to disassemble
of differentiation
ask ourselves
essentially
of the
relations.
the familiar
qsort([HITl.S)
in Prolog-
to assemble
a variety
it, as many
0 Can
we
invertible”
l
how
manual
knowledge
integrate
can then
821) and
qsort(B,Bl),
describing
use that
our
we can
( [M c D ermott
qsort(A,Al),
a manual
usually
or DUCK
Prolog.
2 Directed
Consider
1 Introduction.
Given
CT. 00520
like Prolog
of knowledge,
A special
New Haven,
but
We
one.
for function
give
a
present
inversion
and
invocation
bind
X successively
fact
will happen
and
Quicksort
by Insertionsort
infinite
qsort(X, [1,2,31>
of the goal
to all six permutations
is that
messages
an
and weaknesses.
expect
fail.
recursion,
the
Other
and
of [1,2,3].
interpreter
cases
are
will cause
similar
will return
still
worse
will
What
two
in
error
- replacing
the interpreter
disasters
to
to go into
happen
with
Bubblesort.
Our
algorithms
hlellish
Sl]),
popular
are
which
view
of
implemented
may
seem
Prolog
is as
in Prolog
at first
a
( [Clocksin
a bit strange
“declarative’
since
&
the
language.
The
“wrong”
In
that
section
2 we dispel
sometimes
itself.
encouraged
Our
language
that
by the
- the
could
employs
convenient
the
output
rationalization
variables
by the
reader
rely on the formalism
expected
optical
algorithms
particularly
language
this
to have
illusion
logic
be
oddly
enough
programming
written
backtracking;
because
which
in
Prolog
of the explicit
be the judge
of logic
a basic
programming,
understanding
is obviously
arguments
sortname(X,Y)
that
instantiated.
goals
In this
is a function2
from
are
invoked
case
we
with
the
might
say
X to Y rather
than
applicative
happens
to
be
representation
of that).
but
of
post-hoc
for
the
We do not
the reader
of deductive
a
is
relation
on
X
and
following
definitions:
Y. More
generally
one
can
make
community
any
this
is
a
(or
perhaps
first author
of his enthusiasm
may
problem
is
systems
‘This work was supported
in part by the Advanced Research Projects
Agency of the Department
of Defense and monitored under the Office of
Naval Research under contract N00014-83-K-0281
Definition:
A Prolog
predicate R with a given intended
extension is said to be a function from Sl to S2 if <Sl,S2>
is a partition of the set of all variables appearing in R, and
for all invocations
of R with all the variables
in Sl
instantiated,
all the tuples in the intended extension of R
matching the instantiation
of variables in Sl will be fairly
generated.
For our purposes a partition of a set S is a tuple <Sl,S2>
of disjoint sets whose union is S. A fair generation
of a
sequence is one in which any given element is generated
after a finite amount of time.
Deffnition:
A Prolog predicate R with a given intended
extension is said to be D-directed relation if D is a set of
the
tuples {<Sli,SL?i>}
such that R is a function from Sli to
S2i for all i. Note that a function from Sl to S2 is a special
case of a directed relation, one that is {<Sl,S2>}-directed.
Definition: A Prolog predicate R is called complete
D-directed
for D the set of all partitions
of the
variables in R.
It
is not
predicate
immediately
in
a
clear
given
what
program
-
the
;
;
;
X =
[3,1,2]
;
X =
[3,2,1]
;
no
I ?-
direction
the
is
if it is
set of
X = [1,3,2]
X = [2,1,3]
X = [2,3,11
a given
traditional
which
view
is indeed
procedure
encourages
regarding
it
as
complete,
while
typically
it
as a function.
a function
However
a question
that
once
a predicate
arises
naturally
is identified
as
is whether
its
of
directionality
can
be extended,
(in the latter
been completed).
is a function
A special
from
Sl
a general
given
discussion
paper
in
so as to make
that
Here
which
we
is the
Armed
some
it to be
original
the
and
of a
subject
The
the
problem
immediate
of the
we
the
general
statement
we
problem
would
on Fermat’s
are
not
trying
investigating
we
inversion.
In this
description
of the
to more
global
inversion
For
yield
invert
ones
present
section
we
algorithms
easily
considerations
are
algorithm
functions,
really
hard
invertible.
heuristics
are
Thus
the
with
function
in section
4.
first
present
roughly
says
reverse
order.
otherwise
given
from
inversion
algorithm
which
solve
the conjuncts
it”.
a single
The
goal
goal
precise
Prolog
it
if
stated
in
An example
both
is
N candidates
first
above
2 we observe
algorithm
the following
to the sorting
program
qsortK[1,2,31)
used
FAME
you
[1,2,31 ;
to provide
intuition
for the
*Since our formalization
ser ves mainly
remainder
of the paper, we allow ourselves some freedom in using the
terminology.
As we will define the term /unction
it will always denote a
nondeterminstic
function.
write
choose
into
a set set2
a set set3
now
ask
the
rest
In that
problem
is the
expression
inverting
count.
The result
and
the
(FAME
the
that
the
was no
to handle
way
program
other
to go about
II)
it,
solved
that
could
be written
II to synthesize
a program
of counting.
the knowledge
it reads
of size r from
problem
solved
“In how many
by
ways
a set set1
of size n,
-
“What
counting
a solution
to”
set2?“).
question
c(n,r)*c(r,l)
is shown
first
we pointed
namely
the program
of size 1 from
among
of
in it and there
“correct”
is
of R
choosing
paper
program,
English
team,
of first
of a counting
converse
process
of the
process
of FAME
example
II (translated
the
another
I, by inverting
3 is an
equality
from
a program
Then
the knowledge
3All the examples
version 3.47.
296
to
to FAME
and choose
We
X =
was
of this
the
is
“X choose
a captain
our
The
for
appoint
was only implicit
extend
same
a team
captain.
to gracefully
problems.
proof
the
equality
to choose
the
of
to
of ways
then
the
structure
argument
an
stands
describes
in combinatorics.
said,
can
1.
then
of counting
Figure
invgoal(
and
shortcomings
that
1:
Quickeort
and
describes
the
similar
behavior:3
captain
expression
way
of
841
combinatorial
general
solution
c(X,Y)
and
expression
knowledge
we
correct
in
In [Shoham
proving
example
number
from
problems
a
trivial,
will be a bit
example
The
of a combinatorial
the
is not
of problems
by a combinatorial
where
The
team
this
do
to our
of counting
example
I) for
equal
An
players
the
the
arguments.
are
them.
counting
the
a
we can
us back
is requested.
(FAME
both
describe
brings
the solution
in itself,
expressions
that
Y”.
obvious
possible,
implementation
two
that
whole
reduce
account
present
but pays more
the solution
indulgence
problem.
second
we return
1.
we apply
section
a conjunctive
Given
in Figure
Example
inverting
I ?-
“Given
execute
When
a simple
Since
a program
showing
out
We
2 we
algorithm
meaty
automating
by combinatorial
choosing
a detailed
performance;
inversion
into
algorithm,
of inverting
N*c(N-l,R-l)=R*c(N,R),
that
and their
basic
more
that
and the reader’s
counting
a
rather
for
Figure
The next example
we think
describe
is
to
and
however
but
concerned
and
a solution
Remember
all
are
are
is
example
a factoring
last theorem.
to
which
algorithms
function
caveats.
slightly
is of interest
of proving
of
this
take
features.
in combinatorics.
because
long
inversion
some
this
motivation,
equalities
general
suggests
not
In
the same
Prolog
inversions.
combinatorics
next section.
3 Function
adopts
with
more
problems
841) we
restrict
idiosyncracies.
to special
relation
a directionality
However
as it does
it
had
to invert
& McDermott
program.
inversion,
to extend
is we want
for exploring
a given
to function
that
the predicate
the directed
we want
( [Shoham
procedure
predicate
even
is where
irected,
In another
describe
case
to S2, and
{ <Sl,S2>,62,Sl>}-d
function.
perhaps
case we will say that
Prolog’s
procedure
respect
complete
required.
is
simplistic
is
some
written
what
is too
in figure
in this paper were done on a
by
4.
running
Prolog- 10
invgoal((A,B))
:- !,invgoal(B),invgoal(A).
The
next
algorithm,
invgoal(A)
:- !,clause(A,B),invgoal(B).
like an elaborate
invgoal(A)
:- call(A).
the first
their
Figure
1:
Algorithm
1: A simple inversion
interactive
inverse
according
to
invgoal(assert(X))
presented
:- call(X).
:- retract(X).
algorithm
goal
is unifiable
invgoal(asserta(X))
:- retract(X).
given
invgoal(retract(X))
:- assert(X).
quitting
is B+C)
:- var(B),B is A-C.
invgoal(A
is B+C) :- var(C),C
invgoal(A
is B-C) :- var(B),B
invgoal(A
is B-C) :- var(C),C
invgoal(A
is -B) :- B is -A.
invgoal((A,B))
is A-B.
is A+C.
is B-A.
previous
% and any other
% mathematical
inversions
% needed; see below.
%
clause
:- !,invgoal(B),invgoal(A).
The
detect
infinite
it from
when
tree
he may
:- !,clause(A,B),invgoal(B).
inversion
:- call(A).
is defined
the
2:
Algorithm
where
along
A
the
occurring
during
inv (F) .
with
inv(A)
to the
a head
on the body
3 is that
the
inversion
runtime.
The
a
of the tree or
clause
is in contrast
recurse
the
second
As it is
B, the user is
:-
branch
This
- in
and whenever
if a goal is unifiable
during
the
F is called
tree
that
on B.4
recursion
sight
asserts
run.
asserting
of Algorithm
user
In
of a clause
will definitely
first
to a file - all
is simply
computation
means
recursing
of a
of that
user
phase,
can
and
disadvatage
is
decides
to quit
pursuing
a branch
of the
lose information.
The
example
we choose
is the
of a function
with
in [Clocksin
definition
code
of continuing
advantage
that
invgoal(A)
.
a head
at
functions,
them
of a function
with
the algorithm
clause.
invgoal(A)
Figure
inverse
Continuing
inverts
writes
specification.
inverted
the
algorithm
prevent
%
the
the choice
it.
user’s
the
traverses
inv (B) , and
:invgoal(A
here,
The
and
seem
2. It has two phases
the system
database
the
phase
3, may
of Algorithm
phase
to the
independent
invgoal(invgoal(X))
Algorithm
version
is very similar
side effects.
& Mellish
gensym
The predicate
811 (p.
we will not repeat
150)
and
since
our
it here.
2: A less simple inversion,
I ?- findinv(gensym(X,Y)).
1 ?- count([(setl,n),(set2,r),(set3,1)],
Do you want the resulting
[subset(set3,set2),subset(set2,setl)],
in the database?
code asserted
(y/n)
I: Y.
Solution).
(Where) do you want to save the resulting
code? (filename/no)
I: no.
Solution
= c(r,l)*c(n,r)
Do you want to invert the goal gensym(-31,-52)?
(y/n)
I: Y.
Figure
3:
Solving a counting
problem
1 ?- inv(gensgm(X,input7)).
X = input
1 ?- invgoal(count(X,Y,c(n,r)*c(r,l))).
** Error: evaluate( -246)
yes
1?-
X = ((_241,r),(_368,1),(_242,n)l_832],
Y = jsubset(-241,-
242),subset(-368,-241)]
Figure
;
Finally,
X = 1(_369,r),(_368,1),(_242,n),(_241,1)1_948],
Y = (subset(-241,-
suffice
5:
Example
we demonstrate
to invert
all functions.
that
5: inverting
the
Consider
above
the
gensym
algorithms
will not
following program:
242),subset(-368,-369))
f([alXl>
:-
f([blXI)
:- g(X).
gUc,-I)
g(X)
Figure
4:
Example
2: inverting
Count
g(X).
*
:- f(X).
‘The limitations
imposed on the length of this presentation
prohibit
TTWP detailed descriotion of the alnorithm or a comtAete I/O 10~.
a
Considered
as
recognizer
would
for
a
function
the
cause
it
from
regular
to
act
as
(in the sense
defined
convince
himself
none
fl, f(X)
(a+b)*.c.C.
“fair”
a
language
that
[X] to
language
generator
in section
acts
as
Inverting
f
of
the
2). The reader
of the above
algorithms
same
that
inversion
deterministic
inversion
and
all
inversion
- conduct
problems
aspects
of
an obvious
predicate
search
and
We have
transforming
the
the language
“the
is lost”,
while
such
another
a
from
case
While
general
80)) suggests
a way
subsect ion).
computations
behind
that
references
are two
not
basic
function
the redundant
information
work
ideas
may
731, [Burks
for
is different
carry
to theoretical
are [Bennett
the
does
insure
by making
essential
the two basic
Other
paper
to
be
equivalent
cost of doubling
there
motivation
an
of this
information
entropy
but we feel that
to
of his work,
function
The
scope
is
algorithm
the
circuit
additional
the
discussion
one
function.
ours,
reversible
(a+b)*.c.C
a worst
“redundant”
to
( [Toffoli
computational
and try to reduce
information
theorem-
initiate
add
-
(see last
6: Generating
Toffoli
of channels.
inversion,
proof.
Example
paper
any
a detailed
ideas
on the
a breadth-first
bf (G) will
goal
open.
one with
number
permit
Both
theoretical
be demonstrated
implemented
invoking
tree.
its
(namely,
can
to
in general)
of the computation
impracticality)
in Prolog;
non-solution
redirection
%on-solutioness’
its
program.
prover
mention
(and
a breadth-first
completeness
above
we should
information
remains
In an interesting
invertible
point
no
problem
because
should
will invert
of
At this
is straightforward
work
over
on
711, [Toffoli
771.
I ?- bf(f(X)).
X
X
X
X
=
=
=
=
[a,c,-3121
[b.c.-5161
[a,a,c,-13421
[a,b,c,-16181
4.2
;
;
;
;
X =
[b,b,a,a,c,-148651
X =
[b,b,a,b,c,-153981
;
X =
Cb,b.b,a,c,-159411
;
! more
4 Related
aborted
work,.
4.1 Discussion
1950
recursive
of the
the
Summary,
of related
functions
enumeration
see
procedure,
text
speculated
on
what,
procedure,
and
one
is
can
More
inversion
recently
which
of the vector
out
the
difficulty
analog
English
proof
of
be needed
consider
inverting
he discussed
is the
a correct
of
the
to
text
the
explicitely
is
of proving
a
theorem.
He
upon
this
work
described
has
In [Dijkstra
inversion
also
considered
831
he
problem.
the
gives
problem
a
A complete
yet impractical
algorithm
for predicate
redirection
has been presented
(namely
a breadthfirst
search
of the computation
tree)
and
its
performance
has been demonstrated.
of
(manual)
As he himself
of
l
a
here
case
It has been demonstrated
that these algorithms
are
effective
in some non-trivial
cases, and that there
exist functions
not invertible
by either. The exact
characterization
of functions
invertible
by each
algorit,hm
has not been given (see discussion
below).
and testing
improve
special
l
speculations.
Dijkstra
inversion.
problem
the
We have presented
two effective
algorithms
for
inverting
functions
- Algorithm
2 and Algorithm
3.
Both involve
reversing
the bodies of encountered
clauses,
but the latter
is more selective
in which
clauses
are inverted.
Both allow for extra-logical
features
of Prolog,
namely
inverting
assert/retract
and arithmetic
operations.
The treatment
of the
latter is very cursory
and ad-hoc,
and if any nontrivial
inversion
of mathematical
functions
is
desired
the
question
of the
representation
of
mathematical
objects requires closer attention.
Research.
561, pointing
method
generating
would
cant inuat ion of those
program
one
the
with
l
work.
[hlcCarthy
by systematically
if the
Further
addressed
The
problem.’
theorem
to
;
1
hlcCarthy
We suggest
viewing
Prolog
predicates
as denoting
directed
relations.
For a predicate
denoting
a
relation
with a certain direction,
we asked whether
its direction
can be extended.
A major part of the
paper has been concerned
function
inversion.
core needed
[ Execution
In
Summary.
l
says,
5We do not agree with his claim there that solving any “well specified”
problem
amounted
to the inversion
of some Turing Machine.
In our
notation a specification
procedure is a {<S,[]>}-directed
relation R (i.e. a
function)
for some S and R, while the algorithm
solving it is not the
{ <[],S>}-directed
R but rather the {<Sl,S2>}-directed
R for some
partition
<Sl,S2>
of S. This however does not affect the relevance 01 his
subsequent discussion of inverting functions defined by Turing Machines.
4.3 Further
We repeat
research.
the two questions
0 Can
we
invertible”
l
Can
we
knowledge
As we said
question.
posed
characterize
knowledge?
automate
in those
there,
The task
the
in the introduction:
instances
the inversion
easy cases?
we only
remains,
gave
a partial
then,
of
of
procedural
answer
to complete
“easily
to the second
that
answer
and
provide
one for the first
question.
Several
half of the task
suggest
themselves.
the first
explored
the
power
perform
Algorithm
of
2
: - bf (G). A related
ail implicit
definite
as
While
we have
strategy
for
of
on the
ordering
A recent
itself
with
be
paper
current
of a clause
body.
unqualified
inference
Toffoli’s
work
the first
question
one. It implies
of entropy
case
invertible.
Where
information,
start,
so that
later.
programming
we
redundant
base
an
reconstruct
the
excess
just
whereby
an
for
the
the
“right”
of
the
of
at the
subset
the
of it
automatic
process
existing
is
loss
information
the
it.
computation
eliminate
application
to
approach
answering
and try to minimize
cannot
suggests
information
conjuncts
data
look for an appropriate
is zero
try to supply
paradigm,
choice
solving
on the optimal
in the
both
one should
the
also
to
approach
the
those
as well a technique
entropy
we could
This
on
even
is necessary).
the
we should
not
is a
831) has concerned
assertions
in the computation,
where
and
problem
case where
suggests
that
have
Another
of deciding
in the simple
against
we
AI, that
& Genesereth
that
as a sole
candidate
goal,
of mainstream
( [Smith
Finally,
the
if
for
flip a coin to decide
could
of the problem,
is, no further
tree,
One obvious
the
answering
In
that
be crucial
BFS
a knowledge-intensive
of conjuncts
measure
be
ignore
example
may
computation
against
ordering
part
only
second
for
the
f(X,Y,Z)
sometimes
discredited
strategies.
in the spirit
itself
task.
(that
and
the
possible
to resolve
be more
resolve
information,
one - the interpreter
clause
ordering
[Z], we
of information
mentioned
searching
other
probablistic
decide
to
that
of
piece
[Smith
adding
of
code
is
automated.
We have
allowed
subsection,
which
It is not clear
example
Whether
a learning
people,
survey
process
and
free speculation
learning
of knowledge
knowledge
much
in this last
the possibilities.
neglected
as part
is classified
a fundamental
frqm
- for
( [Michalski
inversion
inversion
or not it see&
AI will benefit
with
has been largely
of machine
is no ment)ion
acquisition.
some
our excitement
why the problem
in the
831) there
ourselves
reflects
a better
go to Tom
Dean,
for helpful comments
Stan
Letovsky,
on previous
Dave
drafts.
capability
of
understanding
Miller and
We &o
[Toffoli
771
Toffoli, T.
Computation
and Construction
Universality
of Reversible
Cellular Automata.
J. Comp. Sys. Sci. 15, 1977.
[Toffoli
801
Toffoli, T.
Reversible
Computing,
Technical
Report MIT/LCS/TM-151,
Laboratory
for Computer
Science,
February,
1980.
of
ACKNOWLEDGMENTS
Thanks
submitted
, 1984.
& Genesereth
831
Smith, D.E. and Genesereth,
M.R.
Ordering
Conjuncts
in Problem
Solving.
Computer
Science Department,
Stan ford
Uniuersity
, 1983.
unpublished
at this time.
of skill
of it.
Spohrer
731
et al
as part
work by S. Sickel of which
References
of f.
mentioned
could
[X,Y]
th is sort
Z=[];
the inversion
which
from
intention
out related
Bennett,
C.H.
Logical Reversibility
of Computation.
IBM J. Res. Dev. 6, 1973.
Burks, A.W.
(Burks 711
On Backwards-Deterministic,
Erasable, and
Garden-of-Eden
Automata.
Technical
Report 012520-4-T,
Comp. Comm.
Sci. Dept., University
of Michigan,
1971.
[Clocksin & Mellish 811
Clocksin,
W.F.
and Mellish, C.S.
Programming
in Prolog.
Springer-Verlag,
1981.
Dijkstra,
E.W.
[Dijkstra 83)
,!iJ’WD671: Program Inversion.
Springer-Verlag,
1983, .
[McCarthy
561
McCarthy,
J.
The Inversion of Functions
Defined by Turing
Machines.
In Shannon,
C.E. and McCarthy,
J. (editor),
Automata
Studies,
. Princeton
University,
Press, 1956.
[McDermott
821 McDermott,
D.V.
DUCK: A Lisp-Based
Deductive
System.
Department
of Computer
Yale University,
. Science , 1982.
[Michalski et al 83)
Michalski,
R.S., Carbone!!,
J.G. and Mitchell,
T.M.
Machine Learning: An Artificial
Intelligence
approach.
Tioga, 1983.
[Shoham 841
Shoham,
Y.
FAME: A Prolog Program
That Solves
Problems
in Combinatorics.
In Proc. 2nd Intl. Logic Programming
Conf..
Uppsala,
Sweden, 1984.
to appear.
[Shoham & McDermott
841
Shoham,Y.
and McDermott,
D.V.
Prolog Predicates
as Denoting
Directed
Relations.
[Bennett
is how to make
if we write
pointing
we had not been aware.
not
example
i nvgoa I(bf (G)>
example,
the
we have
- for
exploring
For
f (X, X, Z) with
First,
clause
needs
explicit.
(overdetermining)
then
the
referee for correctly
of approaching
techniques
add
issue that
a function
additional
X=Y
and
knowledge
clause
used
combining
ways
Jim
thank one
299
MIT,
Download