Monday, December 17, 2018

Mathematical vs. Computational approach II - linear algebra

I was solving LeetCode #874 - Walking Robot Simulation. (Yes, I am almost done with solving Easy level problems!) Here you need to be able to turn the direction of robot motion, out of four possible orientations: North / South / East / West, or simply ±X and ±Y. What came to me first was purely mathematical, or linear algebra: rotation matrix. For clockwise rotation, you can use R(-90°) where R is the 2x2 unitary matrix corresponding to CCW rotation, and R(90°) for opposite rotation.

But there are only four direction vectors: (±1, 0) and (0, ±1). Rotation means circulating the four either with increasing or decreasing indices. R(90°) is equivalent to cyclic (1,0) → (0,1) → (-1,0) → (0,-1) → (1,0).

The mathematical logic using rotation matrix can generalize the vector rotation into any angle. In that sense it is a fundamental principle. But the special case of direction vectors only along x or y axis doesn't even need any math, except that you denote the direction vectors with proper tuple (set) of coordinates. The latter is obviously much simpler and quicker to calculate, thus optimal for this particular problem.

To me the distinction between mathematical and computational approach in the present case goes far beyond a question of which is faster or better. I feel that I am seeing a deep philosopical dichotomy between pure and applied knowledge (or science). The former type of people, or principle-based thinkers may not understand or like those with the latter, and vice versa. The gap between the two regime might be far wider and deeper than we assume.

No comments:

Post a Comment

Philips SAECO Xsmall espresso machine repaired

I have a SAECO Xsmall espresso machine. I bought it in Dec 2014, and brewed 2~3 cups of espresso per day on the average over the last 6 year...