Skip to content
July 9, 2010 / cdsmith

Data Constructors In Math

This is a short post — nothing deep or complex, but just a simple observation.  Often, distinctions that are made in programming language reflect ideas that already exist, but that we tend to be less clear about, in other contexts, too!

We make an observation about Haskell…

In Haskell programming, there’s a distinction between a variable, which starts with a lower-case letter, and a data constructor, which starts with an upper-case letter.  For example, consider the following declaration of a familiar data type.

data Bool = True | False

This defines the type Bool, and its two values True and False.  They are data constructors.  On the other hand, we can also write this:

true = True
false = False

This defines two new symbols, true and false (note the lower-case letters) that mean the same thing as True and False…. sort of.  They mean the same thing only when they occur in the context of an expression.  Still, there remains a difference: True and False can occur in pattern matching, which true and false cannot.

At first glance, this looks like a rather arbitrary distinction.  Pattern matching, after all, is a particular Haskell language construct.  Indeed, there are plenty of languages without the distinction.  But is it really all that arbitrary?

Ultimately what’s happening here is that Haskell has provided us with syntax to say that True and False are defined on the fly by virtue of their occurring inside the definition of Bool.  Furthermore, since they have no other definition to tell us otherwise, we’re left to assume that values built from different data constructors are distinct, as are the values obtained by applying any one data constructor to different arguments.

Meanwhile…

While we wrestle with these issues in Haskell programming, mathematics students in an algebra course are tackling a different problem: the lecture notes for their courses don’t seem to make much sense!  They start out with some analysis, where they come across the following:

Consider the sequence (x_i \cdot y_i) obtained by multiplying corresponding elements of x and y.  Let \epsilon > 0

This they understand: Here x and y are essentially maps from the natural numbers to values of some sequences.  These maps were defined earlier, and now specific values of them are obtained by applying them to particular natural numbers.  Now on to algebra, where perhaps they are learning about Leavitt algebras, and their notes say:

The Leavitt algebra L(1,n) is generated by \{ x_i, y_i \mid 1 \leq i \leq n \} together with relations…

Almost exactly the same wording occurs here (x_i, y_i for certain values of i), but at first the students are very confused.  Here, there are no maps x and y that were previously known.  Our hypothetical students are left to figure out on their own what the x and y might mean.

Hopefully, these students eventually realize that here, the x and y are is being defined right here alongside L(1,n).  Before that sentence, x and y meant nothing in particular.  From context, one infers that they are maps from numbers to L(1,n).  Because no one mentioned otherwise, one is supposed to assume that values taken by x and y are distinct, as are the values of each of x and y when applied to different arguments…

Ah ha!

Now we get to the point.  What’s happened here is that our hypothetical mathematics students have encountered the difference between a variable and a data constructor.  Their analysis notes were using variables, while their algebra notes were using data constructors.  But in the mathematical world, there is no distinct notation to clarify what is going on!

Perhaps it would be made clearer if we rewrite their notes in Haskell.  In the analysis context:

x :: Int -> Double
y :: Int -> Double

p :: Int -> Double
p i = x i * y i

While in the algebra context, we have:

data LeavittGenerator where
    X :: Int -> LeavittGenerator
    Y :: Int -> LeavittGenerator

The data constructors are now clearly something different, as they begin with capital letters!

About these ads

2 Comments

Leave a Comment
  1. Alessandro Stamatto / Jul 9 2010 11:51 pm

    Cool, it was nice to see a Parallel between haskell and Math. I don’t understand most of them, but this one was simple and i got it! Nice =)

  2. Dan Piponi / Jul 10 2010 6:43 pm

    Check out the book “Logic, Induction and Sets” by T Forster. It is intended as a book on logic and set theory to go with a course for mathematicians, but he borrows the language of ML-type languages, including the term “constructor”. He also uses the term “founder” to mean elements of your structure that are explicitly listed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 80 other followers

%d bloggers like this: