0% found this document useful (0 votes)
71 views

PDF Learning functional data structures and algorithms learn functional data structures and algorithms for your applications and bring their benefits to your work now Khot download

your

Uploaded by

pacotemendoj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

PDF Learning functional data structures and algorithms learn functional data structures and algorithms for your applications and bring their benefits to your work now Khot download

your

Uploaded by

pacotemendoj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Download the full version of the textbook now at textbookfull.

com

Learning functional data structures and


algorithms learn functional data structures
and algorithms for your applications and
bring their benefits to your work now Khot
https://textbookfull.com/product/learning-
functional-data-structures-and-algorithms-learn-
functional-data-structures-and-algorithms-for-
your-applications-and-bring-their-benefits-to-
your-work-now-khot/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Learning Functional Data Structures and Algorithms Learn


functional data structures and algorithms for your
applications and bring their benefits to your work now 1st
Edition Atul S. Khot
https://textbookfull.com/product/learning-functional-data-structures-
and-algorithms-learn-functional-data-structures-and-algorithms-for-
your-applications-and-bring-their-benefits-to-your-work-now-1st-
edition-atul-s-khot/
textbookfull.com

Probabilistic data structures and algorithms for big data


applications Gakhov

https://textbookfull.com/product/probabilistic-data-structures-and-
algorithms-for-big-data-applications-gakhov/

textbookfull.com

Data Structures and Algorithms in Swift Kevin Lau

https://textbookfull.com/product/data-structures-and-algorithms-in-
swift-kevin-lau/

textbookfull.com

Narratives Of Fear And Safety Kaisa Kaukiainen

https://textbookfull.com/product/narratives-of-fear-and-safety-kaisa-
kaukiainen/

textbookfull.com
Logic and Philosophy of Time Further Themes from Prior 1st
Edition Blackburn

https://textbookfull.com/product/logic-and-philosophy-of-time-further-
themes-from-prior-1st-edition-blackburn/

textbookfull.com

Intelligent Virtual Agents 14th International Conference


IVA 2014 Boston MA USA August 27 29 2014 Proceedings 1st
Edition Timothy Bickmore
https://textbookfull.com/product/intelligent-virtual-agents-14th-
international-conference-iva-2014-boston-ma-usa-
august-27-29-2014-proceedings-1st-edition-timothy-bickmore/
textbookfull.com

Discover Excellence: An Overview of the Shingo Model and


Its Guiding Principles 1st Edition Gerhard J. Plenert
(Editor)
https://textbookfull.com/product/discover-excellence-an-overview-of-
the-shingo-model-and-its-guiding-principles-1st-edition-gerhard-j-
plenert-editor/
textbookfull.com

Data Analytics & Visualization All-in-One For Dummies Jack


A. Hyman & Luca Massaron & Paul Mcfedries & John Paul
Mueller & Lillian Pierson & Jonathan Reichental
https://textbookfull.com/product/data-analytics-visualization-all-in-
one-for-dummies-jack-a-hyman-luca-massaron-paul-mcfedries-john-paul-
mueller-lillian-pierson-jonathan-reichental/
textbookfull.com

Muslim Women and Power: Political and Civic Engagement in


West European Societies 1st Edition Danièle Joly

https://textbookfull.com/product/muslim-women-and-power-political-and-
civic-engagement-in-west-european-societies-1st-edition-daniele-joly/

textbookfull.com
Maulid Ad Daiba i 4th Edition Ash-Shaykh Al-Wali Al-
Muhaddith Abdur-Rahman Ad-Daiba‘I

https://textbookfull.com/product/maulid-ad-daiba-i-4th-edition-ash-
shaykh-al-wali-al-muhaddith-abdur-rahman-ad-daibai/

textbookfull.com
Learning Functional Data
Structures and Algorithms
Table of Contents
Learning Functional Data Structures and Algorithms
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Why Functional Programming?
The imperative way
Higher level of abstraction
Functional programming is declarative
No boilerplate
Higher order functions
Eschewing null checks
Controlling state changes
Recursion aids immutability
Copy-on-write
Laziness and deferred execution
Composing functions
Summary
2. Building Blocks
The Big O notation
Space/time trade-off
A word frequency counter
Matching string subsets
Referential transparency
Vectors versus lists
Updating an element
Not enough nodes
Complexities and collections
The sliding window
Maps
Persistent stacks
Persistent FIFO queues
Sets
Sorted set
Summary
3. Lists
First steps
List head and tail
Drop elements
Concatenating lists
Persistent data structures
Tail call optimization
List append
List prepend
Getting value at index
Modifying a list value
Summary
4. Binary Trees
Node definitions
Building the tree
Size and depth
Complete binary trees
Comparing trees
Flipping a binary tree
Binary tree traversal
The accumulator idiom
Binary Search Trees
Node insertion
Searching a key
Updating a value
Exercising it
Summary
5. More List Algorithms
Binary numbers
Addition
Multiplication
Greedy algorithms and backtracking
An example of a greedy algorithm
The backtracking jig
Summary
6. Graph Algorithms
Reversing a list
Graph algorithms
Graph traversal
Avoiding list appending
Topological sorting
Cycle detection
Printing the cycle
Summary
7. Random Access Lists
Incrementing a binary number
Adding two binary numbers
List of tree roots
Insertion
Lookup
Removal, head, and tail
Update
Summary
8. Queues
Understanding FIFO queues
Functional FIFO queues
Invariants
Implementing a priority queue
Understanding priority queues/heaps
Leftist trees
Functional heaps
Summary
9. Streams, Laziness, and Algorithms
Program evaluation
Eager evaluation
Argument evaluation
Lazy evaluation
Lazy evaluation in Scala
Lazy evaluation in Clojure
Memoization - remembering past results
Memoization in Scala
Memoization in Clojure
Memoizing simpleFactFun
Streams
Stream in Scala
Indexing the elements of a stream
Creation of an infinite length stream
Stream is immutable
Creating a stream from another
Stream to list
Appending one stream to another
Length of a stream
Some mathematical functions of the stream class
Some more methods of the stream class
Streams (lazy sequence) in Clojure
Creating a memoized function of lazy sequences in Clojure
Some algorithms on stream
Arithmetic progression
Arithmetic progression in Scala
Arithmetic progression in Clojure
Standard Brownian motion
Standard Brownian motion in Scala
Standard Brownian motion in Clojure
Fibonacci series
First form of Fibonacci series
Second form of Fibonacci series
Fibonacci series in Scala
Fibonacci series in Clojure
Summary
10. Being Lazy - Queues and Deques
Imperative implementations
Amortization
Problem with queues
Strict versus lazy
Streams
Streams meet queues
A sense of balance
Amortized deques
Summary
11. Red-Black Trees
Terminology
Almost balanced trees
The concept of rotation
Red-Black trees
Inserting a node
The Black-Red-Red path
Left, left - red child and grand child
Left child, right grand child
Right child, right grand child
Right, left
Verifying the transformation
Complexity
Summary
12. Binomial Heaps
Binomial trees
Left child, right sibling
A binomial heap
Linking up
Inserting a value
Binary number equivalence
Merging
Find the minimum
Deleting the minimum
Exercising the code
Complexity
Summary
13. Sorting
Stable and unstable sorting
Stable sorting
Unstable sorting
Bubble sort
Scala implementation of bubble sort
Complexity of bubble sort
Selection sort
Complexity of selection sort
Insertion sort
Complexity of insertion sort
Merge sort
Splitting the sequence
Merging two sorted subsequences
Complexity of merge sort
Quick sort
Partition
Complexity of quick sort
Summary
Learning Functional Data
Structures and Algorithms
Learning Functional Data
Structures and Algorithms
Copyright © 2017 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a


retrieval system, or transmitted in any form or by any means, without
the prior written permission of the publisher, except in the case of brief
quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the
accuracy of the information presented. However, the information
contained in this book is sold without warranty, either express or
implied. Neither the authors, nor Packt Publishing, and its dealers and
distributors will be held liable for any damages caused or alleged to be
caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information


about all of the companies and products mentioned in this book by the
appropriate use of capitals. However, Packt Publishing cannot guarantee
the accuracy of this information.

First published: February 2017

Production reference: 1170217

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78588-873-1
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
www.packtpub.com
Credits
Authors
Copy Editor
Atul S. Khot
Gladson Monteiro
Raju Kumar Mishra

Reviewer Project Coordinator

Muhammad Ali Ejaz Sheejal Shah

Commissioning Editor Proofreader

Kunal Parikh Safis Editing

Acquisition Editor Indexer

Denim Pinto Mariammal Chettiyar

Content Development Editor Graphics

Nikhil Borkar Abhinash Sahu

Technical Editor Production Coordinator

Hussain Kanchwala Shantanu Zagade


About the Authors
Atul S. Khot grew up in Marathwada, a region of the state of
Maharashtra, India. A self-taught programmer, he started writing
software in C and C++. A Linux aficionado and a command-line guy at
heart, Atul has always been a polyglot programmer. Having extensively
programmed in Java and dabbled in multiple languages, these days, he is
increasingly getting hooked on Scala, Clojure, and Erlang. Atul is a
frequent speaker at software conferences, and a past Dr. Dobb's product
award judge. In his spare time, he loves to read classic British detective
fiction. He is a foodie at heart and a pretty good cook. Atul someday
dreams of working as a master chef, serving people with lip-smacking
dishes.

He was the author of Scala Functional Programming Patterns


published by Packt Publishing in December 2015. The book looks at
traditional object-oriented design patterns and shows how we could use
Scala's functional features instead.

I would like to thank my mother, late Sushila S. Khot, for teaching


me the value of sharing. Aai, I remember all you did for the needy
girl students! Your support for the blind school - you brought hope
to so many lives! You are no more, however your kindness and
selfless spirit lives on! I know you are watching dear mother, and I
will carry on the flame till I live! I also would like to thank my
father, late Shriniwas V. Khot. Anna, I have a photo of the 'Tamra
pat'--an engraved copper plaque--commemorating your great
contribution to the country's freedom struggle. You never
compromised on core values --always stood for the needy and
poor. You live on in my memories--a hero forever! I would also
want to thank Martin Odersky for giving us the Scala
programming language. I am deeply thankful to Rich Hickey and
the Clojure community for their work on persistent data
structures. Chris Okasaki’s "Purely Functional Data Structures" is
a perennial source of inspiration and insight. I wish to thank Chris
for writing the book. This book is influenced by many ideas Chris
presented in his book. I also wish to thank the functional
programming community for all the technical writings which is a
source of continual learning and inspiration. I would love to
express my heartfelt thanks to Nikhil Borkar for all the support
through out the book writing. I also would take this opportunity to
thank Hussain Kanchwala for the detailed editing efforts to make
the book perfect. You guys are awesome! Thanks to y’all!

Raju Kumar Mishra is a consultant and corporate trainer for big data
and programming. After completing his B.Tech from Indian Institute of
Technology (ISM) Dhanbad, he worked for Tata Steel. His deep passion
for mathematics, data science, and programming took him to Indian
Institute of Science (IISc). After graduating from IISc in computational
science, he worked for Oracle as a performance engineer and software
developer. He is an Oracle-certified associate for Java 7. He is a
Hortonworks-certified Apache Hadoop Java developer, and holds a
Developer Certification for Apache Spark (O'Reilly School of
Technology and Databriks), and Revolution R Enterprise-certified
Specialist Certifications. Apart from this, he has also cleared Financial
Risk Manager (FRM I) exam. His interest in mathematics helped him in
clearing the CT3 (Actuarial Science) exam.

My heartiest thanks to the Almighty. I would like to thank my mom,


Smt. Savitri Mishra, my sisters, Mitan and Priya, and my maternal
uncle, Shyam Bihari Pandey, for their support and
encouragement. I am grateful to Anurag Pal Sehgal, Saurabh
Gupta, and all my friends. Last but not least, thanks to Nikhil
Borkar, Content Development Editor at Packt Publishing for his
support in writing this book.
About the Reviewer
Muhammad Ali Ejaz is currently pursuing his graduate degree at Stony
Brook University. His experience, leading up to this academic
achievement, ranges from working as a developer to cofounding a start-
up, from serving in outreach organizations to giving talks at various
prestigious conferences. While working as a developer at
ThoughtWorks, Ali cofounded a career empowerment based start-up by
providing photographers a platform to showcase their art and be
discovered by potential employers. His passion for computer science is
reflected in his contributions to open source projects, such as GoCD,
and his role in serving as the cofounder and Community Outreach
Director of a non-profit organization, "Women Who Code - Bangalore
Chapter". Along with this, he has also been given the opportunity to
speak at different conferences on Continuous Integration and Delivery
practices.

When he is not coding, he enjoys traveling, reading, and tasting new


cuisine. You can follow him on Twitter at @mdaliejaz.

I want to thank my Mom and Dad, who have always been my


inspiration. I’d also like to thank Ahmad and Sana, my siblings,
who have been a constant source of cheerful support. A lot of what
I am today is because of them.
www.PacktPub.com
For support files and downloads related to your book, please
visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book
published, with PDF and ePub files available? You can upgrade to the
eBook version at www.PacktPub.com and as a print book customer, you
are entitled to a discount on the eBook copy. Get in touch with us
at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical


articles, sign up for a range of free newsletters and receive exclusive
discounts and offers on Packt books and eBooks.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full
access to all Packt books and video courses, as well as industry-leading
tools to help you plan your personal development and advance your
career.

Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Customer Feedback
Thank you for purchasing this Packt book. We take our commitment to
improving our content and products to meet your needs seriously—that's
why your feedback is so valuable. Whatever your feelings about your
purchase, please consider leaving a review on this book's Amazon page.
Not only will this help us, more importantly it will also help others in the
community to make an informed decision about the resources that they
invest in to learn. You can also review for us on a regular basis by
joining our reviewers' club. If you're interested in joining, or would
like to learn more about the benefits we offer, please contact us:
[email protected].
Preface
This book is about functional algorithms and data structures. Algorithms
and data structures are fundamentals of computer programming.

I started my career writing C and C++ code. I always enjoyed designing


efficient algorithms. I have experienced many an Aha! moments, when I
saw how powerful and creative pointer twiddling could be!

For example, reversing a singly linked list using three node pointers is a
well known algorithm. We scan the list once and reverse it by changing
the pointer fields of each node. The three pointer variables guide the
reversal process.

I have come across many such pointer tricks and have used them as
needed.

I was next initiated into the world of multi-threading! Variables became


shared states between threads! My bagful of tricks was still valid;
however, changing state needed a lot of care, to stay away from
insidious threading bugs.

The real world is never picture perfect and someone forgot to


synchronize a data structure.

Thankfully we started using C++, which had another bagful of tricks, to


control the state sharing. You could now make objects immutable!

For example, we were able to implement the readers/writer locking


pattern effectively. Immutable objects could be shared without worry
among thousands of readers!

We slept easier, the code worked as expected, and all was well with the
world!

I soon realized the reason it worked well! Immutability was finally


helping us better understand the state changes!
The sands of time kept moving and I discovered functional
programming.

I could very well see why writing side-effect free code worked! I was
hooked and started playing with Scala, Clojure, and Erlang. Immutability
was the norm here.

However, I wondered how the traditional algorithms would look like in a


functional setting--and started learning about it.

A data structure is never mutated in place. Instead, a new version of the


data structure is created. The strategy of copy on write with maximized
sharing was an intriguing one! All that careful synchronization is simply
not needed!

The languages come equipped with garbage collection. So, if a version is


not needed anymore, the runtime would take care of reclaiming the
memory.

All in good time though! Reading this book will help you see that we
need not sacrifice algorithmic performance while avoiding in-place
mutation!

What this book covers


Chapter 1, Why Functional Programming?, takes you on a whirlwind
tour of the functional programming (FP) paradigm. We try to highlight
the many advantages FP brings to the table when compared with the
imperative programming paradigm. We discuss FP’s higher level of
abstraction, being declarative, and reduced boilerplate. We talk about
the problem of reasoning about the state change. We see how being
immutable helps realize "an easier to reason about system".

Chapter 2, Building Blocks, provides a whirlwind tour of basic concepts


in algorithms. We talk about the Big O notation for measuring algorithm
efficiency. We discuss the space time trade-off apparent in many
algorithms. We next look at referential transparency, a functional
programming concept. We will also introduce you to the notion of
persistent data structures.

Chapter 3, Lists, looks at how lists are implemented in a functional


setting. We discuss the concept of persistent data structures in depth
here, showing how efficient functional algorithms try to minimize
copying and maximize structural sharing.

Chapter 4, Binary Trees, discusses binary trees. We look at the


traditional binary tree algorithms, and then look at Binary Search Trees.

Chapter 5, More List Algorithms, shows how the prepend operation of


lists is at the heart of many algorithms. Using lists to represent binary
numbers helps us see what lists are good at. We also look at greedy and
backtracking algorithms, with lists at the heart.

Chapter 6, Graph Algorithms, looks at some common graph algorithms.


We look at graph traversal and topological sorting, an important
algorithm for ordering dependencies.

Chapter 7, Random Access Lists, looks at how we could exploit Binary


Search Trees to access a random list element faster.

Chapter 8, Queues, looks at First In First Out (FIFO) queues. This is


another fundamental data structure. We look at some innovative uses of
lists to implement queues.

Chapter 9, Streams, Laziness, and Algorithms, looks at lazy evaluation,


another FP feature. This is an important building block for upcoming
algorithms, so we refresh ourselves with some deferred evaluation
concepts.

Chapter 10, Being Lazy – Queues and Deques, looks at double-ended


queues, which allow insertion and deletion at both ends. We first look at
the concept of amortization. We use lazy lists to improve the queue
implementation presented earlier, in amortized constant time. We
implement deques also using similar techniques.
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 11, Red-Black Trees, shows how balancing helps avoid
degenerate Binary Search Trees. This is a comparatively complex data
structure, so we discuss each algorithm in detail.

Chapter 12, Binomial Heaps, covers heap implementation offering very


efficient merge operation. We implement this data structure in a
functional setting.

Chapter 13, Sorting, talks about typical functional sorting algorithms.


What you need for this book
You need to install Scala and Clojure. All the examples were tested with
Scala version 2.11.7. The Clojure examples were tested with Clojure
version 1.6.0. You don’t need any IDE as most of the examples are small
enough, so you can key them in the REPL (Read/Eval/Print Loop).

You also need a text editor. Use whichever you are comfortable with.
Who this book is for
The book assumes some familiarity with basic data structures. You
should have played with fundamental data structures like linked lists,
heaps, and binary trees. It also assumes that you have written some code
in a functional language.

Scala is used as an implementation language. We do highlight related


Clojure features too. The idea is to illustrate the basic design principles.

We explain the language concepts as needed. However, we just explain


the basics and give helpful pointers, so you can learn more by reading
the reference links.

We try to site links that offer hands-on code snippets, so you can
practice them yourself.

Walking through an algorithm and discussing the implementation line by


line is an effective aid to understanding.

A lot of thought has gone into making helpful diagrams. Quizzes and
exercises are included, so you can apply what you've learned.

All the code is available online. We strongly advocate keying in the code
snippets though, to internalize the principles and techniques.

Welcome to the wonderland of functional data structures and


algorithms!
Conventions
In this book, you will find a number of text styles that distinguish
between different kinds of information. Here are some examples of
these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file
extensions, pathnames, dummy URLs, user input, and Twitter handles
are shown as follows: "The following function f has a side effect,
though."

A block of code is set as follows:


user=> (def v [7 11 19 52 42 72])
#'user/v
user=> (def v1 (conj v 52))
#'user/v1

If there is a line (or lines) of code that needs to be highlighted, it is set as


follows:
scala> def pop(queue: Fifo): (Int, Fifo) = {
| queue.out match {
| case Nil => throw new
IllegalArgumentException("Empty queue");
| case x :: Nil => (x, queue.copy(out =
queue.in.reverse, Nil))
| case y :: ys => (y, queue.copy(out = ys))
| }
| }
pop: (queue: Fifo)(Int, Fifo)

New terms and important words are shown in bold. Words that you
see on the screen, for example, in menus or dialog boxes, appear in the
text like this: "Clicking the Next button moves you to the next screen."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Random documents with unrelated
content Scribd suggests to you:
Socialisme et population, par Leon Marinont.—0 fr. 40
c.
Socialisme et malthusisme, par Victor Ernest.—0 fr. 60
c.
Malthus et ses disciples, par G. Hardy.—0 fr. 50 c.
La loi de Malthus, par G. Hardy.—0 fr. 75 c.
Population et subsistances, par G. Giroud.—1 fr.
Aux jeunes hommes, aux jeunes filles. Ce qu’ils
doivent apprendre sur la vie sexuelle, par Valentin
Grandjean.—1 fr.
Valeur scientifique du malthusianisme, par le Dr.
Gottschalk. Deux brochures (1re et 2e parties). Ensemble, 1 fr. 50 c.

POUR EVITER LA CONCEPTION.


Ayons peu d’enfans! Pourquoi? Comment? par Emile
Chapelier.—0 fr. 20 c.
Moyens d’eviter les grandes familles, par les docteurs J.
Rutgers et F. Mascaux.—0 fr. 30 c.
Generation consciente, par Franck Sutor.—0 fr. 75 c.

VOLUMES.
Moyens d’eviter la grossesse, par G. Hardy.—1 fr. 25 c.
L’education sexuelle, par Jean Marestan.—2 fr. 50 c.
Peu d’enfants. Pourquoi? Comment? par Eugene
Lericolais.—3 fr.
Le breviaire de la femme enceinte.—4 fr.
La pauvrete, sa seule cause, son seule remede, par le Dr.
George Drysdale.—1 fr.
La procreation volontaire, par le Dr. Klotz-Forest.—2 fr.
Elements de science sociale, par le Dr. G. Drysdale.—3
fr.
L’initiation sexuelle, par G. Bessede.—3 fr.
La vie sexuelle et ses lois, par le Dr. Anton Nystrom.—6
fr.
Notions d’hygiene feminine populaire: l’Adolescente,
par le Dr. Rene Martial.—2 fr.
La fonction sexuelle, par le Dr. Sicard de Plauzoles.—6
fr.
La generation humaine, par le Dr. G.-J. Witkowski.—8 fr.
La question sexuelle, par Auguste Forel.—10 fr.
De l’avortement. Est-ce un crime? par le Dr. Klotz-
Forest.—3 fr. 50 c.
De l’amour physique, par Camille Mauclair.—3 fr.
La physique de l’amour, par Remy de Gourmont.—3 fr.

Generation Consciente.

Organe de propagande pour la limitation volontaire des naissances.


Neo-malthusisme. Eugenisme.

Eugene Humbert, Directeur.

Administration: 27 rue de la Duée, Paris (XX.).


TRANSCRIBER’S NOTES
1. Silently corrected typographical errors and variations in
spelling.
2. Anachronistic, non-standard, and uncertain spellings
retained as printed.
*** END OF THE PROJECT GUTENBERG EBOOK MAGNETATION
METHODS OF BIRTH CONTROL ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like