A Computational Method with MAPLE for a Piecewise Polynomial Approximation to the Trigonometric Functions

: A complete MAPLE procedure is designed to effectively implement an algorithm for approximating trigonometric functions. The algorithm gives a piecewise polynomial approximation on an arbitrary interval, presenting a special partition that we can get its parts, subintervals with ending points of ﬁnite rational numbers, together with corresponding approximate polynomials. The procedure takes a sequence of pairs of interval–polynomial as its output that we can easily exploit in some useful ways. Examples on calculating approximate values of the sine function with arbitrary accuracy for both rational and irrational arguments as well as drawing the graph of the piecewise approximate functions are presented. Moreover, from the approximate integration on [ a , b ] with integrands of the form x m sin x , another MAPLE procedure is proposed to ﬁnd the desired polynomial estimates in norm for the best L 2 -approximation of the sine function in the vector space P (cid:96) of polynomials of degree at most (cid:96) , a subspace of L 2 ( a , b ) .


Introduction
There are two aspects of implementation of an algorithm. One is the illustration for the validity of the algorithm, and the other for the efficient exploitation of its steps thanks to the choice of suitable tools.
Remez's minimax algorithm is well established (see Section 3.5 in [1]), but all the steps to proceed it contain the two main obstacles when being performed in practice: • solving a nonlinear equation and a system of linear equations; and • using the cosine function to compute the initial set of points.
As a warning to experienced users, they should have close control of the evaluation error at almost every calculation for the above steps. Therefore, it could be difficult to effectively implement this algorithm for approximating the trigonometric functions themselves.
Here, we choose Algorithm 2 in [2] to be implemented with MAPLE (or any of Computer Algebra Systems (CAS), if possible), because it has the great advantage: only using arithmetic calculations on finite rational numbers and comparisons. The choice of MAPLE is due to its powerfulness of symbolic computation and its ability to display exact number of significant digits for the obtained numerical results. The description of Algorithm 2 is clear, but examples on numerical integration and graphical plots in [2] seem to be as of the first kind of implementation as mentioned above. Therefore, we come back to the article [2] with aspiration to provide the beginners or occasional users with a complete MAPLE procedure, the output of which being easy and convenient to exploit when implementing Algorithm 2.
From [2], we have that the function sin x is piecewise approximated on an interval [a, b] by the polynomials A i (x) on the subintervals [α i , α i+1 ], i = 0, . . . , n, such that [a, b] These approximations all have the accuracy of 1/10 r in absolute value for a given arbitrary positive integer r. The main purpose of Algorithm 2 is to give the pairs of [α i , α i+1 ], A i (x) , i = 0, . . . , n, and, as a convention, the notations of this output is used in the next sections.
The paper is organized as follows. In Section 2, we construct a complete MAPLE procedure by blocks of commands so that we can modify them easily. These blocks whose purpose is clearly explained may be useful to design other procedures. Section 3 is for exploitation of the obtained results from the output of the procedure. Section 3 is the detailed discussion on how to find a desired estimate p for the best L 2 -approximation p best of the sine function in the vector space P . In particular, it is possible to make a complete MAPLE procedure to find p's with different values of from the existing materials, and we let the reader do it with his or her close control of evaluation error for the steps containing norms of vectors. Moreover, the crucial components of a procedure that computes approximate values of integration with integrands of the form x m sin x (m ∈ N) are also provided. Section 4 is the conclusion.

Implementation by MAPLE Procedures
We list here the MAPLE commands that appear in our procedures. They are all very important and frequently used in MAPLE programming: add, coeff, Digits, ERROR, evalf, floor, for, irem, int, nops, op, piecewise, RETURN, seq, sort, and while. A declaration to create a function, e.g., f, such as f:=x->F(x) or f:=unapply(F(x),x), where F(x) is an expression in x, is a very useful and convenient tool in MAPLE procedures for doing calculations. In addition, the conditional structure if-then is indispensable in branch programming, whereas the type list is a flexible ordered arrangement of operands (or things and elements). See [3,4] and MAPLE help pages in each session to know more details about meaning, syntax and usage of these commands, structures and types.
In the following, we consider in succession the steps to perform Algorithm 2 in [2] with their content and corresponding MAPLE codes. However, we modify some steps in Algorithm 2 to get the extraction results conveniently from its output. Firstly, we recall the two blocks of commands (inside steps) for getting the degree n of the approximate polynomial P c n (x) of the function sin x (Block 1), which satisfies the accuracy of 1/10 r , and for finding the approximate values of π/2, which appear in P c n (x). Block 2 is nothing but the full content of FindPoint, a procedure to determine nodes of the form kp , where k ∈ Z and p is an approximate value of π/2 (see [2]). These nodes are ending points of subintervals in the partition of an arbitrary interval [a, b]. The output of FindPoint from its argument y also gives the approximate polynomial F. Moreover, we have them all together, k, p and F from a list of three components; that is, we may write FindPoint(y) = [k,p ,P] with p ≈ p = π/2, | sin x − P(x)| < 1/10 r for all x ∈ [kp − p /2, kp + p /2] and |y − kp | < 0.8. if (irem(k0-1,2)=0) then F:=unapply((-1)^((k0-1)/2)*add((-1)^s*(t-k0*q)^(2*s)/((2*s)!), s=0..floor(n/2)),t): else F:=unapply((-1)^(k0/2)*add((-1)^s*(t-k0*q)^(2*s+1)/((2*s+1)!), s=0..floor((n-1)/2)),t): Next, Block 3 that may be the most important one is designed to find approximate polynomials A j (x), corresponding to intervals [α j−1 , α j ], where α j , j = 1, . . . , i, are the nodes mentioned above. This block gives a so-called spreading technique that takes nodes together with the polynomials A j (x), by using Block 2 successively, as clearly described in [2]. We choose the output of Block 3 as a function of a finite sequence of lists given in the form of This output has the advantages of a function itself or a sequence of terms, because we can take its values H(x) and H(−x), or its components (or operands) We design a MAPLE procedure named ApproxFunct to give the approximate function P for the sine function on an interval [a, b] for a ≥ 0. In the cases of 0 ≤ a < b ≤ 0.8 and 0 ≤ a < 0.8 < b, we may set P = G on [a, b] and P = G on [a, 0.8], respectively, where and n is determined by Block 1. Before giving the MAPLE codes of Block 3 chosen as the full content of TempApproxFunct, the procedure to give the approximation to the sine function on [a, b] only for a ≥ 0.8, we recall here (from [2]) the important remark: if α, β ∈ [a, b] are numbers such that , then we have |α − kp | < 0.8 and |β − kp | < 0.8.
Note that TempApproxFunct takes three arguments in order as a, b and r. Next, we combine Block 1 and Block 3 with some conditional commands to form Block 4, which is the content of the ApproxFunct. Now, we may call ApproxFunct(a,b,r) to fully access all subintervals together with approximate polynomials for the accuracy of 1/10 r on an interval [a, b], a ≥ 0. In particular, if we want to extract the jth interval and its corresponding approximate polynomial, use the calling sequence ApproxFunct(a,b,r)(x)[j], where j is chosen from the output ApproxFunct(a,b,r)(x).
Finally, from the above analysis, we obtain the desired procedure named PiecewiseFunct (see the supplementary material accompanying this paper for MAPLE codes), which gives a special partition of an arbitrary interval [a, b] into subintervals [α j−1 ,α j ] together with corresponding approximate polynomials A j (x), where Because the converted intervals should be arranged in the correct order on the real axis, we use the calling sequence seq( In fact, PiecewiseFunct contains a technique that indirectly solves a difficult problem "How to reduce values of arguments when doing calculations with the trigonometric functions". There was a great attempt to solve the problem and perhaps [1] would be one of the best reference books on this fact. However, this technique is only a suitable remedy for applying Taylor's Theorem, which has not been considered a good way in approximation theory. PiecewiseFunct can be also used to give pointwise approximate values of the sine function, so we do not need to recall here Algorithm 1 (see [2]). A hint: Combine Block 1, Block 2 and the illustrated MAPLE codes for the distinction between "r-th decimal digit" and "r significant digits" on [2] to make a procedure, e.g., Sine, to implement Algorithm 1.

Exploitation of the Output of the PiecewiseFunct Procedure
Now, we have sin x ≈ f (x) for all x ∈ [a, b] with the accuracy of 1/10 r .
In the following, we take examples on approximating values of the sine function at rational and irrational arguments and getting the graph of approximate functions on an arbitrary intervals with various accuracy. Moreover, the approximation of integration on [a, b] with integrands of the form x m sin x (m ∈ N) is considered in both theoretical and practical aspects.
To find the approximate value of sin(123.45) with the accuracy of 1/10 20 , we put A := [PiecewiseFunct(123,124,20)]. Then, nops(A) = 2 and the interval [123, 124] is partitioned into the subintervals [123, 123.3075117] and [123.3075117, 124]. Thus, we take f := unapply (op(2,A[2]),x) and obtain Now, with an irrational number x, how do we approximate the value of sin x with the accuracy of 1/10 r ? In principle, we can find a rational number x such that |x − x | < 1/10 r+1 and use the PiecewiseFunct procedure to determine a polynomial P that satisfies | sin(x ) − P(x )| < 1/10 r+1 . Then, we have the estimate | sin x − P(x )| < 1/10 r . For example, we approximate the value of sin( √ 3) with the accuracy of 1/10 50 by first taking There are many algorithms in the literature to find rational approximations to an irrational number with the desired accuracy, mostly using continued fractions. The theoretical basis of this classic problem can be found in the two great books [5] and [6]. CAS of course have their built-in commands to compute such approximations. Here, we may take x by the calling sequence evalf[51](sqrt (3)).
Besides, from Equation (1) with the declaration in Equation (2), we derive the graph of piecewise polynomial approximation to the sine function by the command plot(f(x),x=a..b,numpoints=500). We choose the large values r = 150 and r = 500 for the intervals [−200, −50] and [−100, 600], respectively. Let us try the case r = 500 to see the display of 448 pairs of interval-polynomial with the accuracy of 1/10 500 . The corresponding graphs are depicted in Figure 1.
We may also exploit PiecewiseFunct from the other side of our approximation. We have used Taylor polynomials with larger degrees when higher accuracy is required thus far. If we want to confine approximate polynomials to a fixed degree, we might relate this determination to the vector space P , a subspace of L 2 (a, b). We know that in P there is the best polynomial approximation p best of the sine function in L 2 -norm · = ·, · 1/2 of L 2 (a, b), which is endowed with the inner product Once the orthonormal basis has been found, we obtain p best = sin, p 0 p 0 + sin, p 1 p 1 + · · · + sin, p p = ∑ k=0 sin, p k p k .
To give an estimate for sin −F , where F is our piecewise polynomial approximation to the sine function on [a, b], we first approximate sin, p k by These estimates have the absolute error Therefore, we may choose as an approximation of p best . Then, we have the following estimation for the error norm Hence, we may take r = lg(( + 1) √ b − a) + 1 + u to obtain the estimate To determine p c best with MAPLE, it would be better to write the polynomial p k in the form of p k := ∑ k s=0 a ks x s , hence we have According to the initial settings in Equation (1), the coefficients a ks and the inner products F, x s can be computed by the following commands We can make a procedure named PowerIntApprox only to compute F, x s , s = 0, . . . , . This procedure, which has one more argument, e.g., "deg", for the chosen degree of p best , may take all the blocks of PiecewiseFunct, but replacing the output of Block 3, Block 4 and the last part of PiecewiseFunct with the commands recapped in the following. For the output RETURN of Block 3, we take the sum of integrals of x s A i (x) on [α i , α i+1 ], instead of giving the sequence of [α i , α i+1 ], A i ; and we do similarly for the output of and the reason we do so can be easily recognized. Here, ApproxInt has a similar role as ApproxFunct, but is simpler to use. Now, we have enough materials derived from Equations (3)-(6) to make a procedure for finding a desired approximation on [a, b] in L 2 -norm to the best approximation p best of the sine function in P with a given positive integer . The procedure takes four arguments, a, b, and u, to give p ∈ P as its output such that p − p best < 1/10 u . As mentioned above, if we named the procedure BestApprox, hence it takes PowerIntApprox as its local variable, then it would be interesting to run BestApprox with different values of its input. However, as warned in Section 1, we should pay much attention to the cases of large values of and u to take an appropriate regulation.

Conclusions
There could be some more useful ways to exploit the output of PiecewiseFunct and its corollary, PowerIntApprox, as well as Sine. Although these procedures are designed only for the sine function, we can make some appropriate changes to the blocks of commands to obtain their "cosine" version. It is hoped that some application results of our procedures would supply some more improved computational tools in applied mathematics.