Skip to content

Base Types

This section documents the fundamental data types supported by the constraint_handler. Each type comes with its own set of operators.


Notation

In the following sections, we will use the here declared notation to describe types and their available operators.

Operator Signatures

Operators are described using a function signature notation:

(input_type1, input_type2, ...) -> output_type

Where input_type and output_type refer to the data types involved in the Operation.

Simple

Simple operators often only require a single input type and produce a single output type. For example, an addition operator for two integers would be represented as:

(int, int) -> int

Variadic

To represent operators that can take a variable number of inputs, we use notation similar to regex, where a * indicates zero or more occurrences of a type. For example, an operator that sums any number of integers could be represented as:

(int*) -> int

Union

Sometimes, arguments or return values may allow for multiple types. In such cases, the overall type is represented as a union of possible types. This is denoted using the pipe symbol |. For example:

(int | float, int | float) -> int
Could represent an Operation like the integer division. This accepts two arguments that may be any combination of integers and floats, but always returns an integer.

Generic Variables

Capitalized letters act as placeholders for any type.

  • Consistency: If the same letter appears multiple times (e.g., A), all arguments using that letter must be of the same type.
  • Distinctness: Different letters (e.g., A and B) can represent different types.

When defining more complex operators, the output type may depend directly on the input types. This is indicated using placeholders like A, B, etc. For example:

(A, B) -> A | B
Indicates that the output type can be either of the input types.

Example: Same Type

Given some operator signature:

(T, T) -> bool
This means that the operator takes two inputs of the same type (denoted by T), and returns a boolean value.

Example: Different Types

Given some operator signature:

(A,B) -> A

This means that the operator takes two inputs of potentially different types (denoted by A and B), and returns a value of the same type as the first input (A).


None

To represent undefined values, the constraint handler uses none. Unlike a variable simply missing from a list, none is an explicit value that propagates through certain operations.

Definition

val(none, none)

Output

value(name, val(none, none))

Supported Operators

Operator Name Signature Description
Comparison
eq Equality (none | T, none | T) \(\to\) bool true if both arguments have the same value, otherwise false.
neq Inequality (none | T, none | T) \(\to\) bool true if both arguments have different values, otherwise false.
Logical
limp Implication (none | bool, none | bool) \(\to\) bool | none true if the first argument is false or the second is true. Evaluates to false if true implies false, and none otherwise.
Negation
lnot Classical Negation (none) \(\to\) none The negation of none is still none.

Bool

Booleans represent the logical values true and false. They are the result of comparisons and the building blocks for logical conditions.

Definition

val(bool, true)
val(bool, false)

Output

value(name, val(bool, true))
value(name, val(bool, false))

Supported Operators

Operator Name Signature Description
Comparison
eq Equality (bool | none, bool | none) \(\to\) bool true if both arguments have the same value, otherwise false.
neq Inequality (bool | none, bool | none) \(\to\) bool true if both arguments have different values, otherwise false.
Logical
conj Conjunction (bool*) \(\to\) bool true only if all arguments in the list are true. Short-circuits if false is found.
disj Disjunction (bool*) \(\to\) bool true if at least one argument in the list is true.
limp Implication (bool | none, bool | none) \(\to\) bool | none true if the first argument is false or the second is true. Evaluates to false if true implies false, and none otherwise.
lxor Exclusive OR (bool*) \(\to\) bool true if an odd number of arguments are true.
leqv Equivalence (bool*) \(\to\) bool true if an even number of arguments are true.
Negation
lnot Logical (bool) \(\to\) bool Standard inversion (true \(\to\) false, false \(\to\) true).
snot Strong (bool) \(\to\) bool Treats undefined/missing values as false.
wnot Weak (bool) \(\to\) bool Treats undefined/missing values as true.

Example

Checking for inequality of two variables

variable_define(a, val(bool, true)).
variable_define(b, val(bool, false)).
variable_define(c, operation(neq, (variable(a), (variable(b), ())))).

This would assign the value true to the variable c.


Int

Integers represent positive and negative whole numbers. They support standard arithmetic operations as well as comparisons.

Definition

val(int, 42)
val(int, -7)

Output

value(name, val(int, 42))
value(name, val(int, -7))

Supported Operators

Operator Name Signature Description
Arithmetic
add Addition (int*) \(\to\) int Adds all provided integers together.
sub Subtraction (int, int) \(\to\) int Subtracts the second integer from the first.
mult Multiplication (int*) \(\to\) int Multiplies all provided integers together.
int_div Integer Division (int | float, int | float) \(\to\) int Divides the first argument by the second and rounds down to the nearest integer.
pow Exponentiation (int, int) \(\to\) int Raises the first integer to the power of the second.
abs Absolute Value (int) \(\to\) int Returns the absolute value of the integer.
minus Unary Minus (int) \(\to\) int Negates the integer.
max Maximum (int, int) \(\to\) int Returns the larger of the two integers.
min Minimum (int, int) \(\to\) int Returns the smaller of the two integers.
Trigonometry
sqrt Square Root (int) \(\to\) float Calculates the square root of the integer.
sin Sine (int) \(\to\) float Calculates the sine of the integer.
cos Cosine (int) \(\to\) float Calculates the cosine of the integer.
tan Tangent (int) \(\to\) float Calculates the tangent of the integer.
asin Arc Sine (int) \(\to\) float Calculates the inverse sine.
acos Arc Cosine (int) \(\to\) float Calculates the inverse cosine.
atan Arc Tangent (int) \(\to\) float Calculates the inverse tangent.
Comparison
eq Equality (int | none, int | none) \(\to\) bool true if both arguments have the same value, otherwise false.
neq Inequality (int | none, int | none) \(\to\) bool true if both arguments have different values, otherwise false.
lt Less Than (int, int) \(\to\) bool true if first is strictly less than second.
leq Less Than or Equal (int, int) \(\to\) bool true if first is less than or equal to second.
gt Greater Than (int, int) \(\to\) bool true if first is strictly greater than second.
geq Greater Than or Equal (int, int) \(\to\) bool true if first is greater than or equal to second.

Example

Adding two integers

variable_define(a, val(int, 5)).
variable_define(b, val(int, 10)).
variable_define(c, operation(add, (variable(a), (variable(b), ())))).
This would assign the value 15 to the variable c.


Float

Floats represent real numbers with fractional parts. They support a wide range of mathematical operations, including trigonometry.

Info

Since neither , nor . can be used in ASP to represent floating point numbers, floats are represented by strings inside of the function symbol float/1. This means "3.14" is used for strings, while float("3.14") is used for floats.

Definition

val(float, float("3.14159"))
val(float, float("-0.001"))

Output

value(name, val(float, float("3.14159")))
value(name, val(float, float("-0.001")))

Supported Operators

Type Promotion

If a binary operation involves one int and one float (e.g. the addition of an int and a float), the integer is automatically promoted to a float. The result is then calcualted as if both operands were floats.

Operator Name Signature Description
Arithmetic
add Addition ([int | float]*) \(\to\) float Adds all provided numbers together.
sub Subtraction (float, float) \(\to\) float Subtracts the second float from the first.
mult Multiplication ([int | float]*) \(\to\) float Multiplies all provided numbers together.
float_div Float Division (int | float, int | float) \(\to\) float Performs explicit floating point division.
floor Floor (float) \(\to\) int Rounds the float down to the nearest integer value.
ceil Ceiling (float) \(\to\) int Rounds the float up to the nearest integer value.
pow Exponentiation (float, float) \(\to\) float Raises the first value to the power of the second.
abs Absolute Value (float) \(\to\) float Returns the absolute value.
minus Unary Minus (float) \(\to\) float Negates the value.
max Maximum (A[int | float], B[int | float]) \(\to\) A | B Returns the larger of the two values, keeping the respective type.
min Minimum (A[int | float], B[int | float]) \(\to\) A | B Returns the smaller of the two values, keeping the respective type.
Trigonometry
sqrt Square Root (float) \(\to\) float Calculates the square root.
sin Sine (float) \(\to\) float Calculates the sine.
cos Cosine (float) \(\to\) float Calculates the cosine.
tan Tangent (float) \(\to\) float Calculates the tangent.
asin Arc Sine (float) \(\to\) float Calculates the inverse sine.
acos Arc Cosine (float) \(\to\) float Calculates the inverse cosine.
atan Arc Tangent (float) \(\to\) float Calculates the inverse tangent.
Comparison
eq Equality (float | none, float | none) \(\to\) bool true if both arguments have the same value, otherwise false.
neq Inequality (float | none, float | none) \(\to\) bool true if both arguments have different values, otherwise false.
lt Less Than (float, float) \(\to\) bool true if first is strictly less than second.
leq Less Than or Equal (float, float) \(\to\) bool true if first is less than or equal to second.
gt Greater Than (float, float) \(\to\) bool true if first is strictly greater than second.
geq Greater Than or Equal (float, float) \(\to\) bool true if first is greater than or equal to second.

Example

Multiplying two floats

variable_define(a, val(float, float("2.5"))).
variable_define(b, val(float, float("4.0"))).
variable_define(c, operation(mult, (variable(a), (variable(b), ())))).
This would assign the value float("10.0") to the variable c.


String

Strings are used to represent text-based data. They support concatenation and comparison operations.

Definition

val(string, "Hello, World!")
val(string, "Constraint Handling")

Output

value(name, val(string, "Hello, World!"))
value(name, val(string, "Constraint Handling"))
Operator Name Signature Description
Manipulation
concat Concatenation (string, string) \(\to\) string Joins two strings together.
length Length (string) \(\to\) int Returns the number of characters in the string.
Comparison
eq Equality (string | none, string | none) \(\to\) bool true if both arguments have the same value, otherwise false.
neq Inequality (string | none, string | none) \(\to\) bool true if both arguments have different values, otherwise false.

Example

Concatenating a prefix to a name.

variable_define(prefix, val(string, "var_")).
variable_define(suffix, val(string, "x")).
variable_define(full_name, operation(concat, (variable(prefix), (variable(suffix), ())))).

This would assign the value "var_x" to the variable full_name.


Symbol

Normal ASP symbols can also be used as values. They are frequently used for representing states or identifiers.

Definition

val(symbol, active)
val(symbol, state(idle))

Output

value(name, val(symbol, active))
value(name, val(symbol, state(idle)))

Supported Operators

Ordering

Symbol comparison follows the standard Clingo/ASP ordering rules.

Operator Name Signature Description
Comparison
eq Equality (symbol | none, symbol | none) \(\to\) bool true if both arguments have the same value, otherwise false.
neq Inequality (symbol | none, symbol | none) \(\to\) bool true if both arguments have different values, otherwise false.
lt Less Than (symbol, symbol) \(\to\) bool true if first argument is smaller than the second.
leq Less Than or Equal (symbol, symbol) \(\to\) bool true if first argument is smaller than or equal to the second.
gt Greater Than (symbol, symbol) \(\to\) bool true if first argument is larger than the second.
geq Greater Than or Equal (symbol, symbol) \(\to\) bool true if first argument is larger than or equal to the second.

Example

Checking if a status variable is set to error.

variable_define(current_status, val(symbol, error)).
variable_define(is_critical, operation(eq, (variable(current_status), (val(symbol, error), ())))).

This would assign true to is_critical.