
International Journal of Computer Applications (0975 – 8887) Volume 46– No.3, May 2012 Applications of Symbolic computation in C++ Programming Language Satabaldiyev Askar Bakytzhanuly Latuta Konstantin Nikolayevich SuleymanDemirel University SuleymanDemirel University Almaty, Kazakhstan Almaty, Kazakhstan ABSTRACT symbolic form, as opposed to numeric computation that deals This paper contains the brief information about symbolic with computation techniques. The location of symbolic approximations of specific numerical quantities expressed by computation within Computer Language classification is those symbols. The software that implements symbolic defined. Programming languages (PL) can be divided into two calculations might be user for symbolic differentiation, main areas: imperative PL and declarative PL. Declarative PL substitution one expression into another, finding polynomial, is generally used for logical and functional programming (ex: etc...generally for every computation with mathematical terms PROLOG, LISP, ML, Haskell,…) Symbolic computation for well-known algorithms. Symbolic computations are more techniques are commonly derived from both, logical and exact rather than numeric solutions. The reason is that functional programming. numeric solutions are more approximate and they are oriented Imperative programming languages are practically used for for specific cases, but symbolic computations are more numerical computations. Some of well-known examples of general. Because of this, symbolic computation methods may imperative PL’s are C, C++, Java, MATLAB, etc… But for need to take long time and resources to solve problems. last few years, the programming languages mentioned above Numeric computation methods are much faster. Some have been oriented to solve problems symbolically. problems can be better solved using symbolical way, while The general idea of this paper is to provide the other can be solved better in a numerical way[11]. implementation of well-known mathematical problems In Computer Science there exist many programming symbolically solved on the basis of C++ programming languages, which are used for numerical applications as language. It follows some typical examples to illustrate the solution to problems. properties of symbolic C++. Programming languages (PL) can be divided into two main areas: imperative PL and declarative PL. Declarative PL is generally used for logical and functional programming (ex: General Terms PROLOG, LISP, ML, Haskell,…) Symbolic computation Programming languages, symbolic computation, logical techniques are commonly derived from both, logical and programming, functional programming functional programming. Imperative programming languages are practically used for numerical computations. Some of well-known examples of Keywords imperative PL are C, C++, Java, MATLAB, etc… But for last Symbolic computation, C++, “symbolic++.h” few years, the programming languages mentioned above have been oriented to solve problems symbolically. 1. INTRODUCTION General classification of programming languages Symbolic computation relates to algorithms and software for is illustrated in Figure 1 manipulating mathematical expressions and equations in Programming languages(PL) Declarative PL Imperative PL Logical PL PROLOG, Functional PL ALGOL, C, C++ LISP ML, Haskell, ... Java, MATLAB Symbolic computation techniques Figure1: Classification of programming languages 6 International Journal of Computer Applications (0975 – 8887) Volume 46– No.3, May 2012 Symbolic computation techniques (SCT) are created from There are not much publications about symbolic C++. There is knowledge logical and functional programming techniques. only one textbook and some papers [7],[8],[9] Some examples of SCT open-source, cost free tools are given in the following list: Axiom, Bergmann, Calc, CoCoA, There is an extensive library for symbolic C++, namely DoCon, DCAS, Eigenmath, Franklin Math, FriCAS, GAP, “GiNaC”[10], which is widely used for projects with symbolic etc… C++. The following examples illustrate the basic idea of symbolic computation applying the core library Also there are more than 30 commercial SCT tools. Detailed “symbolicc++.h”, without using extensive “GiNaC” library. information can be found in reference [1], [2], [3], [4], [5], [6]. • Header files 1 • Declaration of symbolic variables 2 • Symbolic computations 3 • Output results 4 Figure 2: General procedure for symbolic C++ program 2. APPLICATION OF SYMBOLIC C++ 2.4 Series This chapter demonstrates the application of symbolic C++ Table 4. List of functions, descriptions and source codes programming for the most common mathematical subjects, for examples with series such as Vector Algebra, Algebra, Polynomials, and Series. Function Description Source code 2.1 Vector Algebra Taylor series expansion taylor.cpp Table 1.List of functions, descriptions and source codes for 2.5 Source codes and output examples from vector algebra Function Description Source code 2.5.1 Vector addition and subtraction + Vector addition and veca.cpp // "veca.cpp" - subtraction // Vector addition and subtraction | Scalar product sp.cpp #include <iostream> % Cross product cp.cpp #include "symbolicc++.h" Gradient grad.cpp using namespace std; Divergence diverge.cpp int main(void){ // 1. Block: Declaration of symbolic variables 2.2 Algebra Symbolic x("x", 2), y("y", 2), z("z", 2), s("s", 2); Table 2.List of functions, descriptions and source codes for // 2. Block: Computations examples from algebra z = (x + y); Function Description Source code s = (x - y); // 3. Block: Output the results Df Differentiation diff.cpp cout<< "Addition z = " << z <<endl; Integrate Integration integ.cpp cout<< "Subtraction s = " << s <<endl; 2.3 Polynomial system("PAUSE"); return 0; } Table 3.List of functions, descriptions and source codes for examples with polynomials /* Sample output: Function Description Source code Addition z = Diff Multivariable poly.cpp [x0+y0] polynomial [x1+y1] differentiation Legendre Solution of Legendre legendre.cpp Subtraction s = differential equations [x0-y0] [x1-y1] */ 7 International Journal of Computer Applications (0975 – 8887) Volume 46– No.3, May 2012 This symbolic computation gives directly the results of vector // Gradient example addition and subtraction for the given vectors #include <iostream> 2.5.2 Scalar product #include "symbolicc++.h" using namespace std; // "sp.cpp" // Scalar product int main(void){ // 1. Block: Declaration of symbolic variables #include <iostream> Symbolic x("x"), y("y"), z("z"); #include "symbolicc++.h" Symbolic f = x*x+y*y+z*z; using namespace std; Symbolic res("res", 3); // 2. Block: Computations int main(void){ res(0) = df(f,x); // 1. Block: Declaration of symbolic variables res(1) = df(f,y); Symbolic x("x", 2), y("y", 2), z("z", 2); res(2) = df(f,z); // 2. Block: Computations // 3. Block: Output the results z = (x|y); cout<< "Gradient : "<< res <<endl; // 3. Block: Output the results system("PAUSE"); cout<< "z = " << z <<endl; return 0; } system("PAUSE"); /* return 0; Sample output: } Gradient : /* [2*x] Sample output: [2*y] z = x0*y0+x1*y1 [2*z] */ */ This symbolic computation gives directly the result of scalar This symbolic computation gives directly the result of product for the given expression gradient for the given expression 2.5.3 Cross product // "cp.cpp" 2.5.5 Divergence // Cross product // "diverge.cpp" // Divergence #include <iostream> #include "symbolicc++.h" #include <iostream> using namespace std; #include "symbolicc++.h" using namespace std; int main(void){ // 1. Block: Declaration of symbolic variables int main(void){ Symbolic x("x", 3), y("y", 3), z("z", 3); // 1. Block: Declaration of symbolic variables Symbolic x("x"), y("y"), z("z"); // 2. Block: Computations Symbolic f = x*x+y*y+z*z; z = (x % y); // 2. Block: Computations // 3. Block: Output the results Symbolic res = df(f,x) + df(f,y) + df(f,z); cout<< "z = " << z <<endl; // 3. Block: Output the results system("PAUSE"); cout<< "Divergence : "<< res <<endl; return 0; } system("PAUSE"); /* return 0; Sample output: } z = /* [x1*y2-y1*x2] Sample output: [y0*x2-x0*y2] Divergence : 2*x+2*y+2*z [x0*y1-y0*x1] */ */ This symbolic computation gives directly the result of This symbolic computation gives directly the result of cross divergenceof the function above. product for the given expression 2.5.6 Differentiation 2.5.4 Gradient // "diff.cpp" // "grad.cpp" // Differentiation 8 International Journal of Computer Applications (0975 – 8887) Volume 46– No.3, May 2012 int main(void){ #include <iostream> // 1. Block: Declaration of symbolic variables #include "symbolicc++.h" Multinomial <double>a("a"); Multinomial <double>b("b"); using namespace std; Multinomial <double>x("x"); int main(void){ Multinomial <double> p = a*(x^3) + b*(x^2) + 1; // 1. Block: Declaration of symbolic variables // 2. Block: Computations Symbolic x("x"); Symbolic y = sin(x) + cos(x); Multinomial <double> res = Diff(p, "x"); // 2. Block: Computations Symbolic res = df(y,x); // 3. Block: Output the results cout<< "Diff(p,x) => "<< res <<endl; // 3. Block: Output the results cout<< "Differentiation : res = "<< res <<endl; system("PAUSE"); return 0; system("PAUSE"); } return 0; /* } Sample output: /* Diff(p,x) => (3)ax^2 + (2)bx Sample output: */ Differentiation : res = cos(x)-sin(x) This symbolic computation gives directly the result of */ multivariable polynomial differentiation for the given The general terms after differentiation with symbolic computation are multinomial shown. 2.5.9 Solution
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages5 Page
-
File Size-