FunLog++ - introduction - glossary - language - library - special - semiknown - dynamic
FunLog++ Library
FunLog++ hierarchy - competence - types - control - arithmetic - texts&lists - SI units - date&position - unification&ordering - identity - semiknown - exceptions - subprograms - locations - resources

The FunLog++ standard library provides functions for known number objects, text objects, list objects as well as for semiknown or unknown objects. Objects with dimensional units (for length, area, volume, mass, time) and absolute date objects can be also calculated by the standard library.

This document is still and will be under development (at least until December 1998). Minor changes will occur without further notice. Last modification: 9 Jan 1998


Contents



FunLog++ standard library object-type hierarchy (to contents)
The FunLog++ standard library is implemented in pure object oriented technology where the following class hierarchy is implemented by inheritance. In FunLog++ (like in Prolog) types of local variables and parameter positions need not to be declared. It is presented here to support the following explanations of FunLog++ standard library functions.
Classes for competence levels (to contents)
In FunLog++ competence reasoning deals with more or less vague knowledge. Vague knowledge is knowledge using vague data. A FunLog++ variable is unknown if it is not bound to a known or semiknown object. Semiknown objects are introduced by specific possibilistic or probabilistic denotation functions. These generate unions, intervals (e.g. 2--8), grammars, probabilities (e.g. normal @ 20 % \/ high @ 58%) and stochastic data objects. Known objects are all those which also occur in conventional programming languages (e.g. the text "Boston"). Finally the result of a term (or message) may be empty which means that the set of solutions of this term has no elements. Functions for these four competence levels are implemented in the standard library as ordinary class programs. There are four functions is_unknown/1, is_semiknown/1, is_known/1, and is_empty/1 which can be used to test the competence level of some object. Testing for competence level in a FunLog++ program introduces non monotonic reasoning. Unfortunately in real life knowledge based systems it is necessary to test if an input variable is unknown or if the set of solutions is empty. So realistic logic programming requires some kind of non monotonic reasoning which is based on competence testing in FunLog++. Other FunLog++ standard library functions that introduce non monotonic reasoning are A|B, A,B, A;B, and A??B (see below).

In FunLog++ tests usually may succeed or fail. The test result (in contrast to Prolog) is an object. It is comfortable to include in each class a function which succeeds if its parameter is of the respective class. But if the parameter belongs to a different class we get an undefined_exception. Therefore there is a postfix operator A? (see below) which returns failure if the respective function A returned an undefined_exception. So, e.g. to test if some object X is unknown you will have to write is_unknown(X)?.


Classes for standard data types (to contents)
Known and semiknown objects belong either to the user-defined objects or to one of the standard library data types which are: number, text, list, measure, or date. For the latter there are specific type tests.

length; mass; duration; temperature; current, light; substance
 
 

These tests succeed for the respective known objects and for pure semiknown objects, i.e. where only objects of one of these types are possible. The tests return the undefined_exception for known, unknown or empty objects. Again use postfix operator ?/1 to convert the undefined_exception into failure. E.g. write is_number(X)? in order to test if X is a number or not. Within the measure objects we can furthermore test if the measure is a length, a mass, a (temporal) duration, a temperature, an electric current, strength of light, amount of substance, or a composed measure.

Control functions (to contents)
As in FunLog++ there is no cut operator like in Prolog we need different conjunction and disjunction operator pairs to restrict search space of FunLog++ functions. Furthermore in Prolog we can not differentiate if a function is not defined or if the set of solutions is empty. But in an object-oriented language like FunLog++ we have to decide if the message in question is accepted by a certain function. Technically speaking if a message is not accepted then the respective function returns the missing/0 object. In this case the message would go to the next function or apply inheritance. The following binary control functions take two arbitrary parameters A and B. The main reason to introduce success and failure was readability of the FunLog++ program. Success is represented by a special success/0 object and failure is represented by a special failure/0 object.

In order to select the wanted function depending on parameter objects types two new operators A!B and A::B were introduced. A!B is used to check the premises A (e.g. a type check) before an evaluation of message B. If the premise A fails then this function does not accepted the message and the next function of the program has to be tried. In so far the location of a function within a FunLog++ program may be of importance.

A::B is used to combine two FunLog++ program functions if signatures (name and arity) are equal. So the function is equivalent to the first two functions.


A,,B and A;;B work like A,B and A;B do in Prolog.

But as there is no cut operator in FunLog++ and as the inference function returns all possible solutions Y="not negative" will be returned also if X is negative. So here an extra check X>=0 in the second alternative would be better.


There is another pair of conjunction and disjunction, A /\ B and A \/ B.

The function of A\/B is similar to A;;B and the function of A/\B is similar to A,,B. The difference is an intensionalistic property: While A;;B and A,,B use backtracking, A/\B and A\/B use the technique of semiknown data where alternatives are implemented in lists. If disjunction/conjunction is used for syntax analysis than A;;B and A,,B would be more appropriate. But when operands are semiknown data, e.g. numeric intervals, than the other approach is more efficient as 2--8 \/ 6--10 merges to 2--10 while 2--8;6--10 returns the two possible solutions 2--8 and 6--10 one after the other.


With backtracking or semiknown conjunction or disjunction both operand A and B might backtrack or be ambiguous. But if we want that disjunction A;;B should fail if A failed (independent of B) then we can use A;B instead. If we known that in a conjunction A,,B the left operand A cannot backtrack then we can tell this to the interpreter by using A,B instead (see above).


Arithmetic functions (to contents)
From the FunLog++ standard library we can obtain two sorts of numeric objects: numbers which are integers (e.g. 4711) or reals (e.g. 3.14) and measures which may be of one basic SI unit (e.g. 30 km) or composed (e.g. 11.2 km/1 s). Furthermore numeric objects may be unknown (e.g. _ ), semiknown (e.g. 2--8) or known (e.g. 35). The following functions take known, semiknown, or unknown number or measure parameters A and B. Not all numeric functions are already defined for all kinds of numeric operands in the current implementation. All functions are available if the operands are known. If A or B are semiknown numeric objects then +A, -A, A+B, A-B and A% are implemented. But A*B, A/B, A//B as well as sqrt(A), ln(A), and exp(A) are not in all cases (we are working on that). If you try (2--8)*(1--3) then you will get (2--24). If A or B are unknown then product and ratio are also unknown  - so far this works. But see the following example: In the current implementation SUM will remain unknown after evaluation of logic_sum(2,5,SUM) which is not correct. In order to be consistent with logic commutativity of operands is required. We hope that this will be fixed in one of the next FunLog++ versions, when numerical constraints will be implemented.

Texts and Lists (to contents)
There are two types of sequences in FunLog++ standard library, texts and lists. A text is a sequence of characters. A list is a sequence of arbitrary element objects. There is a function display(X) which converts an arbitrary object to a text. If A and B are both texts or both lists then A&B results the concatenation of A and B. In FunLog++ there are currently no functions to select in texts. But texts together with logic variables, concatenation (A#B) and disjunction (A;;B or A\/B) might be used to define grammars which are some kind of semiknown (possibilistic) text objects. There is some more work to be done here and we hope to be able to make it available in future versions of FunLog++.

Measure objects (SI units) (to contents)
There are measure types which are covered by the international standard units (SI units). Functions for all implemented SI units are syntactically supported by postfix enhancement, i.e. dimensional units may be written postfix (Number Unit). Examples are 40 km, 5 s, 80 kg. Length (m), mass (kg), and time (s) are implemented. Now also intensity of current ('A'), temperature ('K'), intensity of light (cd), and amount of substance (mol) are  implemented. Measures with one SI unit are called a basic measures. In contrast composed measures are obtained by multiplication and/or division between basic (or composed) measures.

From the composed units area (m2) and volume(m3) are supported by denotation functions (e.g. 5 m3) and the display/1 function. The other composed measures as there are frequency (1/s), velocity (m/s), acceleration (m/s2), force ('N'=kg*m/s2), density (kg/m3), specific gravity ('N'/m2), pressure ('Pa'='N'/m2), work=energy ('J'='N'*m), power ('W'='N'*m/s), turning moment ('N'*m), impulse (kg*m/s) have to be specified in terms of the basic SI units.

There are 7 functions to denote (temporal) duration. Duration is represented as multiples of 1 second and multiples of 1 month. Unfortunately months can not be directly converted to seconds and so time is internally represented as a pair (Months,Seconds). As a consequence, 25 days < 1 months will succeed, 35 days < 1 months will fail. But X days < 1 months is not defined for X between 28 and 30 as here it is unclear which month to compare. So if you compare two durations of time where you don't know if duration was given in seconds or months be prepared to get an undefined_exception. Finally there are denotations for strength of current, amount of substance, temperature, and strength of light. In addition to the basic SI units there is also a list of derived units with special names - these are also supported in the FunLog++ standard library.
Date and position (to contents)
There are absolute temporal (date) and spatial (position) references. A temporal reference is e.g. "September 8 1996 12:37". A spatial reference is "51th degree of northern latitude, 20th of eastern longitude, 550 m altitude (above sea level)". Temporal references may be denoted using the functions on/6, now/0 or today/0. Furthermore some arithmetic functions and the order relation < is defined on dates. Absolute spatial measures are not yet implemented.
Unification and ordering functions (to contents)
To unify two objects A=B is to try to make them equal by mutual binding variables and (sub-)terms. To order two objects A<B analogously is to try to make A less B by mutual binding variables and (sub-)terms. Unification and ordering is defined for known, semiknown, and unknown objects. Unification or ordering of an empty object is not defined (returns an undefined_exception).
Object identity (to contents)
The identity of a FunLog++ object is the list of  logic variables in its parameter positions.  If an object has no logic variable then it has no identity. An object with no identity is called ground. In FunLog++ all objects of competence level semiknown and unknown have an identity.  If a known object is ground (or not) depends on its parameters. Known numbers and texts are ground and so have no identity. A FunLog++ list is ground if all its elements are ground. A measure is ground, if all its parameters are ground.

Two ground objects A and B are identical if  A = B succeeds. Two unknown (variable) objects are identical if they are one and the same, e.g. if the message A=V, display(A)=display(B) succeeds for any value of V. Two parameterless objects are identical if they belong to the same class. Two arbitrary objects are identical if they belong to the same class and if all parameters are pairwise identical.

In order to test if an object A is ground or not we could define the following function:
    ground(A) ::=  identity(A) = [ ].

Semiknown objects (to contents)
Semiknown objects represent data, which are not precisely known but also not completely unknown.

A semiknown possibilistic object specifies a subset of at least two elements of some domain. Examples of possibilistic objects are unions, which may be implemented with semiknown generator function A\/B. Another semiknown possibilistic object is an interval A--B which states that all object X are possible where A<X and X<B. Another kind of a possibilistic object is a grammar which defines a subset of (syntactically correct) sequences, e.g. texts, (not yet implemented).

A semiknown probabilistic object specifies a probability density function over some domain. Examples are probability distributions for qualitative domains where the probability may be attached element by element, e.g. gastroenteritis @ 60% \/ appendicitis @ 40%. For quantitative domains Gauss normal distribution is available, e.g. gauss returns a semiknown number with mean 0 and variance 1. To obtain a distribution with mean A and variance B we have to write A+(sqrt(B)*gauss). In the future distribution with upto four moments (mean, variance, skewness, and kurtosis) are planned to be implemented.

A semiknown number or measure may be represented as union, interval, or Gauss distribution where the elements, bounds, mean and variance are numbers or measures. A semiknown text is a union, interval, or (in future) grammar where the elements and bounds are texts. Unions may be constructed of any type. An interval A--B requires at least the order relation A<B to be satisfied.

Exception handling (to contents)
An exception is a usual object with the property that most functions return the exception X if X was delivered by one of its parameters. The only functions that do not pass exceptions directly as a result are catch(KIND,TERM,VALUE). An exception has two parameters KIND and ORIGIN. KIND is a text to classify the exception. ORIGIN is an object holding class and method where the exception was thrown. Sometimes we want to define that a specific object if a given data type. In this case the ?/1 function is useful which checks if there is a function defined for message A. It fails if there is no acceptable function for message A or if A fails. See function number(SELF,X) ::= X=A. which can be defined in the following class
    number(A) ::= {
        number(SELF,X) ::= X=A. 
        min(SELF,PAR2) ::= number(PAR2,B)? | A<=B, A \/ A>B, B. 
        max(SELF,PAR2) ::= number(PAR2,B)? | A<=B, B \/ A>B, A. 
    }.
As method number/2 is only defined for the number object a message like number("Boston",V) would return an undefined_exception. Therefore we need the ?/1 function to convert the undefined_exception into a failure object.

There are some exceptions which are predefined in the FunLog++ runtime system. The TopMessage is the message which started FunLog++ interpreter execution (e.g. root("lipid.fun"):result.). The TopMessage usually comes from within a command line, from within an icon or from an external program.
 
Exception
Meaning
function undefined
  <Context> <Message>
There is no suitable function defined in the given context for the given message. Please try to modify the message or insert an appropriate function definition.
top message undefined
  <Message>
In the top message which is (mostly) of type root(A):B one of its submessages in A or B are not suitably defined in the FunLog++ system.
top message failed
  <Message>
The top message failed. In contrast to other contexts, top messages must not fail in FunLog++.
receiver undefined
  <Context> <Message>
In a message like Receiver:Term the receiver message is nowhere defined in the current context.
receiver failed
  <Context> <Message>
In a message like Receiver:Term the receiver message returned a failure object. In contrast to other contexts a receiver message must not fail in FunLog++.
receiver unknown
  <Context> <Message>
In a message like Receiver:Term the receiver message returned an unknown object. In contrast to other contexts a receiver message must not be unknown in FunLog++.
compiletime error 
  <Location> <ErrorKind>
There was a compilertime error which was ignored. Now during runtime it was tried to execute the erroneous function. Please correct your FunLog++ program according to the compiletime error message.
runtime error
  <ErrorKind> 
There is an error in the FunLog++ runtime system. Please tell this error to the FunLog++ system developers.
predefined exceptions

If an exception occurs and it is not handled within the FunLog++ program by =/1 or catch/3 then it will be passed to the runtime system which causes an appropriate error message.
 


Libraries and subprograms (to contents)
An application implemented using FunLog++ is defined in one or more source files. There is one source file which represents the application, the FunLog++ main program. If the main program wants to send a single message to the root class of another source file then this other subprogram has to be made accessible by static or dynamic loading.

Static loading: Function load(Library) loads a compiled library into the FunLog++ heap space where Library is the file name of the library's source file.  The file extension then has to be ".FUN" or must be omitted (where then ".FUN" is assumed). Function ::/1 gives access to the libraries public root level functions.

In this example we assuem that in the root object of source file "database.fun" there is a public function sql/0. Then the message ::sql:connect(A) send connect/1 to the resulting object of this function.

Dynamic loading: Function root(SubProgram) dynamically creates and loads a program object where SubProgram is the file name of the subprograms FunLog++ source file. The file extension then has to be ".FUN" or must be omitted (where then ".FUN" is assumed).

In this example we assume that there is a different FunLog++ source file, called "vrml_tools.fun". In the root class of "vrml_tools.fun" there should be defined a function draw_diagram(X,Y) which calculates the wanted VRML text.



Locations of external data resources (to contents)
Database tables in FunLog++ are usually stored in SQL databases using the ODBC and/or the JDBC interface. There is one function sqltable(DataSource,TableId) to return one specific table from the accessible world of databases. This table then will define a function record(KEY) in order to select one record and to return it as another object. This record object finally provides a function field(FieldName) to return the wanted location object. In the given example "jdbc:odbc:lis" is the datasource which is given as a database URL. Database URLs are strings with the following structure: <protocolname>:<subprotocol>:<subname> (see JDBC documentation). The table is a FunLog++ specific object which serves as a link descriptor to the wanted SQL database table "patients". The Key is some unique identifier for the requested patient, say "JM550824-1". If the Key is not unique for some reason than the result of record(Key) is semiknown. Finally "BirthDate" is the field identifier of the patient's birthdate.



Access to external data resources (database records and text files) (to contents)
FunLog++ programs may be used to read from and to write to external data resources. The structure of the external data resources, the data model, is represented as a collection of user defined functions which support calculation of so called location objects. A location is a descriptor which, in conjunction with a selector, carries all information necessary to read from or to write to external data resources. As an example a specific database record or a text file name are represented by location objects. Function get/3 is used to read and function put/3 is used to write to external data resources. Read access is performed immediately during inference. A write access directive is a special object which contains location and value of the intended write operation. Each function that defines a write access has to return a list of write access directives as its result. The selector for the content of text files usually is "". Regard the list of put directives at the end of the function result/3. Assume that function result/3 defined above occurs in some FunLog++ program source file mykb.fun then the command
     fun root("mykb.fun"):result(1234,"28.Feb 1997","<HTML> ... </HTML>").
will write into SQL database jdbc:odbc:lis record 1234 field "BirthDate" the text "28.Feb 1997" and it will write the text "<HTML> ... </HTML>" into file /temp/output.html on computer //promdsvr.
 
FunLog++ - introduction - glossary - language - library - special - semiknown - dynamic
Last modification: B. Pohl 15. September 1997 / 27.August 2000 / 18.Oktober 2000