Instant Access to Doing Math with Python Use Programming to Explore Algebra Statistics Calculus and More 1st Edition Amit Saha ebook Full Chapters
Instant Access to Doing Math with Python Use Programming to Explore Algebra Statistics Calculus and More 1st Edition Amit Saha ebook Full Chapters
com
https://ebookmeta.com/product/doing-math-with-python-use-
programming-to-explore-algebra-statistics-calculus-and-
more-1st-edition-amit-saha/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/practical-weak-supervision-doing-more-
with-less-data-1st-edition-tok-wee-hyong-bahree-amit-filipi-senja/
ebookmeta.com
https://ebookmeta.com/product/algebra-and-geometry-with-python-1st-
edition-sergei-kurgalin/
ebookmeta.com
https://ebookmeta.com/product/christmas-a-story-1st-edition-zona-gale/
ebookmeta.com
Aircraft Performance: An Engineering Approach, 2nd Edition
Mohammad H Sadraey
https://ebookmeta.com/product/aircraft-performance-an-engineering-
approach-2nd-edition-mohammad-h-sadraey/
ebookmeta.com
https://ebookmeta.com/product/society-and-economy-in-colonial-
connecticut-jackson-turner-main/
ebookmeta.com
https://ebookmeta.com/product/unredacted-magazine-
issue-003-july-2022-3rd-edition-unredacted-magazine/
ebookmeta.com
https://ebookmeta.com/product/outsmart-your-studies-how-to-study-
effectively-hack-your-memory-and-learn-faster-william-wadsworth/
ebookmeta.com
https://ebookmeta.com/product/mathematics-and-its-history-3rd-edition-
john-stillwell/
ebookmeta.com
Bought To Carry His Heir Jane Porter
https://ebookmeta.com/product/bought-to-carry-his-heir-jane-porter/
ebookmeta.com
DOING MATH
EXPLORE MATH
WITH CODE
Doing Math with Python shows you how to use • Write programs to find derivatives and integrate
WITH PYTHON
Python to delve into high school–level math topics functions U S E P R O G R A M M I N G T O E X P L O R E A L G E B R A ,
like statistics, geometry, probability, and calculus.
Creative coding challenges and applied examples help S T A T I S T I C S , C A L C U L U S , AND MORE!
You’ll start with simple projects, like a factoring
you see how you can put your new math and coding
program and a quadratic-equation solver, and then
skills into practice. You’ll write an inequality solver, plot
create more complex projects once you’ve gotten
gravity’s effect on how far a bullet will travel, shuffle a
the hang of things. AMIT SAHA
deck of cards, estimate the area of a circle by throwing
Along the way, you’ll discover new ways to explore 100,000 “darts” at a board, explore the relationship
math and gain valuable programming skills that you’ll between the Fibonacci sequence and the golden ratio,
use throughout your study of math and computer and more.
science. Learn how to:
Whether you’re interested in math but have yet to dip
• Describe your data with statistics, and visualize it into programming or you’re a teacher looking to bring
with line graphs, bar charts, and scatter plots programming into the classroom, you’ll find that Python
makes programming easy and practical. Let Python
• Explore set theory and probability with programs for
handle the grunt work while you focus on the math.
coin flips, dicing, and other games of chance
ABOUT THE AUTHOR
• Solve algebra problems using Python’s symbolic math
functions Amit Saha is a software engineer who has worked
for Red Hat and Sun Microsystems. He created and
• Draw geometric shapes and explore fractals like
maintains Fedora Scientific, a Linux distribution for
the Barnsley fern, the Sierpiński triangle, and the
scientific and educational users. He is also the author
Mandelbrot set
of Write Your First Program (Prentice Hall Learning).
COVERS PYTHON 3
T H E F I N E ST I N G E E K E N T E RTA I N M E N T ™
w w w.nostarch.com
www.allitebooks.com
Doing Math with Python
www.allitebooks.com
www.allitebooks.com
Doing Math
with Python
Use Programming to
Explore Algebra, Statistics,
Calculus, and More!
b y Amit Sa ha
San Francisco
www.allitebooks.com
Doing Math with Python. Copyright © 2015 by Amit Saha.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
Printed in USA
First printing
19 18 17 16 15 1 2 3 4 5 6 7 8 9
ISBN-10: 1-59327-640-0
ISBN-13: 978-1-59327-640-9
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other
product and company names mentioned herein may be the trademarks of their respective owners. Rather
than use a trademark symbol with every occurrence of a trademarked name, we are using the names only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The information in this book is distributed on an “As Is” basis, without warranty. While every precaution
has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or
indirectly by the information contained in it.
www.allitebooks.com
To Protyusha, for never giving up on me
www.allitebooks.com
www.allitebooks.com
Brief Contents
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Afterword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
www.allitebooks.com
www.allitebooks.com
Conte nt s in De ta il
Acknowledgments xiii
Introduction xv
Who Should Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
What’s in This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Scripts, Solutions, and Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
1
Working with Numbers 1
Basic Mathematical Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Labels: Attaching Names to Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Different Kinds of Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Working with Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Getting User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Handling Exceptions and Invalid Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Fractions and Complex Numbers as Input . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Writing Programs That Do the Math for You . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Calculating the Factors of an Integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Generating Multiplication Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Converting Units of Measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Finding the Roots of a Quadratic Equation . . . . . . . . . . . . . . . . . . . . . . . . . . 20
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
#1: Even-Odd Vending Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
#2: Enhanced Multiplication Table Generator . . . . . . . . . . . . . . . . . . . . . . . . 23
#3: Enhanced Unit Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
#4: Fraction Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
#5: Give Exit Power to the User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2
Visualizing Data with Graphs 27
Understanding the Cartesian Coordinate Plane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Working with Lists and Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Iterating over a List or Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Creating Graphs with Matplotlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Marking Points on Your Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Graphing the Average Annual Temperature in New York City . . . . . . . . . . . . . 35
Comparing the Monthly Temperature Trends of New York City . . . . . . . . . . . . 38
Customizing Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Saving the Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Plotting with Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Newton’s Law of Universal Gravitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Projectile Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
#1: How Does the Temperature Vary During the Day? . . . . . . . . . . . . . . . . . . 55
#2: Exploring a Quadratic Function Visually . . . . . . . . . . . . . . . . . . . . . . . . . 55
www.allitebooks.com
#3: Enhanced Projectile Trajectory Comparison Program . . . . . . . . . . . . . . . . 56
#4: Visualizing Your Expenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
#5: Exploring the Relationship Between
the Fibonacci Sequence and the Golden Ratio . . . . . . . . . . . . . . . . . . . . . 59
3
Describing Data with Statistics 61
Finding the Mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Finding the Median . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Finding the Mode and Creating a Frequency Table . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Finding the Most Common Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Finding the Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Creating a Frequency Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Measuring the Dispersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Finding the Range of a Set of Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Finding the Variance and Standard Deviation . . . . . . . . . . . . . . . . . . . . . . . . 72
Calculating the Correlation Between Two Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Calculating the Correlation Coefficient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
High School Grades and Performance on College Admission Tests . . . . . . . . . 78
Scatter Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Reading Data from Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Reading Data from a Text File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Reading Data from a CSV File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
#1: Better Correlation Coefficient–Finding Program . . . . . . . . . . . . . . . . . . . . 89
#2: Statistics Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
#3: Experiment with Other CSV Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
#4: Finding the Percentile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
#5: Creating a Grouped Frequency Table . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4
Algebra and Symbolic Math with SymPy 93
Defining Symbols and Symbolic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Working with Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Factorizing and Expanding Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Pretty Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Substituting in Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Converting Strings to Mathematical Expressions . . . . . . . . . . . . . . . . . . . . . . 103
Solving Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Solving Quadratic Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Solving for One Variable in Terms of Others . . . . . . . . . . . . . . . . . . . . . . . . 106
Solving a System of Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Plotting Using SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Plotting Expressions Input by the User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Plotting Multiple Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
#1: Factor Finder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
#2: Graphical Equation Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
#3: Summing a Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
#4: Solving Single-Variable Inequalities . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
x Contents in Detail
5
Playing with Sets and Probability 121
What’s a Set? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Set Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Subsets, Supersets, and Power Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Set Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Probability of Event A or Event B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Probability of Event A and Event B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Generating Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Nonuniform Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
#1: Using Venn Diagrams to Visualize Relationships Between Sets . . . . . . . . . 140
#2: Law of Large Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
#3: How Many Tosses Before You Run Out of Money? . . . . . . . . . . . . . . . . . 144
#4: Shuffling a Deck of Cards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
#5: Estimating the Area of a Circle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
6
Drawing Geometric Shapes and Fractals 149
Drawing Geometric Shapes with Matplotlib’s Patches . . . . . . . . . . . . . . . . . . . . . . . . 150
Drawing a Circle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Creating Animated Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Animating a Projectile’s Trajectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Drawing Fractals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Transformations of Points in a Plane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Drawing the Barnsley Fern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
#1: Packing Circles into a Square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
#2: Drawing the Sierpiński Triangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
#3: Exploring Hénon’s Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
#4: Drawing the Mandelbrot Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
7
Solving Calculus Problems 177
What Is a Function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Domain and Range of a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
An Overview of Common Mathematical Functions . . . . . . . . . . . . . . . . . . . . 178
Assumptions in SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Finding the Limit of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Continuous Compound Interest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Instantaneous Rate of Change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Finding the Derivative of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
A Derivative Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Calculating Partial Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Higher-Order Derivatives and Finding the Maxima and Minima . . . . . . . . . . . . . . . . . 188
Finding the Global Maximum Using Gradient Ascent . . . . . . . . . . . . . . . . . . . . . . . . 191
A Generic Program for Gradient Ascent . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
A Word of Warning About the Initial Value . . . . . . . . . . . . . . . . . . . . . . . . 196
The Role of the Step Size and Epsilon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Contents in Detail xi
Finding the Integrals of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Probability Density Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
What You Learned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Programming Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
#1: Verify the Continuity of a Function at a Point . . . . . . . . . . . . . . . . . . . . . 205
#2: Implement the Gradient Descent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
#3: Area Between Two Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
#4: Finding the Length of a Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Afterword 209
Things to Explore Next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Project Euler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Python Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
A
Software Installation 213
Microsoft Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Updating SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Installing matplotlib-venn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Starting the Python Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Updating SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Installing matplotlib-venn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Starting the Python Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Updating SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Installing matplotlib-venn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Starting the Python Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
B
Overview of Python Topics 221
if __name__ == '__main__' . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
List Comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Dictionary Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Multiple Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Specifying Multiple Exception Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
The else Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Reading Files in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Reading All the Lines at Once . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Specifying the Filename as Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Handling Errors When Reading Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Reusing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Index 237
xii Contents in Detail
Ac k n o w l ed g me n t s
I would like to thank everyone at No Starch Press for making this book
possible. From the first emails discussing the book idea with Bill Pollock
and Tyler Ortman, through the rest of the process, everyone there has
been an absolute pleasure to work with. Seph Kramer was amazing with his
technical insights and suggestions and Riley Hoffman was meticulous in
checking and re-checking that everything was correct. It is only fair to say
that without these two fine people, this book wouldn’t have been close to
what it is. Thanks to Jeremy Kun and Otis Chodosh for their insights and
making sure all the math made sense. I would also like to thank the copy-
editor, Julianne Jigour, for her thoroughness.
SymPy forms a core part of many chapters in this book and I would
like to thank everyone on the SymPy mailing list for answering my queries
patiently and reviewing my patches with promptness. I would also like to
thank the matplotlib community for answering and clearing up my doubts.
I would like to thank David Ash for lending me his Macbook, which
helped me when writing the software installation instructions.
I also must thank every writer and thinker who inspired me to write,
from humble web pages to my favorite books.
I n t r o duc t i o n
xvi Introduction
• Chapter 4, Algebra and Symbolic Math with SymPy, introduces sym-
bolic math using the SymPy library. It begins with the basics of repre-
senting and manipulating algebraic expressions before introducing
more complicated matters, such as solving equations.
• Chapter 5, Playing with Sets and Probability, discusses the representa-
tion of mathematical sets and moves on to basic discrete probability.
You’ll also learn to simulate uniform and nonuniform random events.
• Chapter 6, Drawing Geometric Shapes and Fractals, discusses using
matplotlib to draw geometric shapes and fractals and create animated
figures.
• Chapter 7, Solving Calculus Problems, discusses some of the math-
ematical functions available in the Python standard library and SymPy
and then introduces you to solving calculus problems.
• Appendix A, Software Installation, covers installation of Python 3,
matplotlib, and SymPy on Microsoft Windows, Linux, and Mac OS X.
• Appendix B, Overview of Python Topics, discusses several Python
topics that may be helpful for beginners.
Introduction xvii
1
W o r k i n g w i t h Numbe r s
www.allitebooks.com
Figure 1-1: Python 3 IDLE shell
>>> 1 + 2
3
>>> 1 + 3.5
4.5
>>> -1 + 2.5
1.5
>>> 100 – 45
55
>>> -1.1 + 5
3.9
>>> 3 * 2
6
>>> 3.5 * 1.5
5.25
>>> 3 / 2
1.5
>>> 4 / 2
2.0
As you can see, when you ask Python to perform a division operation,
it returns the fractional part of the number as well. If you want the result in
the form of an integer, with any decimal values removed, you should use the
floor division (//) operator:
>>> 3 // 2
1
2 Chapter 1
The floor division operator divides the first number by the second
number and then rounds down the result to the next lowest integer. This
becomes interesting when one of the numbers is negative. For example:
>>> -3 // 2
-2
The final result is the integer lower than the result of the division oper-
ation (-3/2 = -1.5, so the final result is -2).
On the other hand, if you want just the remainder, you should use the
modulo (%) operator:
>>> 9 % 2
1
You can calculate the power of numbers using the exponential (**)
operator. The examples below illustrate this:
>>> 2 ** 2
4
>>> 2 ** 10
1024
>>> 1 ** 10
1
We can also use the exponential symbol to calculate powers less than 1.
For example, the square root of a number n can be expressed as n1/2 and the
cube root as n1/3 :
>>> 8 ** (1/3)
2.0
>>> 5 + 5 * 5
30
>>> (5 + 5) * 5
50
u >>> a = 3
>>> a + 1
4
v >>> a = 5
>>> a + 1
6
>>> type(3)
<class 'int'>
>>> type(3.5)
<class 'float'>
>>> type(3.0)
<class 'float'>
4 Chapter 1
Here, you can see that Python classifies the number 3 as an integer
(type 'int') but classifies 3.0 as a floating point number (type 'float'). We
all know that 3 and 3.0 are mathematically equivalent, but in many situa-
tions, Python will treat these two numbers differently because they are two
different types.
Some of the programs we write in this chapter will work properly only
with an integer as an input. As we just saw, Python won’t recognize a num-
ber like 1.0 or 4.0 as an integer, so if we want to accept numbers like that
as valid input in these programs, we’ll have to convert them from floating
point numbers to integers. Luckily, there’s a function built in to Python that
does just that:
>>> int(3.8)
3
>>> int(3.0)
3
The function int() takes the input floating point number, gets rid of
anything that comes after the decimal point, and returns the resulting inte-
ger. The float() function works similarly to perform the reverse conversion:
>>> float(3)
3.0
float() takes the integer that was input and adds a decimal point to
turn it into a floating point number.
Now you know the basics of working with fractions in Python. Let’s
move on to a different kind of number.
Complex Numbers
The numbers we’ve seen so far are the so-called real numbers. Python also
supports complex numbers with the imaginary part identified by the letter j
or J (as opposed to the letter i used in mathematical notation). For example,
the complex number 2 + 3i would be written in Python as 2 + 3j:
>>> a = 2 + 3j
>>> type(a)
<class 'complex'>
As you can see, when we use the type() function on a complex number,
Python tells us that this is an object of type complex.
You can also define complex numbers using the complex() function:
>>> a = complex(2, 3)
>>> a
(2 + 3j)
Here we pass the real and imaginary parts of the complex number as
two arguments to the complex() function, and it returns a complex number.
You can add and subtract complex numbers in the same way as real
numbers:
>>> b = 3 + 3j
>>> a + b
(5 + 6j)
>>> a - b
(-1 + 0j)
6 Chapter 1
Multiplication and division of complex numbers are also carried out
similarly:
>>> a * b
(-3 + 15j)
>>> a / b
(0.8333333333333334 + 0.16666666666666666j)
The modulus (%) and the floor division (//) operations are not valid for
complex numbers.
The real and imaginary parts of a complex number can be retrieved
using its real and imag attributes, as follows:
>>> z = 2 + 3j
>>> z.real
2.0
>>> z.imag
3.0
The conjugate of a complex number has the same real part but an imagi-
nary part with an equal magnitude and an opposite sign. It can be obtained
using the conjugate() method:
>>> z.conjugate()
(2 - 3j)
Both the real and imaginary parts are floating point numbers. Using the
real and imaginary parts, you can then calculate the magnitude of a complex
number with the following formula, where x and y are the real and imaginary
parts of the number, respectively: . In Python, this would look like
the following:
>>> abs(z)
3.605551275463989
The standard library’s cmath module (cmath for complex math) provides
access to a number of other specialized functions to work with complex
numbers.
u >>> a = input()
v 1
At u, we call the input() function, which waits for you to type something,
as shown at v, and press enter. The input provided is stored in a:
>>> a
w '1'
>>> a = '1'
>>> int(a) + 1
2
>>> float(a) + 1
2.0
These are the same int() and float() functions we saw earlier, but this
time instead of converting the input from one kind of number to another,
they take a string as input ('1') and return a number (2 or 2.0). It’s impor-
tant to note, however, that the int() function cannot convert a string con-
taining a floating point decimal into an integer. If you take a string that has
a floating point number (like '2.5' or even '2.0') and input that string into
the int() function, you’ll get an error message:
>>> int('2.0')
Traceback (most recent call last):
8 Chapter 1
File "<pyshell#26>", line 1, in <module>
int('2.0')
ValueError: invalid literal for int() with base 10: '2.0'
>>> a = float(input())
3/4
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
a=float(input())
ValueError: could not convert string to float: '3/4'
>>> try:
a = float(input('Enter a number: '))
except ValueError:
print('You entered an invalid number')
The user will now see the message hinting to enter an integer as input:
Input an integer: 1
In many programs in this book, we’ll ask the user to enter a number
as input, so we’ll have to make sure we take care of conversion before we
attempt to perform any operations on these numbers. You can combine the
input and conversion in a single statement, as follows:
>>> a = int(input())
1
>>> a + 1
2
This works great if the user inputs an integer. But as we saw earlier, if
the input is a floating point number (even one that’s equivalent to an inte-
ger, like 1.0), this will produce an error:
>>> a = int(input())
1.0
Traceback (most recent call last):
File "<pyshell#42>", line 1, in <module>
a=int(input())
ValueError: invalid literal for int() with base 10: '1.0'
In order to avoid this error, we could set up a ValueError catch like the
one we saw earlier for fractions. That way the program would catch float-
ing point numbers, which won’t work in a program meant for integers.
However, it would also flag numbers like 1.0 and 2.0, which Python sees as
floating point numbers but that are equivalent to integers and would work
just fine if they were entered as the right Python type.
To get around all this, we will use the is_integer() method to filter out
any numbers with a significant digit after the decimal point. (This method
is only defined for float type numbers in Python; it won’t work with num-
bers that are already entered in integer form.)
Here’s an example:
>>> 1.1.is_integer()
False
10 Chapter 1
hand, when the method is called with 1.0 as the floating point number, the
result is True:
>>> 1.0.is_integer()
True
The ZeroDivisionError exception message tells you (as you already know)
that a fraction with a denominator of 0 is invalid. If you’re planning on hav-
ing users enter fractions as input in one of your programs, it’s a good idea
to always catch such exceptions. Here is how you can do something like that:
>>> try:
a = Fraction(input('Enter a fraction: '))
except ZeroDivisionError:
print('Invalid fraction')
www.allitebooks.com
Discovering Diverse Content Through
Random Scribd Documents
staff changed frequently. Generally speaking, with very few
exceptions, commanding officers received their instruction from the
staff of Commander in Chief U-boats after I myself had given them
their instructions. Commanding officers were generally speaking in
much closer personal contact with these young staff officers than
they were with myself as senior officer of a purely transit flotilla.
There were many commanding officers whom I only saw and got to
know for a few days in Kiel while they were fitting their boats out for
operations.
Having given considerable thought to the whole of this matter I now
remember that during one of my visits to Commander in Chief U-
boats' staff in the winter of 1942/3 or the summer '43, one of the
staff officers, Korvettenkapitaen Hessler or perhaps more likely
Korvettenkapitaen Kuppisch, with whom because of very close ties of
friendship I used to converse intimately as long as he was
Commander in Chief U-boats' staff, told me of the following
occurrence (whether I broached the subject or how the matter came
up I can no longer remember).
A type VII boat (500-tonner) reported in her war log that when
outward bound from a base in France, she met far out in the Bay of
Biscay a raft with five enemy airmen, but was not able to take them
on board owing to shortage of room (she had a complement of 54
and carried full provisions for 14 weeks). The boat therefore
proceeded without taking any notice of the survivors.
This action of the U-boat was vehemently denounced by the
Commander in Chief U-boats' staff. It was stated that she would
have acted more correctly in destroying this raft since it was highly
probable that the enemy air crew would be rescued by the enemy
and in the meantime might once more have destroyed a German U-
boat.
This occurrence made the views of the Commander in Chief U-boats
clear to me.
As concerns making the order known to commanding officers: the
order was always passed on during a commanding officers'
conference while their boats were having their final overhaul or
while they were being fitted out in Kiel for operational patrols;
during these conferences I passed on to commanding officers once
again all important orders about the equipping of their boats,
procedure on departure, in home waters and while in convoy to
Norway. Operational orders were not given by the flotilla; they were
always given by the Commander in Chief U-boats himself or by
Captain U-boats West on his behalf.
I was wont to pass on this controversial and serious order with more
or less the following words:—"I have now to inform you of a High
Command order concerning conduct towards survivors. It is a very
ticklish matter. Commander in Chief U-boats in September 1942 gave
the following order in an 'officers only' signal ( ... the exact words of
the order were then read out)."
Since I am myself in my innermost conscience in disagreement with
this order, I was very glad that in most cases commanding officers
raised no queries and I was therefore relieved of any further
discussion on this point.
Sometimes however queries were raised and I was wont to answer
somewhat as follows:—
"I will explain the viewpoint of the High Command, which gave this
order, by reference to the following event": I then mentioned the
example of the Type VII boat in the Bay of Biscay together with the
explanation and viewpoint expressed to me by Commander in Chief
U-boats' staff. I then went on to say, "Gentlemen, you must
yourselves decide what is compatible with own consciences. The
safety of your own boat must always remain your prime
consideration."
Since the introduction of total underwater war ("Schnorchel"), I have
in this connection in various ways further stated that commanding
officers were in a much easier position in this respect since they had
no occasion to surface and that the order was therefore illusory for
them. They had to keep clear of everything which was not worth the
firing of a torpedo.
I also remember that many commanding officers after the order of
September 1942 had been read said, "That is quite clear and
unequivocal however hard it may be". Had this order been given to
me as a commanding officer I would have taken note of it in silence
but in practice would always have been able with a clear conscience
not to carry it out since I consider I would endanger my own boat by
acting in this way, (i.e., by shooting at life-boats).
If therefore U-boat commanding officers state that they had received
from me the order to destroy life-boats, this does not correspond
with the facts, but they received from me quite insufficiently clearly
expressed instructions from the High Command together with my
personal views thereon.
Before the order of September 1942 was issued I never discussed
this difficult question at a commanding officers' conference and the
subject of conduct towards survivors was never broached.
B. Conduct Towards Neutral and Hospital Ships
On this matter, which I treated together with what has gone before,
I gave commanding officers the following directions:
There was an express order of the High Command, and Commander
in Chief U-boats was adamant on this point and would relentlessly
pursue the breach of it by court martial (i.e., he insisted on the order
being strictly obeyed), that no neutral or Red Cross ship might be
molested even if the enemy misused neutral flags or the Red Cross.
The political results of sinking a neutral were much more serious
than would have been the usefulness of the tonnage sunk.
I told commanding officers for their guidance in doubtful cases—in
bad visibility, when neutral markings were not distinct, etc.—that it
was better to allow five enemy vessels to go free than to sink one
neutral.
So far as concerns the stopping and examination of neutrals, an
order was made in January 1944 that in particular Spanish and
Portuguese steamers in the North and Central Atlantic were to be
stopped and examined for contraband and members of enemy
nations of military age. I told commanding officers "Don't touch
them. Stay underwater. You are endangering yourselves too much by
that because you will certainly be reported by wireless and we know
from experience that when such examinations are made
watchfulness is liable to suffer. You are only exposing yourself to the
danger of being surprised. If a ship carries neutral markings let it go
by unscathed."
Objection was often made that German hospital ships had often
been destroyed by the enemy, as German propaganda had stressed
for years. My answer was: That does not matter, however
unpleasant it may be. The order of the High Command is decisive
and binding. Politics come before warfare.
C. Rendering of Reports
There was an order—I do not remember whether it was in the form
of a written or verbal instruction—that no events during a war patrol
which contravened established international agreements should be
entered in the war log. I believe that the reason for this order was
that eight copies were made of war logs and were available to many
authorities; there was always the danger therefore that events of
this nature would become known and it was undoubtedly
undesirable for reasons of propaganda that this should be so.
Events of this nature were only to be reported if asked for when
commanding officers made their personal reports; these were
invariably made after every patrol to Commander in Chief U-boats or
later in certain instances to Captain U-boats.
I also gave the commanding officers instructions on this point.
To conclude, I can only stress that the order of September 1942
appeared to me personally to go too far and I am in total
disagreement with it at heart. As a serving officer I had however to
carry out the command to pass on this order to commanding officers
for their instruction.
During the long time that I was senior officer of the Flotilla no single
commanding officer mentioned to me that he could not reconcile
obedience to this order with his conscience and that he was
therefore unable to carry it out.
An order of this nature was never given by me, i.e. on my own
initiative, and could not be given by me since, had I exceeded my
authority in so serious a way, I would immediately and without
question have been relieved.
[signed] MOEHLE
Korvettenkapitaen
TRANSLATION OF DOCUMENT
386-PS
Berlin, 10 Nov 1937
Schm
[Major Schmundt's writing and initialled by him]
Written by an officer
[The following are handwritten notes]
22 April
A. POLITICAL POSSIBILITIES
1. Sudden surprise attack out of clear sky not possible. World
opinion can produce critical situation. Would be thinkable only for
ultimate conflict without the threat of other opponents.
2. Action after a period of tension and constant aggravation of the
situation.
3. Action as the result of an incident. (example)
B. MILITARY NECESSITIES
Cases 2 and 3 can be considered. In case 2 "security measures" will
be taken. Duration of transporting by rail to be looked into.
1. Invasion by columns ready to march at points which lie in a
direction, strategically important. (Permanent fortifications must be
known, columns assembled to suit particular situations, roads
reconnoitred.) Simultaneous attack by Luftwaffe, cooperation with
Luftwaffe, isolation of garrisons of the fortifications, cutting of
communications.
2. "Dead Space" in first 4 days prior to actual operation must be
avoided under all circumstances. Must be bridged through motorized
army. Penetrating via Pilsen. Hamper mobilization.
3. Separation of transport movement "Rot" and "Gruen",
a. in order not to aggravate "Rot",
b. but also so as not to arrive late, if necessary.
Basic Principle: Create Accomplished Facts so that
a. help comes too late—other powers do not intervene
b. Allies take part (like wolves also want something out of it)
c. State collapse from within.
Propaganda: Directions to Germans. Threats to others.
Submit:
1. Fortifications (strength in detail)
2. Distribution of nationalities within Wehrmacht.
[ITEM 4] [Telegram]
MBZ 05 17/5 1505
TO MAJOR SCHMUNDT, ARMED FORCES ADJUTANT TO THE
FUEHRER—MOST SECRET
IN ANSWER TO OBERST LEUTNANT ZEITZLER AND WITH REGARD
TO MAP OF FORTIFICATIONS:
FORTIFIED CONSTRUCTION CONSISTS OF FAIRLY LARGE NUMBER
OF STEEL AND CONCRETE FORTIFICATIONS AS WELL AS LIGHT,
MEDIUM AND HEAVY MG EMPLACEMENTS TO CLOSE GAPS
BETWEEN FORTIFICATIONS. NUMBER OF STEEL AND CONCRETE
FORTIFICATIONS VARIES FROM ONE TO NINE PER KILOMETER.
POSITIONS CONSTRUCTED CONSIST OF LIGHT, MEDIUM AND
HEAVY MG EMPLACEMENTS AND AN OCCASIONAL STEEL AND
CONCRETE FORTIFICATION IN BETWEEN. NUMBER OF MG
EMPLACEMENTS VARIES FROM TWO TO NINE PER KILOMETER.
BLOCK CONSTRUCTION CONSISTS OF LIGHT, SOMETIMES MEDIUM
AND HEAVY MG EMPLACEMENTS AT MAIN ROADS AND
THOROUGHFARES. DEFENSIVE POTENTIALITIES: STEEL AND
CONCRETE FORTIFICATIONS BULLET PROOF AGAINST ALL KNOWN
CALIBRES. LIGHT MG EMPLACEMENTS BULLET PROOF AGAINST ALL
CALIBRES UP TO 10.5 CM., MEDIUM MG EMPLACEMENTS BULLET
PROOF AGAINST CALIBRES UP TO 10.5 CM., HEAVY MG
EMPLACEMENT BULLET PROOF AGAINST CALIBRES UP TO 21.00
CM., SOMETIMES AGAINST THE LARGEST CALIBRES.
ZEITZLER OBERSTLEUTNANT ON THE GENERAL STAFF
MOST SECRET
My Fuehrer!
Effective 1 October 1938 (beginning of the new mobilization year for
the army) new strategic directives must be issued, whose political
bases and stipulations you, my Fuehrer, yourself intend to make.
For the meantime, however, it is necessary that the "Gruen" section
of the strategic directives be replaced by a new version that takes
into account the situation which has arisen as a result of the
incorporation of Austria into the Reich and the newly-suspected
intentions of the Czech General Staff.
A draft of this kind is attached. It has not yet been discussed with
the Commanders in Chief. I intend to do this only after this draft in
its fundamental ideas has been approved by you my Fuehrer, so that
it can then be resubmitted to be signed.
Heil, my Fuehrer
[signed] Keitel
written by an officer
MOST SECRET
S.O. Only
access only through officer
[ITEM 6] [Typescript]
Questions on "Gruen"
1. Peace-time strength of divisions prepared for march readiness.
2. Strength of mobile divisions.
3. Composition of 2nd Armored Division in the case of mobilization.
4. Strength, possibilities and composition of a motorized unit
(motorized divisions) to be used for independent thrust.
5. When can the field units be equipped with 15 cm. mortars?
6. What calibres and how large a number of artillery pieces are
available for combating fortifications such as fortresses?
MOST SECRET
L Ia
Berlin, 23 May
Questionnaire of 23 May
1. Peace-time strength of divisions prepared for march readiness.
Strength of a peacetime division 14,000 men
Strength of a division made ready to march 14,000 men
(but composition is different from that of a peacetime division, i.e.
some men are left out and others included).
2. Strength of mobile divisions.
Strength of a mobile division 17,000 men
3. Composition of the 2nd Armored Division in the case of
Mobilization. In the case of mobilization the 2nd Armored Division is
composed of 1 rifle brigade, one tank brigade and divisional troops.
The rifle brigade has one Infantry regiment motorized of 2 battalions
and one motorcycle rifle battalion.
The tank brigade has two tank regiments of two battalions.
The Divisional Troops will include 1 Artillery Regiment motorized of 2
light Battalions, 1 Reconnaissance Battalion motorized, 1 Anti-Tank
Battalion, 1 Engineer Battalion motorized, and 1 Signal Battalion
motorized.
Altogether the 2nd Armored Division (mobile) has 807 light Machine
guns, 250 heavy Machine guns, 18 light mortars, 12 heavy mortars,
8 light Infantry howitzers, 48 Anti-Tank guns, 122 2 cm. guns, 16 37
cm. guns, 16 7.5 cm. guns and 24 light field howitzers.
4. Strength, possibilities and composition of a motorized unit
(motorized divisions) for independent thrust. In the case of
mobilization, C-in-C Army is in command of the motorized units. C-
in-C Army must therefore be questioned as regards any new
employment.
Altogether the 1st, 2nd and 3rd Armored Divisions (rapid march
readiness is intended) 4 motorized divisions and the light division
(for the moment not yet intended for rapid march readiness;
presumably from 1 October).
5. When can the field units be equipped with 15 cm. mortars?
Mobilization of the infantry guns (= 15 cm. mortars) planned only for
the fall, as ammunition for them will only then be available. For
training purposes nearly all corps except the 3 corps have the heavy
infantry guns at the moment without live ammunition, however.
6. What calibres and how large a number of artillery pieces are
available for combatting fortifications such as fortresses? Only 21
cm. howitzers. Altogether 23 (of which 8 are in East Prussia) with
16,000 rounds (of which 4,000 in East Prussia).
[In Schmundt writing]: In general, single experimental artillery piece
(guns).
Z
[Initialled by Zeitzler]
[On next page the questions are put again, plus the following
additional questions:]
7. What do the individual types of Czechoslovakian permanent
frontier fortifications look like? Profile?
8. Is cooperation between infantry and bombers assured for attacks
against enemy strong points etc.?
9. Can the construction of fortifications in the West, in the form of
MG strong points and road blocks, be hastened by the employment
of work columns of the Inspector of Road Construction?
10. What progress has been made in the howitzer (Moerser)
programme? What progress has been made in the conversion of
heavy naval guns?
[Next three pages contain the first 6 questions above and answers
to them in a teleprint message, beginning: "I am answering several
questions which the Fuehrer put to me during conferences. I request
that you report the answers to the Fuehrer."]
[ITEM 8] [Telegram]
1. INFORM GENERAL KEITEL: THE FUEHRER IS GOING INTO
"GRUEN" IN DETAIL. BASIC IDEAS NOT CHANGED. SURPRISE
ELEMENT TO BE EMPHASIZED MORE. CONFERENCE WITH
PARTICIPANTS WILL TAKE PLACE AFTER RETURN, AT THE LATEST.
CONFERENCE HERE NOT OUT OF THE QUESTION. RETURN
PROBABLY BEGINNING NEXT WEEK.
2. INFORM COLONEL GENERAL VON BRAUCHITSCH AND GENERAL
KEITEL: