Question

Define a predicate unifiable(List1,Term,List2) where List2 is the list of all members of List1 that unify...

Define a predicate unifiable(List1,Term,List2) where List2 is the list of all members of List1 that unify with Term. The elements of List2 should not be instantiated by the unification. For example,


unifiable([X,b,t(Y)],t(a),List).
List= [X,t(Y)].

Note that X and Y are still not instantiated. So the tricky part is: how do we check that they unify with t(a) without instantiating them? Write the predicate so that it terminates immediately after finding the correct answer. (That is, after prolog produces its first solution, it terminates executing the query immediately.)


Hint: consider using possibilities associated with using tests of the form: \+ term1 = term2.

Homework Answers

Answer #1

Solution

 if \+ H = Term succeeds we know that the H and Term cannot be unified so we fail and go to the default to second myUnifiable and add H to List2.
 if it fails we use a cut (i.e. it can be unified) we make a cut so that we don't end up trying the second myUnifiable which would add it regardless to  List2 even though it can't be unified Alternative we could've used a double \+ \+ so we add H in the case where the check succeeds to avoid confusion about the default case being the one that adds H to List2.

myUnifiable([H | List1],Term,List2) :-
  \+ H = Term, !,
  myUnifiable(List1, Term, List2).

myUnifiable([H | List1], Term, [H | List2]) :-
  myUnifiable(List1, Term, List2).

myUnifiable([],Term,[]).
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a prolog program that defines the predicate groundTerm(Term) which tests whether or not Term is...
Write a prolog program that defines the predicate groundTerm(Term) which tests whether or not Term is a ground term. Ground terms are those taht don't contain variables. Here are examples of how the predicate should behave. groundTerm(X). false. groundTerm(french(bic_mac,le_bic_mac)). true. groundTerm(french(whopper,X)). false. Also, the predicate should terminate execution immediately after producing its first (and only) solution.
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT