Deolingo is a tool for reasoning about Deontic Logic based in Answer Set Programming. The tool is implemented in Python and uses Clingo as the ASP solver.
Deolingo implements the theoretical foundation described in the paper "Deontic Equilibrium Logic with eXplicit negation" by Pedro Cabalar, Agata Ciabatonni and Leendert van der Torre.
DELX extends Equilibrium Logic for normative reasoning. In contrast to modal approaches, DELX utilizes a normal form that restricts deontic operators solely to atoms. The cited paper establishes that any theories in DELX can be reduced to ASP.
To install Deolingo, you need to have Python 3.6 or later installed in your system.
You can install Deolingo using pip:
pip install git+https://github.com/ovidiomanteiga/deolingo.git@main
You can use Deolingo as a library in your Python code or as a command line tool.
To use Deolingo as a command line tool, you can use the deolingo
command.
$ deolingo [OPTIONS] FILES...
Where FILES
are paths to the file containing the Deontic Equilibrium Logic programs.
The following options are available:
-h, --help
: Show this message and exit.-v, --version
: Show the version and exit.--translate
: Prints the translated deontic logic program to the standard output.--ungrouped
: Prints the answer sets ungrouped (by default they are grouped by world: facts, obligations, prohibitions).--outf=3
: Remove all Clingo output. Use in conjunction with--translate
to output the translated program only.
The deolingo
command supports most of the options of the Clingo command.
You can use the --help
option to see the available options.
To use Deolingo as a library, you can import the deolingo
module and use the deolingo.solve
function.
import deolingo
program = """
% Your Deontic Equilibrium Logic program here
% Example: It is permitted to park if there is no evidence that it is forbidden to park.
&permitted{park} :- not &forbidden{park}.
"""
solutions = deolingo.solve(program, all_models=True, grouped=True)
print(solutions)
The deolingo.solve
function returns a string with the output of the ASP solver.
You can find examples of Deontic Equilibrium Logic programs in the examples directory. See example from example 2
% I must normally work (it is obligatory that I work if it is not explicitly omissible).
&obligatory{work} :- not &omissible{work}.
% On weekends, I have an explicit permission not to work.
&omissible{work} :- weekend.
% It is not a weekend.
-weekend.
% I decided not to work.
-work.
$ deolingo deolingo/examples/preliminary/example1.lp
Output from deolingo:
Answer: 1
Answer:
FACTS: [-work, -weekend]
OBLIGATIONS: [&obligatory{work}]
PROHIBITIONS: []
SATISFIABLE
The output shows that the program is satisfiable and there is an answer set whose atoms mean:
- FACTS:
-work
: I did not work.-weekend
: It is not a weekend.
- OBLIGATIONS:
&obligatory{work}
: It is obligatory that I work. The obligation to work is violated, although that is not checked in any rule and it is excluded from the answer set.- PROHIBITIONS:
- Nothing remarkable in the world of prohibitions.
The examples are also used as tests for Deolingo. You can run all the tests using the following command in the root directory of the project
$ python -m pytest
// OR SIMPLY
$ pytest
Deolingo uses the following atoms to represent the deontic theory:
&obligatory{p}
: It is obligatory thatp
. Equivalent to forbidden notp
:&forbidden{-p}
. Also known as mandatory, duty and required.&forbidden{p}
: It is forbidden thatp
. Equivalent to obligatory notp
:&obligatory{-p}
. Also known as prohibited and impermissible.&omissible{p}
: It is omissible thatp
. Equivalent to not explicitly obligatory:-&obligatory{p}
(but this syntax is not allowed, see "Syntax limitations" below).&permitted{p}
: It is permitted (or permissible) thatp
. Equivalent to not explicitly forbidden:-&obligatory{p}
(but this syntax is not allowed, see "Syntax limitations" below).&optional{p}
: It is optional thatp
. Equivalent to omissible and permissible. Cannot be neither obligatory nor forbidden.&deontic{p}
:p
is a deontic atom. It can be obligatory, forbidden, omissible, permitted or optional.
Deolingo also reifies the truth of the deontic atoms to allow general rules requiring it.
It is represented by the holds theory atom &holds{p}
, which is true if, and only if, the atom p
is true.
&violated_obligation{p}
: The obligation ofp
is violated.&violated_prohibition{p}
: The obligation ofp
is fulfilled.&non_fulfilled_obligation{p}
: The obligation ofp
is not fulfilled.&non_violated_obligation{p}
: The obligation ofp
is not violated.&undetermined_obligation{p}
: The obligation ofp
is undetermined. It is neither violated nor fulfilled.&violated_prohibition{p}
: The prohibition ofp
is violated.&fulfilled_prohibition{p}
: The prohibition ofp
is fulfilled.&non_fulfilled_prohibition{p}
: The prohibition ofp
is not fulfilled.&non_violated_prohibition{p}
: The prohibition ofp
is not violated.&undetermined_prohibition{p}
: The prohibition ofp
is undetermined. It is neither violated nor fulfilled.
&default_obligation{p}
: It is obligatory by default thatp
. If there is no evidence of notp
being permitted, it is obligatory by default thatp
.&default_prohibition{p}
: It is forbidden by default thatp
. If there is no evidence of notp
being omissible, it is forbidden by default thatp
.&om_d{p}
: It is omissible by default thatp
. If there is no evidence ofp
being obligatory, it is omissible by default thatp
.&permitted_by_default{p}
: It is permitted by default thatp
. If there is no evidence ofp
being forbidden, it is permitted by default thatp
.&omissible_implicitly{p}
: It is omissible implicitly thatp
. Requires default omissibility. Equivalent to not obligatory (default negation): there is no evidence of obligation:not &obligatory{p}.
&permitted_implicitly{p}
: It is permitted implicitly thatp
. Requires default permissibility. Equivalent to not obligatory (default negation): there is no evidence of prohibition:not &forbidden{p}.
.
#theory _deolingo_ {
deontic_term {
- : 1, unary
};
show_term { / : 1, binary, left };
&obligatory/0 : deontic_term, any;
&forbidden/0 : deontic_term, any;
&omissible/0 : deontic_term, any;
&permitted/0 : deontic_term, any;
&optional/0 : deontic_term, any;
&permitted_by_default/0 : deontic_term, any;
&omissible_by_default/0 : deontic_term, any;
&holds/0 : deontic_term, any;
&deontic/0 : deontic_term, any;
&permitted_implicitly/0 : deontic_term, any;
&omissible_implicitly/0 : deontic_term, any;
&violated/0 : deontic_term, any;
&fulfilled/0 : deontic_term, any;
&violated_obligation/0 : deontic_term, any;
&fulfilled_obligation/0 : deontic_term, any;
&non_violated_obligation/0 : deontic_term, any;
&non_fulfilled_obligation/0 : deontic_term, any;
&undetermined_obligation/0 : deontic_term, any;
&default_obligation/0 : deontic_term, any;
&violated_prohibition/0 : deontic_term, any;
&fulfilled_prohibition/0 : deontic_term, any;
&non_violated_prohibition/0 : deontic_term, any;
&non_fulfilled_prohibition/0 : deontic_term, any;
&undetermined_prohibition/0 : deontic_term, any;
&default_prohibition/0 : deontic_term, any;
&show/0 : show_term, directive
}.
-&obligatory{p}
explicit negation of theory atoms is not allowed by Clingo. Use the corresponding negative deontic atom instead, in this case&omissible{p}
.not &obligatory{p} :- conditions...
default negation of theory atoms is not allowed in the head of a rule by Clingo. If default negation of a theory atom is needed in the head, it can be obtained by the following constraint::- not &obligatory{p}, conditions...
Deolingo version 1 only supports simple terms in the deontic theory atoms, like atoms, their explicit negations and variables.
In future versions of Deolingo, the support for complex terms will be added as per the DELX paper;
for example: &obligatory{p & q}.
meaning that it is obligatory that p
and q
.
Deolingo is licensed under the MIT License. See the LICENSE file for more information.