Expert system that solves logical expressions (finds the values of all facts depending on the given true facts) using backward-chaining inference engine.
There are logical expressions, for example:
A => B (A implies B)
C | D => A (C or D implies A)
All facts (fact is uppercase letter) are false by default, you can set true facts.
This program calculates, depending on the entered true facts - all facts values.
A=>B
# A - false, B - false
# A=>B - false=>false
# B - false
A=>B
=A
# A - true, B - false
# A=>B - true=>true (if implying fact is true, then fact which it implies must become true)
# B - true
()
which means high priority. Example:A + (B | C) => D
!
which means NOT. Example:!B
+
which means AND. Example:A + B
|
which means OR. Example:A | B
ˆ
which means XOR. Example:A ˆ B
=>
which means "implies". Example:A + B => C
(expression always true)<=>
which means "if and only if". Example:A + B <=> C
(expression always true)
# this is a comment
C => E # C implies E
A + B + C => D # A and B and C implies D
A | B => C # A or B implies C
A + !B => F # A and not B implies F
C | !G => H # C or not G implies H
V ^ W => X # V xor W implies X
A + B => Y + Z # A and B implies Y and Z
C | D => X | V # C or D implies X or V
E + F => !V # E and F implies not V
A + B <=> C # A and B if and only if C
A + B <=> !C # A and B if and only if not C
=ABG # Initial facts : A, B and G are true. All others are false.
?GVX # Queries : What are G, V and X ? (it doesn't matter in visual mode)
git submodule update --init --recursive
cmake -S . -B build -DINSTALL_DEPS=true
make -C build
./expert_system -v example.txt (visual mode with the ability to change expressions in real time)
or
./expert_system example.txt (console answer)
or
./expert_system_tests