Can a constant function have slope 1?

2025 James B. Wilson

\(I(x) = x\)

\(K_c(x)=c\)

So

\(K_x(x)=x\)?

A motivated introduction to \(\lambda\)-calculus

Curry and Feys go to lunch

A fable by James B. Wilson

Every day Haskell Curry and Robert Feys would go to lunch at Constants.

The menu was always the one posted item.

On Curry days, Haskell was happy.

...but Robert would be sad.

Curry and Feys go to lunch

A fable by James B. Wilson

On Fry days, Robert was delighted...

...but Haskell was mad.

Curry and Feys go to lunch

A fable by James B. Wilson

Then one day the two of them had and idea!

Replace the menu with a variable so they could both order what they wanted!

How did Curry and Feys Hack Constants' Lunch?

Constant functions have slope 0

Constant functions are

  • \(y=2\) or
  • \(f(x)=3.14\) or
  • \(f(x)=\pi\) or just
  • \(K_c(x)=c\).

 

Graph is a horizontal line (Slope 0).

(Thanks to Desmos.com)

Do constant functions have slope 0?

\(c\) in \(K_c(x)=c\) is a place-holder for some future choice.

(Thanks to Desmos.com)

I'm going to choose \(c:=x\).

 

\(K_x(x)=x\)

Graph that ...

 

IT HAS SLOPE 1!

Constant functions DON'T have slope 1, so what's the mistake?

Substitution isn't just         "replace all symbols."

  • There are rules to substitution.  
  • When you make rules, you are choosing a logic.
  • The name?  "Lambda (\(\lambda\)) Calculus"

Substitution Refresh

  1. Identity Law:  \[x|_{x:=\sigma}\quad \text{yields}\quad \sigma\]
  2. Constant Law: \[a|_{x:=\sigma}\quad \text{yields}\quad a\]
  3. Composition Law: \[\rho\phi |_{x:=\sigma}\quad\text{yields}\quad \rho|_{x:=\sigma} \phi|_{x:=\sigma}\]

\(x\) from alphabet of variables

\(a\) from separate alphabet of constants

\(\sigma\) a string of variables, constants, and the \(\mapsto\) symbol.

  1. \(x|_{x:=35+y}\rhd 35+y\)

3. \(\begin{aligned} x7|_{x:=35+y} & \rhd (x|_{x:=35+y})(7|_{x:=35+y})\\ & \rhd (35+y)7\end{aligned}\)

2. \(5|_{x:=35+y}\rhd 5\)

Technical point, the parentheses, \(|\), \(:=\), and \(\rhd\) are outside the language, they are "meta-language".

> x:=35+y
> x
35+y
> x:=35+y
> 27
27
> x:=35+y
> (x-5)(x+5)
(35+y-5)(35+y+5)

Substitution Refresh

 \[\begin{aligned} (x\mapsto x^2)|_{x:=35+y} & \rhd (x\mapsto x^2)\end{aligned}\]

x := 35+y
def f(x)
	return x*x

Not the "same" x.

4. Local Variables are invisible from outside scope: \[(x\mapsto \tau)|_{x:=\sigma}\qquad \text{yields}\qquad x\mapsto \tau\]

Not the "same" \(x\).

(More confusing in math notation.)

def f(x)
	return x*x

Substitution Refresh

x := 35+y
def f(y)
	s := 0
	for x in [1..10]
    	s := y*x 
	return s

Not the "same" x.

5. Avoid Trapping variables!

  • If \(x\) is local (or not even in) \(\tau\) then \[(y\mapsto \tau)|_{x:=\sigma}\quad\text{yields}\quad y\mapsto \tau\]
def f(y)
	s := 0
	for x in [1..10]
    	s := y*x 
	return s

Substitution Refresh

x := 35+pi
def f(y)
	return y + x

SAME  x.

If \(x\) is in \(\tau\) but free, then avoid trapping variables!

  • If \(y\) not visible in \(\sigma\) \[(y\mapsto \tau)|_{x:=\sigma}\quad \text{yields}\quad y\mapsto (\tau|_{x:=\sigma})\]
  • Else \[(y\mapsto \tau)|_{x:=\sigma}\quad \text{yields}\quad y\mapsto ((\tau|_{y:=z})|_{x:=\sigma})\]
def f(y)
	return y + (35+pi)

No "visible" y.

x := 35+y
def f(y)
	return y + x

SAME  x.

def f(y)
	return y + (35+y)

y is visible (free)! 

x := 35+y
def f(z)
	return z + (35+y)

Not the same y.

Trapped variable

x := 35+pi
def f(y)
	return y + x

SAME  x.

No "visible" y, 

so not trapped

x := 35+y
def f(y)
	return y + x

SAME  x.

y is visible (free)! 

So it is trapped between same x's

Trapped variable

SAME  x=c.

No "visible" x, 

so not trapped

\(c:=5\)

\(K_c(x)=c\)

SAME  x=c.

"visible" x, 

trapped;

rename!

\(c:=x\)

\(K_c(x)=c\)

\(c:=x\)

\(K_c(z)=c\);

So \(K_x(z)=x\)

(still slope 0, but in the zx-plane)

 

\(K_5(x)=5\)

Quick History

  • Rules are by Curry-Feys
  • \(x\mapsto \sigma\) was traditionally written \[\lambda x.\sigma\]
  • Hence the name "lambda calculus" (thanks A. Church!)

Recap as one rule:

Substitute like normal except if you trap a free variable.

(....be honest, did you really know that?)

Substitution

By James Wilson

Substitution

Substitution seems so obvious that we can be fooled by simple mistakes. Fixing them forces us into a logic and calculus to go with it. This is known as Lambda calculus and the rules we will use are by Curry-Feys. Come along for a playful tour of what goes wrong when we substitute.

  • 83