Hacker News new | past | comments | ask | show | jobs | submit login
Tour of CLIPS (2022) (ryjo.codes)
75 points by ryjo 20 days ago | hide | past | favorite | 41 comments



Considering the 4th edition of "Expert Systems: Principles and Programming" (The original book on CLIPS) is going for $300 at amazon, you are offering a good alternative.

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!


Here is a cheaper version: https://archive.org/details/expertsystemspri4thegiar

and here is also the most recent CLIPS tutorial by Riley available for a good price: https://www.amazon.com/dp/B09ZCL2VMM/


The same has happened to "LISP Lore: A Guide to Programming the LISP Machine", $668 for the hardcover version!

https://www.amazon.com/LISP-Lore-Programming-Machine-1987-06...


The rest of the books are enough:

https://www.clipsrules.net/


Wow! That must have been an incredible work environment.

I've got both the 4th edition and Adventures in Rule-Based Programming sitting in front of me now.


There is an interesting extension called FuzzyClips https://en.m.wikipedia.org/wiki/FuzzyCLIPS

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.


The only way I've found to back up the claims: try to prove them myself :)

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.


I’ve worked on systems that manage risk, and we had two pieces:

- 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.


That sounds like an excellent use case.

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


Rate has been a secret sauce for a long time. Only described in an out of print magazine or very expensive books.

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.


> Rate has been a secret sauce for a long time. Only described in an out of print magazine or very expensive books.

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...


Big fan of CLIPS! Rule based expert systems are so ubiquitous in business and scientific codes, yet a lot of devs are not even familiar with pattern matching let alone powerful rules engines like CLIPS.


This has been similar to my experience. Rules Engines like CLIPS are just outside of the bounds of "cheap enough to spend time learning on the off-chance it is indeed better than what we've already written."


I'll admit, even as a programmer who's tried a lot of languages, I know a lot more about logic program and unification-based languages – and nothing practical about expert systems and their core algorithms.


Here's a java implementation of rete that I worked on about 20 years ago https://github.com/sgt101/zeus/tree/master/src/zeus/rete

It might work!


Thanks. The links in the readme to the papers don't seem to work anymore; the second is available here: https://web.archive.org/web/20220301000000*/http://citeseerx... but I didn't find a source for the first and third one. Any hints?



That worked, great, thanks!


Thanks for flagging, I updated the readme.

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?


Thanks for sharing! I really enjoy seeing different implementations of the Rete Algorithm.


Related. Others?

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.


Not to self-promote too much, but the main focus of my programming efforts is currently CLIPS. Over the past few years, I've written articles about and even made some fun projects with CLIPS:

* 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


Is it possible to make a reasonable rules engine in Ruby rather than a "bolt-on" (separate rules language files)? I think its interesting that its the LISP languages that spawned rules-engines, and as far as I've seen, the only language that can produce a reasonable rules engine as an API library.


Is it possible: yes.

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.


Do these Ruby libraries actually implement the Rete optimization in control flow though?


Does it exist for Common Lisp/Scheme? I know that could be implemented in a day, but still...

Edit: https://lisa.sourceforge.net/


The precursor to CLIPS was called ART Inference and was a large commercial & very expensive Expert System development tool, written in Common Lisp. Unfortunately it seems to be lost - I haven't seen anything about it for several decades.

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.

https://www.lispworks.com/products/knowledgeworks.html


I just made CLIPSockets public, which is a culmination of learning I've taken from trying to make web applications using primarily CLIPS. Thought I'd bump it here:

CLIPSockets: Clips low-level socket implementation - https://news.ycombinator.com/item?id=40300303


>Symbolic...

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.


MTG Arena, the new digital client for the Magic the Gathering trading-card game, uses CLIPS to implement the actual game-rules based on the English text of the cards. Magic cards are written using a very standardized language (look at custom-card communities and discussions around "templating"), but the fact that they've had such success with this approach is incredibly impressive to me.

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.


Holy moly. I had my suspicions Magic would be a good candidate for something like CLIPS when it comes to software implementation. Do you have a source for that info? What an amazing bug.


The source for them using CLIPS is a conversation I had with Arena team lead Ian Adams in a Magic-community Discord.

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.


Here's an article: https://magic.wizards.com/en/news/mtg-arena/on-whiteboards-n...

> 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.


Thanks for sharing!


There is also Drools, another major Rete based open source rule engine. It is based on Java so its bit easier to work with for non-specialized developers, although it also inherits many downsides from Java too


Did you happen to do performance comparisons with CLIPS?


The predecessor to CLIPS has been apparently kept in a building state[1]; I haven't tried it though.

1: https://github.com/sharplispers/ops5


Now that is cool. Thanks for sharing this.


I have found 6 open source rule engines written in Python, all of them dead (in terms of recent commits), except maybe one:

https://lab.abilian.com/Tech/Programming%20Techniques/Rule-b...


Cool, looks like sauron-engine is indeed actively developed. I've not used it myself.

Also for your consideration, clipspy, which exposes CLIPS in Python: https://github.com/noxdafox/clipspy


https://www.clipsrules.net/

FLOSS interpreter and four books.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: