Dr Charles Forgy (http://en.wikipedia.org/wiki/Charles_Forgy) delivered a presentation at Decision Camp 2013 (http://www.decision-camp.com) today on how to write simpler rules.
This is a new type of presentation from Charles – a presentation from the perspective of the user of rules rather than the implementer of a rules engine. This switch in perspective from the father of Rete (http://en.wikipedia.org/wiki/Rete_algorithm) is interesting.
Charles sees a fundamental shift taking place in the expression of rules. We are switching from instance-oriented rules to set-oriented rules – rules that express conditions based on set conditions, and that fire on the conditions met at the set level rather than the object level. Charles makes the distinction between:
- conditions that returns a collection of objects
- conditions that select one object from a set of objects
- conditions that compute a value out of a collection of objects
Of course, these conditions may perfectly well be combined.
Set-oriented rules are:
- are more concise
- are easier to understand and manage
- remove the need to implement “tricks” in rules of object model
They also may have a significant impact on performance. Charles took a look at WaltzDB – 4 of the rules in this venerable benchmark are clearly set-oriented rules. In any run of the program, two of the rules fire (one time each) – which on the hardware he uses results in a 4.3 sec run time.
Now, when rewriting these rules into smarter set-oriented rules, the performance on the same hardware for these rules is orders of magnitude better – 0.1 secs.
After applying set-oriented rules to WaltzDB, the overall execution time on his hardware went from 109 sec to 63 secs, with a significant gain in understandability and manageability.
Different engines support set-oriented rules in different ways – with more or less syntax artifacts. Charles presented examples in OPS/J, Jess, Drools and SMARTS.
Charles provides the following recommendations:
- Set oriented rules are more concise and easier to understand
- Set oriented rules may yield significant performance enhancements
- Adding the ability to add user-defined aggregates significantly enhances the expressive power of the rules
Disclaimer: the next paragraphs are related to the product we, at Sparkling Logic have brought to market: SMARTS(tm)
We strongly believe that set-oriented rules are a significant tool in the hands of business users. Very frequently, the business problem to solve is naturally expressed in terms of set operations:
if the shopping basket contains at least 2 food items of different categories and a magazine and if the customer has made purchases of at least $50 in the last 3 weeks, then offer promotion X
A business rules such as this one is not simple to express without powerful set-oriented capabilities – without them, the business rule will be implemented in complex set of iterating rules, or mostly in the object model, making its management a technical ordeal, and not something a business user can tackle.
SMARTS provides high level constructs to handle set-oriented rules that have the expressive power of SQL but are nicely integrated in the business rules management system.
Learn more about Decision Management and Sparkling Logic’s SMARTS™ Data-Powered Decision Manager