The biggest nightmare for most people learning Haskell is monads. Monads are the
key to how you can implement IO, state, parallelism, and sequencing (among numerous other things) in Haskell. The trick is wrapping your head around them.
Category Archives: Good Math
Basics: Natural Numbers and Integers
One of the interestingly odd things about how people understand math is numbers. It’s
astonishing to see how many people don’t really understand what numbers are, or what different kinds of numbers there are. It’s particularly amazing to listen to people arguing
vehemently about whether certain kinds of numbers are really “real” or not.
Today I’m going to talk about two of the most basic kind of numbers: the naturals and the integers. This is sort of an advanced basics article; to explain things like natural numbers and integers, you can either write two boring sentences, or you can go a bit more formal. The formal
stuff is more fun. If you don’t want to bother with that, here are the two boring sentences:
- The natural numbers (written N) are zero and the numbers that can be
written without fractions that are greater than zero. - The integers (written Z) are all of the numbers, both larger and smaller than
zero, that can be written without fractions.
Basics: Margin of Error
The margin of error is the most widely misunderstood and misleading concept in statistics. It’s positively frightening to people who actually understand what it means to see how it’s commonly used in the media, in conversation, sometimes even by other scientists!
The basic idea of it is very simple. Most of the time when we’re doing statistics, we’re doing statistics based on a sample – that is, the entire population we’re interested in is difficult to study; so what we try to do is pick a representative subset called a sample. If the subset is truly representative, then the statistics you generate using information gathered from the sample will be the same as information gathered from the population as a whole.
But life is never simple. We never have perfectly representative samples; in fact, it’s impossible to select a perfectly representative sample. So we do our best to pick good samples, and we use probability theory to work out a predication of how confident we can be that the statistics from our sample are representative of the entire population. That’s basically what the margin of error represents: how well we think that the selected sample will allow us to predict things about the entire population.
Hellish Programming: Malbolge
I decided that for today, I’d show the most thoroughly evil programming language ever
devised. This is a language so thoroughly evil that it’s named Malbolge after a circle
of hell. It’s so evil that it’s own designer was not able to write a hello world program! In
fact, the only way that anyone managed to write a “Hello World” was by designing a genetic algorithm
to create one. This monstrosity is so thoroughly twisted that I decided to put it in the “Brain and Behavior” category on ScienceBlogs, because it’s a demonstration of what happens when you take a brain, and twist it until it breaks.
Sex Crimes and Illegal Immigrants: Misuse of Statistics for Politics
Yet another reader sent me a great bad math link. (Keep ’em coming guys!) This one is an astonishingly nasty slight of hand, and a great example of how people misuse statistics to support a political agenda. It’s by someone
named “Dr. Deborah Schurman-Kauflin”, and it’s an attempt to paint illegal
immigrants as a bunch of filthy criminal lowlifes. It’s titled “The Dark Side of Illegal Immigration: Nearly One Million Sex Crimes Committed by Illegal Immigrants in the United States.”
With a title like that, you’d think that she has actual data showing that nearly one million sex crimes were committed by illegal immigrants, wouldn’t you? Well, you’d be wrong.
Basics: Standard Deviation
When we look at a the data for a population+ often the first thing we do
is look at the mean. But even if we know that the distribution
is perfectly normal, the mean isn’t enough to tell us what we know to understand what the mean is telling us about the population. We also need
to know something about how the data is spread out around the mean – that is, how wide the bell curve is around the mean.
There’s a basic measure that tells us that: it’s called the standard deviation. The standard deviation describes the spread of the data,
and is the basis for how we compute things like the degree of certainty,
the margin of error, etc.
Haskell: the Basics of Type Classes
One thing that we’ve seen already in Haskell programs is type
classes. Today, we’re going to try to take our first look real look
at them in detail – both how to use them, and how to define them. This still isn’t the entire picture around type-classes; we’ll come back for another look at them later. But this is a beginning – enough to
really understand how to use them in basic Haskell programs, and enough to give us the background we’ll need to attack Monads, which are the next big topic.
Type classes are Haskell’s mechanism for managing parametric polymorphism. Parametric polymorphism
is a big fancy term for code that works with type parameters. The idea of type classes is to provide a
mechanism for building constrained polymorphic functions: that is, functions whose type involves a type parameter, but which needs some constraint to limit the types that can be used to instantiate it, to specify what properties its type parameter must have. In essence, it’s doing very much the same thing that parameter type declarations let us do for the code. Type declarations let us say “the value of this parameter can’t be just any value – it must be a value which is a member of this particular type”; type-class declarations let us say “the type parameter for instantiating this function can’t be just any type – it must be a type which is a member of this type-class.”
Quantum Computation Complexity: BQP
What started me on this whole complexity theory series was a question in
the comments about the difference between quantum computers and classical
computers. Taking the broadest possible view, in theory, a quantum computer
is a kind of non-deterministic machine – so in the best possible case,
a quantum machine can solve NP-complete problems in polynomial time. The set
of things computable on a quantum machine is not different from the set of
things computable on a classical machine – but the things that are tractable (solvable in a reasonable amount of time) on a quantum
computer may be different.
Basics: Normal Distributions
In general, when we gather data, we expect to see a particular pattern to
the data, called a normal distribution. A normal distribution is one
where the data is evenly distributed around the mean in a very regular way,
which when plotted as a
histogram will result in a bell curve. There are a lot of ways of
defining “normal distribution” formally, but the simple intuitive idea of it
is that in a normal distribution, things tend towards the mean – the closer a
value is to the mean, the more you’ll see it; and the number of values on
either side of the mean at any particular distance are equal.
Basics: Mean, Median, and Mode
Statistics is something that surrounds us every day – we’re constantly
bombarded with statistics, in the form of polls, tests, ratings, etc. Understanding those statistics can be an important thing, but unfortunately, most people have never been taught just what statistics really mean, how they’re computed, or how to distinguish the different between
statistics used properly, and statistics misused to deceive.
The most basic concept in statistics in the idea of an average. An average is a single number which represents the idea of a typical value. There are three different numbers which can represent the idea of an average value, and it’s important to know which one is being used, and whether or not that is appropriate. The three values are the mean, the median, and the mode.