Coder Social home page Coder Social logo

propaganda's Introduction

propaganda

Punching values through the system

The propaganda library is a Clojure implementation of the propagator computational model described in The Art of the Propagator. The aim of the library is to be easy to use and reason about, yet extensible.

Two different strategies have been implemented: one using the Clojure STM for handling the propagation of values in the system; and one representing the system as an immutable value, without the aid of any underlying transactional model. The latter approach makes it possible to use propagators from javascript, and is the biggest contribution from this project.

There is a Clojars release containing an implementation that works in both Clojure and ClojureScript.

The leiningen dependency is

[propaganda "0.2.0"]

Tutorial

Here follows a short tutorial. For more in depth information, please consult the following sources:

To use the propaganda library, you need to define a merge, function, create cells and set up propagators. The merge function is invoked when a propagator attempts to store a new value in a cell. The merge function is invoked with the current value and the new value, and must return either a new value which will be stored in the cell, or a Conflict object.

In this short example we just use the default merger function, we define the square and square-root propagator and set up relations beween simple cells.

(use 'propaganda.stm)
(use 'propaganda.values)

default-merge will give us a merger that will merge nothing with anything, but will enforce that anything else that is attempted to be merged will return a contradiction

(def my-merge
  (default-merge))

nothing can be merged with nothing and will return nothing

(my-merge nothing nothing)
;; => :propaganda.values/nothing

Anything else will be the result of the merge

(my-merge nothing 1)
;; => 1
(my-merge 2 nothing)
;; => 2
(my-merge 1 1)
;; => 1

... unless it gives rise to a contradiction

(my-merge 1 2)
;; => #propaganda.core.Contradiction{:reason "1 != 2"}

The function->propagator-constructor can be used for setting up simple one way relations

(def squarer
  (function->propagator-constructor
   (fn [val] (* val val))))

(def sqrter
  (function->propagator-constructor
   (fn [val] (Math/sqrt val))))

... which can be extended to go both ways

(defn quadratic
  [x x-squared]
  (squarer x x-squared)
  (sqrter  x-squared x))

We can now construct cells and set up the quadratic relations to read the squared of a number in our system:

(let [x (make-cell)
      x-squared (make-cell)]
  (binding [*merge* my-merge]
    (quadratic x x-squared)
    (add-content x 10.0)
    (get-content x-squared)))
;; => 100.0

Or the square-root, depending on the input from the user

(let [y (make-cell)
      y-squared (make-cell)]
  (binding [*merge* my-merge]
    (quadratic y y-squared)
    (add-content y-squared 1764.0)
    (get-content y)))
;; => 42.0

We will be warned of any inconsistencies in our system when adding content

(let [z (make-cell)
      z-squared (make-cell)]
  (binding [*merge* my-merge]
    (quadratic z z-squared)
    (add-content z 10.0)
    (add-content z-squared 123.0)))
;; Exception: Inconsistency: 100.0 != 123.0

Motivation

The objective of this project is to create an extinsible propagator library for Clojure. Propagators define a declarative computational model. They are described in the article The Art of the Propagator.

Along with the library itself, the project should supply documentation of the API, good examples and tutorials.

I have not previously worked with propagtors, so this will also be an exploration for me.

Thanks to

Ragnar Dahlén and Kasper Langer for feedback on the library.

propaganda's People

Contributors

tgk avatar yuanmai avatar

Stargazers

PRim avatar Dimitris Mostrous avatar Dennis Hansen avatar Tobias Paulus avatar Christian Weilbach avatar  avatar Jake avatar Harry avatar Felippe Alves avatar  avatar Edward Hughes avatar Curtis Bowman avatar  avatar V avatar 胡雨軒 Петр avatar Ben Sless avatar Joshua Suskalo avatar Daniel avatar Benton Edmondson avatar Cristian Filipov avatar Josh Mize avatar  avatar Jeremy Taylor avatar Hoàng Minh Thắng avatar Pedro Henrique da Silva Sampaio avatar Andrew Foltz-Morrison avatar Tom H. avatar Mikkel Gravgaard avatar Adam Lancaster avatar  avatar Denis Yermakov avatar Kollan House avatar STYLIANOS IORDANIS avatar Daniel A. Matysiak avatar Ahmed Hassan avatar breandan avatar  avatar Imre Kószó avatar Alex avatar Krisztián Szabó  avatar Matt Chowning avatar Martin Clausen avatar M Suleman Khalid avatar Bo Jeanes avatar Andy Nicholson avatar Martin Jung avatar Carlos Fontes avatar Kirill Chernyshov avatar Abdulaziz Alkhoraidly avatar A ghost. avatar Michel A. avatar Erik Kaplun avatar Philippe Voyer avatar syzer avatar Mariano Montone avatar  avatar Vic avatar  avatar Burin Choomnuan avatar Justin Spedding avatar Veha Suwatphisankij avatar Brian Marco avatar Andrew Taber avatar Mike Fletcher avatar yāλu avatar Jim Oly avatar Goutham Bhat avatar Brent avatar Harrison Klaperman avatar Yuri Govorushchenko avatar Kenneth Bruskiewicz avatar ND avatar  avatar Kevin Archer avatar Göran Kirchner avatar Jose Luis Prado avatar Harry Moreno avatar Javier Fernandez-Ivern avatar Harold Ancell avatar Xiyang Chen avatar  avatar David G. Durand avatar Pierre-Yves Baccou avatar clojj avatar Victor Roemer avatar Justin avatar Michael O'Keefe avatar Roland Kaercher avatar Andy Kirkpatrick avatar  avatar Satoru Mikami avatar Frank Shearar avatar Robert Medeiros avatar Ripley Flammer avatar Vic Goldfeld avatar  avatar Adam Howard avatar Dmitri Sotnikov avatar Jay Kominek avatar Syed Khurram avatar

Watchers

h h avatar Martin Clausen avatar  avatar Sunil S Nandihalli avatar Phat Loc avatar  avatar Harry Moreno avatar Eugene Apollonsky avatar James Cloos avatar Jim White avatar Hannah avatar Nilton Lessa avatar Marshall Abrams avatar  avatar Göran Kirchner avatar Diego Casás Rodríguez avatar  avatar

propaganda's Issues

Purpose of merge function

I think the readme would benefit a lot from a few sentences on the purpose of the merge function.

Dependencies for Alternate Worldviews

Subsection 6.2 of The Art of the Propagator describes how alternate worldviews can be implemented in a propagator systems such as propaganda. Due to the immutable implementation of systems in propaganda, different worldviews can be held by adding two different sets of restrictions to a base system. However, this does not allow for some of the interesting interaction that can be achieved through using the approach described in the original paper.

This issue proposes implementing alternate worldviews as described in the original article, and to use this for the basis of implementing implicit search, as described in Subsection 6.3.

Is it possible to define predicate type propagators?

For instance, is it possible to model the relationships between the edge lengths of a triangle? As in:

| b - c | <= a <= b + c
| a - c | <= b <= a + c
| a - b | <= c <= a + b

I know I can create an intermediary (two in the <= case) cell, but I couldn't find a way to have a propagator result in an interval.

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.