Giter VIP home page Giter VIP logo

mu-kanren's Introduction

mu-kanren

Overview

This application is a step-by-step evaluator for a dialect of microKanren.

Programs define goals, and execution finds solutions to those goals if solutions exist. Run the program by clicking the Run button at the top of the page.

The execution path is chosen by clicking on subgoals of the current goal. Possible paths are highlighted, and can be clicked to continue execution.

Terms

The language consists of two types of terms:

  • Symbols, such as a, b, c, and nil.
  • Pairs, such as (a b).

Pairs can be nested to generate more interesting terms, such as (a (b (c nil))).

During evaluation, terms may also contain unknowns, indicated by a hash symbol: #1, #2, etc.

Goals

There are three basic types of goals - equality, conjunctions and disjunctions:

Equality

An equality goal asserts that two terms should be equal. Here is an example:

(= x (y z))

This goal asserts that the term x is equal to the pair (y z).

If the current goal is an equality, then it can be clicked, and this will expand the current substitution.

Conjunctions

A conjunction asserts that two or more goals are satisfied simultaneously. A conjunction is introduced using the conj keyword. Here is an example:

(conj (= x a)
      (= y b)
)

This goal asserts that x equals a, and also that y equals b.

If the current goal is a conjunction, any of the subgoals can be clicked. Execution will proceed for the selected subgoal and the remaining subgoals will be added to the list of remaining goals. When execution of the current goal completes, the first remaining goal will be executed.

Disjunctions

A disjunction asserts that at least one of a set of goals is satisfied. A disjunction is introduced using the disj keyword. Here is an example:

(disj (= x a)
      (= x b)
      (= x c)
)

This goal asserts that x is either equals to a, b or c.

If the current goal is a disjunction, any of the subgoals can be clicked. Execution will proceed only for the selected subgoal.

Fresh Names

To generate fresh names, use the fresh keyword with one or more names, and a goal as the last argument:

(fresh x y z (= x (y z)))

This goal generates three fresh names, and asserts that x is equal to the pair (y z). Execution will try to find terms x, y and z such that this relation holds.

Defining Functions

The defines pane can be used to define functions which can be used in the goal. A function is defined using the define keyword, which takes a list of arguments and the defined goal. For example, to define the addo relation on natural numbers:

(define addo x y z
  (disj (conj (= x zero)
              (= y z)
        )
        (fresh p r
          (conj (= x (succ p))
                (addo p y r)
                (= z (succ r))
          )
        )
  )
)

This function can then be used in the goal, to search for numbers which sum to (succ (succ zero)) (2):

(fresh x y
  (addo x y (succ (succ zero)))
)

Note that functions can be defined recursively.

mu-kanren's People

Contributors

paf31 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

Forkers

avh4

mu-kanren's Issues

Live demo fails on Chromium 49 and Firefox 45

Open http://functorial.com/mu-kanren
When pressing Run, nothing changes in UI.
console show the following exception, from just loading the page

22:23:40.361 TypeError: n is undefined
this.$onChangeMode() ace.js:2446
this.setMode/<() ace.js:2439
t.loadModule/a/</<() ace.js:2018
forEach() self-hosted:208
t.loadModule/a/<() ace.js:2017
r() ace.js:32
s/a() ace.js:62
t.loadModule/a() ace.js:2014
t.loadScript/i.onreadystatechange() ace.js:2097
1 ace.js:2446:1

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.