Tour of CLIPS (2022)
ryjo.codes
ryjo.codes
I worked with Gary Riley and Joe Giarratano at JSC in the mid 80s when CLIPS was in heavy development. Joe had the unique ability to teach very technical topics with a special brand of humor.
Knowing CLIPs got me my first job in Silicon Valley / Los Altos in '88. Thanks Gary!
and here is also the most recent CLIPS tutorial by Riley available for a good price: https://www.amazon.com/dp/B09ZCL2VMM/
I've got both the 4th edition and Adventures in Rule-Based Programming sitting in front of me now.
https://www.amazon.com/LISP-Lore-Programming-Machine-1987-06...
Unsurprisingly this is an attempt to meld fuzzy logic and KBS together.
Every now and then you hear of these things being deployed and saving someone millions in the process, but it proves remarkably hard to back it up.
or at least attempt to. I'm fairly convinced CLIPS is an unexplored middle-ground answer to conversations around "does our company really need AI/ML? SQL is enough."
I also see CLIPS as a declarative abstraction around our classic imperative CRUD applications. It exposes abstract concepts within the language that we end up implementing ourselves, like application caches (working memory), pattern matchers (LHS of Rules), and permission systems (in CLIPS, the object-oriented concepts known as "COOL" list User as a separate object inheritance chain from the other objects).
Consider PostgreSQL, a popular database that one could consider a Rules Engine: 1. records stored in tables can be implemented with facts in working memory 2. constraints, foreign keys, views, and other abstractions that come with RDBMSs which we slowly replicate within our application layer over time can be implemented with defrules 3. and you can even add "Rules" (https://www.postgresql.org/docs/current/sql-createrule.html) proper in psql
From this, we could conclude PostgreSQL is an example of an application you can build with a rules engine. However, the ambitions of CLIPS is to be a tool used for creating "Expert Systems." Whenever I bring up that term with other people, I'm met with:
1. blank stares 2. scoffs
regardless of their profession.
However, I argue that ChatGPT and other AI/ML chat bots are highly advanced "jack of all trade" Expert Systems. I also argue that some very successful web applications, such as the Pennie Pennsylvania health insurance application and TurboTax are "specific" Expert Systems. In all of these systems, you interact with someone who is the "expert" and can carry a "conversation" on the topic you specify.
We already use imperative programming languages that query remote databases specifically written to store data. I think Rules Engines (CLIPS) is "low hanging fruit" because, at its core, it's "lower level" than an RDBMS in terms of abstractions provided to the developer, but the implementation of the algorithm that interprets CLIPS code is closer inline with AI/ML. ie: neural networks are built based on inferred rules from the data they're trained on. Rete networks are built based on explicitly defined Rules by the developer. Thus, CLIPS is sort-of like having a formal language for interacting with a simplified neural network.
I hope my efforts are reaching developers on teams who have reached the point in their product's life when CLIPS "would have been a good idea to start with."
The difficult part: forgoing the temptation to reason "we don't need to use Foo, our product doesn't need all of that."
If any of the above resonates with you, I encourage you to read the CLIPS documentation and try to build something fun with it. You might be surprised at what you learn.
- A statistical model for probability of default - A rule-based model implementing a policy, taking into account the probability and other signals not captured in the probability
Not everything could be incorporated into the probability, so this was a nice way of having a hand-crafted decision tree. Also, we could tune it eventually, much easier than training and validating a new statistical model.
You bring up something awesome about CLIPS: it's easy to tailor it to your needs. Once you have your CLIPS code, you can trim out the parts you don't need using compiler flags. Once you have a compiled `clips` binary with only the constructs you need (defrules and deffacts, maybe?), you can execute it, load your rules/facts into the engine, and then generate C code for your specific rules engine. This compiles into an even smaller/faster binary. You can do all of this from within CLIPS proper. Check out the Advanced Progamming Guide section 11: Creating a CLIPS Run-time Program https://www.clipsrules.net/documentation/v641/apg641.pdf
Today the open articles about it are much better. But for awhile, it was elusive.
One of the big advantages of Rete is the culling of the rule base that needs to be evaluated based on the working/changed data set. If you have a 1000 rules, and assert “age=35”, Rete will only select those rules that deal with age, for example.
I’ve been on several projects where a rules system was appropriate, but they never really needed more that a few hundred rules. So we just wrote simple engines that would take a soup of expressions, and keep running through them until the working set stopped changing.
There was a lot of expressiveness with the rules, making development much simpler, and it was fast enough to brute force its way through the rule space and get the results.
Larger rulesets or deeper ones (where there are a lot of derivative rules based on previous rule results) can certainly warrant the complexities of a full boat Rete system.
But a simple system can take you quite a long way on modern hardware.
Or tons of web pages and a whole bunch of scholarly articles available from Google Scholar with full text.
Heck, over a decade ago I did an implementation (lost now) in Ruby based on a 1995 paper [0]. It hasn't really been secret sauce for a long time.
[0] https://scholar.google.com/scholar?hl=en&as_sdt=0%2C5&q=prod...
It might work!
I may download everything again and see if I can get the test scenarios running with modern Java. I am so out of date with Java though - what's the accepted best version to run things with now that Oracle has made the license so eyepoppingly evil?
A Simple TCP Server Written in Go and CLIPS - https://news.ycombinator.com/item?id=34187247 - Dec 2022 (1 comment)
Show HN: Tour of CLIPS - https://news.ycombinator.com/item?id=33083169 - Oct 2022 (4 comments)
CLIPS: A Tool for Building Expert Systems - https://news.ycombinator.com/item?id=19835214 - May 2019 (62 comments)
Symbolic Integration Using CLIPS (1997) - https://news.ycombinator.com/item?id=15399391 - Oct 2017 (0 comments, but interesting)
Build Node-JS expert systems with node-CLIPS - https://news.ycombinator.com/item?id=5424493 - March 2013 (1 comment)
Edit: since there has been so little discussion over the years, I've changed the top URL from https://ryjo.codes/articles/forgoing-implicity-using-the-alg... to an article (suggested by ryjo) that gives more of an intro and overview.
* Stop Writing In-app Caches and Start Writing Inherently Cached Apps with CLIPS - https://news.ycombinator.com/item?id=33342959
* Conway's Game of Life Written in CLIPS - https://news.ycombinator.com/item?id=34428083
* A* Algorithm Written in CLIPS - https://news.ycombinator.com/item?id=34340212
* Run CLIPS in a C++ AWS Lambda - https://news.ycombinator.com/item?id=37322937
* Write a Ruby C Extension to Use CLIPS from Ruby: Part 1 - https://news.ycombinator.com/item?id=35708717
* Write a Ruby C Extension to Use CLIPS from Ruby: Part 2 - https://news.ycombinator.com/item?id=36461022
Can you write your own home-grown rules engine in Ruby: yes.
Can you use off-the-shelf gems: yes. Here's a few I poked around in my previous explorations into Ruby Rules Engines:
* durable rules - https://github.com/jruizgit/rules?tab=readme-ov-file#ruby
* wongi - https://github.com/ulfurinn/wongi-engine
* rules - https://github.com/azach/rules
* ruleby - https://github.com/Ruleby/ruleby
- bonus: video of original ruleby author explaining rules engines: https://www.youtube.com/watch?v=qMh2RDL6aBM
edit: It's also possible to write your own Ruby gem in C so that you can pass the handling of the RHS of your rules to a Ruby script.Other than that there are a bunch of rule-based systems in Common Lisp.
For example LispWorks Enterprise includes "KnowledgeWorks", which features a forward chainer based on the RETE algorithm.
Close on how Maclisp/Macsyma or CL/Maxima did integration/differentiation. Also, a chapter of Paradigms of Artificial Intelligence. OFC, writting a CLIPS parser under CL would be trivial.
CLIPSockets: Clips low-level socket implementation - https://news.ycombinator.com/item?id=40300303
It also leads to some really funny bugs that arise from grammar ambiguities - things like a card that says "[...] then put them into your hand" and the game losing track of what "them" refers to and putting _all_ the cards into your hand.
The source for the bug is a video WotC did that I can't find right now that featured the Arena team talking about developing Kaldheim - the bug came from the card Alrund, God of the Cosmos.
> So first, a quick summary of how the rules engine works. When a game of Magic is in progress on MTG Arena, the program that is tracking the state of the game and enforcing all the rules-correct card interactions is called the Game Rules Engine (GRE). It's one of the two main programs that we work on. It's written in a combination of C++ and a language called CLIPS, which is a variant of LISP.
https://lab.abilian.com/Tech/Programming%20Techniques/Rule-b...
Also for your consideration, clipspy, which exposes CLIPS in Python: https://github.com/noxdafox/clipspy
FLOSS interpreter and four books.