next up previous
Next: 5.3 Linked-In Functions and Up: 5 Predicates and Functions Previous: 5.1 User-defined Predicates and

5.2 Internal Functions and Predicates

Alchemy implements several internal predicates and functions. These are widely used operators such as those from arithmetic, string concatenation, etc. The common arithmetic and comparison operators found in most programming languages can also be used in infix notation. Note, the equality predicate, introduced in the previous section, is not internally computed, but rather it is something you can do inference over and can be used with any type. Here is a list of the internally implemented predicates and functions with the infix notation where available:

Internal Predicates
Symbol Declaration Explanation
> greaterThan(int, int) Tests if first argument is greater than the second
< lessThan(int, int) Tests if first argument is less than the second
>= greaterThanEq(int, int) Tests if first argument is greater than or equal to the second
<= lessThanEq(int, int) Tests if first argument is less than or equal to the second
(none) substr(string, string) Tests if first argument is a substring of the second

Internal Functions
Symbol Declaration Explanation
(none) int succ(int) Returns the successor of the argument (+1)
+ int plus(int, int) Returns the addition of the two arguments
- int minus(int, int) Returns the first argument minus the second argument
* int times(int, int) Returns the multiplication of the two arguments
/ int dividedBy(int, int) Returns the first argument divided by the second argument
% int mod(int, int) Returns the remainder of the first argument divided by the second argument
(none) string concat(string, string) Returns the concatenation of the two arguments

The types of the variables used in internal functions and predicates (and the return type of functions) are determined by the parser as it encounters each formula. This information is used, for example, to count the number of groundings during inference or learning. If the type can not be determined, an error is thrown and Alchemy exits. For example, if the formula name(x) ^ substr(y,x) => name(y) is given, the type of variables x and y can be determined from the declaration of the predicate name.


next up previous
Next: 5.3 Linked-In Functions and Up: 5 Predicates and Functions Previous: 5.1 User-defined Predicates and
Marc Sumner 2010-01-22