22 August 2012

CRS function with single factor

An assumption of Ricardian model is constant returns to scale production function with single production factor (labor). Therefore, the marginal product of labor (or, in the usual manner of presentation, its inverse, the units of labor required to produce one unit of good) completely describes the production function. This was so intuitively clear that I never bothered to check.

A production function F(x): Rn → R has constant returns to scale if F(ax) = aF(x) for all a > 0, where x is a n-vector and a is a scalar. In other words, it's economists' way of saying degree 1 homogeneous.

The claim is that if n = 1, then F(x) = cx for some real number c. The proof is simple. Suppose F has constant returns to scale, and denote F(1) = c. Then ac = aF(1) = F(a) for all a > 0. F(0) = 0 follows from the observation that F(0) = aF(0) for all a > 0. Finally, since F(1) = -F(-1), it follows -ac = aF(-1) = F(-a) for all a > 0.

Of course, I could have used Euler's theorem which states that F(x) is homogeneous of degree k iff nF(x) = ΣixiFi where Fi is partial derivative of F regard to xi. Thus, single factor CRS function satisfies F(x) = xF'(x). Solving differential equation yields F(x) = cx.

17 August 2012

Circular shift

I am going through the book Algorithms by Sedgewick and Wayne and found this interesting problem:

A string s is a circular rotation of a string t if it matches when the characters are circularly shifted by any number of positions; e.g., ACTGACG is a circular shift of TGACGAC, and vice versa. Detecting this condition is important in the study of genomic sequences. Write a program that checks whether two given strings s and t are circular shifts of one another.

Claim: strings t and s are circular shifts if and only if t and s have the same length and s is a substring of t + t, where + indicates string concatenation.

One direction is easy to show. Suppose t and s are circular shifts. By definition of circular rotation t and s are of the same length. Also by definition, there exist substrings u and v of t such that t = u + v and s = v + u. Therefore, t + t = u + v + u + v = u + s + v, so s is a substring of t + t.

Conversely, suppose t and s are strings of the same length N and that s is a substring of t + t. Thus, there exist substrings u and v such that t + t = u + s + v. Since t + t is of length 2N and s is of length N, u + v is of length N. Suppose u is of length m. Clearly, u is first m letters of t and v is last N - m letters of t. This implies t = u + v. It follows that t + t = u + v + u + v = u + s + v and thus s = v + u.

With the claim, the implementation is simple. In Java:

public static boolean circularshift(String t, String s)
{
  return t.length() == s.length() && (t + t).indexOf(s) != -1;
}