-
Notifications
You must be signed in to change notification settings - Fork 0
Input file
The input file consists of three parts:
- Rules
- Initial facts
- Queries
Example of the input file:
# Rules
B + C => A
D | E => B
B => C
# Initial facts
=D
# Queries
?A
Also, a file can contain comments — a part of the line which starts with #.
Rules are equations that combine facts with operators.
Facts represented by uppercase letters.
Operators can be one of:
-
(and)— Parenthesis -
!— NOT (Negation) -
+— AND -
^— XOR -
|— OR -
=>— Implication
Note: The support of the equivalence operator (
<=>) can be implemented as a bonus.
Let's take a look at the truth table of each operator:
A |
!A |
|---|---|
false |
true |
true |
false |
A |
B |
A + B |
|---|---|---|
false |
false |
false |
false |
true |
false |
true |
false |
false |
true |
true |
true |
A |
B |
A ^ B |
|---|---|---|
false |
false |
false |
false |
true |
true |
true |
false |
true |
true |
true |
false |
A |
B |
A | B |
|---|---|---|
false |
false |
false |
false |
true |
true |
true |
false |
true |
true |
true |
true |
A |
B |
A => B |
|---|---|---|
false |
false |
true |
false |
true |
true |
true |
false |
false |
true |
true |
true |
Each rule should have exactly one implication operator.
An implication operator divides each rule into two parts: a condition (left part) and a conclusion (right part).
The result of implication must be equal to true because the rule must be truthy.
Each input file must have a line that starts with = — initial facts.
After = must be listed facts which will receive the initial value true.
The list of initial facts also can be empty:
=
Also, the file must contain the “Queries” part — a line that starts with ?.
After ? must be listed facts whose value must be returned (displayed) as a result of expert system calculations.