Expert2 Propositional Logic

Version 2.0 (35.2 KB) by Bill Whiten
A deduction engine useful for small expert systems and complex condition statements.


Updated 10 Oct 2015

View License

Update to expert1, 2015-10-08 BSD license, extra functions to
extend rules and an alternative deduction function.
Rules are written in a structure (one field for each rule) using
a general format easily obtained from "If And Then" rules e.g.
"If bird And ~flies And swims Then penguin" is input as
rules.r1={'~bird' 'flies’ '~swims’ 'penguin’}
(This is the conjunctive normal form where each term (proposition) in
the converted rule is separated by an "or" operator, and each rule by
an "and" operator. Any logical conditions can be converted to this form)
Data is entered as a second struct e.g.
data.penguin=false; data.bird=true; data.swims=true

Deduction is done as: results=deduce(rules,data)

Both data and results can be printed e.g.:
printdata(data); printdata(results)

A meaning struct can be created for propositions names:
info.penguin='The animal is a penguin’; info.bird=’The animal is a bird'
and used with printdata e.g. printdata(data,info)

Rules can be constructed using classical logic, but deduction is done
using a two variable logic that includes unknown, partly true, partly
false, and if you get it wrong inconsistent, as well as the ordinary
true and false. Logic is implemented as "min" for "and" and "max" for
"or", which avoids problems with redundant rules and allows efficient
simple deductions.

The function rulecomplete searches for additional rules that allow
additional deductions to be made by the deduction code.

Results give what is known about a proposition as %true and %false. So
true is 100% true and 0 %false, while false is 0% true and 100% false.
Data can be entered in this format also e.g. data.flies=[50 0].

Deduction is carried out using a more efficient numerical internal
format, that can be used in place of the above structs for repeated
use of large rule sets e.g.


The file demo1 contains a simple example. The matlab command
“doc contents" brings up the contents file and allows access to
the individual help files for each function.

Also “doc filename” % to get more information on individual files

A Simple Algorith for Deduction, Bill Whiten,
The ANZIAM Journal , Volume 51 , Issue 01 , Jul 2009 , pp 102-122
doi: 10.1017/S1446181109000352

Cite As

Bill Whiten (2023). Expert2 Propositional Logic (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: EXPERT1, Optional function arguments

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes