Andrey GrozinGraduate Texts in Physics Introduction to Mathematica ® for Physicists 201410.1007/978-3-319-00894-3© Springer International Publishing Switzerland 2014

Graduate Texts in Physics

Series EditorsWilliam T. Rhodes, H. Eugene Stanley, Richard Needs, Martin Stutzmann and Susan Scott

Graduate Texts in Physics publishes core learning/teaching material for graduate- and advanced-level undergraduate courses on topics of current and emerging fields within physics, both pure and applied. These textbooks serve students at the MS- or PhD-level and their instructors as comprehensive sources of principles, definitions, derivations, experiments and applications (as relevant) for their mastery and teaching, respectively. International in scope and relevance, the textbooks correspond to course syllabi sufficiently to serve as required reading. Their didactic style, comprehensiveness and coverage of fundamental material also make them suitable as introductions or references for scientists entering, or requiring timely knowledge of, a research field.

For further volumes: http:​/​/​www.​springer.​com/​series/​8431

Andrey Grozin

Introduction to Mathematica ® for Physicists

Andrey Grozin

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

ISSN 1868-4513e-ISSN 1868-4521

ISBN 978-3-319-00893-6e-ISBN 978-3-319-00894-3

Springer Cham Heidelberg New York Dordrecht London

Library of Congress Control Number: 2013941732

© Springer International Publishing Switzerland 2014

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law.

The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Printed on acid-free paper

Springer is part of Springer Science+Business Media (www.springer.com)

Preface

Computer algebra systems are widely used in pure and applied mathematics, physics, and other natural sciences, engineering, economics, as well as in higher and secondary education (see, e.g., [1–5]). For example, many important calculations in theoretical physics could never be done by hand, without wide use of computer algebra. Polynomial or trigonometric manipulations using paper and pen are becoming as obsolete as school long division in the era of calculators.

There are several powerful general-purpose computer algebra systems. The system Mathematica is most popular. It contains a huge amount of mathematical knowledge in its libraries. The fundamental book on this system [6] has more than 1,200 pages. Fortunately, the same information (more up-to-date than in a printed book) is available in the help system and hence is always at the fingertips of any user. Many books about Mathematica and its application in various areas have been published; see, for example, the series [7–10] of four books (each more than 1,000 pages long) or [11]. The present book does not try to replace these manuals. Its first part is a short systematic introduction to computer algebra and Mathematica ; it can (and should) be read sequentially. The second part is a set of unrelated examples from physics and mathematics which can be studied selectively and in any order. Having understood the statement of a problem, try to solve it yourself. Have a look at the book to get a hint only when you get stuck. Explanations in this part are quite short.

This book ¹ is a result of teaching at the physics department of Novosibirsk State University. Starting from 2004, the course “Symbolic and numeric computations in physics applications” is given to students preparing for M.Sc., and an introduction to Mathematica is the first part of this course (the second part is mainly devoted to Monte Carlo methods). Practical computer classes form a required (and most important) part of the course. Most students have no problems with mastering the basics of Mathematica and applying it to problems in their own areas of interest.

The book describes Mathematica 9. Most of the material is applicable to other versions too. The Mathematica Book (fifth edition) [6], as well as, e.g., the book series [7–10], describes Mathematica 5. The main source of up-to-date information is the Mathematica Help system.

The whole book (except Lecture 1 and Problems for students) consists of Mathematica notebooks. They can be found at

\url{http://www.inp.nsk.su/~grozin/mma/mma.zip}

The zip file is password protected. The password is the last sentence of Lecture 7 (case-sensitive, including the trailing period). The reader is encouraged to experiment with these notebook files. In the printed version of the book, plots use different curve styles (dashed, dotted, etc.) instead of colors.

The book will be useful for students, Ph.D. students, and researchers in the area of physics (and other natural sciences) and mathematics.

Andrey Grozin

Novosibirsk, Russia

Contents

Part I Lectures

1 Computer Algebra Systems 3

2 Overview of Mathematica 9

2.​1 Symbols 9

2.​2 Numbers 10

2.​3 Polynomials and Rational Functions 10

2.​4 Elementary Functions 12

2.​5 Calculus 13

2.​6 Lists 14

2.​7 Plots 15

2.​8 Substitutions 17

2.​9 Equations 18

3 Expressions 21

3.​1 Atoms 21

3.​2 Composite Expressions 22

3.​3 Queries 24

3.​4 Forms of an Expression 25

4 Patterns and Substitutions 27

4.​1 Simple Patterns 27

4.​2 One-Shot and Repeated Substitutions 28

4.​3 Products 29

4.​4 Sums 31

4.​5 Conditions 32

4.​6 Variable Number of Arguments 33

5 Functions 35

5.​1 Immediate and Delayed Assignment 35

5.​2 Functions 36

5.​3 Functions Remembering Their Values 36

5.​4 Fibonacci Numbers 37

5.​5 Functions from Expressions 38

5.​6 Antisymmetric Functions 39

5.​7 Functions with Options 40

5.​8 Attributes 40

5.​9 Upvalues 41

6 Mathematica as a Programming Language 43

6.​1 Compound Expressions 43

6.​2 Conditional Expressions 44

6.​3 Loops 46

6.​4 Functions 47

6.​5 Local Variables 49

6.​6 Table 50

6.​7 Parallelization 50

6.​8 Functions with an Index 51

6.​9 Hold and Evaluate 51

7 Gröbner Bases 55

7.​1 Statement of the Problem 55

7.​2 Monomial Orders 55

7.​3 Reduction of Polynomials 56

7.​4 S-Polynomials 57

7.​5 Buchberger Algorithm 58

7.​6 Is the System Compatible?​ 59

7.​7 Gröbner Bases with Respect to Lexicographic Order 60

7.​8 Is the Number of Solutions Finite?​ 61

8 Calculus 63

8.​1 Series 63

8.​2 Differentiation 67

8.​3 Integration 68

8.​4 Summation 70

8.​5 Differentiol Equations 70

9 Numerical Calculations 73

9.1 Approximate Numbers in Mathematica 73

9.​2 Solving Equations 76

9.​3 Numerical Integration and Summation 77

9.​4 Differential Equations 78

10 Risch Algorithm 79

10.​1 Rational Functions 79

10.​2 Logarithmic Extension 80

10.​3 Exponential Extension 85

10.​4 Elementary Functions 89

11 Linear Algebra 91

11.​1 ConstructingMatr​ices 91

11.​2 Parts of a Matrix 92

11.​3 Queries 93

11.​4 Operations with Matrices and Vectors 93

11.​5 Eigenvalues and Eigenvectors 95

11.​6 Jordan Form 96

11.​7 Symbolic Vectors, Matrices, and Tensors 97

12 Input–Output and Strings 99

12.​1 Reading and Writing .​m Files 99

12.​2 Output 101

12.​3 C, Fortran, and TEX Forms 102

12.​4 Strings 102

13 Packages 105

13.​1 Contexts 105

13.​2 Packages 106

13.​3 Writing Your Own Package 106

Part II Computer Classes

14 Plots 111

14.​1 2D Plots 111

14.​2 3D Plots 120

15 Trigonometric Functions 125

16 Quantum Oscillator 127

16.​1 Lowering and Raising Operators 127

16.​2 Ground State 129

16.​3 Excited States 129

16.​4 Some Properties 131

17 Spherical Harmonics 133

17.​1 Angular Momentum in Quantum Mechanics 133

17.2 $$Y _{ll}(\theta,\varphi )$$ 134

17.3 $$Y _{lm}(\theta,\varphi )$$ 135

18 Adding Angular Momenta in Quantum Mechanics 139

19 Classical Nonlinear Oscillator 145

19.​1 Statement of the Problem 145

19.​2 The First Correction 146

19.​3 The Second Correction 147

19.4 The n th Correction 149

20 Quantum Nonlinear Oscillator 153

20.​1 Perturbation Theory 153

20.​2 Nonlinear Oscillator 154

20.​3 Energy Levels 154

20.​4 Correspondence Principle 157

20.​5 States 159

21 Riemann Curvature Tensor 161

22 Multi- ζ Functions 165

22.​1 Definition 165

22.​2 Stuffling Relations 165

22.​3 Integral Representation 167

22.​4 Shuffling Relations 168

22.​5 Duality Relations 170

22.​6 Weight 4 170

22.​7 Weight 5 171

23 Rainbow 173

23.​1 Statement of the Problem 173

23.​2 0 Ray Segments Inside the Drop 174

23.​3 1 Ray Segment Inside the Drop 179

23.​4 2 Ray Segments Inside the Drop 181

23.5 L Ray Segments Inside the Drop 188

24 Cyclohexane 193

24.​1 Statement of the Problem 193

24.​2 First Steps 194

24.​3 Equations 196

24.4 Projection onto the x , y Plane 198

24.​5 Complete Analysis of the Solutions 205

24.​6 Shape of the Molecule 206

25 Problems for Students 209

References213

Index215

Footnotes

1

Work partially supported by the Russian Ministry of Education and Science.

Part 1
Lectures

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3© Springer International Publishing Switzerland 2014

Catching a lion, the computer-algebra method: catch a cat, put it into the cage and lock it; then substitute a lion for the cat.

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_1© Springer International Publishing Switzerland 2014

1. Computer Algebra Systems

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

First attempts to use computers for calculations not only with numbers but also with mathematical expressions (e.g., symbolic differentiation) were made in the 1950s. In the 1960s research in this direction became rather intensive. This area was known under different names: symbolic calculations, analytic calculations, and computer algebra. Recently this last name is most widely used. Why algebra and not, say, calculus? The reason is that it is most useful to consider operations usually referred to calculus (such as differentiation) as algebraic operations in appropriate algebraic structures (differential fields).

First attempts to use computers for calculations not only with numbers but also with mathematical expressions (e.g., symbolic differentiation) were made in the 1950s. In the 1960s research in this direction became rather intensive. This area was known under different names: symbolic calculations, analytic calculations, and computer algebra. Recently this last name is most widely used. Why algebra and not, say, calculus? The reason is that it is most useful to consider operations usually referred to calculus (such as differentiation) as algebraic operations in appropriate algebraic structures (differential fields).

First universal (i.e., not specialized for some particular application area) computer algebra systems appeared at the end of the 1960s. Not many such systems have been constructed; they are shown in the Table 1.1. Creating a universal computer algebra system is a huge amount of work, at the scale of hundreds of man-years. Some projects of this kind were not sufficiently developed and subsequently died; they are not shown in Table 1.1.

Table 1.1

Universal computer algebra systems

System

Year

Implementation

Current

Status

language

name

REDUCE

1968

Lisp

Free (BSD)

Macsyma

1969

Maxima

Free (GPL)

Scratchpad

Axiom

1974

OpenAxiom

Free (BSD)

FriCAS

muMATH

1979

Derive

Dead

Maple

1983

C, C++

Proprietary

Mathematica

1988

Proprietary

MuPAD

1992

MATLAB

Proprietary

symbolic toolbox

Theoretical physicist A. Hearn (known to specialists for the Drell–Hearn sum rule) has written a Lisp program REDUCE to automatize some actions in calculating Feynman diagrams. It quickly grew into a universal system. At first, it was distributed free (it was sufficient to ask for Hearn’s permission) and became widely used by physicists. Later it became commercial. At the end of 2008 it has become free, with a modified BSD license.

Macsyma was born in the MAC project at MIT (1969), the name means MAC SYmbolic MAnipulator. The project has nothing to do with Macintosh computers, which appeared much later. Its name had several official meanings (Multiple-Access Computer, Man And Computer, Machine Aided Cognition) and some unofficial ones (Man Against Computer, Moses And Company, Maniacs And Clowns, etc.). The work was done on a single PDP-6, later PDP-10 computer (about 1 MByte memory; there were no bytes back then, but 36-bit words). One of the first time-sharing operating systems, ITS, was written for this computer, and many users at once worked on it interactively. Later this computer became one of the first nodes of ARPANET, the ancestor if Internet, and users from other universities could use Macsyma.

The company Symbolics was spun off MIT. It produced Lisp machines—computers with a hardware support of Lisp, as well as software for these computers, including Macsyma—the largest Lisp program at that time. Later production of Lisp machines became unprofitable, because general-purpose workstations (Sun, etc.) became faster and cheaper. Symbolics went bankrupt; Macsyma business was continued by Macsyma Inc., who sold Macsyma for a number of platforms and operating systems. Its market share continued to shrink because of the success of Maple and Mathematica, and finally the company was sold in 1999 to Andrew Topping. The new owner stopped Macsyma development and marketing. Then he died, and the rights to the commercial Macsyma now belong to his inheritors. All efforts spent on improving this branch of Macsyma are irreversibly lost.

Fortunately, this was not the only branch. Macsyma development at MIT was largely funded by DOE, and MIT transferred this codebase to DOE who distributed it. This version was ported to several platforms. All these ports died except one. Professor William Schelter ported DOE Macsyma to Common Lisp, the new Lisp standard, and developed this version until he died in 2001. This version was called Maxima, to avoid trademark problems. In 1998 he obtained permission from DOE to release Maxima under GPL. He also developed GCL (GNU Common Lisp). Currently Maxima is an active free software project and works on many Common Lisp implementations.

Macsyma has played a huge role in the development of computer algebra systems. It was the first system in which modern algorithms for polynomials, integration in elementary functions, etc., were implemented (REDUCE and Macsyma influenced each other strongly and are rather similar to each other). Macsyma was designed as an interactive system. For example, if the form of an answer depends on the sign of a parameter, it will ask the user

Is a positive or negative?

Scratchpad was born in IBM research laboratories (1974). At first it did not differ from other systems (Macsyma, REDUCE) very much and borrowed chunks of code from them. It was radically redesigned in the version Scratchpad II (1985). And this design, perhaps, still remains the most beautiful one from a mathematical point of view. It is a strongly typed system (the only one among universal computer algebra systems). Any object (formula) in it belongs to some domain (e.g., it is a single-variable polynomial with integer coefficients). Each domain belongs to some category (e.g., it is a ring, or a commutative group, or a totally ordered set). New domains can be constructed from existing ones. For example, a matrix of elements belonging to any ring can be constructed. It is sufficient to program a matrix multiplication algorithm once. This algorithm calls the operations of addition and multiplication of the elements. If matrices of rational numbers are being multiplied, then addition and multiplication of rational numbers are called; and if matrices of polynomials—then addition and multiplication of polynomials.

Scratchpad was never distributed to end users by IBM. At last, IBM decided to stop wasting money for nought (or for basic research) and sold Scratchpad II to the English company NAG (famous for its numerical libraries). It marketed this system under the name Axiom. However, the product did not bring enough profit and was withdrawn in 2001. Axiom development took about 300 man-years of work of researchers having highest qualification. All this could easily disappear without a trace. Fortunately, one of old-time Scratchpad II developers at IBM, Tim Daly, has succeeded in convincing NAG to release Axiom under the modified BSD license. Now it is a free software project and still the most beautiful system from mathematical point of view. But unfortunately, due to incompatible visions of the directions of the future development, two forks appeared—OpenAxiom and FriCAS. And it is not clear which one is better.

muMATH (Soft Warehouse, Hawaii, 1979) got to the list of universal computer algebra systems with some stretch. It was written for microprocessor systems with a very limited memory (later called personal computers); mu in its name, of course, means μ, i.e.,  micro. This system never implemented advanced modern algorithms. It used heuristic methods instead, as taught in university calculus courses: let’s try this and that, and if you can’t get it, you can’t get it. But it was surprisingly powerful at its humble size. The system has been essentially rewritten in 1988 and got a menu interface, graphics, and the new name, Derive. Then Soft Warehouse was bought by Texas Instruments, who presented a calculator with a (Derive-based) computer algebra system in 1995. Derive was withdrawn from market in 2007.

All these systems can be referred to the first generation. They are all written in various dialects of Lisp. They were considered related to the area of artificial intelligence.

The first representative of the second generation is the Canadian system Maple. It has a small kernel written in C, which implements an interpreted procedural language convenient for writing computer algebra algorithms. The major part of its mathematical knowledge is contained in the library written in this language. Maple can work on many platforms. It quickly became popular. In 2009 Maplesoft (Waterloo Maple Inc.) has been acquired by the Japanese company Cybernet Systems Group; development of Maple is not affected. By the way, numerical program MathCAD used a cut-down version of Maple to provide some computer algebraic capabilities.

In the beginning of the 1980s, a young theoretical physicist Steven Wolfram, an active Macsyma user, together with a few colleagues, has written a system SMP (Symbolic Manipulation Program). The project was a failure (I still have a huge SMP manual sent to me by S. Wolfram). After that, he understood what mass users want—they want a program to look pretty. He, together with a few colleagues, has rewritten the system, paying a lot of attention to the GUI and graphics (the symbolic part was largely based on SMP). The result was Mathematica, version 1 (1988). And Wolfram got his first million in three months of selling it.

Mathematica heavily relies on substitutions. Even a procedure call is a substitution. Pattern matching and their replacing by right-hand sides of substitutions are highly advanced in Mathematica. Often a set of mathematical concepts can be easily and compactly implemented via substitutions. On the other hand, this can lead to inefficiency: pattern matching is expensive.

The latest arrival in the list of universal computer algebra systems is MuPAD (its name initially meant Multi-Processor Algebra Data tool, and indeed early versions contained experimental support of multiprocessor systems, which later disappeared). The system was designed and implemented by a research group at the University of Paderborn in Germany (this is one more meaning of PAD in the name) in 1992 and later was distributed commercially by the company SciFace. Initially, MuPAD was quite similar to Maple. Later it borrowed many ideas from Axiom (domains, categories; however, MuPAD is dynamically typed). During a long period, it was allowed to download and use MuPAD Light for free; it had no advanced GUI, but its symbolic functionality was not cut down. Funding of the University project was stopped in 2005; in 2008, SciFace was bought by Mathworks, the makers of MATLAB. After that, MuPAD is available only as a MATLAB addon.

It seems that Mathematica dominates the market of commercial computer algebra systems, with Maple being number two. Mathematica is highly respected for the huge amount of mathematical knowledge accumulated in its libraries. It is not bug-free (this is true for all systems). Often it requires more resources (memory, processor time) for solving a given problem than other systems. But it is very convenient and allows a user to do a lot in a single framework.

In addition to universal systems, there are a lot of specialized computer algebra systems. Here we’ll briefly discuss just one example important for theoretical physics.

In the 1960s, a well-known Dutch theoretical physicist M. Veltman, a future Nobel prize winner, has written a system Schoonschip in the assembly language of CDC-6000 computers (in Dutch Schoonschip means “to clean a ship,” in a figurative sense “to put something in order,” “to throw unneeded things overboard”). This system was designed for handling very long sums (millions of terms) whose size can be much larger than the main memory and is limited only by the available disk space. All operations save one are local: they are substitutions which replace a single term by several new ones. The system gets a number of terms from the disk, applies the substitution to them, and puts the results back to the disk. The only unavoidable nonlocal operation is collecting similar terms; it is done with advanced disk sorting algorithms. Built-in mathematical knowledge of the system is very limited; the user has to program everything from scratch. Many nontrivial algorithms, such as polynomial factorization, are highly nonlocal and impossible to implement. On the other hand, this was the only system which could work with very large expressions, orders of magnitude larger than in other systems. Later Schoonschip was ported to IBM-360 (in PL/I; you can guess that this was not done by Veltman:–). Then Veltman has rewritten it from the CDC assembly language to the 680x0 assembly language. When 680x0-based personal computers (Amiga, Atari) became extinct, it became clear that something similar but more portable is needed.

In 1989 another well-known Dutch theoretical physicist, Vermaseren, has written (in C) a new system, Form. It follows the same ideology, but many details differ. It was distributed free of charge as binaries for a number of platforms; recently it became free software (GPL). Development of Form continues. A parallel version for multiprocessor computers and for clusters with fast connections now exists. Many important Feynman diagram calculations could never have been done without Schoonschip and later Form.

The percentage of theoretical physicists among authors of computer algebra systems is suspiciously high. Some of them remained physicists (and even got a Nobel prize); some completely switched to development of their systems (and even became millionaires).

In conclusion we’ll discuss a couple of important computer algebra concepts. For some (sufficiently simple) classes of expressions an algorithm of reduction to a canonical form can be constructed. Two equal expressions reduce to the same canonical form. In particular, any expression equal to 0, in whatever form it is written, has the canonical form 0.

For example, it is easy to define a canonical form for polynomials of several variables with integer (or rational) coefficients: one has to expand all brackets and collect similar terms. What’s left is to agree upon an unambiguous order of terms, and we have a canonical form (this can be done in more than one way).

It is more difficult, but possible, to define a canonical form for rational expressions (ratios of polynomials). One has to expand all brackets and to bring the whole expression to a common denominator (collecting similar terms, of course). However, this is not sufficient: one can multiply both the numerator and the denominator by the same polynomial and obtain another form of the rational expression. It is necessary to cancel the greatest common divisor (gcd) of the numerator and the denominator. Calculating polynomial gcd’s is an algorithmic operation, but it can be computationally expensive. What’s left is to fix some minor details—an unambiguous order of terms in both the numerator and the denominator and, say, the requirement that the coefficient of the first term in the denominator is 1, and we obtain a canonical form.

A normal form for a class of expressions satisfies a weaker requirement: any expression equal to 0 must reduce to the normal form 0. For example, bringing to common denominator (without canceling gcd) defines a normal form for rational expressions.

For more general classes of expressions containing elementary functions, not only canonical but even normal form does not exist. Richardson has proved that it is algorithmically undecidable if such an expression is equal to 0.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_2© Springer International Publishing Switzerland 2014

2. Overview of Mathematica

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Let’s assign an expression containing a symbol x to a variable a. No value is assigned to x. $$\boldsymbol{\mathbf{In}[1]:= a = {x}^{\wedge }2 - 1}$$ $$\begin{array}{l} \text{Out}[1] = -1 + {x}^{2} \end{array}$$ Now let’s assign some value to x and see what happens to a. $$\boldsymbol{\mathbf{In}[2]:= x = z + 1;\;a}$$ $$\begin{array}{l} \text{Out}[2] = -1 + {(1 + z)}^{2} \end{array}$$ The value of a has not really changed. It is still the same expression containing x. What if we assign another value to x?

2.1 Symbols

Let’s assign an expression containing a symbol x to a variable a. No value is assigned to x.

Now let’s assign some value to x and see what happens to a.

The value of a has not really changed. It is still the same expression containing x. What if we assign another value to x?

We can delete the value of the variable x, thus returning it to its initial state in which it means just the symbol x. We see that indeed the value of a has not changed.

Now let’s try to assign an expression containing x to the variable x.

$RecursionLimit: : reclim: Recursion depth of 32 exceeded.

$$\begin{array}{l} \text{Out}[5] = 1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1+\end{array}$$ (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + Hold[1 + x])))))))))))))))))))))))))))))

Mathematica complains. What has happened? Mathematica wants to print x, and to this end it calculates the value of x. It sees x in this value and substitutes the value of x. In this value, it again sees x and substitutes its value. And so on ad infinitum. In reality, the depth of such substitutions is limited; the default value of the limit is 1,024 (we have temporarily changed it to 32). The value of the expression 1 + x which failed to evaluate is returned as the function Hold; we shall discuss it in Sect. 6.​9.

2.2 Numbers

Mathematica can work with arbitrarily long integer numbers.

When working with a rational number, the greatest common divisors of its numerator and denominator are canceled.

Calculations with rational numbers are exact.

How much is this numerically? Say, with 30 significant digits?

Mathematica can work with real (floating-point) numbers having arbitrarily high precision.

Here are π and $$\mathrm{e}$$ with 100 significant digits.

2.3 Polynomials and Rational Functions

Let’s take a polynomial.

Expand it.

The degree in x.

The coefficient of x ².

Collect terms with the same power of x together.

Factorize it.

Suppose we want to factorize polynomials x n  − 1 with various n. The parameter n can be varied from 2 to 10 by dragging the marker with the mouse.

There exists an algorithm which completely factorizes any polynomial with integer coefficients into factors which also have integer coefficients.

If we want to get factors whose coefficients come from an extension of the ring of integers, say, by the imaginary unit $$\mathrm{i}$$, we should say so explicitly.

This polynomial factorizes into two factors with integer coefficients.

If coefficients from the extension of the ring of integers by $$\sqrt{ 2}$$ are allowed—into three factors.

And if the ring of coefficients is extended by both $$\sqrt{ 2}$$ and $$\mathrm{i}$$—into four factors.

And this is a rational function.

It is not canceled by the greatest common divisor of its numerator and denominator; this should be done explicitly.

(% means the result of the previous calculation). A sum of rational functions.

Let’s put it over the common denominator.

Partial fraction decomposition with respect to x.

2.4 Elementary Functions

Mathematica knows some simple properties of elementary functions.

And why not x? Because this simplification is not always correct. Try to substitute $$2\pi \mathrm{i}$$.

And why not x? Try to substitute − 1.

This result can be improved, if we know that x > 0.

And this is the case x < 0.

Expansion of trigonometric functions of multiple angles, sums, and differences:

The inverse operation—transformation of products and powers of trigonometric functions into linear combinations of such functions—is used more often. Let’s take a truncated Fourier series.

Its square is again a truncated Fourier series.

2.5 Calculus

Let’s take a function.

Calculate its derivative.

Put over the common denominator.

A stupid integration algorithm would try to solve the fifth degree equation in the denominator, in order to decompose the integrand into partial fractions. Mathematica is more clever than that.

Let’s expand our function in x at 0 up to x ¹⁰.

Mathematica can calculate many definite integrals even when the corresponding indefinite integral cannot be taken. Here is an integral from 0 to 1.

Mathematica knows how to sum many series.

Let’s clear all the garbage we have generated—a very good habit.

2.6 Lists

We have already encountered this construct several times:

This is a list. And here are its elements.

2.7 Plots

A simple plot of a function.

A curve given parametrically—x and y are functions of t. This particular curve contains a parameter a, which can be adjusted by the mouse. If you click the small plus sign near the marker, a control panel will open. There you can start (and stop) animation.

A three-dimensional plot of a function of two variables. It can be rotated by the mouse.

A three-dimensional curve given parametrically. The parameter a can be adjusted by the mouse.

A surface given parametrically.

2.8 Substitutions

Substitutions are a fundamental concept in Mathematica, its main working instrument. This substitution replaces f[x] by x ².

Let’s apply it to the expression f[x].

We’ve got x ², as expected. And what if we apply it to f[y]?

It hasn’t triggered. The following substitution replaces the function f with an arbitrary argument by the square of this argument.

Let’s check.

2.9 Equations

Here is an equation.

Let’s solve it for x.

We’ve got a list of solutions, in this particular case having a single element. Each solution is a list of substitutions, which replaces our unknowns by the corresponding expressions. And how can we extract the value of x from this result? Let’s take the first (and the only) element of the list S.

And now we apply this list of substitutions (in this particular case, it’s single element) to the unknown x.

Here is a more advanced example—a quadratic equation. It has two solutions.

How can we extract the value of x in the second solution? Let’s apply the second element of the solutions list S (which is a single-element list of substitutions) to the unknown x.

And here is a system of 2 linear equations.

It has a single solution.

This (first and the only) solution is a list of two substitutions.

How to find the values of x and y in this solution? Apply this list of substitutions to the unknowns x and y.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_3© Springer International Publishing Switzerland 2014

3. Expressions

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

All objects with which Mathematica works are expressions. There are two classes of them—atoms and composite expressions.

All objects with which Mathematica works are expressions. There are two classes of them—atoms and composite expressions.

3.1 Atoms

There are three kinds of atoms—numbers, symbols, and strings.

Numbers

Integer numbers (of unlimited size).

A rational number consists of the numerator and the denominator.

A complex number consists of the real and imaginary parts.

Real numbers can have arbitrarily high precision.

Symbols

A variable can be in one of two states. Initially it is free—it means itself (a symbol).

Assigning a value to it, we make it bound.

Now, when we use it (e.g., just by asking Mathematica to print it), its value is substituted.

How to make it free again?

Let’s check.

Strings

3.2 Composite Expressions

A composite expression is a function of a number of arguments, each of which is an expression (i.e., an atom or a composite expression).

Each composite expression has a head—the function which is applied to arguments.

The number of arguments is given by the function Length.

Arguments are extracted by the function Part.

And this is the first part of the second part of the expression a.

An alternative syntax.

Zeroth part of an expression is its head.

By the way, a head can be any expression, not just a symbol.

Expressions are trees whose leaves are atoms.

Parts of an expressions can be changed.

A group of arguments can be selected, not just a single argument.

An alternative syntax.

From the beginning to 3:

From 4 to the end:

From 1 to 5 by 2:

If such a form is used in the left-hand side of an assignment, each of the selected arguments will be replaced:

3.3 Queries

Let’s define an integer number, a rational number, a real (floating point) number, and a complex number.

The query AtomQ (Q from Query) returns the symbol True if its argument is an atom and False if it is a composite expression.

The function Head can be applied even to atoms.

The function FullForm shows the internal form of an expression with which Mathematica operates (to some approximation). For example, a rational number has the head Rational and two arguments—its numerator and denominator.

A complex number has the head Complex and two arguments—its real and imaginary parts.

The internal representation of a floating point number is rather complicated. It contains the mantissa and the exponent and also the number of significant (decimal) digits. In this particular case, there are 37 significant digits.

The query IntegerQ checks if its argument is an integer number.

The functions Numerator and Denominator extract the parts of a rational number.

The functions Re and Im extract the real and imaginary parts of a complex number.

3.4 Forms of an Expression

FullForm is a very useful function. It shows what Mathematica really thinks about an expression. Use it often, and you will learn a lot. For example, the following expression is a sum of 4 terms, one of which is the number − 1 multiplied by the symbol z.

And this one is a product of 4 factors, among which are the rational number 2 ∕ 3 and the negative power z  − 1.

Nevertheless, the functions Numerator and Denominator work as expected.

We have already handled lists many times. A list appears to be just the function List with arguments—elements of the list.

Any Mathematica command can be written as a function with arguments (sometimes, it can also be written in some other way). For example, assignment is the function Set. In order to see this, we’ll have to put an assignment inside the function Hold. Otherwise it would be executed immediately, and the function FullForm would receive only the result returned by the assignment—the symbol x.

Here is a rational expression.

Its full form:

And this is the same expression as a tree.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_4© Springer International Publishing Switzerland 2014

4. Patterns and Substitutions

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Substitution is the most fundamental operation in Mathematica. Its left-hand side is a pattern. In a given expression, all subexpressions matching the pattern are found and replaced by the right-hand side of the substitution.

Substitution is the most fundamental operation in Mathematica. Its left-hand side is a pattern. In a given expression, all subexpressions matching the pattern are found and replaced by the right-hand side of the substitution.

4.1 Simple Patterns

f[x] with a specific argument x.

f with an arbitrary argument.

f with two identical (arbitrary) arguments.

An example of a more complicated pattern.

f with an argument being an arbitrary integer number.

In fact, such a form of an arbitrary argument checks its head. This substitution applies when the argument’s head is g.

And this one—when the argument is a sum.

And this one—when the argument is a list. By the way, note what happens when a list is being squared.

One more example.

Why hasn’t the second substitution triggered?

a does not contain y 1 ∕ 2, only y  − 1 ∕ 2; therefore, the substitution $${y}^{1/2} \rightarrow v$$ does not work.

4.2 One-Shot and Repeated Substitutions

Here is an expression.

Let’s increase x by 1 in it. This example demonstrates that a substitution is not applied repeatedly. Mathematica searches for subexpressions matching the pattern (in this case x) in the expression a. After finding such a subexpression, Mathematica replaces it by the right-hand side. The result of such a replacement is not searched again for subexpressions matching the pattern.

A list of substitutions can be applied to an expression. They are all applied in parallel—Mathematica searches for subexpressions matching some pattern from the list and replaces these subexpressions by the corresponding right-hand side. Therefore two symbols can be interchanged in an expression in this simple way.

The operator ∕ ∕ . (in contrast to $$/.$$) applies a substitution repeatedly, while it is applicable. If several substitutions are applicable to some subexpression, Mathematica first applies the most specific one (it is not always easy to determine which substitution is more specific and which is more general; in simple cases, this is clear).

By the way, what are the real names of ∕ . and ∕ ∕ . ?

4.3 Products

Let’s take a product.

The pattern x y is considered contained in this product, though the internal representation of a does not contain Times[x, y] explicitly.

And this product does not contain x y.

This product contains powers of x and y.

We want to replace each product of powers of x and y by the function f of these powers. Such a problem occurs very often. For example, we want to integrate some class of expressions, and we know the result of integration as a function of powers of some variables (or subexpressions).

This works OK. And here?

This doesn’t work. The product a does not contain a product of powers of x and y: the symbol y is not in the argument of the function Power. In the next example the substitution works again—as we have seen, Mathematica considers dividing by y as multiplying by y  − 1.

Let’s return to the previous expression. How can we instruct Mathematica to consider y as a particular case of the pattern “y to an arbitrary power”? This is what an optional arbitrary argument $$m\,{\_}\,.$$ is for. When it is used in an exponent, its default value (which is used when there is no power at all) is 1.

So far so good. But what if the symbol y is absent? Will Mathematica consider this as a particular case of the pattern “y to an arbitrary power” with the power equal 0? It will not.

The following method will work always. Let’s collect several test expressions to a list.

The method is as follows. Multiply our expression by f[0, 0], and apply a list of substitutions. If f with some arguments is multiplied by an arbitrary power of x, then the first argument of f is increased by this power. Of course, if x is not raised to any power, we want to use the default power equal to 1. Powers of y are treated in the same way. We need to use the repeated substitution $$//.$$—after one substitution from the list has been applied (e.g., the one about x), we want the other one to be applied to the result (to take y into account).

4.4 Sums

Substitutions for sums are similar to those for products. They are used much more rarely. Don’t use them if you can avoid this.

This substitution replaces a sum of x and y with arbitrary coefficients by the function f of these coefficients.

Here again an optional arbitrary argument can be used. When it is used as a factor, a subexpression is considered matching this pattern even if there is no such a factor, and its value in this case is taken to be 1.

And here is our method which always works.

4.5 Conditions

Substitutions which apply only when an arbitrary variable satisfies some condition are often needed.

But this method is not very general. It checks a condition depending on a single variable. The operator $$/;$$ can be applied to a pattern (or its part). It can be read as “such that.” The condition in it can depend on several arbitrary variables.

Internally, this operator is the function Condition.

One common case is when you want to replace f[x] by g[x] only for some values of x.

4.6 Variable Number of Arguments

A pattern can involve a construct which matches not a single subexpression but an arbitrary-length subsequence of arguments of a function. This is very convenient for working with functions having an arbitrary number of arguments. Let’s consider an example. The function f has any number of arguments. We want to shuffle them in the opposite order. First, let’s put a fence at the end of the argument list.

Now we take the arguments from the left one by one and throw them over the fence (placing them immediately after the fence).

Now the fence is at the left, and the arguments are after it in the opposite order. What’s left is to remove the fence.

Of course, this method only works when the symbol Fence is not present among the arguments. Here is the method which always works. Let the part of the arguments which has not yet been processed be in the first list and the processed part—in the second one. We take the arguments one by one from the beginning of the first list and move them to the beginning of the second one.

In addition to $$x\,{\_}\,{\_}\,{\_}$$ (with three underscores), which means an arbitrary subsequence of arguments of a function (maybe an empty one), there is also $$x\,{\_}\,{\_}$$ (with two underscores)—an arbitrary nonempty subsequence of arguments. I find the first construct more useful.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_5© Springer International Publishing Switzerland 2014

5. Functions

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

This is an ordinary (immediate) assignment. The result of calculation of the right-hand side (in this case, a quadratic polynomial) is assigned to the variable a.

5.1 Immediate and Delayed Assignment

This is an ordinary (immediate) assignment. The result of calculation of the right-hand side (in this case, a quadratic polynomial) is assigned to the variable a.

And this is a delayed assignment. The unevaluated right-hand side (in this case, an expression with the function Expand) is assigned to the variable b.

Note that a delayed assignment returns no value (an ordinary assignment returns the result of calculation of its right-hand side). The difference between a and b can be seen if we assign something to the variable x. In the first case, the value of x is substituted into the quadratic polynomial.

In the second case, the value of x is substituted into the expression with the function Expand, and then this expression is calculated.

The real name of the operator: = is SetDelayed.

Similarly, in addition to ordinary substitutions a − > b (where the right-hand side is calculated at the moment the substitution is defined), there are delayed substitutions a: > b (where the substitution keeps the right-hand side unevaluated, and it is calculated each time the substitution is applied).

5.2 Functions

Left-hand side of an assignment can be a pattern, not just a variable. In this case, in all subsequent calculations, any subexpression matching the pattern will be replaced by the right-hand side of the assignment. This can be canceled by the command Clear. A pattern can contain arbitrary variables. This is how functions are defined. Here is an example—a function f. In all subsequent calculations, all subexpressions of the form f[x] with arbitrary arguments x will be replaced by the right-hand side (in this case, a quadratic polynomial), in which the value of the actual argument is substituted for x.

And this is another function. Its body is an unevaluated expression with Expand. Expanding brackets will take place each time the function g with some argument is calculated.

Note the difference between them.

5.3 Functions Remembering Their Values

Let’s consider a useful trick—a function remembering its calculated values. If it is called again with the same argument, it will not perform calculations, but just return the remembered result. For example, take the factorial. We know fac[0].

And now attention—the main trick. A delayed assignment to the pattern $$\text{fac}[n\,{\_}]$$ (with an arbitrary n). And what do we have in the right-hand side? An immediate assignment to the pattern fac[n] (for a specific n, namely, the value of the actual argument with which the function fac was called). What happens when we call fac[10]? If the function was never calculated with this argument, then this definition for an arbitrary argument will be used. The right-hand side with 10 substituted for n will be calculated, namely, an immediate assignment fac[10] = ⋯. Its right-hand side is calculated (it is the factorial of 10), and it is remembered as the value of fac[10]. The immediate assignment returns the calculated value of its right-hand side, and this value becomes the result of the function call. If we ask Mathematica to calculate fac[10] again, then this specific definition for fac[10] (generated during the first calculation) will be used, and not the general definition for $$\text{fac}[n\,{\_}]$$.

What does Mathematica know about the symbol fac?

Only two definitions—for the argument 0 and for an arbitrary argument. Now let’s calculate the factorial of 10.

And what does Mathematica know about this symbol now?

In addition to the general definition, we see also specific ones for all integer values of the argument from 0 to 10. If we ask for the value of fac for one of these arguments, then the corresponding specific definition will be used, and the calculation will not be performed again.

5.4 Fibonacci Numbers

This method is useful but not vital for the factorial, because the time of calculation of fac[n] grows linearly with n. For Fibonacci numbers the difference is crucial. For a naive definition, the calculation time grows exponentially. This means you will never get a Fibonacci number with a large n. When results are remembered, the calculation time grows linearly—the result for each value of the argument from 2 to n is calculated once.

5.5 Functions from Expressions

In most cases, a delayed assignment is used when defining a function. But there are situations when an immediate assignment is needed. Here is one of them. Suppose you have derived an expression a containing a symbol x as a result of some calculation.

Now you want to calculate it many times with different values of x. This can be done by substitutions.

But this is not very convenient. It would be nice to have a function f with the argument x which is given by the calculated expression a. Such a function can be defined by an immediate assignment. The calculated value is substituted for a in the right-hand side.

5.6 Antisymmetric Functions

It is often useful to give a partial definition of a function. To this end we write not just a function with all arguments being arbitrary but a more restrictive pattern in the left-hand side of an assignment. Then, if the values of the actual arguments match the pattern, the function is calculated (i.e., replaced by the right-hand side of the assignment). Otherwise the function remains unevaluated. Here is a simple example. Let’s define an antisymmetric function of two arguments. If the arguments are equal, it vanishes.

If they are not equal, we have to decide if they need to be interchanged. The expressions f[x, y] and f[y, x] should reduce to either the first form or the second one, for any x and y. It does not matter to which form, as long as the result is always the same. To this end the function OrderedQ is useful. Its argument is a list. It returns True if the list is ordered, i.e., each element is “greater than or equal to” the previous one in the sense of some internal ordering Mathematica uses for expressions. Details of this ordering are not important.

Now it is easy to write a substitution which interchanges the arguments if they are not properly ordered.

Of course, a symmetric function can be defined similarly. An odd function of a single argument can be defined in the same way.

Of course, an even function can be defined similarly.

5.7 Functions with Options

You have undoubtedly noted that many Mathematica functions (e.g., Plot) have options. They can be specified in any order; each option is given by a substitution with its name in the left-hand side and its value in the right-hand side. If they are not given, their default values are used. Suppose you want your own function f to have options. This can be done in the following way. Let’s assign a list of substitutions giving default values of all options to Options[f]. Define the function f with some mandatory arguments and an arbitrary sequence of arguments $$\text{opts}\,{\_}\,{\_}\,{\_}$$ (it may be empty). At the point in the function body where you need the value of the option opt1 use opt1 ∕. {opts} ∕. Options[f]. The operations ∕. are executed left to right. Therefore, if the user has included a substitution opt1 → ⋯ among the arguments, the left ∕. will trigger, and the result will be some value which contains no option names; the right ∕. will not change it. If the user has not given such a substitution, the left ∕. will do nothing, and the right one will replace opt1 by the default value of this option.

In recent versions of Mathematica this can also be written as follows:

5.8 Attributes

A function can have attributes which affect simplification of expressions with this function. The attribute Flat removes nested function calls (e.g., Plus and Times have this attribute).

The attribute Orderless means that the function is symmetric in all arguments, and Mathematica may interchange them at will (Plus and Times have also this attribute).

The attribute Listable means that if the first argument is a list, then the function is applied to each element, and the list of results is returned (Plus and Times have this attribute, too).

There exist a few attributes more. Of course, a function can have several attributes at once. The command Clear[f] removes only substitutions for f (with any arguments), but not its attributes. In order to remove attributes too, use ClearAll.

5.9 Upvalues

Suppose we want to define a function f such that f[x] ∗ f[y] is replaced by f[x + y] for arbitrary x and y. This can be done by the assignment $$f[x\,{\_}] {\ast} f[y\,{\_}]:= f[x + y]$$. This definition will be associated with the function Times; Mathematica will have to check it each time it multiplies something, i.e., very often, and performance will degrade. It is possible to associate this definition with the function f instead. Then it will be used only when processing a product containing at least one function f.

Here the left-hand side is $$\text{Times}[f[x\,{\_}],f[y\,{\_}]]$$, and the definition is associated with f. If we want a definition for $$\text{Times}[f[x\,{\_}],g[y\,{\_}]]$$, we can associate it with either f or g. $$\boldsymbol{\mathbf{In}[59]:= f/: f[x\,{\_}] {\ast} g[y\,{\_}]:= f[\mathbf{Expand}[x - y]]}$$

When processing an expression $$f[\text{g1}[\ldots ],\text{g2}[\ldots ],\text{g3}[\ldots ]]$$, Mathematica uses definitions associated with f and also definitions associated with g1, g2, g3, and having the form f[…]: = ⋯ (upvalues of g1, g2, g3). It does not look deeper, into arguments of g1, g2, and g3—this would be too inefficient. In addition to the delayed assignments ∧: = and f ∕ : lhs: = rhs there are also immediate assignments ∧ = and f ∕ : lhs = rhs.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_6© Springer International Publishing Switzerland 2014

6.  Mathematica as a Programming Language

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

A compound expression consists of several expressions separated by the operator ;. They are calculated left to right. The value of a compound expression is the value of the last (rightmost) expression. The values of all the other expressions are thrown away; they are calculated only for side effects. The operator ; has a low priority, so that it is often necessary to put a compound expression inside brackets. The last expression may be empty. Its value (and hence the value of the compound expression) is the symbol Null which is not printed. Therefore, if you want to suppress printing of the result of some calculation (e.g., because it is lengthy), put ; after it.

6.1 Compound Expressions

A compound expression consists of several expressions separated by the operator ;. They are calculated left to right. The value of a compound expression is the value of the last (rightmost) expression. The values of all the other expressions are thrown away; they are calculated only for side effects. The operator ; has a low priority, so that it is often necessary to put a compound expression inside brackets. The last expression may be empty. Its value (and hence the value of the compound expression) is the symbol Null which is not printed. Therefore, if you want to suppress printing of the result of some calculation (e.g., because it is lengthy), put ; after it.

6.2 Conditional Expressions

If

When Mathematica cannot determine if the condition is true, a conditional expression is returned unevaluated. If such a possibility will appear later, an unevaluated If will be simplified.

And what to do if several actions should be performed in the branches of If? Use compound expressions, of course! The priority of the operator; is higher than that of, (which separates function arguments, in particular, those of If).

Which

This is a choice with many branches. Arguments of the function Which form pairs: a condition and a result. The conditions are evaluated left to right. As soon as a true one is found, the corresponding result is evaluated and returned. Often (but not always) the last condition is True; the corresponding result is returned when none of the previous conditions is satisfied. When Mathematica cannot decide if the conditions are true, the function Which returns unevaluated.

Conditions

What can be used as conditions in If and Which? The operator = = returns True if its left-hand side and right-hand side are the same expression. Let’s stress: mathematically equivalent expressions written in different forms don’t qualify. If the left-hand side and the right-hand one are not identical, this operator returns unevaluated. It is used for writing equations, for example, for the function Solve.

In contrast to this, the operator = = = returns False if its arguments are not identical (even if they are mathematically equivalent).

$$\text{Not}[a == b]$$ is written as a! = b, and $$\text{Not}[a === b]$$ as a = ! = b.

The function NumberQ checks if its argument is a number (integer, rational, real, complex).

The function NumericQ returns True also for symbolic mathematical constants.

The function FreeQ returns True if its first argument contains no subexpressions given by the second argument. It is often used to check if an expression contains a given symbol.

The function MatchQ checks if the expression—its first argument— matches the pattern, its second argument. When designing a system of substitutions, use this function often in order to check if your ideas about the structure of expressions agree with those of Mathematica.

Switch

The function Switch starts from evaluating its first argument. All the remaining arguments form couples: a pattern and a result. The first argument is matched against the patterns from left to right. As soon as a match is found, the corresponding result is evaluated and returned. Often (but not always) the last pattern is x _ (or just _ because we don’t need the value of x).

6.3 Loops

Do

This loop is very convenient to those pupils who were ordered by a teacher to write “I shall behave well” 100 times.

In this loop the parameter varies from 1 to an upper limit.

And here—from a lower limit to an upper one.

And now with a given step.

This loop takes the elements of a list.

While

While the list is not empty, we print and remove its first element.

For

This is a C style loop. First the initialization (the first argument) is executed. If the condition (the second argument) is satisfied, then the loop body (the fourth argument) is executed. Then the increment (the third argument) is performed. The condition is checked again, and so on.

A loop running through several parameters (or data structures) in parallel can be easily written.

6.4 Functions

The function Function returns an anonymous function. Its first argument is a formal parameter (or a list of formal parameters), and the second one is an expression containing these formal parameters. When the function is called, the actual parameters are substituted for the formal ones in this expression, and the result of its evaluation is returned as the value of the function. A note for experts: the function Function is a λ-expression. Of course, an anonymous function can be assigned to a variable. This is similar to a function defined by f[x _]: = ⋯, but more efficient. The usual method of assigning a function body to a pattern is more general, because it is possible to construct a function which is defined only for arguments which satisfy some condition (such a function returns unevaluated if the conditions are not satisfied). This is not possible in the case of Function.

An anonymous function can be just applied to some arguments.

The function Map applies the function given by its first argument to each element of the list given by the second argument and returns the list of results.

An anonymous function can be the first argument of Map. Any function with arguments (e.g., Plus) can be the second argument, not just a list. The function given by the first argument is applied to each argument of the expression—the second argument. An expression having the same Head (as the second argument) and the calculated results is constructed and returned.

The function Apply[f, l] applies f to the list of arguments l; this simply means that the Head of l is replaced by f.

The first argument of the function Select is a list. It returns the list of those elements which satisfy the condition given by the second argument. In order to avoid inventing names for such disposable things, anonymous functions are often used as the second argument.

Function Generator

Here’s an interesting example. The function Adder has a formal parameter n and returns a function which adds n to its argument, that is, Adder is a function generator.

Specific functions can be obtained from it. This one, for example, adds 2 to its argument.

6.5 Local Variables

When writing a function which can be used as a black box by a user, it is crucial to use local variables. Assigning a value to a local variable does not change the global one with the same name (which can store some value precious for the user). To this end the function Module is used. Its first argument is a list of local variables.

Coding functions like this means inviting big troubles.

This is much better.

What happens if a local variable escapes from its scope? We can see that Mathematica implements local variables in the most trivial way—by renaming.

The function Block introduces another kind of local variables. As you value your life or your reason keep away from the function Block. Especially in those dark hours when the powers of evil are exalted.

Local Constants

Local variables which cannot be changed after initialization can be introduced. This is done by the function With. Such local constants can be considered temporary notations introduced to make writing a single expression easier.

6.6 Table

The function Table constructs a list of values of an expression where a parameter varies in a given way (like in the Do loop).

Let’s turn the list into a product.

6.7 Parallelization

Now most computers have multi-core processors. The function Parallelize tries to calculate its argument faster by starting several Mathematica kernels and ordering them to calculate parts of the expression and then collecting these parts together.

($KernelID is the number of the kernel in which a particular list element has been evaluated). In addition to Table, it can handle Map[f, {…}] (orf[{…}] where f is a Listable function) and some other cases. Note that the slave Mathematica kernels started by Parallelize don’t know definitions made in the master process; only built-in functions can be used. If you need a user-defined function f to be available in slave processes, you should explicitly distribute it.

6.8 Functions with an Index

Something like an array of functions can be constructed. Let f[1] be the function adding 1 to its argument and f[2]—the function adding 2 to its argument; f[n] is undefined for other values of n.

6.9 Hold and Evaluate

Assignment

Assignment does not evaluate its left-hand side. This is natural: the value of the right-hand side is assigned to the variable given by the left-hand side, not to its value.

The attribute HoldFirst is responsible for this.

Evaluate

It is possible to assign a value to the value of the left-hand side. To this end the function Evaluate is used.

Delayed Assignment

Delayed assignment does not evaluate also its right-hand side. The attribute HoldAll is responsible for this.

You can use these attributes for your functions, too.

The First Argument of the Function Plot

The function Plot does not evaluate its arguments.

The first argument f[x] can be meaningful only for numerical values of x, not for symbolic x. Therefore it is better not to evaluate f[x] before the function Plot will call it for numerical values of x. But if the first argument is a command which generates the list of expressions to draw, it will not work. We want the command to be executed; to this end Evaluate is used.

Hold

The function Hold suppresses evaluation of its argument.

This suppression can be removed by the function ReleaseHold.

The function Hold is simple—it has the attribute HoldAll, i.e., it does not evaluate its arguments.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_7© Springer International Publishing Switzerland 2014

7. Gröbner Bases

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

In this lecture we shall consider (in a slightly vulgarized form, without rigorous mathematical terms) an important mathematical achievement of the second half of the last century—Gröbner bases, the Buchberger algorithm (which constructs them), and their applications (see [12, 13] for an introduction).

7.1 Statement of the Problem

In this lecture we shall consider (in a slightly vulgarized form, without rigorous mathematical terms) an important mathematical achievement of the second half of the last century—Gröbner bases, the Buchberger algorithm (which constructs them), and their applications (see [12, 13] for an introduction).

Suppose we have n variables x ₁, …, x n . They are not independent, but satisfy some polynomial equations p ₁ = 0, …, p m  = 0 (p j are polynomials of x i ). Let’s consider some polynomial q of the same variables. It is natural to ask if this polynomial is equal to 0 due to the constraints on our variables or not. If there is another polynomial q ₂, there is the question of their equality.

These questions would become very easy if we had an algorithm reducing polynomials of dependent variables to a canonical form. Two equal polynomials reduce to the same canonical form; a polynomial equal to 0 reduces to the canonical form 0.

We can try to use the equations p j  = 0 for simplifying the polynomial q, i.e.,  for replacing its more complicated terms by combinations of simpler ones. But to do so we first have to accept some convention in which terms are more complicated and which are more simple.

7.2 Monomial Orders

We need a total order of monomials (i.e.,  products of powers of the variables $$x_{1}^{n_{1}}\cdots x_{n}^{n_{n}}$$). An order is total if for any monomials s and t either s < t or s > t or s = t is true. An order is admissible if two properties are satisfied:

$$1 \leqslant s$$ for any monomial s.

If s < t then s u < t u for any monomial u.

Three admissible orders are most popular.

Lexicographic

Anybody who has ever seen a dictionary knows what is lexicographic order. We are comparing two monomials: $$s = x_{1}^{n_{1}}x_{2}^{n_{2}}\cdots x_{n}^{n_{n}}$$ and $$t = x_{1}^{m_{1}}x_{2}^{m_{2}}\cdots x_{n}^{m_{n}}$$. If the degree of the main variable x ₁ in s is larger than in t ($$n_{1} > m_{1}$$), then s > t. If it is smaller ($$n_{1} < m_{1}$$), then s < t. If $$n_{1} = m_{1}$$, we compare the degrees of the next variable x ₂: if $$n_{2} > m_{2}$$, then s > t; if $$n_{2} < m_{2}$$, then s < t; if $$n_{2} = m_{2}$$, we compare the degrees of x ₃; and so on.

By Total Degree than Lexicographic

First we compare the total degree $$n = n_{1} + n_{2} + \cdots + n_{n}$$ of the monomial s and the total degree $$m = m_{1} + m_{2} + \cdots + m_{n}$$ of the monomial t. If n > m then s > t; if n < m then s < t; if the total degrees are equal, we compare s and t lexicographically.

By Total Degree than Reverse Lexicographic

First we compare the total degrees. If they are equal, then we begin from the junior variable x n : if its degree in s is larger than in t ($$n_{n} > m_{n}$$), then s < t; if it is smaller ($$n_{n} < m_{n}$$), then s > t; if $$n_{n} = m_{n}$$, we compare the degrees of the previous variable $$x_{n-1}$$; and so on, that is,  this is (within some total degree) the reverse lexicographic order with respect to the reverse list of variables.

7.3 Reduction of Polynomials

Let’s fix some admissible monomial order. We’ll write polynomials in descending order: the leading term first, followed by the rest ones. We’ll normalize all polynomials p i in such a way that the coefficient of the leading term is 1. Now they can be used as substitutions which replace the leading term by minus sum of the remaining ones, that is,  if some term of a polynomial q is divisible by the leading term of some polynomial p i , we remove this leading term and insert minus sum of the remainder terms of p i instead. This is called reduction of the polynomial q with respect to the set of polynomials p i ; if none of the substitutions is applicable, the polynomial q is called reduced. For example, let’s consider a set of polynomials

Let’s try to reduce the polynomial

(we use the lexicographic order with x > y). This can be done in different ways. Let’s first reduce q with respect to $$p_{1}$$:

The result means that if we subtract the polynomial p ₁ multiplied by y from q, then the reduced polynomial $$y - {y}^{3}$$ is obtained. This is what we are interested in.

Now let’s reduce q with respect to p ₂:

So, we have obtained two different results, q ₁ and q ₂. In fact they are equal due to p ₁ = 0 and p ₂ = 0, but this is not evident. Every time when more than one substitution can be applied to a term of a polynomial q (in this particular case, we can replace either x ² or x y in x ² y), a fork appears; maybe, its branches join later, but maybe, they don’t (as in this case).

A set of polynomials p ₁, …, p n is called a Gröbner basis (for a given monomial order) if reduction of any polynomial q with respect to this set is unique.

This definition is not constructive: it does not say how to check if a given set of polynomials forms a Gröbner basis. Presently we shall formulate Buchberger algorithm which transforms a set of polynomials (constraints on variables) into an equivalent system of constraints which is a Gröbner basis.

7.4 S-Polynomials

In our example, the constraints p ₁ = 0 and p ₂ = 0 allow us to simplify the monomials x ² and x y. Do these constraints contain an extra information usable for simplification but not obvious? Yes, they do! Let’s multiply p ₁ and p ₂ by monomials (i.e.,  products of powers of variables) in such a way that their leading terms become identical (equal to the least common multiple of the leading terms of p ₁ and p ₂). Then we subtract the second polynomial from the first one. The leading terms cancel, and we get a new polynomial with a new leading term which can be used for simplifying terms in q (because this new polynomial also vanishes). This polynomial is called the S-polynomial $$S\left [p_{1},p_{2}\right ]$$ (from the word subtraction). In our example

This polynomial can be added to the system of constraints p ₁ = 0, p ₂ = 0. Let’s normalize its leading coefficient to 1:

Now we have a new possibility for reduction:

Now we’ve got the same result q ₁. The polynomials $$\left \{p_{1},p_{2},p_{3}\right \}$$ form a Gröbner basis. This set can be simplified by reducing them with respect to each other:

The polynomial p 1a reduces to 0, and hence it can be excluded from the system of constraints on our variables x, y. The polynomials p 2a and p ₃ form a reduced Gröbner basis (with respect to the lexicographic order with x > y). Reduced Gröbner basis is unique (for a given monomial order), if we accept the convention that the coefficients of the leading terms are 1.

7.5 Buchberger Algorithm

Generalizing this example, we can formulate an algorithm for construction of the Gröbner basis of a set of n polynomials $$P = \left \{p_{i}\right \}$$:

1.

2.

while S is not empty

3.

choose and remove some pair $$\left (p_{i},p_{j}\right )$$ from S;

4.

calculate the S-polynomial $$S\left [p_{i},p_{j}\right ]$$;

5.

reduce it with respect to P;

6.

if the result is not 0, add this polynomial to P, and the corresponding pairs to S.

The set of pairs S alternatingly shrinks and grows. But it can be proved that this process terminates after a finite number of steps and produces a Gröbner basis P. Reducing these polynomials with respect to each other and throwing zeros away, one can get the reduced Gröbner basis. Some variations can improve the efficiency of the algorithm. For example, when adding a new polynomial to the set P, we can reduce all polynomials already in P with respect to the new one; if some of them changes, reduce other ones with respect to them, and so on (throwing zeros away while doing so). The order in which pairs are selected from the set S is very important—a good choice can reduce the amount of computations drastically.

Let’s ask Mathematica to construct the Gröbner basis for the system $$\left \{p_{1},p_{2}\right \}$$ with respect to the lexicographic order with x > y:

Let’s reduce the polynomial q to the canonical form, i.e., reduce it with respect to the Gröbner basis (the result is unique).

It is difficult to predict the complexity of the Buchberger algorithm. In worst cases it can be very high, i.e., constructing the Gröbner basis of a moderately large system can require a huge amount of calculations. The complexity strongly depends on the monomial order being used. In the case of ordering by the total degree (and then something) reduction tries to lower the total degree of a polynomial. The number of possible terms in a polynomial of a low total degree is small. In the case of the lexicographic order, a polynomial of y of an arbitrarily large degree is considered simpler than x to the first power. Therefore reduction does not lower the number of terms in a polynomial as strongly as in the case of total-degree orders, and the complexity of Gröbner basis calculations is higher. On the other hand, a reduced Gröbner basis with respect to a lexicographic order provides more information useful for solving the system, as we shall see soon. Mathematica knows how to construct Gröbner bases with respect to monomial orders we discussed.

7.6 Is the System Compatible?

Consider the system

Let’s construct its Gröbner basis—an equivalent system of equations.

This system contains the equation 1 = 0. This means that it has no solutions. If the Gröbner basis contains 1, the system is incompatible. The inverse statement can be also proved—the Gröbner basis of an incompatible system always contains 1 (if we normalize all leading coefficients to 1; otherwise, just some nonzero constant).

7.7 Gröbner Bases with Respect to Lexicographic Order

Reduction with respect to the lexicographic order first of all tries to lower the degree of the main variable (x in our examples), and if possible, down to 0. Therefore usually there is a subset of polynomials in a reduced Gröbner bases which don’t contain x. When x is absent, reduction tries to lower the degree of y, and if possible, down to 0. Therefore usually among these polynomials there are those which don’t contain y, and so on. In other words, a lexicographic Gröbner bases has a triangular structure. For example,

The polynomial

depends only on the most junior variable z. This means that projections of all solutions of our system on the z axis form a finite set of points—roots of this equation. In our example, they are z = 0 and

Substituting any of these z values to

we find the corresponding y value. Substituting these z and y into

we find the corresponding x value. Thus solving any system of polynomial equations with several unknowns reduces to solving single-variable polynomial equations sequentially, thanks to lexicographic Gröbner bases. Even when some of them cannot be solved in radicals, it is easy to solve them numerically to any desired precision.

And here is another example.

Now we have no equations with a single variable z; there are 2 equations containing z and y:

The common set of their solutions is the circle $${y}^{2} + {z}^{2} = 1$$. Substituting a point on this circle into

we find the corresponding x value, that is,  the set of solutions of this system is one-dimensional.

For solving a system of polynomial equations it is useful to construct its Gröbner basis and then to factorize its elements.

7.8 Is the Number of Solutions Finite?

Gröbner bases with respect to other monomial orders don’t have such simple triangular structure. But any Gröbner basis can tell us not only if the system is compatible but also if the number of its solutions is finite. Let’s consider the same examples.

The leading terms of the polynomials forming this basis are x, z ², and y ². What is the dimensionality of the space of polynomials which cannot be reduced with respect to this basis? Only monomials which are not divisible by these leading terms cannot be reduced, namely, 1, y, and z. So the space of polynomials reduced to the canonical form is three-dimensional for our system of constraints on the variables. Therefore our system has 3 solutions (there explicit form can be obtained more easily from the lexicographic Gröbner basis, as we have seen).

If each variable raised to some power is the leading term of some element of a Gröbner basis, then any monomials with this (or higher) degree of this variable are reducible. Irreducible monomials are inside the parallelepiped bounded by these powers, and their number is finite. Therefore the space of polynomials reduced to the canonical form is finite-dimensional, and the system has a finite number of solutions.

And here is our second example:

The leading terms are $$x\,z$$, x y, x ², y ² z, and y ³. Among them there are powers of x and of y, but not of z. Therefore the space of polynomials in the canonical form (i.e.,  reduced with respect to this basis) is infinite-dimensional. This space contains, e.g., the directions 1, z, z ², z ³… (and not only them). This means that the set of solutions of our system is infinite.

So, the criterion works in the opposite direction, too. If there exists a variable no power of which appears as the leading term of some element of the Gröbner basis (not being multiplied by some other variable), then all powers of this variable are irreducible, and the space of polynomials in the canonical form is infinite-dimensional. And hence the set of solutions of the equation system is infinite.

Knowing the reduced Gröbner basis (for any monomial order) one can also find the dimensionality of the set of solutions [14]. Consider sets of variables satisfying the following condition: none of the leading terms of the elements of the basis is a product of powers of these variables. The number of variables in the longest set gives the dimensionality of the set of solutions. In our example there is just one such set—{z}. Therefore the set of solutions of this system is one-dimensional.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7.​ Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_8© Springer International Publishing Switzerland 2014

8. Calculus

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Let’s expand a function in x at the point x = 0 up to the fifth order.

8.1 Series

Let’s expand a function in x at the point x = 0 up to the fifth order.

How are series represented in Mathematica? By the function SeriesData. Its first argument is the expansion variable; the second one—the expansion point; the third one—the list of coefficients; the fourth one—the minimum degree (here 0); the fifth one—the power of O[x]; the sixth one is 1 for series with integer degrees (all degrees are divided by it if it’s not 1). Thus a series is not a sum (Plus) in spite of its appearance.

Coefficients are extracted by the function SeriesCoefficient.

This series begins with degree − 1.

This is a series with half-integer degrees.

This is an expansion at infinity.

Coefficients of a series in x may depend on x, but only weakly, weaker than any degree.

Operations with Series

Let’s take three series.

Series can be added, multiplied, divided, etc.

If a series occurs as an argument of a function, the function is expanded automatically.

Here is an interesting method to expand a function in x.

Series can be differentiated and integrated.

A series (beginning from a small term) can be substituted for the expansion variable of another series. This is Sin[Tan[x]].

An alternative syntax.

Let’s subtract Tan[Sin[x]]; this expression is expanded automatically, i.e., series are contagious.

Series inversion—solving the equation tanx = y for x as a series in y.

The result should be the arctangent.

It is not allowed to substitute a numerical value for the expansion variable into a series. The function Normal converts a series into a normal expression by dropping + O[x] n . Here is a plot of sine and a few truncations of its series.

You should work with series as long as possible, converting them into normal polynomials only at the very end. Then terms of too high orders of smallness are dropped automatically. At any moment you know exactly what is the order of the neglected term O[x] n .

Arbitrary-Order Term

The function SeriesCoefficient can also be used in this way.

This is the 4th coefficient in the expansion of Exp[x] in x at 0. The number of the series term can be given symbolically.

8.2 Differentiation

The derivative in x; in y; in x and y; the second derivative in x; the second derivative in x and the first one in y:

Unknown Functions

Expressions with unknown functions can be differentiated.

Mathematica represents the first derivative of an unknown function f as the operator Derivative[1] applied to f.

And this is the second derivative.

Derivative[2, 3] means the second derivative in the first argument and the third one in the second.

Defining Derivatives

Let’s tell Mathematica that the derivative of the function f is g.

The second derivative is not substituted automatically.

we can tell Mathematica that $$\frac{\partial^3 f[x,y]}{\partial x\, \partial^2 y}$$ is a function g.

8.3 Integration

Indefinite Integrals

Definite Integrals

Here Mathematica produces a result with some assumptions about the parameter n.

Let’s tell it that n >  − 1.

The default value of the option Assumptions for Simplify, Integrate, etc. can be given in the variable $Assumptions.

Now we can clear $Assumptions.

Multiple integral

8.4 Summation

Series

8.5 Differentiol Equations

A first-order differential equation.

The solution contains an arbitrary constant C[1]. Let’s add an initial condition:

A second-order differential equation.

Initial conditions.

Boundary conditions.

A system of differential equations.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_9© Springer International Publishing Switzerland 2014

9. Numerical Calculations

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Mathematica usually works with exact numbers, either symbolic (π, e) or rational, and derives exact analytical results. However, it can also perform approximate numerical calculations. Many problems cannot be solved analytically, but numerical solution is possible. On the other side, an analytical result can depend on symbolic parameters; in order to do a numerical calculation, you have to substitute some numerical values for all parameters. It is often useful to check the correctness of a complicated analytical derivation by a direct numerical calculation for a few sets of values of the parameters.

9.1 Approximate Numbers in Mathematica

Mathematica usually works with exact numbers, either symbolic (π, e) or rational, and derives exact analytical results. However, it can also perform approximate numerical calculations. Many problems cannot be solved analytically, but numerical solution is possible. On the other side, an analytical result can depend on symbolic parameters; in order to do a numerical calculation, you have to substitute some numerical values for all parameters. It is often useful to check the correctness of a complicated analytical derivation by a direct numerical calculation for a few sets of values of the parameters.

There are two kinds of approximate real numbers in Mathematica. The first one is machine numbers.

Precision is the number of significant decimal digits. For machine numbers it is a symbolic constant:

It is 53 bits (or about 16 decimal digits) of precision. In other languages (C, Fortran) such numbers are usually called double precision. Operations with such numbers in Mathematica are performed by hardware, as in C or Fortran. They are less efficient than in these languages, but nevertheless rather efficient.

There are also arbitrary-precision numbers. Operations with them are implemented in software and are far less efficient.

Precision is a part of a value, not of a variable, as in some other languages. If it is equal to n, then the estimated relative error of the value is 10 − n . There is also accuracy—the number of significant decimal digits after the point. If it is equal to m, then the estimated absolute error of the value is 10 − m .

When approximate numbers are added or subtracted, the absolute errors are added. The difference of two approximately equal numbers has a lower precision than the operands.

When approximate numbers are multiplied or divided, the relative errors are added.

This error handling sometimes may be too pessimistic. Let’s consider an example [15]. The sequence $$x_{n} = f\left (x_{n-1}\right )$$, x ₁ = 1,

converges to 2. With machine numbers

this is indeed so. Now let x ₁ be 1.0 with 17-digits precision:

The tail of this list is

The initial precision is completely lost in 58 iterations.

9.2 Solving Equations

NSolve tries to solve equations numerically. They must not contain symbolic parameters, only numbers and unknowns. Only very limited classes of equations can be solved analytically; numerical solution is possible nearly always. The option Reals says to find only real roots.

We can add an interval in which we want to find solutions.

9.3 Numerical Integration and Summation

The function NIntegrate integrates numerically, without trying to do it analytically first—it uses an appropriate numerical method right away. Of course, integration limits must be numbers, and there must be no symbolic parameters.

The option PrecisionGoal states the desired precision of the result. If the result is close to 0 due to strong cancellations, it may be difficult to attain a high precision (i.e., a small relative error). Then it is better to specify AccuracyGoal, i.e., the desired absolute error. The option WorkingPrecision specifies the precision level at which internal calculations are done; it must be $$\geqslant \text{PrecisionGoal}$$.

The integration method is selected automatically; however, we can specify it:

Suppose we suspect that the integral i is a linear combination of ζ(3) and 1 with rational coefficients. FindIntegerNullVector tries to find integer coefficients such that the linear combination vanishes:

This means that $$2\,i - 3\,\zeta (3) = 0$$, i.e., our integral is $$\frac{3} {2}\,\zeta (3)$$. Of course, this is not a mathematical proof. However, if we increase precision, and the linear combination stays the same, we can be practically sure that the result is correct (this is called experimental mathematics).

NSum is similar.

If we suspect that the sum s is a linear combination of π ⁴ and 1 with rational coefficients, we can do

This means that our sum is, probably, $$\frac{{\pi }^{4}} {90}$$.

9.4 Differential Equations

NDSolve solves differential equations numerically, for a finite interval of the independent variable. It returns results in terms of InterpolatingFunction; this result can be numerically evaluated for any value of the independent variable in the given interval.

Let’s compare with the analytical solution.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_10© Springer International Publishing Switzerland 2014

10. Risch Algorithm

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

We were taught at calculus classes that integration is an art, not a science (in contrast to differentiation—even a monkey can be trained to take derivatives). And we were taught wrong. The Risch algorithm (which is known for decades) allows one to find, in a finite number of steps, if a given indefinite integral can be taken in elementary functions, and if so, to calculate it. This algorithm has been constructed in works by an American mathematician Risch near 1970; many cases were not analyzed completely in these works and were later considered by other mathematicians. The algorithm is very complicated, and no computer algebra system implements it fully. Its implementation in Mathematica is rather complete, even with extensions to some classes of special functions, but details are not publicly known. Strictly speaking, it is not quite an algorithm, because it contains algorithmically unsolvable subproblems, such as finding out if a given combination of elementary functions vanishes. But in practice computer algebra systems are quite good in solving such problems. Here we shall consider, at a very elementary level, the main ideas of the Risch algorithm; see [16] for more details.

We were taught at calculus classes that integration is an art, not a science (in contrast to differentiation—even a monkey can be trained to take derivatives). And we were taught wrong. The Risch algorithm (which is known for decades) allows one to find, in a finite number of steps, if a given indefinite integral can be taken in elementary functions, and if so, to calculate it. This algorithm has been constructed in works by an American mathematician Risch near 1970; many cases were not analyzed completely in these works and were later considered by other mathematicians. The algorithm is very complicated, and no computer algebra system implements it fully. Its implementation in Mathematica is rather complete, even with extensions to some classes of special functions, but details are not publicly known. Strictly speaking, it is not quite an algorithm, because it contains algorithmically unsolvable subproblems, such as finding out if a given combination of elementary functions vanishes. But in practice computer algebra systems are quite good in solving such problems. Here we shall consider, at a very elementary level, the main ideas of the Risch algorithm; see [16] for more details.

10.1 Rational Functions

We begin with a very simple case—integration of rational functions. Better methods than the partial fraction decomposition exist for this problem. And these methods can be generalized to much wider classes of integrands. Let’s consider an integral

where N(x) and D(x) are polynomials. If deg N ≥ deg D, we can divide with remainder; integration of a polynomial is trivial. Therefore we’ll assume deg N < deg D. The integration result consists of a rational part and a logarithmic one:

where a i are the roots of the denominator D(x), and c i are constants. If

then

Indeed, at x → a i the rational part has a pole of the order d i  − 1; when differentiated, it becomes a pole of the order d i , as needed. The numerator P(x) is a polynomial of degree $$\deg P <\deg \hat{ D}$$:

Substituting all these parts and differentiating, we can find the unknown coefficients c i and p n by solving a linear system.

For example, let’s calculate

10.2 Logarithmic Extension

Now we begin to extend the class of integrands and consider

where y depends on x (in a nonrational way). The extension is called algebraic if y is a root of a polynomial equation p(x, y) = 0. For example, $$y = \root{n}\of{p(x)/q(x)}$$ is a root of the equation $$q(x){y}^{n} - p(x) = 0$$. An algorithm for integration of expressions belonging to algebraic extensions has been constructed, but it requires an advanced mathematical apparatus [17], and we shall not discuss it here.

Extensions which are not algebraic are called transcendental. There are two important classes of such extensions. A logarithmic extension $$y =\log r(x)$$ (where r(x) is a rational function) is characterized by the property $$y^{\prime} = r^{\prime}/r$$. An exponential extension y = expr(x)—by y′ = r′ y.

If an integral of an expression from a logarithmic extension with some $$y =\log r(x)$$ can be taken in elementary functions, it has the form

where

q i are the irreducible factors of all D i , c i are constants,

is a polynomial with unknown (so far) coefficients. Differentiating this general form of the result, putting everything over a common denominator, and equating coefficients of $${x}^{m}{y}^{n}$$, we obtain a linear system for finding all unknown coefficients. If this system is incompatible, this means that the integral cannot be taken in elementary functions.

Example 1

We shall consider several examples. Let $$y =\log x$$ so that $$y^{\prime} = 1/x$$. Let’s calculate the integral

When differentiated, the degree in y reduces by 1, so that the result is quadratic in y (there is no denominator, and hence no q i ).

We see that $$p_{2}(x)$$ is a constant:

Since $$p_{1}(x)$$ is a polynomial, the second equation can be satisfied only if p ₂₀ = 0:

The second equation gives

Now the first equation

gives p ₁₀ = 0:

Therefore p ₀(x) =  − x (omitting the integration constant):

We have derived the well-known result

Consider the integrals

in a similar way.

Example 2

Let’s calculate the integral

Here $$\hat{D} = 1$$; it seems that there is a single q, namely x, but $$\log (x) = y$$, so that the logarithmic part contributes nothing new.

From the second equation, $$p_{20} = 1/2$$; then p ₁ is a constant:

From the first equation, p ₁₀ = 0; then p ₀ is a constant (which may be omitted):

We have derived the well-known result

Example 3

Let’s change the previous integral a little:

As in the previous examples, p ₂(x) is a constant:

A polynomial p ₁(x) satisfying the second equation does not exist. Therefore, this integral cannot be taken in elementary functions.

Example 4

Let’s consider

(it is not quite clear what the degree of the right-hand side in y should be; we shall see in a moment that this is irrelevant).

From the last equation, p ₁(x) is a constant. The previous equation shows that it is 0, and p ₀(x) is a constant (it may be set to 0). It is clear that if we started from some other degree in y, we would all the same find that all p n (x) = 0. And the first equation cannot be solved for c.

Consider the integrals

in a similar way.

10.3 Exponential Extension

Now we shall consider an exponential extension with some y = expr(x). If an integral of an expression from this extension can be taken in elementary functions, it has the form

where $$\hat{d}_{i} = d_{i} - 1$$ always except the case D i  = y in which $$\hat{d}_{i} = d_{i}$$. This is because the derivative of 1 ∕ y is proportional to 1 ∕ y, the degree of y in the denominator does not increase. We exclude y from the list of the factors q i (if it was present, of course) because $$\log y = r(x)$$ is a rational function, and such a contribution is already accounted for. As usual, we differentiate the result and equate to the integrand to obtain a linear system. If it cannot be solved, then the integral does not exist in elementary functions.

Example 1

Let $$y =\mathrm{ {e}}^{x}$$:

Let’s calculate

(the degree in y does not change when differentiating; therefore the polynomial in y in the right-hand side should have the same degree as the integrand).

From this equation:

Therefore $$p_{0}(x)$$ is a constant (which may be omitted):

We’ve got the expected result.

Example 2

Now let’s calculate

From this equation:

And without integration by parts!

Consider

in a similar way.

Example 3

Now let’s try to calculate

A polynomial $$p_{1}(x)$$ satisfying the second equation does not exist. Therefore this integral cannot be taken in elementary functions.

Example 4

Let’s calculate

(here $$\hat{D} = y$$, and there are no q i ). Of course, we could denote $$\mathrm{{e}}^{-x}$$ as y, and the problem would reduce to the Example 1 with trivial modifications; but we want to observe how the algorithm works in this new case.

From the second equation, p ₁(x) is a constant, which may be omitted—this is the integration constant.

Therefore

Example 5

Let’s consider

(now $$\hat{D} = 1$$, and there is a single q, namely y − 1).

Therefore

From the first equation, p ₀(x) =  − x (omitting the integration constant).

Consider

in a similar way and demonstrate that this integral does not exist in elementary functions.

Example 6

Of course, the method can be also used for other exponential extensions. For example, let $$y =\exp {x}^{2}$$:

Let’s consider

This equation cannot be solved. A larger degree of p ₁(x) does not help. Therefore this integral cannot be taken in elementary functions.

Example 7

And what about

From this equation, p ₁₁ = 0, p ₁₀ = 1 ∕ 2. The first equation says that p ₀(x) is a constant (it may be omitted).

Consider

in a similar way.

10.4 Elementary Functions

A tower of extensions can be constructed. We start from the set of rational functions N(x) ∕ D(x). Then we introduce y ₁, which is either a root of a polynomial equation $$p\left (x,y_{1}\right ) = 0$$, or logarithm or exponent of some rational function of x, and we obtain a first extension—the set of functions $$N\left (x,y_{1}\right )/D\left (x,y_{1}\right )$$. Then we introduce y ₂, which is either a root of a polynomial equation $$p\left (x,y_{1},y_{2}\right ) = 0$$, or logarithm or exponent of some function from the previous extension, and we get a next extension—the set of rational functions of x, y ₁, y ₂. And so on. We should take care that an extension which seems transcendental is not in fact algebraic; if we neglect this, the methods designed for transcendental extensions may break down, e.g., produce divisions by 0. For example, if $$y_{1} =\mathrm{ {e}}^{x}$$, then it would not be a good idea to introduce the exponential extension with $$y_{2} = {e}^{2x}$$, because y ₂ is not algebraically independent: $$y_{2} = y_{1}^{2}$$. Similarly, if $$y_{1} =\log x$$, then it’s not reasonable to introduce the logarithmic extension with $$y_{2} =\log 2x$$, because $$y_{2} = y_{1} +\log 2$$ (in this case the field of constants needs to be extended by the transcendental number $$\log 2$$). In simple cases such restrictions are obvious, but in complicated ones it is necessary to decide if some function from some extension is identical 0, and this problem is algorithmically unsolvable in general.

Such towers of algebraic, logarithmic, and exponential extensions include all functions called elementary. And even some extra ones: an algebraic extension can be defined, e.g., by a root of a fifth degree polynomial unsolvable in radicals. Indeed, trigonometric functions reduce to exponentials, and inverse trigonometric ones—to logarithms. For each elementary function there exists a tower of extensions to which it belongs (it is not unique).

Suppose we want to integrate an elementary function. We construct a tower of extensions to which it belongs. If the indefinite integral exists in elementary functions, it belongs to some further extension of our tower by some extra logarithms (their number may be zero). The Risch algorithm allows one to decide in a finite number of steps if the result exists in this further extension, and if so, to find it; if it does not exist, the algorithm proves this fact. In its classical form, the algorithm is recursive in extensions—it calls itself for solving integration subproblems in previous (smaller) extensions, until rational functions. There is a simpler and more efficient version of the Risch algorithm—to write down the general form of the result with unknown coefficients, differentiate it and equate to the integrand. Then the problem reduces to solving a linear system. This approach is guaranteed to be correct if we know upper bounds on the degrees of the polynomial $$P\left (x,y_{1},y_{2},\ldots \right )$$ in its variables. But such upper bounds are not always known (as we have seen in the examples, they are known if there is no denominator). Therefore some heuristic rules to bound the degrees of P are used. This can give a situation when no result is found, though it really exists (but has a larger degree in some variables).

The Risch algorithm is an outstanding achievement of mathematics in the twentieth century. But it does not solve all problems with indefinite integration. The answer that no result exists in elementary functions is not very useful. It would be much better to get the result with some special functions. There were attempts to generalize the Risch algorithm to some special functions (the error function, polylogarithms). Some of them are implemented in Mathematica.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7.​ Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_11© Springer International Publishing Switzerland 2014

11. Linear Algebra

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

A matrix in Mathematica is a list of lists; all the lists—rows of the matrix—must have the same length.

11.1 Constructing Matrices

A matrix in Mathematica is a list of lists; all the lists—rows of the matrix—must have the same length.

MatrixForm is used to print a matrix nicely.

If the (i, j)th element of a matrix is given by an expression depending on i and j, this matrix can be constructed by the function Table.

The function Array is similar, but its first argument is a function of two parameters, not an expression. It may be just a symbol or an anonymous function (Function).

Mathematica does not distinguish column vectors and row vectors; both are just lists.

11.2 Parts of a Matrix

A matrix element.

A row.

A column.

A new value can be assigned to a matrix element.

Add 1 to the first row.

Add the second column to the first one.

11.3 Queries

The function VectorQ checks if its argument is a vector, i.e., a list whose elements are not lists.

The function MatrixQ checks if its argument is a matrix, i.e., a list of same-length lists.

The argument of the function Dimensions must be a matrix. This function returns a two-element list—the numbers of rows and columns of the matrix.

It can be conveniently used for simultaneous assignment to two variables.

11.4 Operations with Matrices and Vectors

Vectors can be added and multiplied by scalar expressions.

Matrices can be added and multiplied by scalar expressions.

The scalar product of two vectors.

The product of a matrix and a column vector.

The product of a row vector and a matrix.

The product of two matrices.

It is not commutative.

Determinant (the matrix must be square).

Trace (the matrix must be square).

Transposing.

The inverse matrix.

A square matrix can be raised to an integer power.

The power − 1 is the inverse matrix.

This is the solution of the linear system $$A.X = V$$.

The same can be done using LinearSolve.

11.5 Eigenvalues and Eigenvectors

Here is some symbolic matrix.

It is singular.

Its rank.

The function NullSpace returns a list of vectors forming a basis of the null space of the matrix, i.e., the subspace of vectors nullified by the matrix.

In this case, the null space is one-dimensional—it has a single basis vector. Let’s check it.

The function Eigenvalues returns a list of eigenvalues of a matrix.

We have added the second argument to Simplify which informs Mathematica that the variable x is real. The function Eigenvectors returns the list of the corresponding eigenvectors (in the same order).

The function Eigensystem returns both. It is convenient for simultaneous assignment to two variables.

Let’s check.

11.6 Jordan Form

Here is a matrix of rational numbers.

The function JordanDecomposition returns a pair of matrices—the Jordan form J and the transformation matrix P which reduces our matrix to its Jordan form.

Let’s check.

Here are the eigenvalues and the eigenvectors of our matrix. Note that only one eigenvector corresponds to the eigenvalue 2, because the corresponding Jordan block has the size 2 ×2. The eigenvectors are the columns of the transformation matrix P.

11.7 Symbolic Vectors, Matrices, and Tensors

Let’s inform Mathematica that u, v, and w are symbolic three-dimensional vectors with real components. The scalar product is u. v, and the vector product is Cross[u, v]. The function TensorReduce simplifies expressions with vectors.

Now let’s say that u and v are d-dimensional vectors, and S and A are d ×d matrices, S symmetric and A antisymmetric.

The tensor product $$S_{i\,j}\,A_{k\,l}$$ is contracted in j and k and in i and l.

The Riemann curvature tensor has the properties $$R_{i\,j\,k\,l} = -R_{j\,i\,k\,l}$$ and $$R_{i\,j\,k\,l} = R_{k\,l\,i\,j}$$.

The Ricci tensor.

$$R_{i\,j\,k\,l}\,R_{i\,j\,k\,l} + R_{i\,j\,k\,l}\,R_{k\,l\,j\,i} + R_{i\,j\,k\,l}\,R_{i\,k\,j\,l}$$.

Unfortunately, Mathematica cannot take $$R_{i\,j\,k\,l} + R_{i\,k\,l\,j} + R_{i\,l\,j\,k} = 0$$ into account.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_12© Springer International Publishing Switzerland 2014

12. Input–Output and Strings

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

When developing any nontrivial Mathematica program, it is better to write it in a text file, using a text editor, and then to read it into a fresh Mathematica session. In this way, your actions will be reproducible. You can fix a bug and see what has changed. Suppose we have a text file called wrong.m. It contains the text

12.1 Reading and Writing.m Files

When developing any nontrivial Mathematica program, it is better to write it in a text file, using a text editor, and then to read it into a fresh Mathematica session. In this way, your actions will be reproducible. You can fix a bug and see what has changed. Suppose we have a text file called wrong.m. It contains the text

We can read it. Now the variables a and b have values:

The value of b is not what we expected. Why? When Mathematica sees an end of a line, it checks if the text read so far forms a syntactically correct expression. If so, the expression is considered complete; the next line starts a new expression. Otherwise, the next line is considered a continuation of the current expression. Thus our file wrong.m contains not two but three expressions: two assignments (to a and b) and a separate polynomial consisting of two terms. One way to prevent such unintended splitting of multiline expressions is to place a binary operator (e.g., + or − ) at the end of each line. Mathematica always writes its result in such a way. But it is easy to forget about it when writing a long expression in a text editor. Also, if we paste results from some other system into a Mathematica program, it would be tedious and error-prone to bring long expressions to such a form by hand. It is better to enclose each multiline expression in extra parentheses, then any incomplete subset of lines is not syntactically correct. Therefore we edit our wrong.m and obtain a file right.m:

Now everything’s all right:

Let us modify the file:

Now the last expression is not an assignment, but just a polynomial. What happens if we read it?

The operator < < (its full name is Get) returns the value of the last expression. Therefore, we can use it in an assignment (or as an argument of any other function):

The function Get tries to find the file in all directories in the list $Path. Its default value contains, in particular, the current directory “.”. You can add more directories to it using list operations, such as Append, Prepend, or Join.

And this operator (its full name is Put) writes the value of an expression into a file. The value is written in the input form, and hence can be later read by Mathematica.

The function > > writes just an expression, not an assignment to some variable. Often it is more useful to write an assignment (or several of them) which defines some variable (or function). Suppose we have

We can save the definition of the function f into a file:

12.2 Output

The function Print prints expressions (including strings, plots, etc.). It does not separate them by spaces, so that it is usually a good idea to insert ” ” between expressions. It adds a newline at the end.

$$\begin{array}{l} \text{Out}[28] = \text{A strings}\end{array}$$with a newline x ² + 2xy + y ² 

The function Print is most useful when you want to know what happens at some point deep inside your own function when it is called. If you want to write expressions to a file instead, use Write:

Expressions are written in the input form and can be read later.

12.3 C, Fortran, and TE X Forms

Suppose you have derived analytically a valuable expression a:

Now you want to do some large-scale numerical calculations with it. In order to avoid possible errors when translating this expression into a form suitable to inclusion into a numerical program, it is a good idea to do this step automatically. The function CForm converts an expression into a form which can be inserted into a C (or C++) program.

The macros Power, Sin, and friends are defined in the file mdefs.h which is supplied with Mathematica. If the expression contains special functions, you will need some extra C libraries which can calculate them numerically. Of course, it is better to write the C form of an expression into a file and then insert it into your program. For those old-fashioned enough to do numerical computations in Fortran, there is also FortranForm.

At last, all computations are done, and you are writing an article to be submitted to a scientific journal. You want to include your valuable expression a and to avoid errors in process of doing so. Scientific articles are written in LaTeX (in most cases). The function TeXForm converts an expression into a form which can be inserted into a LaTeX file.

12.4 Strings

The simplest string operation is concatenation:

Mathematica has string patterns and substitutions.

$$x\,{\_}$$ means an arbitrary (single) character.

Internally, these patterns are the function StringExpression.

A pattern with two identical arbitrary characters.

b | c means b or c.

x _ _ means any nonempty sequence of characters.

$$x\,{\_}\,{\_}\,{\_}$$ means any sequence of characters (including empty).

As in the case of general patterns, ∕ ; means a condition (such that).

The function StringMatchQ tests if a string matches a pattern.

The function StringFreeQ tests if there are no substrings matching a pattern.

The function StringSplit splits a string at each occurrence of a pattern; if the second argument is not given, then at each white space.

Mathematica contains many more string manipulation functions and additional powerful features of string patterns and can be used for text processing instead of Perl. For more details, see the online help.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_13© Springer International Publishing Switzerland 2014

13. Packages

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

When writing a large program, it is easy to accidentally use one symbol for two different quantities in different parts of the program. This leads to difficult-to-find bugs. This is especially true if parts of the program are written by different persons (in particular, when some packages from the standard library, or third-party packages, are used). To avoid such problems, contexts are used.

13.1 Contexts

When writing a large program, it is easy to accidentally use one symbol for two different quantities in different parts of the program. This leads to difficult-to-find bugs. This is especially true if parts of the program are written by different persons (in particular, when some packages from the standard library, or third-party packages, are used). To avoid such problems, contexts are used.

In Mathematica, a full symbol name consists of two parts: the context and the short name. Two symbols in different contexts may have the same short name. For example, the global symbol x and the symbol x in the contexts a and b are unrelated.

Contexts may be nested. Here the variable x lives in the context b which lives in the context a (and thus is unrelated to the global context b used above).

The current default context is held in the variable $Context. It is used when a new symbol is created without specifying its context.

When a symbol without an explicit context is used, it is being searched in contexts specified in $ContextPath.

Built-in symbols live in the context $$System\grave{\;}$$.

You can change $ContextPath using standard list functions. The function Remove removes symbols from the system.

13.2 Packages

Mathematica comes with a library of packages extending its built-in functionality. A package can be loaded by

Now this context is prepended to $ContextPath.

Short names will be searched in this context first, possibly shadowing variables and functions from $$Global\grave{\;}$$.

The package Quaternions lives in the directory Quaternions, which lives in the standard library directory.

Many additional packages are available at http:​/​/​library.​wolfram.​com/​infocenter/​MathSource/​. You can download them and install somewhere in your $Path.

You can instruct Mathematica to load a package whenever any function defined in it is used.

13.3 Writing Your Own Package

Begin, End

$$\text{Begin}[``a\grave{\;}^{\prime \prime}]$$ changes the default $Context; all symbols defined after this will live in this context.

End[] restores the previous $Context.

BeginPackage, EndPackage

$$\text{BeginPackage}[\mathrm{\textquotedblright }a\grave{\;}\mathrm{\textquotedblright }]$$ sets $Context and changes $ContextPath in such a way that only the contexts $$a\grave{\;}$$ and $$\text{System}\grave{\;}$$ are available.

EndPackage[] restores the previous $Context; ContextPath gets its old value prepended by $$a\grave{\;}$$, so that symbols defined after $$\text{BeginPackage}[a\grave{\;}]$$ remain available.

A Typical Package

A simple package looks like this.

After $$\text{BeginPackage}[\mathrm{\textquotedblright APackage}\grave{\;}\mathrm{\textquotedblright }]$$, publicly available functions and variables of the package are introduced, usually by assignments to their usage messages. Implementation of the package is done in the context $$\text{APackage}\grave{\;}\text{Private}\grave{\;}$$, which may contain additional functions and variables (not seen by users of the package).

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Part 2
Computer Classes

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3© Springer International Publishing Switzerland 2014

Before spending your time and effort on catching a lion, check: maybe, somebody has already caught it, and it is available for download at http:​/​/​library.​wolfram.​com/​infocenter/​MathSource/​.

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_14© Springer International Publishing Switzerland 2014

14. Plots

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

After typing a Mathematica command in its notebook interface, you can send it to the kernel (which performs calculations) by pressing Shift-Enter. The result appears in the output cell which follows your input cell. Both are nested in an outer cell representing a calculation step. Later you can return to this input cell, edit the command, and execute it again. The old output will be replaced by the new result. It is allowed to type several commands in a single input cell, but this is not convenient—don’t do so unless you have good reasons.

After typing a Mathematica command in its notebook interface, you can send it to the kernel (which performs calculations) by pressing Shift-Enter. The result appears in the output cell which follows your input cell. Both are nested in an outer cell representing a calculation step. Later you can return to this input cell, edit the command, and execute it again. The old output will be replaced by the new result. It is allowed to type several commands in a single input cell, but this is not convenient—don’t do so unless you have good reasons.

Mathematica Help contains all the necessary information. The Help menu contains Documentation Center, Function Navigator, and Virtual Book (among other things). You can quickly get help for a specific function if you select it with the mouse and press F1.

14.1 D Plots

Function Plot

See Help → Virtual Book → Visualization and Graphics → Graphics and Sound → Basic Plotting, and Help → Function Navigator → Visualization and Graphics → Function Visualization → Plot for more details.

Several Functions

You can set colors and styles of the curves (Virtual Book → Visualization and Graphics → Graphics and Sound → Options for Graphics; Function Navigator → Visualization and Graphics → Options and Styling → Plotting Options → PlotStyle).

Unbounded Function

Mathematica has chosen some y scale. How to set it? Find in the Help.

Logarithmic Scale

If our function is positive and varies by orders of magnitude in our region, it is convenient to use logarithmic scale in y. If the independent variable also varies by orders of magnitude, the x-axis scale also should be logarithmic (Function Navigator → Visualization and Graphics → Function Visualization → LogPlot, LogLogPlot).

Parametric Curve

Lissajous figures.

Implicit Plots

Experimental Points

In real life they are being read from a file. We don’t have such a file at hand, and therefore we’ll generate a list of “experimental” points according to some formulas.

Function Navigator → Visualization and Graphics → Data Visualization → ListPlot.

Let’s try to fit these points by a quadratic polynomial.

And now the curve and the points on a single plot (Function Navigator → Visualization and Graphics → Data Visualization → Annotation & Combination → Show).

Inequalities

Function Navigator → Visualization and Graphics → Function Visualization → RegionPlot.

Vector Fields

14.2 3D Plots

Hat

Let’s draw a hat with a wavy pent. First define a function.

Virtual Book → Visualization and Graphics → Three-Dimensional Surface Plots; Function Navigator → Visualization and Graphics → Function Visualization → Plot3D.

And why is the top of the hat cut off?

All 3D plots can be rotated by the mouse. If you press Shift, the mouse will move the plot; and if you press Ctrl, then it will resize it.

Sphere

Donut

Take a point on the x-axis at a distance R from the origin; draw a circle of a radius r around it in the x, z plane; and rotate it around the z axis. You will get a donut (torus). Let R be 1; r can be tuned by the mouse from 0 to 1, with the initial value 0.3.

Spiral

ParametricPlot3D can draw curves, too.

Implicit Surface

Inequalities

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_15© Springer International Publishing Switzerland 2014

15. Trigonometric Functions

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Mathematica can calculate Cos and Sin for many arguments equal to π times rational numbers.

Statement of the Problem

Mathematica can calculate Cos and Sin for many arguments equal to π times rational numbers. For example,

But it does not apply the half-angle formulas in all possible cases. We’ll write our own cos function which does this; then

Simple Cases

These cases should be considered separately because Mathematica does not treat them as rational numbers times π.

General Case

For example,

Check

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_16© Springer International Publishing Switzerland 2014

16. Quantum Oscillator

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

The Hamiltonian of the harmonic oscillator is [18]

There is a dimensionful constant $$\hslash $$ in quantum mechanics; therefore, two quantities m and ω define a scale of length $$\sqrt{\hslash /(m\,\omega )}$$, momentum $$\sqrt{\hslash \,m\,\omega }$$, energy $$\hslash \,\omega$$, and any other quantity of any dimensionality. They have the meaning of the characteristic amplitude, momentum, and energy of zero oscillations. We shall put $$\hslash = 1$$, m = 1, and ω = 1, thus choosing these characteristic scales as units for measurement of corresponding quantities.

Catching a lion, the Schrödinger’s method: At any moment, there is a nonzero probability that a lion is inside the cage. Sit and wait.

16.1 Lowering and Raising Operators

The Hamiltonian of the harmonic oscillator is [18]

There is a dimensionful constant $$\hslash $$ in quantum mechanics; therefore, two quantities m and ω define a scale of length $$\sqrt{\hslash /(m\,\omega )}$$, momentum $$\sqrt{\hslash \,m\,\omega }$$, energy $$\hslash \,\omega$$, and any other quantity of any dimensionality. They have the meaning of the characteristic amplitude, momentum, and energy of zero oscillations. We shall put $$\hslash = 1$$, m = 1, and ω = 1, thus choosing these characteristic scales as units for measurement of corresponding quantities. Then

Let’s introduce the operator

and its Hermitian conjugate

The commutation relation $$\left [\hat{p},\hat{x}\right ] = -\mathrm{i}$$ implies for them

The Hamiltonian is expressed via these operators as

from where we obtain $$\left [\hat{H},\hat{a}\right ] = -\hat{a}$$, $$\left [\hat{H},\hat{{a}}^{+}\right ] =\hat{ {a}}^{+}$$. Therefore, if | ψ > is an eigenstate of $$\hat{H}$$ with the energy E: $$\hat{H}\,\vert \psi > = E\,\vert \psi >$$, then $$\hat{a}\,\vert \psi >$$ and $$\hat{{a}}^{+}\,\vert \psi >$$ are also eigenstates of $$\hat{H}$$ with the energies E − 1 and E + 1:

(if only these states don’t vanish). Hence the eigenvalues of $$\hat{H}$$ form an arithmetic progression with step equal to 1. It is bounded from below because $$\hat{H}$$ is a positive definite operator. Therefore, there exists a state | 0 > with the lowest energy that cannot be lowered any more:

Its energy is equal to $$\frac{1} {2}$$:

(this is the zero oscillations energy). Acting on | 0 > by the raising operator $$\hat{{a}}^{+}$$ n times, we obtain a state | n > with the energy

Hence, $$\hat{H}\,\vert n> = \left (\hat{{a}}^{+}a + \frac{1} {2}\right )\,\vert n> = \left (n + \frac{1} {2}\right )\,\vert n>$$ or

i.e., $$\hat{{a}}^{+}\hat{a}$$ acts as an operator of the level number.

We have $$\hat{a}\,\vert n> = c_{n}\,\vert n - 1>$$; it is possible to make c n real and positive by tuning the phases of the states | n > . These coefficients can be found from the normalization condition: $$\vert c_{n}{\vert }^{2} = <n\vert \hat{{a}}^{+}\hat{a}\vert n> = n$$. The action of the operator $$\hat{{a}}^{+}$$ follows from Hermitian conjugation:

From this we again have $$\hat{{a}}^{+}\hat{a}\,\vert n> = n\,\vert n>$$.

In the coordinate representation

Let’s implement the operators $$\hat{a}$$ and $$\hat{{a}}^{+}$$ in Mathematica.

16.2 Ground State

This is the state which cannot be lowered by $$\hat{a}$$.

The normalization integral.

16.3 Excited States

The wave functions of a few first states.

And here the level number can be set by the mouse.

The wave functions of a few first states.

And this is a live plot: the level number can be set by the mouse.

16.4 Some Properties

Orthogonality and normalization.

Wave functions in the momentum representation (Fourier transforms) are the same as in the coordinate one, up to phase factors.

The probability density.

Why is it larger near the boundaries?

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_17© Springer International Publishing Switzerland 2014

17. Spherical Harmonics

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

The angular momentum operator $$\hat{\boldsymbol{J}}$$ is defined [18] in such a way that $$\hat{U} =\exp \left (-\mathrm{i}\hat{\boldsymbol{J}}\cdot \delta \boldsymbol{\varphi }\right )$$ is the operator of an infinitesimal rotation with the angle $$\delta \boldsymbol{\varphi }$$: if | ψ > is a state, then $$\hat{U}\,\vert \psi >$$ is the same state rotated by $$\delta \boldsymbol{\varphi }$$.

17.1 Angular Momentum in Quantum Mechanics

The angular momentum operator $$\hat{\boldsymbol{J}}$$ is defined [18] in such a way that $$\hat{U} =\exp \left (-\mathrm{i}\hat{\boldsymbol{J}}\cdot \delta \boldsymbol{\varphi }\right )$$ is the operator of an infinitesimal rotation with the angle $$\delta \boldsymbol{\varphi }$$: if | ψ > is a state, then $$\hat{U}\,\vert \psi >$$ is the same state rotated by $$\delta \boldsymbol{\varphi }$$. Therefore, the average value $$\boldsymbol{V }\,^{\prime}$$ of a vector operator $$\hat{\boldsymbol{V }}$$ over $$\hat{U}\,\vert \psi >$$ is related to its average value $$\boldsymbol{V }$$ over | ψ > by the formula $$\boldsymbol{V }^{\prime} =\boldsymbol{ V } +\delta \boldsymbol{\varphi } \times \boldsymbol{V }$$ and hence . Therefore, for any vector operator $$\hat{\boldsymbol{V }}$$ the commutation relation $$\left [\hat{V }_{i},\hat{J}_{j}\right ] = \mathrm{i}\varepsilon _{ijk}\hat{V }_{k}$$ holds. The average value of a scalar operator $$\hat{S}$$ does not change at rotations; hence $$\left [\hat{S},\hat{J}_{i}\right ] = 0$$. In particular, the angular momentum $$\hat{\boldsymbol{J}}$$ is a vector operator, and its square $$\hat{\boldsymbol{{J}}}^{2} =\hat{ J}_{x}^{2} +\hat{ J}_{y}^{2} +\hat{ J}_{z}^{2}$$ is a scalar one:

Therefore, a system of common eigenstates of $$\hat{\boldsymbol{{J}}}^{2}$$ and $$\hat{J}_{z}$$ exists. Let’s introduce the operators $$\hat{J}_{\pm } =\hat{ J}_{x} \pm \mathrm{i}\hat{J}_{y}$$, $$\hat{J}_{\pm }^{+} =\hat{ J}_{\mp }$$; we have $$\left [\hat{J}_{z},\hat{J}_{\pm }\right ] = \pm \hat{J}_{\pm }$$. This means that if $$\vert \psi >$$ is an eigenstate of $$\hat{J}_{z}$$ ($$\hat{J}_{z}\,\vert \psi > = m\,\vert \psi >$$), then $$\hat{J}_{\pm }\,\vert \psi >$$ are also eigenstates of $$\hat{J}_{z}$$: $$\hat{J}_{z}\hat{J}_{\pm }\,\vert \psi > = (m \pm 1)\hat{J}_{\pm }\,\vert \psi >$$ (if they don’t vanish). Therefore, eigenvalues $$m$$ of $$\hat{J}_{z}$$ form a progression with unit step, and the ladder operators $$\hat{J}_{\pm }$$ increase and decrease $$m$$.

Let’s consider states with a given eigenvalue of $$\hat{\boldsymbol{{J}}}^{2}$$. For these states, eigenvalues of $$\hat{J}_{z}$$ are bounded from above and from below because the operator $$\hat{\boldsymbol{{J}}}^{2} -\hat{ J}_{z}^{2} =\hat{ J}_{x}^{2} +\hat{ J}_{y}^{2}$$ is positive definite. Let $$\vert m_{\pm }>$$ be the eigenstates with the maximum and the minimum eigenvalues of $$\hat{J}_{z}$$ equal to $$m_{\pm }$$. Then these eigenvalues cannot be further increased and decreased by the operators $$\hat{J}_{\pm }$$ correspondingly: $$\hat{J}_{\pm }\,\vert m_{\pm }> = 0$$. We have

Therefore, $$\hat{J}_{\mp }\hat{J}_{\pm }\,\vert m_{\pm }> = 0 ={\bigl [\hat{\boldsymbol{ {J}}}^{2} - m_{\pm }\left (m_{\pm }\pm 1\right )\bigr ]}\,\vert m_{\pm }>$$, i.e., the eigenvalue of the operator $$\hat{\boldsymbol{{J}}}^{2}$$ for these states (as well as for all the other states being considered) is $$m_{+}\left (m_{+} + 1\right ) = m_{-}\left (m_{-}- 1\right )$$. Hence $$\left (m_{+} + m_{-}\right )\left (m_{+} - m_{-} + 1\right ) = 0$$; taking into account $$m_{+} \geq m_{-}$$ we obtain $$m_{-} = -m_{+}$$ or $$m_{\pm } = \pm j$$. The number $$j$$ must be integer or half-integer because $$m_{+}$$ and $$m_{-}$$ differ by an integer.

Finally, we have a system of common eigenstates $$\vert j,m>$$ of the operators $$\hat{\boldsymbol{{J}}}^{2}$$ and $$\hat{J}_{z}$$:

where $$j$$ is integer or half-integer, and $$m$$ varies from $$-j$$ to $$j$$ by 1. The operators $$\hat{J}_{\pm }$$ increase and decrease $$m$$ correspondingly: $$\hat{J}_{\pm }\,\vert j,m> = a_{\pm }(j,m)\,\vert j,m \pm 1>$$. Tuning the phases of $$\vert j,m>$$ we can make $$a_{\pm }(j,m)$$ real and positive. They can be found from the normalization: $$\vert a_{\pm }(j,m){\vert }^{2} = <j,m\vert \hat{J}_{\mp }\hat{J}_{\pm }\vert j,m> = j(j + 1) - m(m \pm 1)$$. Finally we arrive at

The orbital angular momentum of a particle $$\hat{\boldsymbol{l}} =\boldsymbol{ r} \times \hat{\boldsymbol{ p}}$$ (where $$\hat{\boldsymbol{p}} = -\mathrm{i}\boldsymbol{\nabla }$$ in the coordinate representation) is an example of angular momentum. In spherical coordinates

The eigenfunctions of $$\hat{l}_{z}$$ are $$\mathrm{{e}}^{\mathrm{i}m\varphi }$$; they must not change at $$\varphi \rightarrow \varphi +2\pi$$; hence $$m$$ must be integer. The common eigenfunctions of $$\hat{\boldsymbol{{l}}}^{2}$$ and $$\hat{l}_{z}$$ are called spherical harmonics:

where $$l$$ is integer, and $$m$$ varies from $$-l$$ to $$l$$ by 1; $$Y _{lm}(\theta,\varphi ) = P_{lm}(\theta )\mathrm{{e}}^{\mathrm{i}m\varphi }$$. They are orthonormalized:

Here are the operators $$\hat{l}_{\pm }$$ in Mathematica:

17.2 $$Y _{ll}(\theta,\varphi )$$

The angular momentum projection of this state cannot be raised by $$\hat{l}_{+}$$.

The normalization integral.

The phase can be chosen arbitrarily. According to Landau–Lifshitz [18]:

17.3 $$Y _{lm}(\theta,\varphi )$$

These states can be obtained from $$Y _{ll}(\theta,\varphi )$$ by the lowering operator $$\hat{l}_{-}$$.

Orthogonality of $$Y _{l_{1}m_{1}}$$ and $$Y _{l_{2}m_{2}}$$ with $$m_{1}\neq m_{2}$$ is evident; let’s check all the rest.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_18© Springer International Publishing Switzerland 2014

18. Adding Angular Momenta in Quantum Mechanics

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Let $$\hat{\boldsymbol{J}}_{1}$$ and $$\hat{\boldsymbol{J}}_{2}$$ be two angular momentum operators commuting with each other. Then the basis $$\vert j_{1},m_{1};j_{2},m_{2}>$$ of common eigenstates of the operators $$\hat{\boldsymbol{J}}_{1}^{2}$$, $$\hat{J}_{1z}$$, $$\hat{\boldsymbol{J}}_{2}^{2}$$, $$\hat{J}_{2z}$$ exists. On the other hand, the total angular momentum $$\hat{\boldsymbol{J}} =\hat{\boldsymbol{ J}}_{1} +\hat{\boldsymbol{ J}}_{2}$$ is also an angular momentum operator.

Let $$\hat{\boldsymbol{J}}_{1}$$ and $$\hat{\boldsymbol{J}}_{2}$$ be two angular momentum operators commuting with each other. Then the basis $$\vert j_{1},m_{1};j_{2},m_{2}>$$ of common eigenstates of the operators $$\hat{\boldsymbol{J}}_{1}^{2}$$, $$\hat{J}_{1z}$$, $$\hat{\boldsymbol{J}}_{2}^{2}$$, $$\hat{J}_{2z}$$ exists. On the other hand, the total angular momentum $$\hat{\boldsymbol{J}} =\hat{\boldsymbol{ J}}_{1} +\hat{\boldsymbol{ J}}_{2}$$ is also an angular momentum operator. Therefore, linear combinations $$\vert j,m>$$ of the states $$\vert j_{1},m_{1};j_{2},m_{2}>$$ at given $$j_{1}$$, $$j_{2}$$ can be constructed in such a way that they are eigenstates of $$\hat{\boldsymbol{{J}}}^{2}$$ and $$\hat{J}_{z}$$. This problem [18] is called addition of the angular momenta $$j_{1}$$ and $$j_{2}$$.

We always have $$m = m_{1} + m_{2}$$ because $$\hat{J}_{z} =\hat{ J}_{1z} +\hat{ J}_{2z}$$. The following figure illustrates addition of $$j_{1}$$ and $$j_{2}$$ (it assumes $$j_{1} \geq j_{2}$$).

There is one state with $$m = j_{1} + j_{2}$$, two states with $$m = j_{1} + j_{2} - 1$$, etc. Such an increase of the number of states occurs up to $$m = j_{1} - j_{2}$$; further on it is constant up to $$m = -\left (j_{1} - j_{2}\right )$$ and then decreases to one at $$m = -\left (j_{1} + j_{2}\right )$$. Therefore, the maximum angular momentum resulting from adding $$j_{1}$$ and $$j_{2}$$ is $$j = j_{1} + j_{2}$$. One state in the two-dimensional space of states with $$m = j_{1} + j_{2} - 1$$ refers to the same angular momentum, and the other one is the state with the maximum projection for the angular momentum $$j = j_{1} + j_{2} - 1$$. Continuing such reasoning, we see that all angular momenta up to $$j_{1} - j_{2}$$ appear. In general, adding angular momenta $$j_{1}$$ and $$j_{2}$$ results in the angular momenta $$j$$ from $$\left \vert j_{1} - j_{2}\right \vert $$ to $$j_{1} + j_{2}$$ in steps of 1.

This description naturally leads to the algorithm implemented below. We start from the only state with $$m = j_{1} + j_{2}$$, namely the state $$\vert j_{1},j_{1};j_{2},j_{2}>$$. It has $$j = j_{1} + j_{2}$$, i.e., it is $$\vert j_{1} + j_{2},j_{1} + j_{2}>$$. Repeatedly acting by the ladder operator $$\hat{J}_{-} =\hat{ J}_{1-} +\hat{ J}_{2-}$$ (and dividing by the appropriate normalization factor) we construct all the states with the total angular momentum $$j = j_{1} + j_{2}$$: $$\vert j_{1} + j_{2},j_{1} + j_{2} - 1>$$, … , $$\vert j_{1} + j_{2},-\left (j_{1} + j_{2}\right )>$$. Then we turn to the projection $$m = j_{1} + j_{2} - 1$$ and choose the state orthogonal to the already constructed one $$\vert j_{1} + j_{2},j_{1} + j_{2} - 1>$$. It has $$j = j_{1} + j_{2} - 1$$, i.e., it is $$\vert j_{1} + j_{2} - 1,j_{1} + j_{2} - 1>$$. Using the ladder operator we construct all the states with $$j = j_{1} + j_{2} - 1$$.

Then we proceed in a similar way. At the beginning of each step, when considering a new value of the projection $$m$$, we need to construct the state orthogonal to all the states with the same $$m$$ already constructed. This is achieved as follows: we start from an arbitrary state, say, $$\vert j_{1},j_{1};j_{2},m - j_{1}>$$, subtract its components along the already constructed states, and finally normalize the result. Then we construct all the states with the same total angular momentum from this state repeatedly acting by $$\hat{J}_{-}$$.

The function $$\text{AddJ}$$ constructs the states $$\vert j,m>$$ (denoted $$\text{Ket}[j,m]$$) as linear combinations of the states $$\vert j_{1},m_{1};j_{2},m_{2}>$$ (denoted $$\text{ket}[\text{m1},\text{m2}]$$). It uses two local functions: $$\text{Jm}$$ is the lowering operator $$\hat{J}_{-}$$ and $$\text{ScaP}$$ is the scalar product. The procedure returns its local $$\text{Ket}$$, so that later the user will be able to inquire about $$\text{Ket}[j,m]$$ for specific values of $$j$$, $$m$$; in addition to this, the procedure prints all its results.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_19© Springer International Publishing Switzerland 2014

19. Classical Nonlinear Oscillator

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Let’s consider one-dimensional motion of a particle with mass $$m$$ near a minimum of an arbitrary smooth potential [19]

(we have chosen the origin of $$x$$ and the zero energy level to be at the minimum). If we neglect $$V (x)$$, then the equation of motion

becomes

and has the solution

Now we consider the effect of

Choosing units of measurement in such a way that $$m = 1$$ and $$k = 1$$, we have the equation of motion

Its solution $$x(t)$$ is a periodic function of $$t$$.

19.1 Statement of the Problem

Let’s consider one-dimensional motion of a particle with mass $$m$$ near a minimum of an arbitrary smooth potential [19]

(we have chosen the origin of $$x$$ and the zero energy level to be at the minimum). If we neglect $$V (x)$$, then the equation of motion

becomes

and has the solution

Now we consider the effect of

Choosing units of measurement in such a way that $$m = 1$$ and $$k = 1$$, we have the equation of motion

Its solution $$x(t)$$ is a periodic function of $$t$$. If we choose the time origin at a maximum of $$x(t)$$, then $$x(t)$$ is an even function, due to reversibility. In the zeroth approximation $$x(t) = a\,\cos t$$.

The equation of motion is satisfied at $$O(a)$$.

19.2 The First Correction

Now we want to take terms of order $${a}^{2}$$ into account. The right-hand side is

Let’s expand it in harmonics.

That is, the ”driving force” contains zeroth and second harmonics. This means that we should add such harmonics to $$x(t)$$. We’ll not add the solution of the homogeneous equation—the first harmonic: by definition of the amplitude $$a$$, it is completely given by the leading term $$a\,\cos t$$.

Now we substitute this form of the solution into the equation of motion.

This expression should vanish. How can we separate harmonics? Let’s help Mathematica a little.

The coefficients of $${z}^{0}$$ and $${z}^{2}$$ should vanish.

We can find $$b[2,0]$$ from the first equation and $$b[2,2]$$ from the second one.

Now we know the solution.

Let’s check energy conservation.

19.3 The Second Correction

Now we want to find two corrections.

This is $$x[t]$$ up to $${a}^{2}$$.

The right-hand side of the equation of motion.

There are the first and the third harmonics at the order $${a}^{3}$$, that is, there is a resonant term in the ”driving force” which would lead to an unbounded growth of the solution. This means we have forgotten something. Namely, we have forgotten that the oscillation period depends on the amplitude (unless the potential is strictly parabolic). And our solution should contain $$\cos (j\omega t)$$. If we denote $$\tau =\omega t$$, then the equation of motion is

Let’s suppose that the variable $$t$$ in the program really means $$\tau$$ and denote $${\omega }^{2} = w$$. It is a series in $${a}^{2}$$ beginning with 1.

Now we are able to cancel the first harmonic in the $${a}^{3}$$ term of the equation of motion. And the third one should be added to the general form of the solution.

The equation of motion is

We already know how to solve it at the order $${a}^{2}$$.

At the order $${a}^{3}$$:

This is the coefficient of the first harmonic, i.e., of $${z}^{1}$$:

It can be nullified by choosing $$u[2]$$.

And this is the coefficient of the third harmonic, i.e., of $${z}^{3}$$:

It can be nullified by choosing $$b[3,3]$$.

Now we know the oscillation frequency

and $$x[t]$$:

Let’s check energy conservation.

19.4 The nth Correction

Now we’ll write a program which can find $$n$$ corrections in $$a$$ to the particle motion for any $$n$$. Just a single line should be changed for the calculation with a new value of $$n$$.

The correction to the potential and the “driving force.”

The frequency squared is a series in $${a}^{2}$$.

The general form of the solution. The order $${a}^{i}$$ contains harmonics up to the $$i$$th one. They are all even at even values of $$i$$ and odd at odd values. The first harmonic never appears—by definition, it is entirely contained in the leading term $$a\,\cos t$$.

The equation of motion.

All terms of the orders $${a}^{i}$$ for $$i$$ from 2 to $$n + 1$$ must vanish. If $$i$$ is odd, the first harmonic is present; a correction to the frequency squared is found from the condition that this harmonic vanishes. All other harmonics give us coefficients in $$x(t)$$.

Now we know the frequency squared.

and $$x(t)$$

Let’s check energy conservation.

It is easy to write a function with the parameter $$n$$ which can be used as a black box. It should use only local variables.

Now we save the results for the energy $$\text{Et}$$ and the frequency squared $$w$$ to a file; later we’ll compare them to the similar results in quantum mechanics.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_20© Springer International Publishing Switzerland 2014

20. Quantum Nonlinear Oscillator

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Suppose we know eigenvalues and eigenstates of a Hamiltonian $$\hat{H}_{0}$$ and want to find them for a Hamiltonian $$\hat{H} =\hat{ H}_{0} +\hat{ V }$$ in the form of series in $$\hat{V }$$ [18].

20.1 Perturbation Theory

Suppose we know eigenvalues and eigenstates of a Hamiltonian $$\hat{H}_{0}$$ and want to find them for a Hamiltonian $$\hat{H} =\hat{ H}_{0} +\hat{ V }$$ in the form of series in $$\hat{V }$$ [18]. Let’s concentrate on a non-degenerate eigenstate of the unperturbed Hamiltonian

After switching the perturbation on it transforms to a similar eigenstate of the full Hamiltonian

Let’s normalize $$\vert \psi >$$ in such a way that $$<\psi _{0}\vert \psi > = 1$$, then $$\vert \psi > = \vert \psi _{0}> + \vert \delta \psi >$$, $$<\psi _{0}\vert \delta \psi > = 0$$. We need to solve the equation

Let’s separate its components parallel and orthogonal to $$\vert \psi _{0}>$$. The parallel part is singled out by multiplying by $$<\psi _{0}\vert $$:

The orthogonal part is singled out by the projector $$\hat{P} = 1 -\vert \psi _{0}> <\psi _{0}\vert $$:

or

Solving this equation by iterations, we obtain

and

Note that $$\hat{D}$$ contains $$E = E_{0} +\delta E$$ and should be expanded in $$\delta E$$:

20.2 Nonlinear Oscillator

We are going to apply the perturbation theory to the nonlinear oscillator

The oscillation amplitude is $$\sim 1$$ if $$n \sim 1$$; therefore, $$c_{k} \sim {a}^{k}$$, where $$a \sim 1/L \ll 1$$, $$L$$ is the characteristic length of the potential in the oscillator units. If $$n \gg 1$$, the amplitude is $$\sqrt{n}$$ times larger, and the real expansion parameter is $$a\sqrt{n}$$.

We concentrate on the eigenstate $$\vert n>$$ of $$\hat{H}_{0}$$ having the energy $$E_{0} = n + \frac{1} {2}$$. In order to calculate $$\delta E$$ up to the $$M$$th order of the perturbation theory, we need to sum all expressions of the form

where $$\hat{\Delta }$$ is $$\hat{V }$$ or $$-\delta E$$ and the sum of the orders of smallness $$k_{1} + k_{2} + \cdots + k_{N} \leq M$$; the sum over all nonzero $$j_{1}$$, $$j_{2}$$, … $$j_{N-1}$$ is assumed. The following procedure prepares the values $$V [k,j]$$ of $$\left (\hat{V }_{k}\right )_{n+j,n}$$ ($$x[k,j]$$ means $$\left (\hat{{x}}^{k}\right )_{n+j,n}$$):

20.3 Energy Levels

The expressions we want to generate and calculate can be visualized as paths in the following graph:

Here $$l$$ is the number of orders of smallness we need to distribute. We start at the point $$l = M$$, $$j = 0$$. At each step we consider all possible $$\hat{\Delta }_{k}$$. If we choose $$\left (\hat{V }_{k}\right )_{n+j+i,n+j}$$, we move $$k$$ steps to the left and $$i$$ steps vertically. If we choose $$-\delta \,E_{k}$$, we move $$k$$ steps to the left horizontally (this choice is not allowed as the first or the last step). Whenever we hit the $$j = 0$$ axis, we have a complete expression for a contribution to $$\delta E$$. The fastest movement along $$j$$ at varying $$l$$ occurs when $$\hat{V }_{1}$$ is used, and its velocity is 3. Hence, in order to have enough time to return to $$j = 0$$, we should not leave the rhombus in the figure.

Suppose we have already generated a right-hand part $$a$$ of the expression up to some $$\hat{G}_{n+j}$$ inclusively, and there remain $$l$$ orders of smallness to distribute. The procedure considers all possible $$\left (\hat{\Delta }_{k}\right )_{n+j+i,n+j}$$ which can be inserted to the left of $$a$$. It may be $$-\delta E_{k}$$ with all possible values of $$k$$ (if we are not at the very first step $$l = M$$), the maximum $$k$$ is obtained from the rhombus. Or it may be $$\left (\hat{V }_{k}\right )_{n+j+i,n+j}$$ with all possible values of $$k$$ and $$i$$. $$\hat{V }_{k} = c_{k}\hat{{x}}^{k+2}$$ has nonzero matrix elements for $$i$$ from $$-k - 2$$ to $$k + 2$$ in steps of 2. The limits of the $$i$$ loop follow from the intersection of this range with the rhombus, and the $$k$$ loop terminates when this intersection disappears. If we happen to return to the initial state ($$j + i = 0$$), this means that the generation of an expression is complete, and it should be added to the element of the list $$d$$ which accumulates contributions to $$\delta E$$ (this contribution may contain lower-order $$\delta E_{k} = \text{de}[k]$$). In all other cases, the procedure is called recursively, with $$l$$ replaced by $$l - k$$, $$j$$ by $$j + i$$, and $$a$$ multiplied by $$\left (\hat{\Delta }_{k}\right )_{n+j+i,n+j}$$ and $$\hat{G}_{n+j+i}$$.

Now we substitute lower-order $$\delta \,E$$ into expressions for higher-order ones, to get explicit formulas.

20.4 Correspondence Principle

At $$n \gg 1$$ the expansion parameter of the perturbation series is $$a\sqrt{n}$$ where $$c_{k} \sim {a}^{k}$$. Keeping only the highest powers of $$n$$ in each order, we have

Bohr’s correspondence principle must hold. From the quantum point of view, the particle at the $$n$$th energy level can radiate a photon, jumping to the $$(n - 1)$$th one, or more generally to the $$(n - k)$$th one. The frequency of this photon is $$E_{n} - E_{n-k}$$, or approximately $$\frac{\mathrm{d}E_{n}} {\mathrm{d}n} k$$. From the classical point of view, the frequencies of the emitted light are equal to the oscillation frequency $$\omega$$ and its harmonics. Therefore, the oscillation frequency is

We want to compare it with the result of the calculation in classical mechanics. But the quantum expression for $$\omega$$ is in terms of $$n$$ and the classical one in terms of the oscillation amplitude $$a$$. We need to re-express both of them via the same quantity, the energy $$E$$.

Now we read the classical results for the energy $$\text{Ec}$$ and the frequency $$\text{Wc}$$ (written in terms of $$A = \left.{a}^{2}\right /2$$, where the amplitude $$a$$ is defined as the coefficient of the first harmonic $$\cos \omega t$$).

20.5 States

The following procedure accumulates contributions to $$\delta E$$ in elements of the list $$d$$ and to $$\vert \delta \psi >$$ in the list $$\text{dp}$$. Now we have to consider the large triangle in the figure, not just the rhombus.

As an additional problem, calculate the average values of $$\hat{{x}}^{k}$$ over the states just obtained, for several $$k$$. At $$n \gg 1$$ compare them to the classical averages obtained from the particle’s motion $$x(t)$$.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_21© Springer International Publishing Switzerland 2014

21. Riemann Curvature Tensor

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Suppose we have a coordinate system $${x}^{\mu }$$ in a region of an $$n$$-dimensional Riemann (or pseudo-Riemann) manifold [20]. Components of the metric tensor $$g_{\mu \nu }$$ are given as functions of $${x}^{\mu }$$. We want to calculate the Riemann curvature tensor $${R}^{\mu }\,_{\nu \alpha \beta }$$ and related quantities (the Ricci tensor $$R_{\mu \nu }$$, the scalar curvature $$R$$).

The metric tensor is symmetric; therefore, it is reasonable to ask the user to provide only the components with $$\mu \geq \nu$$.

Catching a lion, the Einstein’s method: Enter the cage and lock it from inside. Then the Universe will be subdivided into two disjoint regions in such a way that you are in one of them and the lion is in the other one. It depends on one’s point of view whom to consider caught; for convenience, let’s say it’s the lion.

Suppose we have a coordinate system $${x}^{\mu }$$ in a region of an $$n$$-dimensional Riemann (or pseudo-Riemann) manifold [20]. Components of the metric tensor $$g_{\mu \nu }$$ are given as functions of $${x}^{\mu }$$. We want to calculate the Riemann curvature tensor $${R}^{\mu }_{\nu \alpha \beta }$$ and related quantities (the Ricci tensor $$R_{\mu \nu }$$, the scalar curvature $$R$$).

The metric tensor is symmetric; therefore, it is reasonable to ask the user to provide only the components with $$\mu \geq \nu$$. If the user gives an argument having a wrong shape, we print an error message and abort the calculation. We shall also need the contravariant metric tensor $${g}^{\mu \nu }$$ defined by $${g}^{\mu \lambda }g_{\lambda \nu } =\delta _{ \nu }^{\mu }$$.

Next we calculate the Christoffel symbols

and $${\Gamma }^{\lambda }_{\mu \nu } = {g}^{\lambda \rho }\Gamma _{\rho \mu \nu }$$. They are symmetric in $$\mu$$ and $$\nu$$; therefore, we calculate them only at $$\nu \leq \mu$$ and reuse the calculated values at $$\nu >\mu$$. If the optional parameter $$\text{PrintNonZero}$$ is $$\text{True}$$, nonzero components are printed (following the tradition, in the printed results all indices vary from 0 to $$n - 1$$).

Finally, we calculate the Riemann tensor

the Ricci tensor $$R_{\mu \nu } = {g}^{\alpha \beta }R_{\alpha \mu \beta \nu }$$, and the scalar curvature $$R = {g}^{\mu \nu }R_{\mu \nu }$$. The Riemann tensor has the properties

and we use them to avoid unnecessary calculations.

Let’s consider an example: the Schwarzschild metric

First we give names to the coordinates.

Setting the Schwarzschild radius $$r_{0} = 1$$, we obtain

The Ricci tensor (and hence the scalar curvature) vanishes. Therefore, the Schwarzschild metric satisfies the vacuum Einstein equation.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_22© Springer International Publishing Switzerland 2014

22. Multi-ζ Functions

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

The Riemann ζ-function is defined by

Mathematica knows this function; it can be expressed via powers of $$\pi$$ for even integer values of $$s$$.

22.1 Definition

The Riemann ζ-function is defined by

Mathematica knows this function; it can be expressed via powers of $$\pi$$ for even integer values of $$s$$.

Let’s define

and so on. These series converge at $$s_{1} > 1$$. Mathematica does not know these multi-ζ functions. The sum $$s_{1} + s_{2} + \cdots + s_{k}$$ is called the weight. All relations we shall discuss contain terms of the same weight (the weight of a product is the sum of the weights of its factors).

22.2 Stuffling Relations

Suppose we want to multiply $$\zeta _{s}\zeta _{s_{1}s_{2}}$$:

Here $$n$$ can be anywhere with respect to $$n_{1}$$, $$n_{2}$$. There are five contributions:

This process reminds shuffling cards. The order of cards in the upper deck, as well as in the lower one, is kept fixed. We sum over all possible shufflings. Unlike real playing cards, however, two cards may be exactly on top of each other. In this case they are stuffed together: a single card (which is their sum) appears in the resulting deck. A mathematical jargon term for such shuffling with (possible) stuffing is stuffling.

Let’s implement this in Mathematica. The multi-ζ function will be called $$\zeta$$; it can have any number of arguments. The function $$\text{Stuffling}$$ first of all transforms products of $$\zeta$$ functions (including squares) to a local function $$z$$ with three list parameters: the first two contain the arguments of the initial $$\zeta$$ functions, and the third one is empty. These are our two decks for shuffling and the resulting deck, initially empty. All the work is done by the following repeated substitution. Let the two unprocessed decks be nonempty: the first one contains some front “card” $$a\,{\_}$$ and the remainder $$A\,{\_}\,{\_}\,{\_}$$; the second one—the front “card” $$b\,{\_}$$ and the remainder $$B\,{\_}\,{\_}\,{\_}$$. Then there are three possibilities: either we move the front “card” from the first deck ($$a$$) to the resulting deck, or we move the front “card” from the second deck ($$b$$) to the resulting deck, or we take the front “cards” from both decks and put their sum to the resulting deck (stuffing). We need to use a delayed substitution $$: >$$ here to ensure that the command $$\text{Expand}$$ in its right-hand side is executed when the substitution is applied. In addition to this, we should take care of the situations when one of the source decks becomes empty. In this case we can just append the other source deck to the resulting one and yield the result.

This process can also be described as the following. The final result is a sum of many $$\zeta$$ functions with various argument lists. During intermediate steps, the function $$z[\text{deck1},\text{deck2},\text{res}]$$ represents the sum of a subset of terms of the result whose argument lists begin with $$\text{res}$$. At each step we subdivide this sum into three parts, according to three possible values of the next argument.

22.3 Integral Representation

It is easy to check the integral representation of the ζ-function of an integer argument

Let’s denote

All integrals will always have the integration region $$1 > x_{1} > \cdots > x_{s} > 0$$. Then

This representation can be generalized to multi-ζ functions:

and so on. Let’s write functions for transforming $$\zeta$$ with integer arguments to such integral representation and back. The integral representation $$\mathrm{\zeta\ i}$$ takes an arbitrary number of arguments equal to 0 or 1 corresponding to $$\omega _{0}$$, $$\omega _{1}$$.

22.4 Shuffling Relations

Suppose we want to multiply $$\zeta _{2} \cdot \zeta _{2}$$:

The order of primed and non-primed integration variables is not fixed. There are six contributions:

Now we are multiplying integrals, not sums. Therefore our “cards” are now infinitely thin and cannot be exactly on top of each other. There are just two kinds of “cards”: $$\omega _{0}$$ and $$\omega _{1}$$, and we sum over all possible shufflings of two decks.

22.5 Duality Relations

The integral representation allows us to derive another set of useful relations, even simpler than shuffling—duality relations. Let’s make the substitution $$x_{i} \rightarrow 1 - x_{i}$$. Then $$\omega _{0}\longleftrightarrow \omega _{1}$$; to preserve the order $$1 > x_{1} > \cdots > x_{s} > 0$$, we have to arrange all the $$\omega$$ factors in the opposite order. In other words, after writing down an integral representation for a multi-ζ value, we may read it in the Arabic fashion, right to left, simultaneously replacing $$\omega _{0}\longleftrightarrow \omega _{1}$$. Duality relations are the only known relations which say that two multi-ζ values with distinct arguments are just equal to each other.

22.6 Weight 4

There are four converging multi-ζ series of weight 4: $$\zeta _{4}$$, $$\zeta _{31}$$, $$\zeta _{22}$$, and $$\zeta _{211}$$. Due to duality, two of them are equal to each other.

We can express $$\zeta _{4}$$ via $$\zeta _{2}^{2}$$ using their explicit values:

Two equations for $$\zeta _{2}^{2}$$ follow from stuffling

and shuffling

They can be solved for $$\zeta _{22}$$ and $$\zeta _{31}$$ (taking the expression for $$\zeta _{4}$$ into account).

Thus we have demonstrated that all multi-ζ values of weight 4 can be expressed via $$\zeta _{2}^{2}$$.

22.7 Weight 5

There are four distinct multi-ζ values of weight 5,

due to duality. The stuffling relation for $$\zeta _{2}\zeta _{3}$$:

A similar equation where $$\zeta _{3}$$ is written in the dual form.

The shuffling relation for $$\zeta _{2}\zeta _{3}$$:

This system can be solved for $$\zeta _{41}$$, $$\zeta _{32}$$, and $$\zeta _{23}$$.

Thus we have demonstrated that all multi-ζ values of weight 5 can be expressed via $$\zeta _{2}\zeta _{3}$$ and $$\zeta _{5}$$.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_23© Springer International Publishing Switzerland 2014

23. Rainbow

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

We consider scattering of light by a spherical water drop in geometrical optics. For small drops, diffraction becomes significant; our analysis is only valid for drops which are not too small. Let the drop radius be 1. The ray with the impact parameter $$\rho$$ splits into the reflected ray and the refracted one. Their directions are given by the Snell law

23.1 Statement of the Problem

We consider scattering of light by a spherical water drop in geometrical optics. For small drops, diffraction becomes significant; our analysis is only valid for drops which are not too small. Let the drop radius be 1. The ray with the impact parameter $$\rho$$ splits into the reflected ray and the refracted one. Their directions are given by the Snell law

where the refraction index of water is

The incident ray hits the drop at the point $$\{\text{Cos}[\varphi ],\text{Sin}[\varphi ]\}$$, where $$\varphi =\pi -\alpha$$. The reflected ray has the direction $$\vartheta =\pi -2\alpha$$. The refracted ray hits the drop surface again at $$\{\text{Cos}[\psi ],\text{Sin}[\psi ]\}$$, where $$\psi =\varphi +2\beta -\pi$$.

The incident light has two polarizations, with the electric field orthogonal to the scattering plane or lying in this plane. The reflection coefficients for these polarizations are given by the Fresnel formulas [21] (they don’t depend on the direction, i.e., are the same for a ray entering water and a ray leaving it).

23.2 0 Ray Segments Inside the Drop

First let’s consider rays reflected by the drop immediately after they hit its surface.

The scattering angle is

In order to calculate the differential cross section, we need to express $$\rho$$ via the scattering angle $$\vartheta$$:

The angles $$\alpha$$ and $$\beta$$ are

The area of the ring in the transverse plane corresponding to the scattering angles between $$\vartheta$$ and $$\vartheta +\mathrm{d}\vartheta$$, divided by $$\mathrm{d}\Omega = 2\pi \,\text{Sin}[\vartheta ]\,\mathrm{d}\vartheta$$, is

Therefore, the cross sections for the two polarizations are

Note that there is a scattering angle $$\vartheta$$ at which the scattered light is completely polarized: its electric field is orthogonal to the scattering plane. This happens when $$\alpha$$ is equal to the Brewster angle $$\mbox{ $\alpha $B}$$

In this case

so that $$\mbox{ $\alpha $B} + \mbox{ $\beta $B} =\pi /2$$ —the refracted ray is perpendicular to the reflected one:

When the incoming light with the electric field in the scattering plane reaches water, electric dipoles in it oscillate along the direction perpendicular to the refracted ray; they don’t radiate in the direction along this axis, i.e., don’t produce the reflected ray: $$\text{Rp} = 0$$.

23.3 1 Ray Segment Inside the Drop

When entering water, the ray is deflected by $$\alpha -\beta$$ clockwise; when leaving water, it is deflected by the same angle again. The direction of the outgoing ray is

The scattering angle $$\vartheta$$ is obtained by reducing $$\mbox{ $\vartheta $1}$$ to the interval $$[-\pi,\pi ]$$ and then taking $$\text{Abs}$$; in the present case, it is just $$-\mbox{ $\vartheta $1}$$.

It varies from 0 to

Now we have to solve the equation $$\alpha -\beta =\vartheta /2$$ for $$\rho$$.

We discard the negative solutions. The positive ones evaluated at $$\mbox{ $\vartheta $1m}$$ are

So, the right solution is number 2:

The geometrical cross section for $$\vartheta$$ between $$\vartheta$$ and $$\vartheta +\mathrm{d}\vartheta$$, divided by $$\mathrm{d}\Omega $$, is

where $$\text{c2} = \text{Cos}[\vartheta /2]$$, $$\text{s2} = \text{Sin}[\vartheta /2]$$. The angles $$\alpha$$ and $$\beta$$ are

The differential cross sections for the two polarizations are

(the transmission coefficient is $$T = 1 - R$$, and transmission happens twice).

23.4 2 Ray Segments Inside the Drop

The second segment of the ray inside the drop is obtained from the first one by rotating by the angle $$\pi -2\beta$$ clockwise; hence the outgoing ray is obtained from the one in the previous section by the same rotation:

The real scattering angle is $$\vartheta = -\mbox{ $\vartheta $2}$$:

It has a minimum at

equal to

Rays from a relatively wide ring around $$\mbox{ $\rho $2r}$$ have practically the same scattering angle $$\mbox{ $\vartheta $2r}$$. This contribution to the cross section tends to $$\infty $$ at this angle. When an observer sees a cloud of water drops illuminated by the sun, especially bright light rays arrive along the cone with angle $$\pi -\mbox{ $\vartheta $2r}$$. Usually, only a part of the circle is seen (the full circle can be sometimes observed from an airplane).

The scattering angle at $$\rho = 1$$ is

Now we have to solve the equation $$\alpha -2\beta = (\vartheta -\pi )/2$$ for $$\rho$$.

The solution number 3 is the smaller one; number 4 is the larger one (1 and 2 are negative).

In order to scatter between $$\vartheta$$ and $$\vartheta +\mathrm{d}\vartheta$$, the incident ray has to hit one of the two rings, $$\mbox{ $\sigma $2a}$$ or (if $$\vartheta < \mbox{ $\vartheta $2m}$$) $$\mbox{ $\sigma $2b}$$.

The angles $$\alpha$$ and $$\beta$$ in these two cases are

The differential cross sections for the two polarizations are

The considered contributions (0, 1, 2 ray segments inside the drop) to the cross sections with the s, p polarizations, as well as their sums, are

Of course, there are also higher contributions, not included here. The cross section is small for scattering angles below the rainbow peak; i.e., the sky just outside the rainbow is darker.

Near the rainbow peak, the last contribution (2 ray segments) is dominant; the ratio of the s and p polarizations is

The rainbow light is highly linearly polarized, with the electric field orthogonal to the scattering plane, i.e., along the rainbow. The reason is that the incidence angle $$\beta$$ of the ray which is about to reflect from the inner surface of the drop

is close to the Brewster angle

23.5 L Ray Segments Inside the Drop

Repeating the arguments from the previous sections, we obtain the direction of the outgoing ray $$\mbox{ $\vartheta $L} = 2(\beta -\alpha ) - (L - 1)(\pi -2\beta )$$:

Scattering angles for $$L = 0$$, 1, 2, 3, 4 as functions of $$\rho$$ are

Naturally, those with even $$L$$ start from $$\pi$$ at $$\rho = 0$$; for odd $$L$$ they start from 0. For $$L \geq 2$$ each one has a single extremum:

These extrema produce rainbows at the angles (in degrees)

The angles at which an observer sees the first and the second rainbow are

The sky is somewhat darker between the first rainbow and the second one, because neither rays with $$L = 2$$ nor those with $$L = 3$$ come from these directions.

Until now, we discussed monochromatic light. Then each rainbow is just a bright arc of the same color. In fact, the refraction index of water $$n$$ depends on the color (wavelength) of light (dispersion). It is larger for violet light than for red one. Therefore the positions of the maxima of intensity of the scattered light also depend on the color.

We see that the order of colors in the second rainbow is opposite to that in the first one; and the second rainbow is wider.

The ratios of s and p polarizations at the rainbow peaks are

Higher rainbows are not so strongly polarized as the first one, because the incidence angle for the reflections inside the drop is not so close to the Brewster angle.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_24© Springer International Publishing Switzerland 2014

24. Cyclohexane

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Cyclohexane molecule contains 6 C atoms connected cyclically by single chemical bonds; 2 H atoms are attached to each carbon one. Single bonds of a C atom have a fixed length and form fixed angles: if the C atom is put to the center of a tetrahedron, then its single bonds point to its vertices. The problem is: how many geometrical configurations (conformations, as chemists call them) of the cyclohexane molecule exist—one, several, or infinitely many (and if so, what is the dimensionality of this set).

24.1 Statement of the Problem

Cyclohexane molecule contains 6 C atoms connected cyclically by single chemical bonds; 2 H atoms are attached to each carbon one. Single bonds of a C atom have a fixed length and form fixed angles: if the C atom is put to the center of a tetrahedron, then its single bonds point to its vertices. The problem is: how many geometrical configurations (conformations, as chemists call them) of the cyclohexane molecule exist—one, several, or infinitely many (and if so, what is the dimensionality of this set).

Tetrahedron

What is the angle between single bonds? The unit vectors a[1], … a[4] (blue) are directed from the center of the tetrahedron (red) to its vertices.

Let’s check: the vectors are indeed unit and form equal angles with each other; hence all edges have equal lengths, so this is indeed a tetrahedron.

Cosine of the angle between these vectors is $$-1/3$$.

24.2 First Steps

Thus we have 6 vectors a[1], …, a[6] drawn from each C atom to the next one. They form a closed hexagon: $$a[1] + \cdots + a[6] = 0$$. Let the length of a single C–C bond be 1, then all the vectors are unit. Scalar products of neighboring vectors are 1 ∕ 3 (the sign has changed because now one of the vectors points in, not out). In order not to deal with the overall orientation of the molecule, let’s consider invariant quantities—cosines of the angles c[i, j] = a[i]. a[j].

Linear Equations

Multiplying the vector equality $$a[1] + \cdots + a[6] = 0$$ by each vector a[i], we get 6 linear equations for c[i, j].

Let’s take x = c[1, 3], y = c[3, 5], z = c[5, 1] as independent variables and express the remaining ones via them.

24.3 Equations

Generating Combinations

Now let’s recall that our vectors a[1], …, a[6] live in 3-dimensional space. Any 4 of them are linearly dependent. First we have to find a way to generate all 4-element lists made of the numbers from 1 to 6 in the increasing order. We shall accumulate them in the list L. The main work is done by the recursive function Gen. Its parameters: l—part of the list which has been already constructed; n—how many elements are to be added; a and b—boundaries of the interval from which numbers can be taken. If everything has been done (n = 0), the constructed list l is appended to the list of results L. Otherwise, we add each number i from the allowed interval to l and call Gen recursively to add n − 1 numbers. The upper limit of the loop is determined by the requirement to have at least n − 1 numbers in the interval from i + 1 to b.

It works. There are 15 4-combinations of 6 numbers.

Nonlinear Equations

For each set of 4 vectors, the determinant of the corresponding 4 ×4 submatrix of the matrix M (it is the square of the 4-dimensional volume spanned by these vectors) should be equal to 0.

These 15 polynomials of 3 variables must be equal to 0.

Gröbner Basis

Let’s find a simpler set of polynomials having the same solution set—the Gröbner basis.

Do they factorize?

24.4 Projection onto the x, y Plane

Allowed Region

First let’s find the projection of the solution set onto the x, y plane. What part of this plane are we interested in? First, x and y should lie between − 1 and 1; second,

should also lie between − 1 and 1.

That is, the allowed region is the triangle with the vertices $$(-1,-1)$$, $$(-1,1/3)$$, and $$(1/3,-1)$$.

Solutions with x =  − 1 ∕ 3

The second equation is satisfied at x =  − 1 ∕ 3. What about the other ones?

So, we have found the solutions $$x = y = z = -1/3$$; $$x = y = -1/3$$, $$z = -7/9$$; and $$x = z = -1/3$$, $$y = -7/9$$.

It is clear from the symmetry argument that $$y = z = -1/3$$, $$x = -7/9$$ is also a solution.

Other Solutions

The first equation contains only x and y.

This equation is quadratic in y.

Does c[2] vanish somewhere?

In our region c[2] > 0. The discriminant:

The discriminant is positive between $$x = -7/9$$ and

Two values of y (with $$\text{pm} = \pm 1$$) correspond to each x from this interval.

Do the points we found earlier lie on this curve?

Yes, they do. Let’s denote these points A, B, C.

So, all solutions we are interested in project onto this curve in the x, y plane.

We shall need a few extra points on this curve. Let’s find the second intersection with the diagonal x = y (the first one is the point A).

Let’s call this point D.

Finally, let’s introduce some additional point between A and B (rather arbitrarily; e.g., let it have $$x = -1/4$$) and call it E. Let its mirror image be the point F.

This is shown in the plot.

What’s the reason for introducing the points D, E, F? Now it is easy to write down our curve parametrically. For t ∈ [0, 1] let the point move from F to A, the motion along x being uniform.

For t ∈ [1, 2] let the point move from A to E; this segment is mirror-symmetric to the previous one.

For t ∈ [2, 3] the point moves from E to D, the motion along x being uniform.

Finally, for t ∈ [3, 4] the point moves from D to F; this segment is mirror-symmetric to the previous one.

Later we shall join these segments and construct a parametric curve in the 3-dimensional space x, y, z.

24.5 Complete Analysis of the Solutions

How to find the value (or values) of z corresponding to some point x, y on our curve? It is easiest to use the second equation—it is linear in z.

Does c[1] vanish somewhere in our region?

No, it does not.

So there is a single solution:

And what about the third and fourth equations?

They are satisfied automatically. What z corresponds to $$x = y = -1/3$$?

So, one of the solutions found earlier, namely $$x = y = z = -1/3$$, does not belong to our one-dimensional family of solutions. To summarize: we have found one isolated solution plus a one-dimensional family of solutions. In the parametric form:

You can rotate this plot with your mouse to understand it better.

24.6 Shape of the Molecule

What does the cyclohexane molecule look like? Let’s direct the x-axis along a[1]:

Let a[2] lie in the x, y plane:

That is,  the unit vector along y is a combination of a[1] and a[2]:

The projections of a[3] onto x and y are c[1, 3] = x and

The projection of a[3] onto the z axis can be found from normalization:

where pm =  ± 1. Two molecule shapes correspond to a single set of values of x, y, z; they differ by the mirror reflection of the z coordinates. We shall discuss this matter in a moment.

That is,  the unit vector along the z axis is a combination of a[1], a[2], a[3]:

The rest is easy.

Let’s write a function which constructs the molecule for a given values of x, y, z and of the sign pm.

This is the isolated conformation of the cyclohexane molecule with $$x = y = z = -1/3$$. Use your mouse to understand it better.

And this is the one-parameter family of conformations. To ensure smooth dependence on t, it is necessary to flip the sign pm when passing through the point C (where the expression under the radical sign vanishes). This happens at

So, the molecule returns to its initial shape after we traverse the loop in the x, y, z space twice. You can see this conformation family especially clearly if you start animation.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​: http:​/​/​function.​wolfram.​com/​

Andrey GrozinGraduate Texts in PhysicsIntroduction to Mathematica® for Physicists201410.1007/978-3-319-00894-3_25© Springer International Publishing Switzerland 2014

25. Problems for Students

Andrey Grozin1 

(1)

Theory Division, Budker Institute of Nuclear Physics, Novosibirsk, Russia

Abstract

Write a procedure which returns the hydrogen wave function (in spherical coordinates, i. e., an expression containing r, θ, ϕ) for given quantum numbers n, l, m. Write a procedure to calculate the rate of the electric dipole transition [22] from the state n, l, m to the state n′, l′, m′.

1.

Write a procedure which returns the hydrogen wave function (in spherical coordinates, i. e., an expression containing r, θ, ϕ) for given quantum numbers n, l, m. Write a procedure to calculate the rate of the electric dipole transition [22] from the state n, l, m to the state n′, l′, m′.

2.

Calculate Poisson brackets of the Hamiltonian, the angular momentum components, and the Runge–Lenz vector components [19] for a particle in the Coulomb field $$U = -a/r$$. Calculate commutators of the same quantities in quantum mechanics [18].

3.

The hypergeometric function [23, 24, 27] is defined as the sum of the series

where $$(x)_{n} = x(x + 1)\cdots (x + n - 1)$$ is the Pochhammer symbol. In many cases it can be expressed via simpler functions. Write a list of substitutions for simplifying hypergeometric functions. It is sufficient to consider only simplifications valid for an arbitrary x (not for specific values) where results are expressed via elementary functions. More general substitutions should be near the beginning of the list, then their particular cases can be eliminated.

4.

Consider indefinite integrals of the form

where A(x) and B(x) are rational functions of x. Mathematica can calculate such integrals, but often produces results in which some terms have imaginary parts in the region of x we are interested in. It is not easy to trace their cancellations. We’ll suppose that A(x) and B(x) contain no parameters (except x), only numbers. We’ll also suppose that Mathematica is able to find all roots of the denominator of A(x), as well as of the numerator and the denominator of B(x), and all these roots are real. We are interested in a neighborhood of some point x ₀; we want to get a result all terms of which are real near this point (if this is possible, of course). Implement the following obvious approach:

Expand A(x) into partial fractions with respect to x.

Replace logB(x) by a combination of terms log(x − a i ) and log(a i  − x) (plus a constant) in such a way that they are all real near x ₀.

Multiply.

Take integrals of x n log(x − a) (n ≥ 0), $$\log (x - a)/{(x - b)}^{n}$$ (n ≥ 2) by parts to eliminate the logarithm. Don’t use the Mathematica integrator—it can produce log(x − a) where log(a − x) is needed.

We are left with the most difficult terms of the forms $$\log (x - a)/(x - b)$$ and $$\log (a - x)/(x - b)$$. By linear substitutions they reduce to 3 cases:

where y is positive near x = x ₀ (the third formula is the definition of Li₂(y); the first one follows from it using the substitution y → − y; the second one—using integration by parts).

The result must be real (log(x) is real at x > 0; Li₂(x)—at x < 1). If this is impossible, print an error message.

5.

Implement the algebra of Boolean expressions. They consist of the constants true and false, variables, the function not (one argument), and the functions and, or (an arbitrary number of arguments). The last two functions are commutative and associative. Take into account simplifications when one of the arguments is true or false; when two arguments coincide or equal to a and not[a]. Expressions should be reduced to the disjunctive normal form: “or” at the top level; its arguments can be “and”; their arguments can be “not” or variables.

6.

Implement the algebra of quaternions.

7.

Implement Dirac γ-matrix expressions, including trace calculations (in 4 dimensions [22] or in the general case of dimensional regularization, see, e.g., [24]). Pay no attention to efficiency.

8.

Implement calculation of color factors of Feynman diagrams for the color group SU(N c ) using the Cvitanović algorithm [27] (see also [24]).

9.

Write a procedure to calculate two-loop massless propagator diagrams using integration by parts (see, e.g., [24]). Results should be linear combinations of the two basis integrals.

10.

Hypergeometric functions whose argument is 1 and whose parameters contain a small parameters ε and tend to integers at ε → 0 can be expanded in series in ε. The algorithm is described, e.g., in [24]; implement it.

11.

Any polynomial over the field of complex numbers can be factorized into linear factors:

where a i are its roots and d i are their multiplicities (to simplify formulas, we have assumed that the leading coefficient is 1). Let’s group factors with equal d i :

where all d i are distinct and the polynomials p i (x) have only simple zeros (are square-free). This square-free factorization can be obtained by a simple algorithm which uses only gcd (this is much simpler than the full factorization). Namely,

Indeed, the polynomial p(x) has zero of the order d i at x → a i , and its derivative p′(x) has zero of the order d i  − 1. Write a function to calculate square-free factorization using only gcd.

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)CrossRef

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)CrossRef

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6, 231 (1988)MathSciNetCrossRef

15.

Fateman, R.J.: A review of Mathematica. J. Symbolic Comput. 13, 545 (1992). (http:​/​/​www.​cs.​berkeley.​edu/​∼fateman/​papers/​mma.​pdf); http:​/​/​www.​cs.​berkeley.​edu/​∼fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)CrossRef

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

http:​/​/​function.​wolfram.​com/​

26.

Grozin, A.G.: Lectures on QED and QCD: Practical calculation and renormalization of one- and multi-loop Feynman diagrams. World Scientific (2007)

27.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​:

Andrey GrozinGraduate Texts in Physics Introduction to Mathematica ® for Physicists 201410.1007/978-3-319-00894-3© Springer International Publishing Switzerland 2014

References

1.

Buchberger, B., Collins, G.E., Loos, R. (ed.): Computer Algebra: Symbolic and Algebraic Computation, 2nd edn. Springer, Vienna (1983)

2.

Davenport, J.H., Siret, Y., Tournier, E.: Computer Algebra: Systems and Algorithms for Algebraic Computation, 2nd edn. Academic Press, London (1993)

3.

Geddes, K.O., Czapor, S.R., Labahn, G.: Algorithms for Computer Algebra. Kluwer Academic Publishers, Boston (1992)

4.

von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 2nd edn. Cambridge University Press, Cambridge (2003)

5.

Grozin, A.G.: Using REDUCE in High Energy Physics. Cambridge University Press, New York (1997); paperback edition (2005)

6.

Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Champaign (2003)

7.

Trott, M.: The Mathematica GuideBook for Symbolics. Springer Science+Business Media, Inc., New York (2006)

8.

Trott, M.: The Mathematica GuideBook for Numerics. Springer Science+Business Media, Inc., New York (2006)

9.

Trott, M.: The Mathematica GuideBook for Graphics. Springer, New York (2004)

10.

Trott, M.: The Mathematica GuideBook for Programming. Springer, New York (2004)

11.

Mangano, S.: Mathematica Cookbook, O’Reilly Media, Inc., Sebastopol, CA (2010)

12.

Cox, D., Little, J., O’Shea, D.: Ideals, Varieties, and Algorithms, 3rd edn. Springer, New York (2007)

13.

Arzhantsev, I.V.: Gröbner Bases and Systems of Algebraic Equations (in Russian), 3rd edn. MCCMO, Moscow (2003). http:​/​/​www.​mccme.​ru/​free-books/​dubna/​arjantsev.​pdf

14.

Kredel, H., Weispfenning, V.: J. Symbolic Computing dimension and independent sets for polynomial ideals 6 , 231 (1988)

15.

Fateman, R.J.: A review of Mathematica . J. Symbolic Comput. 13 , 545 (1992). ( http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma.​pdf ); http:​/​/​www.​cs.​berkeley.​edu/​~fateman/​papers/​mma6rev.​pdf

16.

Bronstein, M.: Symbolic Integration I. Springer, Berlin (1997)

17.

Davenport, J.H.: On the integration of algebraic functions. In: Lecture notes in computer science, vol. 102. Springer, New York (1981)

18.

Landau, L.D., Lifshitz, E.M.: Quantum Mechanics: Non-relativistic Theory, 3rd edn. Butterworth-Heinemann, Oxford (1981)

19.

Landau, L.D., Lifshitz, E.M.: Mechanics, 3rd edn. Butterworth-Heinemann, Oxford (1982)

20.

Landau, L.D., Lifshitz, E.M.: The Classical Theory of Fields, 4th edn. Butterworth-Heinemann, Oxford (1980)

21.

Landau, L.D., Lifshitz, E.M., Pitaevskii, L.P.: Electrodynamics of Continuous Media, 2nd edn. Butterworth-Heinemann, Oxford (1995)

22.

Berestetskii, V.B., Lifshitz, E.M., Pitaevskii, L.P.: Quantum Electrodynamics, 2nd edn. Butterworth-Heinemann, Oxford (1982)

23.

Prudnikov, A.P., Brychkov, Yu.A., Marichev, O.I.: Integrals and Series, vol. 3, Chapter 7. Gordon and Breach, New York (1990)

24.

NIST Handbook of Mathematical Functions, ed. by F.W.J. Olver, D.W. Lozier, R.F. Boisvert, C.W. Clark, Cambridge University Press, Cambridge (2010). http:​/​/​dlmf.​nist.​gov/​

25.

http://functions.wolfram.com/

26.

Grozin, A.G.: Lectures on QED and QCD: Practical calculation and renormalization of oneand multi-loop Feynman diagrams. World Scientific (2007)

27.

Cvitanović, P.: Group Theory. Princeton University Press, Princeton (2008). http:​/​/​www.​nbi.​dk/​GroupTheory/​ : http:​/​/​function.​wolfram.​com/​

Index

Symbols

” ”

!=

.

/.

//.

/:

/;

::

:=

:>

;

;;

?

[[]]

[]

%

&&

_

_?

_.

__

___

̀

~~

{}

*=

++

+=

-=

−>

<<

<>

=!=

=

==

===

>>

∧:=

∧=

||

|

$Assumptions

$Context

$ContextPath

$KernelID

$Path

$RecursionLimit

A

Abort

Abs

Accuracy

AccuracyGoal

All

Antisymmetric

Apart

Appearance

Append

Apply

ArcSin

ArcTan

Array

Arrays

Assumptions

AtomQ

Attributes

Automatic

AxesLabel

B

Begin

BeginPackage

BesselI

Binomial

Blank

Block

Boxed

C

Cancel

CForm

Circle

Clear

ClearAll

Close

Coefficient

Collect

Complex

ComplexExpand

ComplexInfinity

ComposeSeries

CompoundExpression

Condition

ConditionalExpression

Cone

Conjugate

Context

ContourPlot

ContourPlot3D

Contours

Cos

Cot

Cross

Csc

Cycles

Cylinder

D

D

Darker

Dashed

DeclarePackage

Degree

DegreeLexicographic

Denominator

Derivative

Det

Dimensions

DirectedInfinity

Disk

DistributeDefinitions

Do

DSolve

E

E

Eigensystem

Eigenvalues

Eigenvectors

Element

EllipticF

End

EndPackage

Erfi

EulerSum

Evaluate

EvenQ

Exp

Expand

ExpandAll

Exponent

Extension

F

Factor

Factorial

False

FilePrint

FindIntegerNullVector

First

Fit

Flat

For

FortranForm

FractionalPart

FreeQ

FullForm

Function

G

Gamma

Get

Global

Graphics

Graphics3D

Greater

GroebnerBasis

H

Head

Hold

HoldAll

HoldFirst

Hypergeometric2F1Regularized

I

I

If

Im

Import

Indeterminate

Infinity

Inset

Integer

IntegerQ

Integrate

InterpolatingFunction

Inverse

InverseSeries

J

Join

JordanDecomposition

K

KroneckerDelta

L

Length

Line

LinearSolve

List

Listable

ListPlot

Log

LogIntegral

LogLogPlot

LogPlot

M

MachineNumberQ

MachinePrecision

Manipulate

Map

MatchQ

Matrices

MatrixForm

MatrixPower

MatrixQ

MatrixRank

Max

Message

Method

Min

Mod

Module

N

N

ND

NDSolve

NIntegrate

NLimit

Normal

Not

NResidue

NSeries

NSolve

NSum

NSumTerms

Null

NullSpace

NumberQ

Numerator

NumericalCalculus

NumericQ

O

OddQ

Opacity

OpenWrite

Options

OptionsPattern

OptionValue

OrderedQ

Orderless

OutputStream

P

Parallelize

ParametricPlot

ParametricPlot3D

Part

Pattern

Pi

Plot

Plot3D

PlotMarkers

PlotPoints

PlotRange

PlotStyle

Plus

Point

PointSize

PolyLog

PolynomialReduce

Power

Precision

PrecisionGoal

Prepend

Print

Put

Q

Quaternion

Quaternions

Quotient

R

Random

Rational

Re

Real

Reals

RegionPlot

RegionPlot3D

ReleaseHold

Remove

ReplaceAll

ReplaceRepeated

Rest

Rule

S

Save

Select

Series

SeriesCoefficient

SeriesData

Set

SetDelayed

Show

Simplify

Sin

Solve

Span

Sphere

Sqrt

StreamPlot

StringExpression

StringFreeQ

StringLength

StringMatchQ

StringReplace

StringSplit

Style

Sum

Switch

Symmetric

System

T

Table

Tan

TensorContract

TensorDimensions

TensorProduct

TensorRank

TensorReduce

TensorSymmetry

TeXForm

Text

Ticks

Times

Together

Tr

Transpose

TreeForm, (26

TrigExpand

TrigReduce

True

V

VectorPlot

VectorQ

Vectors

ViewPoint

W

Which

While

With

WorkingPrecision

Write

Z

Zeta