Tag Archives: program

Metaphors in computing science 2

In Metaphors in Computer Science 1, I discussed some metaphors used when thinking about various aspects of computing.  This is a continuation of that post.

Metaphor: A program is a list of instructions.

  • I discussed this metaphor in detail in the earlier post.
  • Note particularly that the instructions can be in a natural or a programming language. (Is that a zeugma?)  Many writers would call instructions in a natural language an algorithm.
  • I will continue to use “program” in the broader sense.

Metaphor: A programming language is a language.

  • This metaphor is a specific conceptual blend that associates the strings of symbols that constitute a program in a computer language with text in a natural language.
  • The metaphor is based on some similarities between expressions in a programming language and expressions in a natural language.
    • In both, the expressions have a meaning.
    • Both natural and programming languages have specific rules for constructing well-formed expressions.
  • This way of thinking ignores many deep differences between programming languages and natural languages. In particular, they don’t talk about the same things!
  • The metaphor has been powerful in suggesting ways of thinking about computer programs, for example semantics (below) and ambiguity.

Metaphor: A computer program is a list of statements

  • A consequence of this metaphor is that a computer program is a list of symbols that can be stored in a computer’s memory.
  • This metaphor comes with the assumption that if the program is written in accordance with the language’s rules, a computer can execute the program and perhaps produce an output.
  • This is the profound discovery, probably by Alan Turing, that made the computer revolution possible. (You don’t have to have different physical machines to do different things.)
  • You may want me to say more in the heading above: “A computer program is a list of statements in a programming language that satisfies the well-formedness requirements of the language.”  But the point of the metaphor is only that a program is a list of statements.  The metaphor is not intended to define the concept of “program”.

Metaphor: A program in a computer language has meanings.

A program is intended to mean something to a human reader.

  • Some languages are designed to be easily read by a human reader: Cobol, Basic, SQL.
    • Their instructions look like English.
    • The algorithm can nevertheless be difficult to understand.
  • Some languages are written in a dense symbolic style.
    • In many cases the style is an extension of the style of algebraic formulas: C, Fortran.
    • Other languages are written in a notation not based on algebra:  Lisp, APL, Forth.
  • The boundary between “easily read” and “dense symbolic” is a matter of opinion!

A program is intended to be executed by a computer.

  • The execution always involves translation into intermediate languages. 
    • Most often the execution requires repeated translation into a succession of intermediate languages.
    • Each translation requires the preservation of the intended meaning of the program.
  • The preservation of intended meaning is what is usually called the semanticsof a programming language.
    • In fact, the meaning of the program to a person could be called semantics, too.
    • And the human semantics had better correspond in “meaning” to the machine semantics!
  • The actual execution of the program requires successive changes in the state of the computer.
    • By “state” I mean a list of the form of the electrical charges of each unit of memory in the computer.
    • Or you can restrict it to the relevant units of memory, but spelling that out is horrifying to contemplate.
    • The resulting state of the machine after the program is run is required to preserve the intended meaning as well as all the intermediate translations.
    • Notice that the actual execution is a series of physical events.  You can describe the execution in English or in some notation, but that notation is not the actual execution.

References

Conceptual blend (Wikipedia)

Conceptual metaphors (Wikipedia)

Images and Metaphors (article in abstractmath)

Semantics in computer science (Wikipedia)

Send to Kindle

Conceptual blending

This post uses MathJax.  If you see formulas in unrendered TeX, try refreshing the screen.

A conceptual blend is a structure in your brain that connects two concepts by associating part of one with part of another.  Conceptual blending is a major tool used by our brain to understand the world.

The concept of conceptual blend includes special cases, such as representations, images and conceptual metaphors, that math educators have used for years to understand how mathematics is communicated and how it is learned.  The Wikipedia article is a good starting place for understanding conceptual blending. 

In this post I will illustrate some of the ways conceptual blending is used to understand a function of the sort you meet with in freshman calculus.  I omit the connections with programs, which I will discuss in a separate post.

A particular function

Consider the function $h(t)=4-(t-2)^2$. You may think of this function in many ways.

FORMULA:

$h(t)$ is defined by the formula $4-(t-2)^2$.

  • The formula encapsulates a particular computation of the value of $h$ at a given value $t$.
  • The formula defines the function, which is a stronger statement than saying it represents the function.
  • The formula is in standard algebraic notation. (See Note 1)
  • To use the formula requires one of these:
    • Understand and use the rules of algebra
    • Use a calculator
    • Use an algebraic programming language. 
  • Other formulas could be used, for example $4t-t^2$.
    • That formula encapsulates a different computation of the value of $h$.

TREE: 

$h(t)$ is also defined by this tree (right).
  • The tree makes explicit the computation needed to evaluate the function.
  • The form of the tree is based on a convention, almost universal in computing science, that the last operation performed (the root) is placed at the top and that evaluation is done from bottom to top.
  • Both formula and tree require knowledge of conventions.
  • The blending of formula and tree matches some of the symbols in the formula with nodes in the tree, but the parentheses do not appear in the tree because they are not necessary by the bottom-up convention.
  • Other formulas correspond to other trees.  In other words, conceptually, each tree captures not only everything about the function, but everything about a particular computation of the function.
  • More about trees in these posts:

GRAPH:

$h(t)$ is represented by its graph (right). (See note 2.)

  • This is the graph as visual image, not the graph as a set of ordered pairs.
  • The blending of graph and formula associates each point on the (blue) graph with the value of the formula at the number on the x-axis directly underneath the point.
  • In contrast to the formula, the graph does not define the function because it is a physical picture that is only approximate.
  • But the formula does represent the function.  (This is "represents" in the sense of cognitive psychology, but not in the mathematical sense.)
  • The blending requires familiarity with the conventions concerning graphs of functions. 
  • It sets into operation the vision machinery of your brain, which is remarkably elaborate and powerful.
    • Your visual machinery allows you to see instantly that the maximum of the curve occurs at about $t=2$. 
  • The blending leaves out many things.
    • For one, the graph does not show the whole function.  (That's another reason why the graph does not define the function.)
    • Nor does it make it obvious that the rest of the graph goes off to negative infinity in both directions, whereas that formula does make that obvious (if you understand algebraic notation).  

GEOMETRIC

The graph of $h(t)$ is the parabola with vertex $(2,4)$, directrix $x=2$, and focus $(2,\frac{3}{4})$. 

  • The blending with the graph makes the parabola identical with the graph.
  • This tells you immediately (if you know enough about parabolas!) that the maximum is at $(2,4)$ (because the directrix is vertical).
  • Knowing where the focus and directrix are enables you to mechanically construct a drawing of the parabola using a pins, string, T-square and pencil.  (In the age of computers, do you care?)

HEIGHT:

$h(t)$ gives the height of a certain projectile going straight up and down over time.

  • The blending of height and graph lets you see instantly (using your visual machinery) how high the projectile goes. 
  • The blending of formula and height allows you to determing the projectile's velocity at any point by taking the derivative of the function.
  • A student may easily be confused into thinking that the path of the projectile is a parabola like the graph shown.  Such a student has misunderstood the blending.

KINETIC:

You may understand $h(t)$ kinetically in various ways.

  • You can visualize moving along the graph from left to right, going, reaching the maximum, then starting down.
    • This calls on your experience of going over a hill. 
    • You are feeling this with the help of mirror neurons.
  • As you imagine traversing the graph, you feel it getting less and less steep until it is briefly level at the maximum, then it gets steeper and steeper going down.
    • This gives you a physical understanding of how the derivative represents the slope.
    • You may have seen teachers swooping with their hand up one side and down the other to illustrate this.
  • You can kinetically blend the movement of the projectile (see height above) with the graph of the function.
    • As it goes up (with $t$ increasing) the projectile starts fast but begins to slow down.
    • Then it is briefly stationery at $t=2$ and then starts to go down.
    • You can associate these feelings with riding in an elevator.
      • Yes, the elevator is not a projectile, so this blending is inaccurate in detail.
    • This gives you a kinetic understanding of how the derivative gives the velocity and the second derivative gives the acceleration.

OBJECT:

The function $h(t)$ is a mathematical object.

  • Usually the mental picture of function-as-object consists of thinking of the function as a set of ordered pairs $\Gamma(h):=\{(t,4-(t-2)^2)|t\in\mathbb{R}\}$. 
  • Sometimes you have to specify domain and codomain, but not usually in calculus problems, where conventions tell you they are both the set of real numbers.
  • The blend object and graph identifies each point on the graph with an element of $\Gamma(h)$.
  • When you give a formal proof, you usually revert to a dry-bones mode and think of math objects as inert and timeless, so that the proof does not mention change or causation.
    • The mathematical object $h(t)$ is a particular set of ordered pairs. 
    • It just sits there.
    • When reasoning about something like this, implication statements work like they are supposed to in math: no causation, just picking apart a bunch of dead things. (See Note 3).
    • I did not say that math objects are inert and timeless, I said you think of them that way.  This post is not about Platonism or formalism. What math objects "really are" is irrelevant to understanding understanding math [sic].

DEFINITION

definition of the concept of function provides a way of thinking about the function.

  • One definition is simply to specify a mathematical object corresponding to a function: A set of ordered pairs satisfying the property that no two distinct ordered pairs have the same second coordinate, along with a specification of the codomain if that is necessary.
  • A concept can have many different definitions.
    • A group is usually defined as a set with a binary operation, an inverse operation, and an identity with specific properties.  But it can be defined as a set with a ternary operation, as well.
    • A partition of a set is a set of subsets of a set with certain properties. An equivalence relation is a relation on a set with certain properties.  But a partition is an equivalence relation and an equivalence relation is a partition.  You have just picked different primitives to spell out the definition. 
    • If you are a beginner at doing proofs, you may focus on the particular primitive objects in the definition to the exclusion of other objects and properties that may be more important for your current purposes.
      • For example, the definition of $h(t)$ does not mention continuity, differentiability, parabola, and other such things.
      • The definition of group doesn't mention that it has linear representations.

SPECIFICATION

A function can be given as a specification, such as this:

If $t$ is a real number, then $h(t)$ is a real number, whose value is obtained by subtracting $2$ from $t$, squaring the result, and then subtracting that result from $4$.

  • This tells you everything you need to know to use the function $h$.
  • It does not tell you what it is as a mathematical object: It is only a description of how to use the notation $h(t)$.

Notes

1. Formulas can be give in other notations, in particular Polish and Reverse Polish notation. Some forms of these notations don't need parentheses.

2. There are various ways to give a pictorial image of the function.  The usual way to do this is presenting the graph as shown above.  But you can also show its cograph and its endograph, which are other ways of representing a function pictorially.  They  are particularly useful for finite and discrete functions. You can find lots of detail in these posts and Mathematica notebooks:

3. See How to understand conditionals in the abstractmath article on conditionals.

References

  1. Conceptual blending (Wikipedia)
  2. Conceptual metaphors (Wikipedia)
  3. Definitions (abstractmath)
  4. Embodied cognition (Wikipedia)
  5. Handbook of mathematical discourse (see articles on conceptual blendmental representationrepresentation, and metaphor)
  6. Images and Metaphors (article in abstractmath)
  7. Links to G&G posts on representations
  8. Metaphors in Computing Science (previous post)
  9. Mirror neurons (Wikipedia)
  10. Representations and models (article in abstractmath)
  11. Representations II: dry bones (article in abstractmath)
  12. The transition to formal thinking in mathematics, David Tall, 2010
  13. What is the object of the encapsulation of a process? Tall et al., 2000.

 

Send to Kindle

Metaphors in computing science I

(This article is continued in Metaphors in computing science II)

Michael Barr recently told me of a transcription of a talk by Edsger Dijkstra dissing the use of metaphors in teaching programming and advocating that every program be written together with a proof that it works.  This led me to think about the metaphors used in computing science, and that is what this post is about.  It is not a direct answer to what Dijkstra said. 

We understand almost anything by using metaphors.  This is a broader sense of metaphor than that thing in English class where you had to say "my love is a red red rose" instead of "my love is like a red red rose".  Here I am talking about conceptual metaphors (see references at the end of the post).  

Metaphor: A program is a set of instructions

You can think of a program as a list of instructions that you can read and, if it is not very complicated, understand how to carry them out.  This metaphor comes from your experience with directions on how to do something (like directions from Google Maps or for assembling a toy).   In the case of a program, you can visualize doing what the program says to do and coming out with the expected output. This is one of the fundamental metaphors for programs. 

Such a program may be informal text or it may be written in a computer language.

Example

A description of how to calculate $n!$ in English could be:  "Multiply the integers $1$ through $n$".  In Mathematica, you could define the factorial function this way:

fac[n_] := Apply[Times, Table[i, {i, 1, n}]]

This more or less directly copies the English definition, which could have been reworded as "Apply the Times function to the integers from $1$ to $n$ inclusive."  Mathematica programmers customarily use the abbreviation "@@" for Apply because it is more convenient:

Fac[n_]:=Times @@ Table[i, {i, 1, 6}]

As far as I know, C does not have list operations built in.  This simple program gives you the factorial function evaluated at $n$:

 j=1;  for (i=2; i<=n; i++)   j=j*i; return j;  

This does the calculation in a different way: it goes through the numbers $1, 2,\ldots,n$ and multiplies the result-so-far by the new number.  If you are old enough to remember Pascal or Basic, you will see that there you could use a DO loop to accomplish the same thing.

What this metaphor makes you think of

Every metaphor suggests both correct and incorrect ideas about the concept.  

  • If you think of a list of instructions, you typically think that you should carry out the instructions in order.  (If they are Ikea instructions, your experience may have taught you that you must carry out the instructions in order.)  
  • In fact, you don't have to "multiply the numbers from $1$ to $n$" in order at all: You could break the list of numbers into several lists and give each one to a different person to do, and they would give their answers to you and you would multiply them together.
  • The instructions for calculating the factorial can be translated directly into Mathematica instructions, which does not specify an order.   When $n$ is large enough, Mathematica would in fact do something like the process of giving it to several different people (well, processors) to speed things up.
  • I had hoped that Wolfram alpha would answer "720" if I wrote "multiply the numbers from $1$ to $6$" in its box, but it didn't work.  If it had worked, the instruction in English would not be translated at all. (Note added 7 July 2012:  Wolfram has repaired this.)
  • The example program for C that I gave above explicitly multiplies the numbers together in order from little to big.  That is the way it is usually taught in class.  In fact, you could program a package for lists using pointers (a process taught in class!) and then use your package to write a C program that looks like the  "multiply the numbers from $1$ to $n$" approach.  I don't know much about C; a reader could probably tell me other better ways to do it.

So notice what happened:

  • You can translate the "multiply the numbers from $1$ to $n$" directly into Mathematica.
  •  For C, you have to write a program that implements multiplying the numbers from $1$ to $n$. Implementation in this sense doesn't seem to come up when we think about instruction sets for putting furniture together.  It is sort of like: Build a robot to insert & tighten all the screws.

Thus the concept of program in computing science comes with the idea of translating the program instruction set into another instruction set.

  • The translation provided above for Mathematica resembles translating the instruction set into another language. 
  • The two translations I suggested for C (the program and the definition of a list package to be used in the translation) are not like translating from English to another language.  They involve a conceptual reconstruction of the set of instructions.

Similarly, a compiler translates a program in a computer language into machine code, which involves automated conceptual reconstruction on a vast scale.

Other metaphors

In writing about this, I have brought in other metaphors, for example:

  • C or Mathematica as like a natural language in some ways 
  • Compiling (or interpreting) as translation

Computing science has used other VIM's (Very Important Metaphors) that I need to write about later:

  • Semantics (metaphor: meaning)
  • Program as text — this allows you to treat the program as a mathematical object
  • Program as machine, with states and actions like automata and Turing machines.
  • Specification of a program.  You can regard  "the product of the numbers from $1$ to $n$" as a specification.  Notice that saying "the product" instead of "multiply" changes the metaphor from "instruction" to "specification".

References

Conceptual metaphors (Wikipedia)

Images and Metaphors (article in abstractmath)

Images and Metaphors for Sets (article in abstractmath)

Images and Metaphors for Functions (incomplete article in abstractmath)

 

 
Send to Kindle