## Name:

function keyword for declaring a procedure-based function or a keyword representing a function type

## Library names:

sollya_obj_t sollya_lib_procedurefunction(sollya_obj_t, sollya_obj_t) sollya_obj_t sollya_lib_build_function_procedurefunction(sollya_obj_t,                                                          sollya_obj_t) SOLLYA_EXTERNALPROC_TYPE_FUNCTION

## Usage:

function(procedure) : procedure -> function function : type type

## Parameters:

• procedure is a procedure of type (range, integer, integer) -> range

## Description:

• For the sake of safety and mathematical consistency, Sollya distinguishes clearly between functions, seen in the mathematical sense of the term, i.e. mappings, and procedures, seen in the sense Computer Science gives to functions, i.e. pieces of code that compute results for arguments following an algorithm. In some cases however, it is interesting to use such Computer Science procedures as realisations of mathematical functions, e.g. in order to plot them or even to perform polynomial approximation on them. The function keyword allows for such a transformation of a Sollya procedure into a Sollya function.
• The procedure to be used as a function through function(procedure) must be of type (range, integer, integer) -> range. This means it must take in argument an interval X, a degree of differentiation n and a working precision p. It must return in result an interval Y encompassing the image f^(n)(X) of the n-th derivative of the implemented function f, i.e. f^(n)(X) c Y. In order to allow Sollya's algorithms to work properly, the procedure must ensure that, whenever (p, diam(X)) tends to (infinity, 0), the computed over-estimated bounding Y tends to the actual image f^(n)(X).
• The user must be aware that they are responsible of the correctness of the procedure. If, for some n and X, procedure returns an interval Y such that f^n(X) is not included in Y, function will successfully return a function without any complain, but this function might behave inconsistently in further computations.
• For cases when the procedure does not have the correct signature or does not return a finite interval as a result function(procedure) evaluates to Not-A-Number (resp. to an interval of Not-A-Numbers for interval evaluation).
• function also represents the function type for declarations of external procedures by means of externalproc.

Remark that in contrast to other indicators, type indicators like function cannot be handled outside the externalproc context. In particular, they cannot be assigned to variables.

## Example 1:

> procedure EXP(X,n,p) {
var res, oldPrec;
oldPrec = prec;
prec = p!;

res = exp(X);

prec = oldPrec!;
return res;
};
> f = function(EXP);
> f(1);
2.7182818284590452353602874713526624977572470937
> exp(1);
2.7182818284590452353602874713526624977572470937
> f(x + 3);
(function(proc(X, n, p)
{
var res, oldPrec;
oldPrec = prec;
prec = p!;
res = exp(X);
prec = oldPrec!;
return res;
}))(3 + x)
> diff(f);
diff(function(proc(X, n, p)
{
var res, oldPrec;
oldPrec = prec;
prec = p!;
res = exp(X);
prec = oldPrec!;
return res;
}))
> (diff(f))(0);
1
> g = f(sin(x));
> g(17);
0.38235816999386683402690554641655641359573458342088
> diff(g);
(diff(function(proc(X, n, p)
{
var res, oldPrec;
oldPrec = prec;
prec = p!;
res = exp(X);
prec = oldPrec!;
return res;
})))(sin(x)) * cos(x)
> (diff(g))(1);
1.25338076749344683697237458088447611474812675164344
> p = remez(f,3,[-1/2;1/2]);
> p;
0.99967120901420646830315493949039176881764871951833 + x * (0.99973702983571140134762682913614052309208076875596 + x * (0.510497293602826249216227216546435103583073053437 + x * 0.169814324607133287588897694747370380479108785868016))
Go back to the list of commands