Orbital library

orbital.moon.logic
Class MathExpressionSyntax

java.lang.Object
  extended by orbital.moon.logic.MathExpressionSyntax
All Implemented Interfaces:
ExpressionBuilder, ExpressionSyntax

public class MathExpressionSyntax
extends java.lang.Object
implements ExpressionSyntax

This class implements an expression syntax for mathematical expressions. Those expressions currently get parsed as a composition of functions. An alternative implementation would already evaluate the expression instead of explicitly constructing a representation as a composition of functions.

Author:
André Platzer
Structure:
depends orbital.logic.sign.concrete.Notation Uses registered notation functors reverse.

Field Summary
static java.lang.String usage
           
 
Constructor Summary
MathExpressionSyntax()
           
 
Method Summary
 Expression.Composite compose(Expression compositor, Expression[] arguments)
          Create a compound expression representation with a composition operation.
 Signature coreSignature()
          Get the core signature which is supported by the language of this expression syntax.
 Expression createAtomic(Symbol symbol)
          Create an atomic expression representation of a non-compound sign.
 Expression createExpression(java.lang.String expression)
          Create a term representation by parsing a (compound) expression..
 Arithmetic createMathExpression(java.lang.String expression)
          Parses an expression and queries its arithmetic object.
 Arithmetic getValueOf(Expression x)
          Get the arithmetic object represented by an expression.
static void main(java.lang.String[] arg)
          tool-main
 Signature scanSignature(java.lang.String expression)
          Scan for the signature Σ of all syntactic symbols in an expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

usage

public static final java.lang.String usage
See Also:
Constant Field Values
Constructor Detail

MathExpressionSyntax

public MathExpressionSyntax()
Method Detail

main

public static void main(java.lang.String[] arg)
                 throws java.lang.Exception
tool-main

Throws:
java.lang.Exception

createExpression

public Expression createExpression(java.lang.String expression)
                            throws ParseException
Create a term representation by parsing a (compound) expression.

In fact, parsing expressions is only possible with a concrete syntax. So implementations of this method are encouraged to define and parse a standard notation which can often be close to the default notation of the abstract syntax.

.

Specified by:
createExpression in interface ExpressionSyntax
Parameters:
expression - the compound expression to parse. A string of "" denotes the empty expression. However note that the empty expression may not be accepted in some term algebras. Those parsers rejecting the empty expression are then inclined to throw a ParseException, instead.
Returns:
an instance of Expression that represents the given expression string in this language.
Throws:
ParseException - when the expression is syntactically malformed. Either due to a lexical or grammatical error.
See Also:
createMathExpression(String)

createMathExpression

public Arithmetic createMathExpression(java.lang.String expression)
                                throws ParseException
Parses an expression and queries its arithmetic object.

Throws:
ParseException
See Also:
Convenience Method, createExpression(String), getValueOf(Expression)
Postconditions:
RES = getValueOf(createExpression(expression))

coreSignature

public Signature coreSignature()
Description copied from interface: ExpressionSyntax
Get the core signature which is supported by the language of this expression syntax.

The core "signature" contains the logical signs that inherently belong to this term algebra and are not subject to interpretation. Logical signs are logical constants like true, false, and logical operators like ¬, ∧, ∨, →, ∀, ∃. The latter are also called logical junctors.

Note that some authors do not count the core "signature" as part of the proper signature Σ but would rather call it "meta"-signature.

Specified by:
coreSignature in interface ExpressionSyntax
Returns:
the core signature that is valid for every expression following this syntax. Elements in the core signature all have a fixed interpretation.
See Also:
Logic.coreInterpretation()

scanSignature

public Signature scanSignature(java.lang.String expression)
                        throws ParseException
Description copied from interface: ExpressionSyntax
Scan for the signature Σ of all syntactic symbols in an expression.

However, note that this method does not necessarily perform rich type querying. Especially for user-defined functions with an arbitrary argument-type structure, it is generally recommended to construct the relevant signature entries explicitly.

Specified by:
scanSignature in interface ExpressionSyntax
Parameters:
expression - the expression that should be scanned for symbol names.
Returns:
Signature of the syntactic symbols in expression except those of the core signature.
Throws:
ParseException - (optional) when the expression is syntactically malformed. Either due to a lexical or grammatical error. (optional behaviour for performance reasons). Will not throw ParseExceptions if createExpression would not either.
See Also:
ExpressionSyntax.coreSignature(), "Factory Method"

createAtomic

public Expression createAtomic(Symbol symbol)
Description copied from interface: ExpressionBuilder
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.

Specified by:
createAtomic in interface ExpressionBuilder
Parameters:
symbol - the symbol whose atomic expression representation to create.
Returns:
an instance of Expression that represents the atomic symbol in this logic.
See Also:
Factory Method

compose

public Expression.Composite compose(Expression compositor,
                                    Expression[] arguments)
                             throws ParseException
Description copied from interface: ExpressionBuilder
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.

Specified by:
compose in interface ExpressionBuilder
Parameters:
compositor - the expression that is used for composing the arguments.
arguments - 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).
See Also:
Factory Method

getValueOf

public Arithmetic getValueOf(Expression x)
Get the arithmetic object represented by an expression.

Preconditions:
x = this.compose(...) ∨ x = this.createAtomic(...)

Orbital library
1.3.0: 11 Apr 2009

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