{"id":15451564,"url":"https://github.com/davidar/aspi","last_synced_at":"2025-08-03T12:07:03.106Z","repository":{"id":53598840,"uuid":"203991344","full_name":"davidar/aspi","owner":"davidar","description":"Answer Set Programming, Interactively","archived":false,"fork":false,"pushed_at":"2021-03-22T06:43:04.000Z","size":645,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-28T13:08:56.042Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-23T12:09:05.000Z","updated_at":"2024-05-21T00:42:41.000Z","dependencies_parsed_at":"2022-09-21T21:53:25.950Z","dependency_job_id":null,"html_url":"https://github.com/davidar/aspi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidar%2Faspi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidar%2Faspi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidar%2Faspi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidar%2Faspi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidar","download_url":"https://codeload.github.com/davidar/aspi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251319607,"owners_count":21570427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T21:29:18.487Z","updated_at":"2025-04-28T13:09:01.405Z","avatar_url":"https://github.com/davidar.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aspi\n*[Answer Set Programming](https://en.wikipedia.org/wiki/Answer_set_programming), Interactively*\n[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/davidar/aspi)\n\nThis project started as an interactive shell for [clingo](https://github.com/potassco/clingo), and is gradually morphing into an experimental programming language based on [Lambda Dependency-Based Compositional Semantics](https://arxiv.org/abs/1309.4408) (λdcs). It supports a variety of declarative programming paradigms in a cohesive manner:\n\n- [Functional programming](https://en.wikipedia.org/wiki/Functional_programming)\n  ```\n  fib[0]: 0.\n  fib[1]: 1.\n  fib[N 2..45]: fib[N-1] + fib[N-2].\n  ```\n- [Relational programming](http://matt.might.net/articles/microkanren/)\n  ```\n  pythag(A n2, B n2, C n2): (A**2) = ((B**2) + (C**2)).\n  ```\n- [Constraint programming](https://en.wikipedia.org/wiki/Constraint_programming)\n  ```\n  triple(A,B,C): pythag(A,B,C), ((A+B)+C) = 96?\n  ```\n  - [Zebra puzzle solver](test/zebra.log)\n- [Logic programming](https://en.wikipedia.org/wiki/Logic_programming)\n  ```\n  mine: block ~red ~supports.pyramid.\n  in.box mine?\n  ```\n- [Definite clause grammars](https://en.wikipedia.org/wiki/Definite_clause_grammar)\n  ```\n  #macro words[A,B]: concatenate[A, \" \", B].\n  sentence[s(N,V)]: words[noun_phrase.N, verb_phrase.V].\n  noun_phrase[np(D,N)]: words[det D, noun N].\n  verb_phrase[vp(V,N)]: words[verb V, noun_phrase.N].\n  det: \"a\" | \"the\".\n  noun: \"bat\" | \"cat\".\n  verb: \"eats\".\n  parse.S: sentence'.S.\n  ```\n  ```\n  \u003e\u003e\u003e parse.\"the bat eats a cat\"?\n  that: s(np(\"the\",\"bat\"),vp(\"eats\",np(\"a\",\"cat\"))).\n  ```\n- [Predicating type specifiers](https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node47.html)\n  ```\n  collatz[N even n3]: N / 2.\n  collatz[N odd n3]: (3*N) + 1.\n  say[N multiple.100 100..900]: concatenate[say[N/100], \" hundred\"].\n  ```\n- [Automated planning](https://en.wikipedia.org/wiki/Automated_planning_and_scheduling)\n  - [Tower of Hanoi solver](test/hanoi.log)\n  - [SHRDLU-inspired dialogue](test/shrdlu.log)\n\nThe language is still unstable and lacking much documentation yet, but there are several example programs in this repo, e.g. [solutions to Project Euler-like problems](test/euler/).\n\n## Syntax\n\nλdcs can be used to write logic programs in a concise, [pointfree](https://wiki.haskell.org/Pointfree) manner. Below are a number of examples comparing how λdcs expressions translate to standard logic programs, as well as monadic functional programs.\n\n\u003ctable\u003e\n\u003cthead\u003e\u003ctr\u003e\u003cth scope=\"col\"\u003e\u003c/th\u003e\u003cth scope=\"col\"\u003eλdcs\u003c/th\u003e\u003cth scope=\"col\"\u003eASP logic program\u003c/th\u003e\u003cth scope=\"col\"\u003eHaskell\u003c/th\u003e\u003c/tr\u003e\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eUnary predicate\u003c/th\u003e\n\u003ctd\u003e\n\n```\nseattle?\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nwhat(A) :- seattle(A).\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\n[Seattle]\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eJoin binary to unary predicate\u003c/th\u003e\n\u003ctd\u003e\n\n```\nplace_of_birth.seattle?\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nwhat(B) :- place_of_birth(B,A), seattle(A).\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\nplaceOfBirth =\u003c\u003c [Seattle]\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eReverse operator\u003c/th\u003e\n\u003ctd\u003e\n\n```\nplace_of_birth'.john?\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nwhat(B) :- place_of_birth(A,B), john(A).\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\ninv placeOfBirth =\u003c\u003c [John]\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eJoin chain\u003c/th\u003e\n\u003ctd\u003e\n\n```\nchildren.place_of_birth.seattle?\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nwhat(C) :- children(C,B),\n           place_of_birth(B,A),\n           seattle(A).\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\nchildren =\u003c\u003c placeOfBirth =\u003c\u003c [Seattle]\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eIntersection\u003c/th\u003e\n\u003ctd\u003e\n\n```\nprofession.scientist place_of_birth.seattle?\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nwhat(C) :- profession(C,A), scientist(A),\n           place_of_birth(C,B), seattle(B).\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\n[ x | x \u003c- profession =\u003c\u003c [Scientist]\n    , x' \u003c- placeOfBirth =\u003c\u003c [Seattle]\n    , x == x' ]\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eUnion\u003c/th\u003e\n\u003ctd\u003e\n\n```\noregon | washington | type.canadian_province?\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nwhat(C) :- disjunction(C).\ndisjunction(B) :- oregon(B).\ndisjunction(B) :- washington(B).\ndisjunction(B) :- type(B,A),\n                  canadian_province(A).\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\n[Oregon] \u003c|\u003e [Washington]\n         \u003c|\u003e (type' =\u003c\u003c [CanadianProvince])\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eNegation\u003c/th\u003e\n\u003ctd\u003e\n\n```\ntype.us_state ~border.california?\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nwhat(D) :- type(D,A), us_state(A),\n           not negation(D).\nnegation(C) :- border(C,B), california(B).\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\n(type' =\u003c\u003c [USState]) \\\\ (border =\u003c\u003c [California])\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eAggregation\u003c/th\u003e\n\u003ctd\u003e\n\n```\ncount{type.us_state}?\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nwhat(C) :- C = #count { B : type(B,A),\n                            us_state(A) }.\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\n[length . nub $ type' =\u003c\u003c [USState]]\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eμ abstraction\u003c/th\u003e\n\u003ctd\u003e\n\n```\nX children.influenced.X?\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nwhat(B) :- B = MuX, children(B,A),\n           influenced(A,MuX).\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\n[ x | x \u003c- universe\n    , x' \u003c- children =\u003c\u003c influenced =\u003c\u003c [x]\n    , x == x' ]\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003cth scope=\"row\"\u003eλ abstraction\u003c/th\u003e\n\u003ctd\u003e\n\n```\nnumber_of_children.X: count{children'.X}.\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```prolog\nnumber_of_children(B,MuX) :-\n  B = #count { A : children(MuX,A) }.\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```haskell\nnumberOfChildren x =\n  [length . nub $ inv children =\u003c\u003c [x]]\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\nThe Haskell code above uses the following definitions:\n\n```haskell\nuniverse :: (Bounded a, Enum a) =\u003e [a]\nuniverse = [minBound .. maxBound]\n\ninv :: (Bounded a, Enum a, Eq b) =\u003e (a -\u003e [b]) -\u003e b -\u003e [a]\ninv f y = [ x | x \u003c- universe, y' \u003c- f x, y == y' ]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidar%2Faspi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidar%2Faspi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidar%2Faspi/lists"}