Orbital library

orbital.logic.sign
Interface ExpressionBuilder

All Known Subinterfaces:
ExpressionSyntax, Logic
All Known Implementing Classes:
ClassicalLogic, FuzzyLogic, MathExpressionSyntax, ModalLogic

public interface ExpressionBuilder

Defines a general interface for constructing complex expressions. Implementations of this interface are responsible for constructing compound expressions (like terms, formulas). They usually correspond to a formal language of a corresponding abstract syntax for expressions. This interface effectively works as a builder for syntactic expressions.

Refer to the ParseException dilemma to read about why the exception types may have to change some day.

Author:
André Platzer
See Also:
Expression, Builder
Invariants:
true

Method Summary
 Expression.Composite compose(Expression compositor, Expression[] arg)
          Create a compound expression representation with a composition operation.
 Expression createAtomic(Symbol symbol)
          Create an atomic expression representation of a non-compound sign.
 

Method Detail

createAtomic

Expression createAtomic(Symbol symbol)
                        throws java.lang.IllegalArgumentException
Create an atomic expression representation of a non-compound sign.

Atomic symbols are either elemental atoms, strings or numbers. In contrast, a logical formula that is not compound of something (on the level of logical junctors) like "P(x,y)" is sometimes called atom.

Note
A compound expression like "P(x)" will not be atomic symbols (although a logic might consider such single predicate applications as atomic in the sense of atomicity on the level of logical junctors). However, the variable "x", and the predicate symbol "P" are atomic symbols.

Parameters:
symbol - the symbol whose atomic expression representation to create.
Returns:
an instance of Expression that represents the atomic symbol in this logic.
Throws:
java.lang.IllegalArgumentException - if the symbol is illegal for some reasons. Note that this is a rather rare case and no parsing is involved at all, which is why this method does not throw a ParseException.
See Also:
Factory Method
Preconditions:
null≠symbol∈Σ∪V∪... is a syntactically valid symbol
Postconditions:
RES≠null ∧ RES.getType().equals(symbol.getType()) ∧ (RES.isVariable() ⇔ symbol.isVariable())

compose

Expression.Composite compose(Expression compositor,
                             Expression[] arg)
                             throws ParseException,
                                    TypeException
Create a compound expression representation with a composition operation. Connects expressions with a compositor to form a complex expression.

Signature.get(String,Object[]) may be useful for determining the right functor symbol for a composition in case of an atomic compositor.

Be aware that this method does a composition (in the sense of semiotics) of signs/expressions, but not usually a composition (in the sense of mathematics) of functions. Mathematically speaking, the composition that this method performs would usually be called application instead of composition. Although composition (in the sense of mathematics) and application are correlated, they have different types at first sight

:(σ→τ)×(τ'→σ') → (τ→τ'); (g,f) ↦ g∘f = (x↦g(f(x))), provided that σ'σ
_(_):(σ→τ)×σ' → τ; (f,x) ↦ f(x) provided that σ'σ
Yet together with λ-abstraction, composition can be expressed in terms of application (as the definition above shows). And in conjunction with the (selective) identification of type void→σ' with σ' application can also be expressed per composition.

Parameters:
compositor - the expression that is used for composing the arguments.
arg - the arguments a passed to the combining operation.
Returns:
an expression that represents the combined operation with its arguments, like in
compositor(a[0],…,a[a.length-1])
Throws:
ParseException - if the composition expression is syntactically malformed. Either due to a lexical or grammatical error (also due to wrong type of arguments).
TypeException - if the arguments have the wrong type for composition, i.e. compositor.getType().on(typeOf(arg)) raises a TypeException. Note that type errors are still a kind of syntactic errors, but should be separated from pure parse exceptions in order to simplify distinction for exception handlers.
See Also:
Factory Method
Preconditions:
compositor≠null ∧ succeedes(compositor.getType().on(typeOf(arg))) ∧ "compositor(arg)"∈L "compositor applied to arg represents a syntactically well-formed expression"
Postconditions:
RES≠null ∧ RES.getType()=compositor.getType().on(typeOf(arg)) ∧ ....

Orbital library
1.3.0: 11 Apr 2009

Copyright © 1996-2009 André Platzer
All Rights Reserved.