项目作者: dolovnyak

项目描述 :
Expert system for logical expressions on backward-chaining inference engine.
高级语言: C++
项目地址: git://github.com/dolovnyak/Expert-System.git
创建时间: 2020-05-24T06:26:33Z
项目社区:https://github.com/dolovnyak/Expert-System

开源协议:The Unlicense

下载


Expert-System

" class="reference-link">MacOS - Build

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:

  1. A => B (A implies B)
  2. 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.

  1. A=>B
  2. # A - false, B - false
  3. # A=>B - false=>false
  4. # B - false
  1. A=>B
  2. =A
  3. # A - true, B - false
  4. # A=>B - true=>true (if implying fact is true, then fact which it implies must become true)
  5. # B - true

Available logical operations:

  • () 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)

Input file example:

  1. # this is a comment
  2. C => E # C implies E
  3. A + B + C => D # A and B and C implies D
  4. A | B => C # A or B implies C
  5. A + !B => F # A and not B implies F
  6. C | !G => H # C or not G implies H
  7. V ^ W => X # V xor W implies X
  8. A + B => Y + Z # A and B implies Y and Z
  9. C | D => X | V # C or D implies X or V
  10. E + F => !V # E and F implies not V
  11. A + B <=> C # A and B if and only if C
  12. A + B <=> !C # A and B if and only if not C
  13. =ABG # Initial facts : A, B and G are true. All others are false.
  14. ?GVX # Queries : What are G, V and X ? (it doesn't matter in visual mode)

Build and run on MacOS:

  1. git submodule update --init --recursive
  2. cmake -S . -B build -DINSTALL_DEPS=true
  3. make -C build
  4. ./expert_system -v example.txt (visual mode with the ability to change expressions in real time)
  5. or
  6. ./expert_system example.txt (console answer)
  7. or
  8. ./expert_system_tests

Graphical examples:

Simple logic example:

K=true, C=false -> K|C=true -> A=true -> B=true

K=false, C=false -> K|C=false -> A=false -> B=false

K=false, C=false -> K|C=false -> !(K|C)=true -> A=true -> B=true

K=true, C=false -> K|C=true -> !(K|C)=false -> A=false -> B=false