Recipe, formula, or program
[ Modified: 2024 Apr 23 ]

A recipe (kitchen) and a mathematical formula (academic) and a computer program (office) are all the same thing: a set of instructions. The only significant difference is the notation.

A program is a list of events, such as the handout received at a theater of plays. Making the word "program" into an action word for "making a list of events" (t.i. "programming") is probably easier to pronounce/spell than with "recipe", f.e. "recipe-ing" or "recipying" or "reciping".


Examples


# Recipe notation

Typical format for a recipe:

Peanut butter and jelly sandwich
    2 slices of bread
    1 glob of peanut butter
    1 glob of jelly

Put glob of peanut butter on a slice of bread.
Put glob of jelly on another slice of bread.
Put both together.

The ingredients might vary, t.i. each ingredient is "variable".


# Mathematical notation

Typical abbreviations for a formula or equation use "f( )", with "f" for the word "function", along with a list of ingredients.

For example:

    f(x, y, z)
     = ( (x + y) + (z + x) )

That can represent the "Peanut butter and jelly sandwich" recipe:

f for the recipe name:
    "Peanut butter and jelly sandwich"

x for the 1st ingredient:
    bread

y for the 2nd ingredient:
    peanut butter

z for the 3rd ingredient:
    jelly

Then, "(x + y)" is "bread combined with peanut butter", and so forth. Or consider different abbreviations:

R for "recipe"
b for "bread"
p for "peanut butter"
j for "jelly"

R(b, p, j)
    = ( (b + p) + (j + b) )

Again, each ingredient might vary, t.i. is "variable". Consider choosing "Romaine lettuce" for b, "mashed pecan" for p, and "mashed blackberries" for j.

b = Romaine lettuce
p = mashed pecans
j = mashed blackberries

Then apply the ingredients to the formula of the function R(b, p, j).

R(b, p, j)
    = ( (b + p)
      + (j + b) )

would become

R(b, p, j)
    = ( ("Romaine lettuce" + "mashed pecans")
      + ("mashed blackberries" + "Romaine lettuce") )

and the result could be (a sandwich):

Romaine lettuce leaf
    mashed pecans
mashed blackberries
Romaine lettuce leaf

# Computer program notation

Common computer program notation for describing that recipe (or formula).

/* Make a peanut butter and jelly sandwich. */

function
peanutButterAndJellySandwich
(bread, peanutButter, jelly)
{
return (
(bread  +  ", "  +  peanutButter)
+ ", "
+ (jelly  +  ", "  +  bread) )
}

Then, consider choosing "green leaf lettuce" for bread, "mashed walnut" for peanutButter, and "sliced avocado" for jelly. The function itself is used similar to a math function, except the desired values are listed within the parentheses.

peanutButterAndJellySandwich("green leaf lettuce", "mashed walnut", sliced-avocado)

Then the computer does the substitution on its own.

return (
("green leaf lettuce"  +  ", "  +  "mashed walnut")
+ ", "
+ ("sliced avocado"  +  ", "  +  "green leaf lettuce") )

Finally, the result is returned.

"green leaf lettuce, mashed walnut, sliced avocado, green leaf lettuce"

Another way of describing the recipe might be in a typical Lisp notation (Lisp, pseudo common).

(defun
peanut-butter-and-jelly-sandwich
(bread  peanut-butter  jelly)

"Make a peanut butter and jelly sandwich."

(cons
(cons  bread  peanut-butter)
(cons  jelly  bread)))

The recipe is applied similarly as before.

(peanut-butter-and-jelly-sandwich
"red chard"  "pistachios"  "mashed black olives")

Then the computer applies the values itself.

(cons
(cons  "red chard"  "pistachios")
(cons  "mashed black olives"  "red chard"))

The word cons refers to a function that "constructs" a pair of values by creating a list with two values within parentheses. Such a pair is notated by a space-separated-dot " . ". See Lisp: "1.1 Dotted-pair notation".

(cons
("red chard" . "pistachios")
("mashed black olives" . "red chard"))

The result is similar to the prior example, this time as dotted-pairs rather than as a comma-separated list. [ Easier to take apart the sandwich, or add more ingredients. ]

(("red chard" . "pistachios")
. ("mashed black olives" . "red chard"))

sharing