Question: It is commonly asserted that no consistent, interacting quantum field theory can be constructed with fields that have spin greater than 2 (possibly with some allusion to renormalization). I've also seen (see Bailin and Love, Supersymmetry) that we cannot have helicity greater than 1, absenting gravity. I am yet to see an explanation as to why this is the case; so can anyone help?

Higher spin particles have to be coupled to conserved currents, and there are no conserved currents of high spin in quantum field theories. The only conserved currents are vector currents associated with internal symmetries, the stress-energy tensor current, the angular momentum tensor current, and the spin-3/2 supercurrent, for a supersymmetric theory.
This restriction on the currents constrains the spins to 0,1/2 (which do not need to be coupled to currents), spin 1 (which must be coupled to the vector currents), spin 3/2 (which must be coupled to a supercurrent) and spin 2 (which must be coupled to the stress-energy tensor). The argument is heuristic, and I do not think it rises to the level of a mathematical proof, but it is plausible enough to be a good guide.
Preliminaries: All possible symmetries of the S-matrix
You should accept the following result of O'Raferteigh, Coleman and Mandula--- the continuous symmetries of the particle S-matrix, assuming a mass-gap and Lorentz invariance, are a Lie Group of internal symmetries, plus the Lorentz group. This theorem is true, given its assumptions, but these assumptions leave out a lot of interesting physics:

Coleman-Mandula assume that the symmetry is a symmetry of the S-matrix, meaning that it acts nontrivially on some particle state. This seems innocuous, until you realize that you can have a symmetry which doesn't touch particle states, but only acts nontrivially on objects like strings and membranes. Such symmetries would only be relevant for the scattering of infinitely extended infinite energy objects, so it doesn't show up in the S-matrix. The transformations would become trivial whenever these sheets close in on themselves to make a localized particle. If you look at Coleman and Mandula's argument (a simple version is presented in Argyres' supersymmetry notes, which gives the flavor. There is an excellent complete presentation in Weinberg's quantum field theory book, and the original article is accessible and clear), it almost begs for the objects which are charged under the higher symmetry to be spatially extended. When you have extended fundamental objects, it is not clear that you are doing field theory anymore. If the extended objects are solitons in a renormalizable field theory, you can zoom in on ultra-short distance scattering, and consider the ultra-violet fixed point theory as the field theory you are studying, and this is sufficient to understand most examples. But the extended-object exception is the most important one, and must always be kept in the back of the mind.
Coleman and Mandula assume a mass gap. The standard extension of this theorem to the massless case just extends the maximal symmetry from the Poincare group to the conformal group, to allow the space-time part to be bigger. But Coleman and Madula use analyticity properties which I am not sure can be used in a conformal theory with all the branch-cuts which are not controlled by mass-gaps. The result is extremely plausible, but I am not sure if it is still rigorously true. This is an exercise in Weinberg, which unfortunately I haven't done.
Coleman and Mandula ignore supersymmetries. This is fixed by Haag–Lopuszanski–Sohnius, who use the Coleman mandula theorem to argue that the maximal symmetry structure of a quantum field theory is a superconformal group plus internal symmetries, and that the supersymmetry must close on the stress-energy tensor.

What the Coleman Mandula theorem means in practice is that whenever you have a conserved current in a quantum field theory, and this current acts nontrivially on particles, then it must not carry any space-time indices other than the vector index, with the only exceptions being the geometric currents: a spinor supersymmetry current, $J^{\alpha\mu}$, the (Belinfante symmetric) stress-energy tensor $T^{\mu\nu}$, the (Belinfante) angular momentum tensor $S^{\mu\nu\lambda} = x^{\mu} T^{\nu\lambda} - x^\nu T^{\mu\lambda}$, and sometimes the dilation current $D^\mu = x^\mu T^\alpha_\alpha$ and conformal and superconformal currents too.
The spin of the conserved currents is found by representation theory--- antisymmetric indices are spin 1, whether there are 1 or 2, so the spin of the internal symmetry currents is 1, and of the stress energy tensor is 2. The other geometric tensors derived from the stress energy tensor are also restricted to spin less then 2, with the supercurrent having spin 3/2.
What is a QFT?
Here this is a practical question--- for this discussion, a quantum field theory is a finite collection of local fields, each corresponding to a representation of the Poincare group, with a local interaction Lagrangian which couples them together. Further, it is assumed that there is an ultra-violet regime where all the masses are irrelevant, and where all the couplings are still relatively small, so that perturbative particle exchange is ok. I say pseudo-limit, because this isn't a real ultra-violet fixed point, which might not exist, and it does not require renormalizability, only unitarity in the regime where the theory is still perturbative.
Every particle must interact with something to be part of the theory. If you have a noninteracting sector, you throw it away as unobservable. The theory does not have to be renormalizable, but it must be unitary, so that the amplitudes must unitarize perturbatively. The couplings are assumed to be weak at some short distance scale, so that you don't make a big mess at short distances, but you can still analyze particle emission order by order
The Froissart bound for a mass-gap theory states that the scattering amplitude cannot grow faster than the logarithm of the energy. This means that any faster than constant growth in the scattering amplitude must be cancelled by something.
Propagators for any spin
The propagators for massive/massless particles of any spin follow from group theory considerations. These propagators have the schematic form
$$ s^J\over s-m^2$$
And the all-important s scaling, with its J-dependence can be extracted from the physically obvious angular dependence of the scattering amplitude. If you exchange a spin-J particle with a short propagation distance (so that the mass is unimportant) between two long plane waves (so that their angular momentum is zero), you expect the scattering amplitude to go like $\cos(\theta)^J$, just because rotations act on the helicity of the exchanged particle with this factor.
For example, when you exchange an electron between an electron and a positron, forming two photons, and the internal electron has an average momentum k and a helicity +, then if you rotate the contribution to the scattering amplitude from this exchange around the k-axis by an angle $\theta$ counterclockwise, you should get a phase of $\theta/2$ in the outgoing photon phases.
In terms of Mandelstam variables, the angular amplitude goes like $(1-t)^J$, since t is the cosine of the scattering variable, up to some scaling in s. For large t, this grows as t^J, but "t" is the "s" of a crossed channel (up to a little bit of shifting), and so crossing t and s, you expect the growth to go with the power of the angular dependence. The denominator is fixed at $J=0$, and this law is determined by Regge theory.
So that for $J=0,1/2$, the propagators shrink at large momentum, for $J=1$, the scattering amplitudes are constant in some directions, and for $J>1$ they grow. This schematic structure is of course complicated by the actual helicity states you attach on the ends of the propagator, but the schematic form is what you use in Weinberg's argument.
Spin 0, 1/2 are OK
That spin 0 and 1/2 are ok with no special treatment, and this argument shows you why: the propagator for spin 0 is
$$ 1\over k^2 + m^2$$
Which falls off in k-space at large k. This means that when you scatter by exchanging scalars, your tree diagrams are shrinking, so that they don't require new states to make the theory unitary.
Spinors have a propagator
$$ 1\over \gamma\cdot k + m $$
This also falls off at large k, but only linearly. The exchange of spinors does not make things worse, because spinor loops tend to cancel the linear divergence by symmetry in k-space, leaving log divergences which are symptomatic of a renormalizable theory.
So spinors and scalars can interact without revealing substructure, because their propagators do not require new things for unitarization. This is reflected in the fact that they can make renormalizable theories all by themselves.
Spin 1
Introducing spin 1, you get a propagator that doesn't fall off. The massive propagator for spin 1 is
$$ { g_{\mu\nu} - {k_\mu k_\nu\over m^2} \over k^2 + m^2 }$$
The numerator projects the helicity to be perpendicular to k, and the second term is problematic. There are directions in k-space where the propagator does not fall off at all! This means that when you scatter by spin-1 exchange, these directions can lead to a blow-up in the scattering amplitude at high energies which has to be cancelled somehow.
If you cancel the divergence with higher spin, you get a divergence there, and you need to cancel that, and then higher spin, and so on, and you get infinitely many particle types. So the assumption is that you must get rid of this divergence intrinsically. The way to do this is to assume that the $k_\mu k_\nu$ term is always hitting a conserved current. Then it's contribution vanishes.
This is what happens in massive electrodynamics. In this situation, the massive propagator is still ok for renormalizability, as noted by Schwinger and Feynman, and explained by Stueckelberg. The $k_\mu k_\nu$ is always hitting a $J^\mu$, and in x-space, it is proportional to the divergence of the current, which is zero because the current is conserved even with a massive photon (because the photon isn't charged).
The same argument works to kill the k-k part of the propagator in Yang-Mills fields, but it is much more complicated, because the Yang-Mills field itself is charged, so the local conservation law is usually expressed in a different way, etc,etc. The heuristic lesson is that spin-1 is only ok if you have a conservation law which cancels the non-shrinking part of the numerator. This requires Yang-Mills theory, and the result is also compatible with renormalizability.
If you have a spin-1 particle which is not a Yang-Mills field, you will need to reveal new structure to unitarize its longitudinal component, whose propagator is not properly shrinking at high energies.
Spin 3/2
In this case, you have a Rarita Schwinger field, and the propagator is going to grow like $\sqrt{s}$ at large energies, just from the Mandelstam argument presented before.
The propagator growth leads to unphysical growth in scattering exchanging this particle, unless the spin-3/2 field is coupled to a conserved current. The conserved current is the Supersymmetry current, by the Haag–Lopuszanski–Sohnius theorem, because it is a spinor of conserved currents.
This means that the spin-3/2 particle should interact with a spin 3/2 conserved supercurrent in order to be consistent, and the number of gravitinos is (less then or equal to) the number of supercharges.
The gravitinos are always introduced in a supermultiplet with the graviton, but I don't know if it is definitely impossible to introduce them with a spin-1 partner, and couple them to the supercurrent anyway. These spin-3/2/spin-1 multiplets will probably not be renormalizable barring some supersymmetry miracle. I haven't worked it out, but it might be possible.
Spin 2
In this case, you have a perturbative graviton-like field $h_{\mu\nu}$, and the propagator contains terms growing linearly with s.
In order to cancel the growth in the numerator, you need the tensor particle to be coupled to a conserved current to kill the parts with too-rapid growth, and produce a theory which does not require new particles for unitarity. The conserved quantity must be a tensor $T_{\mu\nu}$. Now one can appeal to the Coleman Mandula theorem and conclude that the conserved tensor current must be the stress energy tensor, and this gives general relativity, since the stress-tensor includes the stress of the h field too.
There is a second tensor conserved quantity, the angular momentum tensor $S_{\mu\nu\sigma}$, which is also spin-2 (it might look like its spin 3, but its antisymmetric on two of its indices). You can try to couple a spin-2 field to the angular momentum tensor. To see if this works requires a detailed analysis, which I haven't done, but I would guess that the result will just be a non-dynamical torsion coupled to the local spin, as required by the Einstein-Cartan theory.
Witten mentions yet another possiblity for spin 2 in chapter 1 of Green Schwarz and Witten, but I don't remember what it is, and I don't know whether it is viable.
Summary
I believe that these arguments are due to Weinberg, but I personally only read the sketchy summary of them in the first chapters of Green Schwarz and Witten. They do not seem to me to have the status of a theorem, because the argument is particle by particle, it requires independent exchange in a given regime, and it discounts the possiblity that unitary can be restored by some family of particles.
Of course, in string theory, there are fields of arbitrarily high spin, and unitarity is restored by propagating all of them together. For field theories with bound states which lie on Regge trajectories, you can have arbitrarily high spins too, so long as you consider all the trajectory contributions together, to restore unitarity (this was one of the original motivations for Regge theory--- unitarizing higher spin theories).
For example, in QCD, we have nuclei of high ground-state spin. So there are stable S-matrix states of high spin, but they come in families with other excited states of the same nuclei.
The conclusion here is that if you have higher spin particles, you can be pretty sure that you will have new particles of even higher spin at higher energies, and this chain of particles will not stop until you reveal new structure at some point. So the tensor mesons observed in the strong interaction mean that you should expect an infinite family of strongly interacting particles, petering out only when the quantum field substructure is revealed.
Some comments
James said:

It seems higher spin fields must be massless so that they have a gauge symmetry and thus a current to couple to
A massless spin-2 particle can only be a graviton.

These statements are as true as the arguments above are convincing. From the cancellation required for the propagator to become sensible, higher spin fields are fundamentally massless at short distances. The spin-1 fields become massive by the Higgs mechanism, the spin 3/2 gravitinos become massive through spontaneous SUSY breaking, and this gets rid of Goldstone bosons/Goldstinos.
But all this stuff is, at best, only at the "mildly plausible" level of argument--- the argument is over propagator unitarization with each propagator separately having no cancellations. It's actually remarkable that it works as a guideline, and that there aren't a slew of supersymmetric exceptions of higher spin theories with supersymmetry enforcing propagator cancellations and unitarization. Maybe there are, and they just haven't been discovered yet. Maybe there's a better way to state the argument which shows that unitarity can't be restored by using positive spectral-weight particles.
Big Rift in 1960s
James askes

Why wasn't this pointed out earlier in the history of string theory?

The history of physics cannot be well understood without appreciating the unbelievable antagonism between the Chew/Mandelstam/Gribov S-matrix camp, and the Weinberg/Glashow/Polyakov Field theory camp. The two sides hated each other, did not hire each other, and did not read each other, at least not in the west. The only people that straddled both camps were older folks and Russians--- Gell-Mann more than Landau (who believed the Landau pole implied S-matrix), Gribov and Migdal more than anyone else in the west other than Gell-Mann and Wilson. Wilson did his PhD in S-matrix theory, for example, as did David Gross (under Chew).
In the 1970s, S-matrix theory just plain died. All practitioners jumped ship rapidly in 1974, with the triple-whammy of Wilsonian field theory, the discovery of the Charm quark, and asymptotically freedom. These results killed S-matrix theory for thirty years. Those that jumped ship include all the original string theorists who stayed employed: notably Veneziano, who was convinced that gauge theory was right when t'Hooft showed that large-N gauge fields give the string topological expansion, and Susskind, who didn't mention Regge theory after the early 1970s. Everybody stopped studying string theory except Scherk and Schwarz, and Schwarz was protected by Gell-Mann, or else he would never have been tenured and funded.
This sorry history means that not a single S-matrix theory course is taught in the curriculum today, nobody studies it except a few theorists of advanced age hidden away in particle accelerators, and the main S-matrix theory, string-theory, is not properly explained and remains completely enigmatic even to most physicists. There were some good reasons for this--- some S-matrix people said silly things about the consistency of quantum field theory--- but to be fair, quantum field theory people said equally silly things about S-matrix theory.
Weinberg came up with these heuristic arguments in the 1960s, which convinced him that S-matrix theory was a dead end, or rather, to show that it was a tautological synonym for quantum field theory. Weinberg was motivated by models of pion-nucleon interactions, which was a hot S-matrix topic in the early 1960s. The solution to the problem is the chiral symmetry breaking models of the pion condensate, and these are effective field theories.
Building on this result, Weinberg became convinced that the only real solution to the S-matrix was a field theory of some particles with spin. He still says this every once in a while, but it is dead wrong. The most charitable interpretation is that every S-matrix has a field theory limit, where all but a finite number of particles decouple, but this is not true either (consider little string theory). String theory exists, and there are non-field theoretic S-matrices, namely all the ones in string theory, including little string theory in (5+1)d, which is non-gravitational.
Lorentz indices
James comments:

regarding spin, I tried doing the group theoretic approach to an antisymmetric tensor but got a little lost - doesn't an antisymmetric 2-form (for example) contain two spin-1 fields?

The group theory for an antisymmetric tensor is simple: it consists of an "E" and "B" field which can be turned into the pure chiral representations E+iB, E-iB. This was also called a "six-vector" sometimes, meaning E,B making an antisymmetric four-tensor.
You can do this using dotted and undotted indices more easily, if you realize that the representation theory of SU(2) is best done in indices--- see the "warm up" problem in this answer: Mathematically, what is color charge?


Question:
What can go wrong when using preconditoned Krylov methods from KSP (PETSc's linear solver package) to solve a sparse linear system such as those obtained by discretizing and linearizing partial differential equations?
What steps can I take to determine what is going wrong for my problem?
What changes can I make to successfully and efficiently solve my linear system?

Initial advice

Always run with -ksp_converged_reason -ksp_monitor_true_residual when trying to learn why a method is not converging.
Make the problem size and number of processes as small as possible to demonstrate the failure. You often gain insight by determining what small problems exhibit the behavior that is causing your method to break down and the turn-around time is reduced. Additionally, there are some investigation techniques that can only be used for small systems.
If the issue only arises after a large number of time steps, continuation steps, or nonlinear solve steps, consider writing the model state out when failure occurs so that you can experiment quickly.
Alternatively, especially if your software does not have checkpoint capability, use -ksp_view_binary or MatView() to save the linear system, then use the code at $PETSC_DIR/src/ksp/ksp/examples/tutorials/ex10.c to read in the matrix and solve it (possibly with a different number of processes). This requires an assembled matrix, so it's usefulness can be somewhat limited.
There are many possible solver choices (e.g. an infinite number available at the command line in PETSc due to an arbitrary number of levels of composition), see this question for general advice on choosing linear solvers.

Common reasons for KSP not converging

The equations are singular by accident (e.g. forgot to impose boundary conditions). Check this for a small problem using -pc_type svd -pc_svd_monitor. Also try a direct solver with -pc_type lu (via a third-party package in parallel, e.g. -pc_type lu -pc_factor_mat_solver_package superlu_dist).
The equations are intentionally singular (e.g. constant null space), but the Krylov method was not informed, see KSPSetNullSpace().
The equations are intentionally singular and KSPSetNullSpace() was used, but the right hand side is not consistent. You may have to call MatNullSpaceRemove() on the right hand side before calling KSPSolve().
The equations are indefinite so that standard preconditioners don't work. Usually you will know this from the physics, but you can check with -ksp_compute_eigenvalues -ksp_gmres_restart 1000 -pc_type none. For simple saddle point problems, try -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_detect_saddle_point. See the User's Manual and PCFIELDSPLIT man page for more details. For more difficult problems, read the literature to find robust methods and ask here (or petsc-users@mcs.anl.gov or petsc-maint@mcs.anl.gov) if you want advice about how to implement them. For example, see this question for high frequency Helmholtz. For modest problem sizes, see if you can live with just using a direct solver.
If the method converges in preconditioned residual, but not in true residual, the preconditioner is likely singular or nearly so. This is common for saddle point problems (e.g. incompressible flow) or strongly nonsymmetric operators (e.g. low-Mach hyperbolic problems with large time steps).
The preconditioner is too weak or is unstable. See if -pc_type asm -sub_pc_type lu improves the convergence rate. If GMRES is losing too much progress in the restart, see if longer restarts help -ksp_gmres_restart 300. If a transpose is available, try -ksp_type bcgs or other methods that do not require a restart. (Note that convergence with these methods is frequently erratic.)
The preconditioning matrix may not be close to the (possibly unassembled) operator. Try solving with a direct solver, either in serial with -pc_type lu or in parallel using a third-party package (e.g. -pc_type lu -pc_factor_mat_solver_package superlu_dist, or mumps). The method should converge in one iteration if the matrices are the same, and in a "small" number of iterations otherwise. Try -snes_type test to check the matrices if solving a nonlinear problem.
The preconditioner is nonlinear (e.g. a nested iterative solve), try -ksp_type fgmres or -ksp_type gcr.
You are using geometric multigrid, but some equations (often boundary conditions) are not scaled compatibly between levels. Try -pc_mg_galerkin to algebraically construct a correctly scaled coarse operator or make sure that all the equations are scaled in the same way if you want to use rediscretized coarse levels.
The matrix is very ill-conditioned. Check the condition number using the methods described here.
Try to improve it by choosing the relative scaling of components/boundary conditions.
Try -ksp_diagonal_scale -ksp_diagonal_scale_fix.
Perhaps change the formulation of the problem to produce more friendly algebraic equations. If you cannot correct the scaling, you may need to use a direct solver.
The matrix is nonlinear (e.g. evaluated using finite differencing of a nonlinear function). Try different differencing parameters (e.g. -mat_mffd_type ds). Try using higher precision to make the differencing more accurate, ./configure --with-precision=__float128 --download-f2cblaslapack. Check if it converges in "easier" parameter regimes.
A symmetric method is being used for a non-symmetric problem.
Classical Gram-Schmidt is becoming unstable, try -ksp_gmres_modifiedgramschmidt or use a method that orthogonalizes differently, e.g. -ksp_type gcr.


Question:
I work in computational science, and as a result, I spend a non-trivial amount of my time trying to increase the scientific throughput of many codes, as well as understanding the efficiency of these codes.
Let's assume I have evaluated the performance vs. readability/reusability/maintainability tradeoff of the software I am working on, and I have decided that it's time to go for performance.  Let's also assume that I know I don't have a better algorithm for my problem (in terms of flop/s and memory bandwidth).  You can also assume my code base is in a low-level language like C, C++, or Fortran.  Finally, let's assume that there is no parallelism to be had in the code, or that we're only interested in performance on a single core.
What are the most important things to try first?  How do I know how much performance I can get?

First of all, as skillman and Dan have pointed out, profiling is essential. I personally use Intel's VTune Amplifier on Linux as it gives me a very fine-grained overview of where time was spent doing what.
If you're not going to change the algorithm (i.e. if there will be no major changes that will turn all your optimizations obsolete), then I'd suggest looking for some common implementation details that can make a big difference:

Memory locality: is data that is read/used together also stored together, or are you picking up bits and pieces here and there?
Memory alignment: are your doubles actually aligned to 4 bytes? How did you pack your structs? To be pedantic, use posix_memalign instead of malloc.
Cache efficiency: Locality takes care of most cache efficiency issues, but if you have some small data structures that you read/write often, it helps if they are an integer multiple or fraction of a cache line (usually 64 bytes). It also helps if your data is aligned to the size of a cache line. This can drastically reduce the number of reads necessary to load a piece of data.
Vectorization: No, don't go mental with hand-coded assembler. gcc offers vector types that get translated to SSE/AltiVec/whatever instructions automagically.
Instruction-Level Parallelism: The bastard son of vectorization. If some often-repeated computation does not vectorize well, you can try accumulating input values and computing several values at once. It's kind of like loop unrolling. What you're exploiting here is that your CPU will usually have more than one floating-point unit per core.
Arithmetic precision: Do you really need double-precision arithmetic in everything you do? E.g. if you're computing a correction in a Newton iteration, you usually don't need all the digits you're computing. For a more in-depth discussion, see this paper.

Some of these tricks are used in the daxpy_cvec this thread. Having said that, if you're using Fortran (not a low-level language in my books), you will have very little control over most of these "tricks".
If you're running on some dedicated hardware, e.g. a cluster you use for all your production runs, you may also want to read-up on the specifics of the CPUs used. Not that you should write stuff in assembler directly for that architecture, but it might inspire you to find some other optimizations that you may have missed. Knowing about a feature is a necessary first step to writing code that can exploit it.
Update
It's been a while since I wrote this and I hadn't noticed that it had become such a popular answer. For this reason, I'd like to add one important point:

Talk to your local Computer Scientist: Wouldn't it be cool if there were a discipline which dealt exclusively with making algorithms and/or computations more efficient/elegant/parallel, and we could all go ask them for advice? Well, good news, that discipline exists: Computer Science. Chances are, your institution even has a whole department dedicated to it. Talk to these guys.

I'm sure to a number of non-Computer Scientists this will bring back memories of frustrating discussions with said discipline that led to nothing, or memories of other people's anecdotes thereof. Don't be discouraged. Interdisciplinary collaboration is a tricky thing, and it takes a bit of work, but the rewards can be massive.
In my experience, as a Computer Scientist (CS), the trick is in getting both the expectations and the communication right.
Expectation-wise, a CS will only help you if he/she thinks your problem is interesting. This pretty much excludes trying to optimize/vectorize/parallelize a piece of code you've written, but not really commented, for a problem they don't understand. CSs are usually more interested in the underlying problem, e.g. the algorithms used to solve it. Don't give them your solution, give them your problem.
Also, be prepared for the CS to say "this problem has already been solved", and just give you a reference to a paper. A word of advice: Read that paper and, if it really does apply to your problem, implement whatever algorithm it suggests. This is not a CS being smug, it's a CS that just helped you. Don't be offended, remember: If the problem is not computationally interesting, i.e. it has already been solved and the solution shown to be optimal, they won't work on it, much less code it up for you.
Communication-wise, remember that most CSs are not experts in your field, and explain the problem in terms of what you are doing, as opposed to how and why. We usually really don't care about the why, and the how is, well, what we do best.
For example, I'm currently working with a bunch of Computational Cosmologists on writing a better version of their simulation code, based on SPH and Multipoles. It took about three meetings to stop talking in terms of dark matter and galaxy haloes (huh?) and to drill down to the core of the computation, i.e. that they need to find all the neighbours within a given radius of each particle, compute some quantity over them, and then run over all said neighbours again and apply that quantity in some other computation. Then move the particles, or at least some of them, and do it all again. You see, while the former may be incredibly interesting (it is!), the latter is what I need to understand to start thinking about algorithms.
But I'm diverging from the main point: If you're really interested in making your computation fast, and you're not a Computer Scientist yourself, go talk to one.


Question: What is the difference between a matrix and a tensor? Or, what makes a tensor, a tensor? I know that a matrix is a table of values, right? But, a tensor?

Maybe to see the difference between rank 2 tensors and matrices, it is probably best to see a concrete example. Actually this is something which back then confused me very much in the linear algebra course (where we didn't learn about tensors, only about matrices).
As you may know, you can specify a linear transformation $a$ between vectors by a matrix. Let's call that matrix $A$. Now if you do a basis transformation, this can also be written as a linear transformation, so that if the vector in the old basis is $v$, the vector in the new basis is $T^{-1}v$ (where $v$ is a column vector). Now you can ask what matrix describes the transformation $a$ in the new basis. Well, it's the matrix $T^{-1}AT$.
Well, so far, so good. What I memorized back then is that under basis change a matrix transforms as $T^{-1}AT$.
But then, we learned about quadratic forms. Those are calculated using a matrix $A$ as $u^TAv$. Still, no problem, until we learned about how to do basis changes. Now, suddenly the matrix did not transform as $T^{-1}AT$, but rather as $T^TAT$. Which confused me like hell: how could one and the same object transform differently when used in different contexts?
Well, the solution is: because we are actually talking about different objects! In the first case, we are talking about a tensor that takes vectors to vectors. In the second case, we are talking about a tensor that takes two vectors into a scalar, or equivalently, which takes a vector to a covector.
Now both tensors have $n^2$ components, and therefore it is possible to write those components in a $n\times n$ matrix. And since all operations are either linear or bilinear, the normal matrix-matrix and matrix-vector products together with transposition can be used to write the operations of the tensor. Only when looking at basis transformations, you see that both are, indeed, not the same, and the course did us (well, at least me) a disservice by not telling us that we are really looking at two different objects, and not just at two different uses of the same object, the matrix.
Indeed, speaking of a rank-2 tensor is not really accurate. The rank of a tensor has to be given by two numbers. The vector to vector mapping is given by a rank-(1,1) tensor, while the quadratic form is given by a rank-(0,2) tensor. There's also the type (2,0) which also corresponds to a matrix, but which maps two covectors to a number, and which again transforms differently.
The bottom line of this is:

The components of a rank-2 tensor can be written in a matrix.
The tensor is not that matrix, because different types of tensors can correspond to the same matrix.
The differences between those tensor types are uncovered by the basis transformations (hence the physicist's definition: "A tensor is what transforms like a tensor").

Of course, another difference between matrices and tensors is that matrices are by definition two-index objects, while tensors can have any rank.


Question:
In a book of word problems by V.I Arnold, the following appears:

The hypotenuse of a right-angled  triangle  (in  a  standard  American  examination) is $10$ inches, the altitude dropped onto it is 6 inches. Find the area of the triangle.
American school students had been coping successfully with this problem for over a decade. But then Russian school students arrived from Moscow, and none of them was able to solve it as had their American peers (giving $30$ square inches as the answer). Why?

Here's the book. I assume the answer is some joke at the expense of the Americans, but I don't get it. Possibly a joke about inches? Anyone?

There is no such right triangle. The maximum possible altitude is half the hypotenuse (inscribe the triangle into a circle to see this), which here is $5$ inches. You would only get $30$ square inches if you tried to compute the area without checking whether the triangle actually exists.


Question: I know that bit-wise operations are so fast on modern processors, because they can operate on 32 or 64 bits on parallel, so bit-wise operations take only one clock cycle. However addition is a complex operation that consists of at least one and possibly up to a dozen bit-wise operations, so I naturally thought it will be 3-4 times slower. I was surprised to see after a simple benchmark that addition is exactly as fast as any of the bit-wise operations(XOR, OR, AND etc). Can anyone shed light on this?

Addition is fast because CPU designers have put in the circuitry needed to make it fast.  It does take significantly more gates than bitwise operations, but it is frequent enough that CPU designers have judged it to be worth it.  See
Both can be made fast enough to execute within a single CPU cycle.  They're not equally fast -- addition requires more gates and more latency than a bitwise operation -- but it's fast enough that a processor can do it in one clock cycle.  There is a per-instruction latency overhead for the instruction decoding and control logic, and the latency for that is significantly larger than the latency to do a bitwise operation, so the difference between the two gets swamped by that overhead.  AProgrammer's answer and Paul92's answer explain those effects well.


Question: I read in some places that music is mostly sampled at 44.1 kHz whereas we can only hear up to 20 kHz. Why is it?

The sampling rate of a real signal needs to be greater than twice the signal bandwidth. Audio practically starts at 0 Hz, so the highest frequency present in audio recorded at 44.1 kHz is 22.05 kHz (22.05 kHz bandwidth).
Perfect brickwall filters are mathematically impossible, so we can't just perfectly cut off frequencies above 20 kHz.  The extra 2 kHz is for the roll-off of the filters; it's "wiggle room" in which the audio can alias due to imperfect filters, but we can't hear it.
The specific value of 44.1 kHz was compatible with both PAL and NTSC video frame rates used at the time.

Note that the rationale is published in many places: Wikipedia: Why 44.1 kHz?


Question:
I'm not sure where this question should go, but I think this site is as good as any.
When humankind started out, all we had was sticks and stones. Today we have electron microscopes, gigapixel cameras and atomic clocks. These instruments are many orders of magnitude more precise than what we started out with and they required other precision instruments in their making. But how did we get here? The way I understand it, errors only accumulate. The more you measure things and add or multiply those measurements, the greater your errors will become. And if you have a novel precision tool and it's the first one of its kind - then there's nothing to calibrate it against.
So how it is possible that the precision of humanity's tools keeps increasing?

I work with an old toolmaker who also worked as a metrologist who goes on about this all day.
It seems to boil down to exploiting symmetries since the only way you can really check something is against itself.
Squareness:
For example, you can check a square by aligning one edge to the center of straight edge and tracing a right angle, then flip it over, re-align to the straight edge while also trying to align to the traced edge as best you can. Then trace it out again. They should overlap if the square is truly square. If it's not, there will be an angular deviation. The longer the arms, the more evident smaller errors will be and you can measure the linear deviation at the ends relative to the length of the arms to quantify squareness.
Other Angles:
A lot of other angles can be treated as integer divisions of 90 degree angle which you obtained via symmetry. For example, you know two 45 degrees should perfectly fill 90 degrees so you can trace out a 45 degree angle and move it around to make it sure it perfectly fills the remaining half. Or split 90 degrees into two and compare the two halves to make sure they match. You can also use knowledge of geometry and form a triangle using fixed lengths with particular ratios to obtain angles, such as the 3-4-5 triangle.
Flat Surfaces:
Similarly, you can produce flat surfaces by lapping two surfaces against each other and if you do it properly (it actually requires three surfaces and is known as the 3-plate method), the high points wear away first leaving two surfaces which must be symmetrical, aka flat. In this way, flat-surfaces have a self-referencing method of manufacture. This is supremely important because, as far as I know, they are the only things that do.
I started talking about squares first since the symmetry is easier to describe for them, but it is the flatness of surface plates and their self-referencing manufacture that allow you to begin making the physical tools to actually apply the concept of symmetries to make the other measurements. You need straight edges to make squares and you can't make (or at least, check) straight edges without flat surface plates, nor can you check if something is round...
"Roundness":
After you've produced your surface plate, straight edges,and squares using the methods above, then you can check how round something is by rolling it along a surface plate and using a gauge block or indicator to check how much the height varies as it rolls.

EDIT: As mentioned by a commenter, this only checks diameter and you can have non-circular lobed shapes (such as those made in centerless grinding and can be nearly imperceptibly non-circular) where the diameter is constant but the radius is not. Checking roundness via radius requires a lot more parts. Basically enough to make a lathe and indicators so you can mount the centers and turn it while directly measuring the radius. You can also place it in V-blocks on a surface-plate and measure but the V-block needs to be the correct angle relative to the number of lobes so they seat properly or the measurement will miss them. Fortunately lathes are rather basic and simple machinery and make circular shapes to begin with. You don't encounter lobed shapes until you have more advanced machinery like centerless grinders.
I suppose you could also place it vertically on a turntable if it has a flat squared end and indicate it and slide it around as you turn it to see if you can't find a location where the radius measures constant all the way around.

Parallel:
You might have asked yourself "Why do you need a square to measure roundness above?" The answer is that squares don't just let you check if something is square. They also let you check indirectly check the opposite: whether something is parallel. You need the square to make sure the the gauge block's top and bottom surfaces are parallel to each other so that you can place the gauge block onto the surface plate, then place a straight edge onto the gauge block such that the straight edge runs parallel to the surface plate. Only then can you measure the height of the workpiece as it, hopefully, rolls. Incidentally, this also requires the straight edge to be square which you can't know without having a square.
More On Squareness:
You can also now measure squareness of a physical object by placing it on a surface plate, and fixing a straight edge with square sides to the side of the workpiece such that the straight edge extends horizontally away from the workpiece and cantilevers over the surface plate. You then measure the difference in height for which the straight edge sits above the surface plate at both ends. The longer the straight edge, the more resolution you have, so long as sagging doesn't become an issue.

From these basic measurements (square, round, flat/straight), you get all the other mechanical measurements. The inherent symmetries which enable self-checking are what makes "straight", "flat", "round", and "square" special. It's why we use these properties and not random arcs, polygons, or angles as references when calibrating stuff.

Actually making stuff rather than just measuring:
Up until now I mainly talked about measurement. The only manufacturing I spoke about was the surface plate and its very important self-referencing nature which allows it to make itself. That's because so long as you have a way to make that first reference from which other references derive, you can very painstakingly free-hand workpieces and keep measuring until you get it straight, round or square. After which you can use the result to more easily make other things.
Just think about free-hand filing a round AND straight hole in a wood wagon wheel, and then free-hand filing a round AND straight axle. It makes my brain glaze over too. It'd also be a waste since you would be much better off doing that for parts of a lathe which could be used to make more lathes and wagon wheels.
It's tough enough to file a piece of steel into a square cube with file that is actually straight, let alone a not-so-straight file which they probably didn't always have in the past. But so long as you have a square to check it with, you just keep correcting it until you get it. It is apparently a common apprentice toolmaker task to teach one how to use a file.
Spheres:
To make a sphere you can start with a stick fixed at one end to draw an arc. Then you put some stock onto a lathe and then lathe out that arc. Then you take that work piece and turn it 90 degrees and put it back in the lathe using a special fixture and then lathe out another arc. That gives you a sphere-like thing.
I don't know how sphericity is measured especially when lobed shapes exist (maybe you seat them in a ring like the end of a hollow tube and measure?). Or how really accurate spheres, especially gauge spheres, are made. It's secret, apparently.
EDIT: Someone mentioned putting molten material into freefall and allow surface tension to pull it into a sphere and have it cool on the way down. Would work for low tech production of smaller spheres production and if you could control material volume as it was dropped you can control size. Still not sure how precisely manufactured spheres are made though or how they are ground. There doesn't seem to be an obvious way to use spheres to make more spheres unlike the other things.


Question:
I am looking for a tool to visualize very large directional link graphs.
I currently have ~2million nodes with ~10million edges. I have tried a few different things, but most take hours to even do 100k node graphs
What I have tried:
I spent a day with gephi, but 80K nodes take about an hour to add and the application becomes mostly useless.
Any suggestions?
An interactive visualization would be a plus.

Graphviz should work. I believe that the images associated with the matrices in the University of Florida sparse matrix collection were visualized using sfdp, a force-directed graph visualization algorithm developed by Yifan Hu. Most of the matrices in the collection have a computational time associated with generating a corresponding visualization, so you might be able to search for matrices whose graphs have characteristics similar to the ones you wish to visualize. For instance, a graph with ~2.1 million nodes and ~3 million edges took Hu ~36000s to generate, or 10 hours. While it's not clear what hardware was used to generate the graph, it's probably a reasonable guess that a desktop or laptop was used, and the times would at least give you a rough idea of how much time rendering the graph may take. Hu's algorithm appears to be one of the state-of-the-art visualization algorithms (he published it in 2005), but not being an expert in the field, I can't speak to whether or not better algorithms exist. This algorithm is included with Graphviz as an option, and is designed to be used on large graphs such as the one you describe.


Question: Bit of a strange question, but what is it? My physics teacher said it was kind of like a "push" that pushes electrons around the circuit. Can I have a more complex explanation? Any help is much appreciated.

Your teacher was right.
Current is electric charges (usually electrons) moving.  They don't do that by themselves for no reason, no more so than a shopping cart moves across the floor of a store by itself.  In physics, we call the force that pushes charges the electromotive force, or "EMF".  It is almost always expressed in units of volts, so we usually take little shortcut and say "voltage" most of the time.  Technically EMF is the physical quantity and volts is one unit it can be quantified in.
EMF can be generated several ways:
Electromagnetic.  When a conductor (like a wire) is moved sideways thru a magnetic field, there will be a voltage generated along the length of the wire.  Electric generators like in power plants and the alternator in your car work on this principle.
Electrochemical.  A chemical reaction can cause a voltage difference.  Batteries work on this principle.
Photovoltaic.  Crash photons into a semiconductor diode at the right place and you get a voltage.  This is how solar cells work.
Electrostatic.  Rub two of the right kind of materials together and one sheds electrons onto the other.  Two material that exhibit this phenomenon well are a plastic comb and a cat.  This is what happens when you shuffle across the right kind of carpet and then get a zap when you touch a metal object.  Rubbing a balloon against your shirt does this, which then allows the balloon to "stick" to something else.  In that case the EMF can't make the electrons move, but it still pulls on them, which then in turn pull on the baloon they are stuck on.
This effect can be scaled up to make vary high voltages and is the basis for how Van de Graaff generators work.
Thermo-electric.  A temperature gradient along most conductors causes a voltage.  This is called the Siebeck effect.  Unfortunately you can't harness that because to use this voltage there is eventually a closed loop.  Any voltage gained by a temperature rise in part of the loop is then offset by a temperature decrease in another part of the loop.  The trick is to use two different materials that exhibit a different voltage as a result of the same temperature gradient (different Siebeck coefficient).  Use one material going out to a heat source and a different coming back, and you do get a net voltage you can use at the same temperature.
The total voltage you get from one out and back, even with a high temperature difference is pretty small.  By putting many of these out and back combinations together, you can get a useful voltage.  A single out and back is called a thermocouple, and can be used to sense temperature.  Many together is a thermocouple generator.  Yes, those actually exist.  There have been spacecraft powered on this principle with the heat source coming from the decay of a radio-isotope.
Thermionic.  If you heat something high enough (100s of °C), then the electrons on its surface move so fast that sometimes they fly off.  If they have a place to land that is colder (so they won't fly off again from there), you have a thermionic generator.  This may sound far fetched, but there have also been spacecraft powered from this principle with the heat source again being radio-isotope decay.
Electron tubes use this principle in part.  Instead of heating something so that electrons fly off on their own, you can heat it to almost that point so that they fly off when a little extra voltage is applied.  This is the basis of the vacuum tube diode and important to most vacuum tubes.  This is why these tubes had heaters and you could see them glow.  It takes glowing temperatures to get to where the thermionic effect is significant.
Piezo-electric.  Certain materials (quartz crystal for example) generate a voltage when you squeeze them.  Some microphones work on this principle.  The varying pressure waves in the air we call sound squish and squash a quartz crystal alternately, which causes it to make tiny voltage waves as a result.  We can amplify them to eventually make signals you can record, drive loudspeakers with so you can hear them, etc.
This principle is also used in many barbecue grill igniters.  A spring mechanism whacks a quartz crystal pretty hard so that it makes enough of a voltage to cause a spark.


Question:
The pH of pure liquid water depends on temperature. It is about pH = 7.0 at room temperature, pH = 6.1 at 100 °C, and pH = 7.5 at 0 °C. What happens to the pH (or to the ion product) of pure water when it freezes?
I assume that the proton transfer reactions
$$\ce{2H2O <=> H3O+ + OH-}$$
$$\ce{H3O+ + H2O <=> H2O + H3O+}$$
$$\ce{H2O + OH- <=> OH- + H2O}$$
are too fast, so that any present $\ce{H3O+}$ and $\ce{OH-}$ cannot be easily trapped in the solid ice crystal when it grows. Does that mean that pure ice crystals are free of $\ce{H3O+}$ and $\ce{OH-}$ ions?

According to Martin Chaplin's Water Dissociation and pH:

In ice, where the local hydrogen bonding rarely breaks to separate the constantly forming and re-associating ions, the dissociation constant is much lower (for example at $-4~\mathrm{^\circ C}$, $K_\mathrm{w} = 2 \times 10^{-20}~\mathrm{mol^2~L^{-2}}$).

So $[\ce{H+}] = 1.4 \times 10^{-10}~\mathrm{mol\ L^{-1}} \Longrightarrow \mathrm{p[\ce{H+}]} = 9.9$
For more information see Self-Dissociation and Protonic Charge Transport in Water and Ice Proceedings of the Royal Society of London. Series A, Mathematical and Physical Sciences Vol. 247, No. 1251 (Oct. 21, 1958), pp. 505-533
This is a review article by Nobel Prize winner Manfred Eigen , after whom hydrated $\ce{H3O+}$ is sometimes referred to as the Eigen Ion.


Question:
Does there exist a set of programming language constructs in a programming language in order for it to be considered Turing Complete?
From what I can tell from wikipedia, the language needs to support recursion, or, seemingly, must be able to run without halting. Is this all there is to it?

I always though that $\mu$-recursive functions nailed it. Here is what defines the whole set of computable functions; it is the smallest set of functions containing resp. closed against:

The constant $0$ function
The successor function
Selecting parameters
Function composition
Primitive Recursion
The $\mu$-operator (look for the smallest $x$ such that...)

Check above link for details; you see that it makes for a very compact programming language. It is also horrible to program in -- no free lunch. If you drop any of those, you will lose full power, so it is a minimal set of axioms.
You can translate those quite literally into basic syntactical elements for WHILE programs, namely

The constant 0
Incrementation _ + 1
Variable access x
Program/statement concatenation _; _
Countdown loops for ( x to 0 ) do _ end
While loops while ( x != 0 ) do _ end


Question:
Reading discussions of the recent quantum supremacy experiment by Google I noticed that a lot of time and effort (in the experiment itself, but also in the excellent blog posts by Scott Aaronson and others explaining the results) is spent on verifying that the quantum computer did indeed compute the thing we believe it to have computed.
From a naive point of view this is completely understandable: the essence of any quantum supremacy experiment is that you have the quantum computer perform a task that is hard for a classical computer to achieve, so surely it would also be hard for the classical computer to verify that the quantum computer did complete the task we gave it, right?
Well, no. About the first thing you learn when starting to read blogs or talk to people about computational complexity is that, counter-intuitive as it may seem, there exist problems that are hard to solve, but for which it is easy to verify the validity of a given solution: the so called NP problems.
Thus it seems that Google could have saved themselves and others a lot of time by using one of these problems for their quantum supremacy experiment rather than the one they did. So my question is why didn't they?
An answer for the special case of the NP problem factoring is given in this very nice answer to a different question:  Paraphrasing: the regime where the quantum algorithm starts to out perform the best known classical algorithm starts at a point that requires more than the 53 qubits currently available.
So my follow-up question is: does this answer for the special case extend to all NP-problems where quantum speedups are expected or is it specific to factoring? And in the first case: is there a fundamental reason related to the nature of NP that quantum-supremacy 'kicks in later' for NP problems than for sampling problems or is it just that for NP problems better classical algorithms are available due to their being more famous?

there exist problems that are hard to solve, but for which it is easy to verify the validity of a given solution: the so called NP problems.

This statement is wrong. There are many NP problems which are easy to solve. "NP" simply means "easy to verify". It does not mean hard to solve.
What you are probably thinking of is NP-complete problems which is a subset of the NP problems for which we have very, very good evidence to think they are hard. However, quantum computers are not expected to be able to solve NP-complete problems significantly more "easily" than regular computers.
Factoring is also thought to be hard, but the evidence for this is only "very good" and not "very, very good" (in other words: factoring is likely not NP-complete). Factoring is one of very few natural problems which falls in between not being NP-complete and not being easy.
The list of problems that we know that are easy to verify, easy to solve on a quantum computer but hard classicly, is even shorter. In fact, I do not know of any problem other than factoring (and the very closely related discrete logarithm problem) with this property.
Moreover, any easy to verify problem would likely have the same issue as factoring: $53$ qubits is not that many, and $2^{53}$ is huge, but just within reach of classical computing. $2^{53}$ less than $10^{16}$, and most classical computers can execute on the order of $10^9$ operations per second. We could run through all possibilities in about $1/3$rd of a year on a single classical desktop computer.
Quantum computers have very few applications which they're known to be good at, and are essentially useless for most hard NP problems.


Question:
simulate this circuit – Schematic created using CircuitLab
My physics teacher said that the current through the resistor is 4A because each battery has a current of 2A if hooked up to the resistor on its own, and so they both have 2A of current through them so the resistor has 4A total through it because of the junction rule (this was the explanation she gave when I asked her why the total current wasn't 2A), however that isn't true because the current through the resistor is 2A when the voltage is 80 (these batteries are in parallel), and so there is 1A through each battery. How should I explain that her logic doesn't work, as current does not double when you add another battery?
Edit:
Her response to me when I asked about ohm's law: each battery provides 2A of current on its own, so they combine because apparently, you can treat each loop separately, so then by the junction rule, the 2A currents join to become 4A.

Just ask her what the voltage across the resistor is


Question:
Over on the TeX stackexchange, we have been discussing how to detect "rivers" in paragraphs in this question.
In this context, rivers are bands of white space that result from accidental alignment of interword spaces in the text. Since this can be quite distracting to a reader bad rivers are considered to be a symptom of poor typography. An example of text with rivers is this one, where there are two rivers flowing diagonally.

There is interest in detecting these rivers automatically, so that they can be avoided (probably by manual editing of the text). Raphink is making some progress at the TeX level (which only knows of glyph positions and bounding boxes), but I feel confident that the best way to detect rivers is with some image processing (since glyph shapes are very important and not available to TeX). I have tried various ways to extract the rivers from the above image, but my simple idea of applying a small amount of ellipsoidal blurring doesn't seem to be good enough. I also tried some Radon Hough transform based filtering, but I didn't get anywhere with those either. The rivers are very visible to the feature-detection circuits of the human eye/retina/brain and somehow I would think this could be translated to some kind of filtering operation, but I am not able to make it work. Any ideas?
To be specific, I'm looking for some operation that will detect the 2 rivers in the above image, but not have too many other false positive detections.
EDIT: endolith asked why I am pursuing a image-processing-based approach given that in TeX we have access to the glyph positions, spacings, etc, and it might be much faster and more reliable to use an algorithm that examines the actual text. My reason for doing things the other way is that the shape of the glyphs can affect how noticeable a river is, and at the text level it is very difficult to consider this shape (which depends on the font, on ligaturing, etc). For an example of how the shape of the glyphs can be important, consider the following two examples, where the difference between them is that I have replaced a few glyphs with others of almost the same width, so that a text-based analysis would consider them equally good/bad. Note, however, that the rivers in the first example are much worse than in the second.

I have thought about this some more, and think that the following should be fairly stable. Note that I have limited myself to morphological operations, because these should be available in any standard image processing library.
(1) Open image with a nPix-by-1 mask, where nPix is about the vertical distance between letters
#% read image
img = rgb2gray('

%# threshold and open with a rectangle
%# that is roughly letter sized
bwImg = img > 200; %# threshold of 200 is better than 128

opImg = imopen(bwImg,ones(13,1));

(2) Open image with a 1-by-mPix mask to eliminate whatever is too narrow to be a river.
opImg = imopen(opImg,ones(1,5));

(3) Remove horizontal "rivers and lakes" that are due to space between paragraphs, or indentation. For this, we remove all rows that are all true, and open with the nPix-by-1 mask that we know will not affect the rivers we have found previously.
To remove lakes, we can use an opening mask that is slightly larger than nPix-by-nPix.
At this step, we can also throw out everything that is too small to be a real river, i.e. everything that covers less area than (nPix+2)*(mPix+2)*4 (that will give us ~3 lines). The +2 is there because we know that all objects are at least nPix in height, and mPix in width, and we want to go a little above that.
%# horizontal river: just look for rows that are all true
opImg(all(opImg,2),:) = false;
%# open with line spacing (nPix)
opImg = imopen(opImg,ones(13,1));

%# remove lakes with nPix+2
opImg = opImg & ~imopen(opImg,ones(15,15));

%# remove small fry
opImg = bwareaopen(opImg,7*15*4);

(4) If we're interested in not only the length, but also the width of the river, we can combine distance transform with skeleton.
   dt = bwdist(~opImg);
   sk = bwmorph(opImg,'skel',inf);
   %# prune the skeleton a bit to remove branches
   sk = bwmorph(sk,'spur',7);

   riversWithWidth = dt.*sk;

(colors correspond to width of river (though color bar is off by a factor of 2)
Now you can get the approximate length of the rivers by counting the number of pixels in each connected component, and the average width by averaging their pixel values.

Here's the exact same analysis applied to the second, "no-river" image:


Question:
Thanks to everyone who posted comments/answers to my query yesterday (Implementing a Kalman filter for position, velocity, acceleration ).  I've been looking at what was recommended, and in particular at both (a) the wikipedia example on one dimensional position and velocity and also another website that considers a similar thing.
Update 26-Apr-2013: the original question here contained some errors, related to the fact that I hadn't properly understood the the wikipedia example on one dimensional position and velocity.  With my improved understanding of what's going on, I've now redrafted the question and focused it more tightly.
Both examples that I refer to in the introductory paragraph above assume that it's only position that's measured.  However, neither example has any kind of calculation $(x_k-x_{k-1})/dt$ for speed.  For example, the Wikipedia example specifies the ${\bf H}$ matrix as ${\bf H} = [1\ \ \  0]$, which means that only position is input.  Focussing on the Wikipedia example, the state vector ${\bf x}_k$ of the Kalman filter contains position $x_k$and speed $\dot{x}_{k}$, i.e.
$$
\begin{align*}
\mathbf{x}_{k}  & =\left(\begin{array}[c]{c}x_{k}\\
\dot{x}_{k}\end{array}
\right)
\end{align*}
$$
Suppose the measurement of position at time $k$ is $\hat{x}_k$.  Then if the position and speed at time $k-1$ were $x_{k-1}$ and $\dot{x}_{k-1}$, and if $a$ is a constant acceleration that applies in the time interval $k-1$ to $k$, from the measurement of $\hat{x}$ it's possible to deduce a value for $a$ using the formula
$$
\hat{x}_k = x_{k-1} + \dot{x}_{k-1} dt + \frac{1}{2} a dt^2
$$
This implies that at time $k$, a measurement $\hat{\dot{x}}_k$ of the speed is given by
$$
\hat{\dot{x}}_k = \dot{x}_{k-1} + a dt = 2 \frac{\hat{x}_k - {x}_{k-1}}{dt} - \dot{x}_{k-1}
$$
All the quantities on the right hand side of that equation (i.e. $\hat{x}_k$, $x_{k-1}$ and $\dot{x}_{k-1}$) are normally distributed random variables with known means and standard deviations, so the $\bf R$ matrix for the measurement vector
$$
\begin{align*}
\mathbf{\hat{x}}_{k}  & =\left(\begin{array}[c]{c}\hat{x}_{k}\\
\hat{\dot{x}}_{k}\end{array}
\right)
\end{align*}
$$
can be calculated.  Is this a valid way of introducing speed estimates into the process?

Is this a valid way of introducing speed estimates into the process?

If you choose your state appropriately, then the speed estimates come "for free". See the derivation of the signal model below (for the simple 1-D case we've been looking at).
Signal Model, Take 2
So, we really need to agree on a signal model before we can move this forward.  From your edit, it looks like your model of the position, $x_k$, is:
$$
\begin{array}
xx_{k+1} &=& x_{k} + \dot{x}_{k} \Delta t + \frac{1}{2} a (\Delta t)^2\\
\dot{x}_{k+1} &=& \dot{x}_{k} + a \Delta t
\end{array}
$$
If our state is as before:
$$
\begin{align*}
\mathbf{x}_{k}  & =\left(\begin{array}[c]{c}x_{k}\\
\dot{x}_{k}\end{array}
\right)
\end{align*}
$$
then the state update equation is just:
$$
\mathbf{x}_{k+1} =
\left(\begin{array}[c]{c} 1\ \ \Delta t\\
0\ \ 1\end{array}
\right)
\mathbf{x}_{k} +
\left(\begin{array}[c]{c} \frac{(\Delta t)^2}{2} \\
\Delta t \end{array}
\right)
a_k
$$
where now our $a_k$ is the normally distributed acceleration.
That gives different $\mathbf{G}$ matrix from the previous version, but the $\mathbf{F}$ and $\mathbf{H}$ matrices should be the same.

If I implement this in scilab (sorry, no access to matlab), it looks like:
// Signal Model
DeltaT = 0.1;
F = [1 DeltaT; 0 1];
G = [DeltaT^2/2; DeltaT];
H = [1 0];

x0 = [0;0];
sigma_a = 0.1;

Q = sigma_a^2;
R = 0.1;

N = 1000;

a = rand(1,N,"normal")*sigma_a;

x_truth(:,1) = x0;
for t=1:N,
    x_truth(:,t+1) = F*x_truth(:,t) + G*a(t);
    y(t) = H*x_truth(:,t) + rand(1,1,"normal")*sqrt(R);
end

Then, I can apply the Kalman filter equations to this $y$ (the noisy measurements).
// Kalman Filter
p0 = 100*eye(2,2);

xx(:,1) = x0;
pp = p0;
pp_norm(1) = norm(pp);
for t=1:N,
    [x1,p1,x,p] = kalm(y(t),xx(:,t),pp,F,G,H,Q,R);
    xx(:,t+1) = x1;
    pp = p1;
    pp_norm(t+1) = norm(pp);
end

So we have our noisy measurements $y$, and we've applied the Kalman filter to them and used the same signal model to generate $y$ as we do to apply the Kalman filter (a pretty big assumption, sometimes!).
Then following plots show the result.
Plot 1: $y$ and $x_k$ versus time.

Plot 2: A zoomed view of the first few samples:

Plot 3: Something you never get in real life, the true position vs the state estimate of the position.

Plot 4: Something you also never get in real life, the true velocity vs the state estimate of the velocity.

Plot 5: The norm of the state covariance matrix (something you should always monitor in real life!).  Note that it very quickly goes from its initial very large value to something very small, so I've only shown the first few samples.

Plot 6: Plots of the error between the true position and velocity and their estimates.

If you study the case where the position measurements are exact, then you find that the Kalman udpate equations produce exact results for BOTH position and speed.  Mathematically it's straightforward to see why.  Using the same notation as the wikipedia article, exact measurements mean that $\mathbf{z}_{k+1}=x_{k+1}$. If you assume that the initial position and speed are known so that $\mathbf{P}_k=0$, then $\mathbf{P}_{k+1}^{-}=\mathbf{Q}$ and the Kalman gain matrix $\mathbf{K}_{k+1}$ is given by
$$
\mathbf{K}_{k+1} = \left(\begin{array}[c]{c}1\\
2/dt\end{array}
\right)
$$
This means that the Kalman update procedure produces
$$
\begin{align*}
\mathbf{\hat{x}}_{k+1} & = \mathbf{F}_{k+1}\mathbf{x}_k + \mathbf{K}_{k+1}\left(\mathbf{z}_{k+1} - \mathbf{H}_{k+1} \mathbf{F}_{k+1}\mathbf{x}_k\right)\\
& = \left(\begin{array}[c]{c}x_k + \dot{x}_k dt\\
\dot{x}_k\end{array}
\right) +
\left(\begin{array}[c]{c}1\\
2/dt\end{array}
\right)
\left(x_{k+1} - \left( x_k + \dot{x}_k dt\right)
\right)\\
& = \left(\begin{array}[c]{c}x_{k+1}\\
 2 \left(x_{k+1} - x_k \right) /dt - \dot{x}_k\end{array}
\right)
\end{align*}
$$
As you can see, the value for the speed is given by exactly the formula you were proposing to use for the speed estimate.  So although you couldn't see any kind of calculation $(x_k-x_{k-1})/dt$ for speed, in fact it is hidden in there after all.


Question:
I have R data frame like this:
        age group
1   23.0883     1
2   25.8344     1
3   29.4648     1
4   32.7858     2
5   33.6372     1
6   34.9350     1
7   35.2115     2
8   35.2115     2
9   35.2115     2
10  36.7803     1
...

I need to get data frame in the following form:
group mean     sd
1     34.5     5.6
2     32.3     4.2
...

Group number may vary, but their names and quantity could be obtained by calling levels(factor(data$group))
What manipulations should be done with the data to get the result?

Here is the plyr one line variant using ddply:
dt <- data.frame(age=rchisq(20,10),group=sample(1:2,20,rep=T))
ddply(dt,~group,summarise,mean=mean(age),sd=sd(age))

Here is another one line variant using new package data.table.
dtf <- data.frame(age=rchisq(100000,10),group=factor(sample(1:10,100000,rep=T)))
dt <- data.table(dtf)
dt[,list(mean=mean(age),sd=sd(age)),by=group]

This one is faster, though this is noticeable only on table with 100k rows. Timings on my Macbook Pro with 2.53 Ghz Core 2 Duo processor and R 2.11.1:
> system.time(aa <- ddply(dtf,~group,summarise,mean=mean(age),sd=sd(age)))
utilisateur     système      écoulé
      0.513       0.180       0.692
> system.time(aa <- dt[,list(mean=mean(age),sd=sd(age)),by=group])
utilisateur     système      écoulé
      0.087       0.018       0.103

Further savings are possible if we use setkey:
> setkey(dt,group)
> system.time(dt[,list(mean=mean(age),sd=sd(age)),by=group])
utilisateur     système      écoulé
      0.040       0.007       0.048


Question: Is there a generically accepted method of removing motion blur from an image. For a simple case, we can assume that motion happens in a straight line. I assume that it's a two part process composed of motion estimation and then deconvolution, but how is it actually done?

Yes, deconvolution.  This page describes a number of deconvolution methods and methods for estimating the point spread function:

Removing Motion Blur from Astrophotographic Images

They say the deconvolution literature is "extremely extensive".   They choose Lucy-Richardson algorithm for deconvolution and develop their own motion estimation algorithm for determining the point spread function.


Question:
Darwin suggested that sexual selection, especially by female choice, may counter natural selection. Theoretical models, such as a Fisherian runaway process, suggest that evolution of preference and preferred phenotypes may drive each other in ever increasing speed.
Because one male may fertilize many females, one could imagine that natural selection against preferred but energetically costly phenotypes may be weak, and the whole process may not slow down fast enough (i.e., be sufficiently self-limiting). If male mortality is high and their number is low, the random fluctuations may easily cause the extinction of population.
Is there any fossil or experimental evidence that this may really happen?

TL;DR:

There is a dearth of actual experimental evidence. However:

there is at least one study that confirmed the process ([STUDY #7] - Myxococcus xanthus; by Fiegna and Velicer, 2003).
Another study experimentally confirmed higher extinction risk as well ([STUDY #8] - Paul F. Doherty's study of dimorphic bird species an [STUDY #9] - Denson K. McLain).

Theoretical studies produce somewhat unsettled results - some models support the evolutionary suicide and some models do not - the major difference seems to be variability of environmental pressures.
Also, if you include human predation based solely on sexually selected trait, examples definitely exist, e.g. Arabian Oryx

First of all, this may be cheating but one example is the extinction because a predator species specifically selects the species because of selected-for feature.
The most obvious case is when the predator species is human. As a random example, Arabian Oryx was nearly hunted to extinction specifically because of their horns.

Please note that this is NOT a simple question - for example, the often-cited in unscientific literature example of Irish Elk that supposedly went extinct due to its antler size may not be a good crystal-clear example. For a very thorough analysis, see: "Sexy to die for? Sexual selection and risk of extinction" by Hanna Kokko and Robert Brooks, Ann. Zool. Fennici 40: 207-219. [STUDY #1]
They specifically find that evolutionary "suicide" is unlikely in deterministic environments, at least if the costs of the feature are borne by the individual organism itself.
Another study resulting in a negative result was "Sexual selection and the risk of extinction in mammals", Edward H. Morrow and Claudia Fricke; The Royal Society Proceedings: Biological Sciences, Published online 4 November 2004, pp 2395-2401 [STUDY #2]

The aim of this study was therefore to examine whether the level of
  sexual selection (measured as residual testes mass and sexual size dimorphism) was related to the risk of extinction that mammals are currently experiencing. We found no evidence for a relationship between these factors, although our analyses may have been confounded by the possible dominating effect of contemporary anthropogenic factors.

However, if one takes into consideration changes in the environment, the extinction becomes theoretically possible. From "Runaway Evolution to Self-Extinction Under Asymmetrical Competition" - Hiroyuki Matsuda and Peter A. Abrams; Evolution Vol. 48, No. 6 (Dec., 1994), pp. 1764-1772: [STUDY #3]

We show that purely intraspecific competition can cause evolution of extreme competitive abilities that ultimately result in extinction, without any influence from other species. The only change in the model required for this outcome is the assumption of a nonnormal distribution of resources of different sizes measured on a logarithmic scale. This suggests that taxon cycles, if they exist, may be driven by within- rather than between-species competition. Self-extinction does not occur when the advantage conferred by a large value of the competitive trait (e.g., size) is relatively small, or when the carrying capacity decreases at a comparatively rapid rate with increases in trait value. The evidence regarding these assumptions is discussed. The results suggest a need for more data on resource distributions and size-advantage in order to understand the evolution of competitive traits such as body size.

As far as supporting evidence, some studies are listed in "Can adaptation lead to extinction?" by Daniel J. Rankin and Andre´s Lo´pez-Sepulcre, OICOS 111:3 (2005). [STUDY #4]
They cite 3:

The first example is a study on the Japanese medaka
  fish Oryzias latipes (Muir and Howard 1999 - [STUDY #5]). Transgenic males which had been modified to include a salmon growth-hormone gene are larger than their wild-type counterparts, although their offspring have a lower fecundity (Muir and Howard 1999). Females
  prefer to mate with larger males, giving the larger
  transgenic males a fitness advantage over wild-type
  males. However, offspring produced with transgenic
  males have a lower fecundity, and hence average female
  fecundity will decrease. As long as females preferentially
  mate with larger males, the population density will
  decline. Models of this system have predicted that, if
  the transgenic fish were released into a wild-type
  population, the transgene would spread due to its mating
  advantage over wild-type males, and the population
  would become go extinct (Muir and Howard 1999).
  A recent extension of the model has shown that
  alternative mating tactics by wild-type males could
  reduce the rate of transgene spread, but that this is still
  not sufficient to prevent population extinction (Howard
  et al. 2004). Although evolutionary suicide was predicted
  from extrapolation, rather than observed in nature, this
  constitutes the first study making such a prediction from
  empirical data.
In cod, Gadus morhua, the commercial fishing of large
  individuals has resulted in selection towards earlier
  maturation and smaller body sizes (Conover and Munch
  2002 [STUDY #6]). Under exploitation, high mortality decreases the
  benefits of delayed maturation. As a result of this,
  smaller adults, which mature faster, have a higher fitness
  relative to their larger, slow maturing counterparts
  (Olsen et al. 2004). Despite being more successful
  relative to slow maturing individuals, the fast-maturing
  adults produce fewer offspring, on average. This adaptation,
  driven by the selective pressure imposed by
  harvesting, seems to have pre-empted a fishery collapse
  off the Atlantic coast of Canada (Olsen et al. 2004). As
  the cod evolved to be fast-maturing, population size was
  gradually reduced until it became inviable and vulnerable
  to stochastic processes.
The only strictly experimental evidence for evolutionary
  suicide comes from microbiology. In the social
  bacterium Myxococcus xanthus individuals can develop
  cooperatively into complex fruiting structures (Fiegna
  and Velicer 2003 - [STUDY #7]). Individuals in the fruiting body are
  then released as spores to form new colonies. Artificially
  selected cheater strains produce a higher number of
  spores than wild types. These cheaters were found to
  invade wild-type strains, eventually causing extinction of
  the entire population (Fiegna and Velicer 2003). The
  cheaters invade the wild-type population because they
  have a higher relative fitness, but as they spread through
  the population, they decrease the overall density, thus
  driving themselves and the population in which they
  reside, to extinction.

Another experimental study was "Sexual selection affects local extinction and turnover
in bird communities" - Paul F. Doherty, Jr., Gabriele Sorci, et al; 5858–5862 PNAS  May 13, 2003 vol. 100 no. 10 [STUDY #8]

Populations under strong sexual selection experience
  a number of costs ranging from increased predation and
  parasitism to enhanced sensitivity to environmental and demographic
  stochasticity. These findings have led to the prediction that
  local extinction rates should be higher for speciespopulations
  with intense sexual selection. We tested this prediction by analyzing
  the dynamics of natural bird communities at a continental
  scale over a period of 21 years (1975–1996), using relevant statistical
  tools. In agreement with the theoretical prediction, we found
  that sexual selection increased risks of local extinction (dichromatic
  birds had on average a 23% higher local extinction rate than
  monochromatic species). However, despite higher local extinction
  probabilities, the number of dichromatic species did not decrease
  over the period considered in this study. This pattern was caused
  by higher local turnover rates of dichromatic species, resulting in
  relatively stable communities for both groups of species. Our
  results suggest that these communities function as metacommunities,
  with frequent local extinctions followed by colonization.

This result is similar to another bird-centered study: Sexual Selection and the Risk of Extinction of Introduced Birds on Oceanic Islands": Denson K. McLain, Michael P. Moulton and Todd P. Redfearn. OICOS Vol. 74, No. 1 (Oct., 1995), pp. 27-34 [STUDY #9]

We test the hypothesis that response to sexual selection increases the risk of extinction by examining the fate of plumage-monomorphic versus plumage-dimorphic bird species introduced to the tropical islands of Oahu and Tahiti. We assume that plumage dimorphism is a response to sexual selection and we assume that the males of plumage-dimorphic species experience stronger sexual selection pressures than males of monomorphic species. On Oahu, the extinction rate for dimorphic species, 59%, is significantly greater than for monomorphic species, 23%. On Tahiti, only 7% of the introduced dimorphic species have persisted compared to 22% for the introduced monomorphic species.
...
Plumage is significantly associated with increased risk of extinction for passerids but insignificantly associated for fringillids. Thus, the hypothesis that response to sexual selection increases the risk of extinction is supported for passerids and for the data set as a whole. The probability of extinction was correlated with the number of species already introduced. Thus, species that have responded to sexual selection may be poorer interspecific competitors when their communities contain many other species.


Question:
I have a FASTA file with 100+ sequences like this:
>Sequence1
GTGCCTATTGCTACTAAAA ...
>Sequence2
GCAATGCAAGGAAGTGATGGCGGAAATAGCGTTA
......

I also have a text file like this:
Sequence1 40
Sequence2 30
......

I would like to simulate next-generation paired-end reads for all the sequences in my FASTA file. For Sequence1, I would like to simulate at 40x coverage. For Sequence2, I would like to simulate at 30x coverage. In other words, I want to control my sequence coverage for each sequence in my simulation.
Q: What is the simplest way to do that? Any software I should use? Bioconductor?

I am working on a Illumina sequencing simulator for metagenomics: InSilicoSeq
It is still in alpha release and very experimental, but given a multi-fasta and an abundance file, it will generate reads from your input genomes with different coverages.
From the documentation:
iss generate --genomes genomes.fasta --abundance abundance_file.txt \
    --model_file HiSeq2500 --output HiSeq_reads

Where:
# multi-fasta file
>genome_A
ATGC...
>genome_B
CCGT...
...

# abundance file (total abundance must be 1!)
genome_A    0.2
genome_B    0.4
...

I didn't design it to work with coverage but rather abundance of the genome in a metagenome, so you might have to do a tiny bit of math ;)


Question:
I am trying to write a script that generates random graphs and I need to know if an edge in a weighted graph can have the 0 value.
actually it makes sense that 0 could be used as an edge's weight, but I've been working with graphs in last few days and I have never seen an example of it.

Allowed by whom? There is no Central Graph Administration that decides what you can and cannot do. You can define objects in any way that's convenient for you, as long as you're clear about what the definition is. If zero-weighted edges are useful to you, then use them; just make sure your readers know that's what you're doing.
The reason you don't usually see zero-weight edges is that, in most contexts, an edge with weight zero is exactly equivalent to the absence of an edge. For example, if your graph represents countries and the amount of trade done between them, a zero-weight edge would mean no trade, which is the same as having no edge at all. If your graph represents distances, a zero-weight edge would correspond to two places at distance zero from each other, which would mean they'd actually be the same place, so should both be represented by the same vertex. However, in other contexts, zero-weight edges could make sense. For example, if your graph represents a road network and edge weights represent the amount of traffic, there's a big difference between a road that nobody uses (zero-weight edge) and no road at all (no edge).


Question:
The wikipedia page claims that likelihood and probability are distinct concepts.

In non-technical parlance, "likelihood" is usually a synonym for "probability," but in statistical usage there is a clear distinction in perspective: the number that is the probability of some observed outcomes given a set of parameter values is regarded as the likelihood of the set of parameter values given the observed outcomes.

Can someone give a more down-to-earth description of what this means?  In addition, some examples of how "probability" and "likelihood" disagree would be nice.

The answer depends on whether you are dealing with discrete or continuous random variables. So, I will split my answer accordingly. I will assume that you want some technical details and not necessarily an explanation in plain English.
Discrete Random Variables
Suppose that you have a stochastic process that takes discrete values (e.g., outcomes of tossing a coin 10 times, number of customers who arrive at a store in 10 minutes etc). In such cases, we can calculate the probability of observing a particular set of outcomes by making suitable assumptions about the underlying stochastic process (e.g., probability of coin landing heads is $p$ and that coin tosses are independent).
Denote the observed outcomes by $O$ and the set of parameters that describe the stochastic process as $\theta$. Thus, when we speak of probability we want to calculate $P(O|\theta)$. In other words, given specific values for $\theta$, $P(O|\theta)$ is the probability that we would observe the outcomes represented by $O$.
However, when we model a real life stochastic process, we often do not know $\theta$. We simply observe $O$ and the goal then is to arrive at an estimate for $\theta$ that would be a plausible choice given the observed outcomes $O$. We know that given a value of $\theta$ the probability of observing $O$ is $P(O|\theta)$. Thus, a 'natural' estimation process is to choose that value of $\theta$ that would maximize the probability that we would actually observe $O$. In other words, we find the parameter values $\theta$ that maximize the following function:
$L(\theta|O) = P(O|\theta)$
$L(\theta|O)$ is called the likelihood function. Notice that by definition the likelihood function is conditioned on the observed $O$ and that it is a function of the unknown parameters $\theta$.
Continuous Random Variables
In the continuous case the situation is similar with one important difference. We can no longer talk about the probability that we observed $O$ given $\theta$ because in the continuous case $P(O|\theta) = 0$. Without getting into technicalities, the basic idea is as follows:
Denote the probability density function (pdf) associated with the outcomes $O$ as: $f(O|\theta)$. Thus, in the continuous case we estimate $\theta$ given observed outcomes $O$ by maximizing the following function:
$L(\theta|O) = f(O|\theta)$
In this situation, we cannot technically assert that we are finding the parameter value that maximizes the probability that we observe $O$ as we maximize the PDF associated with the observed outcomes $O$.


Question:
I have a camera matrix (I know both intrinsic and extrinsic parameters) known for image of size HxW. (I use this matrix for some calculations I need).
I want to use a smaller image, say: $\frac{H}{2}\times \frac{W}{2}$ (half the original).
What changes do I need to make to the matrix, in order to keep the same relation ?
I have, $K$ as the intrinsic parameters, ($R$,$T$ rotation and translation)
$$\text{cam} = K \cdot [R T]$$
$$K = \left( \begin{array}&a_x &0 &u_0\\0 &a_y &v_0 \\ 0 &0 &1\end{array} \right)$$
$K$ is 3*3, I thought on multiplying $a_x$, $a_y$, $u_0$, and $v_0$ by 0.5 (the factor the image was resized) , but I'm not sure.

Note: That depends on what coordinates you use in the resized image. I am assuming that you are using zero-based system (like C, unlike Matlab) and 0 is transformed to 0. Also, I am assuming that you have no skew between coordinates. If you do have a skew, it should be multiplied as well
Short answer: Assuming that you are using a coordinate system in which $u' = \frac{u}{2} , v' = \frac{v}{2}$, yes, you should multiply $a_x,a_y,u_0,v_0$ by 0.5.
Detailed answer The function that converts a point $P$ in world coordinates to camera coordinates  $(x,y,z,1)->(u,v,S)$ is:
$$ \left( \begin{array}{ccc}
a_x & 0 & u_0 \\
0 & a_y & v_0 \\
0 & 0 & 1 \end{array} \right)
\left( \begin{array}{ccc}
R_{11}  & R_{12} & R_{13} & T_x \\
R_{21}  & R_{22} & R_{23} & T_y  \\
R_{31}  & R_{32} & R_{33} & T_z \\
0  & 0& 0 & 1
\end{array} \right)
\left( \begin{array}{ccc}
x \\
y  \\
z \\
 1
\end{array} \right)
$$
Where $(u,v,S)->(u/S,v/S,1)$, since the coordinates are homogenous.
In short this can be written as
$ u= \frac{m_1 P}{m_3 P} , v = \frac{m_2 P}{m_3 P}$
where $M$ is the product of the two matrixes mentioned above, and $m_i$ is the i'th row of the matrix $M$. (The product is scalar product).
Re-sizing the image can be thought of:
$$ u'=u/2, v'=v/2 $$
Thus
$$ u' = (1/2) \frac {M_1 P} {M_3 P}  \\
v' = (1/2) \frac {M_2 P} {M_3 P}
$$
Converting back to matrix form gives us:
$$
\left( \begin{array}{ccc}
0.5 & 0 & 0 \\
0 & 0.5 & 0 \\
0 & 0 & 1 \end{array} \right)
\left( \begin{array}{ccc}
a_x & 0 & u_0 \\
0 & a_y & v_0 \\
0 & 0 & 1 \end{array} \right)
\left( \begin{array}{ccc}
R_{11}  & R_{12} & R_{13} & T_x \\
R_{21}  & R_{22} & R_{23} & T_y  \\
R_{31}  & R_{32} & R_{33} & T_z \\
0  & 0& 0 & 1
\end{array} \right)
\left( \begin{array}{ccc}
x \\
y  \\
z \\
 1
\end{array} \right)
$$
Which is equal to
$$ \left( \begin{array}{ccc}
0.5 a_x & 0 & 0.5 u_0 \\
0 & 0.5 a_y & 0.5 v_0 \\
0 & 0 & 1 \end{array} \right)
\left( \begin{array}{ccc}
R_{11}  & R_{12} & R_{13} & T_x \\
R_{21}  & R_{22} & R_{23} & T_y  \\
R_{31}  & R_{32} & R_{33} & T_z \\
0  & 0& 0 & 1
\end{array} \right)
\left( \begin{array}{ccc}
x \\
y  \\
z \\
 1
\end{array} \right)
$$
For additional information, refer to Forsyth, chapter 3 - Geometric camera calibration.


Question:
If there are soft clipped base pairs specified in the CIGAR string for a read in a SAM/BAM file, will these be used for variant calling in a samtools + bcftools workflow?
The GATK HaplotypeCaller, for example, has an explicit option --dontUseSoftClippedBases for whether to use soft clipped bases. The samtools documentation does not mention clipped bases.

No, samtools (and therefore bcftools) does not use soft-clipped bases. You can quickly confirm this by using either samtools depth or samtools mpileup to look at a region with a soft-clipped alignment. You'll note that the soft-clipped region isn't used in the depth/pileup (both tools use the same underlying code, so it doesn't matter which you use). If you're curious, samtools ignores soft-clipped bases because it's based on making a per-base stack of alignments covering each position. In the BAM format, alignments are sorted and assigned to bins according to their start/end positions, which won't include soft-clipping. Consequently, when samtools is making the pileup it won't even see the alignments that would overlap a given base if soft-clipped bases were included.
This then sort of begs the question of what GATK's HaplotypeCaller is doing differently. There, regions in the genome are essentially assembled in a small de Bruijn graph, which allows for soft-clipped bases around indels to then be resolved, given that the graph would start/end a little-way on past each side of indels. This is also why you don't need to do indel realignment with the HaplotypeCaller (this was needed in the old UnifiedGenotyper).
Edit: For more details regarding the HaplotypeCaller, see this nice page on GATK's website, which goes into much more detail than I did here.


Question: Safe programming languages (PL) are gaining popularity. What is the formal definition of safe PL? For example, C is not safe, but Java is safe. I suspect that the property “safe” should be applied to a PL implementation rather than to the PL itself. If so, how do we define what is a safe PL implementation?

There is no formal definition of "safe programming language"; it's an informal notion.  Rather, languages that claim to provide safety usually provide a precise formal statement of what kind of safety is being claimed/guaranteed/provided.  For instance, the language might provide type safety, memory safety, or some other similar guarantee.


Question:
Are there NP-complete problems which have proven subexponential-time algorithms?
I am asking for the general case inputs, I am not talking about tractable special cases here.
By sub-exponential, I mean an order of growth above polynomials, but less than exponential, for example $n^{\log n}$.

Depends on what you mean by subexponential. Below I explain a few meanings of "subexponential" and what happens in each case. Each of these classes is contained in the classes below it.

I. $2^{n^{o(1)}}$
If by subexpoential you mean $2^{n^{o(1)}}$, then a conjecture in complexity theory called ETH (Exponential Time Hypothesis) implies that no $\mathsf{NP}$-hard problem can have an algorithm with running-time $2^{n^{o(1)}}$.
Note that this class is closed under composition with polynomials. If we have a subexponential time algorithm for any $\mathsf{NP}$-hard problem, we can combine it with a polynomial-time reduction from SAT to it obtain a subexponential algorithm for 3SAT which would violate ETH.
II. $\bigcap_{0 < \epsilon} 2^{O(n^\epsilon)}$, i.e. $2^{O(n^\epsilon)}$ for all $0 < \epsilon$
The situation is similar to the previous one.
It is closed under polynomials so no $\mathsf{NP}$-hard problem can be solved in this time without violating ETH.

III. $\bigcup_{\epsilon < 1} 2^{O(n^\epsilon)}$, i.e. $2^{O(n^\epsilon)}$ for some $\epsilon < 1$
If by subexponential you mean $2^{O(n^\epsilon)}$ for some $\epsilon<1$ then the answer is yes, there are provably such problems.
Take an $\mathsf{NP}$-complete problem like SAT. It has a brute-force algorithm that runs in time $2^{O(n)}$. Now consider the padded version of SAT by adding a string of size $n^k$ to the inputs:
$$SAT' = \{\langle \varphi,w\rangle \mid \varphi\in SAT \text{ and } |w|=|\varphi|^k \}$$
Now this problem is $\mathsf{NP}$-hard and can be solved in time $2^{O(n^\frac{1}{k})}$.
IV. $2^{o(n)}$
This contains the previous class, the answer is similar.
V. $\bigcap_{0 < \epsilon}2^{\epsilon n}$, i.e. $2^{\epsilon n}$ for all $\epsilon>0$
This contains the previous class, the answer is similar.
VI. $\bigcup_{\epsilon < 1}2^{\epsilon n}$, i.e. $2^{\epsilon n}$ for some $\epsilon<1$
This contains the previous class, the answer is similar.

What does subexponential mean?
"Above polynomial" is not an upper-bound but a lower-bound and is referred to as superpolynomial.
Functions like $n^{\lg n}$ are called quasipolynomial, and as the name indicates are almost polynomial and far from being exponential, subexponential is usually used to refer a much larger class of functions with much faster growth rates.
As the name indicates, "subexponential" means faster than exponential. By exponential we usually mean functions in class $2^{\Theta(n)}$, or in the nicer class $2^{n^{\Theta(1)}}$ (which is closed under composition with polynomials).
Subexponential should be close to these but smaller.
There are different ways to do this and there is not a standard meaning.
We can replace $\Theta$ by $o$ in the two definitions of exponential and obtain I and IV. The nice thing about them is that they are uniformly defined (no quantifier over $\epsilon$). We can replace $\Theta$ with a multiplicative coefficient $\epsilon$ for all $\epsilon>0$, we get II and V. Their are close to I and IV but nonuniformly defined. The last option is to replace $\Theta$ with a multiplicative constant $\epsilon$ for some $\epsilon<1$. This gives II and VI.
Which one should be called subexponential is arguable. Usually people use the one they need in their work and refer to it as subexponential.
I is my personal preference, it is a nice class: it is closed under composition with polynomials and it is uniformly defined. It is similar to $\mathsf{Exp}$ which uses $2^{n^{O(1)}}$.
II is seems to be used in the definition of the complexity class $\mathsf{SubExp}$.
III is used for algorithmic upper-bounds, like those mentioned in Pal's answer.
IV is also common.
V is used to state the ETH conjecture.
Intersections (II and V) are not that useful for algorithmic upper-bounds, their main use seems to be complexity theory.
In practice, you will not see a difference between I and II or between IV and V. IMHO the later three definition (IV, V, VI) are too sensitive, they might be useful for particular problems, but they are not robust which decreases their usefulness as classes. Robustness and nice closure properties are part of the reason why famous complexity classes like $\mathsf{L}$, $\mathsf{P}$, $\mathsf{NP}$, $\mathsf{PSpace}$, and $\mathsf{Exp}$ are interesting.
Summary
IMHO, the main definitions are I and III. We already have subexponential algorithms for $\mathsf{NP}$-hard problems in the sense of III and we cannot have them in the sense of I without violating ETH.