45
15
Task
Your task is to write a function or a program in a language of your choice that analyzes a couple of statements and determines whether it can be concluded from those statements that pigs are able to fly.
Input
The input is a String that can be read from STDIN, taken as a function argument or even be stored in a file. The input can be described using the following EBNF:
input = statement , {statement};
statement = (("Pigs are ", attribute) | ("Everything that is ", attribute, "is also ", attribute)), ". ";
attribute = [not], ("able to fly" | singleAttribute);
singleAttribute = letter, {letter};
letter = "a" | "b" | "c" | "d" | "e" | "f" | "g"
| "h" | "i" | "j" | "k" | "l" | "m" | "n"
| "o" | "p" | "q" | "r" | "s" | "t" | "u"
| "v" | "w" | "x" | "y" | "z" ;
Example input (see more examples below):
Pigs are green. Everything that is green is also intelligent. Everything that is able to fly is also not intelligent. Pigs are sweet.
Output
The output can be returned by your function, be written to a file or print to STDOUT. There are 5 different cases to be handled:
- The given statements are valid, consistent and have as a logical consequence that pigs can fly. In that case, you must output
Yes
. - The given statements are valid, consistent and have as a logical consequence that pigs can not fly. In that case, you must output
No
. - It can not be concluded from the given, valid and consistent statements whether pigs can fly or not. In that case, you must output
Maybe
. - The given statements are valid, but not consistent (i.e. there's a contradiction in the given statements). Since ex falso quodlibet, we decide to output
Yes
in that case. - The given statements are not valid, i.e. they are not formatted according to the given EBNF. In that case, you may do whatever you want.
Details
- You may assume that the given attributes are independent from each other. So, for example, a pig may be young and old, green, red and blue at the same time without causing any inconsistency. However, a pig may not be 'green' and 'not green' at the same time, that's a contradiction and should be handled as described in (4).
- For every attribute, assume that there is at least one object (not necessarily a pig) in the universe that has the given attribute, and one object that doesn't have it.
Example Inputs & Outputs
Input:
Pigs are green. Everything that is green is also intelligent. Everything that is able to fly is also not intelligent.
Output: Since Pigs are green and therefore intelligent, and everything that is able to fly is not intelligent, pigs cannot fly. Output is No
.
Input:
Pigs are old. Everything that is not able to fly is also not old.
Output: If pigs were not able to fly, they were also not old. But as they are old, you must output Yes
.
Input:
Everything that is sweet is also not old. Everything that is intelligent is also blue.
Output: Maybe
.
Input:
Pigs are not able to fly. Everything that is red is also sweet. Everything that is sweet is also not red.
Output: Although the first statement implies that pigs can not fly, the following statements contradict each other and therefore the output must be Yes
.
Input:
Pigs are very smart. Pigs are able to fly.
Output: Whatever you want, as the String doesn't match the criteria mentioned above.
Winner
This is code-golf, so the shortest correct answer (in bytes) wins. The winner will be chosen one week after the first correct answer is posted.
why does the third example return yes? – xem – 2014-08-02T19:27:01.087
10I'm considering writing an answer that translates the input into Prolog code. – Tal – 2014-08-02T20:36:30.037
The third example is not a contradiction: it can be true if nothing exists that is sweet or red. So you can't use that to conclude anything you want, only that nothing sweet or red exists. – amalloy – 2014-08-02T23:14:39.963
1You can only conclude that nothing red exists. Sweet, non-red things are fine. – user2357112 supports Monica – 2014-08-02T23:59:43.273
@amalloy sorry, I meant the fourth example. the one that says yes despite beginning by "pigs are not able to fly". why? – xem – 2014-08-03T05:52:51.123
@ammoly: Oups, I totally forgot that. I've added a new paragraph to the details section to clarify. – vauge – 2014-08-03T06:53:22.710
@xem: I hope the new paragraph added to the details section helps you understand the output? As there is a contradiction in the fourth example, case (4) applies and you therefore have to output 'Yes'. – vauge – 2014-08-03T06:54:21.413
1I was hoping for more examples, just so I can do them myself. – cjfaure – 2014-08-03T16:37:11.937
1@xem: ex falso quodlibet, look it up on wikipedia as the principle of explosion. If a contradiction exists, then anything can be proven. So if 'god exists' is true and 'god does not exist' is true, anything can be shown to be true, therefore pigs can fly can be proven true. – fightermagethief – 2014-09-19T05:30:39.003