Category Archives: Programming

The use of recursive aggregates in Answer Set Programming (ASP) was so far limited because current solvers only deal with monotone aggregates. The grounder is thus in charge for rewriting aggregates into the more constrained form accepted by solvers. However, until now, no rewriting that correctly transform non-convex aggregates was known. This is going to change soon! Give a try to this script on my GitHub. File README, reported below, should give enough information on how to use the script.

$ ./f-aggregates.py --help-syntax
The syntax is almost conformant to ASP Core 2.0, with the exception of aggregates.
Moreover, predicates starting with the prefix 'f_' are reserved for internal use
and must not be used by the user. Remember also to not hide them!
Supported aggregates are COUNT, SUM, AVG, MIN, and MAX. Aggregate sets are
declared by means of predicate f_set/3, where:
- the first argument is the ID of an aggregate;
- the second argument is an integer;
- the third argument is an atom.
The second argument is optional, with default value 1.
A COUNT aggregate can be added in a rule body by using predicate f_count/3, where:
- the first argument is the ID of an aggregate;
- the second argument is a comparator among ">=", ">", "<=", "<", "=", "!=";
- the third argument is an integer.
Aggregates SUM, AVG, MIN, and MAX are similar, and use predicates f_sum/3, f_avg/3,
f_min/3, and f_max/3.
Remember that COUNT is applied on true atoms in the aggregate set, while SUM, AVG,
MIN, and MAX are applied on the multiset of integers associated with true atoms in
the aggregate set.
Variables can be used taking into account the previous description.

$ ./f-aggregates.py --help-syntax
The syntax is almost conformant to ASP Core 2.0, with the exception of aggregates.
Moreover, predicates starting with the prefix 'f_' are reserved for internal use
and must not be used by the user. Remember also to not hide them!
Supported aggregates are COUNT, SUM, AVG, MIN, and MAX. Aggregate sets are
declared by means of predicate f_set/3, where:
- the first argument is the ID of an aggregate;
- the second argument is an integer;
- the third argument is an atom.
The second argument is optional, with default value 1.
A COUNT aggregate can be added in a rule body by using predicate f_count/3, where:
- the first argument is the ID of an aggregate;
- the second argument is a comparator among ">=", ">", "<=", "<", "=", "!=";
- the third argument is an integer.
Aggregates SUM, AVG, MIN, and MAX are similar, and use predicates f_sum/3, f_avg/3,
f_min/3, and f_max/3.
Remember that COUNT is applied on true atoms in the aggregate set, while SUM, AVG,
MIN, and MAX are applied on the multiset of integers associated with true atoms in
the aggregate set.
Variables can be used taking into account the previous description.

I finally completed my teaching semester and have the time to describe a few tools I worked on in this period. The first of these tools is pyrunlim, a Python script for measuring and limiting resources used by a specified command. Actually, it is Continue reading →

PLY is a Python Lex-Yacc parsing tool. Defining a parser in PLY is quite simple, and for a high-level language such as Python this is the key feature. A lack I noted in PLY is the inability of efficiently parsing a file Continue reading →

In a previous post we talked about the program bfsms for sending SMS’s via bluetooth. We also applied a patch for sending splitted SMS’s, in other words messages which are divided in more than one SMS and sent one-by-one.

Clearly, a unique SMS is preferable, like for long SMS’s sent by moder mobile phone. This kind of messages are called concatenated SMS’s and Continue reading →

There are programs which are simple and really useful, but for some reason their development were stopped. Probably, bfsms is one of this, stopped still 2004. This application allows to send SMS’s from a shell, connecting to a mobile phone via bluetooth. The only inconvenience is that such SMS’s must be no longer than 160 characters (or 70 for flash SMS’s).

Since I often send SMS’s longer than 160 characters, I tried to search the web the standard defining concatenated SMS’s (which are sended by modern mobile phone when an SMS of more than 160 character is typed). I lost an afternoon trying to understand the absurd choices of the authors of this protocol. Then, I give up this street and moved to a different approach: I will automatically divide the message in more than one SMS, avoiding Continue reading →