Expression

From Dyna

Jump to: navigation, search

An expression is a term with an associated value. There are three types of expressions, described below. See also semi-expression.

Contents

Primitive expressions

Any primitive term is an expression whose value is itself:

3
"foo"

Items

Any item is an expression.

lambda 
constit("np",3,8)

Remember that a structure type is an item type if it has been declared as such:

:- item(lambda, double, 0).
:- item(constit, boolean, false).

Derived-item expressions

If x is an item, then ?x is a boolean-valued expression that is true iff the item x has been derived. This means either that x has been asserted, or that x is the consequent of at least one inference rule whose antecedent items were all derived.

This is especially useful in conditional expressions . For example, ?edge("u","v") tells you whether a particular edge exists, whereas edge("u","v")!=0 will treat 0-weight edges as nonexistent.

The ? operator incurs some extra overhead. If you use ? with items of type foo, then Dyna must distinguish underived items from items that were asserted, or otherwise derived, with the default value. For example, it cannot get rid of an item (during retraction, say) simply by setting its value to the default.

Computed expressions

Computed expressions work as in languages like C++. Examples:

log(lambda)
lambda*constit("np",3,8)
1 / (1 + exp(-weight(node22)))

A structure type is a computed expression type if it has been declared as such. This means that its functor has been declared to be a function:

% All three of these declarations are actually superfluous since Dyna
% automatically declares the C++ operators, and log, as functions.  
:- computed(log).
:- computed(*, 'operator*').    % second argument is the name of the C++ function to call
:- computed(/, 'operator/').    

Notice that a term whose functor is * will have two subterms such as lambda and constit("np",3,8). The subterms themselves are not numeric values but full-fledged expressions in their own right union. The value of the term is computed by multiplying the values of the two subterms.

What if * is a union over several subtypes: can these have different value types (operator overloading), and can some of them not be computed at all (* as pairing term)?

Current limitations of computed expressions

At present, the :- computed declaration is not implemented, so you can't import your own functions yet. Indeed, the only functions currently allowed are *, +, and &, and only one of them can be used in a given program. For details, see inference rule and current limitations and workarounds.

The "whenever" syntax in inference rules acts like an if/then operator. Actually, since these can be returned as antecedents, I think we need to regard them as expressions, but they're funny expressions since they have no value if the "if" clause fails. So it can't be legal to evaluate them outside the context of an inference rule? Or they can just return null_term as a value?

Logarithmic literals

The current implementation of Dyna also recognizes a special syntax for literal doubles:

log(0.5)   % equivalent to the double 0.69314718

Once Dyna lets you call arbitrary functions; we will be able to remove this special syntax without damaging the meaning of log(0.5).

FIELD_MESSAGE_racbocl

Personal tools