Learning Prolog (cuts, lists, negation) push me in the right direction -


i have following base knowledge: “nba players on 30 years old have won @ least 3 nba championships superstars. nba players below 30 superstars if appear on front cover of videogame or if have @ least 5 million followers in twitter.

define unary predicate superstar gives 1 answer (true/false) each query, when applied concrete person, e.g. superstar(paugasol). rules should check fact once (for instance, should not check age of queried person twice). can’t use “;” operator.

you can use these data in tests (4 of these 8 players superstars, according previous definition):

age(kobebryant,37). championships(kobebryant,5). millionsfollowers(kobebryant,9). age(paugasol,35). championships(paugasol,2). videogamecover(paugasol). millionsfollowers(paugasol,3). age(marcgasol,31). videogamecover(marcgasol). millionsfollowers(marcgasol,1). age(stephencurry,28). championships(stephencurry,1). videogamecover(stephencurry). millionsfollowers(stephencurry,5). age(klaythompson,26). championships(klaythompson,1). age(kevindurant,27). millionsfollowers(kevindurant,13). age(russellwestbrook,27). videogamecover(russellwestbrook). millionsfollowers(russellwestbrook,3). age(dwaynewade,29). championships(dwaynewade,3). millionsfollowers(dwaynewade,4). 

so did this:

superstar(x):- age(x,y), y>=30, championships(x,z), z>=3,!. superstar(x):- age(x,y), y=<30, videogamecover(x),!. superstar(x):- millionsfollowers(x,z), z>=5. 

we learned lists, cuts , negation last lesson. push me in right direction should use, age checked once, , if it's greater 30 goes 1 way less 30 goes other way, im new prolog , programming in general. not asking solution, asking push, hint.

when figure out, post solution self hopefully.

the request access once db table normalizes and/or search tree. introduce service predicate discriminate pre-condition.

superstar(x) :- age(x,y), age_check(x,y). 

now, using cut, can commit branch

age_check(x,y) :- y>=30, !, championships(x,z), z>=3. % other 2 rules age_check, not using y 

or, avoid cut, use correct domain disjunction:

age_check(x,y) :- y>=30, championships(x,z), z>=3. age_check(x,y) :- y<30, etc etc ... 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -