ebook img

Computer Algebra with SymbolicC++ PDF

598 Pages·2008·4.171 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Computer Algebra with SymbolicC++

s. e cl arti s s e c c A n e p O c.compt for cientifid, exce Computer Algebra orldsmitte w.wper with SymbolicC++ wot wn om ctly aded frn is stri oo wnluti C++ Dod distrib SymbolicRe-use an h 9. wit5/1 Algebra on 07/2 er TY mputRSI CoVE NI U E P E T T E C A H y b s. e cl arti s s ce TThhiiss ppaaggee iinntteennttiioonnaallllyy lleefftt bbllaannkk c A n e p O c.compt for cientifid, exce orldsmitte w.wper wot wn om ctly aded frn is stri oo wnluti C++ Dod distrib SymbolicRe-use an h 9. wit5/1 Algebra on 07/2 er TY mputRSI CoVE NI U E P E T T E C A H y b Yorick Hardy University of Johannesburg South Africa Kiat Shi Tan Ilog Co., Ltd., Singapore Willi-Hans Steeb es. University of Johannesburg cl arti South Africa s s e c c A n e p O c.compt for cientifid, exce orldsmitte w.wper Computer Algebra wot wn om ctly aded frn is stri with SymbolicC++ oo wnluti C++ Dod distrib SymbolicRe-use an h 9. wit5/1 Algebra on 07/2 er TY mputRSI CoVE NI U E P E T T E C A H y b World Scientific NEW JERSEY • LONDON • SINGAPORE • BEIJING • SHANGHAI • HONG KONG • TAIPEI • CHENNAI Published by World Scientific Publishing Co. Pte. Ltd. 5 Toh Tuck Link, Singapore 596224 USA office: 27 Warren Street, Suite 401-402, Hackensack, NJ 07601 UK office: 57 Shelton Street, Covent Garden, London WC2H 9HE s. e cl arti s s e c c A n e p O c.compt for British Library Cataloguing-in-Publication Data cientifid, exce A catalogue record for this book is available from the British Library. orldsmitte w.wper wot wn om ctly aded frn is stri oo wnluti C++ Dod distrib COMPUTER ALGEBRA WITH SYMBOLICC++ h Symbolic9. Re-use an AmCloelc prhyigarihngtihsc tar ©el,s ie2nr0cvl0eu8dd .ib Tnygh W ips hbooortloodkc S,o ocpirye ipnnatgirf,t isrc e tPchouerrbdelioisnfh,g im nogar yaC nnooy. tiP nbtfeeo .r rLemptadrto.idounc setdo riang aen ayn fdo rrmet roire vbayl a snyys tmemea nnosw, e klencotwronn oicr otor wit5/1 be invented, without written permission from the Publisher. Algebra on 07/2 er TY mputRSI For photocopying of material in this volume, please pay a copying fee through the Copyright Clearance Center, CoVE Inc., 222 Rosewood Drive, Danvers, MA 01923, USA. In this case permission to photocopy is not required from NI the publisher. U E P E T T E ISBN-13 978-981-283-360-0 C A ISBN-10 981-283-360-9 H y ISBN-13 978-981-283-361-7 (pbk) b ISBN-10 981-283-361-7 (pbk) Printed in Singapore. LaiFun - ComputerAlgebra.pmd 1 7/18/2008, 3:39 PM es. Preface cl arti s s e c c A n e p O c.compt for sInymthbioslitcexatlgwebersahosywstheomwaonbdjehcto-wortiehnetesydsptermogrisamapmpilniegdctaondbie(cid:11)eurseendttaoreimaspilnemmeanttha- cientifid, exce ematics and physics. orldsmitte In the most restrictive sense, computer algebra is used for the manipulation of sci- w.wper enti(cid:12)c and engineeringformulae. Usually, a mathematical formula described in the wot programming languages such as C, C++ and Java can only be evaluated numeri- wn om ctly cally,byassigningtherespectivevaluestoeachvariable. However,thesameformula aded frn is stri mforamyablettrraenastfeodrmasaatiomna,tshuecmhaatsicdali(cid:11)oebrjeencttiaintioans,yimntbeoglricatailognebarnadsysestreiems,ewxphaicnhsiaolnlo,wins wnloutio additiontothenumericalmanipulations. Thisisthereforeanindispensabletoolfor C++ Dod distrib research and scienti(cid:12)c computation. SymbolicRe-use an csOcabileljyne,ccoet-baojsreiciettn-htoaerdsiebnpetreeondgrspaurmgoggmersaintmegdmhaianssgaciprseoaasntseiibdmleapsonoreltuwatnieotrnaaptfoporsroopaftcrwhogatrroaeamdnemavlieynlzogipnimngepcnrotom.bpBleuamtsesir-, Algebra with on 07/25/19. dseoxeftsteiwgnnasiirnbeglep.sryosdtuemctss abnedcobmueildleisnsgesrorlourtipornosn.eB, yeaaspieprlytoingmtahinistamine,thmoodree(cid:11)reecutsiavbellye,atnhde er TY ComputVERSI Tprhoegrpaumrmpoisnegomfatyhibsebaopopkliiesdtotodtehmeodnesvtrealotpemheonwt tohfeafecaotmupreusteorfaolgbejebcrta-osryiestnetmed. NI Among the many object-oriented programming languages available nowadays, we U haveselectedC++asourprogramminglanguage. Itisthemostwidelyusedobject- E EP oriented programminglanguage,which has been successfully utilized by manypro- T T grammersinvariousapplicationareas. Thedesignisbasedpartlyonacknowledged E C principles and partly on solid experience and feedback from actual use. Many ex- A y H perienced individuals and organizations in the industry and academia use C++. b In addition to the reasons stated above, we have selected C++ over other object- oriented languagesbecause of its e(cid:14)ciency in execution speed and its utilization of pointers and templates. The Standard Template Library provided by C++ is very helpful for the implementation of a computer algebra system. Chapter 1 introduces the general notion of Computer Algebra. We discuss the es- sential properties and requirements of a computer algebra system. Some pitfalls v vi PREFACE and limitationsarealsolisted forreference. Finally, wepresentacomputeralgebra system | SymbolicC++. This new system has many advantages over existing computer algebra systems. Chapter 2 presents the general mathematics for a computer algebra system. We describe how fundamental mathematical quantities are built up to form morecom- s. e cl plex mathematical structures. arti s s e Chapter 3 gives a brief introduction to some computer algebra systems available c c A in the market place, such as Reduce, Maple, Axiom, Mathematica, MuPAD and n pe Maxima. The basic operations are described for each system. Examples are used O c.compt for to demonstrate the features of these systems. cientifid, exce cInlasCsehsa,pctoerns4t,ruwcetoirnst,roadnudcetetmhpelalatnesg.uaWgeetdoeoslscriinbeCe+rr+orsuhcahndalsintghetetchhinsiqupeosinatenrd, orldsmitte introduce the concept of exception handling. Examples are also given for demon- w.wper stration purposes. Wealsodescriberecursion. A numberof programsillustratethe wot concepts. wn om ctly aded frn is stri Swthriicnhgscelravsessesasaarevdehisicculessfeodr iinntrCodhuacpitnegrt5h.e fWaceilictoiensstarvuaciltabthleeinStCr+in+g.dTahtae btyupilet-, wnloutio in stringclassof C++isalsodescribedin detail. Anumberofexamples showthe C++ Dod distrib use of this class. This stringclass of C++ will be used in SymbolicC++. SymbolicRe-use an TltahhrrgeeeeSnftoauunmndbdaearrdtiooTfneaemxlpaitmlaemtpelseL:s.icboArnattraytihn(eSerTcsoL,r)ealigosofirntihtthreomSd,tuacanendddairindteCrTahetamoprptsel.artT6ehLteoisbgeertaithreyemraswrewitohthrkae Algebra with on 07/25/19. ibnnuemcuobsneejdrusninicstSiaoylnsmowbiintothlriocodCnue+cae+dn.o.tThehre. bTuhilet-binuilctl-aisnsecslalsissitn,Cv+ec+totro,dmeaapl,wciotmhpcloemxpwleilxl Computer VERSITY Cvehraypltoenrg7ingtievgeesras,croaltlieocntiaolnnuomf ubseerfsu,lqculaastseersnifoonrsc,oemxapcuttdereraivlgaetbivreas.,Wveectionrvse,smtiagtartie- NI ces, arrays, bit vectors, (cid:12)nite sets and polynomials. They are the building blocks U of mathematics as described in Chapter 2. The internal structures and external E EP interfaces of these classes are described in great detail. T T E C In Chapter8, wedescribehowamathematical expressioncanbeconstructedusing A y H object-orientedtechniques. ThecomputeralgebrasystemSymbolicC++isintro- b duced and its internal representations and public interfaces are described. Several examples are also presented to demonstrate the functionalities of the system. A symbolic numeric interface is also described. In Chapter 9, we apply the classes developed in Chapters 7 and 8 to problems in mathematicsandphysics. Applicationsarecategorizedaccordingtoclasses. Several classes may be used simultaneously to solve a particular problem. Many interest- PREFACE vii ing problems are presented, such as ghost solutions, Pad(cid:19)e approximant, Lie series techniques, Picard’s method, Mandelbrot set, etc. In Chapter 10, we discuss how the programming language Lisp can be used to im- plement a computeralgebrasystem. We implement an algebraicsimpli(cid:12)cation and di(cid:11)erentiation program. s. e cl arti We develop a Lisp system using the object-oriented language C++ in Chapter 11. s es (cid:21)-calculus and its implementation in C++ are also be introduced. c c A n e Geneexpressionprogramminganditsusefornumericalandsymbolicmanipulations p O c.compt for isstudiedinChapter12. Anumberofprogramsaregiventoillustratethetechnique. cientifid, exce aTrheelihseteaddeirn(cid:12)Clehsaopftetrhe13c.lasses(abstract data type) introduced in Chapters 8 and 9 orldsmitte w.wper The level of presentation is such that one can study the subject early on in one’s wot education in science. There is a balance between practical programming and the wn aded from n is strictly ubpnuoodtaketr.iloyninagnldanogbujaecgte-.oTriehnetbedoopkroisgridaemamllyinsgu.itTedhefobreugsineninerlewcitlulraelssoonbesnyem(cid:12)btofrliocmcotmhe- oo C++ Downld distributi lTBauhndegdurae(fge1er9e9Cn4+c)e+[l1i1s[t]9.]g,iFv[o1er6s]aa,p[c2po8llil]ce,ac[tt3ii4oo]nn,so[3ifn9t]e,sxc[ti4eb7no]c,oek[5sw9ue].sreefFufoelrrindtoathtSaetessettubrudecyttuoarfle.tsh(ew1ce9o9rm3e)fpe[ur4t9te]or, SymbolicRe-use an Steeb (1994) [50], Steeb (2005) [54] and Steeb et al. (2004) [55]. h 9. The C++ programshavebeen tested with all newer C++ compilers which comply wit5/1 with the C++ Standard and include an implementation of the Standard Template Algebra on 07/2 Library. er TY Allprogramsandheader(cid:12)lesofSymbolicC++fallundertheGNUGeneralPublic mputRSI License. We omit the following comment (or its equivalent) in all header (cid:12)le and CoVE program (cid:12)le listings in the interest of brevity: NI U E /* P SymbolicC++ : An object oriented computer algebra system written in C++ E T T E Copyright (C) 2008 Yorick Hardy and Willi-Hans Steeb C A H y This program is free software; you can redistribute it and/or modify b it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. viii PREFACE You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ The license is included with SymbolicC++ which is available from the web site s. of the International School for Scienti(cid:12)c Computing as described below. e cl arti Without doubt, this book can be extended. If you have comments or suggestions, s es we would be pleased to have them. The email addresses of the authors are: c c A en Yorick Hardy: [email protected] p O [email protected] c.compt for Willi-Hans Steeb: [email protected] orldscientifimitted, exce Sinygm. TbhoelicwCeb+p+agwesasofsdttehveeeelboInwptieeldrlnbiay@tgitomhnaeailIlnS.tccehoronmoaltifoonraSlcSiecnhtoio(cid:12)lcfCoromScpieuntitni(cid:12)gcaCreomput- w.wper wot http://issc.uj.ac.za/ wn om ctly The web page also provides the header (cid:12)les for SymbolicC++. aded frn is stri oo wnluti C++ Dod distrib MJoahracnhn2e0sb0u8rg, Singapore, YKoiaritckShHiaTradny SymbolicRe-use an Willi-Hans Steeb h 9. wit5/1 Algebra on 07/2 er TY mputRSI CoVE NI U E P E T T E C A H y b Contents s. e cl arti s s e c c A n e p O Preface v cientific.comd, except for 1 I1n.1troWduhcattioisnComputer Algebra? . . . . . . . . . . . . . . . . . . . . . . 11 orldsmitte 11..23 PPritofpalelrstiiensCoofmCpomutpeurtAerlgAeblgreabSraysSteymstsem.s. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 23 ww.wot per 1.4 Design of a Computer Algebra System . . . . . . . . . . . . . . . . . 5 wn om ctly 2 Mathematics for Computer Algebra 7 aded frn is stri 22..12 SReitnsgs.a.nd. F. i.el.ds. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 97 oo wnluti 2.3 Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 C++ Dod distrib 22..45 RRaeatiloNnaulmNbuemrsbe.rs. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 1270 SymbolicRe-use an 222...768 VCDeoectmteorpmrlseixnanaNndutmMs b.aet.rris.ce..s.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 223530 h 9. wit5/1 2.9 Quaternions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Algebra on 07/2 22..1110 GPorlo(cid:127)ybnnoemriBalasse.s. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 4375 er TY 2.12 Di(cid:11)erentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 mputRSI 2.13 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 CoVE 2.14 Risch Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 NI 2.15 Commutativity and Non-Commutativity. . . . . . . . . . . . . . . . 63 U E 2.16 Tensor and KroneckerProduct . . . . . . . . . . . . . . . . . . . . . 63 P E 2.17 Exterior Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 T T E C 3 Computer Algebra Systems 69 A H y 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 b 3.2 Reduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 3.2.1 Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . 71 3.2.2 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 3.3 Maple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 3.3.1 Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . 76 3.3.2 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 3.4 Axiom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 ix x CONTENTS 3.4.1 Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . 78 3.4.2 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 3.5 Mathematica . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 3.5.1 Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . 81 3.5.2 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 3.6 MuPAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 s. cle 3.6.1 Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . 82 arti 3.6.2 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 s es 3.7 Maxima . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 c c A 3.7.1 Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . 84 n e 3.7.2 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 p O c.compt for 3.8 G3.i8N.1aC B.a.si.c.O.pe.ra.t.io.ns. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 8855 cientifid, exce 3.8.2 Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 ww.worldsot permitte 4 T44..o21olstPhioniinsCteP+rosi+natnedrR.ef.er.en.c.es. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 889782 wn oaded from on is strictly 4444....3456 CCCTylooapnpsysesterCCsuoocnnt.ovst.rersru.saico.ntnod.rD..aen..sd..trA..ucs..stio..grn..m...e...nt... O... p...e...ra...to...r... .... .... .... .... .... .... .... .... .... .... .... .... .... 99997683 C++ Downld distributi 444...987 FCOulpanescrstaiTtooenrmTOpevlmaetrpellsoaatde.sin.g.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 11910907 h Symbolic9. Re-use an 444...111012 FIVnrihiretenurdiatslahnFipcuenc..tio..n..s.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 111111632 wit5/1 4.13 Wrapper Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Algebra on 07/2 44..1154 ERrercourrsHioannd.li.ng. T.e.ch.n.iq.ue.s. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 112179 er TY 4.16 Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 mputRSI 4.17 Run-Time Type Identi(cid:12)cation . . . . . . . . . . . . . . . . . . . . . 129 CoVE NI 5 String Class 131 U E 5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 P E 5.2 A String Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 T ET 5.3 C++ String Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 C A 5.4 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 H y b 6 Standard Template Library 145 6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 6.2 Namespace Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 6.3 Vector Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 6.4 List Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 6.5 Stack Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 6.6 Queue Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.