[2/24] rule based inference engine (engine itself)
Here I introduce new inference engine which I'm going to use for assumptions.
When I started to play with assumptions ~ half a year ago, the firsts thing
I've noted was that:
- inference itself was intermixed with object creation etc (it was not possible
to use logic stuff as separate subsystem)
- the rules put into assumptions.py and the code was just wrong -- in the end
of this patch series you'll see how much tests I have to change.
So I've started to work on my own inference engine first.
Initially I prototyped a system where one could define rules of form
a -> b (where a & b are atoms -- e.g. integer=T -> rational=T )
and tried to hook this engine into assumptions.py, but I failed because as it
turned out, inference engine that could satisfy all our tests have to be
capable to process joined rules:
a & b -> c (e.g. real & positive -> !negative)
Here I give up the first time:
http://groups.google.com/group/sympy/browse_thread/thread/
c436fd9cfc701138
Recently I refreshed my work and put some time into studying the topic -- its a
whole new world -- good inference engine is an art, and there are even family
of software programs which heart is inference engine (I'm talking about expert systems) ...
In short, there is a classic algorithm called RETE for this stuff
http://en.wikipedia.org/wiki/Rete_algorithm
And what is done here is a very simplistic apprach with some ideas borrowed
from there -- I could not find ready stuff for this task :(
The main design goals were:
1. to be correct, and
2. to be fast at runtime
I think 1 is acheived, and 2 is so-so (but much better than we had before), and
there is a room for improvements.
Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Ondrej Certik <ondrej@certik.cz>
Signed-off-by: Mateusz Paprocki <mattpap@gmail.com>