Skip to content

Input file

VBrazhnik edited this page Jun 21, 2020 · 2 revisions

The input file consists of three parts:

  1. Rules
  2. Initial facts
  3. 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

Rules are equations that combine facts with operators.

Facts

Facts represented by uppercase letters.

Operators

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:

! (NOT)

A !A
false true
true false

+ (AND)

A B A + B
false false false
false true false
true false false
true true true

^ (XOR)

A B A ^ B
false false false
false true true
true false true
true true false

| (OR)

A B A | B
false false false
false true true
true false true
true true true

=> (Implication)

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.

Initial facts

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:

=

Queries

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.