Showing posts with label math. Show all posts
Showing posts with label math. Show all posts

Tuesday, April 23, 2013

Determinant in Haskell

In linear algebra, the determinant is quite a useful operation that can be done on matrices. To further my understanding of Haskell, I decided to program a solver for systems of equations. One of the best ways to do this dynamically is through Cramer's Rule which needs to be able to calculate determinants. So, here's my recursive code for finding determinants:

determinant :: (Num a, Fractional a) => [[a]] -> a

determinant [[x]] = x
determinant mat =
 sum [(-1)^i*x*(determinant (getRest i mat)) | (i, x) <- zip [0..] (head mat)]


So, in this code, the base case is a 1x1 matrix. The getRest function simply returns the matrix without the head row (topmost) and without the \(i\)th column.

The code and tests are available on my github.

Wednesday, April 10, 2013

Creating a Sine Function in Haskell

Using Taylor Series derivation I found the following infinite sum expression for sin:
\[
  \sin \left(x \right) = \sum_{i = 1}^{\infty} \frac{x^{2 i - 1}}{\left( 2 i - 1 \right)!} \left( -1 \right)^{i - 1}
\]
The exact derivation is available as a PDF on github.

The translation of this sum into Haskell code was simple:

sin' :: (Num a, Fractional a) => a -> a
sin' x = sum [sinTerm x i | i <- [1..33]]


sinTerm :: (Num a, Fractional a) => a -> Integer -> a
sinTerm x i = (x^oddTerm / fromIntegral (factorial oddTerm))*(-1)^(i-1)
  where oddTerm = 2*i - 1


So, this code is pretty straight forward, if you wanted to get more accuracy on the results you could change "33" to be some greater value (33 says that we will sum up 33-1=32 terms of the taylor series).

Of course this code references factorial which is defined simply as:

factorial :: Integer -> Integer
factorial 1 = 1
factorial n = n * factorial (n-1)


As usual, code and tests are available on github.

Wednesday, March 27, 2013

Proof by Induction Example

Proof by induction is a powerful, accepted tool for producing not only mathematical proofs but also proofs of algorithms in computer science and other fields as well.

The concept of proof by induction, is generally described as being a three step process:
  1. Prove a base case (in many cases we call this \(P(1)\)).
  2. Assume that the \(k\)th case is true (we call this \(P(k)\)).
  3. Show that the \(k+1\)th case is true (we call this \(P(k+1)\)).
As can be seen \(P(1) \rightarrow P(2)\), since our base case has been established at \( P(1)\) and we have shown that for our \( k+1\)th case, when \( k = 1\) (i.e. \(P(2)\)) our proposition stands. This can be further extended to show that \( P(2) \rightarrow P(3) \rightarrow ... \rightarrow P(n)\).

So, in less-mathematical terms, proof by induction is as simple as proving some proposition is true for some starting value, and then verifying that it is true for the next one, and the next one, continuing on as far as it needs to or, in other words, to the \(n\)th value.

The following is a simple, somewhat standard example.

Problem

\( \forall n \in \mathbb{N} \), prove that: \[ \sum_{i = 1}^{n} i = \frac{n \left( n + 1 \right)}{2} \]

(This is saying that if we sum up all the numbers from one to \(n\), that sum should equivalently be calculable by \( \frac{n \left( n + 1 \right)}{2} \))

Proof

 Before we start the proof, it's useful to...
\[
  \text{let } P(n) =  \sum_{i = 1}^{n} i
\]

Now...

Proof by Induction

Step 1: Prove base-case, \( P(1) \):

So, the sum of all number from one to one is:
\[
  P(1) = \sum_{i = 1}^{1} i = 1
\]

Now we verify that our formula works for \( n = 1\):
\[
  \frac{n \left(n + 1 \right)}{2} = \frac{1 \left(1 + 1 \right)}{2} = \frac{2}{2} = 1
\]

It checks!

Step 2: Assume that \( P(k) \) is true:

So, here we are assuming that:
\[
  P(k) = \sum_{i = 1}^{k} i = 1 + 2 + 3 + ... + k = \frac{k \left( k + 1 \right)}{2}
\]

Step 3: Show that \( P(k+1) \) is consistent:

So, \( P(k+1) \) looks like, (replacing \(n\) with \( k + 1\)):
\[
  P(k+1) =  \sum_{i = 1}^{k+1} i = 1 + 2 + 3 + ... + k + (k + 1) = \frac{\left( k + 1 \right) \left[ \left( k + 1 \right) + 1 \right]}{2}
\]

Noticing that \( 1 + 2 + 3 + ... + k \) is the same as \( P(k) \) from Step 2:
\[
  \frac{k \left( k + 1 \right)}{2} + \left( k + 1 \right) = \frac{\left( k + 1 \right) \left[ \left( k + 1 \right) + 1 \right]}{2}
\]

Multiplying both sides by \(2\):
\[
   k \left( k + 1 \right) + 2\left( k + 1 \right) = \left( k + 1 \right) \left[ \left( k + 1 \right) + 1 \right]
\]

Distribute \(k\) and \(2\) on the left, add the \(1\)s on the right:
\[
  k^2 + k + 2k + 2 = \left( k + 1 \right) \left( k + 2 \right)
\]

FOIL the right:
\[
  k^2 + k + 2k + 2 = k^2 + 2k + k + 2 \text{      $\square$}
\]

It's really as easy as that!

Simple Partial Differential Equations Example

I am really enjoying my current partial differential equations class, so I thought I'd share an example problem. Note that this is probably one of the simplest problems in partial DE.

Problem

\begin{equation}
  \text{(1)    } k^2 \frac{\partial^2 U}{\partial t^2} = \frac{\partial^2 U}{\partial x^2}
\end{equation}
\begin{equation}
  \text{(2)    } U \left( 0, t \right) = 0
\end{equation}
\begin{equation}
  \text{(3)    } U \left( L, t \right) = 0
\end{equation}
\begin{equation}
  \text{(4)    } U \left( x, 0 \right) = 0
\end{equation}
\begin{equation}
  \text{(5)    } \frac{\partial U}{\partial t} \left( x, 0 \right) = f \left( x \right)
\end{equation}

Solution


We are looking for a solution of the form:
\[
  U = XT
\]
Where \(X\) is a function of \(x\) and \(T\) is a function of \(t\).

Translating (1) to match the expected solution, we get:
\[
  k^2 XT^{\prime\prime} = X^{\prime\prime} T
\]

Dividing each side by \( XT \):
\[
  k^2 \frac{T^{\prime\prime}}{T} = \frac{X^{\prime\prime}}{X}
\]

Since we have a function of only \(T\) on the left and only \( X \) on the right, we know that these are equal to a constant.
\[
  k^2 \frac{T^{\prime\prime}}{T} = \frac{X^{\prime\prime}}{X} = constant = \left\{\begin{array}{lr}
  0 \\
  -\lambda^2 \\
  \lambda^2
\end{array}   \right.
\]

The notation above says that the constant can either be \(0\), some negative number (as forced to be negative by \( -\lambda^2 \)) or some positive number (forced by \( \lambda^2 \)).

Case \( constant = 0 \):

Finding \( X \):
\[
  \frac{X^{\prime\prime}}{X} = 0 \Rightarrow X^{\prime\prime} = 0
\]

Integrating both sides:
\[
  X^{\prime} = A
\]
Where \( A \) is an arbitrary constant.

Integrating again:
\[
  X = A x + B
\]
Where \( B \) is an arbitrary constant.

Finding \( T \):
\[
  \frac{k^2 T^{\prime\prime}}{T} = 0 \Rightarrow T^{\prime\prime} = 0
\]

Integrating both sides:
\[
  T^{\prime} = C
\]
Where \( C \) is an arbitrary constant.

Integrating again:
\[
  T = C t + D
\]
Where \( D \) is an arbitrary constant.

Since \( U = XT \):
\[
  U = \left(A x + B\right) \left( C t + D \right)
\]
Therefore, this satisfies (1).

Looking at (2), we have:
\[
  U \left( 0, t \right) = 0 \Rightarrow \left(A (0) + B\right) \left( C t + D \right) = 0 \Rightarrow B \left( C t + D \right)= 0
\]

This implies that \( B = 0 \), so:
\[
  U = A x \left( C t + D \right) = x \left( C t + D \right)
\]
satisfies (1) and (2); note that the constant \( A \) was absorbed into the other constants (since they are, after all, just arbitrary constants).

Looking at (3), we have:
\[
  U \left( L, t \right) = 0 \Rightarrow L \left( C t + D \right) = 0
\]

To make this true, we can't change the value of \( L \) because it is a constraint, so the only option is to make \( C = D = 0\).

So,
\[
  U = 0
\]
This, however, is an uninteresting solution for \( U \). So, we examine the next possible constant.

Case \( constant = -\lambda^2 \):

Finding \( X \):
\[
  \frac{X^{\prime\prime}}{X} = -\lambda^2
\]

Multiply both sides by \( X \):
\[
  X^{\prime\prime} = -\lambda^2 X
\]

Using methods from differential equations (DE), we know that we can solve this by subbing \( \alpha^2 \) in for \( X^{\prime\prime} \) and \( 1 \) in for \( X \):
\[
  \alpha^2 = -\lambda^2
\]

Taking the square root of both sides we get:
\[
  \alpha = \pm \lambda i
\]

From DE we know that this fits the form \(\alpha = b \pm c i \), where the answer the the DE is:
\[
  X = e^{bx} \left[ A \cos \left( c x \right) + B \sin \left( c x \right)\right]
\]
Where \(A\) and \(B\) are arbitrary constants.

Therefore:
\[
  X = e^{0x} \left[ A \cos \left( \lambda x \right) + B \sin \left( \lambda x \right)\right] = \left[ A \cos \left( \lambda x \right) + B \sin \left( \lambda x \right)\right]
\]

Finding \( T \):

\[
  k^2 \frac{T^{\prime\prime}}{T} = -\lambda^2
\]

Multiply both sides by \( \frac{T}{k^2} \):
\[
  T^{\prime\prime} = -\frac{\lambda^2}{k^2} T
\]

Using methods from differential equations (DE), we know that we can solve this by subbing \( \beta^2 \) in for \( T^{\prime\prime} \) and \( 1 \) in for \( T \):
\[
  \beta^2 = -\frac{\lambda^2}{k^2}
\]

Taking the square root of both sides we get:
\[
  \beta = \pm \frac{\lambda}{k} i
\]

From DE we know that this also fits the form \(\beta = b \pm c i \), where the answer the the DE is:
\[
  T = e^{bt} \left[ C \cos \left( c t \right) + D \sin \left( c t \right)\right]
\]
Where \(C\) and \(D\) are arbitrary constants (not necessarily the same as \(A\) and \( B \)).

Therefore:
\[
  T = e^{0t} \left[ C \cos \left( \frac{\lambda}{k} t \right) + D \sin \left( \frac{\lambda}{k} t \right)\right] = \left[ C \cos \left( \frac{\lambda}{k} t \right) + D \sin \left( \frac{\lambda}{k} t \right)\right]
\]

Since \( U = XT \):
\[
  U = \left[ A \cos \left( \lambda x \right) + B \sin \left( \lambda x \right)\right] \left[ C \cos \left( \frac{\lambda}{k} t \right) + D \sin \left( \frac{\lambda}{k} t \right)\right]
\]
Therefore, this satisfies (1).

Looking at (2), we have:
\[
  U \left( 0, t \right) = 0 \Rightarrow \left[ A \cos \left( 0 \right) + B \sin \left( 0 \right)\right] \left[ C \cos \left( \frac{\lambda}{k} t \right) + D \sin \left( \frac{\lambda}{k} t \right)\right] = 0
\]

\(\cos \left( 0 \right) = 1\) and \( \sin \left( 0 \right) = 0\), so,
\[
  A \left[ C \cos \left( \frac{\lambda}{k} t \right) + D \sin \left( \frac{\lambda}{k} t \right)\right] = 0
\]

This implies that \( A = 0 \), so:
\[
  U = \sin \left( \lambda x \right) \left[ C \cos \left( \frac{\lambda}{k} t \right) + D \sin \left( \frac{\lambda}{k} t \right)\right]
\]  
satisfies (1) and (2); note that the constant \( B \) was absorbed into the other constants (since they are, after all, just arbitrary constants).

Looking at (3), we have:
\[
  U \left( L, t \right) = 0 \Rightarrow \sin \left( \lambda L \right) \left[ C \cos \left( \frac{\lambda}{k} t \right) + D \sin \left( \frac{\lambda}{k} t \right)\right] = 0
\]

So, we need to pick a value for \( \lambda \) that causes the above expression to always be zero. We find that there are an infinite number of them (everywhere \( \sin \left( n \pi \right) \) where n is a natural number (better suited to match the solution than an integer). So, because of this, we find that:
\[
  \lambda = \frac{n \pi}{L},\, \forall n \in \mathbb{N}
\]

So, subbing in for \( \lambda \), we have:
\[
  U = \sin \left( \frac{n \pi x}{L} \right) \left[ C \cos \left( \frac{n \pi}{L k} t \right) + D \sin \left( \frac{n \pi}{L k} t \right)\right]
\]
Which satisfies (1), (2) and (3).

Looking at (4), we have:
\[
  U \left( x, 0 \right) = 0 \Rightarrow \sin \left( \frac{n \pi x}{L} \right) \left[ C \cos \left( 0 \right) + D \sin \left( 0 \right)\right] = 0
\]

\(\cos \left( 0 \right) = 1\) and \( \sin \left( 0 \right) = 0\), so,
\[
    U \left( x, 0 \right) = 0 \Rightarrow \sin \left( \frac{n \pi x}{L} \right) \left( C \right) = 0
\]

This implies that \( C = 0\), so,
\[
  U = \sin \left( \frac{n \pi x}{L} \right) \left( D \right) \sin \left( \frac{n \pi}{L k} t \right)
\]
Satisfies (1), (2), (3) and (4).

Since constraint (5) is non-zero, I will evaluate it lastly. For now, I claim that:
\[
  U = \sum_{n = 1}^{\infty} D_n \sin \left( \frac{n \pi x}{L} \right) \sin \left( \frac{n \pi}{L k} t \right)
\]
\( \forall n \in \mathbb{N}\), also satisfies (1), (2), (3), and (4). This claim is justified because, as show above, constraint (3) is satisfied for all values of \( n \). So, for whatever \( n \) I pick from the natural numbers (\( 1,2,3...\), \(\mathbb{N}\)) the resulting \( U \) will also be an answer. So, summing together the infinite answers for \( U \) still meets the problem's criteria. \( D \) became \( D_n \) because \( D \) is not necessarily the same thing for any \( n \) value.

So, considering constraint (5), we need to first find \( \frac{\partial U}{\partial t}\):
\[
  \frac{\partial U}{\partial t} = \sum_{n = 1}^{\infty} D_n \sin \left( \frac{n \pi x}{L} \right) \left( \frac{n \pi}{L k} \right) \cos \left( \frac{n \pi}{L k} t \right)
\]

Looking at the actual constraint, (5):
\[
  \frac{\partial U}{\partial t} \left( x, 0 \right) = f \left( x \right) \Rightarrow \sum_{n = 1}^{\infty} D_n \sin \left( \frac{n \pi x}{L} \right) \left( \frac{n \pi}{L k} \right) \cos \left( 0 \right) = f \left( x \right)
\]

Since, \( \cos \left( 0 \right) = 1\):
\[
  f \left( x \right) = \sum_{n = 1}^{\infty} D_n \sin \left( \frac{n \pi x}{L} \right) \left( \frac{n \pi}{L k} \right)
\]

By the Fourier sine series, we know that the coefficients are given by:
\[
  D_n \left( \frac{n \pi}{L k} \right) = \frac{2}{L} \int_0^L f \left( x \right) \sin \left( \frac{n \pi x}{L} \right) dx
\]
We include \( \left( \frac{n \pi}{L k} \right) \) because it does not match the Fourier series and needs to be divided out.

Solving for the actual coefficients:
\[
  D_n = \frac{2 k}{n \pi} \int_0^L f \left( x \right) \sin \left( \frac{n \pi x}{L} \right) dx
\]

Where our final \( U \) is, as above:
\[
  U = \sum_{n = 1}^{\infty} D_n \sin \left( \frac{n \pi x}{L} \right) \sin \left( \frac{n \pi}{L k} t \right)
\]

Now, we could go on to examine the \( constant = \lambda^2 \) case. However, it ends up just being \( 0 \) (and is therefore redundant). You can use methods like those above to come to this conclusion for yourself.

Thursday, March 21, 2013

Nieve Prime Finder in Haskell

To solve a cyber-dojo challenge (implement a function/method that returns the prime factors of a number) I decided to implement a somewhat nieve (but workable) isPrime function in Haskell. Here's the code:

-- Public type-definition
isPrime :: Integer -> Bool

-- Private type-definition
lookForPrimeFrom :: Integer -> Integer -> Bool

isPrime 2 = True
isPrime n
 | n < 2     = False
 | even n    = False
 | otherwise = lookForPrimeFrom n 5

lookForPrimeFrom n i
 | ceiling (sqrt (fromIntegral n))+1 < i   = True
 | (n `mod` i) == 0                        = False
 | otherwise                               = lookForPrimeFrom n (i+2)



This code (to me at least) seems very self-documenting. The more I'm playing around with Haskell, the more I'm enjoying it and seeing its strength as a functional language. I think if I were to map this algorithm into more mathematical notation it would look like:

\[
  \forall n \in \mathbb{N}
\]
\[
  p \left( n \right) = \left\{ \begin{array}{lr}
  0, & n = 1 \\
  1, & n = 2 \\
  0, & \text{$n$ is even} \\
  1, & \nexists m \in \left\{ x \in \mathbb{N} \, | \, 5 \leq x \leq{\sqrt{n}}, \text{$x$ is odd}  \right\}
  
\end{array} \right.
\]

As you can see, this is somewhat nieve; however, the Haskell code really is quite similar to the mathematical notation.

Tuesday, January 29, 2013

Calculating Standard Deviation

Whenever calculations are made from observed data using some relation there will be an error in these calculations which is known as standard deviation. Now, exactly what this error is varies between the relationship used and the actual data obtained.


The standard deviation is usually represented by the \( \sigma_A \) (sigma) Greek letter, where \( A \) is the thing whose error we are finding. For example, if we calculated some value for gravity (let's call it \( g \)) the standard deviation of the calculated gravity would be represented as \( \sigma_g\). Pretty straight forward, huh?

Equations

Let's first talk about some general equations. For simplicity, let's call our calculated value \( Z \).

If \( Z \) is represented as a sum or difference of terms, \( Z = A_1 + A_2 + ... + A_n\), then \( \sigma_Z = \sqrt{ \sigma_{A_1}^2 + \sigma_{A_2}^2 + ... + \sigma_{A_n}^2 } \).

For example:
\[
  Z = A + B - C \Rightarrow \sigma_Z = \sqrt{ \sigma_A^2 + \sigma_B^2 + \sigma_C^2 }
\]

If \( Z \) is represented as a product or quotient of terms, \( Z = \frac{ A_1 \times A_2 \times ... \times A_n }{ B_1 \times B_2 \times ... \times B_n } \), then its relative standard deviation is given by \( \frac{\sigma_Z}{ Z } = \sqrt{ \left( \frac{\sigma_{A_1}}{A_1} \right)^2 + ... + \left( \frac{\sigma_{A_n}}{A_n} \right)^2 + \left( \frac{\sigma_{B_1}}{B_1} \right)^2 + ... + \left( \frac{\sigma_{B_n}}{B_n} \right)^2} \). Relative standard deviation is just the standard deviation over the calculated value itself. Ergo to get just the standard deviation we just multiply the whole thing by our calculated value.

For example:
\[
  Z = \frac{ A B }{ C } \Rightarrow \sigma_Z = Z \sqrt{ \left( \frac{\sigma_{A}}{A} \right)^2 + \left( \frac{\sigma_{B}}{B} \right)^2 + \left( \frac{\sigma_{C}}{C} \right)^2 }
\]
 If \( Z \) is represented as another variable to a power, \( Z = A^n \), then its relative standard deviation is given by \( \frac{ \sigma_Z }{ Z } = n \frac{ \sigma_A }{ A } \). Like before, to get \( \sigma_Z \), we just multiply by our calculated \( Z \).

For example:
\[
  Z = A^7 \Rightarrow \sigma_Z = 7 Z \frac{ \sigma_A }{ A }

\]


Those are the basic equations that you need to find the standard deviation. For more on techniques, see the following example.

Example

Suppose we want to find the standard deviation of a calculated value, let's call it \( Z\), where:
\[
  Z = A + \frac{ B^2 C}{D}

\]
To make things easier, let \( U = \frac{ B^2 C }{ D } \) and also let \( V = B^2 \). So,
\[
  Z = A + U \Rightarrow \sigma_Z = \sqrt{ \sigma_A^2 + \sigma_U^2 }

\]
So, we need to find \( \sigma_U \), and since \( V = B^2 \),
\[
  U =  \frac{ V C }{ D } \Rightarrow \sigma_U = U \sqrt{ \left( \frac{ \sigma_V }{ V } \right)^2 + \left( \frac{ \sigma_C }{ C } \right)^2 + \left( \frac{ \sigma_D }{ D } \right)^2}

\]
Lastly, we need to find \( \frac{ \sigma_V }{ V } \),
\[
  V = B^2 \Rightarrow \frac { \sigma_V }{ V } = 2 \frac{ \sigma_B }{ B }

\]
Subbing \( 2 \frac{ \sigma_B }{ B } \) in for \( \frac{ \sigma_V }{ V } \), and \(  \frac{B^2 C}{ D } \) for \( U \) we get,
\[
 U =  \frac{ V C }{ D } \Rightarrow \sigma_U = \frac{B^2 C}{ D } \sqrt{ \left( 2 \frac{ \sigma_B }{ B } \right)^2 + \left( \frac{ \sigma_C }{ C } \right)^2 + \left( \frac{ \sigma_D }{ D } \right)^2}
\]
Finally, subbing this new \( \sigma_U \) into the equation for \( \sigma_Z \), we get,
\[
   \sigma_Z = \sqrt{ \sigma_A^2 + \left( \frac{B^2 C}{ D } \sqrt{ \left( 2 \frac{ \sigma_B }{ B } \right)^2 + \left( \frac{ \sigma_C }{ C } \right)^2 + \left( \frac{ \sigma_D }{ D } \right)^2}  \right)^2 }
\]
Which can be more simply written as,
\[
    \sigma_Z = \sqrt{ \sigma_A^2 + \left( \frac{B^2 C}{ D } \right)^2 \left[ \left( 2 \frac{ \sigma_B }{ B } \right)^2 + \left( \frac{ \sigma_C }{ C } \right)^2 + \left( \frac{ \sigma_D }{ D } \right)^2 \right] }
\]

Tuesday, December 11, 2012

Functional Fibonaccis in Haskell

Lately, I've been learning my first functional programming language: Haskell. Thus far, it is truly awesome! Look at the following Fibonacci function (I know it's a dead-horse example):

nthFib :: (Integral a) => a -> a
nthFib 1 = 1
nthFib 2 = 1
nthFib n = nthFib (n-1) + nthFib (n-2) 


So, "What makes this simple Fibonacci example so awesome?" you may ask. Well, there are a few things I really like about it, but the main thing is that it actually looks like the mathematical definition for the Fibonacci Series! Also, that first line looks a lot like "nthFib: Z -> Z", you know, that good-old-mathy notation meaning, "nthFib is a function that maps an integer to an integer" (I know, I know, the first 'a' should be a natural number, I'm still getting there). But this is wicked stuff!


Saturday, December 1, 2012

Programming Challenge Sites

    You know, as a developing programmer one of my biggest challenges is finding ways to exercise new languages/skills/tools that I am learning. There's nothing worse than reading about some new language or paradigm and then thinking, okay, I get it but what now? This is where programming challenge sites come in handy! They tend to provide small problems that can serve as an outlet for new skills and technologies as well as stretch your problem-solving abilities. Here are a few of my favorites:


 
1. Project Euler is a superior collection of mathematical programming challenges which grows progressively more difficult with each new problem. At this point there are 267248 members who have solved at least on problem on PE; however, some problems have as few as 100 solvers! PE is by far one of my favorite sites to turn to for programming challenges on my days off; also it's named after one of the mathematical greats, Leonhard Euler.


    2.  Usually, the StackExchange code golf site's member-provided problems are concerned with shortest code-length solutions (thus the "golf") but there are also a frequent slew of bizarre problems. This is such a cool site. IMHO, the feedback-oriented, well designed StackExchange engine works well in code golf form.



3. Rosalind is a biology programming challenge collection. It has a similar feel to Euler, except what it lacks in mathematical problems it makes up for in string manipulation. The challenges are fun, and more suited for beginners in programming (don't get me wrong, there are some really difficult ones!)



4. Dave Thomas' code katas are designed to challenge and insight the mind. Thomas, co-author of Pragmatic Programmer (that legendary book that us developers should all read) constructed a nice little set of though-provoking challenges, that will (if used properly) increase your critical thinking capacities.



5. Cyber-dojo is a set of team-oriented problems with a focus on TDD. It is meant to be a simplistic environment in which programmers are encouraged to focus on the solving; not the solution. It can be a great way to improve problem solving abilities, hone testing skills and expand your knowledge of new (or old) languages.


Saturday, November 10, 2012

Twitter for Learning

    I used to be a twitter hater. It just seemed like some enormous aggregate of worthless quotes from shallow celebrities and humorous meme-like one-liners from role players.

I couldn't have been more wrong...

    It turns out that, sure, although there exists banality on twitter there are also many valuable resources for gaining information regarding just about anything. Here are some practical aspects of twitter that I have discovered:
  1. Twitter can help you recognize trends in software development, by keeping you up to date on the thoughts of the "rockstars" and professionals in the field. Through their comments, and links to recent blogs you can begin to gauge where the field is heading.
  2. If you are learning a new technology, or already have an abundance of knowledge, you can follow tip-providing twitter accounts which give practical, to-the-point insight. For example, I follow @vimtips, @RegexTip, @java_tips, @TexTip, @AlgebraFact and more. Each of these has taught me some new tricks for tools that I use nearly every day.
  3. Finally, twitter can keep you updated on group activities. The last few months I have gone to local Python and Ruby user group meeting which I heard were happening solely because of twitter.
    Through the last few months of using twitter, I'd really like to say that I have gained some practical knowledge. Do you agree and think that twitter is a useful tool for learning? Perhaps I left out more benefits of twitter? Or is twitter just pure evil? Feel free to share your thoughts.

Why I am in Computer Science and Math

    You know, 8 years ago when my dad first tried to teach me programming in BASIC, I couldn't stand it and thought, why in the world would anyone want to do this? A few years gone by, however, I started playing the massive online virtual reality game titled (quite justly) Second Life.

    I spent a good amount of time on weekends in the virtual world, not to socialize, not to participate in the "gun fights" held therein -- something else drew me in -- building. Second Life provides a very rich environment for constructing objects from basic, mutable shapes called prims. I quickly began constructing swords, jetpacks, guns, and anything else that could come to mind. Building these structures was a blast, but these structures were "dumb;" the extent of their interaction with the world was their ability to be attached to my avatar. This led to my discovery of Second Life's scripting capabilities.

    Scripting the structures was like giving them souls (so to speak), engendering in them an ability to interact with their surroundings. My enjoyment for scripting quickly surpassed my enjoyment for building. It was a very fun experience; I would construct objects, give them "minds" or other teenagers on the site would hire me to give their objects minds. In the end I received a new appreciation for programming, through this virtual sandbox. Later in high school, after I had taken a C programming class for fun, I decided that SW development is what I want to do. Ever since, I have been enjoying learning about new technologies, languages and methodologies and I hope to share some of these here.

    "What about math?" you may ask. Well, the story of my experiences with math is simpler: I have been doing it since I was a small child and it has never ceased to be fun, challenging, and exciting for me.