This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
sc330_f2016:prolog1 [2018/10/25 23:47] morse |
sc330_f2016:prolog1 [2021/06/30 23:42] (current) |
||
---|---|---|---|
Line 37: | Line 37: | ||
*Once you have a solution, check it against the solutions we provide for the puzzles. If you're getting something different, you might not have sufficiently constrained the solution by extracting all of the information from the puzzle. (Or you might have just miscoded one of the facts.) | *Once you have a solution, check it against the solutions we provide for the puzzles. If you're getting something different, you might not have sufficiently constrained the solution by extracting all of the information from the puzzle. (Or you might have just miscoded one of the facts.) | ||
*If you don't constrain the solution enough, you can get multiple possible answers. Even if you get lucky and happen to get the right answer as your first answer, especially if you only look at the first one found, that doesn't mean your Prolog code is correct. **There is exactly one solution to each puzzle.** | *If you don't constrain the solution enough, you can get multiple possible answers. Even if you get lucky and happen to get the right answer as your first answer, especially if you only look at the first one found, that doesn't mean your Prolog code is correct. **There is exactly one solution to each puzzle.** | ||
+ | *Logic tips: | ||
+ | *"A implies B" or "if A then B" is equivalent to "(A and B) or (not A)". | ||
+ | *"if A then B; otherwise C" is equivalent to "(A and B) or ((not A) and C)". | ||
*These problems make extensive use of the "not" operator, \+. | *These problems make extensive use of the "not" operator, \+. | ||
* \+ works as you expect when all variables are completely bound. | * \+ works as you expect when all variables are completely bound. | ||
* If E contains unbound variables, \+E will try to find bindings to that will make E true. If Successful \+ will fail. | * If E contains unbound variables, \+E will try to find bindings to that will make E true. If Successful \+ will fail. | ||
* This lab is taken from [[http://www.cis.upenn.edu/~matuszek/cis554-2015/Assignments/prolog-1-logic-puzzles.html|this site]]. There may be additional resources there. | * This lab is taken from [[http://www.cis.upenn.edu/~matuszek/cis554-2015/Assignments/prolog-1-logic-puzzles.html|this site]]. There may be additional resources there. |