48
Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Embed Size (px)

Citation preview

Page 1: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Ubiquitous

Mr. Karl Castleton

Pacific Northwest National Laboratory

Page 2: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Recursion

• A recursive process is one in which objects are defined in terms of other objects of the same type. Using some sort of recurrence relation , the entire class of objects can then be built up from a few initial values and a small number of rules.

Page 3: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Recursion

• The Fibonacci numbers are most commonly defined recursively. Care, however, must be taken to avoid self-recursion, in which an object is defined in terms of itself, leading to an infinite nesting.

Page 4: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Recursion

• SEE ALSO:

I. Ackermann Function, 

II.Kleene's Recursion Theorem, 

III.McCarthy 91-Function, 

IV.Primitive Recursive Function, 

V.Recurrence Relation, 

VI.Recursive Function,

Page 5: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Recursion

• SEE ALSO:

a. Recursively Undecidable, 

b.Regression, 

c. Richardson's Theorem, 

d.Self-Recursion, 

e. Self-Similarity, 

f. TAK Function

Page 6: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• Recursion is the process of repeating items in a self-similar way.

• For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion.

Page 7: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• The term has a variety of meanings specific to a variety of disciplines ranging from linguistics to logic.

• The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition.

Page 8: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• Specifically this defines an infinite number of instances (function values), using a finite expression that for some instances may refer to other instances, but in such a way that no loop or infinite chain of references can occur.

• The term is also used more generally to describe a process of repeating objects in a self-similar way.

Page 9: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Formal definitions of recursion

• In mathematics and computer science, a class of objects or methods exhibit recursive behavior when they can be defined by two properties:

1. A simple base case (or cases), and

2. A set of rules which reduce all other cases toward the base case.

Page 10: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• For example, the following is a recursive definition of a person's ancestors:

a) One's parents are one's ancestors (base case).

b)The parents of one's ancestors are also one's ancestors (recursion step).

Page 11: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• The Fibonacci sequence is a classic example of recursion:

a)Fib(0) is 0 [base case]

b)Fib(1) is 1 [base case]

c)For all integers n > 1: Fib(n) is (Fib(n-1) + Fib(n-2)) [recursive definition]

Page 12: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• Many mathematical axioms are based upon recursive rules.

• For example, the formal definition of the natural numbers in set theory follows:

• 1 is a natural number, and each natural number has a successor, which is also a natural number.

• By this base case and recursive rule, one can generate the set of all natural numbers

Page 13: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• A more humorous illustration goes:

"To understand recursion, you must first understand recursion."

Page 14: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• Or perhaps more accurate is the following, from Andrew Plotkin:

"If you already know what recursion is, just remember the answer. Otherwise, find someone who is standing closer to Douglas Hofstadter than you are; then ask him or her what recursion is."

Page 15: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• Recursively defined mathematical objects include functions, sets, and especially fractals.

Page 16: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Why discuss recursion?• Fundamental to many

aspects of life– Something being

defined by itself

– and some transformation between levels

– and some criteria to stop recursion

• Simple to state– Most recursive definitions are

very clean

• Intuitive in its definition– Other than the strangeness of

definition

• Difficult to “use” properly– Most software engineers shy

away from its use even though it is very useful

Page 17: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Fibonacci Sequence as an example:

• f(n)=f(n-1)

• + f(n-2)

• Where

• f(0)=1 and f(1)=1

• n>1

Generates the series

1 1 2 3 5 8 13 …

• Defined by itself

• and a transformation

• and a stopping condition– Defines first few

elements and stopping condition

Page 18: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

A software implementation:

• f(n)=f(n-1)

• + f(n-2)

• Where

• f(0)=1 and f(1)=1

• n>1

Generates the series

1 1 2 3 5 8 13 …

• int fib(int n) {

if (n>1)

return fib(n-1)

+fib(n-2);

else return 1;

}

Page 19: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

The Giant’s Shoulders

• Douglas R. Hofstadter in 1979 a book called “Goedel, Escher, Bach: An Eternal Golden Braid” (GEB for short)– A book I stumbled across but in its day was

quite a sensation– Many of the concepts presented here stem from

extensions of ideas presented in this book– By the way this book pre-dates the modern

personal computers and software tools

Page 20: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

But lets not focus on Math and Computer Science

• Recursion occurs in many other aspects of life– We will start as far from Math and Computer

Science as we can get and then return to them for some interesting examples

– I have focused on cultural artifacts more than behaviors. So I do not show any recursive behaviors but we will find artifacts that seem to have recursive structures.

On to Music and Limericks

Page 21: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Does music contain recursion• A key is a series of notes that start and stop on the

same note (although the note could be in a different octave)

• In GEB, Hofstadter explains that “we hear music recursively-in that we maintain a mental stack of the keys”– This is to say when we start hearing a melody you tend to

wait for the starting note to come again– If we diverge from the melody our brains wait for a return

to the start of diversion before we expect to hear the original melody end

– An experiment: start humming a scale and stop somewhere in the middle. It does not feel quite right does it.

Page 22: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Self Defined, Transformed, and Stopped

• Key is a series of keys that we expect to hear

• They can contain time-compressed copies of itself, or shifted in frequency

• and is expected to end at each level of recursion

• Some of the most challenging music to play comes from this nesting a key in a key.

Page 23: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

What about the words?

• Lets look at the typical limericks – There was an Old Man with a

beard, Who said, "It is just as I feared! - Two Owls and a Hen, Four Larks and a Wren, Have all built their nests in my beard!" [Edward Lear]

From: Self-similar syncopations:Fibonacci, L-systems, limericks

and ragtime by Kevin Jones

• Directly correlates the structure to the Fibonacci sequence– There is a “tree” that shows a

recursive structure that in the end generates the di-dum-di-dum rhythm of the limericks

• Author has degrees in Mathematics, Computer Science and Music

• He then goes on to show that ragtime music sometimes shows the same characteristics.

• Visit: http://plus.maths.org/issue10/features/syncopate/

Page 24: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

For a more complete review

• Self-Similarity (another name for recursion) is the bridge between sound and music.

• Self-similar Synthesis: On the Border Between Sound and Music Masters Thesis at MIT for Shahrokh D. Yadegari

• The coherencies which exist in music have to agree with each other in any scale and dimension in which they are being perceived.– http://crca.ucsd.edu/

~syadegar/MasterThesis/node25.html

On to Art

Page 25: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Lets start with older cultural art.

• Rangoli: Ritual Patterns of Rural India– For sacred and festive

places

– Drawn by tracing lines around a grid of dots

• Dr. Ektare pointed out this example

Pattern is repeated ona smaller scale

Sometimes it is distorted

Page 26: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

The Mandala is also recursive

• A mandala is an imaginary palace that is contemplated during meditation in Tibetan Buddhism

• A very complex design repeats itself in four rotations but also in the nested palace in a palace

The border of this mandala also has recursive properties

Page 27: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

A more modern example (Escher)• Image below was

explicitly constructed for its recursive properties.

• M.C. Escher has a number of examples of recursion.

What would the close-up of his eye reveal

Page 28: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

60’s Music Videos

• Video feedback was used to produce many.– Basically you point a video

camera at a monitor and then add some light source

– This was produced (by me) using a net cam and a monitor. The light source is the mouse

• The frame you see is the frame you saw plus the distortion of the alignment of the camera, and processing it stops at the limit of the camera resolution There is an intentional rotation

in the alignment between cameraand monitor On to Nature

Page 29: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Nature uses recursion frequently

• Nature has many fractals– Fractals are self-similar

structures

• This shell is related to the example video because the shell is a simple enlargement and rotation of the previous shell.

• The shell started as small as possible (for the creature)

Page 30: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Flowers and plants also have this self-similar behavior

• Plants are frequent examples

• Fractal ferns are a classic examples of recursive definition

• Vist: http://www.geocities.com/CapeCanaveral/Hangar/7959/fractalapplet.html

Page 31: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Even Sensing Nature Needs Recursion

• Sensing subaudible sound requires a special instrument

• Notice the eight sided star with the eight sided stars…

• That is the sensor used to sense sub-audible sound that elephants and weather produce

• An optical fiber infrasound sensor: A new lower limit on atmospheric pressure noise between 1 and 10 Hz

• Visit: http://klops.geophys.uni-stuttgart.de/~widmer/JASAfinal.pdf

On to Social Structures and Geography

Page 32: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Nesting of Elected Officials with Elected Officials

• The Federal representation structure (Executive, Legislative, Judicial, Press) is repeated at the state and local levels.– With some minor

transformations at each level (term limits, required age, etc.)

• This basically gives a structure that can govern many people with relatively few individuals

• It is not unlike the flower in the nature section

• Does the structure even extend into your household?

• Scientific and technical communities tend to have nested leadership organization as well.

Page 33: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Structure of the Electrical Grid

• The power grid is essentially a binary tree from the power plant to the consumer

• Here the transformation steps voltage up as losses occur over the transmission wires

Page 34: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

How much coast line do we have to protect/govern?

• A rather simple question posed to Benoit B. Mandelbrot

• The solution he came up with was it depends– What scale do you want to

measure on– Can really be any answer

you wish– Any structure at one scale

has equivalent structures at a smaller scale

Back to Computer Science

Page 35: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Many Divide and Conquer Algorithms are Recursive

• Binary Search• Fast Fourier

Transformation• Recursive Decent

Parsers– Backus Naur Form is a

way of encapsulating recursive language structures

• And many many more.

Page 36: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Web Page Design• Nesting of

– Styles within styles

– Tables within tables

– Lists within lists

• A fundamental concept to the layout of web-pages

Back to Mathematics

Page 37: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

The Mandelbrot Set• Simple Computation of

Complex Numbers– Zn+1=Zn

2+C• Has unlimited complexity• Coloring typically done by

the number of computations before divergence away from 0+0i

• Julia sets are a peek at the complexity of a single point of the Mandelbrot set

Page 38: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Another Approach to the Integration of a Function

• Consider the definition of integration where you take smaller and smaller dt until you reach the limit

• What “integrate” means you simply compare the area of one trapezoid including a and b to total area of two trapezoids a and m plus m and b. If the difference is “significant” “integrate” a to m add to “integrate” m to b stop when you hit the precision required

a b

a b

a b

a bm

-dt-

Page 39: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

So where is Godel?

• Godel’s incompleteness theorem is a proof about proofs that uses recursion

• The ability to be comfortable with the concept of one level addressing something about a subsequent level is key

• I will Math professors explain it

more thoroughly or visit: http://home.ddc.net/ygg/etext/godel/godel3.htm

Page 40: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Some interesting contrasts• The recursive nature of the physical world may be the link

Wolfram should have used to make more clear the connection between simple programs and larger physical effects– This is a frequent criticism of ANKOS

• Recursive structures can typically be done in an iterative (step by step) structure but sometimes looses the essence of the concept.– The integration example is like this

– The recursive implementation is much easier to implement in a computer

Page 41: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Importance of paying attentionNature's jokes

• Dyson delightfully opines that the following are three of the jokes of nature: "The most powerful profound joke of nature is

1. the square root of -1;

2. the linearity of Quantum Mechanics;

3.and "the existence of quasi-crystals”.

Page 42: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Importance of paying attentionNature's jokes

• The linearity of Quantum Mechanics has been confirmed in 1950-60s by the theory of linear representations of Lie algebras as the natural language of particle physicists.

Page 43: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Importance of paying attentionNature's jokes

• However, any serious reader who is introduced to the concepts will definitely encounter a series of surprises in the book. In the reviewer's opinion, the greatest of surprises is that Nature which is an unlimited source of surprise to man has been to an extent explained through universal laws and mathematical equations.

Page 44: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

• In mathematics you don't understand things. You just get used to them.

~ Johann von Neumann

Page 45: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Zen and the art of motorcycle maintenance

• The real purpose of scientific method is to make sure Nature hasn't misled you into thinking you know something you don't actually know.

• There's not a mechanic or scientist or technician alive who hasn't suffered from that one so much that he's not instinctively on guard.

Page 46: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Zen and the art of motorcycle maintenance

• That's the main reason why so much scientific and mechanical information sounds so dull and so cautious. If you get careless or go romanticizing scientific information, giving it a flourish here and there, Nature will soon make a complete fool out of you.

Page 47: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Zen and the art of motorcycle maintenance

• It does it often enough anyway even when you don't give it opportunities.

• On must be extremely careful and rigidly logical when dealing with Nature: one logical slip and an entire scientific edifice comes tumbling down.

• One false deduction about the machine and you get hung up indefinitely.

Page 48: Ubiquitous Mr. Karl Castleton Pacific Northwest National Laboratory

Conclusions• Recursive relationships are “everywhere”

– If you are mathematician you should consider recursive approaches and definitions (Godel did)

– If you are a computer scientist you should not be intimidated by a recursive algorithm

• I hope you enjoyed the tour of just a few examples of