A functional ASP solver
Project description
Funasp = Clingo + intensional functions
System funasp extends clingo 6 with intensional functions that can be defined by the user. The major new syntax expression of funasp are assignment rules.
The following is an example of an encoding of the graph coloring problem in funasp:
color(X) := #some{r;g;b} :- country(X).
:- neighbor(C,D), color(C)=color(D).
More examples can be found in the folder examples.
Funasp installation
Funasp requires python 3.13 or later and can be installed using pip.
pip install funasp
funasp examples/family.lp
Language
funasp is a strict superset of the clingo language: every clingo program is a
valid funasp program. On top of it, funasp adds intensional functions —
functions whose values are defined by the rules of the program. Function names
must start with a lowercase letter (as ordinary functions do).
Assignment rules
The headline construct is the assignment rule, which defines the value of a
function. The general form is f(t1,...,tn) := v :- Body., read as "the value of
f(t1,...,tn) is v whenever Body holds".
father(cain) := adam.
x := 2 :- a.
fibo(X) := fibo(X-1) + fibo(X-2) :- number(X), X>1.
The function value is uniques: for each tuple of arguments it takes at most one value. Defining two different values for the same arguments is unsatisfiable.
Choice assignments
#some assignments
Nondeterminitic assignments can be specified by
#some{ ... } choice rules.
color(X) := #some{r;g;b} :- country(X). % each country gets one color
cell(X,Y) := #some{1..9} :- X=0..8, Y=0..8. % each cell gets one digit
next(X) := #some{ Y : edge(X,Y) } :- vertex(X).
A #some{ ... } choice rule state that exactly one value from its set is nondeterministically assigned to the function, if its set is non-empty.
Alternatviely, we can use the usual syntax clingo choice rules by wrapping the head in braces turns the assignment into a choice: the function may take the value or be left undefined.
{ usedcoins(V) := 1..N } :- coins(V)=N. % optionally assign a value in 1..N
Choice assignments combine with cardinality bounds, exactly as clingo choice rules do, to force a function to be defined:
{ king(C) := X : citizen(X,C) } = 1 :- monarchy(C).
1 { move_to(B,T+1) := L : clear(B,T), location(L), L!=B } 1 :- step(T).
Aggregate assignments
The value of a function can be defined by an aggregate (#count, #sum,
#min, #max):
intersection_count := #count{ X : p(X), q(X), r(X) }.
n_orphan := #count{ X : orphan(X) }.
controller(C3) := C1 :- company(C1), company(C3),
#sum{ controlsStk(C1,C2,C3), C2 } > 50.
Functions in rule bodies
Intensional functions can be used as terms anywhere in a body, and may be nested inside other functions or arithmetic:
:- neighbor(C,D), color(C)=color(D). % compare two function values
visited(next(start)). % nested function term
:- on(B,last) != goal(B). % inequality between values
The comparison f(t)=_ tests whether f(t) is defined, and combines with
negation:
block(B) :- on(B,0)=_. % on(B,0) is defined
orphan(X) :- person(X), not father(X)=_, not mother(X)=_.
Showing functions
The #showf directive prints function atoms back in function syntax (f(t)=v)
instead of the internal predicate representation:
#showf color/1.
#showf intersection_count/0.
More examples covering each of these constructs can be found in the examples
folder.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file funasp-0.0.1.post37.tar.gz.
File metadata
- Download URL: funasp-0.0.1.post37.tar.gz
- Upload date:
- Size: 39.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78202e43f93e2a1e3bf5a89e6e333296ed42dee414ebc03ece938825c38d16b9
|
|
| MD5 |
aa375d1530cdfc23ce42a08c8f3e7c8d
|
|
| BLAKE2b-256 |
7bf8c1abcc4497dc83c5d4915305dbf4ba48ce04fd37c12f5bd81e8844b2090f
|
Provenance
The following attestation bundles were made for funasp-0.0.1.post37.tar.gz:
Publisher:
deploy.yml on krr-uno/funasp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
funasp-0.0.1.post37.tar.gz -
Subject digest:
78202e43f93e2a1e3bf5a89e6e333296ed42dee414ebc03ece938825c38d16b9 - Sigstore transparency entry: 1961559369
- Sigstore integration time:
-
Permalink:
krr-uno/funasp@beb834a69f833c9adeca83c26ff690593aac606e -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/krr-uno
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@beb834a69f833c9adeca83c26ff690593aac606e -
Trigger Event:
push
-
Statement type:
File details
Details for the file funasp-0.0.1.post37-py3-none-any.whl.
File metadata
- Download URL: funasp-0.0.1.post37-py3-none-any.whl
- Upload date:
- Size: 40.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09ec732837afc39ebe23e00914374ed124066494ea399797bf9113a618ae6a31
|
|
| MD5 |
bd17016e550077d2ee290b52ff26d510
|
|
| BLAKE2b-256 |
7914d54570f3031b6a4017e59fec2529a22a877f860e9debef2d04c3ca2a5c3a
|
Provenance
The following attestation bundles were made for funasp-0.0.1.post37-py3-none-any.whl:
Publisher:
deploy.yml on krr-uno/funasp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
funasp-0.0.1.post37-py3-none-any.whl -
Subject digest:
09ec732837afc39ebe23e00914374ed124066494ea399797bf9113a618ae6a31 - Sigstore transparency entry: 1961559661
- Sigstore integration time:
-
Permalink:
krr-uno/funasp@beb834a69f833c9adeca83c26ff690593aac606e -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/krr-uno
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@beb834a69f833c9adeca83c26ff690593aac606e -
Trigger Event:
push
-
Statement type: