Coder Social home page Coder Social logo

catseye / samovar Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 1.0 172 KB

MIRROR of https://codeberg.org/catseye/Samovar : Model worlds using propositions and run simulations in them

Home Page: https://catseye.tc/node/Samovar

License: The Unlicense

Python 97.20% Shell 2.80%
experimental-language dsl story-generation simulation-engine proposition hoare-logic production-system production-systems

samovar's Introduction

Samovar

Version 0.6 | Entry @ catseye.tc | See also: The League of Extraordinarily Dull GentlemenThe Swallows


Samovar is a domain-specific language (DSL) for modelling a world using propositions (facts), and possible events that can occur based on those facts, changing them.

Here is a short example of a Samovar description:

scenario IgnatzWithBrick {
  
    [actor(?A),item(?I),~holding(?A,?I)]  ?A picks up the ?I.   [holding(?A,?I)]
    [actor(?A),item(?I),holding(?A,?I)]   ?A puts down the ?I.  [~holding(?A,?I)]

    actor(Ignatz).
    item(brick).

    goal [].
}

And an implementation of Samovar could take this scenario and use it to, among other things, generate textual descriptions of chains of events like

Ignatz picks up the brick. Ignatz puts down the brick.

Of course, this is a very simple example. (It doesn't even prevent two actors from picking up the same item at the same time!) For more complex examples, and a fuller description of the language, see doc/Samovar.md, which also serves as a test suite.

Implementation

The reference implementation of Samovar, samovar, is written in Python. It can run under either Python 2.7 or Python 3.x (tested with 3.5 or higher.)

Discussion

This looks like logic programming but the internals are actually much simpler, and what it's doing is not logical inference.

The internals are far simpler than an inference engine or a theorem prover: there are no logical rules in the database, only propositions, so they can be selected by simple pattern-matching rather than full unification.

I originally described it as an "assertion-retraction engine", which could be thought of as a highly stylized form of Prolog programming. Alternately, it could be thought of as assigning preconditions and postconditions, like in Hoare logic, to actions in a world-model. Instead of constructing a proof, though, we simply chain actions together, by selecting any next one whose preconditions hold, and altering the world so that its postconditions hold.

In (I think) autumn 2019, I came across the concept of a production system, and I realized that is basically what Samovar implements. Researching it further, I discovered CLIPS, a production system built in 1985, and I realized that Samovar is not essentially different from an inefficiently-implemented, stripped-down version of CLIPS.

The main innovation in Samovar is the ability to "narrate" the choices the production system makes, with human-readable text.

This isn't too surprising, since my goal with Samovar was to make an expressive language, a syntax in which the author could write a story generator without the undue effort of switching context between prose and code. Picking logical propositions for the "code" and placing them before and after each fragment of prose was a reasonably "ergonomic" choice, and happens to coincide with the structure of a production system.

TODO

  • Maybe allow variables to be notated so that they can bind reflexively, e.g. ?*A looks at ?*B can bind both variables to Alice.
  • Make ?_ work such that you can say ¬holding(?_, club) to mean "if no one is holding the club".

samovar's People

Contributors

cpressey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

zeeneddie

samovar's Issues

A macro processor

If you'd like a macro processor for Samovar, you might have a look at ML/1, one of the more long-lived programs around. I first used it in 1968, and still like its elegant design. See http://www.ml1.org.uk/ for details. There's a lot more sophistication in that package than appears at first glance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.