Commit Graph

120 Commits

Author SHA1 Message Date
Patrick Lühne ea885f5fdb
Fix integer detection
Clingo treats operations that were assumed to be “invalid” not as
processing errors but as operations returning an empty set.

This changes how formulas have to be evaluated. This commit implements
an explicit function for retrieving the return type of an expression,
that is, both the domain of the result as well as whether it’s an empty,
unit, or general set with multiple values.
2018-04-22 17:04:15 +02:00
Patrick Lühne 92cd114cf8
Rename “general” domain to “noninteger”
The “general” domain wasn’t really about general variables, but meant as
a distinction from integer variables. For this reason, this commit
renames the “general” domain to “noninteger.”
2018-04-22 14:57:16 +02:00
Patrick Lühne 2b62c6227d
Move Domain class to Utils header 2018-04-22 14:56:58 +02:00
Patrick Lühne d950b8ec1a
Add integer simplification rule
This adds the rule “(F in G) === (F = G) if F and G are integer
variables” to the simplification rule tableau
2018-04-21 18:12:43 +02:00
Patrick Lühne d6a811e363
Move arithmetic check to separate header
Checking whether terms are arithmetic will be used not just in integer
variable detection but also in simplifying formulas with integer
variables. For this purpose, the arithmetic check is moved to a commonly
accessible header file.
2018-04-21 17:59:05 +02:00
Patrick Lühne b1ca027de5
Consolidate commonly used enum classes
This moves the commonly enum classes EvaluationResult, OperationResult,
and Tristate to the Utils header file to avoid code duplication.

Additionally, the SimplificationResult class is replaced by the
semantically similar OperationResult.
2018-04-21 17:34:52 +02:00
Patrick Lühne 28dbd407e2
Extend integer variable detection
If making a variable noninteger turns the entire formula obtained from
completion true, we can drop that statement and conclude that the
variable is integer.
2018-04-21 17:26:15 +02:00
Patrick Lühne 9c792ff079
Fix incorrect index in output
The indices printed in the output are meant to be indexed starting with
1 and not 0.
2018-04-21 17:09:45 +02:00
Patrick Lühne f65d4dbbd8
Refactor integer variable detection
This reimplements integer variable detection as two parts. The first one
is a visitor class that recursively searches for all declared variables
in a formula and applies the second part, a custom functor.

Two such functors are implemented. The first one checks whether a
predicate definition is falsified by making a variable noninteger, in
which case it can be concluded that the variable in question is integer.
The second functor checks whether bound variables in a quantified
formula turn the quantified part false, again to conclude that variables
are integer.
2018-04-21 17:02:42 +02:00
Patrick Lühne 8f3ff23f38
Add to-do 2018-04-21 16:58:42 +02:00
Patrick Lühne 03c22d00f5
Remove unwanted detection rule
This piece of code was responsible for propagating the domain of
predicate parameters to argument variables. However, this approach
doesn’t seem to be correct, which is why this commit removes it.
2018-04-21 16:58:42 +02:00
Patrick Lühne aedb7e9bbd
Add option to turn on integer variable detection 2018-04-20 16:37:49 +02:00
Patrick Lühne 5bda14342b
Print rules for integer parameters
For every integer parameter of the predicates visible in the output,
this prints a short fact to the output to make this explicit.
2018-04-20 16:37:49 +02:00
Patrick Lühne 2f54b7d60e
Minor formatting 2018-04-20 16:37:49 +02:00
Patrick Lühne 2245e139b2
Reimplement integer variable detection
This is a reimplementation of the integer variable detection procedure.
The idea is to iteratively assume variables to be noninteger, and to
prove that this would lead to a false or erroneous result. If the proof
is successful, the variable is integer as a consequence.
2018-04-20 16:37:48 +02:00
Patrick Lühne 7ba48044ee
Propagate predicate parameter domains
With this change, domains detected for predicate parameters are properly
propagated to all occurences of the respective variables, enabling more
integer simplifications.
2018-04-20 16:37:48 +02:00
Patrick Lühne 862d03881a
Fix typo 2018-04-20 16:37:48 +02:00
Patrick Lühne 7bde7c498f
Represent predicate parameters explicitly
This adds a vector of Parameter structs to PredicateDeclaration. In this
way, the domain of each parameter can be tracked individually.
2018-04-20 16:37:48 +02:00
Patrick Lühne 159717f51c
Support declaring functions as integer
This adds a new syntax for declaring functions integer:

    #external integer(<function name>(<arity)).

If a function is declared integer, it may enable some variables to be
detected as integer as well.
2018-04-20 16:37:48 +02:00
Patrick Lühne ae918a0846
Moved Domain enum to separate header
For clarity, this moves the Domain enum class to a separate header,
because it’s not just variable-specific but also applicable to
functions, for example.
2018-04-20 16:37:48 +02:00
Patrick Lühne f48802842e
Split functions from their declaration
This splits occurrences of functions from their declaration. This is
necessary to flag integer functions consistently and not just single
occurrences.
2018-04-20 16:37:48 +02:00
Patrick Lühne b5b05b766c
Remove Constant class
Constants are not a construct present in Clingo’s AST and were
unintentionally made part of anthem’s AST. This removes the unused
classes for clarity.
2018-04-20 16:37:48 +02:00
Patrick Lühne 165f6ac059
Implement basic integer variable detection
This adds initial support for detecting integer variables in formulas.
The scope is somewhat limited in that variables matching predicate
parameters with known integer type aren’t propagated to be integer as
well yet. Also, the use of constants and functions prevents variables
from being detected as integer, because they have to be assumed to be
externally defined in such a way that they evaluate to general values
and not necessarily integers.
2018-04-20 16:37:48 +02:00
Patrick Lühne d2b48f9679
Move Tristate class to separate header
The Tristate class (representing truth values that are either true,
false, or unknown) is used at multiple ends. This moves it to a separate
header for reusing it properly.
2018-04-20 16:37:48 +02:00
Patrick Lühne 2372eb24c4
Refactor predicate representation
This refactoring separates predicates from their declarations. The
purpose of this is to avoid duplicating properties specific to the
predicate declaration and not its occurrences in the program.
2018-04-20 16:37:47 +02:00
Patrick Lühne 8c250f5c59
Support modulus operation (absolute value)
This adds support for computing the absolute value of a term along with
an according unit test.
2018-04-12 00:38:48 +02:00
Patrick Lühne 797660d6de
Add new simplification rule
This adds the rule “(not F [comparison] G) === (F [negated comparison]
G)” to the simplification rule tableau.
2018-04-11 21:39:27 +02:00
Patrick Lühne 40ddee8444
Add new simplification rule
This adds the rule “(not F or G) === (F -> G)” to the simplification
rule tableau.
2018-04-10 22:34:47 +02:00
Patrick Lühne 6f7b021712
Add new simplification rule
This adds the rule “(not (F and G)) === (not F or not G)” to the
simplification rule tableau.
2018-04-10 22:34:47 +02:00
Patrick Lühne 23624007ec
Add new simplification rule
This adds the rule “not not F === F” to the simplification rule tableau.
2018-04-10 22:34:47 +02:00
Patrick Lühne 6d7b91c391
Add new simplification rule
This adds the rule “(F <-> (F and G)) === (F -> G)” to the
simplification rule tableau.
2018-04-10 22:34:47 +02:00
Patrick Lühne b88393655a
Iteratively apply simplification tableau rules
With this change, the tableau rules for simplifying formula are applied
iteratively until a fixpoint is reached.
2018-04-10 22:34:47 +02:00
Patrick Lühne c4c3156e77
Move simplification rule to tableau
This moves the rule “[primitive A] in [primitive B] === A = B” to the
simplification rule tableau.
2018-04-10 22:34:47 +02:00
Patrick Lühne 107dae7287
Move simplification rule to tableau
This moves the rule “exists () (F) === F” to the simplification rule
tableau.
2018-04-10 22:34:47 +02:00
Patrick Lühne 827d6e40fe
Move simplification rule to tableau
This moves the rule “[conjunction of only F] === F” to the
simplification rule tableau.
2018-04-10 22:34:47 +02:00
Patrick Lühne 4a85fc4b23
Move simplification rule to tableau
This moves the rule “exists ... ([#true/#false]) === [#true/#false]” to
the simplification rule tableau along with “[empty conjunction] ===
2018-04-10 22:34:46 +02:00
Patrick Lühne 7e3fc007c8
Move simplification rule to tableau
This moves the rule “exists X (X = t and F(X)) === exists () (F(t))” to
the simplification rule tableau.
2018-04-10 22:34:46 +02:00
Patrick Lühne 5c5411c0ff
Implement simplification rule tableau
This implements a tableau containing simplification rules that can be
iteratively applied to input formulas until they remain unchanged.

First, this moves the rule “exists X (X = Y) === #true” to the tableau
as a reference implementation.
2018-04-10 22:34:46 +02:00
Patrick Lühne e64b2e70de
Remove unused captured lambda reference 2018-04-08 20:44:43 +02:00
Patrick Lühne c294a29cb2
Support placeholders with #external declarations
This adds support for declaring predicates as placeholders through the
“#external” directive in the input language of clingo.

Placeholders are not subject to completion. This prevents predicates
that represent instance-specific facts from being assumed as universally
false by default negation when translating an encoding.

This stretches clingo’s usual syntax a bit to make the implementation
lightweight. In order to declare a predicate with a specific arity as a
placeholder, the following statement needs to be added to the program:

    #external <predicate name>(<arity>).

Multiple unit tests cover cases where placeholders are used or not as
well as a more complex graph coloring example.
2018-04-08 20:28:57 +02:00
Patrick Lühne 22238bb398
Switch to C++17
With C++17, optionals, an experimental language feature, were moved to
the “std” namespace. This makes C++17 mandatory and drops the now
obsolete “experimental” namespace.
2018-03-24 16:09:52 +01:00
Patrick Lühne 5f8c144628
Fixed regression in simplifying predicates with more than one argument. 2017-06-12 18:27:39 +02:00
Patrick Lühne 1f1006ea96
Corrected hiding predicates that are simple propositions. 2017-06-12 15:40:02 +02:00
Patrick Lühne a4cd133ba7
Correctly implemented hiding predicates with nested arguments. 2017-06-12 02:25:04 +02:00
Patrick Lühne bbbd0b65a4
Added new option --parentheses=full to make parsing the output easier. 2017-06-06 02:02:26 +02:00
Patrick Lühne 0285c1cbbb
Renamed internal variables for clarity. 2017-06-06 01:44:44 +02:00
Patrick Lühne 95984f0447
Added warning when attempting to use #show statements without completion. 2017-06-05 04:24:00 +02:00
Patrick Lühne 7ae0a1f289
Removed unnecessary parentheses after simplification. 2017-06-05 03:58:39 +02:00
Patrick Lühne 3b26580815
Minor formatting. 2017-06-05 03:54:17 +02:00
Patrick Lühne 14abc37116
Implemented #show statements for completed output. 2017-06-05 03:02:22 +02:00