Go back to the main page of Sollya
Commands available within Sollya
Help pages
Name:
abs
the absolute value.
Library names:
sollya_obj_t sollya_lib_abs(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_abs(sollya_obj_t)
#define SOLLYA_ABS(x) sollya_lib_build_function_abs(x)
Description:
- abs is the absolute value function. abs(x)=x if x>0 and -x otherwise.
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_absolute()
int sollya_lib_is_absolute(sollya_obj_t)
Example 1:
> bashexecute("gcc -fPIC -c externalplotexample.c");
> bashexecute("gcc -shared -o externalplotexample externalplotexample.o -lgmp -lmpfr");
> externalplot("./externalplotexample",absolute,exp(x),[-1/2;1/2],12,perturb);
Go back to the list of commands
Name:
accurateinfnorm
computes a faithful rounding of the infinity norm of a function
Usage:
accurateinfnorm(function,range,constant) : (function, range, constant) -> constant
accurateinfnorm(function,range,constant,exclusion range 1,...,exclusion range n) : (function, range, constant, range, ..., range) -> constant
Parameters:
- function represents the function whose infinity norm is to be computed
- range represents the infinity norm is to be considered on
- constant represents the number of bits in the significant of the result
- exclusion range 1 through exclusion range n represent ranges to be excluded
Description:
- The command accurateinfnorm computes an upper bound to the infinity norm of
function function in range. This upper bound is the least
floating-point number greater than the value of the infinity norm that
lies in the set of dyadic floating point numbers having constant
significant mantissa bits. This means the value accurateinfnorm evaluates to
is at the time an upper bound and a faithful rounding to constant
bits of the infinity norm of function function on range range.
If given, the fourth and further arguments of the command accurateinfnorm,
exclusion range 1 through exclusion range n the infinity norm of
the function function is not to be considered on.
- The command accurateinfnorm is now considered DEPRECATED in Sollya.
Users should be aware about the fact that the algorithm behind
accurateinfnorm is highly inefficient and that other, better suited
algorithms, such as supnorm, are available inside Sollya. As a
matter of fact, while accurateinfnorm is maintained for compatibility reasons
with legacy Sollya codes, users are advised to avoid using accurateinfnorm
in new Sollya scripts and to replace it, where possible, by the
supnorm command.
Example 1:
> p = remez(exp(x), 5, [-1;1]);
> accurateinfnorm(p - exp(x), [-1;1], 20);
4.52055246569216251373291015625e-5
> accurateinfnorm(p - exp(x), [-1;1], 30);
4.5205513970358879305422306060791015625e-5
> accurateinfnorm(p - exp(x), [-1;1], 40);
4.520551396713923253400935209356248378753662109375e-5
Example 2:
> p = remez(exp(x), 5, [-1;1]);
> midpointmode = on!;
> infnorm(p - exp(x), [-1;1]);
0.45205~5/7~e-4
> accurateinfnorm(p - exp(x), [-1;1], 40);
4.520551396713923253400935209356248378753662109375e-5
Go back to the list of commands
Name:
acos
the arccosine function.
Library names:
sollya_obj_t sollya_lib_acos(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_acos(sollya_obj_t)
#define SOLLYA_ACOS(x) sollya_lib_build_function_acos(x)
Description:
- acos is the inverse of the function cos: acos(y) is the unique number
x in [0; Pi] such that cos(x)=y.
- It is defined only for y in [-1; 1].
Go back to the list of commands
Name:
acosh
the arg-hyperbolic cosine function.
Library names:
sollya_obj_t sollya_lib_acosh(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_acosh(sollya_obj_t)
#define SOLLYA_ACOSH(x) sollya_lib_build_function_acosh(x)
Description:
- acosh is the inverse of the function cosh: acosh(y) is the unique number
x in [0; +Inf] such that cosh(x)=y.
- It is defined only for y in [0; +Inf].
Go back to the list of commands
Name:
&&
boolean AND operator
Library name:
sollya_obj_t sollya_lib_and(sollya_obj_t, sollya_obj_t)
Usage:
expr1 && expr2 : (boolean, boolean) -> boolean
Parameters:
- expr1 and expr2 represent boolean expressions
Description:
- && evaluates to the boolean AND of the two
boolean expressions expr1 and expr2. && evaluates to
true iff both expr1 and expr2 evaluate to true.
Example 1:
> true && false;
false
Example 2:
> (1 == exp(0)) && (0 == log(1));
true
Go back to the list of commands
Name:
annotatefunction
Annotates a Sollya function object with an approximation that is faster to evaluate
Library names:
sollya_obj_t sollya_lib_annotatefunction(sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t, ...);
sollya_obj_t sollya_lib_v_annotatefunction(sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t,
va_list);
Usage:
annotatefunction(f, g, I, d) : (function, function, range, range) -> function
annotatefunction(f, g, I, d, x0) : (function, function, range, range, constant) -> function
Parameters:
- f is a function.
- g is a function, in most cases a polynomial.
- I is an interval.
- d is an interval.
- x0 is a constant (default value is 0 when not provided).
Description:
- When a given function f is to be evaluated at several points of a given
interval I to a given precision, it might be useful to precompute a good
approximant g of f and further evaluate it instead of f when the
approximation is good enough to provide the desire precision. If f is a
complicated expression, whereas g is, e.g., a polynomial of low degree,
the cost of precomputing g can be well compensated by the gain of time in
each subsequent evaluation. The purpose of annotatefunction is to provide
such a mechanism to the user.
- When using annotatefunction(f, g, I, d, x0),
resp. annotatefunction(f, g, I, d) (where x0 is assumed to be
zero), it is assumed that
forall x in I, f(x) - g(x - x0) in d.
It is the user responsibility to ensure this property. Otherwise, any
subsequent use of f on points of I might lead to incorrect values.
- A call to annotatefunction(f, g, I, d, x0) annotates the given
Sollya function object f with the approximation g. In further use, when
asked to evaluate f on a point x of I, Sollya will first evaluate g
on x-x0 and check if the result is accurate enough in the given context
(accounting for the fact that the error of approximation between the true
value and g(x-x0) belongs to d). If not (and only in this case), an
evaluation of the expression of f on x is performed.
- The approximation g can be any Sollya function but particular
performance is expected when g is a polynomial. Upon annotation with a
polynomial, precomputations are performed to analyze certain properties of
the given approximation polynomial.
- annotatefunction updates the internal representation of f so as to
persistently keep this information attached with the Sollya object
representing f. In particular, the annotation is persistent through copy
or use of f as a subexpression to build up bigger expressions. Notice
however, that there is no way of deducing an annotation for the derivative
of f from an annotation of f. So, in general, it should not be expected
that diff(f) will be automatically annotated (notice, however that f
might be a subexpression of its derivative, e.g., for f=exp or f=tan, in
which case the corresponding subexpressions of the derivative could inherit
the annotations from f. It is currently not specified whether Sollya does
this automatically or not).
- annotatefunction really is an imperative statement that modifies the
internal representation of f. However, for convenience annotatefunction
returns f itself.
- Sollya function objects can be annotated more than once with different
approximations on different domains, that do not need to be disjoint. Upon
evaluation of the annotated function object, Sollya chooses an
approximation annotation (if any) that provides for sufficient accuracy at
the evaluation point. It is not specified in which order Sollya tries
different possible annotations when several are available for a given
point x.
Example 1:
> verbosity=1!;
> procedure EXP(X,n,p) {
var res, oldPrec;
oldPrec = prec;
prec = p!;
"Using procedure function exponential with X=" @ X @ ", n=" @ n @ ", and p=" @ p;
res = exp(X);
prec = oldPrec!;
return res;
};
> g = function(EXP);
> p = 46768052394588893382516870161332864698044514954899b-165 + x * (23384026197294446691258465802074096632225783601255b-164 + x * (5846006549323611672948426613035653821819225877423b-163 + x * (3897337699549074448627696490806815137319821946501b-164 + x * (7794675399098148717422744621371434831048848817417b-167 + x * (24942961277114075921122941174178849425809856036737b-171 + x * (8314320425704876115613838900105097456456371179471b-172 + x * (19004160973039701371579356991645932289422670402995b-176 + x * (19004160972669324148912122254449912156003926801563b-179 + x * (33785175062542597526738679493857229456702396042255b-183 + x * (6757035113643674378393625988264926886191860669891b-184 + x * (9828414707511252769908089206114262766633532289937b-188 + x * (26208861108003813314724515233584738706961162212965b-193 + x * (32257064253325954315953742396999456577223350602741b-197 + x * (578429089657689569703509185903214676926704485495b-195 + x * 2467888542176675658523627105540996778984959471957b-201))))))))))))));
> h = annotatefunction(g, p, [-1/2;1/2], [-475294848522543b-124;475294848522543b-124]);
> h == g;
true
> prec = 24;
The precision has been set to 24 bits.
> h(0.25);
Warning: rounding has happened. The value displayed is a faithful rounding to 24 bits of the true result.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
1.2840254
> prec = 165;
The precision has been set to 165 bits.
> h(0.25);
Using procedure function exponential with X=[0.25;0.25], n=0, and p=185
Warning: rounding has happened. The value displayed is a faithful rounding to 165 bits of the true result.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
1.28402541668774148407342056806243645833628086528147
Go back to the list of commands
Name:
:.
add an element at the end of a list.
Library name:
sollya_obj_t sollya_lib_append(sollya_obj_t, sollya_obj_t)
Usage:
L:.x : (list, any type) -> list
Parameters:
- L is a list (possibly empty).
- x is an object of any type.
Description:
- :. adds the element x at the end of the list L.
- Note that since x may be of any type, it can in particular be a list.
Example 1:
> [|2,3,4|]:.5;
[|2, 3, 4, 5|]
Example 2:
> [|1,2,3|]:.[|4,5,6|];
[|1, 2, 3, [|4, 5, 6|]|]
Example 3:
> [||]:.1;
[|1|]
Go back to the list of commands
Name:
~
floating-point evaluation of a constant expression
Library name:
sollya_obj_t sollya_lib_approx(sollya_obj_t)
Usage:
~ expression : function -> constant
~ something : any type -> any type
Parameters:
- expression stands for an expression that is a constant
- something stands for some language element that is not a constant expression
Description:
- ~ expression evaluates the expression that is a constant
term to a floating-point constant. The evaluation may involve a
rounding. If expression is not a constant, the evaluated constant is
a faithful rounding of expression with precision bits, unless the
expression is exactly 0 as a result of cancellation. In the
latter case, a floating-point approximation of some (unknown) accuracy
is returned.
- ~ does not do anything on all language elements that are not a
constant expression. In other words, it behaves like the identity
function on any type that is not a constant expression. It can hence
be used in any place where one wants to be sure that expressions are
simplified using floating-point computations to constants of a known
precision, regardless of the type of actual language elements.
- ~ error evaluates to error and provokes a warning.
- ~ is a prefix operator not requiring parentheses. Its
precedence is the same as for the unary + and -
operators. It cannot be repeatedly used without brackets.
Example 1:
> print(exp(5));
exp(5)
> print(~ exp(5));
148.41315910257660342111558004055227962348766759388
Example 2:
> autosimplify = off!;
Example 3:
> print(~sin(5 * pi));
0
Example 4:
> print(~exp(x));
exp(x)
> print(~ "Hello");
Hello
Example 5:
> print(~exp(x*5*Pi));
exp((pi) * 5 * x)
> print(exp(x* ~(5*Pi)));
exp(x * 15.7079632679489661923132169163975144209858469968757)
Example 6:
> print(~exp(5)*x);
148.41315910257660342111558004055227962348766759388 * x
> print( (~exp(5))*x);
148.41315910257660342111558004055227962348766759388 * x
> print(~(exp(5)*x));
exp(5) * x
Go back to the list of commands
Name:
asciiplot
plots a function in a range using ASCII characters
Library name:
void sollya_lib_asciiplot(sollya_obj_t, sollya_obj_t)
Usage:
asciiplot(function, range) : (function, range) -> void
Parameters:
- function represents a function to be plotted
- range represents a range the function is to be plotted in
Description:
- asciiplot plots the function function in range range using ASCII
characters. On systems that provide the necessary
TIOCGWINSZ ioctl, Sollya determines the size of the
terminal for the plot size if connected to a terminal. If it is not
connected to a terminal or if the test is not possible, the plot is of
fixed size 77x25 characters. The function is
evaluated on a number of points equal to the number of columns
available. Its value is rounded to the next integer in the range of
lines available. A letter "x" is written at this place. If zero is in
the hull of the image domain of the function, an x-axis is
displayed. If zero is in range, a y-axis is displayed. If the
function is constant or if the range is reduced to one point, the
function is evaluated to a constant and the constant is displayed
instead of a plot.
Example 1:
> asciiplot(exp(x),[1;2]);
xx
xx
xx
xx
xx
xxx
xx
xxx
xx
xxx
xxx
xxx
xxx
xxx
xxxx
xxx
xxxx
xxxx
xxxx
xxxx
xxxxx
xxxxx
xxxxx
xxx
Example 2:
> asciiplot(expm1(x),[-1;2]);
| x
| x
| x
| x
| xx
| x
| x
| xx
| x
| xx
| xx
| xx
| xx
| xx
| xx
| xxx
| xxx
| xxxx
| xxxx
| xxxx
| xxxxxx
---------------------xxxxxxxx-----------------------------------------------
xxxxxxxxxxxx |
xxxxxxxxx |
Example 3:
> asciiplot(5,[-1;1]);
5
Example 4:
> asciiplot(exp(x),[1;1]);
2.7182818284590452353602874713526624977572470937
Go back to the list of commands
Name:
asin
the arcsine function.
Library names:
sollya_obj_t sollya_lib_asin(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_asin(sollya_obj_t)
#define SOLLYA_ASIN(x) sollya_lib_build_function_asin(x)
Description:
- asin is the inverse of the function sin: asin(y) is the unique number
x in [-Pi/2; Pi/2] such that sin(x)=y.
- It is defined only for y in [-1; 1].
Go back to the list of commands
Name:
asinh
the arg-hyperbolic sine function.
Library names:
sollya_obj_t sollya_lib_asinh(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_asinh(sollya_obj_t)
#define SOLLYA_ASINH(x) sollya_lib_build_function_asinh(x)
Description:
- asinh is the inverse of the function sinh: asinh(y) is the unique number
x in [-Inf; +Inf] such that sinh(x)=y.
- It is defined for every real number y.
Go back to the list of commands
Name:
atan
the arctangent function.
Library names:
sollya_obj_t sollya_lib_atan(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_atan(sollya_obj_t)
#define SOLLYA_ATAN(x) sollya_lib_build_function_atan(x)
Description:
- atan is the inverse of the function tan: atan(y) is the unique number
x in [-Pi/2; Pi/2] such that tan(x)=y.
- It is defined for every real number y.
Go back to the list of commands
Name:
atanh
the hyperbolic arctangent function.
Library names:
sollya_obj_t sollya_lib_atanh(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_atanh(sollya_obj_t)
#define SOLLYA_ATANH(x) sollya_lib_build_function_atanh(x)
Description:
- atanh is the inverse of the function tanh: atanh(y) is the unique number
x in [-Inf; +Inf] such that tanh(x)=y.
- It is defined only for y in [-1; 1].
Go back to the list of commands
Name:
autodiff
Computes the first n derivatives of a function at a point or over an interval.
Library name:
sollya_obj_t sollya_lib_autodiff(sollya_obj_t, sollya_obj_t, sollya_obj_t)
Usage:
autodiff(f, n, x0) : (function, integer, constant) -> list
autodiff(f, n, I) : (function, integer, range) -> list
Parameters:
- f is the function to be differentiated.
- n is the order of differentiation.
- x0 is the point at which the function is differentiated.
- I is the interval over which the function is differentiated.
Description:
- autodiff computes the first n derivatives of f at point x0. The computation
is performed numerically, without symbolically differentiating the expression
of f. Yet, the computation is safe since small interval enclosures are
produced. More precisely, autodiff returns a list [f_0, ..., f_n] such that,
for each i, f_i is a small interval enclosing the exact value of f^(i)(x0).
- Since it does not perform any symbolic differentiation, autodiff is much
more efficient than diff and should be preferred when only numerical values
are necessary.
- If an interval I is provided instead of a point x0, the list returned by
autodiff satisfies: for each i, f^(i)(I) is included in f_i. A particular use
is when one wants to know the successive derivatives of a function at a non
representable point such as pi. In this case, it suffices to call autodiff
with the (almost) point interval I = [pi].
- When I is almost a point interval, the returned enclosures f_i are also
almost point intervals. However, when the interval I begins to be fairly
large, the enclosures can be deeply overestimated due to the dependency
phenomenon present with interval arithmetic.
- As a particular case, f_0 is an enclosure of the image of f over I.
However, since the algorithm is not specially designed for this purpose it is
not very efficient for this particular task. In particular, it is not able to
return a finite enclosure for functions with removable singularities
(e.g. sin(x)/x at 0). The command evaluate is much more efficient for
computing an accurate enclosure of the image of a function over an interval.
Example 1:
> L = autodiff(exp(cos(x))+sin(exp(x)), 5, 0);
> midpointmode = on!;
> for f_i in L do f_i;
0.3559752813266941742012789792982961497379810154498~2/4~e1
0.5403023058681397174009366074429766037323104206179~0/3~
-0.3019450507398802024611853185539984893647499733880~6/2~e1
-0.252441295442368951995750696489089699886768918239~6/4~e1
0.31227898756481033145214529184139729746320579069~1/3~e1
-0.16634307959006696033484053579339956883955954978~3/1~e2
Example 2:
> f = log(cos(x)+x);
> L = autodiff(log(cos(x)+x), 5, [2,4]);
> L[0];
[0;1.27643852425465597132446653114905059102580436018893]
> evaluate(f, [2,4]);
[0.45986058925497069206106494332976097408234056912429;1.20787210589964169595901037621103012113048821362855]
> fprime = diff(f);
> L[1];
[2.53086745013099407167484456656211083053393118778677e-2;1.7568024953079282513726390945118290941359128873365]
> evaluate(fprime,[2,4]);
[2.71048755415961996452136364304380881763456815673085e-2;1.1091953066394329083739722578862353140555843127995]
Example 3:
> L = autodiff(sin(x)/x, 0, [-1,1]);
> L[0];
[NaN;NaN]
> evaluate(sin(x)/x, [-1,1]);
[0.5403023058681397174009366074429766037323104206179;1]
Go back to the list of commands
Name:
autosimplify
activates, deactivates or inspects the value of the automatic simplification state variable
Library names:
void sollya_lib_set_autosimplify_and_print(sollya_obj_t)
void sollya_lib_set_autosimplify(sollya_obj_t)
sollya_obj_t sollya_lib_get_autosimplify()
Parameters:
- activation value represents on or off, i.e. activation or deactivation
Description:
- An assignment autosimplify = activation value, where activation value
is one of on or off, activates respectively deactivates the
automatic safe simplification of expressions of functions generated by
the evaluation of commands or in argument of other commands.
Sollya commands like remez, taylor or rationalapprox sometimes
produce expressions that can be simplified. Constant subexpressions
can be evaluated to dyadic floating-point numbers, monomials with
coefficients 0 can be eliminated. Further, expressions
indicated by the user perform better in many commands when simplified
before being passed in argument to a command. When the automatic
simplification of expressions is activated, Sollya automatically
performs a safe (not value changing) simplification process on such
expressions.
The automatic generation of subexpressions can be annoying, in
particular if it takes too much time for not enough benefit. Further the
user might want to inspect the structure of the expression tree
returned by a command. In this case, the automatic simplification
should be deactivated.
If the assignment autosimplify = activation value is followed by an
exclamation mark, no message indicating the new state is
displayed. Otherwise the user is informed of the new state of the
global mode by an indication.
Example 1:
> autosimplify = on !;
> print(x - x);
0
> autosimplify = off ;
Automatic pure tree simplification has been deactivated.
> print(x - x);
x - x
Example 2:
> autosimplify = on !;
> print(rationalapprox(sin(pi/5.9),7));
33 / 65
> autosimplify = off !;
> print(rationalapprox(sin(pi/5.9),7));
33 / 65
See also: print,
==,
!=,
prec,
points,
diam,
display,
verbosity,
canonical,
taylorrecursions,
timing,
fullparentheses,
midpointmode,
hopitalrecursions,
remez,
rationalapprox,
taylor
Go back to the list of commands
Name:
bashevaluate
executes a shell command and returns its output as a string
Library names:
sollya_obj_t sollya_lib_bashevaluate(sollya_obj_t, ...)
sollya_obj_t sollya_lib_v_bashevaluate(sollya_obj_t, va_list)
Parameters:
- command is a command to be interpreted by the shell.
- input is an optional character sequence to be fed to the command.
Description:
- bashevaluate(command) will execute the shell command command in a shell.
All output on the command's standard output is collected and returned
as a character sequence.
- If an additional argument input is given in a call to
bashevaluate(command,input), this character sequence is written to the
standard input of the command command that gets executed.
- All characters output by command are included in the character
sequence to which bashevaluate evaluates but two exceptions. Every NULL
character ('\0') in the output is replaced with
'?' as Sollya is unable to handle character sequences containing that
character. Additionally, if the output ends in a newline character
('\n'), this character is stripped off. Other
newline characters which are not at the end of the output are left as
such.
Example 1:
> bashevaluate("LANG=C date");
Mon Feb 21 12:19:52 CET 2022
Example 2:
> [| bashevaluate("echo Hello") |];
[|"Hello"|]
Example 3:
> a = bashevaluate("sed -e 's/a/e/g;'", "Hallo");
> a;
Hello
Go back to the list of commands
Library name:
void sollya_lib_bashexecute(sollya_obj_t)
Parameters:
- command is a command to be interpreted by the shell.
Description:
- bashexecute(command) lets the shell interpret command. It is useful to execute
some external code within Sollya.
- bashexecute does not return anything. It just executes its argument. However, if
command produces an output in a file, this result can be imported in Sollya
with help of commands like execute, readfile and parse.
Example 1:
> bashexecute("LANG=C date");
Mon Feb 21 12:20:03 CET 2022
Go back to the list of commands
Name:
bezout
Computes the gcd as well as the co-factors (Bezout coefficients)
Library name:
sollya_obj_t sollya_lib_bezout(sollya_obj_t, sollya_obj_t)
Usage:
bezout(p, q) : (function, function) -> structure
Parameters:
- p is a constant or a polynomial.
- q is a constant or a polynomial.
Description:
- When both p and q are integers, bezout(p,q) computes the greatest
common divisor g of these two integers, i.e., the greatest non-negative
integer g dividing both p and q, as well as co-factors (Bezout
coefficients), i.e., a and b such that a * p + b * q = g.
- bezout always returns a structure containing four elements, g, r, a and b.
These four elements always satisfy the following two properties:
gcd(g,r) = gcd(p,q) and a * p + b * q = g. In addition, the tool tries to
ensure r = 0. This latter property cannot always be ensured, in particular,
it cannot be ensured for constant expression such that r becomes zero but
the tool is unable to prove this fact. bezout ensures that g is the greatest
common divisor of p and q only if r ends up being zero.
- When both p and q are rational numbers, say s/t and u/v,
bezout(p,q) computes the greatest common divisor of s * v and u * t,
divided by the product of the denominators, t * v, as well as co-factors,
still satisfying a * p + b * q = g.
- When both p and q are constants but at least one of them is no rational
number, bezout does not run the extended Euclidian algorithm to reduce
gcd(p,q), i.e., the two elements g, r of the returned structure contain
copies of the inputs p and q. The elements a and b are set to 0 and 1
accordingly. bezout differs from the gcd command in this point.
- When both p and q are polynomials with at least one being non-constant,
bezout(p,q) returns the polynomial of greatest degree dividing both p
and q, and whose leading coefficient is the greatest common divisor of the
leading coefficients of p and q. Polynomial co-factors (Bezout
coefficients), i.e., a and b such that a * p + b * q = g, are returned as
well.
- Similarly to the cases documented for div and mod, bezout may fail to
return the unique polynomial of largest degree dividing both p and q in
cases when certain coefficients of either p or q are constant expressions
for which the tool is unable to determine whether they are zero or not. These
cases typically involve polynomials whose leading coefficient is zero but the
tool is unable to detect this fact. In contrast to the gcd command, the
bezout command is completely safe in this respect, as it returns not only
an alleged greatest common divisor g but also the final remainder r obtained
in the extended Euclidian algorithm. The two properties gcd(g,r) = gcd(p,q)
and a * p + b * q = g are always satisfied for the four elements of the
returned structure.
- When at least one of p or q is a function that is no polynomial, bezout
does not run the extended Euclidian algorithm to reduce gcd(p,q), i.e., the
two elements g, r of the returned structure contain copies of the inputs p
and q. The elements a and b are set to 0 and 1 accordingly. bezout differs
from the gcd command in this point.
Example 1:
> bezout(1001, 231);
{ .b = -4, .a = 1, .r = 0, .g = 77 }
> bezout(13, 17);
{ .b = -3, .a = 4, .r = 0, .g = 1 }
> bezout(-210, 462);
{ .b = 1, .a = 2, .r = 0, .g = 42 }
Example 2:
> rationalmode = on!;
> bezout(6/7, 33/13);
{ .b = -1, .a = 3, .r = 0, .g = 3 / 91 }
Example 3:
> bezout(exp(13),sin(17));
{ .b = 0, .a = 1, .r = -0.96139749187955685726163694486915609849206725405894, .g = 4.4241339200892050332610277594908828178439130606059e5 }
Example 4:
> bezout(24 + 68 * x + 74 * x^2 + 39 * x^3 + 10 * x^4 + x^5, 480 + 776 * x + 476 * x^2 + 138 * x^3 + 19 * x^4 + x^5);
{ .b = 9.1666666666666666666666666666666666666666666666665e-2 + x * (0.125 + x * 5e-2), .a = -1.6666666666666666666666666666666666666666666666667 + x * (-0.575 + x * (-5e-2)), .r = 0, .g = 4 + x * (4 + x) }
> bezout(1001 * x^2, 231 * x);
{ .b = 0.33333333333333333333333333333333333333333333333333, .a = 0, .r = 0, .g = x * 77 }
Example 5:
> bezout(exp(x), x^2);
{ .b = 0, .a = 1, .r = x^2, .g = exp(x) }
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_binary()
int sollya_lib_is_binary(sollya_obj_t)
Description:
- binary is a special value used for the global state display. If
the global state display is equal to binary, all data will be
output in binary notation.
As any value it can be affected to a variable and stored in lists.
Go back to the list of commands
Name:
bind
partially applies a procedure to an argument, returning a procedure with one argument less
Usage:
bind(proc, ident, obj) : (procedure, identifier type, any type) -> procedure
Parameters:
- proc is a procedure to be partially applied to an argument
- ident is one of the formal arguments of proc
- obj is any Sollya object ident is to be bound to
Description:
- bind allows a formal parameter ident of a procedure proc to
be bound to an object obj, hence proc to be partially applied.
The result of this curryfied application, returned by bind, is
a procedure with one argument less. This way, bind permits
specialization of a generic procedure, parameterized e.g. by a function
or range.
- In the case when proc does not have a formal parameter named
ident, bind prints a warning and returns the procedure
proc unmodified.
- bind always returns a procedure, even if proc only has one
argument, which gets bound to ident. In this case, bind
returns a procedure which does not take any argument. Hence
evaluation, which might provoke side effects, is only performed
once the procedure gets used.
- If bind is used on a procedure with an arbitrary number of
arguments, no check is performed whether the procedure actually
has a parameter of name ident. bind returns a procedure
with an arbitrary number of arguments whose argument has the
same name as the original procedure proc. That returned procedure
binds ident to obj and then runs proc within this context,
applying it to its original argument. The execution of bind
fails for procedures with an arbitrary number of arguments if
the original procedure's argument has the same name as ident.
In this case, the procedure is returned unmodified.
Example 1:
> procedure add(X,Y) { return X + Y; };
> succ = bind(add,X,1);
> succ(5);
6
> succ;
proc(Y)
{
nop;
return (proc(X, Y)
{
nop;
return (X) + (Y);
})(1, Y);
}
Example 2:
> procedure add(X,Y) { return X + Y; };
> succ = bind(add,X,1);
> five = bind(succ,Y,4);
> five();
5
> five;
proc()
{
nop;
return (proc(Y)
{
nop;
return (proc(X, Y)
{
nop;
return (X) + (Y);
})(1, Y);
})(4);
}
Example 3:
> verbosity = 1!;
> procedure add(X,Y) { return X + Y; };
> foo = bind(add,R,1);
Warning: the given procedure has no argument named "R". The procedure is returned unchanged.
> foo;
proc(X, Y)
{
nop;
return (X) + (Y);
}
Example 4:
> procedure sum_times(l=...) { var s, i; s = 0; for i in l do s = s + i; return c * s; };
> foo = bind(sum_times, c, 17);
> foo;
proc(l = ...)
{
var c;
c = 17;
return (proc(l = ...)
{
var s, i;
s = 0;
for i in l do
s = (s) + (i);
return (c) * (s);
}) @ (l);
}
> foo(1, 2, 3);
102
Go back to the list of commands
Name:
boolean
keyword representing a boolean type
Library name:
SOLLYA_EXTERNALPROC_TYPE_BOOLEAN
Description:
- boolean represents the boolean type for declarations
of external procedures by means of externalproc.
Remark that in contrast to other indicators, type indicators like
boolean cannot be handled outside the externalproc context. In
particular, they cannot be assigned to variables.
Go back to the list of commands
Name:
canonical
brings all polynomial subexpressions of an expression to canonical form or activates, deactivates or checks canonical form printing
Library names:
void sollya_lib_set_canonical_and_print(sollya_obj_t)
void sollya_lib_set_canonical(sollya_obj_t)
sollya_obj_t sollya_lib_canonical(sollya_obj_t)
sollya_obj_t sollya_lib_get_canonical()
Usage:
canonical(function) : function -> function
canonical = activation value : on|off -> void
canonical = activation value ! : on|off -> void
Parameters:
- function represents the expression to be rewritten in canonical form
- activation value represents on or off, i.e. activation or deactivation
Description:
- The command canonical rewrites the expression representing the function
function in a way such that all polynomial subexpressions (or the
whole expression itself, if it is a polynomial) are written in
canonical form, i.e. as a sum of monomials in the canonical base. The
canonical base is the base of the integer powers of the global free
variable. The command canonical does not endanger the safety of
computations even in Sollya's floating-point environment: the
function returned is mathematically equal to the function function.
- An assignment canonical = activation value, where activation value
is one of on or off, activates respectively deactivates the
automatic printing of polynomial expressions in canonical form,
i.e. as a sum of monomials in the canonical base. If automatic
printing in canonical form is deactivated, automatic printing yields to
displaying polynomial subexpressions in Horner form.
If the assignment canonical = activation value is followed by an
exclamation mark, no message indicating the new state is
displayed. Otherwise the user is informed of the new state of the
global mode by an indication.
Example 1:
> print(canonical(1 + x * (x + 3 * x^2)));
1 + x^2 + 3 * x^3
> print(canonical((x + 1)^7));
1 + 7 * x + 21 * x^2 + 35 * x^3 + 35 * x^4 + 21 * x^5 + 7 * x^6 + x^7
Example 2:
> print(canonical(exp((x + 1)^5) - log(asin(((x + 2) + x)^4 * (x + 1)) + x)));
exp(1 + 5 * x + 10 * x^2 + 10 * x^3 + 5 * x^4 + x^5) - log(asin(16 + 80 * x + 160 * x^2 + 160 * x^3 + 80 * x^4 + 16 * x^5) + x)
Example 3:
> canonical;
off
> (x + 2)^9;
512 + x * (2304 + x * (4608 + x * (5376 + x * (4032 + x * (2016 + x * (672 + x * (144 + x * (18 + x))))))))
> canonical = on;
Canonical automatic printing output has been activated.
> (x + 2)^9;
512 + 2304 * x + 4608 * x^2 + 5376 * x^3 + 4032 * x^4 + 2016 * x^5 + 672 * x^6 + 144 * x^7 + 18 * x^8 + x^9
> canonical;
on
> canonical = off!;
> (x + 2)^9;
512 + x * (2304 + x * (4608 + x * (5376 + x * (4032 + x * (2016 + x * (672 + x * (144 + x * (18 + x))))))))
Go back to the list of commands
Name:
ceil
the usual function ceil.
Library names:
sollya_obj_t sollya_lib_ceil(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_ceil(sollya_obj_t)
#define SOLLYA_CEIL(x) sollya_lib_build_function_ceil(x)
Description:
- ceil is defined as usual: ceil(x) is the smallest integer y such that y >= x.
- It is defined for every real number x.
Go back to the list of commands
Name:
checkinfnorm
checks whether the infinity norm of a function is bounded by a value
Library name:
sollya_obj_t sollya_lib_checkinfnorm(sollya_obj_t, sollya_obj_t,
sollya_obj_t)
Usage:
checkinfnorm(function,range,constant) : (function, range, constant) -> boolean
Parameters:
- function represents the function whose infinity norm is to be checked
- range represents the infinity norm is to be considered on
- constant represents the upper bound the infinity norm is to be checked to
Description:
- The command checkinfnorm checks whether the infinity norm of the given
function function in the range range can be proven (by Sollya) to
be less than the given bound bound. This means, if checkinfnorm
evaluates to true, the infinity norm has been proven (by Sollya's
interval arithmetic) to be less than the bound. If checkinfnorm evaluates
to false, there are two possibilities: either the bound is less than
or equal to the infinity norm of the function or the bound is greater
than the infinity norm but Sollya could not conclude using its
internal interval arithmetic.
checkinfnorm is sensitive to the global variable diam. The smaller diam,
the more time Sollya will spend on the evaluation of checkinfnorm in
order to prove the bound before returning false although the infinity
norm is bounded by the bound. If diam is equal to 0, Sollya will
eventually spend infinite time on instances where the given bound
bound is less or equal to the infinity norm of the function
function in range range. In contrast, with diam being zero,
checkinfnorm evaluates to true iff the infinity norm of the function in
the range is bounded by the given bound.
Example 1:
> checkinfnorm(sin(x),[0;1.75], 1);
true
> checkinfnorm(sin(x),[0;1.75], 1/2); checkinfnorm(sin(x),[0;20/39],1/2);
false
true
Example 2:
> p = remez(exp(x), 5, [-1;1]);
> b = dirtyinfnorm(p - exp(x), [-1;1]);
> checkinfnorm(p - exp(x), [-1;1], b);
false
> b1 = round(b, 15, RU);
> checkinfnorm(p - exp(x), [-1;1], b1);
true
> b2 = round(b, 25, RU);
> checkinfnorm(p - exp(x), [-1;1], b2);
false
> diam = 1b-20!;
> checkinfnorm(p - exp(x), [-1;1], b2);
true
Go back to the list of commands
Name:
coeff
gives the coefficient of degree n of a polynomial
Library name:
sollya_obj_t sollya_lib_coeff(sollya_obj_t, sollya_obj_t)
Usage:
coeff(f,n) : (function, integer) -> constant
Parameters:
- f is a function (usually a polynomial).
- n is an integer
Description:
- If f is a polynomial, coeff(f, n) returns the coefficient of
degree n in f.
- If f is a function that is not a polynomial, coeff(f, n) returns 0.
Example 1:
> coeff((1+x)^5,3);
10
Example 2:
> coeff(sin(x),0);
0
Go back to the list of commands
Name:
composepolynomials
computes an approximation to the composition of two polynomials and bounds the error
Library name:
sollya_obj_t sollya_lib_composepolynomials(sollya_obj_t, sollya_obj_t)
Description:
- Given two polynomials p and q, composepolynomials(p, q) computes an
approximation r to the polynomial (p o q) and bounds the
error polynomial r - (p o q) using interval arithmetic.
- composepolynomials always returns a structure containing two elements,
poly and radii. The element
poly is contains the approximate composed polynomial
r. The element radii contains a list of n + 1
intervals ai bounding the coefficients of the
error polynomial, which is of the same degree n as is the
composed polynomial (p o q). This is, there exist
alphai in ai such that
sum_i alphai * x^i = r(x) - (p o q)(x).
- In the case when either of p or q is not a polynomial, composepolynomials
behaves like substitute used in a literate structure. The list of intervals
bounding the coefficients of the error polynomial is returned empty.
Example 1:
> composepolynomials(1 + 2 * x + 3 * x^2 + 4 * x^3, 5 + 6 * x + 7 * x^2);
{ .radii = [|[0;0], [0;0], [0;0], [0;0], [0;0], [0;0], [0;0]|], .poly = 586 + x * (1992 + x * (4592 + x * (6156 + x * (6111 + x * (3528 + x * 1372))))) }
Example 2:
> print(composepolynomials(1/5 * x + exp(17) + log(2) * x^2, x^4 + 1/3 * x^2));
{ .radii = [|[-3.5873240686715317015647477332221852960774705712039e-43;3.5873240686715317015647477332221852960774705712039e-43], [0;0], [-2.672764710092195646140536467151481878815196880105e-51;2.672764710092195646140536467151481878815196880105e-51], [0;0], [-1.069105884036878258456214586860592751526078752042e-50;1.069105884036878258456214586860592751526078752042e-50], [0;0], [-2.138211768073756516912429173721185503052157504084e-50;2.138211768073756516912429173721185503052157504084e-50], [0;0], [-1.069105884036878258456214586860592751526078752042e-50;1.069105884036878258456214586860592751526078752042e-50]|], .poly = 2.41549527535752982147754351803858238798675673527228e7 + x^2 * (6.6666666666666666666666666666666666666666666666666e-2 + x^2 * (0.2770163533955494788241369023842418408972777927067 + x^2 * (0.46209812037329687294482141430545104538366675624017 + x^2 * 0.69314718055994530941723212145817656807550013436026))) }
Example 3:
> composepolynomials(sin(x),x + x^2);
{ .radii = [| |], .poly = sin(x * (1 + x)) }
Go back to the list of commands
Name:
@
concatenates two lists or strings or applies a list as arguments to a procedure
Library name:
sollya_obj_t sollya_lib_concat(sollya_obj_t, sollya_obj_t)
Usage:
L1@L2 : (list, list) -> list
string1@string2 : (string, string) -> string
proc@L1 : (procedure, list) -> any type
Parameters:
- L1 and L2 are two lists.
- string1 and string2 are two strings.
- proc is a procedure or an external procedure.
Description:
- In its first usage form, @ concatenates two lists or strings.
- In its second usage form, @ applies the elements of a list as
arguments to a procedure or an external procedure. In the case when proc is
a procedure or external procedure with a fixed number of arguments, a check
is done if the number of elements in the list corresponds to the number of
formal parameters of proc. An empty list can therefore be applied only to a
procedure that does not take any argument. In the case when proc accepts an
arbitrary number of arguments, no such check is performed.
Example 1:
> [|1,...,3|]@[|7,8,9|];
[|1, 2, 3, 7, 8, 9|]
Example 2:
> "Hello "@"World!";
Hello World!
Example 3:
> procedure cool(a,b,c) {
write(a,", ", b," and ",c," are cool guys.\n");
};
> cool @ [| "Christoph", "Mioara", "Sylvain" |];
Christoph, Mioara and Sylvain are cool guys.
Example 4:
> procedure sayhello() {
"Hello! how are you?";
};
> sayhello();
Hello! how are you?
> sayhello @ [||];
Hello! how are you?
Example 5:
> bashexecute("gcc -fPIC -Wall -c externalprocexample.c");
> bashexecute("gcc -fPIC -shared -o externalprocexample externalprocexample.o");
> externalproc(foo, "./externalprocexample", (integer, integer) -> integer);
> foo;
foo
> foo @ [|5, 6|];
11
Example 6:
> procedure add(L = ...) {
var acc, i;
acc = 0;
for i in L do acc = i + acc;
return acc;
};
> add(1,2);
3
> add(1,2,3);
6
> add @ [|1, 2|];
3
> add @ [|1, 2, 3|];
6
> add @ [||];
0
Go back to the list of commands
Name:
constant
keyword representing a constant type
Library name:
SOLLYA_EXTERNALPROC_TYPE_CONSTANT
Description:
- constant represents the constant type for declarations
of external procedures externalproc.
Remark that in contrast to other indicators, type indicators like
constant cannot be handled outside the externalproc context. In
particular, they cannot be assigned to variables.
Go back to the list of commands
Name:
cos
the cosine function.
Library names:
sollya_obj_t sollya_lib_cos(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_cos(sollya_obj_t)
#define SOLLYA_COS(x) sollya_lib_build_function_cos(x)
Description:
- cos is the usual cosine function.
- It is defined for every real number x.
Go back to the list of commands
Name:
cosh
the hyperbolic cosine function.
Library names:
sollya_obj_t sollya_lib_cosh(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_cosh(sollya_obj_t)
#define SOLLYA_COSH(x) sollya_lib_build_function_cosh(x)
Description:
- cosh is the usual hyperbolic function: cosh(x) = (exp(x)+exp(-x))/2.
- It is defined for every real number x.
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_decimal()
int sollya_lib_is_decimal(sollya_obj_t)
Description:
- decimal is a special value used for the global state display.
If the global state display is equal to decimal, all data will
be output in decimal notation.
As any value it can be affected to a variable and stored in lists.
Go back to the list of commands
Name:
default
default value for some commands.
Library names:
sollya_obj_t sollya_lib_default()
int sollya_lib_is_default(sollya_obj_t)
Description:
- default is a special value and is replaced by something depending on the
context where it is used. It can often be used as a joker, when you want to
specify one of the optional parameters of a command and not the others: set
the value of uninteresting parameters to default.
- Global variables can be reset by affecting them the special value default.
Example 1:
> p = remez(exp(x),5,[0;1],default,1e-5);
> q = remez(exp(x),5,[0;1],1,1e-5);
> p==q;
true
Example 2:
> prec;
165
> prec=200;
The precision has been set to 200 bits.
Go back to the list of commands
Name:
degree
gives the degree of a polynomial.
Library name:
sollya_obj_t sollya_lib_degree(sollya_obj_t)
Usage:
degree(f) : function -> integer
Parameters:
- f is a function (usually a polynomial).
Description:
- If f is a polynomial, degree(f) returns the degree of f.
- Contrary to the usage, Sollya considers that the degree of the null polynomial
is 0.
- If f is a function that is not a polynomial, degree(f) returns -1.
Example 1:
> degree((1+x)*(2+5*x^2));
3
> degree(0);
0
Example 2:
> degree(sin(x));
-1
Go back to the list of commands
Name:
denominator
gives the denominator of an expression
Library name:
sollya_obj_t sollya_lib_denominator(sollya_obj_t)
Parameters:
- expr represents an expression
Description:
- If expr represents a fraction expr1/expr2, denominator(expr)
returns the denominator of this fraction, i.e. expr2.
If expr represents something else, denominator(expr)
returns 1.
Note that for all expressions expr, numerator(expr) / denominator(expr)
is equal to expr.
Example 1:
> denominator(5/3);
3
Example 2:
> denominator(exp(x));
1
Example 3:
> a = 5/3;
> b = numerator(a)/denominator(a);
> print(a);
5 / 3
> print(b);
5 / 3
Example 4:
> a = exp(x/3);
> b = numerator(a)/denominator(a);
> print(a);
exp(x / 3)
> print(b);
exp(x / 3)
Go back to the list of commands
Name:
diam
parameter used in safe algorithms of Sollya and controlling the maximal length of the involved intervals.
Library names:
void sollya_lib_set_diam_and_print(sollya_obj_t)
void sollya_lib_set_diam(sollya_obj_t)
sollya_obj_t sollya_lib_get_diam()
Usage:
diam = width : constant -> void
diam = width ! : constant -> void
diam : constant
Parameters:
- width represents the maximal relative width of the intervals used
Description:
- diam is a global variable. Its value represents the maximal width allowed
for intervals involved in safe algorithms of Sollya (namely infnorm,
checkinfnorm, accurateinfnorm, integral, findzeros, supnorm).
- More precisely, diam is relative to the width of the input interval of
the command. For instance, suppose that diam=1e-5: if infnorm is called
on interval [0;1], the maximal width of an interval will be 1e-5. But if it
is called on interval [0;1e-3], the maximal width will be 1e-8.
Go back to the list of commands
Name:
dieonerrormode
global variable controlling if Sollya is exited on an error or not.
Library names:
void sollya_lib_set_dieonerrormode_and_print(sollya_obj_t)
void sollya_lib_set_dieonerrormode(sollya_obj_t)
sollya_obj_t sollya_lib_get_dieonerrormode()
Parameters:
- activation value controls if Sollya is exited on an error or not.
Description:
- dieonerrormode is a global variable. When its value is off, which is the default,
Sollya will not exit on any syntax, typing, side-effect errors. These
errors will be caught by the tool, even if a memory might be leaked at
that point. On evaluation, the error special value will be produced.
- When the value of the dieonerrormode variable is on, Sollya will exit
on any syntax, typing, side-effect errors. A warning message will
be printed in these cases at appropriate verbosity levels.
Example 1:
> verbosity = 1!;
> dieonerrormode = off;
Die-on-error mode has been deactivated.
> for i from true to false do i + "Salut";
Warning: one of the arguments of the for loop does not evaluate to a constant.
The for loop will not be executed.
> exp(17);
Warning: rounding has happened. The value displayed is a faithful rounding to 165 bits of the true result.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
2.41549527535752982147754351803858238798675673527224e7
Example 2:
> verbosity = 1!;
> dieonerrormode = off!;
> 5 */ 4;
Warning: syntax error.
The last symbol read has been "/".
Will skip input until next semicolon after the unexpected token. May leak memory.
exp(17);
Warning: rounding has happened. The value displayed is a faithful rounding to 165 bits of the true result.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
2.41549527535752982147754351803858238798675673527224e7
Example 3:
> verbosity = 1!;
> dieonerrormode;
off
> dieonerrormode = on!;
> dieonerrormode;
on
> for i from true to false do i + "Salut";
Warning: one of the arguments of the for loop does not evaluate to a constant.
The for loop will not be executed.
Warning: some syntax, typing or side-effect error has occurred.
As the die-on-error mode is activated, the tool will be exited.
Example 4:
> verbosity = 1!;
> dieonerrormode = on!;
> 5 */ 4;
Warning: syntax error.
The last symbol read has been "/".
Will skip input until next semicolon after the unexpected token. May leak memory.
Warning: some syntax, typing or side-effect error has occurred.
As the die-on-error mode is activated, the tool will be exited.
Example 5:
> verbosity = 0!;
> dieonerrormode = on!;
> 5 */ 4;
Go back to the list of commands
Name:
diff
differentiation operator
Library name:
sollya_obj_t sollya_lib_diff(sollya_obj_t)
Usage:
diff(function) : function -> function
Parameters:
- function represents a function
Description:
- diff(function) returns the symbolic derivative of the function
function by the global free variable.
If function represents a function symbol that is externally bound
to some code by library, the derivative is performed as a symbolic
annotation to the returned expression tree.
Example 1:
> diff(sin(x));
cos(x)
Example 2:
> diff(x);
1
Example 3:
> diff(x^x);
x^x * (1 + log(x))
Go back to the list of commands
Name:
dirtyfindzeros
gives a list of numerical values listing the zeros of a function on an interval.
Library name:
sollya_obj_t sollya_lib_dirtyfindzeros(sollya_obj_t, sollya_obj_t)
Parameters:
- f is a function.
- I is an interval.
Description:
- dirtyfindzeros(f,I) returns a list containing some zeros of f in the
interval I. The values in the list are numerical approximation of the exact
zeros. The precision of these approximations is approximately the precision
stored in prec. If f does not have two zeros very close to each other, it
can be expected that all zeros are listed. However, some zeros may be
forgotten. This command should be considered as a numerical algorithm and
should not be used if safety is critical.
- More precisely, the algorithm relies on global variables prec and points and it performs the following steps:
let n be the value of variable points and t be the value
of variable prec.
- Evaluate |f| at n evenly distributed points in the interval I.
The working precision to be used is automatically chosen in order to ensure that the sign
is correct.
- Whenever f changes its sign for two consecutive points,
find an approximation x of its zero with precision t using
Newton's algorithm. The number of steps in Newton's iteration depends on t:
the precision of the approximation is supposed to be doubled at each step.
- Add this value to the list.
- The user should be aware that the list returned by dirtyfindzeros may
contain a certain floating-point number twice. These repetitions
reflect the existence of different zeros of the function the value of
which rounds to the same floating-point number in the current working
precision. In this case, increasing the working precision will end up
making the two zeros distinguishable even in rounded floating-point
arithmetic.
Example 1:
> dirtyfindzeros(sin(x),[-5;5]);
[|-3.1415926535897932384626433832795028841971693993751, 0, 3.1415926535897932384626433832795028841971693993751|]
Example 2:
> L1=dirtyfindzeros(x^2*sin(1/x),[0;1]);
> points=1000!;
> L2=dirtyfindzeros(x^2*sin(1/x),[0;1]);
> length(L1); length(L2);
18
25
Go back to the list of commands
Name:
dirtyinfnorm
computes a numerical approximation of the infinity norm of a function on an interval.
Library name:
sollya_obj_t sollya_lib_dirtyinfnorm(sollya_obj_t, sollya_obj_t)
Parameters:
- f is a function.
- I is an interval.
Description:
- dirtyinfnorm(f,I) computes an approximation of the infinity norm of the
given function f on the interval I, e.g. max {|f(x)|, x in I}.
- The interval must be bound. If the interval contains one of -Inf or +Inf, the
result of dirtyinfnorm is NaN.
- The result of this command depends on the global variables prec and points.
Therefore, the returned result is generally a good approximation of the exact
infinity norm, with precision prec. However, the result is generally
underestimated and should not be used when safety is critical.
Use infnorm instead.
- The following algorithm is used: let n be the value of variable points
and t be the value of variable prec.
- Evaluate |f| at n evenly distributed points in the
interval I. The evaluation are faithful roundings of the exact
results at precision t.
- Whenever the derivative of f changes its sign for two consecutive
points, find an approximation x of its zero with precision t.
Then compute a faithful rounding of |f(x)| at precision t.
- Return the maximum of all computed values.
Example 1:
> dirtyinfnorm(sin(x),[-10;10]);
1
Example 2:
> prec=15!;
> dirtyinfnorm(exp(cos(x))*sin(x),[0;5]);
1.45856
> prec=40!;
> dirtyinfnorm(exp(cos(x))*sin(x),[0;5]);
1.458528537136
> prec=100!;
> dirtyinfnorm(exp(cos(x))*sin(x),[0;5]);
1.458528537136237644438147455025
> prec=200!;
> dirtyinfnorm(exp(cos(x))*sin(x),[0;5]);
1.458528537136237644438147455023841718299214087993682374094153
Example 3:
> dirtyinfnorm(x^2, [log(0);log(1)]);
NaN
Go back to the list of commands
Name:
dirtyintegral
computes a numerical approximation of the integral of a function on an interval.
Library name:
sollya_obj_t sollya_lib_dirtyintegral(sollya_obj_t, sollya_obj_t)
Parameters:
- f is a function.
- I is an interval.
Description:
- dirtyintegral(f,I) computes an approximation of the integral of f on I.
- The interval must be bound. If the interval contains one of -Inf or +Inf, the
result of dirtyintegral is NaN, even if the integral has a meaning.
- The result of this command depends on the global variables prec and points.
The method used is the trapezium rule applied at n evenly distributed
points in the interval, where n is the value of global variable points.
- This command computes a numerical approximation of the exact value of the
integral. It should not be used if safety is critical. In this case, use
command integral instead.
- Warning: this command is currently known to be unsatisfactory. If you really
need to compute integrals, think of using another tool or report a feature
request to sylvain.chevillard@ens-lyon.org.
Example 1:
> sin(10);
-0.54402111088936981340474766185137728168364301291622
> dirtyintegral(cos(x),[0;10]);
-0.54400304905152629822448058882475382036536298356282
> points=2000!;
> dirtyintegral(cos(x),[0;10]);
-0.54401997751158321972222697312583199035995837926893
Go back to the list of commands
Name:
dirtysimplify
simplifies an expression representing a function
Library name:
sollya_obj_t sollya_lib_dirtysimplify(sollya_obj_t)
Parameters:
- function represents the expression to be simplified
Description:
- The command dirtysimplify simplifies constant subexpressions of the
expression given in argument representing the function
function. Those constant subexpressions are evaluated using
floating-point arithmetic with the global precision prec.
Example 1:
> print(dirtysimplify(sin(pi * x)));
sin(3.1415926535897932384626433832795028841971693993751 * x)
> print(dirtysimplify(erf(exp(3) + x * log(4))));
erf(20.0855369231876677409285296545817178969879078385544 + x * 1.3862943611198906188344642429163531361510002687205)
Example 2:
> prec = 20!;
> t = erf(0.5);
> s = dirtysimplify(erf(0.5));
> prec = 200!;
> t;
0.520499877813046537682746653891964528736451575757963700058806
> s;
0.52050018310546875
Go back to the list of commands
Name:
display
sets or inspects the global variable specifying number notation
Library names:
void sollya_lib_set_display_and_print(sollya_obj_t)
void sollya_lib_set_display(sollya_obj_t)
sollya_obj_t sollya_lib_get_display()
Usage:
display = notation value : decimal|binary|dyadic|powers|hexadecimal -> void
display = notation value ! : decimal|binary|dyadic|powers|hexadecimal -> void
display : decimal|binary|dyadic|powers|hexadecimal
Parameters:
- notation value represents a variable of type decimal|binary|dyadic|powers|hexadecimal
Description:
- An assignment display = notation value, where notation value is
one of decimal, dyadic, powers, binary or hexadecimal, activates
the corresponding notation for output of values in print, write or
at the Sollya prompt.
If the global notation variable display is decimal, all numbers will
be output in scientific decimal notation. If the global notation
variable display is dyadic, all numbers will be output as dyadic
numbers with Gappa notation. If the global notation variable display
is powers, all numbers will be output as dyadic numbers with a
notation compatible with Maple and PARI/GP. If the global notation
variable display is binary, all numbers will be output in binary
notation. If the global notation variable display is hexadecimal,
all numbers will be output in C99/ IEEE754-2008 notation. All output
notations can be parsed back by Sollya, inducing no error if the input
and output precisions are the same (see prec).
If the assignment display = notation value is followed by an
exclamation mark, no message indicating the new state is
displayed. Otherwise the user is informed of the new state of the
global mode by an indication.
Example 1:
> display = decimal;
Display mode is decimal numbers.
> a = evaluate(sin(pi * x), 0.25);
> a;
0.70710678118654752440084436210484903928483593768847
> display = binary;
Display mode is binary numbers.
> a;
1.01101010000010011110011001100111111100111011110011001001000010001011001011111011000100110110011011101010100101010111110100111110001110101101111011000001011101010001_2 * 2^(-1)
> display = hexadecimal;
Display mode is hexadecimal numbers.
> a;
0x1.6a09e667f3bcc908b2fb1366ea957d3e3adec1751p-1
> display = dyadic;
Display mode is dyadic numbers.
> a;
33070006991101558613323983488220944360067107133265b-165
> display = powers;
Display mode is dyadic numbers in integer-power-of-2 notation.
> a;
33070006991101558613323983488220944360067107133265 * 2^(-165)
Go back to the list of commands
Name:
div
Computes the euclidian division of polynomials or numbers and returns the quotient
Library name:
sollya_obj_t sollya_lib_euclidian_div(sollya_obj_t, sollya_obj_t)
Usage:
div(a, b) : (function, function) -> function
Parameters:
- a is a constant or a polynomial.
- b is a constant or a polynomial.
Description:
- When both a and b are constants, div(a,b) computes
floor(a / b). In other words, it returns the quotient of the Euclidian
division of a by b.
- When both a and b are polynomials with at least one being non-constant,
div(a,b) computes a polynomial q such that the polynomial r equal to
a - q * b is of degree strictly smaller than the degree of b (see
exception below). In order to recover r, use the mod command.
- div works on polynomials whose coefficients are constant
expressions that cannot be simplified (by the tool) to rational
numbers. In most cases, the tool is able to perform the Euclidian
polynomial division for such polynomials and stop the Euclidian
division algorithm only when r is of degree strictly smaller than
the degree of b. In certain cases, when the polynomials involve
coefficients given as constant expressions that are mathematically
zero but for which the tool is unable to detect this fact, the tool
may be unable to correctly determine that r is actually of degree
stricly smaller than the degree of b. The issue arises in particular
for polynomials whose leading coefficient is a constant expression
which is zero without the tool being able to detect this. In these
cases, div, together with mod, just guarantee that q and
r, as returned by the two commands, satisfy that r added to the
product of q and b yields a, and that r is of the smallest
degree the tool can admit. However, there might exist another pair of
a quotient and remainder polynomial for which the remainder polynomial
is of a degree less than the one of r.
- When at least one of a or b is a function that is no polynomial,
div(a,b) returns 0.
Example 1:
> div(1001, 231);
4
> div(13, 17);
0
> div(-14, 15);
-1
> div(-213, -5);
42
> div(23/13, 11/17);
2
> div(exp(13),-sin(17));
460177
Example 2:
> div(24 + 68 * x + 74 * x^2 + 39 * x^3 + 10 * x^4 + x^5, 4 + 4 * x + x^2);
6 + x * (11 + x * (6 + x))
> div(24 + 68 * x + 74 * x^2 + 39 * x^3 + 10 * x^4 + x^5, 2 * x^3);
19.5 + x * (5 + x * 0.5)
> div(x^2, x^3);
0
Example 3:
> div(exp(x), x^2);
0
Go back to the list of commands
Name:
/
division function
Library names:
sollya_obj_t sollya_lib_div(sollya_obj_t, sollya_obj_t)
sollya_obj_t sollya_lib_build_function_div(sollya_obj_t, sollya_obj_t)
#define SOLLYA_DIV(x,y) sollya_lib_build_function_div((x), (y))
Usage:
function1 / function2 : (function, function) -> function
interval1 / interval2 : (range, range) -> range
interval1 / constant : (range, constant) -> range
interval1 / constant : (constant, range) -> range
Parameters:
- function1 and function2 represent functions
- interval1 and interval2 represent intervals (ranges)
- constant represents a constant or constant expression
Description:
- / represents the division (function) on reals.
The expression function1 / function2 stands for
the function composed of the division function and the two
functions function1 and function2, where function1 is
the numerator and function2 the denominator.
- / can be used for interval arithmetic on intervals
(ranges). / will evaluate to an interval that safely
encompasses all images of the division function with arguments
varying in the given intervals. If the intervals given contain points
where the division function is not defined, infinities and NaNs will be
produced in the output interval. Any combination of intervals with
intervals or constants (resp. constant expressions) is
supported. However, it is not possible to represent families of
functions using an interval as one argument and a function (varying in
the free variable) as the other one.
Example 1:
> 5 / 2;
2.5
Example 2:
> x / 2;
x * 0.5
Example 3:
> x / x;
1
Example 4:
> 3 / 0;
NaN
Example 5:
> diff(sin(x) / exp(x));
(exp(x) * cos(x) - sin(x) * exp(x)) / exp(x)^2
Example 6:
> [1;2] / [3;4];
[0.25;0.66666666666666666666666666666666666666666666666668]
> [1;2] / 17;
[5.8823529411764705882352941176470588235294117647059e-2;0.11764705882352941176470588235294117647058823529412]
> -13 / [4;17];
[-3.25;-0.76470588235294117647058823529411764705882352941175]
Go back to the list of commands
Names:
double,
D
rounding to the nearest IEEE 754 double (binary64).
Library names:
sollya_obj_t sollya_lib_double(sollya_obj_t)
sollya_obj_t sollya_lib_double_obj()
int sollya_lib_is_double_obj(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_double(sollya_obj_t)
#define SOLLYA_D(x) sollya_lib_build_function_double(x)
Description:
- double is both a function and a constant.
- As a function, it rounds its argument to the nearest IEEE 754 double precision (i.e. IEEE754-2008 binary64) number.
Subnormal numbers are supported as well as standard numbers: it is the real
rounding described in the standard.
- As a constant, it symbolizes the double precision format. It is used in
contexts when a precision format is necessary, e.g. in the commands
round, roundcoefficients and implementpoly.
See the corresponding help pages for examples.
Example 1:
> display=binary!;
> D(0.1);
1.100110011001100110011001100110011001100110011001101_2 * 2^(-4)
> D(4.17);
1.000010101110000101000111101011100001010001111010111_2 * 2^(2)
> D(1.011_2 * 2^(-1073));
1.1_2 * 2^(-1073)
Go back to the list of commands
Names:
doubledouble,
DD
represents a number as the sum of two IEEE doubles.
Library names:
sollya_obj_t sollya_lib_double_double(sollya_obj_t)
sollya_obj_t sollya_lib_double_double_obj()
int sollya_lib_is_double_double_obj(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_double_double(sollya_obj_t)
#define SOLLYA_DD(x) sollya_lib_build_function_double_double(x)
Description:
- doubledouble is both a function and a constant.
- As a function, it rounds its argument to the nearest number that can be written
as the sum of two double precision numbers.
- The algorithm used to compute doubledouble(x) is the following: let xh = double(x)
and let xl = double(x - xh). Return the number xh + xl. Note that if the current
precision is not sufficient to exactly represent xh + xl, a rounding will occur
and the result of doubledouble(x) will be useless.
- As a constant, it symbolizes the double-double precision format. It is used in
contexts when a precision format is necessary, e.g. in the commands
round, roundcoefficients and implementpoly.
See the corresponding help pages for examples.
Example 1:
> verbosity=1!;
> a = 1+ 2^(-100);
> DD(a);
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
1.0000000000000000000000000000007888609052210118054
> prec=50!;
> DD(a);
1.0000000000000000000000000000007888609052210118054117285652827862296732064351090230047702789306640625
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_doubleextended(sollya_obj_t)
sollya_obj_t sollya_lib_doubleextended_obj()
int sollya_lib_is_doubleextended_obj(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_doubleextended(sollya_obj_t)
#define SOLLYA_DE(x) sollya_lib_build_function_doubleextended(x)
Description:
- doubleextended is a function that computes the nearest floating-point number with
64 bits of mantissa to a given number. Since it is a function, it can be
composed with other Sollya functions such as exp, sin, etc.
- doubleextended now does handle subnormal numbers for a presumed exponent width
of the double-extended format of 15 bits. This means, with respect to
rounding, doubleextended behaves as a IEEE 754-2008 binary79 with a 64 bit
significand (with a hidden bit normal range), one sign bit and a
15 bit exponent field would behave. This behavior may be different
from the one observed on Intel-based IA32/Intel64 processors (or compatible
versions from other vendors). However it is the one seen on HP/Intel
Itanium when the precision specifier is double-extended and pseudo-denormals
are activated.
- Since it is a function and not a command, its behavior is a bit different from
the behavior of round(x,64,RN) even if the result is exactly the same.
round(x,64,RN) is immediately evaluated whereas doubleextended(x) can be composed
with other functions (and thus be plotted and so on).
Example 1:
> display=binary!;
> DE(0.1);
1.100110011001100110011001100110011001100110011001100110011001101_2 * 2^(-4)
> round(0.1,64,RN);
1.100110011001100110011001100110011001100110011001100110011001101_2 * 2^(-4)
Example 2:
> D(2^(-2000));
0
> DE(2^(-20000));
0
Example 3:
> verbosity=1!;
> f = sin(DE(x));
> f(pi);
Warning: rounding has happened. The value displayed is a faithful rounding to 165 bits of the true result.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
-5.016557612668332023557327080330757013831561670255e-20
> g = sin(round(x,64,RN));
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_dyadic()
int sollya_lib_is_dyadic(sollya_obj_t)
Description:
- dyadic is a special value used for the global state display.
If the global state display is equal to dyadic, all data will
be output in dyadic notation with numbers displayed in Gappa format.
As any value it can be affected to a variable and stored in lists.
Go back to the list of commands
Name:
==
equality test operator
Library name:
sollya_obj_t sollya_lib_cmp_equal(sollya_obj_t, sollya_obj_t)
Usage:
expr1 == expr2 : (any type, any type) -> boolean
Parameters:
- expr1 and expr2 represent expressions
Description:
- The test expr1 == expr2 returns true when expr1 and expr2 are
syntactically equal and different from error, @NaN@ and [@NaN@, @NaN].
Conversely if expr1 and expr2 are objects that are mathematically
different and Sollya manages to figure it out, the test returns false.
In between these two cases, there is the grey zone of expressions that are
not syntactically equal but are mathematically equal. In such a case,
Sollya normally tries to determine if the expressions are mathematically
equal and if it manages to prove it, it returns true, without a warning. In
the case when expr1 and expr2 are two constant expressions, Sollya will
in particular try to evaluate their difference: in the case when the
difference is 0 or is so small that Sollya does not manage to obtain a
faithful rounding of the real value, it will return true (with a warning if
it has not been possible to actually prove that the real value is 0). In any
other case, when both expressions are not syntactically equal and Sollya
has not been able to prove that they are mathematically equal, it
returns false.
- The level of simplifications performed by Sollya to determine if
expressions are mathematically equal depends on the value of autosimplify.
If it is off, no formal simplification is performed, hence expression trees
as simple as x+1 and 1+x will be considered not equal. Conversely, if
autosimplify is set to on, polynomial subexpressions that are
mathematically equal will in general be recognized as being equal.
- The user should always keep in mind that a litteral constant written in
decimal arithmetic (such as 0.1 for instance) is not considered as an exact
constant by Sollya (unless it is exactly representable in binary without
requiring too much precision) and is first correctly rounded at precision
prec, prior to any other operation. Of course, this leads to a rounding
warning, but it is important to remember that this is done before the
expression trees are compared, possibly leading to two expressions comparing
equal, while they are obviously mathematically different, just because they
contain different constants that have been rounded to the same value at
precision prec. As a general rule, to avoid this behavior, the user should
represent constants in an exact format such as hexadecimal or represent
decimal constants as integer fractions (e.g., 0.1 represented by the constant
expression 1/10).
- Notice that @NaN@, [@NaN, @NaN@] and error share the property that they
compare not equal to anything, including themselves. This means if a variable
a contains @NaN@, [@NaN, @NaN@] or error and whatever the content of
variable b is, the test a == b returns false. The traditional way of
testing if a contains @NaN@, [@NaN@, @NaN@] or error is indeed to check if
a == a returns false. error can be distinguished from @NaN@ and
[@NaN@, @NaN@] using the != operator. In order to distinguish @NaN@ from
[@NaN@, @NaN@], a match ... with ... construct must be used. In general,
match ... with ... constructs work on all of @NaN@, [@NaN, @NaN@] and error
and are able to distinguish between all of these.
Example 1:
> "Hello" == "Hello";
true
> "Hello" == "Salut";
false
> "Hello" == 5;
false
> 5 + x == 5 + x;
true
Example 2:
> verbosity = 1!;
> asin(1) * 2 == pi;
true
> cos(3)^2 == 1 - sin(3)^2;
Warning: the tool is unable to decide an equality test by evaluation even though faithful evaluation of the terms has been possible. The terms will be considered to be equal.
true
> exp(5) == log(4);
false
Example 3:
> autosimplify=off;
Automatic pure tree simplification has been deactivated.
> exp(1+x) == exp(x+1);
false
> autosimplify=on;
Automatic pure tree simplification has been activated.
> exp(1+x) == exp(x+1);
false
> (1/3+x)^2 == x^2 + 1/9 + (5-3)*x/3;
true
> log(x)/log(10) == log10(x);
false
Example 4:
> prec = 12;
The precision has been set to 12 bits.
> verbosity = 1!;
> 16384.1 == 16385.1;
Warning: Rounding occurred when converting the constant "16384.1" to floating-point with 12 bits.
If safe computation is needed, try to increase the precision.
Warning: Rounding occurred when converting the constant "16385.1" to floating-point with 12 bits.
If safe computation is needed, try to increase the precision.
true
> 16384 == 16384.25;
false
> 0.1 == 1/10;
Warning: Rounding occurred when converting the constant "0.1" to floating-point with 12 bits.
If safe computation is needed, try to increase the precision.
false
> 0.1 == round(1/10, prec, RN);
Warning: Rounding occurred when converting the constant "0.1" to floating-point with 12 bits.
If safe computation is needed, try to increase the precision.
true
Example 5:
> error == error;
false
> error != error;
false
> @NaN@ == @NaN@;
false
> @NaN@ != @NaN@;
true
> [@NaN@,@NaN@] == [@NaN@,@NaN@];
false
> [@NaN@,@NaN@] != [@NaN@,@NaN@];
true
> error == @NaN@;
false
> error != @NaN@;
false
> a = error;
> match a with
@NaN@ : ("a contains @NaN@")
[@NaN@, @NaN@] : ("a contains [@NaN@, @NaN@]")
default:("a contains something else");
a contains something else
> a = @NaN@;
> match a with
@NaN@ : ("a contains @NaN@")
[@NaN@, @NaN@] : ("a contains [@NaN@, @NaN@]")
default:("a contains something else");
a contains @NaN@
> a = [@NaN@, @NaN@];
> match a with
@NaN@ : ("a contains @NaN@")
[@NaN@, @NaN@] : ("a contains [@NaN@, @NaN@]")
default:("a contains something else");
a contains [@NaN@, @NaN@]
See also: !=,
>,
>=,
<=,
<,
in,
!,
&&,
||,
error,
prec,
autosimplify
Go back to the list of commands
Name:
erfc
the complementary error function.
Library names:
sollya_obj_t sollya_lib_erfc(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_erfc(sollya_obj_t)
#define SOLLYA_ERFC(x) sollya_lib_build_function_erfc(x)
Description:
- erfc is the complementary error function defined by erfc(x) = 1 - erf(x).
- It is defined for every real number x.
Go back to the list of commands
Name:
erf
the error function.
Library names:
sollya_obj_t sollya_lib_erf(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_erf(sollya_obj_t)
#define SOLLYA_ERF(x) sollya_lib_build_function_erf(x)
Description:
- erf is the error function defined by:
erf(x) = (2/sqrt(Pi)) * integral(exp(-t^2), [0;x])
- It is defined for every real number x.
Go back to the list of commands
Name:
error
expression representing an input that is wrongly typed or that cannot be executed
Library names:
sollya_obj_t sollya_lib_error()
int sollya_lib_obj_is_error(sollya_obj_t)
Description:
- The variable error represents an input during the evaluation of
which a type or execution error has been detected or is to be
detected. Inputs that are syntactically correct but wrongly typed
evaluate to error at some stage. Inputs that are correctly typed
but containing commands that depend on side-effects that cannot be
performed or inputs that are wrongly typed at meta-level (cf. parse),
evaluate to error.
Remark that in contrast to all other elements of the Sollya language,
error compares neither equal nor unequal to itself. This provides a
means of detecting syntax errors inside the Sollya language itself
without introducing issues of two different wrongly typed inputs being
equal.
Example 1:
> print(5 + "foo");
error
Example 2:
> error;
error
Example 3:
> error == error;
false
> error != error;
false
Example 4:
> correct = 5 + 6;
> incorrect = 5 + "foo";
> correct == correct;
true
> incorrect == incorrect;
false
> errorhappened = !(incorrect == incorrect);
> errorhappened;
true
Go back to the list of commands
Name:
evaluate
evaluates a function at a constant point or in a range
Library name:
sollya_obj_t sollya_lib_evaluate(sollya_obj_t, sollya_obj_t)
Usage:
evaluate(function, constant) : (function, constant) -> constant | range
evaluate(function, range) : (function, range) -> range
evaluate(function, function2) : (function, function) -> function
Parameters:
- function represents a function
- constant represents a constant point
- range represents a range
- function2 represents a function that is not constant
Description:
- If its second argument is a constant constant, evaluate evaluates
its first argument function at the point indicated by
constant. This evaluation is performed in a way that the result is a
faithful rounding of the real value of the function at constant to
the current global precision. If such a faithful rounding is not
possible, evaluate returns a range surely encompassing the real value
of the function function at constant. If even interval evaluation
is not possible because the expression is undefined or numerically
unstable, NaN will be produced.
- If its second argument is a range range, evaluate evaluates its
first argument function by interval evaluation on this range
range. This ensures that the image domain of the function function
on the preimage domain range is surely enclosed in the returned
range.
- In the case when the second argument is a range that is reduced to a
single point (such that [1;1] for instance), the evaluation
is performed in the same way as when the second argument is a constant but
it produces a range as a result: evaluate automatically adjusts the precision
of the intern computations and returns a range that contains at most three floating-point
consecutive numbers in precision prec. This corresponds to the same accuracy
as a faithful rounding of the actual result. If such a faithful rounding
is not possible, evaluate has the same behavior as in the case when the
second argument is a constant.
- If its second argument is a function function2 that is not a
constant, evaluate replaces all occurrences of the free variable in
function function by function function2.
Example 1:
> midpointmode=on!;
> print(evaluate(sin(pi * x), 2.25));
0.70710678118654752440084436210484903928483593768847
> print(evaluate(sin(pi * x), [2.25; 2.25]));
0.707106781186547524400844362104849039284835937688~4/5~
Example 2:
> print(evaluate(sin(pi * x), 2));
[-3.100365765139897619749121887390789523854170596558e-13490;5.3002401585857127605350842426029223241500776302528e-13489]
Example 3:
> print(evaluate(sin(pi * x), [2, 2.25]));
[-5.143390272677254630046998919961912407349224165421e-50;0.70710678118654752440084436210484903928483593768866]
Example 4:
> print(evaluate(sin(pi * x), 2 + 0.25 * x));
sin((pi) * 2 + x * (pi) * 0.25)
Example 5:
> print(evaluate(sin(pi * 1/x), 0));
[-1;1]
Go back to the list of commands
Name:
execute
executes the content of a file
Library name:
void sollya_lib_execute(sollya_obj_t)
Usage:
execute(filename) : string -> void
Parameters:
- filename is a string representing a file name
Description:
- execute opens the file indicated by filename, and executes the sequence of
commands it contains. This command is evaluated at execution time: this way you
can modify the file filename (for instance using bashexecute) and execute it
just after.
- If filename contains a command execute, it will be executed recursively.
- If filename contains a call to restart, it will be neglected.
- If filename contains a call to quit, the commands following quit
in filename will be neglected.
Example 1:
> a=2;
> a;
2
> print("a=1;") > "example.sollya";
> execute("example.sollya");
> a;
1
Example 2:
> verbosity=1!;
> print("a=1; restart; a=2;") > "example.sollya";
> execute("example.sollya");
Warning: a restart command has been used in a file read into another.
This restart command will be neglected.
> a;
2
Example 3:
> verbosity=1!;
> print("a=1; quit; a=2;") > "example.sollya";
> execute("example.sollya");
Warning: the execution of a file read by execute demanded stopping the interpretation but it is not stopped.
> a;
1
Go back to the list of commands
Name:
expand
expands polynomial subexpressions
Library name:
sollya_obj_t sollya_lib_expand(sollya_obj_t)
Usage:
expand(function) : function -> function
Parameters:
- function represents a function
Description:
- expand(function) expands all polynomial subexpressions in function
function as far as possible. Factors of sums are multiplied out,
power operators with constant positive integer exponents are replaced
by multiplications.
Example 1:
> print(expand(x^3));
x * x * x
Example 2:
> print(expand((x + 2)^3 + 2 * x));
8 + 12 * x + 6 * x * x + x * x * x + 2 * x
Example 3:
> print(expand(exp((x + (x + 3))^5)));
exp(243 + 405 * x + 270 * x * x + 90 * x * x * x + 15 * x * x * x * x + x * x * x * x * x + x * 405 + 108 * x * 5 * x + 54 * x * x * 5 * x + 12 * x * x * x * 5 * x + x * x * x * x * 5 * x + x * x * 270 + 27 * x * x * x * 10 + 9 * x * x * x * x * 10 + x * x * x * x * x * 10 + x * x * x * 90 + 6 * x * x * x * x * 10 + x * x * x * x * x * 10 + x * x * x * x * 5 * x + 15 * x * x * x * x + x * x * x * x * x)
Go back to the list of commands
Name:
exp
the exponential function.
Library names:
sollya_obj_t sollya_lib_exp(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_exp(sollya_obj_t)
#define SOLLYA_EXP(x) sollya_lib_build_function_exp(x)
Description:
- exp is the usual exponential function defined as the solution of the
ordinary differential equation y' = y with y(0)=1.
- exp(x) is defined for every real number x.
Go back to the list of commands
Name:
expm1
shifted exponential function.
Library names:
sollya_obj_t sollya_lib_expm1(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_expm1(sollya_obj_t)
#define SOLLYA_EXPM1(x) sollya_lib_build_function_expm1(x)
Description:
- expm1 is defined by expm1(x) = exp(x)-1.
- It is defined for every real number x.
Go back to the list of commands
Name:
exponent
returns the scaled binary exponent of a number.
Library name:
sollya_obj_t sollya_lib_exponent(sollya_obj_t)
Usage:
exponent(x) : constant -> integer
Description:
- exponent(x) is by definition 0 if x is one of 0, NaN, or Inf.
- If x is not zero, it can be uniquely written as x = m*2^e where
m is an odd integer and e is an integer. exponent(x) returns e.
Example 1:
> a=round(Pi,20,RN);
> e=exponent(a);
> e;
-17
> m=mantissa(a);
> a-m*2^e;
0
Go back to the list of commands
Name:
externaldata
binds an external data symbol to a Sollya identifier
Library name:
sollya_obj_t sollya_lib_externaldata(char *, void *, void (*)(void *));
Usage:
externaldata(identifier, filename) : (identifier type, string) -> void
Parameters:
- identifier represents the identifier the external symbol is to be bound to
- filename of type string represents the name of the object file where the external symbol can be found
Description:
- externaldata allows for binding the Sollya identifier identifier to an
external symbol, looked up in a dynamically linked library. After this
binding, Sollya can retrieve the bound object in its own symbol
table, can copy it, can assign it to other variables, pass is as
arguments to procedures and externalprocedures, compare it
etc. However, Sollya stays agnostic of the symbol's meaning and
type. Due to this reason, the use of externaldata makes no sense but in
conjuction with the use of externalproc, where an external procedure
is bound to Sollya. This external procedure may know the type and
meaning of the object bound with externaldata and display it, handle it,
execute it etc. The same functionality may also be used for tools that
use Sollya thru its library interface to bind their own objects to
Sollya, pass them thru Sollya code and retrieve them eventually.
Example 1:
> bashexecute("gcc -fPIC -Wall -I.. -I. -c externaldataexample.c");
> bashexecute("gcc -fPIC -shared -o externaldataexample externaldataexample.o");
> externaldata(magic, "./externaldataexample");
> magic;
magic
> print(magic);
magic
> magic == magic;
true
> magic == 17;
false
> zauberei = magic;
> zauberei;
magic
> zauberei == magic;
true
Example 2:
> bashexecute("gcc -fPIC -Wall -I.. -I. -c externaldataexample.c");
> bashexecute("gcc -fPIC -shared -o externaldataexample externaldataexample.o");
> externaldata(magic, "./externaldataexample");
> externalproc(printMagic, "./externaldataexample", object -> void);
> zauberei = magic;
> printMagic;
printMagic
> printMagic(magic);
The magic is 17
> printMagic(magic);
The magic is 18
> printMagic(zauberei);
The magic is 19
> procedure magicAsParameter(m) {
m;
printMagic(m);
m;
};
> magicAsParameter(magic);
magic
The magic is 20
magic
> magicAsParameter(zauberei);
magic
The magic is 21
magic
See also: library,
libraryconstant,
externalproc,
externalplot,
bashexecute,
void,
constant,
function,
range,
integer,
string,
boolean,
list of,
object
Go back to the list of commands
Name:
externalplot
plots the error of an external code with regard to a function
Library names:
void sollya_lib_externalplot(sollya_obj_t, sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t, ...)
void sollya_lib_v_externalplot(sollya_obj_t, sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t, va_list)
Usage:
externalplot(filename, mode, function, range, precision) : (string, absolute|relative, function, range, integer) -> void
externalplot(filename, mode, function, range, precision, perturb) : (string, absolute|relative, function, range, integer, perturb) -> void
externalplot(filename, mode, function, range, precision, plot mode, result filename) : (string, absolute|relative, function, range, integer, file|postscript|postscriptfile, string) -> void
externalplot(filename, mode, function, range, precision, perturb, plot mode, result filename) : (string, absolute|relative, function, range, integer, perturb, file|postscript|postscriptfile, string) -> void
Description:
- The command externalplot plots the error of an external function
evaluation code sequence implemented in the object file named
filename with regard to the function function. If mode
evaluates to absolute, the difference of both functions is
considered as an error function; if mode evaluates to relative,
the difference is divided by the function function. The resulting
error function is plotted on all floating-point numbers with
precision significant mantissa bits in the range range.
If the sixth argument of the command externalplot is given and evaluates to
perturb, each of the floating-point numbers the function is evaluated at gets perturbed by a
random value that is uniformly distributed in +/-1 ulp
around the original precision bit floating-point variable.
If a sixth and seventh argument, respectively a seventh and eighth
argument in the presence of perturb as a sixth argument, are given
that evaluate to a variable of type file|postscript|postscriptfile respectively to a
character sequence of type string, externalplot will plot
(additionally) to a file in the same way as the command plot
does. See plot for details.
The external function evaluation code given in the object file name
filename is supposed to define a function name f as
follows (here in C syntax): void f(mpfr_t rop, mpfr_t op).
This function is supposed to evaluate op with an accuracy corresponding
to the precision of rop and assign this value to
rop.
Example 1:
> bashexecute("gcc -fPIC -c externalplotexample.c");
> bashexecute("gcc -shared -o externalplotexample externalplotexample.o -lgmp -lmpfr");
> externalplot("./externalplotexample",relative,exp(x),[-1/2;1/2],12,perturb);
See also: plot,
asciiplot,
perturb,
absolute,
relative,
file,
postscript,
postscriptfile,
bashexecute,
externalproc,
library
Go back to the list of commands
Name:
externalproc
binds an external code to a Sollya procedure
Library names:
sollya_obj_t sollya_lib_externalprocedure(sollya_externalprocedure_type_t,
sollya_externalprocedure_type_t *,
int, char *, void *);
sollya_obj_t sollya_lib_externalprocedure_with_data(
sollya_externalprocedure_type_t,
sollya_externalprocedure_type_t *,
int, char *, void *, void *,
void (*)(void *));
Usage:
externalproc(identifier, filename, argumenttype -> resulttype) : (identifier type, string, type type, type type) -> void
Parameters:
- identifier represents the identifier the code is to be bound to
- filename of type string represents the name of the object file where the code of procedure can be found
- argumenttype represents a definition of the types of the arguments of the Sollya procedure and the external code
- resulttype represents a definition of the result type of the external code
Description:
- externalproc allows for binding the Sollya identifier identifier to an
external code. After this binding, when Sollya encounters identifier
applied to a list of actual parameters, it will evaluate these parameters and
call the external code with these parameters. If the external code indicated
success, it will receive the result produced by the external code, transform
it to Sollya's internal representation and return it.
In order to allow correct evaluation and typing of the data in parameter and
in result to be passed to and received from the external code, externalproc
has a third parameter argumenttype -> resulttype. Both argumenttype and
resulttype are one of void, constant, function, object, range, integer,
string, boolean, list of constant, list of function, list of object,
list of range, list of integer, list of string, list of boolean.
It is worth mentioning that the difference between the data and
result type function and the type object is minimal and due to
support of legacy Sollya code. Both Sollya functions and Sollya
objects are transferred from and to the external procedure thru the C
type sollya_obj_t. The difference is that
Sollya will check that a certain object is a mathematical function
when function is used as a type, and will skip this test if the
object type is used. Similarly, Sollya relies on an object produced
by the external procedure to be a mathematical function when function
is used and will not make this assumption for object.
If upon a usage of a procedure bound to an external procedure the type of the
actual parameters given or its number is not correct, Sollya produces a type
error. An external function not applied to arguments represents itself and
prints out with its argument and result types.
The external function is supposed to return an integer indicating success. It
returns its result depending on its Sollya result type as follows. Here, the
external procedure is assumed to be implemented as a C function.
- If the Sollya result type is void, the C function has no pointer
argument for the result.
- If the Sollya result type is constant, the first argument of the
C function is of C type mpfr_t *, the result is returned by affecting
the MPFR variable.
- If the Sollya result type is function, the first argument of the
C function is of C type sollya_obj_t *, the result is returned by
affecting the sollya_obj_t variable.
- If the Sollya result type is object, the first argument of the
C function is of C type sollya_obj_t *, the result is returned by
affecting the sollya_obj_t variable.
- If the Sollya result type is range, the first argument of the C function
is of C type mpfi_t *, the result is returned by affecting the MPFI
variable.
- If the Sollya result type is integer, the first argument of the
C function is of C type int *, the result is returned by affecting the
int variable.
- If the Sollya result type is string, the first argument of the
C function is of C type char **, the result is returned by the char *
pointed with a new char *.
- If the Sollya result type is boolean, the first argument of the
C function is of C type int *, the result is returned by affecting the
int variable with a boolean value.
- If the Sollya result type is list of type, the first argument of the
C function is of a C type depending on the Sollya return type:
- For a list of constant: sollya_constant_list_t *
- For a list of function: sollya_obj_list_t *
- For a list of object: sollya_obj_list_t *
- For a list of range: sollya_constant_list_t *
- For a list of integer: sollya_int_list_t *
- For a list of string: sollya_string_list_t *
- For a list of boolean: sollya_boolean_list_t *
The external procedure affects its possible pointer argument if and only if
it succeeds. This means, if the function returns an integer indicating
failure, it does not leak any memory to the encompassing environment.
The external procedure receives its arguments as follows: If the Sollya
argument type is void, no argument array is given. Otherwise the C function
receives a C void ** argument representing an array of size equal to the
arity of the function where each entry (of C type void *) represents a value
with a C type depending on the corresponding Sollya type.
- If the Sollya type is constant, the void * is to be cast to mpfr_t *.
- If the Sollya type is function, the void * is to be cast to
sollya_obj_t.
- If the Sollya type is object, the void * is to be cast to sollya_obj_t.
- If the Sollya type is range, the void * is to be cast to mpfi_t *.
- If the Sollya type is integer, the void * is to be cast to int *.
- If the Sollya type is string, the void * is to be cast to char *.
- If the Sollya type is boolean, the void * is to be cast to int *.
- If the Sollya type is list of type, the void * is to be cast to a list
of a type depending on the type of the list argument:
- For a list of constant: sollya_constant_list_t
- For a list of function: sollya_obj_list_t
- For a list of object: sollya_obj_list_t
- For a list of range: sollya_interval_list_t
- For a list of integer: sollya_int_list_t
- For a list of string: sollya_string_list_t
- For a list of boolean: sollya_boolean_list_t
The external procedure is not supposed to alter the memory pointed by its
array argument void **.
In both directions (argument and result values), empty lists are represented
by NULL pointers.
Similarly to internal procedures, externally bounded procedures can be
considered to be objects inside Sollya that can be assigned to other
variables, stored in list etc.
- The user should be aware that they may use the Sollya library in external
codes to be dynamically bound to Sollya using externalproc. On most systems,
it suffices to include the header of the Sollya library into the source code
of the external procedure. Linking with the actual Sollya library is not
necessary on most systems; as the interactive Sollya executable contains a
superset of the Sollya library functions. On some systems, linking with the
Sollya library or some of its dependencies may be necessary.
In particular, the Sollya library – and, of course, its header file –
contain a certain set of functions to manipulate lists with elements of
certain types, such as sollya_constant_list_t, sollya_obj_list_t and so on.
As explained above, these types are passed in argument to (and received back
thru a reference from) an external procedure. These list manipulation
functions are not strictly necessary to the use of the Sollya library in
free-standing applications that do not use the functionality provided with
externalproc. They are therefore provided as-is without any further
documentation, besides the comments given in the Sollya library header file.
- The dynamic object file whose name is given to externalproc for binding of
an external procedure may also define a destructor function
int sollya_external_lib_close(void). If Sollya finds such a destructor
function in the dynamic object file, it will call that function when closing
the dynamic object file again. This happens when Sollya is terminated or when
the current Sollya session is restarted using restart. The purpose of the
destructor function is to allow the dynamically bound code to free any memory
that it might have allocated before Sollya is terminated or restarted.
The dynamic object file is not necessarily needed to define a destructor
function. This ensure backward compatibility with older Sollya external
library function object files.
When defined, the destructor function is supposed to return an integer
value indicating if an error has happened. Upon success, the destructor
functions is to return a zero value, upon error a non-zero value.
Example 1:
> bashexecute("gcc -fPIC -Wall -c externalprocexample.c");
> bashexecute("gcc -fPIC -shared -o externalprocexample externalprocexample.o");
> externalproc(foo, "./externalprocexample", (integer, integer) -> integer);
> foo;
foo
> foo(5, 6);
11
> verbosity = 1!;
> foo();
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
error
> a = foo;
> a(5,6);
11
See also: library,
libraryconstant,
externaldata,
externalplot,
bashexecute,
void,
constant,
function,
range,
integer,
string,
boolean,
list of,
object
Go back to the list of commands
Name:
false
the boolean value representing the false.
Library names:
sollya_obj_t sollya_lib_false()
int sollya_lib_is_false(sollya_obj_t)
Description:
- false is the usual boolean value.
Example 1:
> true && false;
false
> 2<1;
false
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_file()
int sollya_lib_is_file(sollya_obj_t)
Description:
- file is a special value used in commands plot and externalplot to save
the result of the command in a data file.
- As any value it can be affected to a variable and stored in lists.
Example 1:
> savemode=file;
> name="plotSinCos";
> plot(sin(x),0,cos(x),[-Pi,Pi],savemode, name);
Go back to the list of commands
Name:
findzeros
gives a list of intervals containing all zeros of a function on an interval.
Library name:
sollya_obj_t sollya_lib_findzeros(sollya_obj_t, sollya_obj_t)
Usage:
findzeros(f,I) : (function, range) -> list
Parameters:
- f is a function.
- I is an interval.
Description:
- findzeros(f,I) returns a list of intervals I1, ... ,In such that, for
every zero z of f, there exists some k such that z is in Ik.
- The list may contain intervals Ik that do not contain any zero of f.
An interval Ik may contain many zeros of f.
- This command is meant for cases when safety is critical. If you want to be sure
not to forget any zero, use findzeros. However, if you just want to know
numerical values for the zeros of f, dirtyfindzeros should be quite
satisfactory and a lot faster.
- If d denotes the value of global variable diam, the algorithm ensures
that for each k, |Ik| < d*|I|.
- The algorithm used is basically a bisection algorithm. It is the same algorithm
that the one used for infnorm. See the help page of this command for more
details. In short, the behavior of the algorithm depends on global variables
prec, diam, taylorrecursions and hopitalrecursions.
Example 1:
> findzeros(sin(x),[-5;5]);
[|[-3.14208984375;-3.140869140625], [-1.220703125e-3;1.220703125e-3], [3.140869140625;3.14208984375]|]
> diam=1e-10!;
> findzeros(sin(x),[-5;5]);
[|[-3.14159265370108187198638916015625;-3.141592652536928653717041015625], [-1.16415321826934814453125e-9;1.16415321826934814453125e-9], [3.141592652536928653717041015625;3.14159265370108187198638916015625]|]
Go back to the list of commands
Name:
fixed
indicates that fixed-point formats should be used for fpminimax
Library names:
sollya_obj_t sollya_lib_fixed()
int sollya_lib_is_fixed(sollya_obj_t)
Usage:
fixed : fixed|floating
Description:
- The use of fixed in the command fpminimax indicates that the list of
formats given as argument is to be considered to be a list of fixed-point
formats.
See fpminimax for details.
Example 1:
> fpminimax(cos(x),6,[|32,32,32,32,32,32,32|],[-1;1],fixed);
0.9999997480772435665130615234375 + x^2 * (-0.4999928693287074565887451171875 + x^2 * (4.163351492024958133697509765625e-2 + x^2 * (-1.338223926723003387451171875e-3)))
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_floating()
int sollya_lib_is_floating(sollya_obj_t)
Description:
- The use of floating in the command fpminimax indicates that the list of
formats given as argument is to be considered to be a list of floating-point
formats.
See fpminimax for details.
Example 1:
> fpminimax(cos(x),6,[|D...|],[-1;1],floating);
0.99999974816012215939053930924274027347564697265625 + x * (-2.795931796958502334440230695107655659202089892465e-15 + x * (-0.49999286980201401719980935922649223357439041137695 + x * (4.0484539189054105169841244454207387920433372507922e-14 + x * (4.1633515528919168291466235132247675210237503051758e-2 + x * (-4.015858818743733758578949218474363725507386355118e-14 + x * (-1.3382240885483781024645200119493892998434603214264e-3))))))
Go back to the list of commands
Name:
floor
the usual function floor.
Library names:
sollya_obj_t sollya_lib_floor(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_floor(sollya_obj_t)
#define SOLLYA_FLOOR(x) sollya_lib_build_function_floor(x)
Description:
- floor is defined as usual: floor(x) is the greatest integer y such that y <= x.
- It is defined for every real number x.
Go back to the list of commands
Name:
fpminimax
computes a good polynomial approximation with fixed-point or floating-point coefficients
Library names:
sollya_obj_t sollya_lib_fpminimax(sollya_obj_t, sollya_obj_t, sollya_obj_t,
sollya_obj_t, ...)
sollya_obj_t sollya_lib_v_fpminimax(sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t, va_list)
Usage:
fpminimax(f, n, formats, range, indic1, indic2, indic3, P) : (function, integer, list, range, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, function) -> function
fpminimax(f, monomials, formats, range, indic1, indic2, indic3, P) : (function, list, list, range, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, function) -> function
fpminimax(f, n, formats, L, indic1, indic2, indic3, P) : (function, integer, list, list, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, function) -> function
fpminimax(f, monomials, formats, L, indic1, indic2, indic3, P) : (function, list, list, list, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, function) -> function
fpminimax(f, n, formats, range, indic1, indic2, indic3, Lcoeffs) : (function, integer, list, range, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, list) -> function
fpminimax(f, monomials, formats, range, indic1, indic2, indic3, Lcoeffs) : (function, list, list, range, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, list) -> function
fpminimax(f, n, formats, L, indic1, indic2, indic3, Lcoeffs) : (function, integer, list, list, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, list) -> function
fpminimax(f, monomials, formats, L, indic1, indic2, indic3, Lcoeffs) : (function, list, list, list, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, absolute|relative | fixed|floating | function, list) -> function
Parameters:
- f is the function to be approximated
- n is the degree of the polynomial that must approximate f
- monomials is a list of integers or a list of function. It indicates the basis for the approximation of f
- formats is a list indicating the formats that the coefficients of the polynomial must have
- range is the interval where the function must be approximated
- L is a list of interpolation points used by the method
- indic1 (optional) is one of the optional indication parameters. See the detailed description below.
- indic2 (optional) is one of the optional indication parameters. See the detailed description below.
- indic3 (optional) is one of the optional indication parameters. See the detailed description below.
- P (optional) is the minimax polynomial to be considered for solving the problem.
- Lcoeffs (optional) is a list containing the coefficients of the minimax polynomial to be considered for solving the problem.
Description:
- fpminimax uses a heuristic (but practically efficient) method to find a
good polynomial approximation of a function f on an interval range. It
implements the method published in the article:
Efficient polynomial L^\infty - approximations
Nicolas Brisebarre and Sylvain Chevillard
Proceedings of the 18th IEEE Symposium on Computer Arithmetic (ARITH 18)
pp. 169-176
- The basic usage of this command is fpminimax(f, n, formats, range).
It computes a polynomial approximation of f with degree at most n
on the interval range. formats is a list of integers or format types
(such as double, doubledouble, etc.). The polynomial returned by the
command has its coefficients that fit the formats indications. For
instance, if formats[0] is 35, the coefficient of degree 0 of the
polynomial will fit a floating-point format of 35 bits. If formats[1]
is D, the coefficient of degree 1 will be representable by a floating-point
number with a precision of 53 bits (which is not necessarily an IEEE 754
double precision number. See the remark below), etc.
- In its most general form, fpminimax takes a function f to be
approximated, a list of basis functions g0, ..., gn, a list of points L,
and a constrained part q. It returns an expression p of the form
p = q+a0*g0+...+an*gn such that (p-f) or (p-f)/f (depending whether the
error to be considered is the absolute of relative error) is as small as
possible on the points of L and with coefficients a0, ..., an fitting on
given formats. fpminimax admits several syntaxes listed above and described
below to conveniently handle usual cases (such as when g0, ..., gn is the
standard monomial basis X^0, ..., X^n) and to automatically compute a
suitable list of points L on a given range.
- The second argument may be either an integer, a list of integers or a list
of functions. An integer indicates the degree of the desired polynomial
approximation. A list of integers indicates the list of desired monomials.
For instance, the list [|0,2,4,6|] indicates that the polynomial must be
even and of degree at most 6. Giving an integer n as second argument is
equivalent as giving [|0,...,n|].
Finally, a list of function g_k indicates that the desired approximation
must be a linear combination of the g_k.
The list of formats is interpreted with respect to the list of monomials. For
instance, if the list of monomials is [|0,2,4,6|] and the list
of formats is [|161,107,53,24|], the coefficients of degree 0 is
searched as a floating-point number with precision 161, the coefficient of
degree 2 is searched as a number of precision 107, and so on.
- The list of formats may contain either integers or format types
(halfprecision, single, double, doubledouble, tripledouble, doubleextended
and quad). The list may be too large or even infinite. Only the first
indications will be considered. For instance, for a degree n polynomial,
formats[n+1] and above will be discarded. This lets one use elliptical
indications for the last coefficients. For historical reasons, and as opposed
to the general rule within Sollya, the case of an end-elliptic list whose
last defined element is numeric is interpreted as the infinite list where the
last defined element is repeated: therefore, e.g., [|24...|] is a perfect
synonym for [|SG...|]. Because this behavior can be confusing, using for the
formats an end-elliptic list whose last defined element is numeric is
deprecated and will be forbidden in a future release.
- The floating-point coefficients considered by fpminimax do not have an
exponent range. In particular, in the format list, double is an exact synonym
for 53. Currently, fpminimax only ensures that the corresponding coefficient
has at most 53 bits of mantissa. It does not imply that it is an
IEEE-754 double.
- By default, the list of formats is interpreted as a list of floating-point
formats. This may be changed by passing fixed as an optional argument (see
below). Let us take an example: fpminimax(f, 2, [|107, DD, 53|], [0;1]).
Here the optional argument is missing (we could have set it to floating).
Thus, fpminimax will search for a polynomial of degree 2 with a constant
coefficient that is a 107 bits floating-point number, etc.
Currently, doubledouble is just a synonym for 107 and tripledouble a
synonym for 161. This behavior may change in the future (taking into
account the fact that some double-doubles are not representable with
107 bits).
Second example: fpminimax(f, 2, [|25, 18, 30|], [0;1], fixed).
In this case, fpminimax will search for a polynomial of degree 2 with a
constant coefficient of the form m/2^25 where m is an
integer. In other words, it is a fixed-point number with 25 bits after
the point. Note that even with argument fixed, the formats list is
allowed to contain halfprecision, single, double, doubleextended,
doubledouble, quad or tripledouble. In this this case, it is just
a synonym for 11, 24, 53, 64, 107, 113 or 161. This is deprecated and
may change in the future.
- The fourth argument may be a range or a list. Lists are for advanced users
that know what they are doing. The core of the method is a kind of
approximated interpolation. The list given here is a list of points that
must be considered for the interpolation. It must contain at least as
many points as unknown coefficients. If you give a list, it is also
recommended that you provide the minimax polynomial as last argument.
If you give a range, the list of points will be automatically computed.
- The fifth, sixth and seventh arguments are optional. By default, fpminimax
will approximate f while optimizing the relative error, and interpreting
the list of formats as a list of floating-point formats.
This default behavior may be changed with these optional arguments. You
may provide zero, one, two or three of the arguments in any order.
This lets the user indicate only the non-default arguments.
The three possible arguments are:
The constrained part lets the user assign in advance some of the
coefficients. For instance, for approximating exp(x), it may
be interesting to search for a polynomial p of the form
p = 1 + x + x^2/2 + a3 x^3 + a4 x^4.
Thus, there is a constrained part q = 1 + x + x^2/2 and the unknown
polynomial should be considered in the monomial basis [|3, 4|].
Calling fpminimax with monomial basis [|3,4|] and constrained
part q, will return a polynomial with the right form.
Notice that it is perfectly allowed that the monomial basis contains
monomials also present in the constrained part. This can be useful for
instance to fix the upper part of a doubledouble and look only for the
second double of the expansion. For instance, in the previous example, we
could use the same constrained part q = 1 + x + x^2/2 but with the full
monomial basis [|0,..., 4|]. The resulting polynomial will be of the form
p = 1 + x + x^2/2 + a0 + a1 x + a2 x^2 + a3 x^3 + a4 x^4, or equivalently
(1+a0) + (1+a1) x + (1/2 + a2) x^2 + a3 x^3 + a4 x^4. Therefore, if for
instance the coefficients a0 to a4 are asked to be double, the resulting
polynomial p has its three first coefficients that are doubledouble with
fixed upper parts.
- The last argument is for advanced users. It is the minimax polynomial that
approximates the function f in the given basis. If it is not given
this polynomial will be automatically computed by fpminimax.
This minimax polynomial is used to compute the list of interpolation
points required by the method. It is also used, when floating-point
coefficients are desired, to give an initial assumption for the
exponents of the coeffcients. In general, you do not have to provide this
argument. But if you want to obtain several polynomials of the same degree
that approximate the same function on the same range, just changing the
formats, you should probably consider computing only once the minimax
polynomial and the list of points instead of letting fpminimax recompute
them each time.
Note that in the case when a constrained part is given, the minimax
polynomial must take that into account. For instance, in the previous
example, the minimax would be obtained by the following command:
P = remez(1-(1+x+x^2/2)/exp(x), [|3,4|], range, 1/exp(x));
Note that the constrained part is not to be added to P.
In the case when the second argument is an integer or a list of integers,
there is no restriction for P, as long as it is a polynomial.
However, when the second argument is a list of functions, and even if these
functions are all polynomials, P must be expanded in the given basis.
For instance, if the second argument is 2 or [|0, 1, 2|], P can be given
in Horner form. However, if the second argument is [|1, x, x^2|], P must
be written as a linear combination of 1, x and x^2, otherwise, the algorithm
will fail to recover the coefficients of P and will fail with an error
message.
Please also note that recovering the coefficients of P in an arbitrary
basis is performed heuristically and no verification is performed to check
that P does not contain other functions than the functions of the basis.
For all these reasons, it is sometimes useful to provide a list of
coefficients Lcoeffs instead of P. In this case, the convention is that the
i-th element of Lcoeffs is the coefficient of the i-th basis function in the
minimax polynomial. Lcoeffs might contain more elements than there are basis
functions, in which case the extra elements will be ignored.
- For historical reasons, fpminimax and remez have different syntaxes.
Indeed, the syntax of fpminimax has been designed to be higher level and
closer to usual customer needs. However, the reader's attention is drawn on
the fact that this could be confusing: the argument f in fpminimax is always
the function to be approximated, regardless of the mode (absolute or
relative) which is passed as a separate argument, while remez takes two
arguments f and w and looks for the approximation p that minimizes f-p*w
(with w=1 by default). Therefore, in remez looking for the approximation p
that minimizes the relative error with respect to a given function g is
performed by taking f=1 and w=1/g.
It may seem at first sight that the syntax of remez is more powerful
than fpminimax as one can imagine to simultaneously use a non trivial f and a
non trivial w, hence performing a weighted approximation. The same result can
actually be achieved with fpminimax (to the price of a slightly more involved
syntax) by approximating f in the customed monomial basis formed of w,
w(x)*x, w(x)*x^2, ..., w(x)*x^j, etc.
- Note that fpminimax internally computes a minimax polynomial (using
the same algorithm as remez command). Thus fpminimax may encounter
the same problems as remez. In particular, it may be very slow
when Haar condition is not fulfilled. Another consequence is that
currently fpminimax has to be run with a sufficiently high working precision.
Example 1:
> P = fpminimax(cos(x),6,[|DD, DD, D...|],[-1b-5;1b-5]);
> printexpansion(P);
(0x3ff0000000000000 + 0xbc09fda15e029b00) + x * ((0x3af9eb57163024a8 + 0x37942c2f3f3e3839) + x * (0xbfdfffffffffff98 + x * (0xbbd1693f9c028849 + x * (0x3fa5555555145337 + x * (0x3c7a25f610ad9ebc + x * 0xbf56c138142da5b0)))))
Example 2:
> P = fpminimax(sin(x),6,[|32...|],[-1b-5;1b-5], fixed, absolute);
> display = powers!;
> P;
x * (1 + x^2 * (-357913941 * 2^(-31) + x^2 * (35789873 * 2^(-32))))
Example 3:
> P = fpminimax(exp(x), [|3,4|], [|D,24|], [-1/256; 1/246], 1+x+x^2/2);
> display = powers!;
> P;
1 + x * (1 + x * (1 * 2^(-1) + x * (375300225001191 * 2^(-51) + x * (5592621 * 2^(-27)))))
Example 4:
> print("Weighted approximation: look for p such that (p-f)*w is small");
Weighted approximation: look for p such that (p-f)*w is small
> n = 3;
> f = exp(x);
> w = sqrt(1-x^2);
> monomials = [||];
> for i from 0 to n do { monomials = monomials :. x^i*sqrt(1-x^2); };
> q = fpminimax(f*w, monomials, [|D...|], [-99/100,99/100],absolute);
> display = dyadic!;
> print(q);
3194834406077049b-54 * x^3 * sqrt(1 - x^2) + 4792048811386295b-53 * x^2 * sqrt(1 - x^2) + 8982938415377717b-53 * x * sqrt(1 - x^2) + 561436817847349b-49 * sqrt(1 - x^2)
> leadingcoeff = proc(expr) {
var res;
match(expr) with
a*b+c : {res = [|a,c|]; }
a*b : {res = [|a,0|]; }
default: {res = error; };
return res;
};
> p = 0;
> for i from n to 0 by -1 do {
L = leadingcoeff(q);
p = p + L[0]*x^i;
q = L[1];
};
> print(p);
3194834406077049b-54 * x^3 + 4792048811386295b-53 * x^2 + 8982938415377717b-53 * x + 561436817847349b-49 * x^0
> display=decimal!;
> dirtyinfnorm((p-f)*w, [-1,1]);
2.7416001717508988167160223812127007458632536307517e-3
> r = remez(f*w,n,[-99/100,99/100],w);
> dirtyinfnorm((r-f)*w, [-1,1]);
2.7416001717508734413506680717675258974378965304354e-3
Example 5:
> I = [-1b-20, 1b-22];
> P0 = fpminimax(exp(x), 4, [|DD,DD,DD,D,SG|], I);
> P1 = fpminimax(exp(x), 4, [|D,D,D,D,SG|], I, 1+x+x^2/2);
> for k from 0 to 2 do { DD(coeff(P0,k)) == coeff(P0,k); };
true
true
true
> for k from 0 to 2 do { DD(coeff(P1,k)) == coeff(P1,k); };
true
true
true
> dirtyinfnorm(P0/exp(x)-1, I);
6.2744565211592155928616387674345117702132844508175e-35
> dirtyinfnorm(P1/exp(x)-1, I);
5.8284777124834959383794298527146965060524845952998e-35
Example 6:
> f = cos(exp(x));
> pstar = remez(f, 5, [-1b-7;1b-7]);
> listpoints = dirtyfindzeros(f-pstar, [-1b-7; 1b-7]);
> P1 = fpminimax(f, 5, [|DD...|], listpoints, absolute, default, default, pstar);
> P2 = fpminimax(f, 5, [|D...|], listpoints, absolute, default, default, pstar);
> P3 = fpminimax(f, 5, [|D, D, D, 24...|], listpoints, absolute, default, default, pstar);
> print("Error of pstar: ", dirtyinfnorm(f-pstar, [-1b-7; 1b-7]));
Error of pstar: 7.9048441259903026332577436001060063099817726177425e-16
> print("Error of P1: ", dirtyinfnorm(f-P1, [-1b-7; 1b-7]));
Error of P1: 7.9048441259903026580081299123420463921479618202064e-16
> print("Error of P2: ", dirtyinfnorm(f-P2, [-1b-7; 1b-7]));
Error of P2: 8.2477144579950871737109573536791331686347620955985e-16
> print("Error of P3: ", dirtyinfnorm(f-P3, [-1b-7; 1b-7]));
Error of P3: 1.08454277156993282593701156841863009789063333951055e-15
Example 7:
> L = [|exp(x), sin(x), cos(x)-1, sin(x^3)|];
> g = (2^x-1)/x;
> p = fpminimax(g, L, [|D...|], [-1/16;1/16],absolute);
> display = powers!;
> p;
-3267884797436153 * 2^(-54) * sin(x^3) + 5247089102535885 * 2^(-53) * (cos(x) - 1) + -8159095033730771 * 2^(-54) * sin(x) + 6243315658446641 * 2^(-53) * exp(x)
Example 8:
> n = 9;
> T = [|1, x|];
> for i from 2 to n do T[i] = canonical(2*x*T[i-1]-T[i-2]);
> g = (2^x-1)/x;
> PCheb = fpminimax(g, T, [|DD,DE...|], [-1/16;1/16],absolute);
> display = dyadic!;
> print(PCheb);
112469560253864905423137861008261b-107 + x * (76130818934358736339243350051b-98 + x * (34355379230514621195759363b-89 + x * (381013348011182609334519067b-95 + x * (825307274780189286345649b-89 + x * (3050983523250669954220137b-94 + x * (1180123116639845252291b-86 + x * (6543992088039485657053b-92 + x * (15750497046710770365b-87 + x * 8733930098894247371b-90))))))))
Example 9:
> d = [46768052394588893382517914646921056628989841b-165;1b-7];
> n = 4; f = 1; w = sqrt(x)/acos(1-x);
> p = remez(f, n, d, w);
> monomials = [||]; Lcoeffs = [||];
> for i from 0 to n do {
monomials = monomials :. x^i*sqrt(x);
Lcoeffs = Lcoeffs :. coeff(p, i);
};
> pf = fpminimax(acos(1-x), monomials, [|D...|], d, relative, floating, 0, Lcoeffs);
> display = dyadic!;
> print(pf);
6237591828287231b-61 * x^4 * sqrt(x) + 1137310727877715b-57 * x^3 * sqrt(x) + 7642862123083659b-58 * x^2 * sqrt(x) + 1061508612083747b-53 * x * sqrt(x) + 6369051672525773b-52 * sqrt(x)
See also: remez,
dirtyfindzeros,
absolute,
relative,
fixed,
floating,
default,
halfprecision,
single,
double,
doubleextended,
doubledouble,
quad,
tripledouble,
implementpoly,
coeff,
degree,
roundcoefficients,
guessdegree
Go back to the list of commands
Name:
fullparentheses
activates, deactivates or inspects the state variable controlling output with full parenthesising
Library names:
void sollya_lib_set_fullparentheses_and_print(sollya_obj_t);
void sollya_lib_set_fullparentheses(sollya_obj_t);
sollya_obj_t sollya_lib_get_fullparentheses();
Parameters:
- activation value represents on or off, i.e. activation or deactivation
Description:
- An assignment fullparentheses = activation value, where activation value
is one of on or off, activates respectively deactivates the output
of expressions with full parenthesising. In full parenthesising mode,
Sollya commands like print, write and the implicit command when an
expression is given at the prompt will output expressions with
parenthesising at all places where it is necessary for expressions
containing infix operators to be parsed back with the same
result. Otherwise parentheses around associative operators are
omitted.
If the assignment fullparentheses = activation value is followed by an
exclamation mark, no message indicating the new state is
displayed. Otherwise the user is informed of the new state of the
global mode by an indication.
Example 1:
> autosimplify = off!;
> fullparentheses = off;
Full parentheses mode has been deactivated.
> print(1 + 2 + 3);
1 + 2 + 3
> fullparentheses = on;
Full parentheses mode has been activated.
> print(1 + 2 + 3);
(1 + 2) + 3
Go back to the list of commands
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
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))
See also: proc,
library,
procedure,
externalproc,
boolean,
constant,
integer,
list of,
range,
string,
object
Go back to the list of commands
Name:
gcd
Computes the greatest common divisor of polynomials or numbers.
Library name:
sollya_obj_t sollya_lib_gcd(sollya_obj_t, sollya_obj_t)
Usage:
gcd(p, q) : (function, function) -> function
Parameters:
- p is a constant or a polynomial.
- q is a constant or a polynomial.
Description:
- When both p and q are integers, gcd(p,q) computes the greatest
common divisor of these two integers, i.e. the greatest non-negative integer
dividing both p and q.
- When both p and q are rational numbers, say a/b and c/d,
gcd(p,q) computes the greatest common divisor of a * d and b * c,
divided by the product of the denominators, b * d.
- When both p and q are constants but at least one of them is no rational
number, gcd(p,q) returns 1.
- When both p and q are polynomials with at least one being non-constant,
gcd(p,q) returns the polynomial of greatest degree dividing both p and
q, and whose leading coefficient is the greatest common divisor of the
leading coefficients of p and q.
- Similarly to the cases documented for div and mod, gcd
may fail to return the unique polynomial of largest degree dividing
both p and q in cases when certain coefficients of either p or
q are constant expressions for which the tool is unable to determine
whether they are zero or not. These cases typically involve
polynomials whose leading coefficient is zero but the tool is unable
to detect this fact.
- When at least one of p or q is a function that is no polynomial,
gcd(p,q) returns 1.
Example 1:
> gcd(1001, 231);
77
> gcd(13, 17);
1
> gcd(-210, 462);
42
Example 2:
> rationalmode = on!;
> gcd(6/7, 33/13);
3 / 91
Example 3:
> gcd(exp(13),sin(17));
1
Example 4:
> gcd(24 + 68 * x + 74 * x^2 + 39 * x^3 + 10 * x^4 + x^5, 480 + 776 * x + 476 * x^2 + 138 * x^3 + 19 * x^4 + x^5);
4 + x * (4 + x)
> gcd(1001 * x^2, 231 * x);
x * 77
Example 5:
> gcd(exp(x), x^2);
1
Go back to the list of commands
Name:
>=
greater-than-or-equal-to operator
Library name:
sollya_obj_t sollya_lib_cmp_greater_equal(sollya_obj_t, sollya_obj_t)
Usage:
expr1 >= expr2 : (constant, constant) -> boolean
Parameters:
- expr1 and expr2 represent constant expressions
Description:
- The operator >= evaluates to true iff its operands expr1 and
expr2 evaluate to two floating-point numbers a1
respectively a2 with the global precision prec and
a1 is greater than or equal to a2. The user should
be aware of the fact that because of floating-point evaluation, the
operator >= is not exactly the same as the mathematical
operation "greater-than-or-equal-to".
Example 1:
> 5 >= 4;
true
> 5 >= 5;
true
> 5 >= 6;
false
> exp(2) >= exp(1);
true
> log(1) >= exp(2);
false
Example 2:
> prec = 12;
The precision has been set to 12 bits.
> 16384.1 >= 16385.1;
true
See also: ==,
!=,
>,
<=,
<,
in,
!,
&&,
||,
prec,
max,
min
Go back to the list of commands
Name:
getbacktrace
returns the list of Sollya procedures currently run
Library name:
sollya_obj_t sollya_lib_getbacktrace();
Description:
- The getbacktrace command allows the stack of Sollya procedures that are
currently run to be inspected. When called, getbacktrace returns an
ordered list of structures, each of which contains an element
passed_args and an element called_proc. The element called_proc
contains the Sollya object representing the procedure being run. The
element passed_args contains an ordered list of all effective
arguments passed to the procedure when it was called. The procedure called
last (i.e., on top of the stack) comes first in the list returned
by getbacktrace. When any of the procedure called takes no arguments, the
passed_arg element of the corresponding structure evaluates to an empty
list.
- When called from outside any procedure (at toplevel), getbacktrace returns
an empty list.
- When called for a stack containing a call to a variadic procedure that was
called with an infinite number of effective arguments, the corresponding
passed_args element evaluates to an end-elliptic list.
Example 1:
> procedure testA() {
"Current backtrace:";
getbacktrace();
};
> procedure testB(X) {
"X = ", X;
testA();
};
> procedure testC(X, Y) {
"X = ", X, ", Y = ", Y;
testB(Y);
};
> testC(17, 42);
X = 17, Y = 42
X = 42
Current backtrace:
[|{ .passed_args = [| |], .called_proc = proc()
{
"Current backtrace:";
getbacktrace();
return void;
} }, { .passed_args = [|42|], .called_proc = proc(X)
{
"X = ", X;
testA();
return void;
} }, { .passed_args = [|17, 42|], .called_proc = proc(X, Y)
{
"X = ", X, ", Y = ", Y;
testB(Y);
return void;
} }|]
Example 2:
> getbacktrace();
[| |]
Example 3:
> procedure printnumargs(X) {
var L, t;
"number of arguments: ", X;
L = getbacktrace();
"Backtrace:";
for t in L do {
" " @ objectname(t.called_proc) @ ", ", t.passed_args;
};
};
> procedure numargs(l = ...) {
"l[17] = ", l[17];
printnumargs(length(l));
};
> procedure test() {
numargs @ [|25, 26, 27 ...|];
};
> test();
l[17] = 42
number of arguments: infty
Backtrace:
printnumargs, [|infty|]
numargs, [|25, 26, 27...|]
test, [| |]
Go back to the list of commands
Name:
getsuppressedmessages
returns a list of numbers of messages that have been suppressed from message output
Library name:
sollya_obj_t sollya_lib_getsuppressedmessages();
Description:
- The getsuppressedmessages command allows the user to inspect the state of warning
and information message suppression. When called, getsuppressedmessages returns a
list of integers numbers that stand for the warning and information
messages that have been suppressed. If no message is suppressed,
getsuppressedmessages returns an empty list.
- Every Sollya warning or information message (that is not fatal to the
tool's execution) has a message number. By default, these numbers are
not displayed when a message is output. When message number displaying
is activated using showmessagenumbers, the message numbers are
displayed together with the message. This allows the user to match the
numbers returned in a list by getsuppressedmessages with the actual warning and
information messages.
- The list of message numbers returned by getsuppressedmessages is suitable to be fed
into the unsuppressmessage command. This way, the user may unsuppress
all warning and information messages that have been suppressed.
Example 1:
> verbosity = 1;
The verbosity level has been set to 1.
> 0.1;
Warning: Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> suppressmessage(174);
> 0.1;
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> suppressmessage(407);
> 0.1;
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> getsuppressedmessages();
[|174, 407|]
> suppressmessage(207, 196);
> getsuppressedmessages();
[|174, 196, 207, 407|]
Example 2:
> suppressmessage(174, 209, 13, 24, 196);
> suppressmessage([| 16, 17 |]);
> suppressmessage(19);
> unsuppressmessage([| 13, 17 |]);
> getsuppressedmessages();
[|16, 19, 24, 174, 196, 209|]
> unsuppressmessage(getsuppressedmessages());
> getsuppressedmessages();
[| |]
Example 3:
> verbosity = 12;
The verbosity level has been set to 12.
> suppressmessage(174);
> exp(x * 0.1);
Information: no Horner simplification will be performed because the given tree is already in Horner form.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
exp(x * 0.1)
> getsuppressedmessages();
[|174|]
> verbosity = 0;
The verbosity level has been set to 0.
> exp(x * 0.1);
exp(x * 0.1)
> getsuppressedmessages();
[|174|]
Go back to the list of commands
Name:
>
greater-than operator
Library name:
sollya_obj_t sollya_lib_cmp_greater(sollya_obj_t, sollya_obj_t)
Usage:
expr1 > expr2 : (constant, constant) -> boolean
Parameters:
- expr1 and expr2 represent constant expressions
Description:
- The operator > evaluates to true iff its operands expr1 and
expr2 evaluate to two floating-point numbers a1
respectively a2 with the global precision prec and
a1 is greater than a2. The user should
be aware of the fact that because of floating-point evaluation, the
operator > is not exactly the same as the mathematical
operation "greater-than".
Example 1:
> 5 > 4;
true
> 5 > 5;
false
> 5 > 6;
false
> exp(2) > exp(1);
true
> log(1) > exp(2);
false
Example 2:
> prec = 12;
The precision has been set to 12 bits.
> 16385.1 > 16384.1;
false
See also: ==,
!=,
>=,
<=,
<,
in,
!,
&&,
||,
prec,
max,
min
Go back to the list of commands
Name:
guessdegree
returns the minimal degree needed for a polynomial to approximate a function with a certain error on an interval.
Library names:
sollya_obj_t sollya_lib_guessdegree(sollya_obj_t, sollya_obj_t,
sollya_obj_t, ...)
sollya_obj_t sollya_lib_v_guessdegree(sollya_obj_t, sollya_obj_t,
sollya_obj_t, va_list)
Usage:
guessdegree(f,I,eps,w,bound) : (function, range, constant, function, constant) -> range
Parameters:
- f is the function to be approximated.
- I is the interval where the function must be approximated.
- eps is the maximal acceptable error.
- w (optional) is a weight function. Default is 1.
- bound (optional) is a bound on the degree. Default is currently 128.
Description:
- guessdegree tries to find the minimal degree needed to approximate f
on I by a polynomial with an error err=p*w-f whose infinity norm not
greater than eps. More precisely, it finds n minimal such that there exists
a polynomial p of degree n such that ||p*w-f|| < eps.
- guessdegree returns an interval: for common cases, this interval is reduced
to a single number (i.e. the minimal degree). But in certain cases,
guessdegree does not succeed in finding the minimal degree. In such cases the
returned interval is of the form [n,p] such that:
- no polynomial of degree n-1 gives an error less than eps.
- there exists a polynomial of degree p giving an error less than eps.
- The fifth optional argument bound is used to prevent guessdegree from
trying to find too large degrees. If guessdegree does not manage to find a
degree n satisfying the error and such that n<=bound, an interval of the
form [*, +Inf] is returned. Note that bound must be a positive integer.
Example 1:
> guessdegree(exp(x),[-1;1],1e-10);
[10;10]
Example 2:
> guessdegree(exp(x),[-1;1],1e-10,default, 9);
[10;infty]
Example 3:
> guessdegree(1, [-1;1], 1e-8, 1/exp(x));
[8;9]
Go back to the list of commands
Names:
halfprecision,
HP
rounding to the nearest IEEE 754 half-precision number (binary16).
Library names:
sollya_obj_t sollya_lib_halfprecision(sollya_obj_t)
sollya_obj_t sollya_lib_halfprecision_obj()
int sollya_lib_is_halfprecision_obj(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_halfprecision(sollya_obj_t)
#define SOLLYA_HP(x) sollya_lib_build_function_halfprecision(x)
Description:
- halfprecision is both a function and a constant.
- As a function, it rounds its argument to the nearest IEEE 754 half-precision (i.e. IEEE754-2008 binary16) number.
Subnormal numbers are supported as well as standard numbers: it is the real
rounding described in the standard.
- As a constant, it symbolizes the half-precision format. It is used in
contexts when a precision format is necessary, e.g. in the commands
round and roundcoefficients. It is not supported for implementpoly.
See the corresponding help pages for examples.
Example 1:
> display=binary!;
> HP(0.1);
1.100110011_2 * 2^(-4)
> HP(4.17);
1.00001011_2 * 2^(2)
> HP(1.011_2 * 2^(-23));
1.1_2 * 2^(-23)
See also: single,
double,
doubleextended,
doubledouble,
quad,
tripledouble,
roundcoefficients,
fpminimax,
implementpoly,
round,
printsingle
Go back to the list of commands
Name:
head
gives the first element of a list.
Library name:
sollya_obj_t sollya_lib_head(sollya_obj_t)
Usage:
head(L) : list -> any type
Description:
- head(L) returns the first element of the list L. It is equivalent
to L[0].
- If L is empty, the command will fail with an error.
Example 1:
> head([|1,2,3|]);
1
> head([|1,2...|]);
1
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_hexadecimal()
int sollya_lib_is_hexadecimal(sollya_obj_t)
Description:
- hexadecimal is a special value used for the global state display. If
the global state display is equal to hexadecimal, all data will be
output in hexadecimal C99/ IEEE 754-2008 notation.
As any value it can be affected to a variable and stored in lists.
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_honorcoeffprec()
int sollya_lib_is_honorcoeffprec(sollya_obj_t)
Description:
- Used with command implementpoly, honorcoeffprec makes implementpoly honor
the precision of the given polynomial. This means if a coefficient
needs a double-double or a triple-double to be exactly stored,
implementpoly will allocate appropriate space and use a double-double
or triple-double operation even if the automatic (heuristic)
determination implemented in command implementpoly indicates that the
coefficient could be stored on less precision or, respectively, the
operation could be performed with less precision. See implementpoly
for details.
Example 1:
> verbosity = 1!;
> q = implementpoly(1 - dirtysimplify(TD(1/6)) * x^2,[-1b-10;1b-10],1b-60,DD,"p","implementation.c");
Warning: at least one of the coefficients of the given polynomial has been rounded in a way
that the target precision can be achieved at lower cost. Nevertheless, the implemented polynomial
is different from the given one.
> printexpansion(q);
0x3ff0000000000000 + x^2 * 0xbfc5555555555555
> r = implementpoly(1 - dirtysimplify(TD(1/6)) * x^2,[-1b-10;1b-10],1b-60,DD,"p","implementation.c",honorcoeffprec);
Warning: the inferred precision of the 2th coefficient of the polynomial is greater than
the necessary precision computed for this step. This may make the automatic determination
of precisions useless.
> printexpansion(r);
0x3ff0000000000000 + x^2 * (0xbfc5555555555555 + 0xbc65555555555555 + 0xb905555555555555)
Go back to the list of commands
Name:
hopitalrecursions
controls the number of recursion steps when applying L'Hopital's rule.
Library names:
void sollya_lib_set_hopitalrecursions_and_print(sollya_obj_t)
void sollya_lib_set_hopitalrecursions(sollya_obj_t)
sollya_obj_t sollya_lib_get_hopitalrecursions()
Parameters:
- n represents the number of recursions
Description:
- hopitalrecursions is a global variable. Its value represents the number of steps of
recursion that are tried when applying L'Hopital's rule. This rule is applied
by the interval evaluator present in the core of Sollya (and particularly
visible in commands like infnorm).
- If an expression of the form f/g has to be evaluated by interval
arithmetic on an interval I and if f and g have a common zero
in I, a direct evaluation leads to NaN.
Sollya implements a safe heuristic to avoid this, based on L'Hopital's rule: in
such a case, it can be shown that (f/g)(I) C (f'/g')(I). Since
the same problem may exist for f'/g', the rule is applied recursively.
The number of step in this recursion process is controlled by hopitalrecursions.
- Setting hopitalrecursions to 0 makes Sollya use this rule only once;
setting it to 1 makes Sollya use the rule twice, and so on.
In particular: the rule is always applied at least once, if necessary.
Example 1:
> hopitalrecursions=0;
The number of recursions for Hopital's rule has been set to 0.
> evaluate(log(1+x)^2/x^2,[-1/2; 1]);
[NaN;NaN]
> hopitalrecursions=1;
The number of recursions for Hopital's rule has been set to 1.
> evaluate(log(1+x)^2/x^2,[-1/2; 1]);
[-2.5225887222397812376689284858327062723020005374411;6.7725887222397812376689284858327062723020005374412]
Go back to the list of commands
Name:
horner
brings all polynomial subexpressions of an expression to Horner form
Library name:
sollya_obj_t sollya_lib_horner(sollya_obj_t)
Usage:
horner(function) : function -> function
Parameters:
- function represents the expression to be rewritten in Horner form
Description:
- The command horner rewrites the expression representing the function
function in a way such that all polynomial subexpressions (or the
whole expression itself, if it is a polynomial) are written in Horner
form. The command horner does not endanger the safety of
computations even in Sollya's floating-point environment: the
function returned is mathematically equal to the function function.
Example 1:
> print(horner(1 + 2 * x + 3 * x^2));
1 + x * (2 + x * 3)
> print(horner((x + 1)^7));
1 + x * (7 + x * (21 + x * (35 + x * (35 + x * (21 + x * (7 + x))))))
Example 2:
> print(horner(exp((x + 1)^5) - log(asin(x + x^3) + x)));
exp(1 + x * (5 + x * (10 + x * (10 + x * (5 + x))))) - log(asin(x * (1 + x^2)) + x)
Go back to the list of commands
Library names:
void sollya_lib_implementconstant(sollya_obj_t, ...);
void sollya_lib_v_implementconstant(sollya_obj_t, va_list);
Description:
- The command implementconstant implements the constant expression expr in
arbitrary precision. More precisely, it generates the source code (written
in C, and using MPFR) of a C function const_something with the following
signature:
void const_something (mpfr_ptr y, mp_prec_t prec)
Let us denote by c the exact mathematical value of the constant defined by
the expression expr. When called with arguments y and prec (where the
variable y is supposed to be already initialized), the function
mpfr_const_something sets the precision of y to a suitable precision and
stores in it an approximate value of c such that
|y-c| <= |c|*2^(1-prec).
- When no filename filename is given or if default is given as
filename, the source code produced by implementconstant is printed on
standard output. Otherwise, when filename is given as a
string of characters, the source code is output to a file
named filename. If that file cannot be opened and/or
written to, implementconstant fails and has no other effect.
- When functionname is given as an argument to implementconstant and
functionname evaluates to a string of characters, the default name
for the C function const_something is
replaced by functionname. When default is given as functionname,
the default name is used nevertheless, as if no functionname
argument were given. When choosing a character sequence for
functionname, the user should keep attention to the fact that
functionname must be a valid C identifier in order to enable
error-free compilation of the produced code.
- If expr refers to a constant defined with libraryconstant, the produced
code uses the external code implementing this constant. The user should
keep in mind that it is up to them to make sure the symbol for that
external code can get resolved when the newly generated code is to
be loaded.
- If a subexpression of expr evaluates to 0, implementconstant will most
likely fail with an error message.
- implementconstant is unable to implement constant expressions expr that
contain procedure-based functions, i.e. functions created from Sollya
procedures using the function construct. If expr contains such a
procedure-based function, implementconstant prints a warning and fails
silently. The reason for this lack of functionality is that the
produced C source code, which is supposed to be compiled, would have
to call back to the Sollya interpreter in order to evaluate the
procedure-based function.
- Similarly, implementconstant is currently unable to implement constant
expressions expr that contain library-based functions, i.e.
functions dynamically bound to Sollya using the library construct.
If expr contains such a library-based function, implementconstant prints
a warning and fails silently. Support for this feature is in principle
feasible from a technical standpoint and might be added in a future
release of Sollya.
- Currently, non-differentiable functions such as double, doubledouble,
tripledouble, single, halfprecision, quad, doubleextended,
floor, ceil, nearestint are not supported by implementconstant.
If implementconstant encounters one of them, a warning message is displayed
and no code is produced. However, if autosimplify equals on, it is
possible that Sollya silently simplifies subexpressions of expr
containing such functions and that implementconstant successfully produces
code for evaluating expr.
- While it produces an MPFR-based C source code for expr, implementconstant
takes architectural and system-dependent parameters into account. For
example, it checks whether literal constants figuring in expr can be
represented on a C long int type or if they must
be stored in a different manner not to affect their accuracy. These
tests, performed by Sollya during execution of implementconstant, depend
themselves on the architecture Sollya is running on. Users should
keep this matter in mind, especially when trying to compile source
code on one machine whilst it has been produced on another.
Example 1:
> implementconstant(exp(1)+log(2)/sqrt(1/10));
modify or redistribute this generated code itself, or its skeleton,
you may (at your option) remove this special exception, which will
cause this generated code and its skeleton and the resulting Sollya
output files to be licensed under the CeCILL-C licence without this
special exception.
This special exception was added by the Sollya copyright holders in
version 4.1 of Sollya.
*/
#include <mpfr.h>
void
const_something (mpfr_ptr y, mp_prec_t prec)
{
/* Declarations */
mpfr_t tmp1;
mpfr_t tmp2;
mpfr_t tmp3;
mpfr_t tmp4;
mpfr_t tmp5;
mpfr_t tmp6;
mpfr_t tmp7;
/* Initializations */
mpfr_init2 (tmp2, prec+5);
mpfr_init2 (tmp1, prec+3);
mpfr_init2 (tmp4, prec+8);
mpfr_init2 (tmp3, prec+7);
mpfr_init2 (tmp6, prec+11);
mpfr_init2 (tmp7, prec+11);
mpfr_init2 (tmp5, prec+11);
/* Core */
mpfr_set_prec (tmp2, prec+4);
mpfr_set_ui (tmp2, 1, MPFR_RNDN);
mpfr_set_prec (tmp1, prec+3);
mpfr_exp (tmp1, tmp2, MPFR_RNDN);
mpfr_set_prec (tmp4, prec+8);
mpfr_set_ui (tmp4, 2, MPFR_RNDN);
mpfr_set_prec (tmp3, prec+7);
mpfr_log (tmp3, tmp4, MPFR_RNDN);
mpfr_set_prec (tmp6, prec+11);
mpfr_set_ui (tmp6, 1, MPFR_RNDN);
mpfr_set_prec (tmp7, prec+11);
mpfr_set_ui (tmp7, 10, MPFR_RNDN);
mpfr_set_prec (tmp5, prec+11);
mpfr_div (tmp5, tmp6, tmp7, MPFR_RNDN);
mpfr_set_prec (tmp4, prec+7);
mpfr_sqrt (tmp4, tmp5, MPFR_RNDN);
mpfr_set_prec (tmp2, prec+5);
mpfr_div (tmp2, tmp3, tmp4, MPFR_RNDN);
mpfr_set_prec (y, prec+3);
mpfr_add (y, tmp1, tmp2, MPFR_RNDN);
/* Cleaning stuff */
mpfr_clear(tmp1);
mpfr_clear(tmp2);
mpfr_clear(tmp3);
mpfr_clear(tmp4);
mpfr_clear(tmp5);
mpfr_clear(tmp6);
mpfr_clear(tmp7);
}
Example 2:
> implementconstant(sin(13/17),"sine_of_thirteen_seventeenth.c");
> bashevaluate("tail -n 30 sine_of_thirteen_seventeenth.c");
#include <mpfr.h>
void
const_something (mpfr_ptr y, mp_prec_t prec)
{
/* Declarations */
mpfr_t tmp1;
mpfr_t tmp2;
mpfr_t tmp3;
/* Initializations */
mpfr_init2 (tmp2, prec+6);
mpfr_init2 (tmp3, prec+6);
mpfr_init2 (tmp1, prec+6);
/* Core */
mpfr_set_prec (tmp2, prec+6);
mpfr_set_ui (tmp2, 13, MPFR_RNDN);
mpfr_set_prec (tmp3, prec+6);
mpfr_set_ui (tmp3, 17, MPFR_RNDN);
mpfr_set_prec (tmp1, prec+6);
mpfr_div (tmp1, tmp2, tmp3, MPFR_RNDN);
mpfr_set_prec (y, prec+2);
mpfr_sin (y, tmp1, MPFR_RNDN);
/* Cleaning stuff */
mpfr_clear(tmp1);
mpfr_clear(tmp2);
mpfr_clear(tmp3);
}
Example 3:
> implementconstant(asin(1/3 * pi),default,"arcsin_of_one_third_pi");
modify or redistribute this generated code itself, or its skeleton,
you may (at your option) remove this special exception, which will
cause this generated code and its skeleton and the resulting Sollya
output files to be licensed under the CeCILL-C licence without this
special exception.
This special exception was added by the Sollya copyright holders in
version 4.1 of Sollya.
*/
#include <mpfr.h>
void
arcsin_of_one_third_pi (mpfr_ptr y, mp_prec_t prec)
{
/* Declarations */
mpfr_t tmp1;
mpfr_t tmp2;
mpfr_t tmp3;
/* Initializations */
mpfr_init2 (tmp2, prec+8);
mpfr_init2 (tmp3, prec+8);
mpfr_init2 (tmp1, prec+8);
/* Core */
mpfr_set_prec (tmp2, prec+8);
mpfr_const_pi (tmp2, MPFR_RNDN);
mpfr_set_prec (tmp3, prec+8);
mpfr_set_ui (tmp3, 3, MPFR_RNDN);
mpfr_set_prec (tmp1, prec+8);
mpfr_div (tmp1, tmp2, tmp3, MPFR_RNDN);
mpfr_set_prec (y, prec+2);
mpfr_asin (y, tmp1, MPFR_RNDN);
/* Cleaning stuff */
mpfr_clear(tmp1);
mpfr_clear(tmp2);
mpfr_clear(tmp3);
}
Example 4:
> implementconstant(ceil(log(19 + 1/3)),"constant_code.c","magic_constant");
> bashevaluate("tail -n -9 constant_code.c");
void
magic_constant (mpfr_ptr y, mp_prec_t prec)
{
/* Initializations */
/* Core */
mpfr_set_prec (y, prec);
mpfr_set_ui (y, 3, MPFR_RNDN);
}
Example 5:
> bashexecute("gcc -fPIC -Wall -c libraryconstantexample.c -I$HOME/.local/include");
> bashexecute("gcc -shared -o libraryconstantexample libraryconstantexample.o -lgmp -lmpfr");
> euler_gamma = libraryconstant("./libraryconstantexample");
> implementconstant(euler_gamma^(1/3), "euler.c");
> bashevaluate("tail -n -17 euler.c");
void
const_something (mpfr_ptr y, mp_prec_t prec)
{
/* Declarations */
mpfr_t tmp1;
/* Initializations */
mpfr_init2 (tmp1, prec+1);
/* Core */
euler_gamma (tmp1, prec+1);
mpfr_set_prec (y, prec+2);
mpfr_root (y, tmp1, 3, MPFR_RNDN);
/* Cleaning stuff */
mpfr_clear(tmp1);
}
Go back to the list of commands
Name:
implementpoly
implements a polynomial using double, double-double and triple-double arithmetic and generates a Gappa proof
Library names:
sollya_obj_t sollya_lib_implementpoly(sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t, ...)
sollya_obj_t sollya_lib_v_implementpoly(sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t, va_list)
Usage:
implementpoly(polynomial, range, error bound, format, functionname, filename) : (function, range, constant, D|double|DD|doubledouble|TD|tripledouble, string, string) -> function
implementpoly(polynomial, range, error bound, format, functionname, filename, honor coefficient precisions) : (function, range, constant, D|double|DD|doubledouble|TD|tripledouble, string, string, honorcoeffprec) -> function
implementpoly(polynomial, range, error bound, format, functionname, filename, proof filename) : (function, range, constant, D|double|DD|doubledouble|TD|tripledouble, string, string, string) -> function
implementpoly(polynomial, range, error bound, format, functionname, filename, honor coefficient precisions, proof filename) : (function, range, constant, D|double|DD|doubledouble|TD|tripledouble, string, string, honorcoeffprec, string) -> function
Description:
- The command implementpoly implements the polynomial polynomial in range
range as a function called functionname in C code
using double, double-double and triple-double arithmetic in a way that
the rounding error (estimated at its first order) is bounded by error bound.
The produced code is output in a file named filename. The
argument format indicates the double, double-double or triple-double
format of the variable in which the polynomial varies, influencing
also in the signature of the C function.
If a seventh or eighth argument proof filename is given and if this
argument evaluates to a variable of type string, the command
implementpoly will produce a Gappa proof that the
rounding error is less than the given bound. This proof will be output
in Gappa syntax in a file name proof filename.
The command implementpoly returns the polynomial that has been
implemented. As the command implementpoly tries to adapt the precision
needed in each evaluation step to its strict minimum and as it applies
renormalization to double-double and triple-double precision
coefficients to bring them to a round-to-nearest expansion form, the
returned polynomial may differ from the polynomial
polynomial. Nevertheless the difference will be small enough that
the rounding error bound with regard to the polynomial polynomial
(estimated at its first order) will be less than the given error
bound.
If a seventh argument honor coefficient precisions is given and
evaluates to a variable honorcoeffprec of type honorcoeffprec,
implementpoly will honor the precision of the given polynomial
polynomials. This means if a coefficient needs a double-double or a
triple-double to be exactly stored, implementpoly will allocate appropriate
space and use a double-double or triple-double operation even if the
automatic (heuristic) determination implemented in command implementpoly
indicates that the coefficient could be stored on less precision or,
respectively, the operation could be performed with less
precision. The use of honorcoeffprec has advantages and
disadvantages. If the polynomial polynomial given has not been
determined by a process considering directly polynomials with
floating-point coefficients, honorcoeffprec should not be
indicated. The implementpoly command can then determine the needed
precision using the same error estimation as used for the
determination of the precisions of the operations. Generally, the
coefficients will get rounded to double, double-double and
triple-double precision in a way that minimizes their number and
respects the rounding error bound error bound. Indicating
honorcoeffprec may in this case short-circuit most precision
estimations leading to sub-optimal code. On the other hand, if the
polynomial polynomial has been determined with floating-point
precisions in mind, honorcoeffprec should be indicated because such
polynomials often are very sensitive in terms of error propagation with
regard to their coefficients' values. Indicating honorcoeffprec
prevents the implementpoly command from rounding the coefficients and
altering by many orders of magnitude the approximation error of the
polynomial with regard to the function it approximates.
The implementer behind the implementpoly command makes some assumptions on
its input and verifies them. If some assumption cannot be verified,
the implementation will not succeed and implementpoly will evaluate to a
variable error of type error. The same behaviour is observed if
some file is not writable or some other side-effect fails, e.g. if
the implementer runs out of memory.
As error estimation is performed only on the first order, the code
produced by the implementpoly command should be considered valid iff a
Gappa proof has been produced and successfully run
in Gappa.
Example 1:
> implementpoly(1 - 1/6 * x^2 + 1/120 * x^4, [-1b-10;1b-10], 1b-30, D, "p","implementation.c");
1 + x^2 * (-0.166666666666666657414808128123695496469736099243164 + x^2 * 8.3333333333333332176851016015461937058717012405396e-3)
> bashevaluate("tail -n -29 implementation.c");
#define p_coeff_0h 1.00000000000000000000000000000000000000000000000000000000000000000000000000000000e+00
#define p_coeff_2h -1.66666666666666657414808128123695496469736099243164062500000000000000000000000000e-01
#define p_coeff_4h 8.33333333333333321768510160154619370587170124053955078125000000000000000000000000e-03
void p(double *p_resh, double x) {
double p_x_0_pow2h;
p_x_0_pow2h = x * x;
double p_t_1_0h;
double p_t_2_0h;
double p_t_3_0h;
double p_t_4_0h;
double p_t_5_0h;
p_t_1_0h = p_coeff_4h;
p_t_2_0h = p_t_1_0h * p_x_0_pow2h;
p_t_3_0h = p_coeff_2h + p_t_2_0h;
p_t_4_0h = p_t_3_0h * p_x_0_pow2h;
p_t_5_0h = p_coeff_0h + p_t_4_0h;
*p_resh = p_t_5_0h;
}
Example 2:
> implementpoly(1 - 1/6 * x^2 + 1/120 * x^4, [-1b-10;1b-10], 1b-30, D, "p","implementation.c","implementation.gappa");
1 + x^2 * (-0.166666666666666657414808128123695496469736099243164 + x^2 * 8.3333333333333332176851016015461937058717012405396e-3)
Example 3:
> verbosity = 1!;
> q = implementpoly(1 - dirtysimplify(TD(1/6)) * x^2,[-1b-10;1b-10],1b-60,DD,"p","implementation.c");
Warning: at least one of the coefficients of the given polynomial has been rounded in a way
that the target precision can be achieved at lower cost. Nevertheless, the implemented polynomial
is different from the given one.
> printexpansion(q);
0x3ff0000000000000 + x^2 * 0xbfc5555555555555
> r = implementpoly(1 - dirtysimplify(TD(1/6)) * x^2,[-1b-10;1b-10],1b-60,DD,"p","implementation.c",honorcoeffprec);
Warning: the inferred precision of the 2th coefficient of the polynomial is greater than
the necessary precision computed for this step. This may make the automatic determination
of precisions useless.
> printexpansion(r);
0x3ff0000000000000 + x^2 * (0xbfc5555555555555 + 0xbc65555555555555 + 0xb905555555555555)
Example 4:
> p = 0x3ff0000000000000 + x * (0x3ff0000000000000 + x * (0x3fe0000000000000 + x * (0x3fc5555555555559 + x * (0x3fa55555555555bd + x * (0x3f811111111106e2 + x * (0x3f56c16c16bf5eb7 + x * (0x3f2a01a01a292dcd + x * (0x3efa01a0218a016a + x * (0x3ec71de360331aad + x * (0x3e927e42e3823bf3 + x * (0x3e5ae6b2710c2c9a + x * (0x3e2203730c0a7c1d + x * 0x3de5da557e0781df))))))))))));
> q = implementpoly(p,[-1/2;1/2],1b-60,D,"p","implementation.c",honorcoeffprec,"implementation.gappa");
> if (q != p) then print("During implementation, rounding has happened.") else print("Polynomial implemented as given.");
Polynomial implemented as given.
See also: honorcoeffprec,
roundcoefficients,
double,
doubledouble,
tripledouble,
bashevaluate,
printexpansion,
error,
remez,
fpminimax,
taylor,
implementconstant
Go back to the list of commands
Name:
inf
gives the lower bound of an interval.
Library name:
sollya_obj_t sollya_lib_inf(sollya_obj_t)
Usage:
inf(I) : range -> constant
inf(x) : constant -> constant
Parameters:
- I is an interval.
- x is a real number.
Description:
- Returns the lower bound of the interval I. Each bound of an interval has its
own precision, so this command is exact, even if the current precision is too
small to represent the bound.
- When called on a real number x, inf behaves like the identity.
Example 1:
> inf([1;3]);
1
> inf(0);
0
Example 2:
> display=binary!;
> I=[0.111110000011111_2; 1];
> inf(I);
1.11110000011111_2 * 2^(-1)
> prec=12!;
> inf(I);
1.11110000011111_2 * 2^(-1)
Go back to the list of commands
Name:
infnorm
computes an interval bounding the infinity norm of a function on an interval.
Library names:
sollya_obj_t sollya_lib_infnorm(sollya_obj_t, sollya_obj_t, ...)
sollya_obj_t sollya_lib_v_infnorm(sollya_obj_t, sollya_obj_t, va_list)
Usage:
infnorm(f,I,filename,Ilist) : (function, range, string, list) -> range
Parameters:
- f is a function.
- I is an interval.
- filename (optional) is the name of the file into a proof will be saved.
- IList (optional) is a list of intervals to be excluded.
Description:
- infnorm(f,range) computes an interval bounding the infinity norm of the
given function f on the interval I, e.g. computes an interval J
such that max {|f(x)|, x in I} C J.
- If filename is given, a proof in English will be produced (and stored in file
called filename) proving that max {|f(x)|, x in I} C J.
This feature of English proof generation is considered DEPRECATED in Sollya. The
feature will be removed in future versions of Sollya.
- If a list IList of intervals I1, ... ,In is given, the infinity norm will
be computed on I \ (I1 U ... U I2).
- The function f is assumed to be at least twice continuous on I. More
generally, if f is Ck, global variables hopitalrecursions and
taylorrecursions must have values not greater than k.
- If the interval is reduced to a single point, the result of infnorm is an
interval containing the exact absolute value of f at this point.
- If the interval is not bound, the result will be [0, +Inf]
which is correct but perfectly useless. infnorm is not meant to be used with
infinite intervals.
- The result of this command depends on the global variables prec, diam,
taylorrecursions and hopitalrecursions. The contribution of each variable is
not easy even to analyse.
- The algorithm uses interval arithmetic with precision prec. The
precision should thus be set high enough to ensure that no critical
cancellation will occur.
- When an evaluation is performed on an interval [a,b], if the result
is considered being too large, the interval is split into [a,(a+b)/2]
and [(a+b)/2,b] and so on recursively. This recursion step
is not performed if the (b-a) < d*|I| where d is the value
of variable diam. In other words, diam controls the minimum length of an
interval during the algorithm.
- To perform the evaluation of a function on an interval, Taylor's rule is
applied, e.g. f([a,b]) C f(m) + [a-m, b-m]*f'([a,b])
where m=(a+b)/2. This rule is recursively applied n times
where n is the value of variable taylorrecursions. Roughly speaking,
the evaluations will avoid decorrelation up to order n.
- When a function of the form g/h has to be evaluated on an
interval [a,b] and when g and h vanish at a same point
z of the interval, the ratio may be defined even if the expression
g(z)/h(z)=0/0 does not make any sense. In this case, L'Hopital's rule
may be used and (g/h)([a,b]) C (g'/h')([a,b]).
Since the same can occur with the ratio g'/h', the rule is applied
recursively. The variable hopitalrecursions controls the number of
recursion steps.
- The algorithm used for this command is quite complex to be explained here.
Please find a complete description in the following article:
S. Chevillard and C. Lauter
A certified infinity norm for the implementation of elementary functions
LIP Research Report number RR2007-26
http://prunel.ccsd.cnrs.fr/ensl-00119810
- Users should be aware about the fact that the algorithm behind
infnorm is inefficient in most cases and that other, better suited
algorithms, such as supnorm, are available inside Sollya. As a
matter of fact, while infnorm is maintained for compatibility reasons
with legacy Sollya codes, users are advised to avoid using infnorm
in new Sollya scripts and to replace it, where possible, by the
supnorm command.
Example 1:
> infnorm(exp(x),[-2;3]);
[20.085536923187667740928529654581717896987907838554;20.0855369231876677409285296545817178969879078385544]
Example 2:
> infnorm(exp(x),[-2;3],[| [0;1], [2;2.5] |]);
[20.085536923187667740928529654581717896987907838554;20.0855369231876677409285296545817178969879078385544]
Example 3:
> infnorm(exp(x),[1;1]);
[2.7182818284590452353602874713526624977572470936999;2.7182818284590452353602874713526624977572470937]
Example 4:
> infnorm(exp(x), [log(0);log(1)]);
[0;infty]
See also: prec,
diam,
hopitalrecursions,
taylorrecursions,
dirtyinfnorm,
checkinfnorm,
supnorm,
findzeros,
diff,
taylorrecursions,
autodiff,
numberroots,
taylorform
Go back to the list of commands
Name:
in
containment test operator
Library name:
sollya_obj_t sollya_lib_cmp_in(sollya_obj_t, sollya_obj_t)
Usage:
expr in range1 : (constant, range) -> boolean
range1 in range2 : (range, range) -> boolean
Parameters:
- expr represents a constant expression
- range1 and range2 represent ranges (intervals)
Description:
- When its first operand is a constant expression expr,
the operator in evaluates to true iff the constant value
of the expression expr is contained in the interval range1.
- When both its operands are ranges (intervals),
the operator in evaluates to true iff all values
in range1 are contained in the interval range2.
- in is also used as a keyword for loops over the different
elements of a list.
Example 1:
> 5 in [-4;7];
true
> 4 in [-1;1];
false
> 0 in sin([-17;17]);
true
Example 2:
> [5;7] in [2;8];
true
> [2;3] in [4;5];
false
> [2;3] in [2.5;5];
false
Example 3:
> for i in [|1,...,5|] do print(i);
1
2
3
4
5
See also: ==,
!=,
>=,
>,
<=,
<,
!,
&&,
||,
prec,
print
Go back to the list of commands
Name:
integer
keyword representing a machine integer type
Library name:
SOLLYA_EXTERNALPROC_TYPE_INTEGER
Description:
- integer represents the machine integer type for declarations
of external procedures externalproc.
Remark that in contrast to other indicators, type indicators like
integer cannot be handled outside the externalproc context. In
particular, they cannot be assigned to variables.
Go back to the list of commands
Name:
integral
computes an interval bounding the integral of a function on an interval.
Library name:
sollya_obj_t sollya_lib_integral(sollya_obj_t, sollya_obj_t)
Usage:
integral(f,I) : (function, range) -> range
Parameters:
- f is a function.
- I is an interval.
Description:
- integral(f,I) returns an interval J such that the exact value of
the integral of f on I lies in J.
- This command is safe but very inefficient. Use dirtyintegral if you just want
an approximate value.
- The result of this command depends on the global variable diam.
The method used is the following: I is cut into intervals of length not
greater then d*|I| where d is the value
of global variable diam.
On each small interval J, an evaluation of f by interval is
performed. The result is multiplied by the length of J. Finally all values
are summed.
Example 1:
> sin(10);
-0.54402111088936981340474766185137728168364301291622
> integral(cos(x),[0;10]);
[-0.54710197983579690224097637163525943075698599257333;-0.54094015130013183848150540881373370744053741191729]
> diam=1e-5!;
> integral(cos(x),[0;10]);
[-0.54432915685955427101857780295936956775293876382777;-0.54371306401249969508039644221927489010425803173555]
Go back to the list of commands
Name:
interpolate
computes an interpolation polynomial.
Library names:
sollya_obj_t sollya_lib_interpolate(sollya_obj_t, sollya_obj_t, ...)
sollya_obj_t sollya_lib_v_interpolate(sollya_obj_t, sollya_obj_t, va_list)
Usage:
interpolate(X, Y) : (list, list) -> function
interpolate(X, Y, D) : (list, list, constant) -> function
interpolate(X, Y, D, I) : (list, list, constant, range) -> function
interpolate(X, f) : (list, function) -> function
interpolate(X, f, D) : (list, function, constant) -> function
interpolate(X, f, D, I) : (list, function, constant, range) -> function
Parameters:
- X is a list of constants for the interpolation abscissas
- Y is a list of constants for the interpolation ordinates
- f is a function to be interpolated
- D is a constant defining the maximum permissible error
- I is an interval defining the domain to be considered for the error
Description:
- interpolate computes an interpolation polynomial p of minimal degree such
that for all given abscissa points xi in the list X the interpolation
condition is fullfilled with p(xi) = yi, where yi is the corresponding entry
in the list of ordinates Y. All entries of the lists X and Y need to be
constant expressions; the entries in the list of abscissas X need to be
pairwise distinct. If no parameter D is given, the interpolation is exact,
i.e., an interpolation polynomial (expression) is formed such that the
interpolation condition is satisfied without error.
- interpolate accepts a function f instead of a list of ordinates. When
called in this manner, interpolate computes a polynomial p such that for all
given abscissa points xi in the list X the interpolation condition is
fullfilled with p(xi) = f(xi). All entries in the list X still need to be
constant expressions and they must be pairwise distinct. If no parameter D
is given, the interpolation stays exact, even if this means forming constant
expressions for the ordinates f(xi).
- As exact interpolation is often not needed and in order to speed up
computations, interpolate accepts an optional parameter D, a positive
constant, that defines the maximum permissible error. In this case, instead
of computing the exact interpolation polynomial p as it is defined above,
interpolate computes and returns an approximate interpolation polynomial p~
that does not differ from p more than the amount D with supremum norm over
the interval I that is given by the interval of all abscissa points in X.
Formally, let I be the convex hull of all abscissa points in X; typically,
the lower bound of I is the minimum value amongst all X, the upper bound is
the maximum value amongst all X. Let p be the unique polynomial such that
p(xi) = yi for all xi in the list X and yi either the corresponding entry
in the list Y or yi = f(xi). Then interpolate returns p~ such that
||p~ - p ||^I <= D.
The support for D works for any list of distinct abscissa points X and
for any list of ordinate points Y or function f. The algorithm is however
optimized for the case when X is a list of floating-point (or rational)
constants and a function f. When f is a polynomial of degree n and X
contains at most n+1 abscissa points, interpolate may return f as-is, even
though D has been provided; typically without performing any rounding on
the coefficients of the polynomial f.
- When a permissible-error argument D is given to interpolate, the command
additionnally supports an optional interval parameter I. If this parameter
is specified, the interval I to consider the error between p~ and p on is not
taken as the convex hull of the abscissa points X but assumed to be the
interval I. This parameter is supported to both allow for interpolation over
intervals where the first (or last) interpolation point does not lie on the
lower (resp. upper) bound of the interval and to speed up computation:
determining the minimum and maximum values in X may be expensive.
- interpolate is completely insensible to the tool's working precision prec.
It adapts its own working precision entirely automatically. However the user
should be aware that precision adaption comes at a price: if the
interpolation problem requires high precision to be solved, the execution
time of interpolate will be high. This can typically be observed when the
list of abscissas X contains two values that are mathematically different
but for which high precision is needed to distinguish them.
- In case of error, e.g., when the abscissa points in X are not all
distinct, when the function does not evaluate at one of the abscissa points
or when the permissible error D or domain interval I are not acceptable,
interpolate evaluates to error.
Example 1:
> p = interpolate([| 1, 2, 3 |], [| 3, 5, 9 |]);
> write("p = ", p, "\n");
p = 3 + _x_ * (-1 + _x_)
Example 2:
> p = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |]);
> write("p = ", p, "\n");
p = 21 + _x_ * (-100 / 3 + _x_ * (15.5 + _x_ * -13 / 6))
> p = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |], 2^-17);
> write("p = ", p, "\n");
p = 21 + _x_ * (-33.333333492279052734375 + _x_ * (15.5 + _x_ * (-2.1666666567325592041015625)))
> p = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |], 2^-17, [0; 2^42]);
> write("p = ", p, "\n");
p = 21 + _x_ * (-33.333333333333333333333333333333333333333333363228 + _x_ * (15.5 + _x_ * (-2.1666666666666666666666666666666666666666666647983)))
Example 3:
> p = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |]);
> q = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |], 2^-17);
> delta = horner(p - q);
> write("delta = ", delta, "\n");
delta = _x_ * (1 / 6291456 + _x_^2 * -1 / 100663296)
> Delta = dirtyinfnorm(delta,[1;4]);
> "Delta = ", Delta, " = 2^(", log2(Delta), ")";
Delta = 2.4471294368728034316556666925301338011322095712879e-7 = 2^(-21.962406251802890453634347359869541271899536019231)
> p = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |]);
> q = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |], 2^-2000);
> delta = horner(p - q);
> write("delta = ", delta, "\n");
delta = _x_ * (1 / 4.4088218698531373730540794925222988186456999760206e604 + _x_^2 * -1 / 7.054114991765019796886527188035678109833119961633e605)
> Delta = dirtyinfnorm(delta,[1;4]);
> "Delta = ", Delta, " = 2^(", log2(Delta), ")";
Delta = 3.4920910013773992744476948245123751988401933577684e-605 = 2^(-2007.9624062518028904536343473598695412718995360192)
Example 4:
> p = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |]);
> q = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |], 2^-17, [0;2^10]);
> delta = horner(p - q);
> write("delta = ", delta, "\n");
delta = _x_ * (1 / 422212465065984 + _x_^2 * -1 / 6755399441055744)
> Delta = dirtyinfnorm(delta,[0;2^10]);
> "Delta = ", Delta, " = 2^(", log2(Delta), ")";
Delta = 1.589432940818369388580322265625e-7 = 2^(-22.584984514668420136955755457026138868402791643092)
> p = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |]);
> q = interpolate([| 1, 2, 3, 4 |], [| 1, -1, 2, -3 |], 2^-2000, [0;2^10]);
> delta = horner(p - q);
> write("delta = ", delta, "\n");
delta = _x_ * (-1 / 3.6983878408024986992700435663608496048481867984446e611 + _x_^2 * 1 / 5.9174205452839979188320697061773593677570988775114e612)
> Delta = dirtyinfnorm(delta,[0;2^10]);
> "Delta = ", Delta, " = 2^(", log2(Delta), ")";
Delta = 1.8145160239721784427448462541908690004638874174061e-604 = 2^(-2005.58498451466842013695575545702613886840279164307)
Example 5:
> p = interpolate([| 1, 2, 3, 4 |], 17 + _x_ * (42 + _x_ * (23 + _x_ * 1664)));
> write("p = ", p, "\n");
p = 17 + _x_ * (42 + _x_ * (23 + _x_ * 1664))
Example 6:
> p = interpolate([| 1, 2, 3, 4 |], exp(_x_));
> write("p = ", p, "\n");
p = -1 * (-2 * (-3 * ((exp(4) - exp(3) - (exp(3) - exp(2))) / 2 - (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) / 3 + (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) + exp(2) - exp(1)) + exp(1) + _x_ * (-1 * (-2 * ((exp(4) - exp(3) - (exp(3) - exp(2))) / 2 - (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) / 3 + -3 * ((exp(4) - exp(3) - (exp(3) - exp(2))) / 2 - (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) / 3 + (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) + -2 * (-3 * ((exp(4) - exp(3) - (exp(3) - exp(2))) / 2 - (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) / 3 + (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) + exp(2) - exp(1) + _x_ * (-1 * ((exp(4) - exp(3) - (exp(3) - exp(2))) / 2 - (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) / 3 + -2 * ((exp(4) - exp(3) - (exp(3) - exp(2))) / 2 - (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) / 3 + -3 * ((exp(4) - exp(3) - (exp(3) - exp(2))) / 2 - (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) / 3 + (exp(3) - exp(2) - (exp(2) - exp(1))) / 2 + _x_ * ((exp(4) - exp(3) - (exp(3) - exp(2))) / 2 - (exp(3) - exp(2) - (exp(2) - exp(1))) / 2) / 3))
> p = interpolate([| 1, 2, 3, 4 |], exp(_x_), 2^-17);
> write("p = ", p, "\n");
p = -7.7172116227447986602783203125 + _x_ * (17.9146616198122501373291015625 + _x_ * (-9.7775724567472934722900390625 + _x_ * 2.2984042889438569545745849609375))
> p = interpolate([| 1, 2, 3, 4 |], exp(_x_), 2^-17, [0; 2^42]);
> write("p = ", p, "\n");
p = -7.717211620141288536337557462573403702892010733189 + _x_ * (17.914661614969411928830253122773955194465923548481 + _x_ * (-9.7775724550214350407416860470959032694184512464826 + _x_ * 2.2984042886523568836092778582480142756017855238293))
Example 7:
> p = interpolate([| 1, 2, 3, 4 |], exp(_x_));
> q = interpolate([| 1, 2, 3, 4 |], exp(_x_), 2^-17);
> delta = horner(p - q);
> Delta = dirtyinfnorm(delta,[1;4]);
> "Delta = ", Delta, " = 2^(", log2(Delta), ")";
Delta = 7.8101123470606372346391215972092629613859312741733e-9 = 2^(-26.932009552561199842757802778211432954321538161928)
> p = interpolate([| 1, 2, 3, 4 |], exp(_x_));
> q = interpolate([| 1, 2, 3, 4 |], exp(_x_), 2^-2000);
> delta = horner(p - q);
> Delta = dirtyinfnorm(delta,[1;4]);
> "Delta = ", Delta, " = 2^(", log2(Delta), ")";
Delta = 3.574737886097255322676984068596786349480238060537e-606 = 2^(-2011.2505880400718258175558034736121948862189809702)
Example 8:
> p = interpolate([| 1, 2, 3, 4 |], exp(_x_));
> q = interpolate([| 1, 2, 3, 4 |], exp(_x_), 2^-17, [0;2^10]);
> delta = horner(p - q);
> Delta = dirtyinfnorm(delta,[0;2^10]);
> "Delta = ", Delta, " = 2^(", log2(Delta), ")";
Delta = 3.3174992022654716926120201737930257514243356389991e-9 = 2^(-28.167256735304970710773265696018465191273351786528)
> p = interpolate([| 1, 2, 3, 4 |], exp(_x_));
> q = interpolate([| 1, 2, 3, 4 |], exp(_x_), 2^-2000, [0;2^10]);
> delta = horner(p - q);
> Delta = dirtyinfnorm(delta,[0;2^10]);
> "Delta = ", Delta, " = 2^(", log2(Delta), ")";
Delta = 1.67480290063655159679957323422134460429582811153817e-605 = 2^(-2009.0225060850185477225876655278327362519640642038)
Example 9:
> f = exp(_x_);
> I = [-1/2;1/2];
> n = 17;
> X = [||]; for i from 0 to n do X = (~(1/2 * (inf(I) + sup(I)) + 1/2 * (sup(I) - inf(I)) * cos(pi * ((2 * i + 1)/(2 * (n + 1)))))) .: X; X = revert(X);
> p = interpolate(X, f, 2^-110);
> q = remez(f, n, I);
> Delta = dirtyinfnorm(p-f,I);
> "||p-f|| = ", Delta, " = 2^(", log2(Delta), ")";
||p-f|| = 4.6822823648740795415790209572324990540532715520787e-27 = 2^(-87.464846623211506004130540250100341126958424233896)
> Delta = dirtyinfnorm(q-f,I);
> "||q-f|| = ", Delta, " = 2^(", log2(Delta), ")";
||q-f|| = 4.5615560104462964431174181483603567519672456911095e-27 = 2^(-87.502532530192383004694428978646385337892102159012)
> Delta = dirtyinfnorm(horner(p-q),I);
> "||p-q|| = ", Delta, " = 2^(", log2(Delta), ")";
||p-q|| = 1.20729201910945452306513389470528343007256343110758e-28 = 2^(-92.742211980284523389260465711218526032152621095553)
Example 10:
> interpolate([| 1, 1 + 2^-1000 |], 17 + 42 * x);
17 + x * 42
> interpolate([| 1, 1 + 2^-10000 |], 17 + 42 * x);
17 + x * 42
> interpolate([| 1, 1 |], 17 + 42 * x);
error
Go back to the list of commands
Name:
isbound
indicates whether a variable is bound or not.
Description:
- isbound(ident) returns a boolean value indicating whether the name ident
is used or not to represent a variable. It returns true when ident is the
name used to represent the global variable or if the name is currently used
to refer to a (possibly local) variable.
- When a variable is defined in a block and has not been defined outside,
isbound returns true when called inside the block, and false outside.
Note that isbound returns true as soon as a variable has been declared with
var, even if no value is actually stored in it.
- If ident1 is bound to a variable and if ident2 refers to the global
variable, the command rename(ident2, ident1) hides the value of ident1
which becomes the global variable. However, if the global variable is again
renamed, ident1 gets its value back. In this case, isbound(ident1) returns
true. If ident1 was not bound before, isbound(ident1) returns false after
that ident1 has been renamed.
Example 1:
> isbound(x);
false
> isbound(f);
false
> isbound(g);
false
> f=sin(x);
> isbound(x);
true
> isbound(f);
true
> isbound(g);
false
Example 2:
> isbound(a);
false
> { var a; isbound(a); };
true
> isbound(a);
false
Example 3:
> f=sin(x);
> isbound(x);
true
> rename(x,y);
> isbound(x);
false
Example 4:
> x=1;
> f=sin(y);
> rename(y,x);
> f;
sin(x)
> x;
x
> isbound(x);
true
> rename(x,y);
> isbound(x);
true
> x;
1
Go back to the list of commands
Name:
isevaluable
tests whether a function can be evaluated at a point
Usage:
isevaluable(function, constant) : (function, constant) -> boolean
Parameters:
- function represents a function
- constant represents a constant point
Description:
- isevaluable applied to function function and a constant constant
returns a boolean indicating whether or not a subsequent call to evaluate on
the same function function and constant constant will produce a numerical
result or NaN. This means isevaluable returns false iff evaluate will
return NaN.
- The command isevaluable is now considered DEPRECATED in Sollya.
As checks for NaNs are now possible in Sollya, the command isevaluable
can be fully emulated with a call to evaluate and a couple of tests,
as shown below in the last example.
Example 1:
> isevaluable(sin(pi * log(x)), 0.5);
true
> print(evaluate(sin(pi * log(x)), 0.5));
-0.82148283122563882875872566228649962370813607461095
Example 2:
> isevaluable(sin(pi * log(x)), 0);
true
> print(evaluate(sin(pi * log(x)), 0));
[-1;1]
Example 3:
> isevaluable(sin(pi * 1/x), 0.5);
true
> print(evaluate(sin(pi * 1/x), 0.5));
[-3.100365765139897619749121887390789523854170596558e-13490;5.3002401585857127605350842426029223241500776302528e-13489]
Example 4:
> procedure isEvaluableEmulation(f, c) {
return match evaluate(f, c) with
NaN : (false)
[NaN;NaN] : (false)
default : (true);
};
> isEvaluableEmulation(sin(pi * log(x)), 0.5);
true
> isEvaluableEmulation(sin(pi * log(x)), 0);
true
> isEvaluableEmulation(sin(pi * log(x)), -1);
false
Go back to the list of commands
Name:
<=
less-than-or-equal-to operator
Library name:
sollya_obj_t sollya_lib_cmp_less_equal(sollya_obj_t, sollya_obj_t)
Usage:
expr1 <= expr2 : (constant, constant) -> boolean
Parameters:
- expr1 and expr2 represent constant expressions
Description:
- The operator <= evaluates to true iff its operands expr1 and
expr2 evaluate to two floating-point numbers a1
respectively a2 with the global precision prec and
a1 is less than or equal to a2. The user should
be aware of the fact that because of floating-point evaluation, the
operator <= is not exactly the same as the mathematical
operation "less-than-or-equal-to".
Example 1:
> 5 <= 4;
false
> 5 <= 5;
true
> 5 <= 6;
true
> exp(2) <= exp(1);
false
> log(1) <= exp(2);
true
Example 2:
> prec = 12;
The precision has been set to 12 bits.
> 16385.1 <= 16384.1;
true
See also: ==,
!=,
>=,
>,
<,
in,
!,
&&,
||,
prec,
max,
min
Go back to the list of commands
Name:
length
computes the length of a list or string.
Library name:
sollya_obj_t sollya_lib_length(sollya_obj_t)
Usage:
length(L) : list -> integer
length(s) : string -> integer
Parameters:
- L is a list.
- s is a string.
Description:
- length returns the length of a list or a string, e.g. the number of elements
or letters.
- The empty list or string have length 0.
If L is an end-elliptic list, length returns +Inf.
Example 1:
> length("Hello World!");
12
Example 2:
> length([|1,...,5|]);
5
Example 3:
> length([| |]);
0
Example 4:
> length([|1,2...|]);
infty
Go back to the list of commands
Name:
libraryconstant
binds an external mathematical constant to a variable in Sollya
Library names:
sollya_obj_t sollya_lib_libraryconstant(char *, void (*)(mpfr_t, mp_prec_t))
sollya_obj_t sollya_lib_build_function_libraryconstant(char *,
void (*)(mpfr_t,
mp_prec_t))
sollya_obj_t sollya_lib_libraryconstant_with_data(char *,
void (*)(mpfr_t,
mp_prec_t,
void *),
void *,
void (*)(void *))
sollya_obj_t sollya_lib_build_function_libraryconstant_with_data(
char *,
void (*)(mpfr_t,
mp_prec_t,
void *),
void *,
void (*)(void *))
Description:
- The command libraryconstant lets you extend the set of mathematical
constants known to Sollya.
By default, the only mathematical constant known by Sollya is pi.
For particular applications, one may want to
manipulate other constants, such as Euler's gamma constant, for instance.
- libraryconstant makes it possible to let Sollya know about new constants.
In order to let it know, you have to provide an implementation of the
constant you are interested in. This implementation is a C file containing
a function of the form:
void my_ident(mpfr_t result, mp_prec_t prec)
The semantic of this function is the following: it is an implementation of
the constant in arbitrary precision.
my_ident(result, prec) shall set the
precision of the variable result to a suitable precision (the variable is
assumed to be already initialized) and store in result an approximate value
of the constant with a relative error not greater than 2^(1-prec).
More precisely, if c is the exact value of the constant, the value stored
in result should satisfy |result-c| <= 2^(1-prec)*|c|.
- You can include sollya.h in your implementation and use library
functionnalities of Sollya for your implementation. However, this requires to
have compiled Sollya with -fPIC in order to make the Sollya executable
code position independent and to use a system on with programs, using dlopen
to open dynamic routines can dynamically open themselves.
- To bind your constant into Sollya, you must use the same identifier as the
function name used in your implementation file (my_ident in the previous
example). Once the function code has been bound to an identifier, you can use
a simple assignment to assign the bound identifier to yet another identifier.
This way, you may use convenient names inside Sollya even if your
implementation environment requires you to use a less convenient name.
- Once your constant is bound, it is considered by Sollya as an infinitely
accurate constant (i.e. a 0-ary function, exactly like pi).
- The dynamic object file whose name is given to libraryconstant for binding of an
external library constant may also define a destructor function int sollya_external_lib_close(void).
If Sollya finds such a destructor function in the dynamic object file, it will call
that function when closing the dynamic object file again. This happens when Sollya
is terminated or when the current Sollya session is restarted using restart.
The purpose of the destructor function is to allow the dynamically bound code
to free any memory that it might have allocated before Sollya is terminated
or restarted.
The dynamic object file is not necessarily needed to define a destructor
function. This ensure backward compatibility with older Sollya external
library function object files.
When defined, the destructor function is supposed to return an integer
value indicating if an error has happened. Upon success, the destructor
functions is to return a zero value, upon error a non-zero value.
Example 1:
> bashexecute("gcc -fPIC -Wall -c libraryconstantexample.c -I$HOME/.local/include");
> bashexecute("gcc -shared -o libraryconstantexample libraryconstantexample.o -lgmp -lmpfr");
> euler_gamma = libraryconstant("./libraryconstantexample");
> prec = 20!;
> euler_gamma;
0.577215
> prec = 100!;
> euler_gamma;
0.577215664901532860606512090082
> midpointmode = on;
Midpoint mode has been activated.
> [euler_gamma];
0.57721566490153286060651209008~2/4~
Go back to the list of commands
Name:
library
binds an external mathematical function to a variable in Sollya
Library names:
sollya_obj_t sollya_lib_libraryfunction(sollya_obj_t, char *,
int (*)(mpfi_t, mpfi_t, int))
sollya_obj_t sollya_lib_build_function_libraryfunction(sollya_obj_t, char *,
int (*)(mpfi_t,
mpfi_t, int))
sollya_obj_t sollya_lib_libraryfunction_with_data(
sollya_obj_t, char *,
int (*)(mpfi_t, mpfi_t, int, void *),
void *, void (*)(void *))
sollya_obj_t sollya_lib_build_function_libraryfunction_with_data(
sollya_obj_t, char *,
int (*)(mpfi_t,
mpfi_t, int, void *),
void *, void (*)(void *))
Usage:
library(path) : string -> function
Description:
- The command library lets you extend the set of mathematical
functions known to Sollya.
By default, Sollya knows the most common mathematical functions such
as exp, sin, erf, etc. Within Sollya, these functions may be
composed. This way, Sollya should satisfy the needs of a lot of
users. However, for particular applications, one may want to
manipulate other functions such as Bessel functions, or functions
defined by an integral or even a particular solution of an ODE.
- library makes it possible to let Sollya know about new functions. In
order to let it know, you have to provide an implementation of the
function you are interested in. This implementation is a C file containing
a function of the form:
int my_ident(sollya_mpfi_t result, sollya_mpfi_t op, int n)
The semantic of this function is the following: it is an implementation of
the function and its derivatives in interval arithmetic.
my_ident(result, I, n) shall store in result an enclosure
of the image set of the n-th derivative
of the function f over I: f^(n)(I) C result.
- The integer value returned by the function implementation currently has no
meaning.
- You do not need to provide a working implementation for any n. Most
functions of Sollya requires a relevant implementation only for f,
f' and f''. For higher derivatives, its is not so critical and the
implementation may just store [-Inf, +Inf] in result whenever n>2.
- Note that you should respect somehow interval-arithmetic standards in your
implementation: result has its own precision and you should perform the
intermediate computations so that result is as tight as possible.
- You can include sollya.h in your implementation and use library
functionnalities of Sollya for your implementation. However, this requires to
have compiled Sollya with -fPIC in order to make the Sollya executable code
position independent and to use a system on with programs, using dlopen to
open dynamic routines can dynamically open themselves. IMPORTANT NOTICE: as
the code will be run in a context where a sollya session is already opened,
the library functions must be used directly, without calling sollya_lib_init
and sollya_lib_close (calling these functions would conflict with the
current session, leading to weird and hard to debug behaviors).
- To bind your function into Sollya, you must use the same identifier as the
function name used in your implementation file (my_ident in the previous
example). Once the function code has been bound to an identifier, you can use
a simple assignment to assign the bound identifier to yet another identifier.
This way, you may use convenient names inside Sollya even if your
implementation environment requires you to use a less convenient name.
- The dynamic object file whose name is given to library for binding of an
external library function may also define a destructor function
int sollya_external_lib_close(void).
If Sollya finds such a destructor function in the dynamic object file, it
will call that function when closing the dynamic object file again.
This happens when Sollya is terminated or when the current Sollya session
is restarted using restart.
The purpose of the destructor function is to allow the dynamically bound code
to free any memory that it might have allocated before Sollya is terminated
or restarted.
The dynamic object file is not necessarily needed to define a destructor
function. This ensure backward compatibility with older Sollya external
library function object files.
When defined, the destructor function is supposed to return an integer
value indicating if an error has happened. Upon success, the destructor
functions is to return a zero value, upon error a non-zero value.
Example 1:
> bashexecute("gcc -fPIC -Wall -c libraryexample.c -I$HOME/.local/include");
> bashexecute("gcc -shared -o libraryexample libraryexample.o -lgmp -lmpfr");
> myownlog = library("./libraryexample");
> evaluate(log(x), 2);
0.69314718055994530941723212145817656807550013436025
> evaluate(myownlog(x), 2);
0.69314718055994530941723212145817656807550013436025
Go back to the list of commands
Name:
list of
keyword used in combination with a type keyword
Library names:
SOLLYA_EXTERNALPROC_TYPE_CONSTANT_LIST
SOLLYA_EXTERNALPROC_TYPE_FUNCTION_LIST
SOLLYA_EXTERNALPROC_TYPE_RANGE_LIST
SOLLYA_EXTERNALPROC_TYPE_INTEGER_LIST
SOLLYA_EXTERNALPROC_TYPE_STRING_LIST
SOLLYA_EXTERNALPROC_TYPE_BOOLEAN_LIST
SOLLYA_EXTERNALPROC_TYPE_OBJECT_LIST
Go back to the list of commands
Name:
log10
decimal logarithm.
Library names:
sollya_obj_t sollya_lib_log10(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_log10(sollya_obj_t)
#define SOLLYA_LOG10(x) sollya_lib_build_function_log10(x)
Description:
- log10 is the decimal logarithm defined by: log10(x) = log(x)/log(10).
- It is defined only for x in [0; +Inf].
Go back to the list of commands
Name:
log1p
translated logarithm.
Library names:
sollya_obj_t sollya_lib_log1p(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_log1p(sollya_obj_t)
#define SOLLYA_LOG1P(x) sollya_lib_build_function_log1p(x)
Description:
- log1p is the function defined by log1p(x) = log(1+x).
- It is defined only for x in [-1; +Inf].
Go back to the list of commands
Name:
log2
binary logarithm.
Library names:
sollya_obj_t sollya_lib_log2(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_log2(sollya_obj_t)
#define SOLLYA_LOG2(x) sollya_lib_build_function_log2(x)
Description:
- log2 is the binary logarithm defined by: log2(x) = log(x)/log(2).
- It is defined only for x in [0; +Inf].
Go back to the list of commands
Name:
log
natural logarithm.
Library names:
sollya_obj_t sollya_lib_log(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_log(sollya_obj_t)
#define SOLLYA_LOG(x) sollya_lib_build_function_log(x)
Description:
- log is the natural logarithm defined as the inverse of the exponential
function: log(y) is the unique real number x such that exp(x)=y.
- It is defined only for y in [0; +Inf].
Go back to the list of commands
Name:
<
less-than operator
Library name:
sollya_obj_t sollya_lib_cmp_less(sollya_obj_t, sollya_obj_t)
Usage:
expr1 < expr2 : (constant, constant) -> boolean
Parameters:
- expr1 and expr2 represent constant expressions
Description:
- The operator < evaluates to true iff its operands expr1 and
expr2 evaluate to two floating-point numbers a1
respectively a2 with the global precision prec and
a1 is less than a2. The user should
be aware of the fact that because of floating-point evaluation, the
operator < is not exactly the same as the mathematical
operation "less-than".
Example 1:
> 5 < 4;
false
> 5 < 5;
false
> 5 < 6;
true
> exp(2) < exp(1);
false
> log(1) < exp(2);
true
Example 2:
> prec = 12;
The precision has been set to 12 bits.
> 16384.1 < 16385.1;
false
See also: ==,
!=,
>=,
>,
<=,
in,
!,
&&,
||,
prec,
max,
min
Go back to the list of commands
Name:
mantissa
returns the integer mantissa of a number.
Library name:
sollya_obj_t sollya_lib_mantissa(sollya_obj_t)
Usage:
mantissa(x) : constant -> integer
Description:
- mantissa(x) is by definition x if x equals 0, NaN, or Inf.
- If x is not zero, it can be uniquely written as x = m*2^e where
m is an odd integer and e is an integer. mantissa(x) returns m.
Example 1:
> a=round(Pi,20,RN);
> e=exponent(a);
> m=mantissa(a);
> m;
411775
> a-m*2^e;
0
Go back to the list of commands
Name:
max
determines which of given constant expressions has maximum value
Library names:
sollya_obj_t sollya_lib_max(sollya_obj_t, ...)
sollya_obj_t sollya_lib_v_max(sollya_obj_t, va_list)
Usage:
max(expr1,expr2,...,exprn) : (constant, constant, ..., constant) -> constant
max(l) : list -> constant
Parameters:
- expr are constant expressions.
- l is a list of constant expressions.
Description:
- max determines which of a given set of constant expressions
expr has maximum value. To do so, max tries to increase the
precision used for evaluation until it can decide the ordering or some
maximum precision is reached. In the latter case, a warning is printed
indicating that there might actually be another expression that has a
greater value.
- Even though max determines the maximum expression by evaluation, it
returns the expression that is maximum as is, i.e. as an expression
tree that might be evaluated to any accuracy afterwards.
- max can be given either an arbitrary number of constant
expressions in argument or a list of constant expressions. The list
however must not be end-elliptic.
- Users should be aware that the behavior of max follows the IEEE
754-2008 standard with respect to NaNs. In particular, max
evaluates to NaN if and only if all arguments of max are
NaNs. This means that NaNs may disappear during computations.
Example 1:
> max(1,2,3,exp(5),log(0.25));
148.41315910257660342111558004055227962348766759388
> max(17);
17
Example 2:
> l = [|1,2,3,exp(5),log(0.25)|];
> max(l);
148.41315910257660342111558004055227962348766759388
Example 3:
> print(max(exp(17),sin(62)));
exp(17)
Example 4:
> verbosity = 1!;
> print(max(17 + log2(13)/log2(9),17 + log(13)/log(9)));
Warning: the tool is unable to decide a maximum computation by evaluation even though faithful evaluation of the terms has been possible. The terms will be considered to be equal.
17 + log2(13) / log2(9)
Go back to the list of commands
Name:
mid
gives the middle of an interval.
Library name:
sollya_obj_t sollya_lib_mid(sollya_obj_t)
Usage:
mid(I) : range -> constant
mid(x) : constant -> constant
Parameters:
- I is an interval.
- x is a real number.
Description:
- Returns the middle of the interval I. If the middle is not exactly
representable at the current precision, the value is returned as an
unevaluated expression.
- When called on a real number x, mid behaves like the identity.
Example 1:
> mid([1;3]);
2
> mid(17);
17
Go back to the list of commands
Name:
midpointmode
global variable controlling the way intervals are displayed.
Library names:
void sollya_lib_set_midpointmode_and_print(sollya_obj_t)
void sollya_lib_set_midpointmode(sollya_obj_t)
sollya_obj_t sollya_lib_get_midpointmode()
Parameters:
- activation value enables or disables the mode.
Description:
- midpointmode is a global variable. When its value is off, intervals are displayed
as usual (in the form [a;b]).
When its value is on, and if a and b have the same first significant digits,
the interval in displayed in a way that lets one immediately see the common
digits of the two bounds.
- This mode is supported only with display set to decimal. In other modes of
display, midpointmode value is simply ignored.
Example 1:
> a = round(Pi,30,RD);
> b = round(Pi,30,RU);
> d = [a,b];
> d;
[3.1415926516056060791015625;3.1415926553308963775634765625]
> midpointmode=on!;
> d;
0.314159265~1/6~e1
Go back to the list of commands
Name:
min
determines which of given constant expressions has minimum value
Library names:
sollya_obj_t sollya_lib_min(sollya_obj_t, ...)
sollya_obj_t sollya_lib_v_min(sollya_obj_t, va_list)
Usage:
min(expr1,expr2,...,exprn) : (constant, constant, ..., constant) -> constant
min(l) : list -> constant
Parameters:
- expr are constant expressions.
- l is a list of constant expressions.
Description:
- min determines which of a given set of constant expressions
expr has minimum value. To do so, min tries to increase the
precision used for evaluation until it can decide the ordering or some
maximum precision is reached. In the latter case, a warning is printed
indicating that there might actually be another expression that has a
lesser value.
- Even though min determines the minimum expression by evaluation, it
returns the expression that is minimum as is, i.e. as an expression
tree that might be evaluated to any accuracy afterwards.
- min can be given either an arbitrary number of constant
expressions in argument or a list of constant expressions. The list
however must not be end-elliptic.
- Users should be aware that the behavior of min follows the IEEE
754-2008 standard with respect to NaNs. In particular, min
evaluates to NaN if and only if all arguments of min are
NaNs. This means that NaNs may disappear during computations.
Example 1:
> min(1,2,3,exp(5),log(0.25));
-1.3862943611198906188344642429163531361510002687205
> min(17);
17
Example 2:
> l = [|1,2,3,exp(5),log(0.25)|];
> min(l);
-1.3862943611198906188344642429163531361510002687205
Example 3:
> print(min(exp(17),sin(62)));
sin(62)
Example 4:
> verbosity = 1!;
> print(min(17 + log2(13)/log2(9),17 + log(13)/log(9)));
Warning: the tool is unable to decide a minimum computation by evaluation even though faithful evaluation of the terms has been possible. The terms will be considered to be equal.
17 + log(13) / log(9)
Go back to the list of commands
Name:
-
subtraction function
Library names:
sollya_obj_t sollya_lib_sub(sollya_obj_t, sollya_obj_t)
sollya_obj_t sollya_lib_build_function_sub(sollya_obj_t, sollya_obj_t)
#define SOLLYA_SUB(x,y) sollya_lib_build_function_sub((x), (y))
sollya_obj_t sollya_lib_neg(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_neg(sollya_obj_t)
#define SOLLYA_NEG(x) sollya_lib_build_function_neg(x)
Usage:
function1 - function2 : (function, function) -> function
interval1 - interval2 : (range, range) -> range
interval1 - constant : (range, constant) -> range
interval1 - constant : (constant, range) -> range
- function1 : function -> function
- interval1 : range -> range
Parameters:
- function1 and function2 represent functions
- interval1 and interval2 represent intervals (ranges)
- constant represents a constant or constant expression
Description:
- - represents the subtraction (function) on reals.
The expression function1 - function2 stands for
the function composed of the subtraction function and the two
functions function1 and function2, where function1 is
the subtrahend and function2 the subtractor.
- - can be used for interval arithmetic on intervals
(ranges). - will evaluate to an interval that safely
encompasses all images of the subtraction function with arguments varying
in the given intervals. Any combination of intervals with intervals
or constants (resp. constant expressions) is supported. However, it is
not possible to represent families of functions using an interval as
one argument and a function (varying in the free variable) as the
other one.
- - stands also for the negation function.
Example 1:
> 5 - 2;
3
Example 2:
> x - 2;
-2 + x
Example 3:
> x - x;
0
Example 4:
> diff(sin(x) - exp(x));
cos(x) - exp(x)
Example 5:
> [1;2] - [3;4];
[-3;-1]
> [1;2] - 17;
[-16;-15]
> 13 - [-4;17];
[-4;17]
Example 6:
> -exp(x);
-exp(x)
> -13;
-13
> -[13;17];
[-17;-13]
Go back to the list of commands
Name:
mod
Computes the euclidian division of polynomials or numbers and returns the rest
Library name:
sollya_obj_t sollya_lib_euclidian_mod(sollya_obj_t, sollya_obj_t)
Usage:
mod(a, b) : (function, function) -> function
Parameters:
- a is a constant or a polynomial.
- b is a constant or a polynomial.
Description:
- mod(a,b) computes a - (b * div(a,b)).
In other words, it returns the remainder of the Euclidian division
of a by b.
- See div for subtle cases involving polynomials whose degree can
not easily be computed by the tool as their leading coefficient is
given as a constant expression that is mathematically zero but for
which the tool is unable to detect this fact.
Example 1:
> mod(1001, 231);
77
> mod(13, 17);
13
> mod(-14, 15);
1
> mod(-213, -5);
-3
> print(mod(23/13, 11/17));
105 / 221
> print(mod(exp(13),-sin(17)));
exp(13) + 460177 * sin(17)
Example 2:
> mod(24 + 68 * x + 74 * x^2 + 39 * x^3 + 10 * x^4 + x^5, 4 + 4 * x + x^2);
0
> mod(24 + 68 * x + 74 * x^2 + 39 * x^3 + 10 * x^4 + x^5, 2 * x^3);
24 + x * (68 + x * 74)
> mod(x^2, x^3);
x^2
Example 3:
> mod(exp(x), x^2);
exp(x)
> mod(x^3, sin(x));
x^3
Go back to the list of commands
Name:
*
multiplication function
Library names:
sollya_obj_t sollya_lib_mul(sollya_obj_t, sollya_obj_t)
sollya_obj_t sollya_lib_build_function_mul(sollya_obj_t, sollya_obj_t)
#define SOLLYA_MUL(x,y) sollya_lib_build_function_mul((x), (y))
Usage:
function1 * function2 : (function, function) -> function
interval1 * interval2 : (range, range) -> range
interval1 * constant : (range, constant) -> range
interval1 * constant : (constant, range) -> range
Parameters:
- function1 and function2 represent functions
- interval1 and interval2 represent intervals (ranges)
- constant represents a constant or constant expression
Description:
- * represents the multiplication (function) on reals.
The expression function1 * function2 stands for
the function composed of the multiplication function and the two
functions function1 and function2.
- * can be used for interval arithmetic on intervals
(ranges). * will evaluate to an interval that safely
encompasses all images of the multiplication function with arguments varying
in the given intervals. Any combination of intervals with intervals
or constants (resp. constant expressions) is supported. However, it is
not possible to represent families of functions using an interval as
one argument and a function (varying in the free variable) as the
other one.
Example 1:
> 5 * 2;
10
Example 2:
> x * 2;
x * 2
Example 3:
> x * x;
x^2
Example 4:
> diff(sin(x) * exp(x));
sin(x) * exp(x) + exp(x) * cos(x)
Example 5:
> [1;2] * [3;4];
[3;8]
> [1;2] * 17;
[17;34]
> 13 * [-4;17];
[-52;221]
Go back to the list of commands
Name:
nearestint
the function mapping the reals to the integers nearest to them.
Library names:
sollya_obj_t sollya_lib_nearestint(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_nearestint(sollya_obj_t)
#define SOLLYA_NEARESTINT(x) sollya_lib_build_function_nearestint(x)
Description:
- nearestint is defined as usual: nearestint(x) is the integer nearest to x, with the
special rule that the even integer is chosen if there exist two integers equally near to x.
- It is defined for every real number x.
Go back to the list of commands
Name:
!=
negated equality test operator
Library name:
sollya_obj_t sollya_lib_cmp_not_equal(sollya_obj_t, sollya_obj_t)
Usage:
expr1 != expr2 : (any type, any type) -> boolean
Parameters:
- expr1 and expr2 represent expressions
Description:
- The operator != evaluates to true iff its operands expr1 and
expr2 are syntactically unequal and both different from error,
constant expressions that are not constants and that evaluate to two
different floating-point number with the global precision prec or
polynomials that are unequal while automatic expression simplification
is activated. The user should be aware of the fact that because of
floating-point evaluation, the operator != is not exactly the
same as the negation of the mathematical equality. Further, expressions
that are polynomials may not be structurally equal when != evaluates
to false; in order to obtain purely structural tests, the user should
deactivate automatic simplification using autosimplify.
Following the IEEE 754 standard, NaN compares unequal to itself, even though
this corresponds to a case when expr1 and expr2 are syntactically equal
and different from error. Accordingly, the interval [NaN, NaN] compares
unequal to itself.
Note that the expressions !(expr1 != expr2) and expr1 == expr2
do not always evaluate to the same boolean value. See error for details.
- Notice that @NaN@, [@NaN, @NaN@] and error have special properties
with respect to comparison for equality with == and !=. See
documentation for == for a detailed description.
Example 1:
> "Hello" != "Hello";
false
> "Hello" != "Salut";
true
> "Hello" != 5;
true
> 5 + x != 5 + x;
false
Example 2:
> 1 != exp(0);
false
> asin(1) * 2 != pi;
false
> exp(5) != log(4);
true
Example 3:
> sin(pi/6) != 1/2 * sqrt(3);
true
Example 4:
> prec = 12;
The precision has been set to 12 bits.
> 16384.1 != 16385.1;
false
Example 5:
> NaN != NaN;
true
> [NaN,NaN] != [NaN,NaN];
true
> error != error;
false
Example 6:
> p = x + x^2;
> q = x * (1 + x);
> autosimplify = on;
Automatic pure tree simplification has been activated.
> p != q;
false
> autosimplify = off;
Automatic pure tree simplification has been deactivated.
> p != q;
true
See also: ==,
>,
>=,
<=,
<,
in,
!,
&&,
||,
error,
prec,
autosimplify
Go back to the list of commands
Usage:
nop : void -> void
nop() : void -> void
nop(n) : integer -> void
Description:
- The command nop does nothing. This means it is an explicit parse
element in the Sollya language that finally does not produce any
result or side-effect.
- The command nop may take an optional positive integer argument
n. The argument controls how much (useless) multiprecision
floating-point multiplications Sollya performs while doing nothing.
With this behaviour, nop can be used for calibration of timing
tests.
- The keyword nop is implicit in some procedure
definitions. Procedures without imperative body get parsed as if they
had an imperative body containing one nop statement.
Example 1:
> nop;
Example 2:
> nop(100);
Example 3:
> succ = proc(n) { return n + 1; };
> succ;
proc(n)
{
nop;
return (n) + (1);
}
> succ(5);
6
Go back to the list of commands
Name:
!
boolean NOT operator
Library name:
sollya_obj_t sollya_lib_negate(sollya_obj_t)
Usage:
! expr : boolean -> boolean
Parameters:
- expr represents a boolean expression
Description:
- ! evaluates to the boolean NOT of the boolean expression
expr. ! expr evaluates to true iff expr does not evaluate
to true.
Example 1:
> ! false;
true
Example 2:
> ! (1 == exp(0));
false
Go back to the list of commands
Name:
numberroots
Computes the number of roots of a polynomial in a given range.
Library name:
sollya_obj_t sollya_lib_numberroots(sollya_obj_t, sollya_obj_t)
Usage:
numberroots(p, I) : (function, range) -> integer
Parameters:
- p is a polynomial.
- I is an interval.
Description:
- numberroots rigorously computes the number of roots of polynomial the p in
the interval I. The technique used is Sturm's algorithm. The value returned
is not just a numerical estimation of the number of roots of p in I: it is
the exact number of roots.
- The command findzeros computes safe enclosures of all the zeros of a
function, without forgetting any, but it is not guaranteed to separate them
all in distinct intervals. numberroots is more accurate since it guarantees
the exact number of roots. However, it does not compute them. It may be used,
for instance, to certify that findzeros did not put two distinct roots in
the same interval.
- Multiple roots are counted only once.
- The interval I must be bounded. The algorithm cannot handle unbounded
intervals. Moreover, the interval is considered as a closed interval: if one
(or both) of the endpoints of I are roots of p, they are counted.
- The argument p can be any expression, but if Sollya fails to prove that
it is a polynomial an error is produced. Also, please note that if the
coefficients of p or the endpoints of I are not exactly representable,
they are first numerically evaluated, before the algorithm is used. In that
case, the counted number of roots corresponds to the rounded polynomial on
the rounded interval *and not* to the exact parameters given by the user.
A warning is displayed to inform the user.
Example 1:
> numberroots(1+x-x^2, [1,2]);
1
> findzeros(1+x-x^2, [1,2]);
[|[1.617919921875;1.6180419921875]|]
Example 2:
> numberroots((1+x)*(1-x), [-1,1]);
2
> numberroots(x^2, [-1,1]);
1
Example 3:
> verbosity = 1!;
> numberroots(x-pi, [0,4]);
Warning: the 0th coefficient of the polynomial is neither a floating point
constant nor can be evaluated without rounding to a floating point constant.
Will faithfully evaluate it with the current precision (165 bits)
1
Example 4:
> verbosity = 1!;
> numberroots(1+x-x^2, [0, @Inf@]);
Warning: the given interval must have finite bounds.
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
error
> numberroots(exp(x), [0, 1]);
Warning: the given function must be a polynomial in this context.
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
error
Go back to the list of commands
Name:
numerator
gives the numerator of an expression
Library name:
sollya_obj_t sollya_lib_numerator(sollya_obj_t)
Usage:
numerator(expr) : function -> function
Parameters:
- expr represents an expression
Description:
- If expr represents a fraction expr1/expr2, numerator(expr)
returns the numerator of this fraction, i.e. expr1.
If expr represents something else, numerator(expr)
returns the expression itself, i.e. expr.
Note that for all expressions expr, numerator(expr) / denominator(expr)
is equal to expr.
Example 1:
> numerator(5/3);
5
Example 2:
> numerator(exp(x));
exp(x)
Example 3:
> a = 5/3;
> b = numerator(a)/denominator(a);
> print(a);
5 / 3
> print(b);
5 / 3
Example 4:
> a = exp(x/3);
> b = numerator(a)/denominator(a);
> print(a);
exp(x / 3)
> print(b);
exp(x / 3)
Go back to the list of commands
Name:
objectname
returns, given a Sollya object, a string that can be reparsed to the object
Library name:
sollya_obj_t sollya_lib_objectname(sollya_obj_t);
Description:
- objectname(obj) queries the Sollya symbol table in order to recover the
name of an identifier the object obj is assigned to. If it succeeds, it
returns a string containing the recovered identifier. In contrast, if it
does not succeed, it returns a string simply containing a textual
representation of obj.
- The only condition for an identifier to be eligible to be returned by
objectname(obj) is to be accessible in the scope objectname is executed in,
i.e., not to be shadowed by an identifier of the same name which does not
hold the object obj.
- In any case, if the string returned by objectname is given to the parse
command in the same scope, the original object obj is recovered.
- objectname is particularly useful in combination with getbacktrace, when
the Sollya procedure stack is to be displayed in a fashion, where
procedures are identified by their name and not their procedural content.
- objectname may also be used to get a string representation of the free
mathematical variable.
- If an object is simply to be cast into a string, without trying to
retrieve an identifier for it, objectname is not appropriate. In this case,
it suffices to concatenate it to an empty string with the @ operator.
Example 1:
> s = "Hello";
> objectname("Hello");
s
Example 2:
> f = exp(x);
> g = sin(x);
> [| objectname(exp(x)), objectname(sin(x)), objectname(cos(x)) |];
[|"f", "g", "cos(x)"|]
Example 3:
> o = { .f = exp(x), .I = [-1;1] };
> s1 = o@""; s1;
{ .f = exp(x), .I = [-1;1] }
> s2 = objectname({ .I = [-1;1], .f = exp(x)}); s2;
o
> parse(s1) == parse(s2);
true
> write("s2 = \"", s2, "\" parses to ", parse(s2), "\n");
s2 = "o" parses to { .f = exp(x), .I = [-1;1] }
Example 4:
> n = 1664;
> objectname(n);
n
Example 5:
> f = exp(x);
> g = sin(x);
> procedure test() {
var f;
var h;
f = tan(x);
h = cos(x);
[| objectname(exp(x)), objectname(sin(x)), objectname(cos(x)), objectname(tan(x)) |];
};
> test();
[|"exp(x)", "g", "h", "f"|]
Example 6:
> procedure apply_proc(p, a, b) {
return p(a, b);
};
> procedure show_trace_and_add(n, m) {
var i, bt;
bt = getbacktrace();
write("Procedure stack:\n");
for i from 0 to length(bt) - 1 do {
write(" Procedure ", objectname((bt[i]).called_proc), " called with ", length((bt[i]).passed_args), " arguments\n");
};
write("\n");
return n + m;
};
> procedure show_and_succ(u) {
return apply_proc(show_trace_and_add, u, 1);
};
> show_and_succ(16);
Procedure stack:
Procedure show_trace_and_add called with 2 arguments
Procedure apply_proc called with 3 arguments
Procedure show_and_succ called with 1 arguments
17
Example 7:
> f = exp(three_decker_sauerkraut_and_toadstool_sandwich_with_arsenic_sauce);
> g = sin(_x_);
> h = f(g);
> h;
exp(sin(three_decker_sauerkraut_and_toadstool_sandwich_with_arsenic_sauce))
> objectname(_x_);
three_decker_sauerkraut_and_toadstool_sandwich_with_arsenic_sauce
Go back to the list of commands
Name:
object
keyword representing a Sollya object type
Library name:
SOLLYA_EXTERNALPROC_TYPE_OBJECT
Description:
- object represents the Sollya object type for declarations
of external procedures externalproc.
Remark that in contrast to other indicators, type indicators like
object cannot be handled outside the externalproc context. In
particular, they cannot be assigned to variables.
Go back to the list of commands
Name:
off
special value for certain global variables.
Library names:
sollya_obj_t sollya_lib_off()
int sollya_lib_is_off(sollya_obj_t)
Description:
- off is a special value used to deactivate certain functionnalities
of Sollya.
- As any value it can be affected to a variable and stored in lists.
Example 1:
> canonical=on;
Canonical automatic printing output has been activated.
> p=1+x+x^2;
> mode=off;
> p;
1 + x + x^2
> canonical=mode;
Canonical automatic printing output has been deactivated.
> p;
1 + x * (1 + x)
Go back to the list of commands
Name:
on
special value for certain global variables.
Library names:
sollya_obj_t sollya_lib_on()
int sollya_lib_is_on(sollya_obj_t)
Description:
- on is a special value used to activate certain functionnalities
of Sollya.
- As any value it can be affected to a variable and stored in lists.
Example 1:
> p=1+x+x^2;
> mode=on;
> p;
1 + x * (1 + x)
> canonical=mode;
Canonical automatic printing output has been activated.
> p;
1 + x + x^2
Go back to the list of commands
Name:
||
boolean OR operator
Library name:
sollya_obj_t sollya_lib_or(sollya_obj_t, sollya_obj_t)
Usage:
expr1 || expr2 : (boolean, boolean) -> boolean
Parameters:
- expr1 and expr2 represent boolean expressions
Description:
- || evaluates to the boolean OR of the two
boolean expressions expr1 and expr2. || evaluates to
true iff at least one of expr1 or expr2 evaluates to true.
Example 1:
> false || false;
false
Example 2:
> (1 == exp(0)) || (0 == log(1));
true
Go back to the list of commands
Name:
parse
parses an expression contained in a string
Library name:
sollya_obj_t sollya_lib_parse(sollya_obj_t)
Usage:
parse(string) : string -> function | error
Parameters:
- string represents a character sequence
Description:
- parse(string) parses the character sequence string containing an
expression built on constants and base functions.
If the character sequence does not contain a well-defined expression, a
warning is displayed indicating a syntax error and parse returns a error of
type error.
- The character sequence to be parsed by parse may contain commands that
return expressions, including parse itself. Those commands get executed
after the string has been parsed. parse(string) will return the
expression computed by the commands contained in the character sequence
string.
- parse expects an expression (or a command returning an expression) but
cannot be used to evaluate a command producing a side effect without
returning a result, nor to evaluate a sequence of instructions. However, such
a behavior may be obtained by encapsulating the side effects into an
anonymous procedure that parse can handle and by immediately applying it (see
examples below).
Example 1:
> parse("exp(x)");
exp(x)
Example 2:
> text = "remez(exp(x),5,[-1;1])";
> print("The string", text, "gives", parse(text));
The string remez(exp(x),5,[-1;1]) gives 8.7381909882756203676868315731687604903964388498642e-3 * x^5 + 4.3793696379596015478233171265365272893795005588381e-2 * x^4 + 0.16642465614952768185129433844012193925654065755905 * x^3 + 0.49919698262963614991826575452094101562044819693772 * x^2 + 1.00003834650599815466340068058231011540878088492516 * x + 1.00004475029559502606203712816558243384077522932213
Example 3:
> verbosity = 1!;
> parse("5 + * 3");
Warning: syntax error. Will try to continue parsing (expecting ";"). May leak memory.
Warning: the string "5 + * 3" could not be parsed by the miniparser.
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
error
Example 4:
> i = 17;
> parse("i = 42");
error
> i;
17
> (parse("proc () { i = 42; }"))();
> i;
42
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_perturb()
int sollya_lib_is_perturb(sollya_obj_t)
Example 1:
> bashexecute("gcc -fPIC -c externalplotexample.c");
> bashexecute("gcc -shared -o externalplotexample externalplotexample.o -lgmp -lmpfr");
> externalplot("./externalplotexample",relative,exp(x),[-1/2;1/2],12,perturb);
Go back to the list of commands
Name:
pi
the constant Pi.
Library names:
sollya_obj_t sollya_lib_pi()
int sollya_lib_is_pi(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_pi()
#define SOLLYA_PI (sollya_lib_build_function_pi())
Description:
- pi is the constant Pi, defined as half the period of sine and cosine.
- In Sollya, pi is considered a 0-ary function. This way, the constant
is not evaluated at the time of its definition but at the time of its use. For
instance, when you define a constant or a function relating to Pi, the current
precision at the time of the definition does not matter. What is important is
the current precision when you evaluate the function or the constant value.
- Remark that when you define an interval, the bounds are first evaluated and
then the interval is defined. In this case, pi will be evaluated as any
other constant value at the definition time of the interval, thus using the
current precision at this time.
Example 1:
> verbosity=1!; prec=12!;
> a = 2*pi;
> a;
Warning: rounding has happened. The value displayed is a faithful rounding to 12 bits of the true result.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
6.283
> prec=20!;
> a;
Warning: rounding has happened. The value displayed is a faithful rounding to 20 bits of the true result.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
6.28319
Example 2:
> display=binary;
Display mode is binary numbers.
> prec=12!;
> d = [pi; 5];
> d;
[1.1001001_2 * 2^(1);1.01_2 * 2^(2)]
> prec=20!;
> d;
[1.1001001_2 * 2^(1);1.01_2 * 2^(2)]
Go back to the list of commands
Name:
plot
plots one or several functions
Library names:
void sollya_lib_plot(sollya_obj_t, sollya_obj_t, ...)
void sollya_lib_v_plot(sollya_obj_t, sollya_obj_t, va_list)
Usage:
plot(f1, ... ,fn, I) : (function, ... ,function, range) -> void
plot(f1, ... ,fn, I, file, name) : (function, ... ,function, range, file, string) -> void
plot(f1, ... ,fn, I, postscript, name) : (function, ... ,function, range, postscript, string) -> void
plot(f1, ... ,fn, I, postscriptfile, name) : (function, ... ,function, range, postscriptfile, string) -> void
plot(L, I) : (list, range) -> void
plot(L, I, file, name) : (list, range, file, string) -> void
plot(L, I, postscript, name) : (list, range, postscript, string) -> void
plot(L, I, postscriptfile, name) : (list, range, postscriptfile, string) -> void
Parameters:
- f1, ..., fn are functions to be plotted.
- L is a list of functions to be plotted.
- I is the interval where the functions have to be plotted.
- name is a string representing the name of a file.
Description:
- This command plots one or several functions f1, ... ,fn on an
interval I. Functions can be either given as parameters of plot or as a
list L which elements are functions.
The functions are drawn on the same plot with different colors.
- If L contains an element that is not a function (or a constant), an error
occurs.
- plot relies on the value of global variable points. Let n be the
value of this variable. The algorithm is the following: each function is
evaluated at n evenly distributed points in I. At each point, the
computed value is a faithful rounding of the exact value with a sufficiently
high precision. Each point is finally plotted.
This should avoid numerical artefacts such as critical cancellations.
- The plot can be saved either as a data file or as a postscript file.
- If you use argument file with a string name, Sollya will save a data file
called name.dat and a gnuplot directives file called name.p. Invoking gnuplot
on name.p will plot the data stored in name.dat.
- If you use argument postscript with a string name, Sollya will save a
postscript file called name.eps representing your plot.
- If you use argument postscriptfile with a string name, Sollya will
produce the corresponding name.dat, name.p and name.eps.
- By default, this command uses gnuplot to produce the final plot. If Sollya
is run while the environment variable SOLLYA_GNUPLOT is set, the content of
that variable is used as the gnuplot binary.
If your terminal is not graphic (typically if you use Sollya through
ssh without -X)
gnuplot should be able to detect that and produce an ASCII-art version on the
standard output. If it is not the case, you can either store the plot in a
postscript file to view it locally, or use asciiplot command.
- If every function is constant, plot will not plot them but just display
their value.
- If the interval is reduced to a single point, plot will just display the
value of the functions at this point.
Example 1:
> plot(sin(x),0,cos(x),[-Pi,Pi]);
Example 2:
> plot(sin(x),0,cos(x),[-Pi,Pi],postscriptfile,"plotSinCos");
Example 3:
> plot(exp(0), sin(1), [0;1]);
1
0.84147098480789650665250232163029899962256306079837
Example 4:
> plot(sin(x), cos(x), [1;1]);
0.84147098480789650665250232163029899962256306079837
0.54030230586813971740093660744297660373231042061792
Go back to the list of commands
Name:
+
addition function
Library names:
sollya_obj_t sollya_lib_add(sollya_obj_t, sollya_obj_t)
sollya_obj_t sollya_lib_build_function_add(sollya_obj_t, sollya_obj_t)
#define SOLLYA_ADD(x,y) sollya_lib_build_function_add((x), (y))
Usage:
function1 + function2 : (function, function) -> function
interval1 + interval2 : (range, range) -> range
interval1 + constant : (range, constant) -> range
interval1 + constant : (constant, range) -> range
Parameters:
- function1 and function2 represent functions
- interval1 and interval2 represent intervals (ranges)
- constant represents a constant or constant expression
Description:
- + represents the addition (function) on reals.
The expression function1 + function2 stands for
the function composed of the addition function and the two
functions function1 and function2.
- + can be used for interval arithmetic on intervals
(ranges). + will evaluate to an interval that safely
encompasses all images of the addition function with arguments varying
in the given intervals. Any combination of intervals with intervals
or constants (resp. constant expressions) is supported. However, it is
not possible to represent families of functions using an interval as
one argument and a function (varying in the free variable) as the
other one.
Example 1:
> 1 + 2;
3
Example 2:
> x + 2;
2 + x
Example 3:
> x + x;
x * 2
Example 4:
> diff(sin(x) + exp(x));
cos(x) + exp(x)
Example 5:
> [1;2] + [3;4];
[4;6]
> [1;2] + 17;
[18;19]
> 13 + [-4;17];
[9;30]
Go back to the list of commands
Name:
points
controls the number of points chosen by Sollya in certain commands.
Library names:
void sollya_lib_set_points_and_print(sollya_obj_t)
void sollya_lib_set_points(sollya_obj_t)
sollya_obj_t sollya_lib_get_points()
Parameters:
- n represents the number of points
Example 1:
> f=x^2*sin(1/x);
> points=10;
The number of points has been set to 10.
> dirtyfindzeros(f, [0;1]);
[|0, 0.31830988618379067153776752674502872406891929148092|]
> points=100;
The number of points has been set to 100.
> dirtyfindzeros(f, [0;1]);
[|0, 2.4485375860291590118289809749617594159147637806224e-2, 3.9788735772973833942220940843128590508614911435115e-2, 4.5472840883398667362538218106432674866988470211559e-2, 5.3051647697298445256294587790838120678153215246819e-2, 6.3661977236758134307553505349005744813783858296184e-2, 7.957747154594766788444188168625718101722982287023e-2, 0.106103295394596890512589175581676241356306430493638, 0.15915494309189533576888376337251436203445964574046, 0.31830988618379067153776752674502872406891929148092|]
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_postscriptfile()
int sollya_lib_is_postscriptfile(sollya_obj_t)
Description:
- postscriptfile is a special value used in commands plot and externalplot to save
the result of the command in a data file and a postscript file.
- As any value it can be affected to a variable and stored in lists.
Example 1:
> savemode=postscriptfile;
> name="plotSinCos";
> plot(sin(x),0,cos(x),[-Pi,Pi],savemode, name);
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_postscript()
int sollya_lib_is_postscript(sollya_obj_t)
Description:
- postscript is a special value used in commands plot and externalplot to save
the result of the command in a postscript file.
- As any value it can be affected to a variable and stored in lists.
Example 1:
> savemode=postscript;
> name="plotSinCos";
> plot(sin(x),0,cos(x),[-Pi,Pi],savemode, name);
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_pow(sollya_obj_t, sollya_obj_t)
sollya_obj_t sollya_lib_build_function_pow(sollya_obj_t, sollya_obj_t)
#define SOLLYA_POW(x,y) sollya_lib_build_function_pow((x), (y))
Usage:
function1 ^ function2 : (function, function) -> function
interval1 ^ interval2 : (range, range) -> range
interval1 ^ constant : (range, constant) -> range
interval1 ^ constant : (constant, range) -> range
Parameters:
- function1 and function2 represent functions
- interval1 and interval2 represent intervals (ranges)
- constant represents a constant or constant expression
Description:
- ^ represents the power (function) on reals.
The expression function1 ^ function2 stands for
the function composed of the power function and the two
functions function1 and function2, where function1 is
the base and function2 the exponent.
If function2 is a constant integer, ^ is defined
on negative values of function1. Otherwise ^
is defined as exp(y * log(x)).
- Note that whenever several ^ are composed, the priority goes
to the last ^. This corresponds to the natural way of
thinking when a tower of powers is written on a paper.
Thus, 2^3^5 is interpreted as 2^(3^5).
- ^ can be used for interval arithmetic on intervals
(ranges). ^ will evaluate to an interval that safely
encompasses all images of the power function with arguments
varying in the given intervals. If the intervals given contain points
where the power function is not defined, infinities and NaNs will be
produced in the output interval. Any combination of intervals with
intervals or constants (resp. constant expressions) is
supported. However, it is not possible to represent families of
functions using an interval as one argument and a function (varying in
the free variable) as the other one.
Example 1:
> 5 ^ 2;
25
Example 2:
> x ^ 2;
x^2
Example 3:
> 3 ^ (-5);
4.1152263374485596707818930041152263374485596707819e-3
Example 4:
> (-3) ^ (-2.5);
NaN
Example 5:
> diff(sin(x) ^ exp(x));
sin(x)^exp(x) * ((cos(x) * exp(x)) / sin(x) + exp(x) * log(sin(x)))
Example 6:
> 2^3^5;
14134776518227074636666380005943348126619871175004951664972849610340958208
> (2^3)^5;
32768
> 2^(3^5);
14134776518227074636666380005943348126619871175004951664972849610340958208
Example 7:
> [1;2] ^ [3;4];
[1;16.000000000000000000000000000000000000000000000001]
> [1;2] ^ 17;
[1;131072]
> 13 ^ [-4;17];
[3.501277966457757081334687160813696999404782745702e-5;8650415919381337933]
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_powers()
int sollya_lib_is_powers(sollya_obj_t)
Description:
- powers is a special value used for the global state display. If
the global state display is equal to powers, all data will be
output in dyadic notation with numbers displayed in a Maple and
PARI/GP compatible format.
As any value it can be affected to a variable and stored in lists.
Go back to the list of commands
Name:
precision
returns the precision necessary to represent a number.
Library name:
sollya_obj_t sollya_lib_precision(sollya_obj_t)
Description:
- precision(x) is by definition |x| if x equals 0, NaN, or Inf.
- If x is not zero, it can be uniquely written as x = m*2^e where
m is an odd integer and e is an integer. precision(x) returns the number
of bits necessary to write m in binary (i.e. 1+floor(log2(m))).
Example 1:
> a=round(Pi,20,RN);
> precision(a);
19
> m=mantissa(a);
> 1+floor(log2(m));
19
Example 2:
> a=255;
> precision(a);
8
> m=mantissa(a);
> 1+floor(log2(m));
8
Example 3:
> a=256;
> precision(a);
1
> m=mantissa(a);
> 1+floor(log2(m));
1
Go back to the list of commands
Name:
prec
controls the precision used in numerical computations.
Library names:
void sollya_lib_set_prec_and_print(sollya_obj_t)
void sollya_lib_set_prec(sollya_obj_t)
sollya_obj_t sollya_lib_get_prec()
Description:
- prec is a global variable. Its value represents the precision of the
floating-point format used in numerical computations.
- Many commands try to adapt their working precision in order to have
approximately n correct bits in output, where n is the value of prec.
Example 1:
> display=binary!;
> prec=50;
The precision has been set to 50 bits.
> dirtyinfnorm(exp(x),[1;2]);
1.110110001110011001001011100011010100110111011011_2 * 2^(2)
> prec=100;
The precision has been set to 100 bits.
> dirtyinfnorm(exp(x),[1;2]);
1.11011000111001100100101110001101010011011101101011011100110000110011101000111011101000100000011011_2 * 2^(2)
Go back to the list of commands
Name:
.:
add an element at the beginning of a list.
Library name:
sollya_obj_t sollya_lib_prepend(sollya_obj_t, sollya_obj_t)
Usage:
x.:L : (any type, list) -> list
Parameters:
- x is an object of any type.
- L is a list (possibly empty).
Description:
- .: adds the element x at the beginning of the list L.
- Note that since x may be of any type, it can be in particular a list.
Example 1:
> 1.:[|2,3,4|];
[|1, 2, 3, 4|]
Example 2:
> [|1,2,3|].:[|4,5,6|];
[|[|1, 2, 3|], 4, 5, 6|]
Example 3:
> 1.:[||];
[|1|]
Go back to the list of commands
Name:
printdouble
prints a constant value as a hexadecimal double precision number
Library name:
void sollya_lib_printdouble(sollya_obj_t)
Parameters:
- constant represents a constant
Description:
- Prints a constant value as a hexadecimal number on 16 hexadecimal
digits. The hexadecimal number represents the integer equivalent to
the 64 bit memory representation of the constant considered as a
double precision number.
If the constant value does not hold on a double precision number, it
is first rounded to the nearest double precision number before
displayed. A warning is displayed in this case.
Example 1:
> printdouble(3);
0x4008000000000000
Example 2:
> prec=100!;
> verbosity = 1!;
> printdouble(exp(5));
Warning: the given expression is not a constant but an expression to evaluate. A faithful evaluation to 100 bits will be used.
Warning: rounding down occurred before printing a value as a double.
0x40628d389970338f
Go back to the list of commands
Name:
printexpansion
prints a polynomial in Horner form with its coefficients written as a expansions of double precision numbers
Library name:
void sollya_lib_printexpansion(sollya_obj_t)
Parameters:
- polynomial represents the polynomial to be printed
Description:
- The command printexpansion prints the polynomial polynomial in Horner form
writing its coefficients as expansions of double precision
numbers. The double precision numbers themselves are displayed in
hexadecimal memory notation (see printdouble).
If some of the coefficients of the polynomial polynomial are not
floating-point constants but constant expressions, they are evaluated
to floating-point constants using the global precision prec. If a
rounding occurs in this evaluation, a warning is displayed.
If the exponent range of double precision is not sufficient to display
all the mantissa bits of a coefficient, the coefficient is displayed
rounded and a warning is displayed.
If the argument polynomial does not a polynomial, nothing but a
warning or a newline is displayed. Constants can be displayed using
printexpansion since they are polynomials of degree 0.
Example 1:
> printexpansion(roundcoefficients(taylor(exp(x),5,0),[|DD...|]));
0x3ff0000000000000 + x * (0x3ff0000000000000 + x * (0x3fe0000000000000 + x * ((0x3fc5555555555555 + 0x3c65555555555555) + x * ((0x3fa5555555555555 + 0x3c45555555555555) + x * (0x3f81111111111111 + 0x3c01111111111111)))))
Example 2:
> printexpansion(remez(exp(x),5,[-1;1]));
(0x3ff0002eec90e5a6 + 0x3c9ea6a6a0087757 + 0xb8eb3e644ef44998) + x * ((0x3ff00028358fd3ac + 0x3c8ffa7d96c95f7a + 0xb91da9809b13dd54 + 0x35c0000000000000) + x * ((0x3fdff2d7e6a9fea5 + 0x3c74460e4c0e4fe2 + 0x38fcd1b6b4e85bb0 + 0x3590000000000000) + x * ((0x3fc54d6733b4839e + 0x3c6654e4d8614a44 + 0xb905c7a26b66ea92 + 0xb598000000000000) + x * ((0x3fa66c209b7150a8 + 0x3c34b1bba8f78092 + 0xb8c75f6eb90dae02 + 0x3560000000000000) + x * (0x3f81e554242ab128 + 0xbc23e920a76e760c + 0x38c0589c2cae6caf + 0x3564000000000000)))))
Example 3:
> verbosity = 1!;
> prec = 3500!;
> printexpansion(pi);
(0x400921fb54442d18 + 0x3ca1a62633145c07 + 0xb92f1976b7ed8fbc + 0x35c4cf98e804177d + 0x32631d89cd9128a5 + 0x2ec0f31c6809bbdf + 0x2b5519b3cd3a431b + 0x27e8158536f92f8a + 0x246ba7f09ab6b6a9 + 0xa0eedd0dbd2544cf + 0x1d779fb1bd1310ba + 0x1a1a637ed6b0bff6 + 0x96aa485fca40908e + 0x933e501295d98169 + 0x8fd160dbee83b4e0 + 0x8c59b6d799ae131c + 0x08f6cf70801f2e28 + 0x05963bf0598da483 + 0x023871574e69a459 + 0x8000000005702db3 + 0x8000000000000000)
Warning: the expansion is not complete because of the limited exponent range of double precision.
Warning: rounding occurred while printing.
Go back to the list of commands
Name:
print
prints an expression
Usage:
print(expr1,...,exprn) : (any type,..., any type) -> void
print(expr1,...,exprn) > filename : (any type,..., any type, string) -> void
print(expr1,...,exprn) >> filename : (any type,...,any type, string) -> void
Parameters:
- expr represents an expression
- filename represents a character sequence indicating a file name
Description:
- print(expr1,...,exprn) prints the expressions expr1 through
exprn separated by spaces and followed by a newline.
If a second argument filename is given after a single ">", the
displaying is not output on the standard output of Sollya but if in
the file filename that get newly created or overwritten. If a double
">>" is given, the output will be appended to the file filename.
The global variables display, midpointmode and fullparentheses have
some influence on the formatting of the output (see display,
midpointmode and fullparentheses).
Remark that if one of the expressions expri given in argument is of
type string, the character sequence expri evaluates to is
displayed. However, if expri is of type list and this list
contains a variable of type string, the expression for the list
is displayed, i.e. all character sequences get displayed surrounded
by double quotes ("). Nevertheless, escape sequences used upon defining
character sequences are interpreted immediately.
Example 1:
> print(x + 2 + exp(sin(x)));
x + 2 + exp(sin(x))
> print("Hello","world");
Hello world
> print("Hello","you", 4 + 3, "other persons.");
Hello you 7 other persons.
Example 2:
> print("Hello");
Hello
> print([|"Hello"|]);
[|"Hello"|]
> s = "Hello";
> print(s,[|s|]);
Hello [|"Hello"|]
> t = "Hello\tyou";
> print(t,[|t|]);
Hello you [|"Hello\tyou"|]
Example 3:
> print(x + 2 + exp(sin(x))) > "foo.sol";
> readfile("foo.sol");
x + 2 + exp(sin(x))
Example 4:
> print(x + 2 + exp(sin(x))) >> "foo.sol";
Example 5:
> display = decimal;
Display mode is decimal numbers.
> a = evaluate(sin(pi * x), 0.25);
> b = evaluate(sin(pi * x), [0.25; 0.25 + 1b-50]);
> print(a);
0.70710678118654752440084436210484903928483593768847
> display = binary;
Display mode is binary numbers.
> print(a);
1.01101010000010011110011001100111111100111011110011001001000010001011001011111011000100110110011011101010100101010111110100111110001110101101111011000001011101010001_2 * 2^(-1)
> display = hexadecimal;
Display mode is hexadecimal numbers.
> print(a);
0x1.6a09e667f3bcc908b2fb1366ea957d3e3adec1751p-1
> display = dyadic;
Display mode is dyadic numbers.
> print(a);
33070006991101558613323983488220944360067107133265b-165
> display = powers;
Display mode is dyadic numbers in integer-power-of-2 notation.
> print(a);
33070006991101558613323983488220944360067107133265 * 2^(-165)
> display = decimal;
Display mode is decimal numbers.
> midpointmode = off;
Midpoint mode has been deactivated.
> print(b);
[0.70710678118654752440084436210484903928483593768845;0.70710678118654949743721782517557347782646274417049]
> midpointmode = on;
Midpoint mode has been activated.
> print(b);
0.7071067811865~4/5~
> display = dyadic;
Display mode is dyadic numbers.
> print(b);
[2066875436943847413332748968013809022504194195829b-161;16535003495550825444196237019385936414432675156571b-164]
> display = decimal;
Display mode is decimal numbers.
> autosimplify = off;
Automatic pure tree simplification has been deactivated.
> fullparentheses = off;
Full parentheses mode has been deactivated.
> print(x + x * ((x + 1) + 1));
x + x * (x + 1 + 1)
> fullparentheses = on;
Full parentheses mode has been activated.
> print(x + x * ((x + 1) + 1));
x + (x * ((x + 1) + 1))
See also: write,
printexpansion,
printdouble,
printsingle,
printxml,
readfile,
autosimplify,
display,
midpointmode,
fullparentheses,
evaluate,
rationalmode
Go back to the list of commands
Name:
printsingle
prints a constant value as a hexadecimal single precision number
Library name:
void sollya_lib_printsingle(sollya_obj_t)
Parameters:
- constant represents a constant
Description:
- Prints a constant value as a hexadecimal number on 8 hexadecimal
digits. The hexadecimal number represents the integer equivalent to
the 32 bit memory representation of the constant considered as a
single precision number.
If the constant value does not hold on a single precision number, it
is first rounded to the nearest single precision number before it is
displayed. A warning is displayed in this case.
Example 1:
> printsingle(3);
0x40400000
Example 2:
> prec=100!;
> verbosity = 1!;
> printsingle(exp(5));
Warning: the given expression is not a constant but an expression to evaluate. A faithful evaluation to 100 bits will be used.
Warning: rounding up occurred before printing a value as a single.
0x431469c5
Go back to the list of commands
Name:
printxml
prints an expression as an MathML-Content-Tree
Library names:
void sollya_lib_printxml(sollya_obj_t)
void sollya_lib_printxml_newfile(sollya_obj_t, sollya_obj_t)
void sollya_lib_printxml_appendfile(sollya_obj_t, sollya_obj_t)
Usage:
printxml(expr) : function -> void
printxml(expr) > filename : (function, string) -> void
printxml(expr) > > filename : (function, string) -> void
Parameters:
- expr represents a functional expression
- filename represents a character sequence indicating a file name
Description:
- The command printxml is now considered DEPRECATED in Sollya.
- printxml(expr) prints the functional expression expr as a tree of
MathML Content Definition Markups. This XML tree can be re-read in
external tools or by usage of the readxml command.
If a second argument filename is given after a single ">", the
MathML tree is not output on the standard output of Sollya but if in
the file filename that get newly created or overwritten. If a double
">" is given, the output will be appended to the file filename.
Example 1:
> printxml(x + 2 + exp(sin(x)));
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated by sollya: http://sollya.org/ -->
<!-- syntax: printxml(...); example: printxml(x^2-2*x+5); -->
<?xml-stylesheet type="text/xsl" href="http://sollya.org/mathmlc2p-web.xsl"?>
<?xml-stylesheet type="text/xsl" href="mathmlc2p-web.xsl"?>
<!-- This stylesheet allows direct web browsing of MathML-c XML files (http:// or file://) -->
<math xmlns="http://www.w3.org/1998/Math/MathML">
<semantics>
<annotation-xml encoding="MathML-Content">
<lambda>
<bvar><ci> x </ci></bvar>
<apply>
<apply>
<plus/>
<apply>
<plus/>
<ci> x </ci>
<cn type="integer" base="10"> 2 </cn>
</apply>
<apply>
<exp/>
<apply>
<sin/>
<ci> x </ci>
</apply>
</apply>
</apply>
</apply>
</lambda>
</annotation-xml>
<annotation encoding="sollya/text">(x + 1b1) + exp(sin(x))</annotation>
</semantics>
</math>
Example 2:
> printxml(x + 2 + exp(sin(x))) > "foo.xml";
Example 3:
> printxml(x + 2 + exp(sin(x))) >> "foo.xml";
Go back to the list of commands
Name:
procedure
defines and assigns a Sollya procedure
Usage:
procedure identifier(formal parameter1, formal parameter2,..., formal parameter n) { procedure body } : void -> void
procedure identifier(formal parameter1, formal parameter2,..., formal parameter n) { procedure body return expression; } : void -> void
procedure identifier(formal list parameter = ...) { procedure body } : void -> void
procedure identifier(formal list parameter = ...) { procedure body return expression; } : void -> void
Parameters:
- identifier represents the name of the procedure to be defined and assigned
- formal parameter1, formal parameter2 through formal parameter n represent identifiers used as formal parameters
- formal list parameter represents an identifier used as a formal parameter for the list of an arbitrary number of parameters
- procedure body represents the imperative statements in the body of the procedure
- expression represents the expression procedure shall evaluate to
Description:
- The procedure keyword allows for defining and assigning procedures in
the Sollya language. It is an abbreviation to a procedure definition
using proc with the same formal parameters, procedure body and
return-expression followed by an assignment of the procedure (object)
to the identifier identifier. In particular, all rules concerning
local variables declared using the var keyword apply for procedure.
Example 1:
> procedure succ(n) { return n + 1; };
> succ(5);
6
> 3 + succ(0);
4
> succ;
proc(n)
{
nop;
return (n) + (1);
}
Example 2:
> procedure myprint(L = ...) { var i; for i in L do i; };
> myprint("Lyon","Nancy","Beaverton","Coye-la-Foret","Amberg","Nizhny Novgorod","Cluj-Napoca");
Lyon
Nancy
Beaverton
Coye-la-Foret
Amberg
Nizhny Novgorod
Cluj-Napoca
Go back to the list of commands
Name:
proc
defines a Sollya procedure
Usage:
proc(formal parameter1, formal parameter2,..., formal parameter n) { procedure body } : void -> procedure
proc(formal parameter1, formal parameter2,..., formal parameter n) { procedure body return expression; } : void -> procedure
proc(formal list parameter = ...) { procedure body } : void -> procedure
proc(formal list parameter = ...) { procedure body return expression; } : void -> procedure
Parameters:
- formal parameter1, formal parameter2 through formal parameter n represent identifiers used as formal parameters
- formal list parameter represents an identifier used as a formal parameter for the list of an arbitrary number of parameters
- procedure body represents the imperative statements in the body of the procedure
- expression represents the expression proc shall evaluate to
Description:
- The proc keyword allows for defining procedures in the Sollya
language. These procedures are common Sollya objects that can be
applied to actual parameters after definition. Upon such an
application, the Sollya interpreter applies the actual parameters to
the formal parameters formal parameter1 through formal parameter n
(resp. builds up the list of arguments and applies it to the list
formal list parameter) and executes the procedure body. The
procedure applied to actual parameters evaluates then to the
expression expression in the return statement after the procedure body
or to void, if no return statement is given (i.e. a return
void statement is implicitly given).
- Sollya procedures defined by proc have no name. They can be bound
to an identifier by assigning the procedure object a proc
expression produces to an identifier. However, it is possible to use
procedures without giving them any name. For instance, Sollya
procedures, i.e. procedure objects, can be elements of lists. They can
even be given as an argument to other internal Sollya procedures. See
also procedure on this subject.
- Upon definition of a Sollya procedure using proc, no type check
is performed. More precisely, the statements in procedure body are
merely parsed but not interpreted upon procedure definition with
proc. Type checks are performed once the procedure is applied to
actual parameters or to void. At this time, if the procedure was
defined using several different formal parameters formal parameter 1
through formal parameter n, it is checked whether the number of
actual parameters corresponds to the number of formal parameters. If
the procedure was defined using the syntax for a procedure with an
arbitrary number of parameters by giving a formal list parameter,
the number of actual arguments is not checked but only a list
formal list parameter of appropriate length is built up. Type checks are
further performed upon execution of each statement in procedure body
and upon evaluation of the expression expression to be returned.
Procedures defined by proc containing a quit or restart command
cannot be executed (i.e. applied). Upon application of a procedure,
the Sollya interpreter checks beforehand for such a statement. If one
is found, the application of the procedure to its arguments evaluates
to error. A warning is displayed. Remark that in contrast to other
type or semantic correctness checks, this check is really performed
before interpreting any other statement in the body of the procedure.
- Through the var keyword it is possible to declare local
variables and thus to have full support of recursive procedures. This
means a procedure defined using proc may contain in its procedure body
an application of itself to some actual parameters: it suffices
to assign the procedure (object) to an identifier with an appropriate
name.
- Sollya procedures defined using proc may return other
procedures. Further procedure body may contain assignments of
locally defined procedure objects to identifiers. See var for the
particular behaviour of local and global variables.
- The expression expression returned by a procedure is evaluated with
regard to Sollya commands, procedures and external
procedures. Simplification may be performed. However, an application
of a procedure defined by proc to actual parameters evaluates to the
expression expression that may contain the free global variable or
that may be composed.
Example 1:
> succ = proc(n) { return n + 1; };
> succ(5);
6
> 3 + succ(0);
4
> succ;
proc(n)
{
nop;
return (n) + (1);
}
Example 2:
> add = proc(m,n) { var res; res := m + n; return res; };
> add(5,6);
11
> add;
proc(m, n)
{
var res;
res := (m) + (n);
return res;
}
> verbosity = 1!;
> add(3);
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
error
> add(true,false);
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
Warning: the given expression or command could not be handled.
error
Example 3:
> succ = proc(n) { return n + 1; };
> succ(5);
6
> succ(x);
1 + x
Example 4:
> hey = proc() { print("Hello world."); };
> hey();
Hello world.
> print(hey());
Hello world.
void
> hey;
proc()
{
print("Hello world.");
return void;
}
Example 5:
> fac = proc(n) { var res; if (n == 0) then res := 1 else res := n * fac(n - 1); return res; };
> fac(5);
120
> fac(11);
39916800
> fac;
proc(n)
{
var res;
if (n) == (0) then
res := 1
else
res := (n) * (fac((n) - (1)));
return res;
}
Example 6:
> myprocs = [| proc(m,n) { return m + n; }, proc(m,n) { return m - n; } |];
> (myprocs[0])(5,6);
11
> (myprocs[1])(5,6);
-1
> succ = proc(n) { return n + 1; };
> pred = proc(n) { return n - 1; };
> applier = proc(p,n) { return p(n); };
> applier(succ,5);
6
> applier(pred,5);
4
Example 7:
> verbosity = 1!;
> myquit = proc(n) { print(n); quit; };
> myquit;
proc(n)
{
print(n);
quit;
return void;
}
> myquit(5);
Warning: a quit or restart command may not be part of a procedure body.
The procedure will not be executed.
Warning: an error occurred while executing a procedure.
Warning: the given expression or command could not be handled.
error
Example 8:
> printsucc = proc(n) { var succ; succ = proc(n) { return n + 1; }; print("Successor of",n,"is",succ(n)); };
> printsucc(5);
Successor of 5 is 6
Example 9:
> makeadd = proc(n) { var add; print("n =",n); add = proc(m,n) { return n + m; }; return add; };
> makeadd(4);
n = 4
proc(m, n)
{
nop;
return (n) + (m);
}
> (makeadd(4))(5,6);
n = 4
11
Example 10:
> sumall = proc(L = ...) { var acc, i; acc = 0; for i in L do acc = acc + i; return acc; };
> sumall;
proc(L = ...)
{
var acc, i;
acc = 0;
for i in L do
acc = (acc) + (i);
return acc;
}
> sumall();
0
> sumall(2);
2
> sumall(2,5);
7
> sumall(2,5,7,9,16);
39
> sumall @ [|1,...,10|];
55
Go back to the list of commands
Names:
quad,
QD
rounding to the nearest IEEE 754 quad (binary128).
Library names:
sollya_obj_t sollya_lib_quad(sollya_obj_t)
sollya_obj_t sollya_lib_quad_obj()
int sollya_lib_is_quad_obj(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_quad(sollya_obj_t)
#define SOLLYA_QD(x) sollya_lib_build_function_quad(x)
Description:
- quad is both a function and a constant.
- As a function, it rounds its argument to the nearest IEEE 754 quad precision (i.e. IEEE754-2008 binary128) number.
Subnormal numbers are supported as well as standard numbers: it is the real
rounding described in the standard.
- As a constant, it symbolizes the quad precision format. It is used in
contexts when a precision format is necessary, e.g. in the commands
round and roundcoefficients. It is not supported for implementpoly.
See the corresponding help pages for examples.
Example 1:
> display=binary!;
> QD(0.1);
1.100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001101_2 * 2^(-4)
> QD(4.17);
1.000010101110000101000111101011100001010001111010111000010100011110101110000101000111101011100001010001111010111_2 * 2^(2)
> QD(1.011_2 * 2^(-16493));
1.1_2 * 2^(-16493)
See also: halfprecision,
single,
double,
doubleextended,
doubledouble,
tripledouble,
roundcoefficients,
implementpoly,
fpminimax,
round,
printsingle
Go back to the list of commands
Usage:
quit : void -> void
Description:
- The command quit, when executed, stops the execution of a Sollya
script and leaves the Sollya interpreter unless the quit command
is executed in a Sollya script read into a main Sollya script by
execute or #include.
Upon exiting the Sollya interpreter, all state is thrown away, all
memory is deallocated, all bound libraries are unbound and the
temporary files produced by plot and externalplot are deleted.
If the quit command does not lead to a halt of the Sollya
interpreter, a warning is displayed.
Go back to the list of commands
Name:
range
keyword representing a range type
Library name:
SOLLYA_EXTERNALPROC_TYPE_RANGE
Description:
- range represents the range type for declarations
of external procedures by means of externalproc.
Remark that in contrast to other indicators, type indicators like
range cannot be handled outside the externalproc context. In
particular, they cannot be assigned to variables.
Go back to the list of commands
Library name:
sollya_obj_t sollya_lib_rationalapprox(sollya_obj_t, sollya_obj_t)
Parameters:
- x is a number to approximate.
- n is a integer (representing a format).
Description:
- rationalapprox(x,n) returns a constant function of the form a/b where a and b are
integers. The value a/b is an approximation of x. The quality of this
approximation is determined by the parameter n that indicates the number of
correct bits that a/b should have.
- The command is not safe in the sense that it is not ensured that the error
between a/b and x is less than 2^(-n).
- The following algorithm is used: x is first rounded downwards and upwards to
a format of n bits, thus obtaining an interval [xl,xu]. This interval is then
developed into a continued fraction as far as the representation is the same
for every elements of [xl,xu]. The corresponding fraction is returned.
- Since rational numbers are not a primitive object of Sollya, the fraction is
returned as a constant function. This can be quite amazing, because Sollya
immediately simplifies a constant function by evaluating it when the constant
has to be displayed.
To avoid this, you can use print (that displays the expression representing
the constant and not the constant itself) or the commands numerator
and denominator.
Example 1:
> pi10 = rationalapprox(Pi,10);
> pi50 = rationalapprox(Pi,50);
> pi100 = rationalapprox(Pi,100);
> print( pi10, ": ", dirtysimplify(floor(-log2(abs(pi10-Pi)/Pi))), "bits." );
3.140625 : 11 bits.
> print( pi50, ": ", dirtysimplify(floor(-log2(abs(pi50-Pi)/Pi))), "bits." );
85563208 / 27235615 : 51 bits.
> print( pi100, ": ", dirtysimplify(floor(-log2(abs(pi100-Pi)/Pi))), "bits." );
4422001152019829 / 1407566683404023 : 100 bits.
Example 2:
> a=0.1;
> b=rationalapprox(a,4);
> numerator(b); denominator(b);
1
10
> print(dirtysimplify(floor(-log2(abs((b-a)/a)))), "bits.");
166 bits.
Go back to the list of commands
Name:
rationalmode
global variable controlling if rational arithmetic is used or not.
Library names:
void sollya_lib_set_rationalmode_and_print(sollya_obj_t)
void sollya_lib_set_rationalmode(sollya_obj_t)
sollya_obj_t sollya_lib_get_rationalmode()
Parameters:
- activation value controls if rational arithmetic should be used or not
Description:
- rationalmode is a global variable. When its value is off, which is the
default, Sollya will not use rational arithmetic to simplify expressions. All
computations, including the evaluation of constant expressions given on the
Sollya prompt, will be performed using floating-point and interval
arithmetic.
Constant expressions will be approximated by floating-point numbers, which
are in most cases faithful roundings of the expressions, when shown at the
prompt.
- When the value of the global variable rationalmode is on, Sollya will use
rational arithmetic when simplifying expressions. Constant expressions, given
at the Sollya prompt, will be simplified to rational numbers and displayed
as such when they are in the set of the rational numbers. Otherwise,
floating-point and interval arithmetic will be used to compute a
floating-point approximation, which is in most cases a faithful rounding of
the constant expression.
- When a decimal value is parsed, the behavior of Sollya is different
depending on the value of the global variable rationalmode. If it is off, the
value gets rounded as a floating-point at precision prec. But if rationalmode
is set to on, the decimal value is interpreted exactly and converted as a
rational number of the form M/10^N where M and N are integers. Accordingly,
when rationalmode is set to on and display is set to decimal, all
floating-point values are displayed exactly: indeed, any floating-point
number with radix 2 has a finite decimal expansion. Therefore, any rational
number of the form M/(2^P*5^Q) gets displayed as an exact decimal value
(while other fractions get displayed as fractions).
Example 1:
> rationalmode=off!;
> 19/17 + 3/94;
1.1495619524405506883604505632040050062578222778473
> rationalmode=on!;
> 19/17 + 3/94;
1837 / 1598
Example 2:
> rationalmode=off!;
> exp(19/17 + 3/94);
3.1568097739551413675470920894482427634032816281442
> rationalmode=on!;
> exp(19/17 + 3/94);
3.1568097739551413675470920894482427634032816281441796574919218482279430946893345552216426846046106958476007343642301414070837350944742638603202067315578460693359375
Example 3:
> prec = 12!;
> rationalmode=off!;
> r = 0.1;
> r == 1/10;
false
> rationalmode=on!;
> s = 0.1;
> s == 1/10;
true
> r == s;
false
> r;
0.100006103515625
> s;
0.1
Go back to the list of commands
Name:
RD
constant representing rounding-downwards mode.
Library names:
sollya_obj_t sollya_lib_round_down()
int sollya_lib_is_round_down(sollya_obj_t)
Description:
- RD is used in command round to specify that the value x must be rounded
to the greatest floating-point number y such that y <= x.
Example 1:
> display=binary!;
> round(Pi,20,RD);
1.1001001000011111101_2 * 2^(1)
Go back to the list of commands
Name:
readfile
reads the content of a file into a string variable
Usage:
readfile(filename) : string -> string
Parameters:
- filename represents a character sequence indicating a file name
Description:
- readfile opens the file indicated by filename, reads it and puts its
contents in a character sequence of type string that is returned.
If the file indicated by filename cannot be opened for reading, a
warning is displayed and readfile evaluates to an error variable of
type error.
Example 1:
> print("Hello world") > "myfile.txt";
> t = readfile("myfile.txt");
> t;
Hello world
Example 2:
> verbosity=1!;
> readfile("afile.txt");
Warning: the file "afile.txt" could not be opened for reading.
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
error
Go back to the list of commands
Name:
readxml
reads an expression written as a MathML-Content-Tree in a file
Library name:
sollya_obj_t sollya_lib_readxml(sollya_obj_t)
Usage:
readxml(filename) : string -> function | error
Parameters:
- filename represents a character sequence indicating a file name
Description:
- The command readxml is now considered DEPRECATED in Sollya.
- readxml(filename) reads the first occurrence of a lambda
application with one bounded variable on applications of the supported
basic functions in file filename and returns it as a Sollya
functional expression.
If the file filename does not contain a valid MathML-Content tree,
readxml tries to find an "annotation encoding" markup of type
"sollya/text". If this annotation contains a character sequence
that can be parsed by parse, readxml returns that expression. Otherwise
readxml displays a warning and returns an error variable of type
error.
Example 1:
> readxml("readxmlexample.xml");
2 + x + exp(sin(x))
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_relative()
int sollya_lib_is_relative(sollya_obj_t)
Example 1:
> bashexecute("gcc -fPIC -c externalplotexample.c");
> bashexecute("gcc -shared -o externalplotexample externalplotexample.o -lgmp -lmpfr");
> externalplot("./externalplotexample",relative,exp(x),[-1/2;1/2],12,perturb);
Go back to the list of commands
Name:
remez
computes the minimax of a function on an interval.
Library names:
sollya_obj_t sollya_lib_remez(sollya_obj_t, sollya_obj_t, sollya_obj_t, ...)
sollya_obj_t sollya_lib_v_remez(sollya_obj_t, sollya_obj_t, sollya_obj_t,
va_list)
Usage:
remez(f, n, range, w, quality, bounds) : (function, integer, range, function, constant, range) -> function
remez(f, L, range, w, quality, bounds) : (function, list, range, function, constant, range) -> function
Parameters:
- f is the function to be approximated
- n is the degree of the polynomial that must approximate f
- L is a list of integers or a list of functions and indicates the basis for the approximation of f
- range is the interval where the function must be approximated
- w (optional) is a weight function. Default is 1.
- quality (optional) is a parameter that controls the quality of the returned polynomial p, with respect to the exact minimax p*. Default is 1e-5.
- bounds (optional) is a parameter that allows the user to make the algorithm stop earlier, whenever a given accuracy is reached or a given accuracy is proved unreachable. Default is [0, +Inf].
Description:
- remez computes an approximation of the function f with respect to
the weight function w on the interval range. More precisely, it
searches p such that ||p*w-f|| is
(almost) minimal among all p of a certain form. The norm is
the infinity norm, e.g. ||g|| = max {|g(x)|, x in range}.
- If w=1 (the default case), it consists in searching the best
polynomial approximation of f with respect to the absolute error.
If f=1 and w is of the form 1/g, it consists in
searching the best polynomial approximation of g with respect to the
relative error.
- If n is given, p is searched among the polynomials with degree not
greater than n.
If L is given and is a list of integers, p is searched as a linear
combination of monomials X^k where k belongs to L.
In the case when L is a list of integers, it may contain ellipses but
cannot be end-elliptic.
If L is given and is a list of functions g_k, p is searched as a
linear combination of the g_k. In that case L cannot contain ellipses.
It is the user responsibility to check that the g_k are linearly independent
over the interval range. Moreover, the functions w*g_k must be at least
twice differentiable over range. If these conditions are not fulfilled, the
algorithm might fail or even silently return a result as if it successfully
found the minimax, though the returned p is not optimal.
- The polynomial is obtained by a convergent iteration called Remez'
algorithm (and an extension of this algorithm, due to Stiefel).
The algorithm computes a sequence p1, ..., pk, ...
such that ek = ||pk*w-f|| converges towards
the optimal value e. The algorithm is stopped when the relative error
between ek and e is less than quality.
For this reason, the returned polynomial usually has dyadic coefficients.
However, one should not rely on that property. Especially, a noticeable
exception to that statement is when we manage to detect that f/w exactly
simplifies to a polynomial of the required degree, in which case we return it
as it is without further rounding.
- The optional argument bounds is an interval [satisfying_err, target_err]
with the following behavior:
- if, during the algorithm, we manage to prove that target_err is
unreachable, we stop the algorithm returning the last computed
polynomial.
- if, during the algorithm, we obtain a polynomial with an error smaller
than satisfying_err, we stop the algorithm returning that polynomial.
- otherwise we loop until we find an optimal polynomial with the required
quality, as usual.
Examples of use:
[0, +Inf] (compute the optimal polynomial with the required quality)
[target_err] (stops as soon as a polynomial achieving target_err is
obtained or as soon as such a polynomial is proved not to
exist).
[0, target_err] (finds the optimal polynomial, but provided that its error
is smaller than target_err).
[satisfying_err, +Inf] (stops as soon as a polynomial achieving
satisfying_err is obtained. If such a polynomial
does not exist, returns the optimal polynomial).
Example 1:
> p = remez(exp(x),5,[0;1]);
> degree(p);
5
> dirtyinfnorm(p-exp(x),[0;1]);
1.1295698151096148707171193829266077607222634589363e-6
Example 2:
> p = remez(1,[|0,2,4,6,8|],[0,Pi/4],1/cos(x));
> canonical=on!;
> p;
0.99999999994393732180959690352543887130348096061124 - 0.49999999571556857768772053063721544670949467222259 * x^2 + 4.1666613233473633009941059480570275870113220089059e-2 * x^4 - 1.3886529147145693651355523880319714051047635695061e-3 * x^6 + 2.4372679177224179934800328511009205218114284220126e-5 * x^8
Example 3:
> p1 = remez(exp(x),5,[0;1],default,1e-5);
> p2 = remez(exp(x),5,[0;1],default,1e-10);
> p3 = remez(exp(x),5,[0;1],default,1e-15);
> dirtyinfnorm(p1-exp(x),[0;1]);
1.1295698151096148707171193829266077607222634589363e-6
> dirtyinfnorm(p2-exp(x),[0;1]);
1.12956980227478675612619255125474525171079325793124e-6
> dirtyinfnorm(p3-exp(x),[0;1]);
1.12956980227478675612619255125474525171079325793124e-6
Example 4:
> L = [|exp(x), sin(x), cos(x)-1, sin(x^3)|];
> g = (2^x-1)/x;
> p1 = remez(g, L, [-1/16;1/16]);
> p2 = remez(g, 3, [-1/16;1/16]);
> dirtyinfnorm(p1 - g, [-1/16;1/16]);
9.8841323829271038137685646777951687620288462194746e-8
> dirtyinfnorm(p2 - g, [-1/16;1/16]);
2.54337800593461418356437401152248866818783932027105e-9
Example 5:
> f = sin(x);
> I = [-3b-5;-1b-1074];
> time(popt = remez(1, [|1, 3, 4, 5, 7, 8, 9|], I, 1/f));
0.185799695000000000000000000000000000002291314966024
> time(p1 = remez(1, [|1, 3, 4, 5, 7, 8, 9|], I, 1/f, default, [0, 1b-73]));
0.134645933000000000000000000000000000002249871361033
> time(p2 = remez(1, [|1, 3, 4, 5, 7, 8, 9|], I, 1/f, default, [3b-72, +@Inf@]));
0.150942799000000000000000000000000000010601473971874
> dirtyinfnorm(popt/f-1, I);
2.06750931454112835098093903810531156576504665659064e-22
> dirtyinfnorm(p1/f-1, I);
2.49711266837493110470637913808914046704452778960875e-22
> dirtyinfnorm(p2/f-1, I);
5.4567247553615435246376977231253834265248756996947e-22
> 1b-73;
1.05879118406787542383540312584955245256423950195312e-22
> 3b-72;
6.3527471044072525430124187550973147153854370117187e-22
Go back to the list of commands
Name:
rename
rename the free variable.
Library name:
void sollya_lib_name_free_variable(const char *)
Usage:
rename(ident1,ident2) : void
Parameters:
- ident1 is the current name of the free variable.
- ident2 is a fresh name.
Description:
- rename permits a change of the name of the free variable. Sollya can handle
only one free variable at a time. The first time in a session that an
unbound name is used in a context where it can be interpreted as a free
variable, the name is used to represent the free variable of Sollya. In the
following, this name can be changed using rename.
- Be careful: if ident2 has been set before, its value will be lost. Use
the command isbound to know if ident2 is already used or not.
- If ident1 is not the current name of the free variable, an error occurs.
- If rename is used at a time when the name of the free variable has not been
defined, ident1 is just ignored and the name of the free variable is set
to ident2.
- It is always possible to use the special keyword _x_ to denote the free
variable. Hence ident1 can be _x_.
- Notice that ident2 is an identifier, not a string. In particular, it is
not directly possible to use the content of a variable to provide the new
name of the free variable. This can however be obtained using a level of
indirection: first create a string that contains the call to rename, and
then evaluate it thanks to parse (see example below).
Example 1:
> f=sin(x);
> f;
sin(x)
> rename(x,y);
> f;
sin(y)
Example 2:
> a=1;
> f=sin(x);
> rename(x,a);
> a;
a
> f;
sin(a)
Example 3:
> verbosity=1!;
> f=sin(x);
> rename(y, z);
Warning: the current free variable is named "x" and not "y". Can only rename the free variable.
The last command will have no effect.
> rename(_x_, z);
Information: the free variable has been renamed from "x" to "z".
Example 4:
> verbosity=1!;
> rename(x,y);
Information: the free variable has been named "y".
> isbound(x);
false
> isbound(y);
true
Example 5:
> verbosity=1!;
> f = sin(x);
> new_varname = "foo";
> rename(_x_, new_varname);
Information: the free variable has been renamed from "x" to "new_varname".
> f;
sin(new_varname)
> rename(_x_, x);
Information: the free variable has been renamed from "new_varname" to "x".
> new_varname = "foo";
> str = "rename(_x_, " @ new_varname @ ");";
> (parse("proc () { " @ str @ "}"))();
Information: the free variable has been renamed from "x" to "foo".
> f;
sin(foo)
Example 6:
> verbosity=1!;
> f = sin(x);
> f;
sin(x)
> rename(x, _x_);
Information: the free variable has been renamed from "x" to "_x_".
> f;
sin(_x_)
> g = cos(y);
> f;
sin(y)
> g;
cos(y)
> rename(_x_, _x_);
Information: the free variable has been renamed from "y" to "_x_".
> f;
sin(_x_)
> g;
cos(_x_)
Go back to the list of commands
Name:
restart
brings Sollya back to its initial state
Description:
- The command restart brings Sollya back to its initial state. All
current state is abandoned, all libraries unbound and all memory freed.
The restart command has no effect when executed inside a Sollya
script read into a main Sollya script using execute. It is executed
in a Sollya script included by a #include macro.
Using the restart command in nested elements of imperative
programming like for or while loops is possible. Since in most cases
abandoning the current state of Sollya means altering a loop
invariant, warnings for the impossibility of continuing a loop may
follow unless the state is rebuilt.
Example 1:
> print(exp(x));
exp(x)
> a = 3;
> restart;
The tool has been restarted.
> print(x);
x
> a;
Warning: the identifier "a" is neither assigned to, nor bound to a library function nor external procedure, nor equal to the current free variable.
Will interpret "a" as "x".
x
Example 2:
> print(exp(x));
exp(x)
> for i from 1 to 10 do {
print(i);
if (i == 5) then restart;
};
1
2
3
4
5
The tool has been restarted.
Warning: the tool has been restarted inside a for loop.
The for loop will no longer be executed.
Example 3:
> print(exp(x));
exp(x)
> a = 3;
> for i from 1 to 10 do {
print(i);
if (i == 5) then {
restart;
i = 7;
};
};
1
2
3
4
5
The tool has been restarted.
8
9
10
> print(x);
x
> a;
Warning: the identifier "a" is neither assigned to, nor bound to a library function nor external procedure, nor equal to the current free variable.
Will interpret "a" as "x".
x
Go back to the list of commands
Name:
return
indicates an expression to be returned in a procedure
Usage:
return expression : void
Parameters:
- expression represents the expression to be returned
Description:
- The keyword return allows for returning the (evaluated) expression
expression at the end of a begin-end-block ({}-block) used as a
Sollya procedure body. See proc for further details concerning
Sollya procedure definitions.
Statements for returning expressions using return are only possible
at the end of a begin-end-block used as a Sollya procedure
body. Only one return statement can be given per begin-end-block.
- If at the end of a procedure definition using proc no return
statement is given, a return void statement is implicitly
added. Procedures, i.e. procedure objects, when printed out in Sollya
defined with an implicit return void statement are displayed with
this statement explicitly given.
Example 1:
> succ = proc(n) { var res; res := n + 1; return res; };
> succ(5);
6
> succ;
proc(n)
{
var res;
res := (n) + (1);
return res;
}
Example 2:
> hey = proc(s) { print("Hello",s); };
> hey("world");
Hello world
> hey;
proc(s)
{
print("Hello", s);
return void;
}
Go back to the list of commands
Library name:
sollya_obj_t sollya_lib_revert(sollya_obj_t)
Usage:
revert(L) : list -> list
Description:
- revert(L) returns the same list, but with its elements in reverse order.
- If L is an end-elliptic list, revert will fail with an error.
Example 1:
> revert([| |]);
[| |]
Example 2:
> revert([|2,3,5,2,1,4|]);
[|4, 1, 2, 5, 3, 2|]
Go back to the list of commands
Name:
RN
constant representing rounding-to-nearest mode.
Library names:
sollya_obj_t sollya_lib_round_to_nearest()
int sollya_lib_is_round_to_nearest(sollya_obj_t)
Description:
- RN is used in command round to specify that the value must be rounded
to the nearest representable floating-point number.
Example 1:
> display=binary!;
> round(Pi,20,RN);
1.100100100001111111_2 * 2^(1)
Go back to the list of commands
Name:
roundcoefficients
rounds the coefficients of a polynomial to classical formats.
Library name:
sollya_obj_t sollya_lib_roundcoefficients(sollya_obj_t, sollya_obj_t)
Parameters:
- p is a function. Usually a polynomial.
- L is a list of formats.
Description:
- If p is a polynomial and L a list of floating-point formats,
roundcoefficients(p,L) rounds each coefficient of p to the corresponding format
in L.
- If p is not a polynomial, roundcoefficients does not do anything.
- If L contains other elements than HP, halfprecision, SG, single, D, double,
DE, doubleextended, DD, doubledouble, QD, quad, TD and tripledouble,
an error occurs.
- The coefficients in p corresponding to X^i is rounded to the
format L[i]. If L does not contain enough elements
(e.g. if length(L) < degree(p)+1), a warning is displayed. However, the
coefficients corresponding to an element of L are rounded. The trailing
coefficients (that do not have a corresponding element in L) are kept with
their own precision.
If L contains too much elements, the trailing useless elements are ignored.
In particular L may be end-elliptic in which case roundcoefficients has the
natural behavior.
Example 1:
> p=exp(1) + x*(exp(2) + x*exp(3));
> display=binary!;
> roundcoefficients(p,[|DD,D,D|]);
1.010110111111000010101000101100010100010101110110100101010011010101011111101110001010110001000000010011101_2 * 2^(1) + x * (1.110110001110011001001011100011010100110111011010111_2 * 2^(2) + x * (1.010000010101111001011011111101101111101100010000011_2 * 2^(4)))
> roundcoefficients(p,[|DD,D...|]);
1.010110111111000010101000101100010100010101110110100101010011010101011111101110001010110001000000010011101_2 * 2^(1) + x * (1.110110001110011001001011100011010100110111011010111_2 * 2^(2) + x * (1.010000010101111001011011111101101111101100010000011_2 * 2^(4)))
Example 2:
> f=sin(exp(1)*x);
> display=binary!;
> f;
sin(x * (1.0101101111110000101010001011000101000101011101101001010100110101010111111011100010101100010000000100111001111010011110011110001110110001011100111000101100000111101_2 * 2^(1)))
> roundcoefficients(f,[|D...|]);
sin(x * (1.0101101111110000101010001011000101000101011101101001010100110101010111111011100010101100010000000100111001111010011110011110001110110001011100111000101100000111101_2 * 2^(1)))
Example 3:
> p=exp(1) + x*(exp(2) + x*exp(3));
> verbosity=1!;
> display=binary!;
> roundcoefficients(p,[|DD,D|]);
Warning: the number of the given formats does not correspond to the degree of the given polynomial.
Warning: the 0th coefficient of the given polynomial does not evaluate to a floating-point constant without any rounding.
Will evaluate the coefficient in the current precision in floating-point before rounding to the target format.
Warning: the 1th coefficient of the given polynomial does not evaluate to a floating-point constant without any rounding.
Will evaluate the coefficient in the current precision in floating-point before rounding to the target format.
Warning: rounding may have happened.
1.010110111111000010101000101100010100010101110110100101010011010101011111101110001010110001000000010011101_2 * 2^(1) + x * (1.110110001110011001001011100011010100110111011010111_2 * 2^(2) + x * (1.01000001010111100101101111110110111110110001000001011111001011010100101111011111110001010011011101000100110000111010001110010000010110000101100000111001011100101001_2 * 2^(4)))
See also: halfprecision,
single,
double,
doubleextended,
doubledouble,
quad,
tripledouble,
fpminimax,
remez,
implementpoly,
subpoly
Go back to the list of commands
Name:
roundcorrectly
rounds an approximation range correctly to some precision
Library name:
sollya_obj_t sollya_lib_roundcorrectly(sollya_obj_t)
Parameters:
- range represents a range in which an exact value lies
Description:
- Let range be a range of values, determined by some approximation
process, safely bounding an unknown value v. The command
roundcorrectly(range) determines a precision such that for this precision,
rounding to the nearest any value in range yields to the same
result, i.e. to the correct rounding of v.
If no such precision exists, a warning is displayed and roundcorrectly
evaluates to NaN.
Example 1:
> printbinary(roundcorrectly([1.010001_2; 1.0101_2]));
1.01_2
> printbinary(roundcorrectly([1.00001_2; 1.001_2]));
1_2
Example 2:
> roundcorrectly([-1; 1]);
NaN
Go back to the list of commands
Name:
roundingwarnings
global variable controlling whether or not a warning is displayed when roundings occur.
Library names:
void sollya_lib_set_roundingwarnings_and_print(sollya_obj_t)
void sollya_lib_set_roundingwarnings(sollya_obj_t)
sollya_obj_t sollya_lib_get_roundingwarnings()
Parameters:
- activation value controls if warnings should be shown or not
Description:
- roundingwarnings is a global variable. When its value is on, warnings are
emitted in appropriate verbosity modes (see verbosity) when roundings
occur. When its value is off, these warnings are suppressed.
- This mode depends on a verbosity of at least 1. See
verbosity for more details.
- Default is on when the standard input is a terminal and
off when Sollya input is read from a file.
Example 1:
> verbosity=1!;
> roundingwarnings = on;
Rounding warning mode has been activated.
> exp(0.1);
Warning: Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning: rounding has happened. The value displayed is a faithful rounding to 165 bits of the true result.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
1.1051709180756476248117078264902466682245471947375
> roundingwarnings = off;
Rounding warning mode has been deactivated.
> exp(0.1);
1.1051709180756476248117078264902466682245471947375
Go back to the list of commands
Name:
round
rounds a number to a floating-point format.
Library name:
sollya_obj_t sollya_lib_round(sollya_obj_t, sollya_obj_t, sollya_obj_t)
Usage:
round(x,n,mode) : (constant, integer, RN|RZ|RU|RD) -> constant
round(x,format,mode) : (constant, HP|halfprecision|SG|single|D|double|DE|doubleextended|DD|doubledouble|QD|quad|TD|tripledouble, RN|RZ|RU|RD) -> constant
Parameters:
- x is a constant to be rounded.
- n is the precision of the target format.
- format is the name of a supported floating-point format.
- mode is the desired rounding mode.
Description:
- If used with an integer parameter n, round(x,n,mode) rounds x to a floating-point number with
precision n, according to rounding-mode mode.
- If used with a format parameter format, round(x,format,mode) rounds x to a floating-point number in the
floating-point format format, according to rounding-mode mode.
- Subnormal numbers are handled for the case when format is one of
halfprecision, single, double, doubleextended, doubledouble,
quad or tripledouble. Otherwise, when format is an integer,
round does not take any exponent range into consideration,
i.e. typically uses the full exponent range of the underlying MPFR
library.
- It is worth mentioning that the result of round does not depend on
the current global precision of Sollya, unless a warning is
displayed. As a matter of fact, round rounds the given constant or
constant expression x applying all rules of IEEE 754 correct
rounding, unless a warning is displayed. The result of round is
hence the floating-point value of the given precision n or format
format that is nearest to x (resp. just below or just above,
depending on mode), computed as if infinite precision were used for
evaluating the constant x, unless a warning is displayed.
Example 1:
> display=binary!;
> round(Pi,20,RN);
1.100100100001111111_2 * 2^(1)
Example 2:
> printdouble(round(exp(17),53,RU));
0x417709348c0ea4f9
> printdouble(D(exp(17)));
0x417709348c0ea4f9
Example 3:
> display=binary!;
> a=2^(-1100);
> round(a,53,RN);
1_2 * 2^(-1100)
> round(a,D,RN);
0
> double(a);
0
See also: RN,
RD,
RU,
RZ,
halfprecision,
single,
double,
doubleextended,
doubledouble,
quad,
tripledouble,
roundcoefficients,
roundcorrectly,
printdouble,
printsingle,
ceil,
floor,
nearestint
Go back to the list of commands
Name:
RU
constant representing rounding-upwards mode.
Library names:
sollya_obj_t sollya_lib_round_up()
int sollya_lib_is_round_up(sollya_obj_t)
Description:
- RU is used in command round to specify that the value x must be rounded
to the smallest floating-point number y such that x <= y.
Example 1:
> display=binary!;
> round(Pi,20,RU);
1.100100100001111111_2 * 2^(1)
Go back to the list of commands
Name:
RZ
constant representing rounding-to-zero mode.
Library names:
sollya_obj_t sollya_lib_round_towards_zero()
int sollya_lib_is_round_towards_zero(sollya_obj_t)
Description:
- RZ is used in command round to specify that the value must be rounded
to the closest floating-point number towards zero. It just consists in
truncating the value to the desired format.
Example 1:
> display=binary!;
> round(Pi,20,RZ);
1.1001001000011111101_2 * 2^(1)
Go back to the list of commands
Name:
searchgal
searches for a preimage of a function such that the rounding the image yields an error smaller than a constant
Library name:
sollya_obj_t sollya_lib_searchgal(sollya_obj_t, sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t, sollya_obj_t)
Usage:
searchgal(function, start, preimage precision, steps, format, error bound) : (function, constant, integer, integer, HP|halfprecision|SG|single|D|double|DE|doubleextended|DD|doubledouble|QD|quad|TD|tripledouble, constant) -> list
searchgal(list of functions, start, preimage precision, steps, list of format, list of error bounds) : (list, constant, integer, integer, list, list) -> list
Parameters:
- function represents the function to be considered
- start represents a value around which the search is to be performed
- preimage precision represents the precision (discretization) for the eligible preimage values
- steps represents the binary logarithm (log2) of the number of search steps to be performed
- format represents the format the image of the function is to be rounded to
- error bound represents a upper bound on the relative rounding error when rounding the image
- list of functions represents the functions to be considered
- list of formats represents the respective formats the images of the functions are to be rounded to
- list of error bounds represents a upper bound on the relative rounding error when rounding the image
Description:
- The command searchgal searches for a preimage z of function
function or a list of functions list of functions such that
z is a floating-point number with preimage precision
significant mantissa bits and the image y of the function,
respectively each image yi of the functions, rounds to
format format respectively to the corresponding format in list of format
with a relative rounding error less than error bound
respectively the corresponding value in list of error bounds. During
this search, at most 2^steps attempts are made. The search
starts with a preimage value equal to start. This value is then
increased and decreased by 1 ulp in precision preimage precision
until a value is found or the step limit is reached.
If the search finds an appropriate preimage z, searchgal
evaluates to a list containing this value. Otherwise, searchgal
evaluates to an empty list.
Example 1:
> searchgal(log(x),2,53,15,DD,1b-112);
[| |]
> searchgal(log(x),2,53,18,DD,1b-112);
[|2.0000000000384972054234822280704975128173828125|]
Example 2:
> f = exp(x);
> s = searchgal(f,2,53,18,DD,1b-112);
> if (s != [||]) then {
v = s[0];
print("The rounding error is 2^(",evaluate(log2(abs(DD(f)/f - 1)),v),")");
} else print("No value found");
The rounding error is 2^( -112.106878438809380148206984258358542322113874177832 )
Example 3:
> searchgal([|sin(x),cos(x)|],1,53,15,[|D,D|],[|1b-62,1b-60|]);
[|1.00000000000159494639717649988597258925437927246094|]
Go back to the list of commands
Name:
showmessagenumbers
activates, deactivates or inspects the state variable controlling the displaying of numbers for messages
Library names:
void sollya_lib_set_showmessagenumbers_and_print(sollya_obj_t)
void sollya_lib_set_showmessagenumbers(sollya_obj_t)
sollya_obj_t sollya_lib_get_showmessagenumbers()
Parameters:
- activation value represents on or off, i.e. activation or deactivation
Description:
- An assignment showmessagenumbers = activation value, where activation value
is one of on or off, activates respectively deactivates the
displaying of numbers for warning and information messages. Every
Sollya warning or information message (that is not fatal to the
tool's execution) has a message number. By default, these numbers are
not displayed when a message is output. When message number displaying
is activated, the message numbers are displayed together with the
message. This allows the user to recover the number of a particular
message in order to suppress resp. unsuppress the displaying of this
particular message (see suppressmessage and unsuppressmessage).
- The user should be aware of the fact that message number display
activation resp. deactivation through showmessagenumbers does not affect message
displaying in general. For instance, even with message number
displaying activated, messages with only displayed when general
verbosity and rounding warning mode are set accordingly.
- If the assignment showmessagenumbers = activation value is followed by an
exclamation mark, no message indicating the new state is
displayed. Otherwise the user is informed of the new state of the
global mode by an indication.
Example 1:
> verbosity = 1;
The verbosity level has been set to 1.
> 0.1;
Warning: Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> showmessagenumbers = on;
Displaying of message numbers has been activated.
> 0.1;
Warning (174): Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning (478): For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> showmessagenumbers;
on
> showmessagenumbers = off!;
> 0.1;
Warning: Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
Example 2:
> showmessagenumbers = on;
Displaying of message numbers has been activated.
> verbosity = 1;
The verbosity level has been set to 1.
> diff(0.1 * x + 1.5 * x^2);
Warning (174): Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning (478): For at least 1 of the constants displayed in decimal, rounding has happened.
0.1 + x * 3
> verbosity = 0;
The verbosity level has been set to 0.
> diff(0.1 * x + 1.5 * x^2);
0.1 + x * 3
> verbosity = 12;
The verbosity level has been set to 12.
> diff(0.1 * x + 1.5 * x^2);
Warning (174): Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Information (196): formally differentiating a function.
Information (197): differentiating the expression '0.1 * x + 1.5 * x^2'
Information (195): expression '0.1 + 2 * 1.5 * x' has been simplified to expression '0.1 + 3 * x'.
Warning (478): For at least 3 of the constants previously displayed in decimal, rounding has happened.
Warning (478): For at least 1 of the constants displayed in decimal, rounding has happened.
0.1 + x * 3
Go back to the list of commands
Name:
simplify
simplifies an expression representing a function
Library name:
sollya_obj_t sollya_lib_simplify(sollya_obj_t)
Usage:
simplify(function) : function -> function
Parameters:
- function represents the expression to be simplified
Description:
- The command simplify simplifies the expression given in argument
representing the function function. The command simplify does not
endanger the safety of computations even in Sollya's floating-point
environment: the function returned is mathematically equal to the
function function.
Remark that the simplification provided by simplify is not perfect:
they may exist simpler equivalent expressions for expressions returned
by simplify.
Example 1:
> print(simplify((6 + 2) + (5 + exp(0)) * x));
8 + x * 6
Example 2:
> print(simplify((log(x - x + 1) + asin(1))));
(pi) / 2
Example 3:
> print(simplify((log(x - x + 1) + asin(1)) - (atan(1) * 2)));
(pi) / 2 - (pi) / 4 * 2
Go back to the list of commands
Names:
single,
SG
rounding to the nearest IEEE 754 single (binary32).
Library names:
sollya_obj_t sollya_lib_single(sollya_obj_t)
sollya_obj_t sollya_lib_single_obj()
int sollya_lib_is_single_obj(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_single(sollya_obj_t)
#define SOLLYA_SG(x) sollya_lib_build_function_single(x)
Description:
- single is both a function and a constant.
- As a function, it rounds its argument to the nearest IEEE 754 single precision (i.e. IEEE754-2008 binary32) number.
Subnormal numbers are supported as well as standard numbers: it is the real
rounding described in the standard.
- As a constant, it symbolizes the single precision format. It is used in
contexts when a precision format is necessary, e.g. in the commands
round and roundcoefficients. In is not supported for implementpoly.
See the corresponding help pages for examples.
Example 1:
> display=binary!;
> SG(0.1);
1.10011001100110011001101_2 * 2^(-4)
> SG(4.17);
1.000010101110000101001_2 * 2^(2)
> SG(1.011_2 * 2^(-1073));
0
Go back to the list of commands
Name:
sinh
the hyperbolic sine function.
Library names:
sollya_obj_t sollya_lib_sinh(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_sinh(sollya_obj_t)
#define SOLLYA_SINH(x) sollya_lib_build_function_sinh(x)
Description:
- sinh is the usual hyperbolic sine function: sinh(x) = (exp(x)-exp(-x))/2.
- It is defined for every real number x.
Go back to the list of commands
Name:
sin
the sine function.
Library names:
sollya_obj_t sollya_lib_sin(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_sin(sollya_obj_t)
#define SOLLYA_SIN(x) sollya_lib_build_function_sin(x)
Description:
- sin is the usual sine function.
- It is defined for every real number x.
Go back to the list of commands
Name:
sort
sorts a list of real numbers.
Library name:
sollya_obj_t sollya_lib_sort(sollya_obj_t)
Usage:
sort(L) : list -> list
Description:
- If L contains only constant values, sort(L) returns the same list, but
sorted in increasing order.
- If L contains at least one element that is not a constant, the command fails
with a type error.
- If L is an end-elliptic list, sort will fail with an error.
Example 1:
> sort([| |]);
[| |]
> sort([|2,3,5,2,1,4|]);
[|1, 2, 2, 3, 4, 5|]
Go back to the list of commands
Library names:
sollya_obj_t sollya_lib_sqrt(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_sqrt(sollya_obj_t)
#define SOLLYA_SQRT(x) sollya_lib_build_function_sqrt(x)
Description:
- sqrt is the square root, e.g. the inverse of the function square: sqrt(y)
is the unique positive x such that x^2=y.
- It is defined only for x in [0; +Inf].
Go back to the list of commands
Name:
string
keyword representing a string type
Library name:
SOLLYA_EXTERNALPROC_TYPE_STRING
Description:
- string represents the string type for declarations
of external procedures by means of externalproc.
Remark that in contrast to other indicators, type indicators like
string cannot be handled outside the externalproc context. In
particular, they cannot be assigned to variables.
Go back to the list of commands
Name:
subpoly
restricts the monomial basis of a polynomial to a list of monomials
Library name:
sollya_obj_t sollya_lib_subpoly(sollya_obj_t, sollya_obj_t)
Usage:
subpoly(polynomial, list) : (function, list) -> function
Parameters:
- polynomial represents the polynomial the coefficients are taken from
- list represents the list of monomials to be taken
Description:
- subpoly extracts the coefficients of a polynomial polynomial and builds up a
new polynomial out of those coefficients associated to monomial degrees figuring in
the list list.
If polynomial represents a function that is not a polynomial, subpoly returns 0.
If list is a list that is end-elliptic, let be j the last value explicitly specified
in the list. All coefficients of the polynomial associated to monomials greater or
equal to j are taken.
Example 1:
> p = taylor(exp(x),5,0);
> s = subpoly(p,[|1,3,5|]);
> print(p);
1 + x * (1 + x * (0.5 + x * (1 / 6 + x * (1 / 24 + x * 1 / 120))))
> print(s);
x * (1 + x^2 * (1 / 6 + x^2 / 120))
Example 2:
> p = remez(atan(x),10,[-1,1]);
> subpoly(p,[|1,3,5...|]);
x * (0.99986632941452949026018468446163586361700915018232 + x^2 * (-0.33030478502455936362667794059988443130926433421739 + x^2 * (0.18015929317818756462894237037824735129130095574422 + x * (2.2845584115424788285112501565358576642429856963072e-9 + x * (-8.5156349064111377895500552996061844977507560037485e-2 + x * (-2.717563409627750199168187692393409435243830189218e-9 + x * (2.08451134307114729373239910549169872454686955895e-2 + x * 1.10889861181129057657199664386826630081793400489512e-9)))))))
Example 3:
> subpoly(exp(x),[|1,2,3|]);
0
Go back to the list of commands
Name:
substitute
replace the occurrences of the free variable in an expression.
Library name:
sollya_obj_t sollya_lib_substitute(sollya_obj_t, sollya_obj_t)
Usage:
substitute(f,g) : (function, function) -> function
substitute(f,t) : (function, constant) -> constant
Parameters:
- f is a function.
- g is a function.
- t is a real number.
Description:
- substitute(f, g) produces the function (f o g) : x -> f(g(x)).
- substitute(f, t) is the constant f(t). Note that the constant is
represented by its expression until it has been evaluated (exactly the same
way as if you type the expression f replacing instances of the free variable
by t).
- If f is stored in a variable F, the effect of the commands substitute(F,g) or substitute(F,t) is absolutely equivalent to
writing F(g) resp. F(t).
Example 1:
> f=sin(x);
> g=cos(x);
> substitute(f,g);
sin(cos(x))
> f(g);
sin(cos(x))
Example 2:
> a=1;
> f=sin(x);
> substitute(f,a);
0.84147098480789650665250232163029899962256306079837
> f(a);
0.84147098480789650665250232163029899962256306079837
Go back to the list of commands
Name:
supnorm
computes an interval bounding the supremum norm of an approximation error (absolute or relative) between a given polynomial and a function.
Library name:
sollya_obj_t sollya_lib_supnorm(sollya_obj_t, sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t)
Usage:
supnorm(p, f, I, errorType, accuracy) : (function, function, range, absolute|relative, constant) -> range
Parameters:
- p is a polynomial.
- f is a function.
- I is an interval.
- errorType is the type of error to be considered: absolute or relative (see details below).
- accuracy is a constant that controls the relative tightness of the interval returned.
Description:
- supnorm(p, f, I, errorType, accuracy) tries to compute an
interval bound r=[l,u] for the supremum norm of the error function
epsilon_absolute=p-f (when errorType evaluates to absolute)
or epsilon_relative=p/f-1 (when errorType evaluates to relative),
over the interval I, such that sup{|epsilon(x)|, x in I} C r
and 0<|u/l-1|< accuracy. If supnorm succeeds in computing a suitable
interval r, which it returns, that interval is guaranteed to contain the
supremum norm value and to satisfy the required quality. Otherwise, supnorm
evaluates to error, displaying a corresponding error message. These failure
cases are rare and basically happen only for functions which are too
complicated.
- Roughly speaking, supnorm is based on taylorform to obtain a higher
degree polynomial approximation for f. This process is coupled with
an a posteriori validation of a potential supremum norm upper bound.
The validation is based on showing a certain polynomial the problem gets
reduced to does not vanish. In cases when this process alone does not
succeed, for instance because taylorform is unable to compute a
sufficiently good approximation to f, supnorm falls back to
bisecting the working interval until safe supremum norm bounds can be
computed with the required accuracy or until the width of the
subintervals becomes less than diam times the original interval I,
in which case supnorm fails.
- The algorithm used for supnorm is quite complex, which makes it impossible
to explain it here in further detail.
Please find a complete description in the following article:
Sylvain Chevillard, John Harrison, Mioara Joldes, Christoph Lauter
Efficient and accurate computation of upper bounds of approximation errors
Journal of Theoretical Computer Science (TCS), 2010
LIP Research Report number RR LIP2010-2
http://prunel.ccsd.cnrs.fr/ensl-00445343/fr/
- In practical cases, supnorm should be able to automatically handle
removable discontinuities that relative errors might have. This means
that usually, if f vanishes at a point x0 in the interval
considered, the approximation polynomial p is designed such that it
also vanishes at the same point with a multiplicity large
enough. Hence, although f vanishes, epsilon_relative=p/f-1 may be
defined by continuous extension at such points x0, called
removable discontinuities (see Example 3).
Example 1:
> p = remez(exp(x), 5, [-1;1]);
> midpointmode=on!;
> supnorm(p, exp(x), [-1;1], absolute, 2^(-40));
0.45205513967~0/2~e-4
Example 2:
> prec=200!;
> midpointmode=on!;
> d = [1;2];
> f = exp(cos(x)^2 + 1);
> p = remez(1,15,d,1/f,1e-40);
> theta=1b-60;
> prec=default!;
> mode=relative;
> supnorm(p,f,d,mode,theta);
0.30893006200251428~5/6~e-13
Example 3:
> midpointmode=on!;
> mode=relative;
> theta=1b-135;
> d = [-1b-2;1b-2];
> f = expm1(x);
> p = x * (1 + x * ( 2097145 * 2^(-22) + x * ( 349527 * 2^(-21) + x * (87609 * 2^(-21) + x * 4369 * 2^(-19)))));
> theta=1b-40;
> supnorm(p,f,d,mode,theta);
0.98349131972~2/3~e-7
Go back to the list of commands
Name:
suppressmessage
suppresses the displaying of messages with a certain number
Library names:
void sollya_lib_suppressmessage(sollya_obj_t, ...);
void sollya_lib_v_suppressmessage(sollya_obj_t, va_list);
Parameters:
- msg num 1 thru msg num n represent the numbers of n messages to be suppressed
- msg list represents a list with numbers of messages to be suppressed
Description:
- The suppressmessage command allows particular warning and information
messages to be suppressed from message output, while maintaining
global verbosity levels (see verbosity) high. Every Sollya warning
or information message (that is not fatal to the tool's execution) has
a message number. When these message numbers msg num 1 thru msg num n
are given to suppressmessage, the corresponding message are no longer
displayed. The unsuppressmessage command reverts this suppression
from output for a particular message.
- Instead of giving suppressmessage several message numbers msg num 1 thru
msg num n or calling suppressmessage several times, it is possible to give
a whole list msg list of message numbers to suppressmessage.
- The user should be aware that suppressmessage presents sticky behavior for
the warning and information messages suppressed from output. This
means that even if subsequent calls to suppressmessage occur, a message
suppressed by a call to suppressmessage stays suppressed until it is
unsuppressed using unsuppressmessage or the tool is restarted. This
behavior distinguishes message suppression from other global states of
the Sollya tool. The user may use getsuppressedmessages to obtain a
list of currently suppressed messages.
- When suppressmessage is used on message numbers that do not exist in the
current version of the tool, a warning is displayed. The call has no
other effect though.
Example 1:
> verbosity = 1;
The verbosity level has been set to 1.
> 0.1;
Warning: Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> suppressmessage(174);
> 0.1;
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> suppressmessage(407);
> 0.1;
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> verbosity = 12;
The verbosity level has been set to 12.
> showmessagenumbers = on;
Displaying of message numbers has been activated.
> diff(exp(x * 0.1));
Information (196): formally differentiating a function.
Information (197): differentiating the expression 'exp(x * 0.1)'
Information (207): no Horner simplification will be performed because the given tree is already in Horner form.
Warning (478): For at least 1 of the constants previously displayed in decimal, rounding has happened.
Warning (478): For at least 2 of the constants displayed in decimal, rounding has happened.
exp(x * 0.1) * 0.1
> suppressmessage(207, 196);
> diff(exp(x * 0.1));
Information (197): differentiating the expression 'exp(x * 0.1)'
Warning (478): For at least 1 of the constants previously displayed in decimal, rounding has happened.
Warning (478): For at least 2 of the constants displayed in decimal, rounding has happened.
exp(x * 0.1) * 0.1
> unsuppressmessage(174);
> 0.1;
Warning (174): Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning (478): For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
Example 2:
> verbosity = 12;
The verbosity level has been set to 12.
> showmessagenumbers = on;
Displaying of message numbers has been activated.
> diff(exp(x * 0.1));
Warning (174): Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Information (196): formally differentiating a function.
Information (197): differentiating the expression 'exp(x * 0.1)'
Information (207): no Horner simplification will be performed because the given tree is already in Horner form.
Warning (478): For at least 1 of the constants previously displayed in decimal, rounding has happened.
Warning (478): For at least 2 of the constants displayed in decimal, rounding has happened.
exp(x * 0.1) * 0.1
> suppressmessage([| 174, 207, 196 |]);
> diff(exp(x * 0.1));
Information (197): differentiating the expression 'exp(x * 0.1)'
Warning (478): For at least 1 of the constants previously displayed in decimal, rounding has happened.
Warning (478): For at least 2 of the constants displayed in decimal, rounding has happened.
exp(x * 0.1) * 0.1
Go back to the list of commands
Name:
sup
gives the upper bound of an interval.
Library name:
sollya_obj_t sollya_lib_sup(sollya_obj_t)
Usage:
sup(I) : range -> constant
sup(x) : constant -> constant
Parameters:
- I is an interval.
- x is a real number.
Description:
- Returns the upper bound of the interval I. Each bound of an interval has its
own precision, so this command is exact, even if the current precision is too
small to represent the bound.
- When called on a real number x, sup behaves like the identity.
Example 1:
> sup([1;3]);
3
> sup(5);
5
Example 2:
> display=binary!;
> I=[0; 0.111110000011111_2];
> sup(I);
1.11110000011111_2 * 2^(-1)
> prec=12!;
> sup(I);
1.11110000011111_2 * 2^(-1)
Go back to the list of commands
Name:
tail
gives the tail of a list.
Library name:
sollya_obj_t sollya_lib_tail(sollya_obj_t)
Usage:
tail(L) : list -> list
Description:
- tail(L) returns the list L without its first element.
- If L is empty, the command will fail with an error.
- tail can also be used with end-elliptic lists. In this case, the result of
tail is also an end-elliptic list.
Example 1:
> tail([|1,2,3|]);
[|2, 3|]
> tail([|1,2...|]);
[|2...|]
Go back to the list of commands
Name:
tanh
the hyperbolic tangent function.
Library names:
sollya_obj_t sollya_lib_tanh(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_tanh(sollya_obj_t)
#define SOLLYA_TANH(x) sollya_lib_build_function_tanh(x)
Description:
- tanh is the hyperbolic tangent function, defined by tanh(x) = sinh(x)/cosh(x).
- It is defined for every real number x.
Go back to the list of commands
Name:
tan
the tangent function.
Library names:
sollya_obj_t sollya_lib_tan(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_tan(sollya_obj_t)
#define SOLLYA_TAN(x) sollya_lib_build_function_tan(x)
Description:
- tan is the tangent function, defined by tan(x) = sin(x)/cos(x).
- It is defined for every real number x that is not of the form n*Pi+Pi/2 where n is an integer.
Go back to the list of commands
Name:
taylorrecursions
controls the number of recursion steps when applying Taylor's rule.
Library names:
void sollya_lib_set_taylorrecursions_and_print(sollya_obj_t)
void sollya_lib_set_taylorrecursions(sollya_obj_t)
sollya_obj_t sollya_lib_get_taylorrecursions()
Parameters:
- n represents the number of recursions
Description:
- taylorrecursions is a global variable. Its value represents the number of steps
of recursion that are used when applying Taylor's rule. This rule is applied
by the interval evaluator present in the core of Sollya (and particularly
visible in commands like infnorm).
- To improve the quality of an interval evaluation of a function f, in
particular when there are problems of decorrelation), the evaluator of Sollya
uses Taylor's rule: f([a,b]) C f(m) + [a-m, b-m]*f'([a,b]) where m=(a+b)/2.
This rule can be applied recursively.
The number of step in this recursion process is controlled by taylorrecursions.
- Setting taylorrecursions to 0 makes Sollya use this rule only once;
setting it to 1 makes Sollya use the rule twice, and so on.
In particular: the rule is always applied at least once.
Example 1:
> f=exp(x);
> p=remez(f,3,[0;1]);
> taylorrecursions=0;
The number of recursions for Taylor evaluation has been set to 0.
> evaluate(f-p, [0;1]);
[-0.46839364816268368775174657814112460243249079671039;0.46947781754646820647293019728402934746974652584671]
> taylorrecursions=1;
The number of recursions for Taylor evaluation has been set to 1.
> evaluate(f-p, [0;1]);
[-0.138131114954063839905475752120786856031651747712954;0.13921528433784835862665937126369160106890747684927]
Go back to the list of commands
Name:
taylor
computes a Taylor expansion of a function in a point
Library name:
sollya_obj_t sollya_lib_taylor(sollya_obj_t, sollya_obj_t, sollya_obj_t)
Usage:
taylor(function, degree, point) : (function, integer, constant) -> function
Parameters:
- function represents the function to be expanded
- degree represents the degree of the expansion to be delivered
- point represents the point in which the function is to be developed
Description:
- The command taylor returns an expression that is a Taylor expansion
of function function in point point having the degree degree.
Let f be the function function, t be the point point and
n be the degree degree. Then, taylor(function,degree,point)
evaluates to an expression mathematically equal to
f(t) + f'(t) * x + ... + 1/(n!) * f[n](t) * x^n.
In other words, if p(x) denotes the polynomial returned by taylor,
p(x-t) is the Taylor polynomial of degree n of f developed at point t.
Remark that taylor evaluates to 0 if the degree degree is negative.
Example 1:
> print(taylor(exp(x),3,1));
exp(1) + x * (exp(1) + x * (0.5 * exp(1) + x * exp(1) / 6))
Example 2:
> print(taylor(asin(x),7,0));
x * (1 + x^2 * (1 / 6 + x^2 * (3 / 40 + x^2 * 5 / 112)))
Example 3:
> print(taylor(erf(x),6,0));
x * (2 / sqrt(pi) + x^2 * ((2 / sqrt(pi) * (-2)) / 6 + x^2 * (2 / sqrt(pi) * 12) / 120))
Go back to the list of commands
Name:
time
procedure for timing Sollya code.
Usage:
time(code) : code -> constant
Parameters:
- code is the code to be timed.
Description:
- time permits timing a Sollya instruction, resp. a begin-end block
of Sollya instructions. The timing value, measured in seconds, is returned
as a Sollya constant (and not merely displayed as for timing). This
permits performing computations of the timing measurement value inside Sollya.
- The extended nop command permits executing a defined number of
useless instructions. Taking the ratio of the time needed to execute a
certain Sollya instruction and the time for executing a nop
therefore gives a way to abstract from the speed of a particular
machine when evaluating an algorithm's performance.
Example 1:
> t = time(p=remez(sin(x),10,[-1;1]));
> write(t,"s were spent computing p = ",p,"\n");
4.3581453999999999999999999999999999999318398346354e-2s were spent computing p = 9.0486898749977990986908851357759191711354777014602e-17 * x^10 + 2.68762595115123596299959320959141640012683406736586e-6 * x^9 + -2.4247978492521313349073232289246205727856268698001e-16 * x^8 + -1.98344863020965929701245606503586461226130937598776e-4 * x^7 + 2.2748214757753544349162426281857910162575492126267e-16 * x^6 + 8.3333037186560980567697821420813799547276481409702e-3 * x^5 + -8.574715198972066974170696130354953131211051121887e-17 * x^4 + -0.166666661386013237076216566493953847771564552744173 * x^3 + 1.05699558969863875841493332282097022580493449058156e-17 * x^2 + 0.99999999973628365676559825181776417246038944720795 * x + (-3.1206530956601883024316320853642604562810646600878e-19)
Example 2:
> write(time({ p=remez(sin(x),10,[-1;1]); write("The error is 2^(", log2(dirtyinfnorm(p-sin(x),[-1;1])), ")\n"); }), "s were spent\n");
The error is 2^(log2(2.39601979446524486606649528289933482070294808074097e-11))
7.2049493999999999999999999999999999997972850399973e-2s were spent
Example 3:
> t = time(bashexecute("sleep 10"));
> write(~(t-10),"s of execution overhead.\n");
2.1746699999999999999999999999999992935072666405415e-3s of execution overhead.
Example 4:
> ratio := time(p=remez(sin(x),10,[-1;1]))/time(nop(10));
> write("This ratio = ", ratio, " should somehow be independent of the type of machine.\n");
This ratio = 1.4107690624483488128708021304227376413488139274141 should somehow be independent of the type of machine.
Go back to the list of commands
Name:
timing
global variable controlling timing measures in Sollya.
Library names:
void sollya_lib_set_timing_and_print(sollya_obj_t)
void sollya_lib_set_timing(sollya_obj_t)
sollya_obj_t sollya_lib_get_timing()
Usage:
timing = activation value : on|off -> void
timing = activation value ! : on|off -> void
timing : on|off
Parameters:
- activation value controls if timing should be performed or not
Description:
- timing is a global variable. When its value is on, the time spent in each
command is measured and displayed (for verbosity levels higher than 1).
Example 1:
> verbosity=1!;
> timing=on;
Timing has been activated.
> p=remez(sin(x),10,[-1;1]);
Information: Remez: computing the quality of approximation spent 5 ms
Information: Remez: computing the quality of approximation spent 4 ms
Information: Remez: computing the quality of approximation spent 4 ms
Information: computing a minimax approximation spent 27 ms
Information: assignment spent 33 ms
Information: full execution of the last parse chunk spent 39 ms
Go back to the list of commands
Names:
tripledouble,
TD
represents a number as the sum of three IEEE doubles.
Library names:
sollya_obj_t sollya_lib_triple_double(sollya_obj_t)
sollya_obj_t sollya_lib_triple_double_obj()
int sollya_lib_is_triple_double_obj(sollya_obj_t)
sollya_obj_t sollya_lib_build_function_triple_double(sollya_obj_t)
#define SOLLYA_TD(x) sollya_lib_build_function_triple_double(x)
Description:
- tripledouble is both a function and a constant.
- As a function, it rounds its argument to the nearest number that can be written
as the sum of three double precision numbers.
- The algorithm used to compute tripledouble(x) is the following: let xh = double(x),
let xm = double(x - xh) and let xl = double(x - xh - xm).
Return the number xh + xm + xl. Note that if the
current precision is not sufficient to represent exactly xh + xm + xl, a rounding will
occur and the result of tripledouble(x) will be useless.
- As a constant, it symbolizes the triple-double precision format. It is used in
contexts when a precision format is necessary, e.g. in the commands
roundcoefficients and implementpoly.
See the corresponding help pages for examples.
Example 1:
> verbosity=1!;
> a = 1+ 2^(-55)+2^(-115);
> TD(a);
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
1.00000000000000002775557561562891353466491600711096
> prec=110!;
> TD(a);
1.0000000000000000277555756156289135346649160071109559756997242823115914817262706026923524404992349445819854736328125
Go back to the list of commands
Name:
true
the boolean value representing the truth.
Library names:
sollya_obj_t sollya_lib_true()
int sollya_lib_is_true(sollya_obj_t)
Description:
- true is the usual boolean value.
Example 1:
> true && false;
false
> 2>1;
true
Go back to the list of commands
Name:
unsuppressmessage
unsuppresses the displaying of messages with a certain number
Library names:
void sollya_lib_unsuppressmessage(sollya_obj_t, ...);
void sollya_lib_v_unsuppressmessage(sollya_obj_t, va_list);
Parameters:
- msg num 1 thru msg num n represent the numbers of n messages to be suppressed
- msg list represents a list with numbers of messages to be suppressed
Description:
- The unsuppressmessage command allows particular warning and information
messages that have been suppressed from message output to be
unsuppressed, i.e. activated for display again. Every Sollya warning
or information message (that is not fatal to the tool's execution) has
a message number. When these message numbers msg num 1 thru msg num n
are given to unsuppressmessage, the corresponding message are displayed
again, as they are by default at according verbosity levels. Actually,
the unsuppressmessage command just reverts the effects of the suppressmessage
command.
- Instead of giving unsuppressmessage several message numbers msg num 1 thru
msg num n or calling unsuppressmessage several times, it is possible to give
a whole list msg list of message numbers to unsuppressmessage.
- The user should be aware that unsuppressmessage presents sticky behavior for
the warning and information messages suppressed from output. In fact,
unsuppressmessage just unsuppresses the warning or information messages given
in argument. All other suppressed messages stay suppressed until they
get unsuppressed by subsequent calls to unsuppressmessage or the Sollya tool
is restarted. This behavior distinguishes message suppression from
other global states of the Sollya tool. The user may use
getsuppressedmessages to obtain a list of currently suppressed
messages. In particular, in order to unsuppressed all currently
suppressed warning or information messages, the user may feed the
output of getsuppressedmessages (a list) into unsuppressmessage.
- The user should also note that unsuppressing warning or information
messages with unsuppressmessage just reverts the effects of the suppressmessage
command but that other conditions exist that affect the actual displaying
of a message, such as global verbosity (see verbosity) and modes
like rounding warnings (see roundingwarnings). A message will not just
get displayed because it was unsuppressed with unsuppressmessage.
- When unsuppressmessage is used on message numbers that do not exist in the
current version of the tool, a warning is displayed. The call has no
other effect though.
Example 1:
> verbosity = 1;
The verbosity level has been set to 1.
> 0.1;
Warning: Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> suppressmessage(174);
> 0.1;
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
> suppressmessage(174);
> 0.1;
Warning: For at least 1 of the constants displayed in decimal, rounding has happened.
0.1
Example 2:
> verbosity = 12;
The verbosity level has been set to 12.
> showmessagenumbers = on;
Displaying of message numbers has been activated.
> diff(exp(x * 0.1));
Warning (174): Rounding occurred when converting the constant "0.1" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Information (196): formally differentiating a function.
Information (197): differentiating the expression 'exp(x * 0.1)'
Information (207): no Horner simplification will be performed because the given tree is already in Horner form.
Warning (478): For at least 1 of the constants previously displayed in decimal, rounding has happened.
Warning (478): For at least 2 of the constants displayed in decimal, rounding has happened.
exp(x * 0.1) * 0.1
> suppressmessage([| 174, 207, 196 |]);
> diff(exp(x * 0.1));
Information (197): differentiating the expression 'exp(x * 0.1)'
Warning (478): For at least 1 of the constants previously displayed in decimal, rounding has happened.
Warning (478): For at least 2 of the constants displayed in decimal, rounding has happened.
exp(x * 0.1) * 0.1
> unsuppressmessage([| 174, 196 |]);
Example 3:
> verbosity = 12;
The verbosity level has been set to 12.
> showmessagenumbers = on;
Displaying of message numbers has been activated.
> suppressmessage(207, 387, 390, 388, 391, 196, 195, 197, 205);
> getsuppressedmessages();
[|195, 196, 197, 205, 207, 387, 388, 390, 391|]
> evaluate(x/sin(x) - 1, [-1;1]);
Warning (478): For at least 1 of the constants displayed in decimal, rounding has happened.
[0;0.8508157176809256179117532413986501934703966550941]
> unsuppressmessage(getsuppressedmessages());
> getsuppressedmessages();
[| |]
Go back to the list of commands
Name:
var
declaration of a local variable in a scope
Usage:
var identifier1, identifier2,... , identifiern : void
Parameters:
- identifier1, identifier2,... , identifiern represent variable identifiers
Description:
- The keyword var allows for the declaration of local variables
identifier1 through identifiern in a begin-end-block ({}-block).
Once declared as a local variable, an identifier will shadow
identifiers declared in higher scopes and undeclared identifiers
available at top-level.
Variable declarations using var are only possible in the
beginning of a begin-end-block. Several var statements can be
given. Once another statement is given in a begin-end-block, no more
var statements can be given.
Variables declared by var statements are dereferenced as error
until they are assigned a value.
Example 1:
> exp(x);
exp(x)
> a = 3;
> {var a, b; a=5; b=3; {var a; var b; b = true; a = 1; a; b;}; a; b; };
1
true
5
3
> a;
3
Go back to the list of commands
Name:
verbosity
global variable controlling the amount of information displayed by commands.
Library names:
void sollya_lib_set_verbosity_and_print(sollya_obj_t)
void sollya_lib_set_verbosity(sollya_obj_t)
sollya_obj_t sollya_lib_get_verbosity()
Parameters:
- n controls the amount of information to be displayed
Description:
- verbosity accepts any integer value. At level 0, commands do not display anything
on standard output. Note that very critical information may however be displayed on
standard error.
- Default level is 1. It displays important information such as warnings when
roundings happen.
- For higher levels more information is displayed depending on the command.
Example 1:
> verbosity=0!;
> 1.2+"toto";
error
> verbosity=1!;
> 1.2+"toto";
Warning: Rounding occurred when converting the constant "1.2" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
error
> verbosity=2!;
> 1.2+"toto";
Warning: Rounding occurred when converting the constant "1.2" to floating-point with 165 bits.
If safe computation is needed, try to increase the precision.
Warning: at least one of the given expressions or a subexpression is not correctly typed
or its evaluation has failed because of some error on a side-effect.
Information: the expression or a partial evaluation of it has been the following:
(1.2) + ("toto")
Warning: For at least 1 of the constants previously displayed in decimal, rounding has happened.
error
Go back to the list of commands
Name:
void
the functional result of a side-effect or empty argument resp. the corresponding type
Library names:
sollya_obj_t sollya_lib_void()
int sollya_lib_is_void(sollya_obj_t)
SOLLYA_EXTERNALPROC_TYPE_VOID
Usage:
void : void | type type
Description:
- The variable void represents the functional result of a
side-effect or an empty argument. It is used only in combination with
the applications of procedures or identifiers bound through
externalproc to external procedures.
The void result produced by a procedure or an external procedure
is not printed at the prompt. However, it is possible to print it out
in a print statement or in complex data types such as lists.
The void argument is implicit when giving no argument to a
procedure or an external procedure when applied. It can nevertheless be given
explicitly. For example, suppose that foo is a procedure or an
external procedure with a void argument. Then foo() and foo(void) are
correct calls to foo. Here, a distinction must be made for procedures having an
arbitrary number of arguments. In this case, an implicit void
as the only parameter to a call of such a procedure gets converted into
an empty list of arguments, an explicit void gets passed as-is in the
formal list of parameters the procedure receives.
- void is used also as a type identifier for
externalproc. Typically, an external procedure taking void as an
argument or returning void is bound with a signature void ->
some type or some type -> void. See externalproc for more
details.
Example 1:
> print(void);
void
> void;
Example 2:
> hey = proc() { print("Hello world."); };
> hey;
proc()
{
print("Hello world.");
return void;
}
> hey();
Hello world.
> hey(void);
Hello world.
> print(hey());
Hello world.
void
Example 3:
> bashexecute("gcc -fPIC -Wall -c externalprocvoidexample.c");
> bashexecute("gcc -fPIC -shared -o externalprocvoidexample externalprocvoidexample.o");
> externalproc(foo, "./externalprocvoidexample", void -> void);
> foo;
foo
> foo();
Hello from the external world.
> foo(void);
Hello from the external world.
> print(foo());
Hello from the external world.
void
Example 4:
> procedure blub(L = ...) { print("Argument list:", L); };
> blub(1);
Argument list: [|1|]
> blub();
Argument list: [| |]
> blub(void);
Argument list: [|void|]
Go back to the list of commands
Name:
worstcase
searches for hard-to-round cases of a function
Library names:
void sollya_lib_worstcase(sollya_obj_t, sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t, ...)
void sollya_lib_v_worstcase(sollya_obj_t, sollya_obj_t, sollya_obj_t,
sollya_obj_t, sollya_obj_t, va_list)
Usage:
worstcase(function, preimage precision, preimage exponent range, image precision, error bound) : (function, integer, range, integer, constant) -> void
worstcase(function, preimage precision, preimage exponent range, image precision, error bound, filename) : (function, integer, range, integer, constant, string) -> void
Parameters:
- function represents the function to be considered
- preimage precision represents the precision of the preimages
- preimage exponent range represents the exponents in the preimage format
- image precision represents the precision of the format the images are to be rounded to
- error bound represents the upper bound for the search w.r.t. the relative rounding error
- filename represents a character sequence containing a filename
Description:
- The worstcase command is deprecated. It searches for hard-to-round cases of
a function. The command searchgal has a comparable functionality.
Example 1:
> worstcase(exp(x),24,[1,2],24,1b-26);
prec = 165
x = 1.99999988079071044921875 f(x) = 7.3890552520751953125 eps = 4.5998601423446695596184695493764120138001954979037e-9 = 2^(-27.695763)
x = 2 f(x) = 7.38905620574951171875 eps = 1.44563608749673018122228379395533417878125150587072e-8 = 2^(-26.043720)
Go back to the list of commands
Name:
write
prints an expression without separators
Usage:
write(expr1,...,exprn) : (any type,..., any type) -> void
write(expr1,...,exprn) > filename : (any type,..., any type, string) -> void
write(expr1,...,exprn) >> filename : (any type,...,any type, string) -> void
Parameters:
- expr represents an expression
- filename represents a character sequence indicating a file name
Description:
- write(expr1,...,exprn) prints the expressions expr1 through
exprn. The character sequences corresponding to the expressions are
concatenated without any separator. No newline is displayed at the
end. In contrast to print, write expects the user to give all
separators and newlines explicitly.
If a second argument filename is given after a single ">", the
displaying is not output on the standard output of Sollya but if in
the file filename that get newly created or overwritten. If a double
">>" is given, the output will be appended to the file filename.
The global variables display, midpointmode and fullparentheses have
some influence on the formatting of the output (see display,
midpointmode and fullparentheses).
Remark that if one of the expressions expri given in argument is of
type string, the character sequence expri evaluates to is
displayed. However, if expri is of type list and this list
contains a variable of type string, the expression for the list
is displayed, i.e. all character sequences get displayed surrounded
by quotes ("). Nevertheless, escape sequences used upon defining
character sequences are interpreted immediately.
Example 1:
> write(x + 2 + exp(sin(x)));
> write("Hello\n");
x + 2 + exp(sin(x))Hello
> write("Hello","world\n");
Helloworld
> write("Hello","you", 4 + 3, "other persons.\n");
Helloyou7other persons.
Example 2:
> write("Hello","\n");
Hello
> write([|"Hello"|],"\n");
[|"Hello"|]
> s = "Hello";
> write(s,[|s|],"\n");
Hello[|"Hello"|]
> t = "Hello\tyou";
> write(t,[|t|],"\n");
Hello you[|"Hello\tyou"|]
Example 3:
> write(x + 2 + exp(sin(x))) > "foo.sol";
> readfile("foo.sol");
x + 2 + exp(sin(x))
Example 4:
> write(x + 2 + exp(sin(x))) >> "foo.sol";
See also: print,
printexpansion,
printdouble,
printsingle,
printxml,
readfile,
autosimplify,
display,
midpointmode,
fullparentheses,
evaluate,
roundingwarnings,
autosimplify
Go back to the list of commands
Name:
_x_
universal name for the mathematical free variable.
Library names:
sollya_obj_t sollya_lib_free_variable()
sollya_obj_t sollya_lib_build_function_free_variable()
#define SOLLYA_X_ (sollya_lib_build_function_free_variable())
Description:
- _x_ is an identifier that always denotes the mathematical free variable.
It cannot be assigned.
- Sollya manipulates mathematical functions of a single variable. The first
time that a variable name is used without having been assigned before, this
variable name is automatically considered by Sollya as the name of the
free variable. Subsequently, any other unassigned variable name will be
considered as the free variable with a warning making this conversion
explicit. This is convenient for an every-day use of the interactive tool,
but it has the drawback that the free variable name can change from a
session to another. There are contexts (e.g., within a procedure, or for
doing pattern matching) when one might want to refer to the free variable
regardless of its name in the current session. For this purpose _x_ is
a universal identifier, always available and always denoting the free
variable, whatever its name is in the current context.
- _x_ can be used to retrieve the name of the current free variable as a
string by simply concatenating it to "".
Example 1:
> verbosity=1!;
> sin(a);
sin(a)
> b;
Warning: the identifier "b" is neither assigned to, nor bound to a library function nor external procedure, nor equal to the current free variable.
Will interpret "b" as "a".
a
> _x_;
a
Example 2:
> verbosity=1!;
> sin(y);
sin(y)
> f = proc(a) {
return sin(a + _x_);
};
> rename(y,z);
Information: the free variable has been renamed from "y" to "z".
> f(1);
sin(1 + z)
Example 3:
> f = sin(y);
> match f with
sin(a) : { print("sin of a with a =", a);
match a with
_x_ : { print("a turns out to be the free variable"); }
default : { print("a is some expression"); };
}
_x_ : { print("Free variable") ; }
default: { print("Something else"); };
sin of a with a = y
a turns out to be the free variable
Example 4:
> sin(wurst);
sin(wurst)
> varname = _x_ @ "";
> print("The current name of the free variable is " @ varname);
The current name of the free variable is wurst
Go back to the list of commands