17. In this question, you will write a meta-interpreter for parametrized logic programs. These are logic programs

Question:

17. In this question, you will write a meta-interpreter for parametrized logic programs. These are logic programs that can use constants in arithmetic expressions. The values for the constants are given as part of the input to the meta-interpreter.

Assume that an environment is a list of terms of the form val(Parm, Val), where Val is the value associated with parameter Parm. Assume that each parameter only appears once in an environment. An example environment is [val

(a, 7), val

(b, 5)].

In AILog, you can use <= as the base-level implication and & as the base-level conjunction.

AILog has <= defined as an infix operator and number is a built-in predicate.

(a) Write a predicate lookup(Parm, Val, Env) that is true if parameter Parm has value Val in environment Env.

(b) Write a predicate eval(Exp, Val, Env) that is true if parametrized arithmetic expression Exp evaluates to number Val in environment Env. An expression is either

• of the form (E1 + E2), (E1 * E2), (E1/E2), (E1 − E2), where E1 and E2 are parameterized arithmetic expressions;

• a number; or

• a parameter.

Assume that the operators have their usual meaning, that numbers evaluate to themselves, and that parameters evaluate to their value in the environment. You can use the AILog predicates is, use infix as N is E, which is true if (unparametrized)

expression E evaluates to number N, and number(E), which is true if E is a number.

(c) Write a predicate pprove(G, Env) that is true if goal G is a logical consequence of the base-level KB, where parameters are interpreted in environment Env. An example interaction with AILog is ailog: tell f(X,Y) <= Y is 2*a+b*X.

ailog: ask pprove(f(3,Z),[val(a,7),val(b,5)]).

Answer: pprove(f(3,29),[val(a,7),val(b,5)]).

[ok,more,how,help]: ok.

ailog: ask pprove(f(3,Z),[val(a,5),val(b,7)]).

Answer: pprove(f(3,31),[val(a,5),val(b,7)]).

[ok,more,how,help]: ok.

ailog: tell dsp(X,Y) <= Z is X*X*a & Y is Z*Z*b.

ailog: ask pprove(dsp(3,Z),[val(a,7),val(b,5)]).

Answer: pprove(dsp(3,19845),[val(a,7),val(b,5)]).

[ok,more,how,help]: ok.

ailog: ask pprove(dsp(3,Z),[val(a,5),val(b,7)]).

Answer: pprove(dsp(3,14175),[val(a,5),val(b,7)]).

[ok,more,how,help]: ok.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: