CFLP is delivered as a collection of Mathematica packages, which add solving power to a normal Mathematica session. If CFLP is properly installed, a Mathematica user can enable it by loading the package
In this section we illustrate the functionality of CFLP with a few examples.
A Polynomial Approximation Problem
Consider the problem of finding the relationship between the coefficients of a univariate polynomial of degree 3 and a univariate polynomial of degree 4 related by the constraint that they have the same values for .
In CFLP, the polynomial f of degree 3 can be specified by the -term where a, b, c, d are constants, and the polynomial g of degree 4 can be specified by the -term where m, n, p, q, r are variables whose values have to be computed from the conditions
which can be specified in the compact form
The underlined symbols denote the free variables in the rewrite rules, and
To solve equation (1), we call
The equational symbol denotes strict equality, that is, the fact that the values of the two sides of the equation coincide. We identify the value of an expression with the result of rewriting it to an expression without defined symbols.
The syntax call of
The constant coefficients of f are given as data constructors, and the unknown coefficients of g are given as main variables.
In this example, CFLP returns the unique solution
which is printed out as soon as it is computed, and collected in the output of the
Note the use of higher-order variables and -abstractions in the specification of the goal and functional logic program. CFLP is able to handle equations involving operators defined outside the functional logic program. Furthermore, the computed answer is parametric, since r is a variable.
This example illustrates the expressive power of the functional logic programming style extended with higher-order constructs (function variables and -abstractions) and capabilities to solve differential equations, linear equations, and systems of polynomial equations. We consider the problem of modeling the behavior in time of electrical circuits built from serial and parallel connections of elementary components such as resistors, inductors, and capacitors.
First we introduce a new type constructor
Next, we define a function
The CFLP program is given below. We do not explain the underlying electronic laws since it should be easy to read them off from the program.
Consider the problem of finding the behavior in time of the current in an RLC circuit, under the restriction that the voltage is constant in time and the current was initially set to 0.
In this case, the goal which we want to solve (in variable
The system computes the parametric solution
which is represented in Mathematica by
Note the usage of type annotations in the goal, list of variables, and options of the
A Problem Involving Solver Cooperation
Consider the following program
in complex variables
Solving this goal requires a cooperation among solvers for linear, polynomial, and differential equations over the domain
of complex numbers. To solve
In this case, the solutions computed by CFLP are parametric, and the system has generated the auxiliary variables , , , , , to express them. It is not hard to see that these are all the solutions of
Copyright © 2001 Wolfram Media, Inc. All rights reserved.