Building Expressions

ASTRA provides three kinds of expression.

Logical Expressions

A logical expression is something that can be evaluated to true or false. Typically, it involves some combination of beliefs and comparisons that are joined together using boolean operators (and, or, not). Logical expressions are used in the context of a plan rule, a query statement, and in any other place where the execution of a statement depends on the state of the agent.

OperatorSymbolExample
Not~~likes(string X, "icecream")
~result(int X, int Y, int Z)
And&likes(string X, "icecream") & is(X, "happy")
Or|has(X, "icecream") | has(X, "beer")
Brackets()hungry(string X) & (likes(X, "icecream") | likes(X, "burgers"))

For example, lets consider a football player who has do decide what to do next.  The decision can be modeled as a goal !decde() that has a number of associated rules – one for each option available to the player.

If the player has the ball and is being closed down, but there is a player from the same team near the player then one option is to pass the ball to that player. On the other hand, if the player is in shooting range of the oppositions goal, then they should take a shot. This behaviour can be encoded as the following pair of rules:

rule +!decide() : 
        has("ball") & is("closed_down") & 
        close("opposition_goal") {ccdd
    !shoot();
}

rule +!decide() : 
        has("ball") & is("closed_down") &
        near("team_player", string P) {
    !pass(P);
}

Here, the contexts is a conjunction of belief literals (some beliefs that are “anded” together).

In addition to conjunction, we can also introduce disjunction (or operators). For example, consider somebody who will eat food only if the like that food, or at least tolerate that food:

rule +!eat(string F) : likes(F) | tolerates(F) {
    body.eat(F);
}