Download as pdf or txt
Download as pdf or txt
You are on page 1of 53

Full download test bank at ebook textbookfull.

com

Practical Programming 3rd Edition

CLICK LINK TO DOWLOAD

https://textbookfull.com/product/practical-
programming-3rd-edition-paul-gries/

textbookfull
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Practical Programming An Introduction to Computer


Science Using Python 3 6 3rd Edition Paul Gries

https://textbookfull.com/product/practical-programming-an-
introduction-to-computer-science-using-python-3-6-3rd-edition-
paul-gries/

Programming Scala 3rd Edition Dean Wampler

https://textbookfull.com/product/programming-scala-3rd-edition-
dean-wampler/

Business Management ANSWERS 3rd Edition Paul Hoang

https://textbookfull.com/product/business-management-answers-3rd-
edition-paul-hoang/

Essentials of Programming in Mathematica 1st Edition


Paul Wellin

https://textbookfull.com/product/essentials-of-programming-in-
mathematica-1st-edition-paul-wellin/
Practical Electronics for Inventors, Fourth Edition
Paul Scherz

https://textbookfull.com/product/practical-electronics-for-
inventors-fourth-edition-paul-scherz/

Business Management Workbook ANSWERS 3rd Edition Paul


Hoang

https://textbookfull.com/product/business-management-workbook-
answers-3rd-edition-paul-hoang/

Efficient R Programming A Practical Guide to Smarter


Programming 1st Edition Colin Gillespie

https://textbookfull.com/product/efficient-r-programming-a-
practical-guide-to-smarter-programming-1st-edition-colin-
gillespie/

Practical Numerical C Programming 1st Edition Philip


Joyce

https://textbookfull.com/product/practical-numerical-c-
programming-1st-edition-philip-joyce/

JavaScript Cookbook: Programming the Web 3rd Edition


Scott

https://textbookfull.com/product/javascript-cookbook-programming-
the-web-3rd-edition-scott/
Acknowledgments
This book would be confusing and riddled with errors if it
weren’t for a bunch of awesome people who patiently and
carefully read our drafts.

We had a great team of people provide technical reviews for this


edition and previous editions: in no particular order, Frank
Ruiz, Stefan Turalski, Stephen Wolff, Peter W.A. Wood, Steve
Wolfman, Adam Foster, Owen Nelson, Arturo Martínez
Peguero, C. Keith Ray, Michael Szamosi, David Gries, Peter
Beens, Edward Branley, Paul Holbrook, Kristie Jolliffe, Mike
Riley, Sean Stickle, Tim Ottinger, Bill Dudney, Dan Zingaro, and
Justin Stanley. We also appreciate all the people who reported
errata: your feedback was invaluable.

Greg Wilson started us on this journey when he proposed that


we write a textbook, and he was our guide and mentor as we
worked together to create the first edition of this book.

Finally, we would like to thank our editor Tammy Coron, who


set up a workflow that made the tight timeline possible. Tammy,
your gentle nudges kept us on track (squirrel!) and helped us
complete this third edition in record time.

Copyright © 2018, The Pragmatic Bookshelf.


Preface
This book uses the Python programming language to teach
introductory computer science topics and a handful of useful
applications. You’ll certainly learn a fair amount of Python as
you work through this book, but along the way you’ll also learn
about issues that every programmer needs to know: ways to
approach a problem and break it down into parts, how and why
to document your code, how to test your code to help ensure
your program does what you want it to, and more.

We chose Python for several reasons:

It is free and well documented. In fact, Python is one of the largest


and best-organized open source projects going.

It runs everywhere. The reference implementation, written in C, is


used on everything from cell phones to supercomputers, and it’s
supported by professional-quality installers for Windows, macOS,
and Linux.

It has a clean syntax. Yes, every language makes this claim, but
during the several years that we have been using it at the University
of Toronto, we have found that students make noticeably fewer
“punctuation” mistakes with Python than with C-like languages.

It is relevant. Thousands of companies use it every day: it is one of


the languages used at Google, Industrial Light & Magic uses it
extensively, and large portions of the game EVE Online are written
in Python. It is also widely used by academic research groups.

It is well supported by tools. Legacy editors like vi and Emacs all


have Python editing modes, and several professional-quality IDEs
are available. (We use IDLE, the free development environment that
comes with a standard Python installation.)
Online Resources
All the source code, errata, discussion forums, installation
instructions, and exercise solutions are available at
http://pragprog.com/book/gwpy3/practical-programming.

Footnotes

[1]

See http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html.

[2]

See http://learnyousomeerlang.com.

[3]

See http://learnyouahaskell.com.

Copyright © 2018, The Pragmatic Bookshelf.


Chapter 1
What’s Programming?

(Photo credit: NASA/Goddard Space Flight Center Scientific


Visualization Studio)

Take a look at the pictures above. The first one shows forest
cover in the Amazon basin in 1975. The second one shows the
same area twenty-six years later. Anyone can see that much of
the rainforest has been destroyed, but how much is “much”?

Now look at this:

(Photo credit: CDC)


Are these blood cells healthy? Do any of them show signs of
leukemia? It would take an expert doctor a few minutes to tell.
Multiply those minutes by the number of people who need to be
screened. There simply aren’t enough human doctors in the
world to check everyone.

This is where computers come in. Computer programs can


measure the differences between two pictures and count the
number of oddly shaped platelets in a blood sample. Geneticists
use programs to analyze gene sequences; statisticians, to
analyze the spread of diseases; geologists, to predict the effects
of earthquakes; economists, to analyze fluctuations in the stock
market; and climatologists, to study global warming. More and
more scientists are writing programs to help them do their
work. In turn, those programs are making entirely new kinds of
science possible.

Of course, computers are good for a lot more than just science.
We used computers to write this book. Your smartphone is a
pretty powerful computer; you’ve probably used one today to
chat with friends, check your lecture notes, or look for a
restaurant that serves pizza and Chinese food. Every day,
someone figures out how to make a computer do something that
has never been done before. Together, those “somethings” are
changing the world.

This book will teach you how to make computers do what you
want them to do. You may be planning to be a doctor, a linguist,
or a physicist rather than a full-time programmer, but whatever
you do, being able to program is as important as being able to
write a letter or do basic arithmetic.
We begin in this chapter by explaining what programs and
programming are. We then define a few terms and present some
useful bits of information for course instructors.
Programs and Programming
A program is a set of instructions. When you write down
directions to your house for a friend, you are writing a program.
Your friend “executes” that program by following each
instruction in turn.

Every program is written in terms of a few basic operations that


its reader already understands. For example, the set of
operations that your friend can understand might include the
following: “Turn left at Darwin Street,” “Go forward three
blocks,” and “If you get to the gas station, turn around—you’ve
gone too far.”

Computers are similar but have a different set of operations.


Some operations are mathematical, like “Take the square root of
a number,” whereas others include “Read a line from the file
named data.txt” and “Make a pixel blue.”

The most important difference between a computer and an old-


fashioned calculator is that you can “teach” a computer new
operations by defining them in terms of old ones. For example,
you can teach the computer that “Take the average” means “Add
up the numbers in a sequence and divide by the sequence’s
size.” You can then use the operations you have just defined to
create still more operations, each layered on top of the ones that
came before. It’s a lot like creating life by putting atoms
together to make proteins and then combining proteins to build
cells, combining cells to make organs, and combining organs to
make a creature.
Defining new operations and combining them to do useful
things is the heart and soul of programming. It is also a
tremendously powerful way to think about other kinds of
problems. As Professor Jeannette Wing wrote in Computational
Thinking [Win06], computational thinking is about the
following:

Conceptualizing, not programming. Computer science isn’t


computer programming. Thinking like a computer scientist means
more than being able to program a computer: it requires thinking at
multiple levels of abstraction.

A way that humans, not computers, think. Computational thinking


is a way humans solve problems; it isn’t trying to get humans to
think like computers. Computers are dull and boring; humans are
clever and imaginative. We humans make computers exciting.
Equipped with computing devices, we use our cleverness to tackle
problems we wouldn’t dare take on before the age of computing and
build systems with functionality limited only by our imaginations.

For everyone, everywhere. Computational thinking will be a reality


when it becomes so integral to human endeavors it disappears as an
explicit philosophy.

We hope that by the time you have finished reading this book,
you will see the world in a slightly different way.
What’s a Programming Language?
Directions to the nearest bus station can be given in English,
Portuguese, Mandarin, Hindi, and many other languages. As
long as the people you’re talking to understand the language,
they’ll get to the bus station.

In the same way, there are many programming languages, and


they all can add numbers, read information from files, and
make user interfaces with windows and buttons and scroll bars.
The instructions look different, but they accomplish the same
task. For example, in the Python programming language, here’s
how you add 3 and 4:

​3 + 4

But here’s how it’s done in the Scheme programming language:

​(+ 3 4)

They both express the same idea—they just look different.

Every programming language has a way to write mathematical


expressions, repeat a list of instructions a number of times,
choose which of two instructions to do based on the current
information you have, and much more. In this book, you’ll learn
how to do these things in the Python programming language.
Once you understand Python, learning the next programming
language will be much easier.
What’s a Bug?
Pretty much everyone has had a program crash. A standard
story is that you were typing in a paper when, all of a sudden,
your word processor crashed. You had forgotten to save, and
you had to start all over again. Old versions of Microsoft
Windows used to crash more often than they should have,
showing the dreaded “blue screen of death.” (Happily, they’ve
gotten a lot better in the past several years.) Usually, your
computer shows some kind of cryptic error message when a
program crashes.

What happened in each case is that the people who wrote the
program told the computer to do something it couldn’t do: open
a file that didn’t exist, perhaps, or keep track of more
information than the computer could handle, or maybe repeat a
task with no way of stopping other than by rebooting the
computer. (Programmers don’t mean to make these kinds of
mistakes, they are just part of the programming process.)

Worse, some bugs don’t cause a crash; instead, they give


incorrect information. (This is worse because at least with a
crash you’ll notice that there’s a problem.) As a real-life example
of this kind of bug, the calendar program that one of the authors
uses contains an entry for a friend who was born in 1978. That
friend, according to the calendar program, had his 5,875,542nd
birthday this past February. Bugs can be entertaining, but they
can also be tremendously frustrating.

Every piece of software that you can buy has bugs in it. Part of
your job as a programmer is to minimize the number of bugs
and to reduce their severity. In order to find a bug, you need to
track down where you gave the wrong instructions, then you
need to figure out the right instructions, and then you need to
update the program without introducing other bugs.

Every time you get a software update for a program, it is for one
of two reasons: new features were added to a program or bugs
were fixed. It’s always a game of economics for the software
company: are there few enough bugs, and are they minor
enough or infrequent enough in order for people to pay for the
software?

In this book, we’ll show you some fundamental techniques for


finding and fixing bugs and also show you how to prevent them
in the first place.
The Difference Between Brackets,
Braces, and Parentheses
One of the pieces of terminology that causes confusion is what
to call certain characters. Several dictionaries use these names,
so this book does too:

() Parentheses

[] Brackets

Braces (Some people call these curly brackets or curly braces,


{}
but we’ll stick to just braces.)
Installing Python
Installation instructions and use of the IDLE programming
environment are available on the book’s website:
http://pragprog.com/titles/gwpy3/practical-programming.

Copyright © 2018, The Pragmatic Bookshelf.


Chapter 2
Hello, Python
Programs are made up of commands that tell the computer
what to do. These commands are called statements, which the
computer executes. This chapter describes the simplest of
Python’s statements and shows how they can be used to do
arithmetic, which is one of the most common tasks for
computers and also a great place to start learning to program.
It’s also the basis of almost everything that follows.
How Does a Computer Run a Python
Program?
In order to understand what happens when you’re
programming, it helps to have have a mental model of how a
computer executes a program.

The computer is assembled from pieces of hardware, including


a processor that can execute instructions and do arithmetic, a
place to store data such as a hard drive, and various other
pieces, such as a screen, a keyboard, an Ethernet controller for
connecting to a network, and so on.

To deal with all these pieces, every computer runs some kind of
operating system, such as Microsoft Windows, Linux, or
macOS. An operating system, or OS, is a program; what makes
it special is that it’s the only program on the computer that’s
allowed direct access to the hardware. When any other
application (such as your browser, a spreadsheet program, or a
game) wants to draw on the screen, find out what key was just
pressed on the keyboard, or fetch data from storage, it sends a
request to the OS (see the top image).

This may seem like a roundabout way of doing things, but it


means that only the people writing the OS have to worry about
the differences between one graphics card and another and
whether the computer is connected to a network through
Ethernet or wireless. The rest of us—everyone analyzing
scientific data or creating 3D virtual chat rooms—only have to
learn our way around the OS, and our programs will then run
on thousands of different kinds of hardware.

Today, it’s common to add another layer between the


programmer and the computer’s hardware. When you write a
program in Python, Java, or Visual Basic, it doesn’t run directly
on top of the OS. Instead, another program, called an
interpreter or virtual machine, takes your program and runs it
for you, translating your commands into a language the OS
understands. It’s a lot easier, more secure, and more portable
across operating systems than writing programs directly on top
of the OS:

There are two ways to use the Python interpreter. One is to tell
it to execute a Python program that is saved in a file with a .py
extension. Another is to interact with it in a program called a
shell, where you type statements one at a time. The interpreter
will execute each statement when you type it, do what the
statement says to do, and show any output as text, all in one
window. We will explore Python in this chapter using a Python
shell.

Install Python Now (If You Haven't Already)


If you haven’t yet installed Python 3.6, please do so now. (Python 2 won’t do; there are
significant differences between Python 2 and Python 3, and this book uses Python 3.6.)
Locate installation instructions on the book’s website:
http://pragprog.com/titles/gwpy3/practical-programming.

Programming requires practice: you won’t learn how to program just by reading this book,
much like you wouldn’t learn how to play guitar just by reading a book on how to play guitar.

Python comes with a program called IDLE, which we use to write Python programs. IDLE
has a Python shell that communicates with the Python interpreter and also allows you to
write and run programs that are saved in a file.

We strongly recommend that you open IDLE and follow along with our examples. Typing in
the code in this book is the programming equivalent of repeating phrases back to an
instructor as you’re learning to speak a new language.
Expressions and Values: Arithmetic in
Python
You’re familiar with mathematical expressions like 3 + 4 (“three
plus four”) and 2 - 3 / 5 (“two minus three divided by five”);
each expression is built out of values like 2, 3, and 5 and
operators like + and -, which combine their operands in
different ways. In the expression 4 / 5, the operator is “/” and
the operands are 4 and 5.

Expressions don’t have to involve an operator: a number by


itself is an expression. For example, we consider 212 to be an
expression as well as a value.

Like any programming language, Python can evaluate basic


mathematical expressions. For example, the following
expression adds 4 and 13:

​​>>>​​​4​​+​13​
​17

The >>> symbol is called a prompt. When you opened IDLE, a


window should have opened with this symbol shown; you don’t
type it. It is prompting you to type something. Here we typed 4
+ 13, and then we pressed the Return (or Enter) key in order to
signal that we were done entering that expression. Python then
evaluated the expression.

When an expression is evaluated, it produces a single value. In


the previous expression, the evaluation of 4 + 13 produced the
value 17. When you type the expression in the shell, Python
shows the value that is produced.

Subtraction and multiplication are similarly unsurprising:

​​>>>​​​15​​​-​​3​
​12
​​>>>​​​4​​*​​7​
​28

The following expression divides 5 by 2:

​​>>>​​​5​​/​​2​
​2.5

The result has a decimal point. In fact, the result of division


always has a decimal point even if the result is a whole number:

​​>>>​​​4​​/​​2​
​2.0

TYPES
Every value in Python has a particular type, and the types of
values determine how they behave when they’re combined.
Values like 4 and 17 have type int (short for integer), and values
like 2.5 and 17.0 have type float. The word float is short for
floating point, which refers to the decimal point that moves
around between digits of the number.

An expression involving two floats produces a float:

​​>>>​​​17.0​​​-​​10.0​
​7.0

When an expression’s operands are an int and a float, Python


automatically converts the int to a float. This is why the
following two expressions both return the same answer:

​​>>>​​​17.0​​​-​​10​
​7.0
​​>>>​​​17​​​-​​10.0​
​7.0

If you want, you can omit the zero after the decimal point when
writing a floating-point number:

​​>>>​​​17​​​-​​10.​
​7.0
​​>>>​​​17.​​​- ​10​
​7.0

However, most people think this is bad style, since it makes


your programs harder to read: it’s very easy to miss a dot on the
screen and see 17 instead of 17..

INTEGER DIVISION, MODULO, AND


EXPONENTIATION
Every now and then, we want only the integer part of a division
result. For example, we might want to know how many 24-hour
days there are in 53 hours (which is two 24-hour days plus
another 5 hours). To calculate the number of days, we can use
integer division:

​​>>>​​​53​​​//​​​24​
​2

We can find out how many hours are left over using the modulo
operator, which gives the remainder of the division:

​​>>>​​​53​​​%​​24​
​5

Python doesn’t round the result of integer division. Instead, it


takes the floor of the result of the division, which means that it
rounds down to the nearest integer:

​​>>>​​​17​​​//​​​10​
​1

Be careful about using % and // with negative operands.


Because Python takes the floor of the result of an integer
division, the result is one smaller than you might expect if the
result is negative:

​​>>>​​​-17​​​//​​​10​
​-2

When using modulo, the sign of the result matches the sign of
the divisor (the second operand):

​​>>>​​​-17​​​%​​10​
​3
​​>>>​​​17​​​%​​-10​
​-3
For the mathematically inclined, the relationship between //
and % comes from this equation, for any two non-zero numbers
a and b:

​(b * (a // b) + a % b) is equal to a

For example, because -17 // 10 is -2, and -17 % 10 is 3; then 10 *


(-17 // 10) + -17 % 10 is the same as 10 * -2 + 3, which is -17.

Floating-point numbers can be operands for // and % as well.


With //, division is performed and the result is rounded down
to the nearest whole number, although the type is a floating-
point number:

​​>>>​​​3.3​​​//​​​1​
​3.0
​​>>>​​​3​​//​​1.0​
​3.0
​​>>>​​​3​​//​​1.1​
​2.0
​​>>>​​​3.5​​​//​​​1.1​
​3.0
​​>>>​​​3.5​​​//​​​1.3​
​2.0

The following expression calculates 3 raised to the 6th power:

​​>>>​​​3​​**​​​6​
​729

Operators that have two operands are called binary operators.


Negation is a unary operator because it applies to one operand:

​​>>>​​​-5​
​-5
​​>>>​​​--5
​5
​​>>>​​​---5​
​-5
What Is a Type?
We’ve now seen two types of numbers (integers and floating-
point numbers), so we ought to explain what we mean by a type.
In Python, a type consists of two things:

A set of values

A set of operations that can be applied to those values

For example, in type int, the values are …, -3, -2, -1, 0, 1, 2, 3, …
and we have seen that these operators can be applied to those
values: +, -, *, /, //, %, and **.

The values in type float are a subset of the real numbers, and it
happens that the same set of operations can be applied to float
values. We can see what happens when these are applied to
various values in Table 1, ​Arithmetic Operators​. If an operator
can be applied to more than one type of value, it is called an
overloaded operator.

Table 1. Arithmetic Operators

Symbol Operator Example Result

- Negation -5 -5

+ Addition 11 + 3.1 14.1

- Subtraction 5 - 19 -14
Symbol Operator Example Result

* Multiplication 8.5 * 4 34.0

/ Division 11 / 2 5.5

// Integer Division 11 // 2 5

% Remainder 8.5 % 3.5 1.5

** Exponentiation 2 ** 5 32

FINITE PRECISION
Floating-point numbers are not exactly the fractions you
learned in grade school. For example, look at Python’s version
of the fractions 2/3 and 5/3:

​​>>>​​​2​​/​​3​
​0.6666666666666666
​​>>>​​​5​​/​​3​
​1.6666666666666667

The first value ends with a 6, and the second with a 7. This is
fishy: both of them should have an infinite number of 6s after
the decimal point. The problem is that computers have a finite
amount of memory, and (to make calculations fast and memory
efficient) most programming languages limit how much
information can be stored for any single number. The number
0.6666666666666666 turns out to be the closest value to 2/3
that the computer can actually store in that limited amount of
memory, and 1.6666666666666667 is as close as we get to the
real value of 5/3.

More on Numeric Precision

Integers (values of type int) in Python can be as large or as small as you like. However, float
values are only approximations to real numbers. For example, 1/4 can be stored exactly, but
as we’ve already seen, 2/3 cannot. Using more memory won’t solve the problem, though it
will make the approximation closer to the real value, just as writing a larger number of 6s
after the 0 in 0.666… doesn’t make it exactly equal to 2/3.

The difference between 2/3 and 0.6666666666666666 may look tiny. But if we use
0.6666666666666666 in a calculation, then the error may get compounded. For example, if
we add 1 to 2/3, the resulting value ends in …6665, so in many programming languages, 1 +
2/3 is not equal to 5/3:

​​>>>​​​2​​/​​3​​+​​1​
​1.6666666666666665
​​>>>​​​5​​/​​3​
​1.6666666666666667

As we do more calculations, the rounding errors can get larger and larger, particularly if we’re
mixing very large and very small numbers. For example, suppose we add 10000000000 (10
billion) and 0.00000000001 (there are 10 zeros after the decimal point):

​​>>>​​​10000000000​​​+​​0.00000000001​
​10000000000.0

The result ought to have twenty zeros between the first and last significant digit, but that’s
too many for the computer to store, so the result is just 10000000000—it’s as if the addition
never took place. Adding lots of small numbers to a large one can therefore have no effect at
all, which is not what a bank wants when it totals up the values of its customers’ savings
accounts.

It’s important to be aware of the floating-point issue. There is no magic bullet to solve it,
because computers are limited in both memory and speed. Numerical analysis, the study of
algorithms to approximate continuous mathematics, is one of the largest subfields of
computer science and mathematics.

Here’s a tip: If you have to add up floating-point numbers, add them from smallest to largest
in order to minimize the error.
Another random document with
no related content on Scribd:
Scrap.—After the lard is drawn from the cooking kettle, the scrap
should be drawn from the bottom. This scrap is used in the
prime steam lard tank. If, however, there is no other provision for
handling the scrap, it should be put into a hoop press (Fig. 150), and
pressure applied, thereby liberating all the oil left in the residue, the
scrap then being used as “pressed scrap.”
Packing and Cooling.—Kettle rendered lard is usually sold and
used more extensively during the cooler weather. It is very desirable
that there should be a light, fluffy top. This is only possible when the
lard is drawn hot in a cool room; chilling the lard rapidly causes this
appearance at the top, which is always looked upon by the trade as
a mark of excellence. When the lard is drawn off into small packages
they are placed one on top of the other, covering the top with paper.
The cover should not be put on the package until it is chilled,
otherwise the fluffy appearance is lost.
FIG. 150.—HOOP PRESS.

Drawing Temperatures.—When drawn into wooden packages,


such as ten, twenty or fifty pound pails, lard should be drawn at 150°
F. If drawn into tins it should be drawn off at 175° to 180° F.; when
drawn into tierces, barrels or half barrels it should be drawn at about
130° F. When drawing lard into wooden packages they should be
silicated the day before, giving them ample time to dry, as this
prevents the packages from soaking up the lard and also prevents
excessive shrinkage of the package.
Refining Prime Steam Lard.—Refined prime steam lard is made
into two products, pure refined lard and lard with beef fat added.
Pure Refined Lard.—Pure refined lard consists of prime steam
lard with lard stearine added. This is a product resulting when prime
steam lard is pressed to obtain lard oil, a process described later;
however, the quantity available is quite limited. Descriptions will be
confined to the making of lard with beef fat added.
FIG. 151.—SECTION THROUGH TANK FOR MIXING FULLERS EARTH AND
LARD.

Fullers Earth.—About thirty years ago the method of refining lard


with fullers earth was first inaugurated, and for years only imported
earth from England was thought suitable for this purpose. Deposits
of fullers earth, of fair quality, have been discovered in the United
States and American fullers earth is today used in some lard
refineries. Indications are that with improvements in mining and
methods of grinding, and possibly also in the discovery of better
beds or layers of this substance, manufacturers will not continue to
go abroad for supplies of fullers earth.
An explanation of how fullers earth bleaches lard and its kindred
fats would be interesting, if anyone knew the exact explanation, but
so far there has been no scientific reason given that accounts for this
property of this material, therefore no chemical test can be applied to
different samples of fullers earth to determine whether they are
suitable for refining or not. The only safe test is the practical one of
heating a sample together with lard and watching the result of the
bleach.
Fullers earth is used for bleaching cotton seed oil and other
greases and fats which are subjected to the bleaching process. In
improving the color of lard it is done at the expense of flavor, and a
wholesome odor, which is natural to the lard, is sacrificed in a
greater or lesser degree to the advantage of color. The tendency is
to make lard white, even though it loses in odor and taste. In
compounding lard this is intensified by the general use of tallow.
FIG. 152.—FULLERS EARTH KETTLE FOR SMALL HOUSES.

Bleaching Kettle.—This can be of a predominant size dependent


upon the volume of business. For a moderate business the most
suitable dimensions are about six feet in diameter and four feet
deep. A sectional view of such a kettle is shown in Fig. 151 and a
smaller kettle is illustrated in Fig. 152. It was the practice to use
compressed air for agitation so as to mix the fullers earth with the
lard. This has been discontinued in the best refineries, as it was
found that agitation with air had a tendency to make the lard turn
rancid more readily than if agitated by mechanical device.
The kettle is supplied with a vertical shaft, to the bottom of which is
attached a propellor about fourteen inches in diameter. Around this is
fitted a wire screen about thirty inches high made of galvanized wire,
³⁄₁₆-inch mesh, this screen clearing the blades of the fan about an
inch. On top of this screen is fixed an iron pipe approaching to within
about eighteen inches of the surface of the lard when the kettle is
filled. A kettle of this size will hold about 5,000 pounds of lard for
treatment. The agitating blade should revolve at a speed of from 125
to 175 revolutions per minute. This has the effect of producing a
miniature whirlpool in the body of lard by driving the lard through the
screen against the sides of the kettle, where it rises to the surface
and goes down through the funnel-shaped tube to be again driven
through the screen. In this way the fullers earth is thoroughly mixed
in and if there is a tendency to “lump” the lumps are readily broken
up by impact.
Bleaching Lard.—If cold lard is used it should be melted and any
sediment or moisture which settles should be drawn off. It is best not
to draw off too close to the bottom so as to avoid any moisture.
The temperature at which lard should be bleached is an important
matter to be determined. If the lard has been heavily cooked and has
a strong steam flavor, a temperature of 180° F. is correct. If the lard
has not been well cooked a somewhat lower temperature is
necessary. As a rule the lower the temperature at which bleaching is
done, the more fullers earth is required to get the proper bleach and
at the same time as little earth flavor as possible is a point for careful
and intelligent consideration. The best way to determine, where
there are large quantities of lard, is to take a small sample and make
tests in the laboratory. The point to be obtained is to get the bleach
with as little of the flavor of the earth as possible. Generally
speaking, from three-fourths to one and one-half per cent of fullers
earth will get the desired result.
When the lard is brought to the proper temperature, fullers earth is
put in the kettle, when it is agitated from eight to twelve minutes,
then pumped through the filter press as rapidly as possible. It takes a
certain length of time for fullers earth to do its work properly, and a
strong agitation of from eight to twelve minutes appears to be the
best method to adopt in order to obtain the full effect of the earth.
Refining Tallow Separately.—Where tallow is used in lard, it is
always advisable to bleach the tallow separately. This is done in the
same manner as described for lard, with the exception that about
three per cent of fullers earth is used, after which it is pumped
through the filter press and into the receiving tanks.

FIG. 153.—FILTER PRESS.

When it is compounded with the lard, the desired amount should


be put into the kettle with the lard after it is treated. The same is true
of oleo-stearine, except that in the bleaching of this article from one-
half to one and one-half per cent of fuller earth is sufficient.
Measures must be taken to see that ingredients are intimately mixed
before passing the product to the rolls.
The use of tallow or stearine is for the purpose of cheapening the
product, as well as hardening it, the formula for same being made
according to the values and conditions under which the lard is to be
sold. For instance lard going south, or into a warm climate, is made
much harder than lard for a temperate climate; hence lard formulas,
generally speaking, are worthless for general use, the different
formulas being made to suit widely different conditions, and their
availability also depends to a considerable extent upon the
fluctuation of values.
Filter Press.—After the contents of the kettle have been pumped
through the filter air pressure should be turned into
the filter press in order to blow out all the lard possible. After this live
steam should be turned on, expelling the balance of the lard from the
pipe. A large portion of this latter lard, however, is unfit to be used
again, as it contains sediment and fullers earth combined, having a
rank, strong odor, and can be used only for grease.

FIG. 154.—LARD COOLING CYLINDER.

Lard Roll.—This is a device provided for cooling lard in a film so


as to bring plenty of air in contact with the surface during the
congealing. After the lard has been put through the filtering press it
goes to a receiving tank and is next passed over rollers for chilling.
(Fig. 154.) These are cast iron cylinders containing refrigerated
brine. The cylinders revolve at from ten to fourteen revolutions per
minute, the lard being congealed on the outer surface. Fixed against
the side of the cylinder is the edge of a steel knife which scrapes
close to its surface. The lard, in contact with the cool surface of the
cylinders, congeals and as it passes to the knife it is removed and
drops into the trough. Here it is thoroughly beaten by a revolving
shaft with pickers on it, so that all lumps are broken and the grain is
of a smooth, even consistency. Pure lard passes to an agitator,
which is a jacketed kettle, where it is given a thorough agitation and
drawn off cool as possible, the object being to have the different
ingredients thoroughly mixed at a low temperature.
At times rolls are used in tandem. When a bountiful supply of cold
water, say at 60° F., is available, the saving in refrigeration justifies
the use of tandem rolls. In this instance the first roll is elevated so as
to gravitate the lard to the feed of the second.

WEIGHT OF LARD PACKAGES.


Weight Avg.
Weight packages material weight
3-POUND PAILS:
100 pails 43 lbs., 7 oz. 6.95 oz.
100 bails 5 lbs., 4 oz. .84 oz.
100 covers 9 lbs., 7 oz. 1.51 oz.
100 summer covers 6 lbs., 3 oz. .99 oz.
Average weight each ... 10.29 oz.
5-POUND PAILS:
100 pails 58 lbs., 12 oz. 9.40 oz.
100 bails 5 lbs., 15 oz. .95 oz.
100 covers 13 lbs. 2.08 oz.
100 summer covers 8 lbs., 10 oz. 1.38 oz.
Average weight each ... 13.81 oz.
10-POUND PAILS:
100 pails 92 lbs., 14 oz. 14.86 oz.
100 bails 7 lbs., 12 oz. 1.24 oz.
100 covers 19 lbs., 5 oz. 3.09 oz.
100 summer covers 13 lbs., 10 oz. 2.18 oz.
Average weight each ... 21.37 oz.
20-POUND PAILS:
100 pails 144 lbs., 15 oz. 23.19 oz.
100 bails 10 lbs., 9 oz. 1.69 oz.
100 covers 34 lbs. 5.44 oz.
100 summer covers 22 lbs., 4 oz. 3.56 oz.
Average weight each ... 33.88 oz.
40-POUND SQUARE CANS:
100 cans 268 lbs., 8 oz. 42.96 oz.
100 caps 2 lbs., 8 oz. .40 oz.
Average weight each ... 43.36 oz.
50-POUND ROUND CANS:
100 cans 270 lbs., 10 oz. 43.30 oz.
100 covers 50 lbs., 2 oz. 8.02 oz.
100 summer covers 38 lbs., 12 oz. 6.20 oz.
Average weight each ... 57.52 oz.

Lard Packing.—Refined lard is not usually drawn in a cooler. In


most climates the non-refrigerated rooms will suffice. It is packed in
tubs, barrels or tierces of wood. The lard, when available, in the
picker trough, is usually chilled and stiff. The use of a pump is made
to withdraw and force it through a strainer in an enlarged section of
the pipe, so as to effectually break all lumps. A relief valve should be
placed on the line to spill into the picker in case the draw cocks are
all suddenly closed.
Lard Packages.—In wooden packages tare is deducted. The
table on preceding page shows the actual weight of the different
packages which are usually made from an X L grade of tin.
Inasmuch as lard sells at more per pound than the tin costs, there is
always an endeavor to get the packages as heavy as consistent.
Country Style Lard.—Many moderate sized plants that do not
cater to a trade accustomed to highly refined lard, prefer to make
kettle rendered lard as most of their output, using leaf, back fat and
trimmings, adding the complimentary proportion of killing lard and
agitating the whole in a water jacketed agitator. All implements used
are similar to those described previously, also the method of drawing
from the agitator to packages is the same. Beef fat can be rendered
in the same way when oleo departments are not operated, and it can
thus be used to good advantage.
Compound—What it is.—Compound is a substitute for lard and
is made of cotton seed oil and oleo stearine, or tallow, or both. The
formula on this article varies according to the relative values of the
ingredients. The generally accepted formula is 80 per cent cotton
seed oil, and 20 per cent oleo stearine.
If the market price of oleo stearine is high, a formula may be
substituted as follows: 75 per cent cotton seed oil, 7¹⁄₂ percent tallow,
17¹⁄₂ per cent oleo stearine. In cold weather even a smaller amount
of stearine may be used and a proportionately larger amount of
tallow.
Cottonseed Oil.—This is a product derived from cotton seed.
Before the manufacture of cotton seed oil, the cotton seed, removed
from the cotton, was thrown in large compost heaps and after
decomposition, was used sparingly as a fertilizer. An idea of its value
may be gained from the following table. From one ton of seed, by
average, is obtained:

270 pounds or 36 gallons of oil at 28c per gallon $10.08


750 pounds cotton seed meal at 90c per 100 pounds 6.75
850 pounds hulls at 15c per 100 pounds 1.27
30 pounds lint at 3¹⁄₂c 1.05
Total value $19.15
100 pounds waste and dirt.

The oil when extracted from the seed is termed “crude oil.” In
refining this oil the loss varies from 7 per cent to 12 per cent, on an
average about 9¹⁄₄ per cent.
Refining Crude Oil.—The crude oil is purchased by refiners and
treated to produce “yellow oil.” In this process it is put into a tank (it
is generally considered profitable to refine cotton seed oil only in
large quantities) supplied with a revolving agitator. Into the tank is
put a solution of eighteen to twenty per cent caustic soda. The
quantity and strength of the solution necessary is determined by
treating a small sample. To a small sample of oil add the soda
solution, stirring continuously, having it heated to a temperature of
160° to 180° F. When sufficient soda lye has been added a floculent
precipitation will be noticed. This indicates a “breaking” of the oil. By
calculation of the relative amount the comparative quantities can be
arrived at.
An excessive amount of lye will saponify its equivalent in good oil,
therefore care must be exercised to see that only the proper amount
is used. In a practical way the soda is introduced in the crude oil
solution and agitation is started to insure the thorough mixing of the
caustic soda and the oil. The floculent substance appearing, the
agitation is stopped and the oil allowed to settle, the sediment and
substance other than oil collecting at the bottom of the tank. A small
quantity (about one-quarter of one per cent by weight) of fullers earth
is added and the oil removed by pumping through a filter press
producing what is known to the trade as “yellow oil.”
The sediment, known as “foots” is collected in kettles and treated
with additional lye, boiled and settled with salt; water added, settled
and drawn. This treatment is duplicated as many times as
necessary, until the soap stock will separate from impurities. When
thoroughly settled draw the soap stock into packages for the soap
trade. The finished “foots” contains about 33 to 40 per cent of
moisture and a small percentage of lye.
Deodorizing Cotton Seed Oil.—The “yellow oil” of trade has a
decided flavor which it is desirable to remove, and this process is
accomplished by deodorizing. (See Fig. 155.)
Treating Tank.—This tank is equipped for heating the oil to a very
high temperature by the introduction of a large coil surface,
preferably rings, one within the other and arranged so that each ring
is accessible. The kettle coils, etc., should be made extra heavy. The
top of the kettle must also be hooded and as the oil boils violently the
steam must be given free opportunity to escape. The escape pipe
should be at least sixteen to twenty inches in diameter in a tank six
feet in diameter, and should be provided with a goose neck, so that
the steam rising which condenses, does not drip back into the tank.
Fig. 155 show the construction of an oil treating tank.
The exhaust pipe extends into the atmosphere a short distance
above the deodorizing tanks. On account of the extreme agitation
caused by the heat, the oil is likely to boil over and waste. Special
attention is called to the crook or neck in the exhaust pipe with two-
inch outlet at the lowest point. This is done so that the condensation
will not run back into the oil, but can be taken out at this point.
Process For Oil.—The tank is filled with oil to about half its
capacity. The oil is then heated to a temperature
of 320° to 360° F. After being held at this temperature for an hour to
an hour and a half, it is ready for the washing process. This is done
by means of a two-inch perforated pipe at the top of the kettle,
through which is sprinkled cold water on the oil. The extreme
temperature evaporates the water very rapidly and at the same time
causes a precipitation. The water should be allowed to run for five
minutes, and then the body of oil should stand for from one to two
hours. The cone, or bottom of the kettle, will be found to have a
sediment which has been precipitated from the oil. This “bottom”
should be drawn off, and the steam again turned on the coils.
FIG. 155.—DEODORIZING TANK FOR COTTON SEED OILS.

Blowing.—The oil is heated to the original temperature and steam


of high pressure and temperature introduced into the body of the oil.
The length of time required for treating the oil depends largely upon
its nature, some oils being more neutral and more nearly odorless
than others, consequently no exact rule can be laid down that would
fit all cases; it must be left to the judgment of the person handling the
oil.
Pressure and Temperature.—To obtain the temperature above
mentioned a pressure of 150 pounds should be carried, and late
practice introduces a superheater for reheating the steam to insure
high temperature by adding 100° to 150° F. to the steam
temperature.
FIG. 156.—SECTION OF BOTTOM OF DEODORIZING TANK.

Bleaching Process.—As soon as the oil is deodorized it is drawn


off and allowed to cool. It is pumped into the treating kettle, or what
is known in refineries as the “dirt” kettle. There it is brought up to a
temperature of 160° F., when the fullers earth is added, generally
using from one to two percent of earth with this bleach, following an
agitation of about ten minutes. It should then be pumped through the
filter press into the receiving tank, where it is held until used. After
going through this process the oil is known to the trade as “water
white.”
FIG. 157.—SECTION THROUGH EXHAUST HOOD OF
DEODORIZING TANK.

Mixing.—Refined tallow or oleo stearine melted and clarified by


pumping through a filter press without the use of fullers earth is
added to the cotton seed oil so prepared, and the mixed substance,
containing proportions previously described, are ready for passing
over the cooling roll.
Filter Press.—The filter press (Fig. 158) should not be used more
than two or three times until it is taken apart, all the sediment and dirt
removed and clean cloths substituted. Continued use of filter cloths,
without proper cleaning, has a deteriorating effect upon the material
pumped through the presses, and different kinds of products should
not be passed through the same press.
Color and Roll Treatment.—Color is an important feature of
compound, when an odorless oil has been produced. The mixture
passed to the rolls is usually at a temperature of 120° F. and this
heated body of material amounting to 4000 pounds per hour on an
eight foot roll requires a very large capacity of refrigerating
equipment.
It is desirable to maintain a brine temperature in the shell of from
zero to five degrees above. A fifty-ton refrigerating equipment of
commercial rating is inadequate for this duty. Consequently
compound manufacturers must have ample refrigerating machine
capacity.
The lard roll is preferably of the size noted and should operate at
not to exceed seven revolutions per minute, provided brine of the
above temperature is supplied; fewer revolutions if temperature is
higher, which naturally reduces the capacity.
The lard roll, pump, and strainer equipment is the same as
described for lard, except that the lard is packed directly from the
picker trough without the use of an additional agitator.
Hydrogenation of Oils.—A new process has been devised
whereby soft oils, such as cotton seed oil, can be hardened so as to

You might also like