No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
These functions must currently be written in Prolog (in principle C, Java, Tcl or even other languages can be used via the SICStus Prolog external function interfaces). | These functions must currently be written in Prolog (in principle C, Java, Tcl or even other languages can be used via the SICStus Prolog external function interfaces). | ||
These functions can be used to write <em>expression</em>, <em>predicates</em>, or <em>substitutions</em>. | These functions can be used to write <em>expression</em>, <em>predicates</em>, or <em>substitutions</em>. | ||
The general mechanism that is used is to mark certain DEFINITIONS as external, in which case ProB will make use of external Prolog code rather than using the right-hand-side of the DEFINITION whenever it is used. However, these DEFINITIONS can often (unless they are polymorphic) be wrapped into B (constant) functions. If you just want to use the standard external functions already defined by ProB, then you don't have to understand this mechanism in detail (or at all). | |||
== Standard Libraries provided by ProB == | |||
In a first instance we have predefined a series of external functions and grouped them in various library machines and definition files: | |||
* <tt>LibraryMath.mch</tt>: defining sin, cos, tan, sinx, cosx, tanx, logx, gcd, msb, random as well as access to all other Prolog built-in arithmetic functions. | |||
* <tt>LibraryStrings.mch</tt>: functions manipulating B STRING objects by providing <tt>length</tt>, <tt>append</tt>, <tt>split</tt> and conversion functions <tt>chars</tt>, <tt>codes</tt>. | |||
* <tt>LibraryFiles.mch</tt>: various functions to obtain information about files and directories in the underlying file system | |||
* <tt>LibraryIO.def</tt> providing functions to write information to screen or file | |||
* <tt>CHOOSE.def</tt> providing the Hilbert operator for choosing a designated element from each set | |||
== Overview of the External Function DEFINITION mechanism == | |||
Currently, these external functions are linked to classical B machines using DEFINITIONS as follows: | Currently, these external functions are linked to classical B machines using DEFINITIONS as follows: | ||
Line 12: | Line 23: | ||
Usually, it is also a good idea to encapsulate the external function inside a CONSTANT which is defined as a lambda abstraction with as body simply the call to the first DEFINITION. For <tt>COS</tt> this would be <tt>cos = %x.(x:NATURAL|COS(x))</tt>. Observe that for Atelier-B this is a tautology. | Usually, it is also a good idea to encapsulate the external function inside a CONSTANT which is defined as a lambda abstraction with as body simply the call to the first DEFINITION. For <tt>COS</tt> this would be <tt>cos = %x.(x:NATURAL|COS(x))</tt>. Observe that for Atelier-B this is a tautology. | ||
For ProB, the use of such a constant allows one to have a real B function representing the external function, for which we can compute the domain, range, etc. | For ProB, the use of such a constant allows one to have a real B function representing the external function, for which we can compute the domain, range, etc. | ||
As of version 1.3.5-beta7 ProB can make use of externally defined functions.
These functions must currently be written in Prolog (in principle C, Java, Tcl or even other languages can be used via the SICStus Prolog external function interfaces).
These functions can be used to write expression, predicates, or substitutions.
The general mechanism that is used is to mark certain DEFINITIONS as external, in which case ProB will make use of external Prolog code rather than using the right-hand-side of the DEFINITION whenever it is used. However, these DEFINITIONS can often (unless they are polymorphic) be wrapped into B (constant) functions. If you just want to use the standard external functions already defined by ProB, then you don't have to understand this mechanism in detail (or at all).
In a first instance we have predefined a series of external functions and grouped them in various library machines and definition files:
Currently, these external functions are linked to classical B machines using DEFINITIONS as follows:
Usually, it is also a good idea to encapsulate the external function inside a CONSTANT which is defined as a lambda abstraction with as body simply the call to the first DEFINITION. For COS this would be cos = %x.(x:NATURAL|COS(x)). Observe that for Atelier-B this is a tautology. For ProB, the use of such a constant allows one to have a real B function representing the external function, for which we can compute the domain, range, etc.