100% found this document useful (4 votes)
30 views

Practical Numerical Computing Using Python 1st Edition Mahendra Verma download

The document discusses the book 'Practical Numerical Computing Using Python' by Mahendra Verma, which serves as a comprehensive guide for advanced undergraduate and graduate students to learn numerical computing using Python. It covers various topics including programming basics, numerical methods, and practical applications in scientific computing. The book also provides resources for further learning and exercises to enhance programming skills.

Uploaded by

calinulloa6b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
30 views

Practical Numerical Computing Using Python 1st Edition Mahendra Verma download

The document discusses the book 'Practical Numerical Computing Using Python' by Mahendra Verma, which serves as a comprehensive guide for advanced undergraduate and graduate students to learn numerical computing using Python. It covers various topics including programming basics, numerical methods, and practical applications in scientific computing. The book also provides resources for further learning and exercises to enhance programming skills.

Uploaded by

calinulloa6b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Practical Numerical Computing Using Python 1st

Edition Mahendra Verma install download

https://ebookmeta.com/product/practical-numerical-computing-
using-python-1st-edition-mahendra-verma/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Practical Explainable AI Using Python: Artificial


Intelligence Model Explanations Using Python-based
Libraries, Extensions, and Frameworks Pradeepta Mishra

https://ebookmeta.com/product/practical-explainable-ai-using-
python-artificial-intelligence-model-explanations-using-python-
based-libraries-extensions-and-frameworks-pradeepta-mishra/

Architecture of Advanced Numerical Analysis Systems:


Designing a Scientific Computing System using OCaml 1st
Edition Liang Wang

https://ebookmeta.com/product/architecture-of-advanced-numerical-
analysis-systems-designing-a-scientific-computing-system-using-
ocaml-1st-edition-liang-wang/

The Practice of Computing Using Python 3 [Regular]


Edition William Punch Richard Enbody

https://ebookmeta.com/product/the-practice-of-computing-using-
python-3-regular-edition-william-punch-richard-enbody/

Intelligence in Energy 1st Edition Gülgün Kayakutlu

https://ebookmeta.com/product/intelligence-in-energy-1st-edition-
gulgun-kayakutlu/
Rational Points on Elliptic Curves 2nd Edition Joseph H
Silverman John T Tate

https://ebookmeta.com/product/rational-points-on-elliptic-
curves-2nd-edition-joseph-h-silverman-john-t-tate/

Heritage Culture and Identity 1st Edition Hamzah


Muzaini

https://ebookmeta.com/product/heritage-culture-and-identity-1st-
edition-hamzah-muzaini/

Contraception and Persecution 1st Edition Charles E


Rice Alyssa Bormes Steve Mosher

https://ebookmeta.com/product/contraception-and-persecution-1st-
edition-charles-e-rice-alyssa-bormes-steve-mosher/

Suits A Woman on Wall Street 1st Edition Nina Godiwalla

https://ebookmeta.com/product/suits-a-woman-on-wall-street-1st-
edition-nina-godiwalla/

Music and Mental Imagery 1st Edition Mats B. Küssner

https://ebookmeta.com/product/music-and-mental-imagery-1st-
edition-mats-b-kussner/
The Independent Republic of Arequipa Making Regional
Culture in the Andes Thomas F Love

https://ebookmeta.com/product/the-independent-republic-of-
arequipa-making-regional-culture-in-the-andes-thomas-f-love/
Contents

Preface
Chapter One
Introduction to Computing
Computer Hardware
Supercomputers & Computation Complexity
Computer Software
Brief Overview of Python
Anaconda Python, Notebooks, and Prutor
Applications of Computers
Chapter Two

Integers
Floating Point and Complex Numbers
Python Variables and Logical Variables
Chapter Three

Character & Strings


List
Numpy Arrays
Dictionary
Mutable and Immutable Objects in Python

Chapter Four
Simple Statements
Conditional Flows in Python
Looping in Python
Chapter Five

Functions in Python
Python Namespace and Scope
Recursive Functions
Chapter Six

Good Progamming Practices


Prime Numbers
Searching and Sorting
Chapter Seven

Matplotlib & Field Plots


Miscellaneous Plots
Animation using Python

Chapter Eight

Reading & Writing Text Files in Python


Reading & Writing Numerical Data in Python

Chapter Nine
Error Analysis
Nondimensionalization of Equations

Numerical Methods
Chapter Ten

Lagrange Interpolation
Splines
Chapter Eleven
Newton-Cotes Formulas
Gaussian Quadrature
Python's Quad & Multidimensional Integrals
Chapter Twelve
Computing Numerical Derivatives

Chapter Thirteen

General Overview
Euler Forward Method, Accuracy & Stability
Implicit Schemes
Higher-order Methods
Multistep Method
Solving a System of Equations
Stiff Equations

Chapter Fourteen

Fourier Transform
One-dimensional Discrete Fourier Transforms
Mutlidimensional Fourier Transform

Chapter Fifteen

Solving PDEs Using Spectral Method: Diffusion Equation


Solving Wave, Burgers, and KdV Equations
Spectral Solution of Naiver-Stokes Equation
Spectral Solution of Schrödinger Equation

Chapter Sixteen
General Overview & Diffusion Equation Solver
Solving Wave Equation
Burgers and Navier-Stokes Equations
Schrodinger equation
Chapter Seventeen

Root Finders
Chapter Eighteen
Shooting Method
Eigenvalue Calculation
Chapter Nineteen

Solving Laplace Equation


Solving Poisson Equation

Chapter Twenty

Solution of Algebraic Equations


Eigenvalues and Eigenvectors

Chapter Twenty-One

Random numbers
Integration Using Random Numbers
Regression Analysis
Applications in Statmech
Machine Learning

Epilogue
Appendix A: Errors in Lagrange Interopolation
Appendix B: Improving Accuracy Using Richardson Method
References
Preface

At present, friendly, yet, powerful tools have been developed for computer
programming. One such tool, the programming language Python is versatile, but
easy to learn. It is being used in wide range of applications: scientific computing,
data analysis, machine learning (ML) and artificial intelligence (AI), internet
programming, GUI, etc. At present, researchers are employing Python for
numerical computing, as well as for AI and ML.
Keeping this in mind, I chose Python as the programming language for
teaching numerical computing in my Computational Physics course
(PHY473A). I also use Python for post processing and for writing large
softwares including parallel programs. The present book is a compilation of the
course material and the tools developed in our computational laboratory. The
contents and the usage of the book is discussed below.

Contents of the book: The book has two parts. The first part covers the Python
programming language in a reasonable detail, while the second part contains the
numerical algorithms and associated Python codes. The book contains
discussions on important numerical tools: interpolation, integration,
differentiation, solvers for ordinary and partial differential equations, Fourier
transforms, boundary value problems, linear algebra, and Monte Carlo methods.
In addition, I also include plotting tools, error analysis, nondimensionalization,
and an overview of computer hardware and software.
The computer programs in the book have been tested. These codes are
available at the website https://sites.google.com/view/py-comp. The website will
also host affiliated material, such as PPTs, video lectures, color figures, etc.

Usage of the book: This book is suitable for advanced undergraduate and
graduate students. It does not assume any programming background, but it does
require basic understanding of calculus and differential equations. The material
could be covered in 40 lectures at a fast pace. However, I recommend that the
instructor and students can skip topics that they find complex or somewhat
unnecessary.
Programming is learnt by practice. Hence, I strongly urge the students to
program enthusiastically. One could start with the examples and then do all the
exercises of the book. In my course, we used Prutor (https://prutor.ai) for
evaluating the exercises submitted by the students. We plan to provide the
exercises of the book on Prutor.

Acknowledgements: For the significant contents of the book, I am grateful to


the PHY473A’s TAs (teaching assistants), especially Soumyadeep Chatterjee,
Abhishek Kumar, and Manohar Sharma. Special thanks to PHY473A’s
enthusiastic students, whose interesting questions led to clarity in the
presentation in the book. I also thank Mani Chandra for introducing me to
Python way back in 2008, and to the members of Simulation and Modelling
Laboratory (https://turbulencehub.org), where coding is done for fun.
Next, thanks to Python creator, Guido van Rossum, and many developers for
creating such a wonderful programming environment, that too for free! Also,
thanks to Anancoda for the free Python distribution, and to the creators of
Scrivener that has made writing a joy. I gratefully acknowledge Wikipedia and
Wikieducator for Figures 3, 4, 5, 33, and 138 of the book.
I am also thankful to my friends, Harshawardhan Wanare, Rajesh Ranjan,
Prateek Sharma, Anurag Gupta, Rahul Garg, and Prachi Garg for the
encouragement, and Manmohan Dewbanshi for help in the manuscript
preparation. Finally, I am grateful to pothi.com, especial Jaya Jha and Pratibha,
for the assistance in publication of this book, and for publishing it in India. The
front cover was prepared using Canva, while the full cover was designed by
pothi.com.

Feedback request: I request the readers to send their comments and feedback to
me at [email protected]. Even though I have strived to make this book error-free, I
am sure some lacuna still remain. I will be grateful if such errors are brought to
my attention.

Mahendra Verma
IIT Kanpur
CHAPTER ONE

Introduction

Synopsis

“Computers themselves, and software yet to be developed, will


revolutionize the way we learn.”
—Steve Jobs

This chapter gives a brief introduction to computer hardware and


software. We also describe how to install Python on computers.
INTRODUCTION TO COMPUTING

COMPUTER IS ONE device that has impacted all walks of life. It is employed
for scientific research, e-commerce, banking, cloud computing, etc. On a
personal level, we use computers for surfing internet, emailing, social
networking, etc. See Section Applications of Computers for some of the
computer applications.
ENIAC (Electronic Numerical Integrator and Computer, made in 1945) was
the first general-purpose digital computer. It was used for making Hydrogen
bomb and Monte Carlo simulations. A succession of better and faster computers
have been built since then. Scientists and engineers have used these machines for
research in physics, chemistry, biology, fluids, engineering, geophysics, and
astrophysics. In this book, we will focus on generic computation tools used in
science and engineering.
Both hardware and software have evolved leaps and bounds over the years.
In early days, Fortran, short form for Formula Translation, was the de facto
programming language for scientific applications. Even though Fortran is still a
dominant language in scientific programming, many scientists and engineers
have moved to modern languages such as C, C++, and Python. Among these
languages, Python has become very popular due to its simplicity and availability
of large number of Python modules. In this book, we will use Python language
for writing programs. An added benefit of Python is that it has excellent post-
processing tools, such as plotting, reading/writing data, etc. In addition, Python
is widely used in machine learning (ML) and artificial intelligence (AI). Python
is also becoming popular for high-performance computing (HPC). However, in
this book we will not cover ML, AI, and HPC.
Traditionally, a scientist was either an experimentalist or a theorists. The
former primarily work on experiments, while the latter on theoretical modelling.
However, after the prominence of computers, a new category of researchers
called computational scientists have emerged. These researchers excel in
designing computers and writing large softwares. Another important point to
note is that computers are often used to simulate physical systems, e.g., Earth’s
atmosphere, stars, galaxies, large molecules, automobiles, etc. Thus, computers
perform virtual experiments. Scientists strive to make accurate models of
physical systems using the inputs from experiments and/or computer
simulations. Thus, computers provide an interesting and powerful window of
opportunity for understanding the world.
Often, experiments and computer simulations complement each other. For
example, hydrodynamic experiments can achieve very high Reynolds numbers,
but computer simulations can reach only moderate Reynolds numbers (105).
However, computer simulations can probe velocity field at any point of the flow,
which may not be possible in many experiments (e.g., in an opaque liquid). Also,
it is impossible to perform experiments on a star, but we can comfortably
simulate stars on a computer, at least, approximately.
This book is ideally suited for advanced undergraduate and early graduate
students. Part-I of the book includes discussions on Python language. In this
part, I also cover error analysis and basics of computer hardware, whose
knowledge is required for estimating memory and time complexity of a
computational problem. Part-II of the book covers introduction to computational
methods—numerical interpolation; integration; differentiation; solvers of
ordinary and partial differential-equations; Fourier transforms; linear algebra;
Monte Carlo methods; etc. I have attempted to present these topics coherently by
highlighting connections among them. For example, the formulas of numerical
integration are derived using Lagrange interpolation.
I hope you will enjoy learning these tools.
COMPUTER HARDWARE

FOR AN EFFICIENT use of a car, it is best to know some of its details: its
milage, power of the engine, nature of the brakes, etc. Similarly, an optimal use
of a computer requires knowledge about its memory capacity and power of the
processors. In this chapter, we provide a basic overview of a computer and its
components.
von Neumann Architecture

The present computers are essentially based on von Neumann architecture


(1945). According to this design, a computer has the following components:

1. Processor: A unit that performs arithmetic and logical operations


2. Memory: Data and program instructions are stored here.
3. Input/Output: Computer takes data from input devices, e.g., keyboard,
mouse; and sends results to output devices, such as, printer, terminal, etc.

The processor, memory, I/O controller (for connecting input/output devices to


the processor), and many other small units reside on a printed circuit board
(PCB) called Motherboard or logic board. A schematic diagram of these units is
shown in Figure 1. Note that hard disk (HD) or solid-state drive (SSD), battery,
wireless device, and camera are kept inside the computer. The processor of a
computer receives inputs from ports, keyboard, and camera through I/O
controller; the processor operates on the inputs, and sends the results to the
memory or to appropriate output units (for example, screen or printer). The
website https://www.nemolaptops.com/post/2018/09/11/antamoy-of-a-laptop
provides a good overview of these units.
Figure 1: A schematic diagram of the internal parts of a computer: Processor,
Memory, Hard Disk, Battery.

Let us get a deeper perspectives on the processor, memory, and hard disk.

Processor: The processor, also called central processing unit (CPU), is the most
complex and critical component of a computer. This unit can perform billions of
arithmetic and logical operations per second. For example, the processor adds
two numbers A and B. An important thing to note is that the numbers A, B, and
A+B are stored in a small memory, called registers, of the CPU.
Now we provide a quick overview of the capabilities of one of the best
processors of today. Rome processor (EPY 7002) contains 64 cores residing in
16 blocks of 4 processors each (see Figure 2). The cores of the processor
communicate with each other via the memory block in the middle. Note that
each core has its own L1 and L2 caches, but 4 cores of a block share 16 MB of
L3 cache. Cache, being closer to the core, is faster than RAM. The cores
communicate with each other, as well as to the RAM and PCI devices, via buses.
The clock speed of the processor is 2.5 GHz, which can boosted up to 3.4
GHz. A Rome processor can perform 16 floating-point operations per clock
cycle. Hence, the peak performance of each core can be estimated to be 16x2.24
≈ 35 Giga floating-point operations/second (FLOPS in short). Consequently, a
Rome processor can perform maximum of 35 x 64 cores ≈ 2.24 TeraFLOPS or
TFLOPS. Note however that this is the peak performance, which is not achieved
in typical programs due to various constraints. Such information is useful for
estimating the time for a computing job.
Intel too has fast processors, which are not covered here. Apple’s M1 chip
has 8 compute cores, 8 GPU (graphical processing unit) cores, and 8 neural
engine cores.
Figure 2: Inside Rome 7742 processor, black bidirectional arrows are the buses
that transmit data both ways.

Memory: The data and programs reside in computer’s memory (the green strip
inside the motherboard of Figure 1), also called random access memory (RAM).
The CPU reads the program and data from RAM and write the results back on it.
Note that RAM is active only when the computer is powered on, hence it is a
temporary memory. We need to write the data to the hard disk for permanent
storage.
A laptop or desktop has RAM in the range of 4 Gigabytes to 64 Gigabytes.
Note that 1 byte = 8 bits, and
1 Kilobyte = 1 KB = 210 ≈ 103
1 Megabyte = 1 MB = 220 ≈ 106
1 Gigabyte = 1 GB = 230 ≈ 109
1 Terabyte = 1 TB = 240 ≈ 1012
1 Petabyte = 1 PB = 250 ≈ 1015
1 Exabyte = 1 EB = 260 ≈ 1018

The clock speed of RAM ranges from 200 MHz to 400 MHz, which is slower
than processor’s clock speed. The fastest RAM available at present, DDR4
(double data rate 4), transfers data at the rate of 12.8 to 25.6 Gigabits/second,
which is quite slow compared to CPU’s data processing capability. Following
strategies are adopted to offset this deficiency of RAM:

1. The motherboard has multiple channels or roads for data travel between the
CPU and the RAM.
2. The CPU has its own memory called cache. The data which is needed
immediately is kept in the cache for a faster access.

Hard disk (HD) and Solid-state disk (SSD): HD and SSD are permanent
storage of a computer. Programs and data reside here safely after the computer is
powered off. When a computer is powered on, the required programs and data
are transferred from the HD to the RAM; this process is called boot up. Hence,
the CPU, RAM, and hard disk continuously interact with each other.
A hard disk is an electro-magnetic device in which magnetic heads read data
from the spinning magnetic disks. In these devices, the data transfers rate to
RAM is 100-200 Megabytes (MB) per second. Due to the moving parts, HDs are
prone to failure, specially in laptops during their movements. In the market, we
can buy HDs with capacities ranging from 1 TB to 20 TB.
On the other hand, a SSD is purely an electronic device with no spinning
parts. Hence, SSDs are safer than hard disks, but they cost more. The data
transfer rate in SSD is around 500 MB per second. The capacity of SSD ranges
from 128 GB to 1 TB.

Graphical processing units (GPU): It is efficient to off-load video and image


processing to a specialised processor, called Graphical processing units (GPU).
GPUs have many processors that perform certain operations, such as matrix
rotation and Fourier transforms, very efficiently. In the last 15 years, GPUs are
also being used for supercomputing. See Section Supercomputers & Compute
Complexity.
Interface of a Computer: Input/Output Units

A keyboard, a trackpad, a mouse, and a camera transmit inputs to the CPU via
bluetooth or Universal Serial Bus (USB) or USB-C ports. The CPU processes
these inputs and sends outputs to an external monitor, a TV, a projector, or a
printer. The data is exchanged among the input/output devices via ports,
bluetooth, or wifi (see Figure 3).
Computers come in different avatars, but their basic design remains the
same. Desktops, which are typically more powerful than laptops, sit on desks.
Workstations or compute servers have stronger CPUs and larger memory, hence
they are more powerful than desktops. Supercomputers are built using many
servers. We will provide brief description supercomputers in Section
Supercomputers & Computation Complexity.
Mobiles and tablets too are computers. They too have processors and
memory, and they perform similar operations as a desktop/laptop. However,
these mobile devices are weaker than laptops and consume much less power.
The aforementioned hardware units by themselves cannot perform any task.
A complex program called Operating System (OS) gives life to these systems.
The OS, applications (such as Microsoft Word), and user programs are called
software, and they will be briefly described in Section Computer Software.
Figure 3: (a) Laptop; (b,c) Ports of a laptop. Adopted from a figure of
wikipedia.org

********************
Conceptual Questions

1. Why do computers have memory hierarchy—cache, RAM, hard disk?


2. What are the advantages and disadvantages of USB-C port over USB port?
3. What are the similarities and dissimilarities between the functioning of a
computer and a human brain?
Exercises

1. List the following for your laptop/desktop and your mobile phone: RAM
size, CPU clock speed, Hard disk, and/or SSD capacity.
2. It is best to see the parts of an opened-up desktop. However, do not open
your laptop because it is tricky.
3. Read more about the processors.
SUPERCOMPUTERS & COMPUTATION
COMPLEXITY

LAPTOPS/DESKTOPS HAVE limited power, hence, they cannot perform


complex tasks, such as banking, weather predictions, simulations of aircrafts.
For such operations, we employ servers or supercomputers, also called high
performance systems. Supercomputing is also called High performance
computing.
Modern supercomputers consist of a large number of processors and memory
units. Fugaku, the fastest supercomputer as on June 2021, consists of large
number of racks, each of which contains many nodes with multiple processors.
Figure 4 illustrates many racks of Fugaku. The nodes are connected to each other
via a fast switch called interconnect, through which the processors exchange
data. Note that Fugaku requires 30 Megawatts of power, which is the power
consumed by a typical small town. For reference, we provide the following
specifications of Fugaku:

1. 158,976 nodes each with 48-core A64FX processor (2 GHz clock speed).
Total number of cores: 7,630,848; Power: 29.899 kilowatts
2. Total memory: 4,866,048 GB
3. Peak speed: 442,010 Tera floating-point operations per second (TFLOPS)
4. Interconnect: Tofu interconnect D
We remark that supercomputers employ high-end processors, e.g., Rome
processor, discussed in Section Computer Hardware. Graphical processing units
(GPUs) too are being used heavily in supercomputers. Each GPU contains
thousands of processors, and it can perform huge number of floating-point
operations. GPUs are heavily used in machine learning. Nvidia’s top-end GPU
A100 has 6912 compute cores, and its peak double-precision performance is 7.8
TFLOPS.

Figure 4: Fugaku, the fastest supercomputer as on June 2021. From


wikipedia.org. Work of Hiroko Hama; reprinted under the agreement of CC BY-
SA 4.0 license.
Memory and Interconnect

One of the major bottlenecks in the performance of supercomputers is the slow


data transfer rate from RAM to CPU. As described in the previous section, the
data transfer rate from memory to CPU is several GB’s per second. In
comparison, CPUs can operate on 1000 GB’s of data per second.
Similar bottleneck exists in the interconnects. One of the fastest interconnect,
FDR Infiband, can transfer data at the rate of 56 Gbps (Giga bits per second).
Considering that an interconnect is connected to many nodes, the net
transmission speed is much slower than 56 Gbps.
In contrast, the CPUs can process data at much faster pace. CPU is like a
giant who can compute very fast, but it remains idle because RAM is not giving
it enough data. The performance disparity between the CPU and
RAM/interconnect is one of the biggest challenges of supercomputing. These
bottlenecks are summarised in the following quote, “FLOPS are free, but data
communications are expensive”.
Memory and Time Complexity

It is critical to estimate the memory and time requirements for a numerical


problem. Significant efforts and resources would be wasted if we do not have a
proper estimate of the computation complexity of a given task. For example, the
matrix multiplication of two 105x105 arrays requires 24 GB of RAM (see
Example 1 below), hence we should not try this exercise on a laptop/desktop.
In the following discussion, we present two examples that illustrate how to
estimate the memory and time complexities of a problem. To estimate the
memory requirement, we need to keep in mind that the storage of an integer and
a float normally require 4 and 8 bytes respectively.

Example 1: We need to multiply two arrays A and B of sizes 104x104 and store
the result in array C. For this problem we need 3 arrays of 108 elements each.
Storage of 3x108 real numbers requires 8x3x108 = 24x108 bytes of storage,
which is 0.24 GB. For 105x105 arrays, the corresponding requirement is 24 GB.
The simplest algorithm for multiplication of two NxN arrays requires
approximately N3 multiplications and additions. Therefore, for N = 104, we need
1012 floating-point multiplications and additions. We estimate the peak
performance of a typical laptop with a 4-core CPU to be 50 GFLOPS. Hence, in
the best case scenario, the 2x1012 floating-point operations would require
2x1012/(50x109) ≈ 40 seconds. Here, the prefactor 2 is for the addition and
multiplication.
The retrieval and storage the array elements from/to memory require
additional time. In addition, a laptop/desktop also performs other operations such
as system management, internet browsing, email checking, etc. The processor
works on these tasks in a round-robin and time-sharing manner. Consequently,
we expect that multiplication program to take much larger than 40 seconds.
However, we do not expect the run to go much beyond several (say 10) minutes.
For N = 105, the time complexity will be 1000 x 40 seconds ≈ 666 minutes ≈
11 hours. Hence, the space and time requirements for N = 105 are respectively 24
GB and 11 hours that go beyond the capabilities of a typical laptop.
Example 2: For weather prediction, a computer solves the equations for the flow
velocity, temperature, humidity, etc. For the same, Earth’s surface is divided into
a mesh, as shown in Figure 5. High-resolution simulations employ grid
resolution of 3 km x 3 km that leads to 12000x12000 horizontal grid points.
Suppose, we take 1000 points along the vertical direction, then the total number
of grid points for the simulation is 144x109. At each grid point, we store the
three components of the velocity field, pressure, temperature, humidity, and C02
concentration. Hence, to store these seven variables at each grid point, we need
8x7x144x109 = 8.064 TB of memory, which is way beyond the capacity of a
laptop/desktop. Clearly, we need a supercomputer for weather prediction. The
estimation of time requirement for a weather code is quite complex, and it is
beyond the scope of this book.

Figure 5: For weather simulation, a sample grid on the surface of the Earth.
Courtesy: Wikipedia
With this, we close this section.

********************
Conceptual Questions

1. How are the supercomputers helping scientists and engineers in their


research?
2. How does one estimate the peak computational performance of a
supercomputer? Why don’t we achieve performance close to the peak
value?
3. Why is memory access a major bottleneck for supercomputers?
Exercises

1. A processor has 20 cores that operate at clock speed of 3 GHz. Each of its
cores can perform 20 floating-point operations per clock cycle. Estimate the
peak FLOPS of the processor.
2. Visit the website top500.org and study the top 10 supercomputers of the
world. Compute the maximum FLOP rating of their processor, and then
compute the peak performances of the supercomputers.
3. Estimate the memory requirements for storing the following arrays:
a. Three-dimensional integer array of size 1000x1000x1000.
b. Three-dimensional float array of size 1000x1000x1000.
c. 108 spins that can take values up or down.
4. We want to search for a word in text of 300 words. How many comparisons
are required in the worst-case scenario?
5. Estimate the number of comparisons required to search for a word in a
dictionary with N words.
6. Consider a matrix multiplication operation A = BxC, where each of them
are NxN matrices. If you were to perform the above multiplication on a
server with 4 TB RAM and 4 Rome processors, estimate the largest
possible N for this server. How long will it take to perform this operation?
COMPUTER SOFTWARE

COMPUTER SOFTWARE IS a vast field. This section is not meant to discuss


the nuances of various softwares. Rather, we provide provide a bird’s-eye view
of the operating system and Python programming language. In addition, we
relate the programming languages to various programs of a computer.
Operating System and System Software

The Operating System (OS) makes a computer aware of its hardware—CPU,


memory, hard disk—and the connected input/output units—computer screen,
keyboard, mouse, printer, etc. For example, a computer responds to the inputs
from the keyboard; executes programs; etc.
The OS is loaded from the hard disk to the RAM as soon as a computer is
turned on; this process is called boot up. The OS performs the following tasks:

1. Memory management
2. Process management
3. Management of input/output devices (keyboard, display, printer, mouse,
etc.)
4. Computer security
5. Management of application softwares (to be described below)
6. Interactions with users via input/output devices
7. Compilation and execution of user programs

The leading OS of today’s computers are Unix and Windows. Linux and MacOS
(the OS of Apple Computersis) are another variants of Unix. Unix itself consists
of many programs, which are categorised into two classes: Unix Kernel and Unix
Shell. See Figure 6 for an illustration. Note that OS of mobile devices—iOS,
Android, and Windows—have limited capabilities.
Figure 6: A schematic diagram of various components of Unix OS.
Application Softwares

Everyday we use computers for many jobs: sending/receiving emails, browsing


internet, watching movies, playing songs, writing documents, and occasionally
programming. Each of these tasks are performed using application softwares.
For example, we write documents using Microsoft Word or Pages (on a Mac);
browse internet using Firefox, Internet Explorer, Safari, etc.; watch movies using
Mplayer, VLC, etc.
In addition to the above, we can employ computers to record videos for
surveillance, and to control robots and home devices such as air conditioners,
TV, etc. Supercomputers are employed for more complex and data-intensive
tasks such as banking, weather forecasting, climate modelling, simulations of
airplanes and cars, etc. Note that the application softwares are at the top of Unix
shell in system hierarchy. See Figure 6.
System Software and Programming Languages

At the base level, a computer understands only two alphabets—0 and 1.


Therefore, all the instructions and data are to be converted to strings of 0’s and
1’s. For example, an addition of two numbers A and B involves the following
operations:

1. Get numbers A and B from the memory and put them into the CPU
registers.
2. Add the numbers and put result A+B into another register.
3. Transfer the result from the register to the memory.

The addition of numbers involves bitwise operations, such as 0+0=0, 1+0=1,


1+1=0 with a carry of 1, etc. Such instructions, coded in binary, are called object
code.
It is cumbersome to write object codes for complex tasks, e.g., weather
forecasting code. Compilers and Interpreters help overcome this difficulty. A
user writes programs in a higher-level language; then Compilers and Interpreters
translate these programs into object codes. These softwares save the programmer
from the drudgery of writing object codes.
The leading programming languages are C, C++, Fortran, Java, Python,
Matlab, etc. In C, C++, and Fortran, complete computer programs is written
first, after which the programs are converted to object codes using compilers.
Hence, C, C++, and Fortran are called compiler languages. On the other hand,
Python and Matlab interpreters execute the codes in pieces, hence Python and
Matlab are called interpreter languages. The following snippet illustrates how a
Python interpreter interacts with a user.

In [1]: x=3

In [2]: x
Out[2]: 3

In [3]: y=9
In [4]: print(x+y)
12

In the above, the statements after In [1], In [2], In [3], and In [4] are typed by the
user, while Out [2] and the number 12 after In [4] are the response of the
interpreter. Note that the interpreter replies to the user instantly, unlike compliers
who respond to the user after executing the complete code.
In the next section we will provide an overview of Python programming
language.

********************
Conceptual Questions

1. What are the differences between computer hardware and computer


software? Illustrate your answer using examples.
2. What are the differences between a compiler and an interpreter?
3. List all the application softwares and system softwares that are used often in
your laptop/desktop.
4. Locate Ipython interpreter in your computer.
BRIEF OVERVIEW OF PYTHON

GUIDO VAN ROSSUM created Python programming language, which


appeared in 1991 for the first time. Python is an interpreter language, and it is
very easy to learn and program, which makes it one of the most attractive and
popular languages. Python is used for a large number of applications, for
example,

1. Numerical and scientific computing


2. Data analysis
3. Big data and Machine learning
4. Image processing
5. Software development
6. Interface to experimental devices and control
7. GUI (graphical user interface) development
8. Audio and video applications
9. Internet programming
A Cursory View of Python

As on 2021, Python 3 is the standard and supported version of Python. Some of


the major differences between Python 3 and its earlier version, Python 2, are
given below:

1. In Python 3, the arguments of print statement are within brackets, but it is


not so in Python 2.
2. In Python 2, the division operator, “/” performs integer division for two
integer operands; for real division, one of the operands of “/” must be float
or complex. But, in Python 3, the integer-division and float-division
operators are different, and they are “//“ and “/“ respectively.

The other differences between Python 2 and Python 3 are quite technical to be
discussed here. In this book, we follow Python 3.

Using Python Interpreter: We start Python interpreter from a unix terminal by


typing python at the prompt. After that, we can proceed to write Python
statements. For example:

(base) ~/python
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more
information.
>>> 2+3/4
2.75
>>>

In this book, we recommend Ipython interactive shell with pylab option, which
imports Numpy and Matplotlib.pyplot modules. Ipython does not consume as
much RAM as GUI packages, e.g., Spyder. For invoking ipython, we type the
following at the terminal prompt:
(base) ~/ipython --pylab
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.
Using matplotlib backend: MacOSX

In [1]: 2+3/4
Out[1]: 2.75

Python modules: A major benefit of Python is its large number of libraries


—Numpy, Matplotlib, Scipy, Math, Pandas, Sympy, etc. Technically, Python
libraries are called modules. A brief description on some of the important Python
libraries are here.

1. Numpy: Numpy is a short form for Numerical Python. This module contains
mathematical functions, such as sin, cos, log, sqrt, etc. Also, Numpy
contains optimized functions for array operations.
2. math: This module contains various mathematical functions. Many
mathematical functions, e.g., trigonometric, logarithm, exist in both Math
and Numpy, but some exist in only one of them. For example, the function
factorial exists in Math module, but not in Numpy.
3. Matplotlib: This Python module helps create beautiful plots.
4. Scipy: This module contains advanced scientific functions for integration
and differentiation, interpolators, differential equation solvers, linear
algebra operations, special functions, etc.
5. Pandas: This module is useful for data analysis and plotting.
6. Turtle: Using turtle module, we can create geometrical figures.
7. Sympy: This module is used for symbolic processing.

In this book we will deal with Numpy, Math, Matplotlib, and Scipy modules
extensively. To use these libraries, we need to import them. An illustration of
import operation is given below. Here, math module is imported as ma.

In [6]: import math as ma

In [7]: ma.factorial(5)
Out[7]: 120
Python documentation and Help: Python is one of the best documented
programming languages. There are a large number of websites and books on
various topics of Python. You can just type what you are looking for in google,
and you will find an answer.
Python offers useful online help in the interpreter itself. For example, you
can get description of plot, sqrt, etc. by just typing the requisite functions after ?.
This is useful if you have forgotten the syntax. Two examples are here:

In [**1**]: ? plot

In [**2**]: ? sqrt
Creating a Python File Using an Editor

Small Python program can be written in Ipython window itself. However, it


becomes cumbersome to type large codes on a Ipython window. Instead, large
codes are written in a file using a text editor. You may choose a text editor
among many available at present: Vim, IDLE, Atom, Spyder, Sublime, Xcode, Vi,
etc. However, I recommend Sublime Text (https://www.sublimetext.com), which
is available for all the three platforms: Windows, Mac, and Linux.

Typing in Sublime is very easy. A screenshot of a Python code typed in Sublime


is shown below (Figure 7):

Figure 7: A screenshot of a Python file sum_of_digits.py created using the


sublime text editor.

Note that a Python program needs to be properly indented. That is, we need to
put blocks of code together by placing same number of blank spaces for each
line of the block. In the code of Figure 7, lines 5 to 12 belong to the function
sum_digits(n), hence they are shifted by equal number of spaces, here 4 spaces.
Note however that line 10 is indented further by placing another 4 spaces. This is
because the statement my_sum += int(k) is within the for loop, i.e, it executed for
each k of the loop. Note that you can choose any number of spaces for
indentation; the only condition is that this number must be the same for all the
lines of the code block. Keep in mind that if we do not provide these spaces, the
code will not run. Indentation is a must for Python codes!
We can save the file in the same folder in which Ipython is running. This file
can be executed in Ipython window using a command ``run filename”. For
example, a file named sum_of_digits.py that contains the function definition of
sum_digits() is run in Ipython as follows:

In [115]: run sum_of_digits.py

In [116]: sum_digits(128)
Out[116]: 11

The best way to learn programming is to actually program. Programming is like


sports and art, which can be mastered by practice. I recommend that students
should just starting coding without fear and laziness.
Python vs. C

Python has certain advantages and disadvantages over other programming


languages. Here, we contrast Python with another popular language, C. This
section is meant for advanced students, and it can be skipped by students who
are not familiar with C.
We list several important differences between C and Python in Table 1. A C
program has to be written completely and then compiled, while Python codes
can be developed piece by piece. Due to this reason and because of extensive
Python modules, Python codes are easy to develop. A flipside, however, is that
Python codes are not optimised, hence, they are slow during the execution. It is
often said that a large Python code can be developed 10 times faster than the
corresponding C code, but ir is 10 times slower than its C counterpart.

Table 1: Comparison between the features of Python and C.

Python C
1 An Interpreter language A compiler language
2 No variable declaration Variables need to be declared
3 No need to declare variable type Defining variable type is mandatory
4 Dynamically typed Statically typed
Python has a large set of libraries.
5 Python is used heavily in Machine A limited set of libraries available.
Learning and Artificial Intelligence.
6 Easy syntax Relatively harder syntax
7 Easy testing and debugging Relatively harder to test and debug.
8 Code development is fast Code development is slow
Used for developing systems
9 Used heavily for postprocessing
programming and large codes.
10 Code execution is slow Code execution is fast
Compilers optimise the object codes
Interpreters do not generate as
11 efficient codes as compilers. by taking into considerations the
data structures and loop structures.
Parallel programming in Python
Parallel programming in C using
12 using multithreading and
MPI and OpenMP.
multiprocessing
Reference Type (see Sec. Mutable
13 Value Type
and Immutable Objects in Python)

Items 1-8 of Table 1 make programming in Python very easy. Variable


declaration is an important programming practice for large codes, but it is
relaxed in Python. These features make execution of a Python code slower than
C (see item 10). Note however that we can speed up a Python code by making
use of fast libraries written in C or C++. For example, Python FFT library pyfftw
is quite fast because it makes use of the library FFTW, which is written in C.
Due to the above reasons, large parallel programs (e.g., for atmospheric and
advanced physics applications) are not written in Python. It is best to write such
codes in C, C++, or in Fortran with parallel features. Compilers generate
efficient object codes for such applications by taking into considerations the loop
and data structures. However, it is customary to write a Python prototype first
and test it for a complex and small data set. A comprehensive C/C++ or Fortran
code is written after this. This exercise saves time on the whole. Recall that in
experiments, researchers work on a prototype aeroplane before venturing into a
real-sized aeroplane.
In the next section, we will describe how to run Python on your own
computer.

********************
Other documents randomly have
different content
will keep their eyes from yours; and, in the same way, this law may
be repealed. I can, therefore, see no force in this objection. The
courts of justice undertake to expound the constitution, and shall not
the House of Representatives be as competent to do this as any
court of justice? I will suppose a case, that of a man condemned
under the Sedition law by a tribunal of justice. Suppose men of
different principles come on the bench, would they hesitate to
reverse the preceding decision of the court? Indisputably not. Here,
too, then, we would behold varying and repugnant decisions.
Mr. Eppes.—I have no doubt that every objection which can be
made to a member of this House holding a civil office during his
continuance as a Representative, applies with equal force to his
holding a lucrative contract. The framers of the constitution in
excluding civil officers from the floor of this House, most certainly
intended to prevent any species of dependence which might
influence the conduct of the Representative—to prevent his looking
up for preferment to the Executive, or being biased in his vote by
Executive favor. A lucrative contract creates the same species of
dependence, and every objection which could be urged against an
officer, applies with equal force against contractors, who are
dependent on the Executive will, and particularly carriers of the mail.
While, however, I make this admission, I do not believe we have
power to pass this resolution. The words of the constitution are: “No
person holding an office under the United States shall be a member
of either House during his continuance in office.” These words are
plain and clear. Their obvious intention was to have excluded
officers, and officers only. It would certainly have been equally wise
to have excluded contractors, because the reason for excluding
officers applies to them with equal force. We are not, however, to
inquire what the constitution ought to have been, but what it is. We
cannot legislate on its spirit against the strict letter of the
instrument. Our inquiry must be, is he an officer? If an officer, under
the words of the constitution, he is excluded; if not an officer, we
cannot exclude him by law. It is true, as has been stated, that, by
the constitution, we are made the judges of the qualifications of our
own members. This judgment, however, is confined within very
narrow limits. The constitution prescribes the qualifications of a
member. We can neither narrow nor enlarge them by law. Our
inquiry can go no further than this: has the Representative the
qualifications prescribed by the constitution? An extensive meaning
has been given to the word “office.” How far such a construction of
the meaning of this word is warranted, I leave for others to decide.
That all contractors are not officers, I am certain. A man, for
instance, makes a contract with the Government to furnish supplies.
He is certainly not an officer, according to the common and known
acceptation of that word. He is, however, a contractor, and, under
this resolution, excluded from a seat here. A carrier of the mail
approaches very near an officer. The person takes an oath, is subject
to penalties, the remission of which depends on the Executive. His
duties are fixed and prescribed by law. Near, however, as this species
of contract approaches to an office, I do not consider that the word
“office” in the constitution can include even this species of contract.
I consider the word “office” in the constitution ought to be construed
according to the usual import and meaning of that term; and as I do
conscientiously believe that the word “office” and the word
“contract” cannot be tortured to mean the same thing, I shall vote
against the resolution.
Mr. Alston.—While I am as much opposed as any man to see any
holder of public money within these walls, I cannot justify myself in
declaring what is or what is not the constitution. If in any case this
ought to be done, this surely should be the last. What is its effect?
To deprive a member of his seat on the vote of a bare majority,
when the constitution has declared that “no seat shall be vacated,
but on the vote of two-thirds of the members.” Let this House say
so, and what becomes of a contractor, if any such there be within
these walls? The decision of the House will be in violation of the
constitution. No man who knows me will imagine that I have any
partiality for contractors holding seats within these walls. I have
never held a contract, or received a cent of the public money but for
my wages as a member of this House. I am, therefore, as
disinterested as man can be on this point. If there is a contractor
within the meaning of the constitution, let him be pointed out. I am
not certain how I shall vote upon such a proposition. But I will not
declare beforehand a particular construction of the constitution. If I
believe the case comes within the constitution, of which I am not
certain, I will vote for clearing the House of such a member. But I
will not consent to a majority declaring in this way what they cannot
carry into effect. How can this be done? If you cannot get two-thirds
of the members of this House to vacate the seat, I ask what
becomes of the resolution declaratory of the meaning of the
constitution? But it is idle to pass a declaratory resolution unless it
can be carried into effect. One thing I will say, if the mover will
modify his resolution so as to impose a penalty on any officer who
shall make a contract with a member of Congress, I will give it my
consent. For I wish to see no man in these walls dependent on the
Government. I still adhere to the principle which I set out with,
when I entered into public life, for I became a member of the
legislature of the State which I have the honor to represent at the
age of twenty-one; but there was no office in the gift of any
government which I would possess. This is a principle to which I
strictly adhere, and I do not believe I have any relation on earth who
holds an office, numerous as my relatives are.
Mr. R. Nelson said he was sorry that he could not on this occasion,
consistent with the oath he had taken to support the constitution,
advocate the resolution under consideration. He agreed that it was
highly improper for contractors to hold seats in that House, as there
were many cases in which they could not give a free and impartial
vote; but in his opinion there was no power to exclude members
from a seat, unless that power was contained in the constitution. He
said he would give his idea of the spirit and meaning of the
constitution on this point. They were bound by its letter—where the
letter and the words of it were plain, they were bound strictly to
adhere to them; where, from the wording, the meaning was
doubtful, or difficult, every member was bound to put that
construction which his judgment dictated. But where there was no
difficulty, where the words were plain and obvious, he would ever
raise his hands against what was called the spirit of the constitution,
or, in other words, giving it a meaning which the words would not
bear. If this power existed in the constitution, it must be found under
that section which declares, that “No Senator or Representative
shall, during the time for which he was elected, be appointed to any
civil office under the authority of the United States, which shall have
been created, or the emoluments of which shall have been
increased, during such time; and no person holding any office under
the United States shall be a member of either House, during his
continuance in office.” The question then comes to the single point:
Is a contractor an officer under the constitution? If he is, there is no
doubt he may be excluded from a seat in this House; but if he is not,
he cannot be excluded. What then is the idea of an officer under the
constitution? It either must be recognized by the constitution, or
some law passed in conformity to it, for no man under the
Government has a right without law to create as many offices as he
pleases. The Postmaster-General has a right to contract for carrying
the mail; he may employ for this purpose fifty, five hundred, or five
thousand men. Will any body thence contend that the Postmaster-
General has the right of creating five thousand offices? Our
constitution has been justly extolled as the freest in the world, and
as the best calculated to promote the happiness and security of the
people. It has been called free in contradistinction to those despotic
governments, where all the offices are held up to sale. Is not this
the case with contracts? Are they not uniformly given to the lowest
bidder? What government of principle then is this, which proposes to
put a construction upon the constitution, by which offices under the
Government shall be thus exposed to sale? But are they in truth
officers of the United States, recognized either by the constitution or
laws? No, they are not officers of the United States, they are mere
hirelings of the Postmaster-General; he has not the power of setting
up the constitution to the highest bidder. If so, it is no longer a free
constitution; it does not deserve the eulogiums which have been so
justly passed upon it.
Mr. Early.—I would not rise to trouble you were not the yeas and
nays to be recorded on this question. I am as fully sensible as the
honorable mover of the resolution, or any other gentleman on this
floor, of the extreme impropriety, to say the least of it, of persons
remaining members of this House who hold a contract under the
Government to which any emolument is attached. With him and
them I believe, that of all descriptions of appointment, this is the
most improper to be blended, where the emoluments are not fixed
by law, but rise or fall with circumstances. I am therefore as willing
as any person can be to adopt any measure to effect a remedy of
this evil, which we possess the constitutional right of doing. My
difficulty on this subject is not the same with that presented to the
minds of some gentlemen, that we are not authorized to pass a
resolution putting a construction upon the constitution. On this
subject, by the constitution we are made judges of the qualifications
of the members of this House. If so, we are necessarily judges of
their disqualification also. One power implies the other. I therefore
have no difficulty on this score. The simple question is, in my mind,
whether a contractor is an officer under the constitution? My own
opinion is decidedly in the negative—an opinion formed after the
most mature reflection. I can appeal to you, sir, that I have sought
after truth on this subject with industry; and I can appeal to other
members to attest my having contemplated early in the session the
offering a resolution as the foundation of a law, to give effect to the
object of the gentleman from Virginia, to declare void any contract
made by any officer under this Government with any member of
either House. So far I am prepared to go, if any member shall
introduce such a proposition. The passage of such a law will remove
the inconvenience which might arise from interfering decisions made
in this House at different times, and will prevent the existence of a
different rule in the two branches of the Legislature.
Mr. J. Randolph admitted that this might be, as he was convinced it
was with many gentlemen, and hoped it was with all, a question
admitting of a fair difference of opinion. It was a question that
respected the construction of the Constitution of the United States.
The point in issue, whether a contractor is or is not an officer of the
United States, had been set aside by being begged. Gentlemen
argue as if it was proposed to add a new qualification to holding a
seat on this floor, when in truth, no such question existed; the only
question was, whether there was an existing disqualification. While I
am up, said Mr. R., permit me to say the gentleman from Maryland
has, with a peculiar infelicity, abandoned the ground which he had
first taken. He says that a contract cannot be an office, because the
former are put up to sale; and because no man, under the
constitution, can possess the power of creating an indefinite number
of offices. And yet, how are those men who carry the mail or
discharge the duties of postmasters appointed, but on the mere
dictum of the Postmaster-General? And how are foreign Ministers
appointed? They are not appointed by law. The President nominates
as many as he pleases, and is only limited by the money at his
disposal. As to the offices under the Postmaster-General, as has
been alleged, being let to the lowest bidder, I believe it would be
difficult to establish the allegation. I understand that that is not the
principle on which they have been let out. We are told that a
contract is nothing but a bargain. It certainly is a bargain. But
suppose the office of Postmaster-General, as that seems in this
debate to have engaged so much of the attention of gentlemen,
should be let to the lowest bidder; would the person that discharged
those duties be less an officer of the United States? There is one
office which I believe is always let to the lowest bidder—a common
executioner. Who is he? The deputy of the sheriff: and quo ad hoc,
he is as much an officer as the superior who employs him.
Mr. Elmer said it was perfectly clear to him, that the members of
that House were not at liberty to vote for the resolution under
consideration. Both common sense and the constitution forbade
considering a contract in the light of an office, and he had never
before heard it contended that they were equivalent terms. He
would cordially give his vote for any law which could be
constitutionally passed, to get rid of speculation and corruption of
any sort, but the oath which he had taken to support the
constitution limited his power, which he could not transcend.
Mr. Kelly said he would concisely assign the reasons which would
induce him to vote against the resolution. He did not believe an
officer and a contractor meant the same things. With regard to the
contractors holding a seat on that floor, it might happen that a man
might be a contractor without being in the least disqualified from
impartially discharging all the duties of a member, as the contract
which he formed might be more for the good of others than his own
benefit. He, however, allowed that where a person held a seat, and
made use of the power it gave him to make a contract, he was
highly censurable. Still he was of opinion that it was not in the
power of the House to declare the two appointments incompatible,
unless the constitution expressly authorized them. In examining the
constitution he found no such provision. Though it had been
attempted to be shown that a contractor and an officer were one
and the same, he believed they were very distinct things. A
contractor receives no authority from Government; his contract was
derived from an officer, and all the power he possessed was derived
from him, who was only amenable for the performance of the duty
to the person who appointed him. A contractor could not, therefore,
be considered as an officer under the constitution, amenable to the
United States.
Several allusions, said Mr. K., have been made to cases which have
occurred under the Postmaster-General, but until these shall be
particularly pointed out, it will be impossible for us to decide how we
are to act. I believe that it does not become this House to pass
declaratory acts relative to the constitution. It ought, in my opinion
to stand on its own footing; and every case that is presented ought
to be decided, not by a declaratory act, but by the constitution itself.
My colleague says that the judges of the federal as well as State
courts take an oath as well as we do, to support the constitution;
and that, notwithstanding they are in the daily habit of construing
the constitution. But there is a wide difference between their
deciding particular cases which properly come before them, and this
House going into a general declaration without any such particular
case. Would the judges undertake to declare the meaning of the
constitution without the existence of a particular case calling for
their decision? So that the very thing which the House is about
doing, has been invariably avoided by the judges.
The question was then taken by yeas and nays on agreeing to the
resolution—yeas 25, nays 86.

Monday, March 31.


Yazoo Claims.

A message was received from the Senate informing the House


that they had passed a bill to carry into effect the provisions of the
eighth section of the “Act regulating the grants of land, and
providing for the disposal of the lands of the United States south of
the State of Tennessee.”
The bill having been read the first time—
Mr. R. Nelson said he should not, on this occasion, go into an
examination of the principles of the bill, as they were well
understood by the House. They went to practise one of the grossest
impositions he had ever known. In order to get rid of what he
considered a stain on the statute book, and a disgrace to the nation,
he moved that the bill be rejected.
The question was accordingly put from the Chair, “Shall the bill be
rejected?”
On the motion of Mr. Leib, it was determined to take the yeas and
nays.
The question was then put, Shall the bill be rejected? and passed
in the affirmative—yeas 62, nays 54, as follows:
Yeas.—Isaac Anderson, David Bard, Burwell Bassett, George M.
Bedinger, William Blackledge, John Blake, jun., Thomas Blount,
Robert Brown, William Butler, Levi Casey, John Claiborne,
Christopher Clark, Joseph Clay, Matthew Clay, John Clopton,
Frederick Conrad, John Dawson, Elias Earle, John W. Eppes, James
M. Garnett, Peterson Goodwyn, Edwin Gray, Andrew Gregg, Silas
Halsey, John Hamilton, David Holmes, Walter Jones, Thomas Kenan,
Michael Leib, Duncan McFarland, Robert Marion, Josiah Masters,
Nicholas R. Moore, Thomas Moore, John Morrow, Gurdon S.
Mumford, Roger Nelson, Thomas Newton, jun., Gideon Olin, John
Pugh, John Randolph, Thomas M. Randolph, John Rea of
Pennsylvania, Jacob Richards, Thomas Sammons, Thomas Sanford,
Ebenezer Seaver, James Sloan, John Smilie, John Smith, Samuel
Smith, Henry Southard, Thomas Spalding, Richard Stanford, Philip R.
Thompson, Abram Trigg, John Whitehill, Robert Whitehill, David R.
Williams, Alexander Wilson, Richard Wynn, and Joseph Winston.
Nays.—Willis Alston, jun., Joseph Barker, Silas Betton, Barnabas
Bidwell, John Campbell, John Chandler, Martin Chittenden, Orchard
Cook, Jacob Crowninshield, Richard Cutts, Samuel W. Dana, Ezra
Darby, John Davenport, jun., William Dickson, James Elliot, Caleb
Ellis, Ebenezer Elmer, William Ely, William Findlay, James Fisk, John
Fowler, Isaiah L. Green, Seth Hastings, William Helms, David Hough,
John G. Jackson, James Kelly, Joseph Lewis, jun., Matthew Lyon,
William McCreery, Jeremiah Morrow, Jonathan O. Mosely, Jeremiah
Nelson, Timothy Pitkin, jun., Josiah Quincy, John Russell, Peter Sailly,
Martin G. Schuneman, John Cotton Smith, Joseph Stanton, William
Stedman, Lewis B. Sturges, Samuel Taggart, Benjamin Tallmadge,
Samuel Tenney, David Thomas, Thomas W. Thompson, Uri Tracy,
Killian K. Van Rensselaer, Joseph B. Varnum, Peleg Wadsworth,
Eliphalet Wickes, Marmaduke Williams, and Nathan Williams.

So the bill was rejected.


Mr. J. Randolph moved that the House adjourn. He said that a few
days ago the House had adjourned on account of the death of
General Jackson. He hoped they would now adjourn on account of
his resurrection. For he had told him, that if he could give a death-
blow to the Yazoo business he should die in peace. Adjourned, yeas
58.

Tuesday, April 1.
Plurality of Offices.

On motion of Mr. John Randolph, the House took up the report of


the Committee of the Whole on sundry resolutions agreed to by
them on the 28th ultimo. When the question was put on concurring
in the report of the Committee of the Whole in their agreement to
the second resolution as follows:

2. Resolved, That the union of a plurality of offices in the person


of a single individual, but more especially in the military with the civil
authority, is repugnant to the spirit of the Constitution of the United
States, and tends to the introducing of an arbitrary Government:

Mr. Bidwell said he would very concisely assign his reasons for
voting against this resolution. It declares that “the union of a
plurality of offices in the person of a single individual, but more
especially of the military with the civil authority, is repugnant to the
spirit of the Constitution of the United States, and tends to the
introducing of an arbitrary Government.” It appeared to him that this
was not a correct declaration. If the constitution itself be referred to,
it will appear that it recognizes a union of civil and military offices in
the same person. Such a union is to be found in the First Magistrate
of the United States, who exercises the highest Executive civil
functions, and is at the same time Commander-in-Chief of the Army
and Navy, and of the militia while in actual service. The same
principle pervaded the constitution, he believed, of every State.
There was also a union of civil and military authority in several
offices, by acts of Congress. This was the case with the marshals in
certain cases, and officers who are charged with the
superintendence of Territorial affairs. If it were proper, said Mr. B., as
I do not think it is, by a vote of this House, to undertake to define
the constitution, it still appears to me that we cannot consistently
say that the union of a plurality of offices in the person of a single
individual, but more especially of the military with the civil authority,
is repugnant to the spirit of the Constitution of the United States. A
declaration of that kind would be a vote of censure on the people of
the whole United States, for having adopted the Federal
Constitution, on the people of the several States, for having adopted
their constitutions, and on the Legislature under both Governments,
for having passed laws which authorized such a union.
Mr. J. Clay said, the objections of the gentleman arose from not
having properly considered the nature of the union of civil and
military office in the First Magistrate. By the constitution, the military
was placed in strict subordination to the civil power. For this reason
the President of the United States had placed under his control all
the officers of the Army and Navy. The union contemplated in the
resolution before you, said Mr. C., is that which gives the actual
discharge of civil powers to an officer who has actual command of
your army. I ask if it was ever in the contemplation of the
constitution, that the President should in person head your armies
and command your fleets? I believe not. There exists in one of the
Territories such a union as is contemplated in the resolution. In
Louisiana a person holding the office of Governor, is at the same
time Commander-in-chief of the Army of the United States, in virtue
of his appointment of Brigadier-General. Will any man pretend to say
that a union of offices, such as these, the discharge of whose duties
is incompatible, is such a union as is contemplated in the
constitution? No; the union in the constitution was only intended to
give the President a control over the Army and Navy; while this
resolution contemplates the positive and actual union of powers in
the same person, powers which at the same time he may be called
upon to exercise at different and distant places. To separate these
powers is the object of the resolution. I hope the resolution will be
agreed to, and the separation take place.
Mr. J. Randolph.—My friend from Pennsylvania has left me little to
say on the question, and indeed I have heard nothing in the shape
of argument, or assertion, but what I was prepared to hear, and of
which I apprised the House some time ago. It has come out at last
from the lips of a man who has prided himself upon being the
champion of the Constitution of the United States to-day, although
but a few days ago he threatened us with a dissolution of the Union,
that the constitution has no spirit in it. He calls on any man to lay his
finger on that spirit. What does the Constitution of the United States
say? Does it not guarantee to each State a Republican form of
Government? Is there no spirit in this? Is not the constitution then
devised under the influence of a Republican spirit, for the benefit of
the people who are governed by it, and not for the exclusive benefit
of those who administer it? Will any man pretend to say that a
Republic is any thing or nothing? And that it is congenial to such a
Government that the civil and military authority should be vested in
the same hands? Is it not of the very essence of such a Government
that the military should be kept in strict subordination to the civil
power? And have not your laws, which give to marshals in certain
cases a power over the military, been passed to keep the military
under such subjection? How is the military to be kept in such
subjection, when, according to the usage of the Romans, the leader
of an army is the Governor of a province? If the constitution has no
spirit in it, it is a dead, lifeless thing, not worth the protection of any
man of sense. But I am happy that it has a spirit, which I trust will
save this nation, even if its letter shall be killed.
Mr. Quincy said he would merely observe, that, though it were true
that a union of civil and military offices in the same person was
repugnant to the spirit of the constitution, it was not true that a
union of different offices in the same person was repugnant to it.
They had to-day united two offices in the same person, in the bill
relative to the Territory of Michigan. They had heretofore constituted
several of the officers of the Government Commissioners of the
Sinking Fund. He could see nothing in the constitution which
interfered with a plurality of offices, which in many instances was
attended with great practical benefit. As there was therefore in the
constitution nothing explicit against this union, he could not vote for
the resolution.
Mr. Gregg said he believed it was contrary to the spirit of the
constitution, that civil and military offices should be united in the
same person; but, he would ask, what benefit would result from
such a declaration? The power of appointing to office was vested in
the President and Senate, who were sworn to support the
constitution. They were, therefore, the judges of the powers with
which they were invested. In the exercise of this power, they have
actually declared that they do possess it. What does this resolution
amount to? If they undertook to declare the President guilty of such
a flagrant act as involved a violation of the constitution, it was their
business to impeach him. Mr. G. said, as he could see no good likely
to arise from this resolution, he should not vote for it. The practice it
referred to was not new, though he had always thought it wrong. He
recollected, that, some years since, the Governor of the North-
western Territory was likewise Superintendent of Indian Affairs and
Commander-in-chief of the Army, for all which appointments he
drew pay, though no notice had been taken of it. Other instances of
the same kind might be pointed out. He did believe this union was
contrary to the spirit of the constitution—to the true spirit of a
Republican Government—and if the gentleman from Virginia would
bring forward an amendment to the constitution to prohibit such a
union, he would vote for it.
Mr. J. Randolph.—Six years ago, there could not have been a doubt
of the right of this House to pass this resolution—now, the right is
disputed. Have we not a right to pass a resolution referring to the
constitution, in order to bring in a law grounded on it? Do we not do
this every day? One word as to the appointment of General
Wilkinson. Gentlemen are fond of sheltering themselves behind great
names. I have no hesitation in saying I think the Executive was
wrong in making that appointment. I have no hesitation in saying so
here, though gentlemen who join me out of doors are reluctant to
make the same declaration on this floor. I do not think, however, the
persons who made the appointment as reprehensible as the persons
at whose importunate solicitation it was made. I believe that a man
of good sense, and of upright intentions, may be induced to do that
which his own judgment will afterwards condemn. It is well known,
that the ante-chambers of our great men were crowded with
applicants for offices in Louisiana. I have understood that for every
office there were at least one hundred and fifty applications. Thus
much for the idea which has been thrown out of the existence of a
scarcity of characters to supply these offices.
Mr. Varnum considered the resolution as going too far, and said it
was a very common thing for two offices to be united in one man. It
had been usual to unite the diplomatic character with the military
command in our intercourse with the Indians, and a diplomatic
character had likewise been given to our naval commander in the
Mediterranean. Instances of a plurality of offices in one person were
very numerous. If there existed, at present, any case, in which such
a union was incompatible with the discharge of official duties, he
hoped it would be pointed out; whether there was or was not, he
could not say. But where did the responsibility for such appointments
lie? Not that House, but the other branch of the Legislature was
responsible; for the correct discharge of whose duties they were
accountable to the people. Where, then, was the propriety of an
interference by the House? If the President made an appointment
against the spirit of the constitution, the people would know it. Was
it presumable that if a law was to pass this House, predicated on the
resolution under consideration, the other branch of the Legislature
would agree to it, after having sanctioned the appointments at which
it is levelled? Was this House to sit as a court of censure? The
constitution did not delegate such a power. Our very laws, in various
cases, direct the union of office prescribed by the resolution. Ought
we not, then, in the first place, to repeal those laws before we pass
a resolution in direct hostility to them?
Mr. V. said, he had no hesitation to observe, that the military and
civil office should, in general, be kept distinct; but he believed there
were cases where it was necessary. He was perfectly willing to leave
the responsibility where the constitution had placed it—in the hands
of the President and Senate. With regard to the union of the military
office in the cases alluded to, he would not undertake to say
whether it was proper or not. He could readily, however, conceive,
that the union arose from the most correct motive, as the country
was a frontier, which might be menaced with danger, and which
might require the united exercise of the military and civil authority to
repel it.
Mr. J. Clay said he would ask whether the ordinary union of
military and civil powers in the Governors of the Territories was such
as that contemplated in the resolution? The case of the Governor of
Louisiana had been alluded to, where the same person, he believed,
received the pay of Governor and Brigadier. Is that the case with the
other Governors? He believed gentlemen would not say that it was
necessary that the Governor of New Orleans should be a brigadier-
general in the army; and yet they allowed that to be the most
vulnerable point on the frontier. If, then, they say that the union is
necessary in one case, they will admit that it ought to be in the
other.
Mr. Leib said that, viewing the resolution as an abstract
proposition, he had no objection to giving it his support; but if it was
intended as a side attack upon the Administration, he was not
prepared to vote for it. Before he was prepared to act on it under
this view, he wished for facts which were not before the House. He,
therefore, moved a postponement of the resolution till Monday.
The motion to postpone was lost.
The question was then taken on agreeing to the resolution, and
decided in the negative—yeas 31, nays 81.

Wednesday, April 2.
Claim of Beaumarchais.

Mr. Bassett presented to the House a petition of Amelia Eugene


Beaumarchais, heiress and representative of the late Caron de
Beaumarchais, deceased, by J. A. Chevallie, her attorney, which was
received and read, praying to be relieved from an unfavorable
settlement at the Treasury of the United States, of the accounts of
the deceased, for supplies furnished, and services rendered to the
United States, during the Revolutionary war with Great Britain.
Ordered, That the said petition be referred to the Committee of
Claims.

Charlestown, Va.

Mr. Jackson called for the order of the day, on the report of the
Committee of Commerce and Manufactures, on the petition of
sundry inhabitants of Charlestown, in Virginia, praying that that
place should be made a port of entry.
Mr. Leib moved an indefinite postponement of the report.
Mr. Jackson opposed this motion, and spoke at some length in
favor of the constitutional right of the petitioners to be allowed a
port of entry.
Mr. Crowninshield, though against postponement and in favor of
discussing the principle, contested the right.
Mr. Leib withdrew his motion; when the motion to consider the
report was disagreed to—only 13 members rising in favor of it.

Exclusion of Army and Naval Officers from Civil Offices.

The House took up the unfinished business of yesterday, being the


report of the Committee of the Whole, agreeing to the following
resolution, offered by Mr. J. Randolph:
3d. Resolved, That provision ought to be made, by law, to render
any officer in the Army or Navy of the United States incapable of
holding any civil office under the United States.

Mr. Fisk moved to postpone this resolution indefinitely.


This motion was supported by Messrs. Fisk, Elmer, and Cook; and
opposed by Messrs. J. Clay, J. Randolph, and J. C. Smith.
When the question was taken by yeas and nays, and the motion
disagreed to—yeas 43, nays 72.
The question was then taken that the House do agree with the
Committee of the whole House in their agreement to the said
resolution, and resolved in the affirmative—yeas 94, nays 21, as
follows:

Yeas.—Willis Alston, jun., Isaac Anderson, David Bard, Burwell


Bassett, George M. Bedinger, Silas Betton, William Blackledge, John
Blake, junior, Thomas Blount, Robert Brown, William Butler, John
Campbell, Levi Casey, Martin Chittenden, John Claiborne, Christopher
Clark, Joseph Clay, Matthew Clay, John Clopton, Frederick Conrad,
Leonard Covington, John Dawson, William Dickson, Elias Earle, Peter
Early, James Elliot, Caleb Ellis, William Ely, John W. Eppes, William
Findlay, James Fisk, James M. Garnett, Peterson Goodwyn, Edwin
Gray, Andrew Gregg, Silas Halsey, John Hamilton, Seth Hastings,
David Holmes, David Hough, John G. Jackson, Walter Jones, Thomas
Kenan, John Lambert, Michael Leib, Joseph Lewis, junior, Duncan
MacFarland, Robert Marion, Josiah Masters, Nicholas R. Moore,
Thomas Moore, Jeremiah Morrow, John Morrow, Jonathan O. Mosely,
Gurdon S. Mumford, Thomas Newton, junior, Gideon Olin, Timothy
Pitkin, jun., John Pugh, Josiah Quincy, John Randolph, Thomas M.
Randolph, John Rea of Pennsylvania, Jacob Richards, Peter Sailly,
Thomas Sammons, Thomas Sanford, Martin G. Schuneman, John
Smilie, John Cotton Smith, John Smith, Samuel Smith, Thomas
Spalding, Richard Stanford, Joseph Stanton, William Stedman, Lewis
B. Sturges, Samuel Taggart, Benjamin Tallmadge, Samuel Tenney,
David Thomas, Philip R. Thompson, Thomas W. Thompson, Uri
Tracy, Abram Trigg, Killian K. Van Rensselaer, Peleg Wadsworth,
Robert Whitehill, David R. Williams, Marmaduke Williams, Nathan
Williams, Alexander Wilson, Richard Wynn, and Joseph Winston.
Nays.—Evan Alexander, Joseph Barker, Barnabas Bidwell, John
Chandler, Orchard Cook, Jacob Crowninshield, Richard Cutts, Ezra
Darby, John Davenport, junior, Ebenezer Elmer, Isaiah L. Green,
James Kelly, William McCreery, Roger Nelson, John Rhea of
Tennessee, John Russell, Ebenezer Seaver, James Sloan, Joseph B.
Varnum, John Whitehill, and Eliphalet Wickes.

Ordered, That a bill, or bills, be brought, in pursuant to the said


resolution; and that Mr. John Randolph, Mr. David R. Williams, and Mr.
John C. Smith, do prepare and bring in the same.

Friday, April 4.
Prohibition of Military Officers from holding Civil Office.

Mr. John Randolph, from the committee appointed on the second


instant, presented a bill to prohibit officers of the Army and Navy
from holding or exercising any civil office; which was read twice, and
committed to a Committee of the Whole to-morrow.

Tuesday, April 8.
Motion to Adjourn.

On motion of Mr. Early,

“Resolved by the Senate and House of Representatives of the


United States of America, in Congress assembled, That the President
of the Senate and the Speaker of the House of Representatives be,
and they are hereby, authorized to adjourn their respective Houses
on Wednesday, the sixteenth of April instant.”

Ordered, That the Clerk of this House do carry the said resolution
to the Senate, and desire their concurrence.

Thursday, April 10.


Navy Appropriations.

The House resolved itself into a Committee of the Whole, on the


bill making appropriations for the support of the Navy of the United
States, during the year one thousand eight hundred and six.
The bill was read by sections.
The Chairman having read that part of the bill which makes an
appropriation “for repair of vessels, store rent, pay of armorers,
freight, and other contingent expenses,”[37]
Mr. J. Randolph moved to fill the blank with $411,950.
Mr. D. R. Williams moved to strike out the words “and other
contingent expenses.” He said he made this motion with a view of
ascertaining for what objects these contingent expenses were
intended to provide. He would ask the Chairman of the Committee of
Ways and Means for information on this point. He believed the sum
contemplated to be appropriated unnecessarily large.
Mr. J. Randolph said the gentleman had asked for information
which it was not in his power to give. He was as much in the dark as
the gentleman as to the items of contingent expenditure; and he
should not have moved to fill this blank with so large a sum, but
from the conviction that whether they provided the money or not, it
would be spent, and an additional appropriation be made the next
session. Mr. R. said he viewed an appropriation bill, under present
circumstances, a mere matter of form; he believed also all the items
of appropriation might as well be lumped together, and it might be
declared that a million of dollars were appropriated. Had he been
governed by his own opinion, instead of the forms which had been
observed, he would have been in favor of drafting the bill in this
way, for this reason: If the expenditures of the Navy exceeded this
sum by $600,000 there was no doubt the next Congress would make
good the deficiency without any inquiry. He believed this, as what
had taken place once might take place again.
Mr. R. said he had addressed a note to the head of the
department, stating that on such a day the Committee of Ways and
Means wished the appropriation bill to be taken up, and expressing a
desire that he would give them information of the items of
contingent expenditure, as they consider the sum required
unnecessarily large. He had received an answer to this effect—the
Secretary said he did not think the sum too large, without entering
into any explanation. Mr. R. added, gentlemen may fill the blank as
they please; it will be no check on the expenditure.
The Committee divided on agreeing to the sum named by Mr.
Randolph—ayes 46, noes 37.
Mr. D. R. Williams moved to strike out “and other contingent
expenses.” He had before said that he had been impelled to make
this motion from a sense of duty. This impression had been
strengthened by the statement of the Chairman of the Committee of
Ways and Means. He could not think it proper to make an
appropriation to so large an amount, when the proper organ of the
House had without success required information from the head of
the department, from whom he had only received a mere opinion.
He hoped the committee would agree to strike out this general
appropriation, that all the items of contingent expenditure might be
stated to the House, and thereby form some check on the
expenditure.
Mr. Leib said he perceived in another part of the bill other mention
made of contingent expenses. He would be glad to know what they
were. The House ought to know the various items, or otherwise
make a general provision for contingent expenses, and leave it to
the head of the department to apply the money as he pleases.
Mr. Dana said the first contingent appropriation was for the navy,
the second for the marine corps. If striking out the proposed words
would enable the committee to obtain the information sought, he
should vote for the motion. He had no objection to voting liberally
for a navy; but he thought the Legislature ought to be well informed,
as they would otherwise scarcely discharge their duty to their
constituents.
The motion of Mr. Williams, to strike out “and other contingent
expenses,” was disagreed to—ayes 32.
Mr. J. Randolph moved to strike out that part of the bill making an
appropriation “for completing the marine barracks at the city of
Washington.” Mr. R. said this object appeared to require a standing
appropriation; and, though the building was finite, the appropriation
appeared to be infinite.
Motion agreed to—ayes 66.
The committee rose and reported the bill. The House having taken
the report of the committee into consideration,
Mr. D. R. Williams, called for the reading of the document, stating
the annual expenditures on the Navy, by which it appeared that the
expenditures had been as follows:

For 1798 $ 570,314 24


1799 2,848,187 26
1800 3,385,340 48
1801 2,117,420 74
1802 946,213 24
1803 1,107,925 32
1804 1,246,502 74
1805 1,409,949 67
Total 13,631,853 00
Mr. D. R. W. renewed his motion to strike out “and other
contingent expenses.” He thought the House ought, under existing
circumstances, to show a disposition to economize, and to curtail the
expenses of the Navy. What is the necessity for this expenditure?
Why, the Constitution is in the mud, and the President[38] on her
beam ends! Thirteen millions and a half have been already
expended, and it is now proposed to add $411,000 for contingent
expenses. In making this motion I have no object but to confine the
Navy Department to proper expenses; but let them first state what
they are.
The Speaker observed that this motion could not be received until
the amendments of the committee had been acted upon.
Mr. D. R. Williams moved to strike out “for ordnance $50,000,”[39]
He did not perceive the use of this appropriation. No gentlemen
accustomed to travel, but must have seen the unprotected state of
the ordnance; look at the Turk’s house, you will there see it lying
exposed. To his knowledge it was in many other instances in the
same situation.
This motion was lost—ayes 33.
The amendment of the committee to fill the blank with “$50,000,”
was agreed to, without a division.
Mr. Eppes offered a proviso declaring that a larger sum than
$30,000 shall not be expended on the repairs of any one frigate.
Mr. J. Randolph.—I shall vote against this motion on the same
principle that I voted to fill the blank relative to contingent expenses,
with $411,000. If we cannot restrain the expenditures of the Navy
Department within the sum annually fixed, after giving as much as is
asked for, is it not the idlest thing to attempt to restrain them by
giving less? The principle on which I voted for filling that blank was
this: To give to the Navy Department what it asks, that if, at the end
of the year, more shall be expended, the blame may fall on the
shoulders of the Secretary, and not on us. The sum appropriated for
contingent expenses amounts to $411,000; this is not the half, but it

You might also like