3 views

Uploaded by vincentoid

symbolicC++

- pg534-35
- Spec Gekko
- 1
- Jfp 16 (6): 671–679, 2006.
- Math 100 First Term Exam Ab4
- Lecture 7
- MIT18_06S10_L04
- Oracle Reports 6i_volume2
- Comprehensive Test 12.09.05 SOL
- c++ file
- Practical 1
- day1_ppt
- TCS Reasoning
- Matrix
- 10.1.1.294.7178
- Calculus Matrix Algebra
- GI-FI
- 22 Fixedpoint arithmetic.pdf
- Additional Mathematics 2007 November Paper 2
- 06 Mathematics.pdf

You are on page 1of 4

The Symbolic class provides almost all of the features required for symbolic computation including symbolic terms, substitution, non-commutative multiplication and vectors and matrices. All the necessary classes and denitions are obtained by #include "symbolicc++.h" int the C++ source le. There are a number of constructors available for Symbolic: Symbolic Symbolic Symbolic Symbolic Symbolic Symbolic Symbolic Symbolic Symbolic Symbolic Symbolic zero; int_one1(1), int_one2 = 1; dbl_one1(1.0), dbl_one2 = 1.0; half = Symbolic(1)/2; a("a"); b("b", 3); c = b(2); A("A", 2, 3); d = A(1, 2); e = (a, c, d); B = ( ( half, a ), ( c, A(0,0) ) ); // // // // // // // // // // // // default value is 0 construction from int construction from double fraction 1/2 symbol a vector (b0, b1, b2) copy constructor, c = b2 matrix A with 2 rows and 3 copy constructor, d = A(1, vector (a, b2, A(1, 2)) matrix B = [ 1/2 a [ b2 A(0,0)

columns 2); ] ]

The , operator has been overloaded to create lists of type STL list<Symbolic> which can be assigned to Symbolic to create vectors and matrices as shown for v and B. Matrices and vectors are indexed using the () and (,) operators. All the standard arithmetic operators are provided for Symbolic as well as the usual functions cos, sin, exp, tan, cot, sec, csc, sinh, cosh, ln, pow or alternatively (x^y), and sqrt. The precedence of ^ is lower than |+|so the parenthesis (x^y) are usually necessary. Symbolic C++ also includes an Equation class for expressing equality (or substitution) usually constructed using the == operator: Equation eq = (a == a*c - d); Equations also serve as logical variables, in the sense that they can be cast to bool:

if(eq) cout << "a == a*c - d" << endl; else cout << "a != a*c - d" << endl; if(a == a) cout << "a is a" << endl;

// a != a*c - d // creates the equation (a == a) // the if statement implicitly // casts the equation to bool

Symbols can depend on eachother using the [] operator: Symbolic x("x"), y("y"), t("t"); cout << y << endl; cout << y[x] << endl; cout << y << endl; cout << y[x,t] << endl; cout << y << endl; x = x[t]; y = y[x]; cout << y << endl; // // // // // // // // independent y y[x] (y dependent on x, explicit) independent y y[x,t] (y dependent on x and t) independent y x depends on t (implicit) y depends on x y[x[t]]

Substitution is specied via equations and the [] operator: Symbolic v("v"); Symbolic u = (v^5) + cos(v-2); cout << u[v == 2] << endl; cout << u[cos(v-2) == sin(v-2), v == 2] << endl; cout << u[v == 2, cos(v-2) == sin(v-2)] << endl; cout << u.subst(v == 2) << endl; cout << u.subst_all(v == 2) << endl; cout << u.subst(v == v*v) << endl; cout << u.subst_all(v == v*v) << endl; // u depends implicitly on v // 33 // 32 // 33 // // // // 33 33 v^10 + cos(v^2 - 2) never returns

The above example demonstrates that substitution proceeds from left to right. The member function subst can also be used for substitution, as well as subst_all. The dierence between the two methods is that subst substitutes in each component of an expression only once while subst_all attempts to perform the substitution until the substitution fails, thus for v v*v we have the never ending substitution sequence v v^2 v^4 v^8 . Symbolic variables can be either commutative or non-commutative. By default symbolic variables are commutative, commutativity is toggled using the ~ operator: 2

Symbolic P("P"), Q("Q"); cout << P*Q - Q*P << endl; cout << ~P*~Q - ~Q*~P << endl; cout << P*Q - Q*P << endl; P = ~P; cout << P*Q - Q*P << endl; Q = ~Q; cout << P*Q - Q*P << endl; cout << (P*Q - Q*P)[Q == ~Q] << endl; cout << P*Q - Q*P << endl; Q = ~Q; cout << P*Q - Q*P << endl;

// // // // // // // // // // //

It is also possible to determine the coecient of expressions using the method coeff, and additional power can be specied: Symbolic m("m"), n("n"); Symbolic result = (2*m - 2*n)^2; cout << result.coeff(m^2) << endl; cout << result.coeff(n,2) << endl; cout << result.coeff(m) << endl; cout << result.coeff(m*n) << endl; cout << result.coeff(m,0) << endl; cout << result.coeff(m^2,0) << endl; cout << result.coeff(m*n,0) << endl; // // // // // // // // 4*(m^2) - 8*m*n + 4*(n^2) 4 4 -8*n -8 constant term: 4*(n^2) constant term: -8*m*n + 4*(n^2) constant term: 4*(m^2) + 4*(n^2)

Dierentiation and elementary intergration is supported via the functions df and integrate: Symbolic p("p"), q("q"); cout << df(p, q) << endl; cout << df(p[q], q) << endl; cout << df(p[q], q, 2) << endl; cout << df(cos(p[q]^2) - (q^2)*sin(q),q) << endl; cout << integrate(p, q) << endl; cout << integrate(p[q], q) << endl; cout << integrate(ln(q), q) << endl; // // // // // // // // 0 df(p[q], q) df(p[q], q, q) (2nd derivative) -2*sin(p[q]^(2))*p[q]*df(p[q],q) - 2*q*sin(q)-q^(2)*cos(q) p*q integrate(p[q], q) q*ln(q) - q

A number of operattions are dened on Symbolic which are dependent on the underlying value. For example, a symbolic expression which evaluates to an integer can be cast to int and similarly for double. Note that double is never simplied to int, for example 2.0 2 while fractions do 2 1. 2 3

Symbolic z("z"); cout << int(((z-2)^2) - z*(z-4)) << endl; cout << int(((z-2)^2) - z*(z-4.0)) << endl; cout << int(((z-2.0)^2) - z*(z+4)) << endl; cout << int(((z-2.0)^2) - z*(z-4)) << endl; cout << double(((z-2.0)^2) - z*(z-4)) << endl;

The matrix operations det and tr, scalar product a|b, cross product % and methods rows, columns, row column, identity, transpose, vec, kron dsum and inverse are only dened on matrices with appropriate properties. Symbolic X("X", 3, 3), Y("Y", 3, 3); cout << tr(X) << endl; // X(0,0) + X(1,1) + X(2,2) cout << det(Y) << endl; cout << "X: " << X.rows() // X: 3 x 3 << " x " << X.columns() << endl; cout << X.identity() << endl; cout << X << endl; cout << X.transpose() << endl; cout << X*Y << endl; cout << X.vec() << endl; // vec operator cout << X.kron(Y) << endl; // Kronecker product cout << X.dsum(Y) << endl; // direct sum cout << X.inverse() << endl; // direct sum cout << X.row(0) * Y.column(1) << endl; cout << (X.column(0) | Y.column(0)) << endl; // scalar product cout << (X.column(0) % Y.column(0)) << endl; // vector product

- pg534-35Uploaded byLeonard Gonzalo Saavedra Astopilco
- Spec GekkoUploaded byskynyrd75
- 1Uploaded byscribdman1
- Jfp 16 (6): 671–679, 2006.Uploaded byapi-25884893
- Math 100 First Term Exam Ab4Uploaded byEduard C. Taganap
- Lecture 7Uploaded byTuấnNguyễn
- MIT18_06S10_L04Uploaded byManu Sharma
- Oracle Reports 6i_volume2Uploaded byapi-27048744
- Comprehensive Test 12.09.05 SOLUploaded byPraveen Kumar
- c++ fileUploaded byYog Kunwar
- Practical 1Uploaded byBalavant
- day1_pptUploaded byvinit
- TCS ReasoningUploaded byapi-3818780
- MatrixUploaded byAlhilali Ziyad
- 10.1.1.294.7178Uploaded byfransisca
- Calculus Matrix AlgebraUploaded byrossherbert2005
- GI-FIUploaded bySanmay Kokate
- 22 Fixedpoint arithmetic.pdfUploaded byrukahua
- Additional Mathematics 2007 November Paper 2Uploaded bylornarifa
- 06 Mathematics.pdfUploaded bySubhraJyotiBorah
- knowledgebase-003Uploaded byDeepak Chachra
- Verification and Expansion of SDOF Transformation Factors for BeamsUploaded bybong2rm
- Squares in Arithmetic ProgressionUploaded byschultzmath
- 1223Uploaded byde_wight
- Matlab challenge at high school levelUploaded byPaul Werbos
- PartI2008Solns.pdfUploaded bySahabudeen Salaeh
- SSC CGL Test PaperUploaded byrabi00331278
- The Mathew EffectUploaded bygerimox
- OperaUploaded byLuis Fernandez
- jee u iiserhhhUploaded byAshokKumar

- Trapezium Method QuestionsUploaded byvincentoid
- dbex3Uploaded byvincentoid
- Applied MathUploaded byKhwezi Toni
- Applied MathUploaded byKhwezi Toni
- ChebyshevQuestions.pdfUploaded byvincentoid
- ChebyshevQuestions.pdfUploaded byvincentoid
- L1_4.9_AntiderivativesUploaded byvincentoid
- BisectionMethodQuestions.pdfUploaded byvincentoid
- Byod Best PracticesUploaded byvincentoid
- SecUploaded byvincentoid
- NewtonMethodQuestions.pdfUploaded byvincentoid
- Reference Techniques 2008 Harvard Method and Apa StyleUploaded byvincentoid
- LinAlgSec3.1Uploaded byvincentoid
- GccUploaded byEn Ndy
- Trapezium Method QuestionsUploaded byvincentoid
- Sect 11.5 Alternating SeriesUploaded byvincentoid
- Class Test 5Uploaded byvincentoid
- LinAlgSec4.4Uploaded byvincentoid
- LinAlgSec3.2Uploaded byvincentoid
- dynamicsUploaded byvincentoid
- Weeks 8 11Uploaded byvincentoid

- 12 Rational Worksheet SolutionUploaded byhoangan118
- M. K. Murray- Diff. Geometry-notesUploaded byAnonymous 9rJe2lOskx
- The Lattice of Varieties of BandsUploaded bymciricnis
- Instr Trig6 s42Uploaded byAlexander Rodriguez Angulo
- Physics Chapter 1 Clicker QuestionsUploaded byImcomingforyou
- An Elementary Proof of Stackel's Theorem - ParsUploaded byJama Hana
- solutions (1).pdfUploaded byErick Cargnel
- SEZGIN SUCU and IBRAHIM BUYUKYAZICI-Bulletin of Mathematical Analysis and Applications-2012Uploaded byNarendra Singh
- cfnseUploaded byadhishor
- Some Notes Clean r NgsUploaded byGianfranco Osmar Manrique Portuguez
- LINEAR FUNCTIONALSUploaded byhyd arnes
- A Functorial Model TheoryUploaded byOzgur Tung
- SMARANDACHE NEAR-RINGS AND THEIR GENERALIZATIONSUploaded byMia Amalia
- bab1_mtamUploaded byMohd Hafiz
- hw4vinefUploaded byGREENDEM0N
- SECTION C Properties of Prime NumbersUploaded bygdayanand4u
- COMALGE Algebra : Factoring & Division of PolynomialsUploaded by7 bit
- M.sc Maths 1st Sem SyllabusUploaded bySathish Kumar
- Dot Product - Wikipedia, The Free EncyclopediaUploaded byKim Nora
- Optimal Binary Sequences for Spread Spectrum Multiplexing.pdfUploaded byAriadna Najmy
- An Intuitive Presentation of Faà Di Bruno’s Formula_-_A. MinnucciUploaded byAndres Granados
- Frenet SerretUploaded byjohn
- Uncovered Are as for a GRE Subject MathsUploaded byRuidm Misdfwe
- Unit # 2 Theory of Quadratic EquationsUploaded byAsghar Ali
- Term 3 BUploaded byHon Monda Bw'Onchwati
- Chinese Reminder TheoremUploaded byevan lionheart
- Algebra and Number Theory CoursesUploaded byJulia S
- Trigonometric Sums in Number Theory and AnalysisUploaded bysoufianze
- home_assgn2-BEE1B_CUploaded byheyy_uzair
- Calculus TB AnswersUploaded byMatthew