what is an algorithm
play

What is an Algorithm? Quite generally, an algorithm is a set of - PDF document

What is an Algorithm? Quite generally, an algorithm is a set of instructions that lead to some desired Fundamentals: All About result Algorithms Must first decompose a problem, and then express its method of solution as a Computer


  1. What is an Algorithm? • Quite generally, an algorithm is a set of instructions that lead to some desired Fundamentals: All About result Algorithms • Must first decompose a problem, and then express it’s method of solution as a Computer Literacy series of well defined steps to be followed. Lecture 23 • So an algorithm is a recipe for achieving a certain goal Pancake Recipe It’s All Relative 1. Mix 1 egg and 1 1 / 2 cups of milk • Whether or not a list of instructions counts as an ‘algorithm’ is relative to a set of 2. Add to 2 cups of sifted flour background assumptions about what kind 3. Stir until smooth of device will be following the instructions, 4. Mix in 2 tablespoons of melted butter what its basic capacities are, etc. 5. Pour some of the mixture into a hot pan • Can fill in steps between steps as the level and fry of analysis becomes more and more fine 6. Serve with maple syrup, sugar or jam grained Where to begin Effective Procedures • For example, the Pancake recipe doesn’t In the most rigorous context, algorithms include an initial step: are the recipes that a computer can follow 0. place an adequately sized mixing bowl • In this sense they can be thought of as effective procedures (we’ve seen these on a flat surface before): And it doesn’t tell you how to sift the flour or – a finitary set of instructions that can be melt the butter, etc. followed ‘mechanically’, i.e. with no - these steps between steps are simply understanding or interpretation required assumed 1

  2. World Knowledge Pancake Bugs In this most precise sense of an effective • So even though the average procedure, there can be no missing steps or (contemporary western?) human could ambiguities follow the pancake recipe, it assumes too - ‘ Common sense ’ or ‘ world knowledge ’ is a central much world knowledge for a computer aspect of human intelligence not shared by • Has a number of bugs as a potential computers program: e.g. • One of the most difficult aspects of designing step 1. says to mix 1 egg with milk, algorithms is to break down a problem in such a way that the solution really is mechanical, but it doesn’t say not to include relative to its level of execution the shell More Bugs Numerical Example • Here’s a simple recipe for manipulating Step 2. Add to 2 cups of sifted flour numbers: But add what – more flour, red 1. Pick a number between 1 and 10 wine, marmite? 2. Multiply by 9 3. Add the digits together Step 3. Stir until smooth 4. Subtract 5 But with what, and exactly how smooth Your number is …..? – can the stirring go on for 3 hours? This simple algorithm can be thought of as Step 5. Pour some of the mixture into a hot calculating a function on the numbers between 1 and 10 pan and fry - until when? Functions Functions • One of the best known ancient examples • Since ancient times, mathematicians have is Euclid’s algorithm for calculating the been concerned with giving algorithmic function methods for calculating various functions f(x,y)= the greatest common divisor of • It’s one thing to give a high-level definition x and y of a function, but it can be quite another - The function f(x,y) is perfectly well thing to specify a method for calculating defined with this description, the function on any given values but what procedure should we follow to obtain specific values? 2

  3. Euclid’s Recipe (3 rd century B.C.) Equations For illustration let x = 53,667 and y = 25,527 • Within a normal mathematical context, to calculate f(x,y): equations constitute algorithms for 53,667 = 25,527 · 2 + 2,613 calculating basic values, 25,527 = 2,613 · 9 + 2,010 e.g. areas in Euclidean geometry: 2,613 = 2,010 · 1 + 603 2,010 = 603 · 3 + 201 for a triangle with base b and height h , 603 = 201 · 3 + 0 f(x,y) = 201 A = ( bh ) / 2 for a circle with radius r So the general concept of an algorithm has been around for a long time before computers! A = π r 2 Arithmetical Functions Arithmetical Functions • The equations A = (bh)/2 and A = π r 2 both • But what if you wanted to fill in some steps assume the two-place numerical function between the steps specified in the of product or multiplication equations for computing areas? • This is because the normal context is • The next level of analysis is to give an human beings, who can perform this algorithm for calculating the function x·y operation without even stopping to think - a recipe that could be followed by • We’re trained to multiply by first someone who didn’t know how to multiply memorizing a ‘times table’ of basic values Decomposition More Decomposition • An obvious way to decompose • As with pancakes, we’re familiar with the multiplication is in terms of repeated basic concept of addition and don’t need addition to analyze the operation in more explicit detail to perform everyday manipulations • So x·y can be seen as adding x to itself y many times, e.g. • But what if you wanted to give a recipe for calculating X + Y , a general equation that 3·6 = 3+3+3+3+3+3 could be followed even by a mindless In this manner you could, in principle, device that didn’t understand the abstract eliminate multiplication and define it in concept?? terms of + 3

  4. Plus One Artificial Languages • Here’s an example of a recursive definition to • Addition is a two place function, using specify the simple artificial language L: variables X and Y • Vocabulary of L: • An obvious way to decompose addition is - logical vocabulary: ¬, v, &, → , ),( in terms of a repeated one place - statement letters: P 1 , P 2 , P 3 , … Recursive definition of formulas of L: operation of adding 1 base step: all statement letters are formulas of L • This was utilized by the logician Kurt recursion step: if φ , ψ are formulas of L, then Gödel, to give recursive axioms for ¬ φ , ( φ v ψ ), ( φ & ψ ), ( φ→ψ ) are formulas of L arithmetic Recursive Definitions The Successor Function • Let the one place function s(X) = the next larger • The definition of ‘ formula of L ’ has 2 parts: natural number after X, often called the - the base step specifies a stock of initial successor of X, e.g. s(6)=7, s(9)=10 ingredients (in this case, the atomic formulas) • We can denote all natural numbers in terms of 0 - the recursion step may appear circular: and the successor function: ‘ formula of L’ occurs in the definition of ‘ formula 0=0, 1=s(0), 2=s(s(0)), 3=s(s(s(0))), of L’. But only formulas that have already been 4=s(s(s(s(0)))) … defined in a prior application of the step • Note that the definition will yield infinitely many Although tedious for humans, this notation (non-atomic) formulas of L reduces numbers to their structural core, and is well suited for purely mechanical manipulations • Now back to arithmetic … Axioms for Addition Recursive Definitions • With the successor function and the • The two axioms for addition have the foregoing version of monadic notation we standard recursive form used by many can give a algorithms • Recursive definition of the two-place + • The first equation, X+0 = X, specifies the function in terms of the successor function: initial value i) X + 0 = X • The second equation, X+s(Y) = s(X+Y) may appear circular - it refers to ‘+’ when ii) X + s(Y) = s(X + Y) defining ‘+’. But this is OK - it only uses a value that has already been computed 4

  5. Algorithmic Addition Algorithmic Addition • With the recursive axioms it’s possible to Then apply equation ii), X+s(Y) = s(X+Y) mechanically calculate the sum of any two natural numbers, without understanding • The base step has already given us the the basic concept of two place addition value of X+Y when Y=0, so now we take • Method: if you want to calculate A+B the successor of this value to calculate recursively, it will take B+1 steps. X+s(0) = s(X+0) Let X=A throughout and begin by applying • Keep reapplying equation ii) until you get equation i): this is the base step to the step X+s(Y), where s(Y)=B Add 2+3 Algorithmically Axioms for Multiplication 1. set X=2=s(s(0)) and apply equation i): • As mentioned before, multiplication can be s(s(0))+0 = s(s(0)) decomposed as iterated addition 2. apply equation ii) and get • There are 2 corresponding equations that s(s(0))+s[0] = s[s(s(0))+0] = s[s(s(0))] 3. reapply equation ii) and get give a precise, recursive definition of s(s(0))+s[s(0)] = s[s(s(0))+s(0)] = s[s(s(s(0)))] multiplication in terms of addition 4. reapply equation ii) and get i) X·0 = 0 s(s(0))+s[s(s(0))] = s[s(s(0))+s(s(0))] = s[s(s(s(s(0))))] = 5 ii) X·s(Y) = X+(X·Y) 2·3 Algorithmically More Functions 1. s(s(0))·0 = 0 • So now we can define multiplication with just assuming the one-place successor 2. s(s(0))·s[0] = s(s(0))+0 = s(s(0)) function s(x) as primitive 3. s(s(0))·s[s(0)] = s(s(0))+[s(s(0))·s(0)] • In turn we can use multiplication to define = s(s(0))+s(s(0)) exponentiation, etc. = s(s(s(s(0)))) • Gödel exploited this method to formally 4. s(s(0))·s[s(s(0))] = s(s(0))+[s(s(0))·s(s(0))] define the class of recursive functions , = s(s(0))+s(s(s(s(0)))) which is another framework for expressing = s(s(s(s(s(s(0)))))) = 6 the notion of an effective procedure 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend