Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to create a predicate in prolog called sq explained in the first picture below. I have added a picture of my code

I am trying to create a predicate in prolog called sq explained in the first picture below. I have added a picture of my code so far. What I am trying to do for it is use the member function to see if the strings "u","d","r",and "l" are a member of the input list. I already have predicates that check a list to see if they consist of just "u" or "d",r","l" so I am trying to call member to get the first item and then call my other predicates to see if it is either of the strings I am looking for. But this is not working, how can I get my predicate to check the list to make sure it has at least one "u","l","d","r". It does not matter how many of each are in the list as long as one of each is in the list. What I have now fails.

image text in transcribedimage text in transcribed

3.3 sq/2 (+) This predicate is included just to point out that without contextual con- straints (e.g., all sides of the same length), the desired class is different. See the examples Prototype: sq(+In, +Leftover) Succeeds if In is a string list representing u"n r"m d'l l'p with string Leftover left over. In our use, Leftover is bound to ], i.e. , parse must 'consume' all of the string Remark: Not really a square, just u'n r'm d'l 1'p. Sample Use. 2- sqCE"u","r", "d","1"],[]) true . false. 11, f acts* / 2 str u("u" 3 str_r("r. 4 str_d("d S str l(" 7 /function that checks to make sure a list only includes "u" and returns the number of "u" n the list*/ 8 uA(1,["u"1,11) :-1 9 UA(L,[HIT],[]): 1 str_u(H), L is L1 L2 13 14 15 /*function that checks to nake sure a list only includes "r" and returns the number of "r" in the list*/ 16 rA(1,0".]) :-1. 17 rA(L,[HIT],[]): 18 str_r(H), 19 A(L1, [H],]) 20 A(L2,T,[), 21 L is L1L2 23 /*function that checks to make sure a list only includes "d and returns the number of "d" in the list* 24 dA(1, ["d"],[1) 25 dA(L, [HIT],[]): 2 str_d(H), 27 dA(L1,[H],) 28 dA(L2,T,[] 29 L is L1 L2 31 /*function that checks to make sure a list only includes "L" and returns the number of "l" in the list*/ 32 LA(1,[) 33 LA(L, [HIT],[) str_l(H), 5 LA(L1, [H],u) L is L1 L2 37 38 39/*this function should check the list and make sure it includes "u","r"u","d 40 if it does not include all of them it should return false, if it has all of them no matterlthe number of each it should return true*/ 41 sq([S],)- menber (x,[S, 42 43 uA(L,X,L) rA(L,x,[), 45 3.3 sq/2 (+) This predicate is included just to point out that without contextual con- straints (e.g., all sides of the same length), the desired class is different. See the examples Prototype: sq(+In, +Leftover) Succeeds if In is a string list representing u"n r"m d'l l'p with string Leftover left over. In our use, Leftover is bound to ], i.e. , parse must 'consume' all of the string Remark: Not really a square, just u'n r'm d'l 1'p. Sample Use. 2- sqCE"u","r", "d","1"],[]) true . false. 11, f acts* / 2 str u("u" 3 str_r("r. 4 str_d("d S str l(" 7 /function that checks to make sure a list only includes "u" and returns the number of "u" n the list*/ 8 uA(1,["u"1,11) :-1 9 UA(L,[HIT],[]): 1 str_u(H), L is L1 L2 13 14 15 /*function that checks to nake sure a list only includes "r" and returns the number of "r" in the list*/ 16 rA(1,0".]) :-1. 17 rA(L,[HIT],[]): 18 str_r(H), 19 A(L1, [H],]) 20 A(L2,T,[), 21 L is L1L2 23 /*function that checks to make sure a list only includes "d and returns the number of "d" in the list* 24 dA(1, ["d"],[1) 25 dA(L, [HIT],[]): 2 str_d(H), 27 dA(L1,[H],) 28 dA(L2,T,[] 29 L is L1 L2 31 /*function that checks to make sure a list only includes "L" and returns the number of "l" in the list*/ 32 LA(1,[) 33 LA(L, [HIT],[) str_l(H), 5 LA(L1, [H],u) L is L1 L2 37 38 39/*this function should check the list and make sure it includes "u","r"u","d 40 if it does not include all of them it should return false, if it has all of them no matterlthe number of each it should return true*/ 41 sq([S],)- menber (x,[S, 42 43 uA(L,X,L) rA(L,x,[), 45

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Identify three ways to manage an intergenerational workforce.

Answered: 1 week ago

Question

Prepare a Porters Five Forces analysis.

Answered: 1 week ago

Question

Analyze the impact of mergers and acquisitions on employees.

Answered: 1 week ago