Given a real number , one can find its positive part in multiple ways: by definition:

as a maximum or by using the absolute value: …

This is boring.

You know what else is boring? Spreadsheets.

Google Sheets, in particular. Let’s suppose we have a bunch of numbers in a spreadsheet (in a range like A1:B3), and want a single-cell formula (using arrayformula) that gets the positive parts of all of them.

1 -2
4 0
-1 3

The definition-based approach, =arrayformula(if(A1:B3>0, A1:B3, 0)) does the job:

1 0
4 0
0 3

But it’s kind of redundant: the range has to be typed twice. This can be annoying if you are not just taking positive part once but computing something nested with them: . Each application of positive part would double the length of the formula.

The absolute value approach, =arrayformula((A1:B3+abs(A1:B3))/2), has the same issue.

The maximum looks promising, because involves only once. Alas, =arrayformula(max(A1:B3,0)) returns a single number (4 in this example), because max just takes the maximum of all entries.

Is there a spreadsheet formula that returns positive part in array-compatible way, and uses the argument only once?

Yes, there is: =arrayformula(iferror(sqrt(A1:B3)^2, 0))

Negative arguments throw an error at the evaluation of the square root. This error is handled by iferror wrapper, which returns the second argument in this case, namely 0. Otherwise, the value of the square root gets squared, bringing back the input.

clamps the input values between 0 and 1, performing . Yes, it’s long — but if the input is itself a 100-character formula, this is still a simplification over the other approaches.

An isometry is a map between two metric spaces which preserves all distances: for all . (After typing a bunch of such formulas, one tends to prefer shorter notation: , with the metric inferred from contexts.) It’s a popular exercise to prove that every isometry from a compact metric space into itself is surjective.

A rough isometry allows additive distortion of distances: . (As contrasted with bi-Lipschitz maps, which allow multiplicative distortion). Rough isometries ignore small-scale features (in particular, they need not be continuous), but accurately capture the large scale structure of a space. This makes them convenient for studying hyperbolic spaces (trees and their relatives), where the large-scale structure is of interest.

If is an -rough isometry, then the Gromov-Hausdorff distance between and is at most . This follows from a convenient characterization of : it is equal to where the infimum is taken over all subsets that project surjectively onto each factor, and .

Since small-scale features are ignored, it is not quite natural to talk about rough isometries being surjective. A natural concept for them is -surjectivity, meaning that every point of is within distance of . When this happens, we can conclude that , because the Hausdorff distance between and is at most .

Recalling that an isometry of a compact metric space into is automatically onto, it is natural to ask whether -rough isometries of into are -surjective. This, however, turns out to be false in general.

First example, a finite space: with the metric (when ). Consider the backward shift (and ). By construction, this is a rough isometry with . Yet, the point is within distance from .

The above metric can be thought of a the distance one has to travel from to with a mandatory visit to . This makes it similar to the second example.

Second example, a geodesic space: is the graph shown below, a subset of with the intrinsic (path) metric, i.e., the length of shortest path within the set.

Define where means the positive part. Again, this is a -rough isometry. The omitted part, shown in red below, contains a ball of radius centered at . Of course, can be replaced by any positive integer.

Both of these examples are intrinsically high-dimensional: they cannot be accurately embedded into for low (using the restriction metric rather than the path metric). This raises a question: does there exist such that for every compact subset , equipped with the restriction metric, every -rough isometry is -surjective?

The Euclidean space has a nice property: every closed convex subset is the image of the whole space under a map that is simultaneously:

a contraction, meaning for all ;

a retraction, meaning for all .

Indeed, we can simply define to be the (unique) nearest point of to ; it takes a bit of work to verify that is a contraction, but not much.

In other normed spaces, this nearest point projection does not work that well. For example, take , the two-dimensional space with the Manhattan metric. Consider the line which is a closed and convex set. The nearest point of to is : moving straight up, since changing the first coordinate doesn’t pay off. Since remains fixed, the nearest point projection increases some pairwise distances, in this case from to .

However, there is a contractive retraction onto this line, given by the formuls . Indeed, this is a linear map that fixes the line pointwise and has norm because

More generally, in every normed plane, every closed convex subset admits a contractive retraction. To prove this, it suffices to consider closed halfplanes, since a closed convex set is an intersection of such, and contractions form a semigroup. Furthermore, it suffices to consider lines, because having a contractive retraction onto a line, we can redefine it to be the identity map on one side of the line, and get a contractive retraction onto a halfplane.

Such a retraction onto a line, which is a linear map, is illustrated below.

Given the unit circle (black) and a line (blue), draw supporting lines (red) to the unit circle at the points where it meets the line. Project onto the blue line along the red ones. By construction, the image of the unit disk under this projection is contained in the unit disk. This precisely means that the map has operator norm .

In spaces of dimensions or higher, there are closed convex subsets without a contractive retraction. For example, consider the plane in passing through the points , , and . This plane has equation . The point is at distance from each of A,B,C, and it does not lie on the plane. For any point E other than D, at least one of the distances AE, BE, CE exceeds 1. More precisely, the best place to project D is which is at distance from A, B, and C.

Two natural questions: (a) is there a nice characterization of normed spaces that admit a contractive retraction onto every closed convex subset? (b) what is the smallest constant such that every -dimensional normed space admits an -Lipschitz retraction onto every closed convex subset?

(The answers may well be known, but not to me at present.)

Given: websites on which users can post stuff. For the th site gets posts per day on average. Some of the posts are spam or otherwise harmful.

One of the ways to detect spam automatically is to send an API request to any of the sites, get post content and analyze it. The total number of such requests cannot exceed per day, while the total number of posts, namely , is substantially larger.

This necessitates rationing. The current strategy is to wait until a site has new posts, and then request all of those at once. The upside is that only requests are needed. The downside is that spam may sit undetected for a period of time proportional to .

One would like to minimize the mean lifetime of spam. Assuming for now that spam is uniformly distributed among the sites, this lifetime is proportional to

So, we need to minimize subject to . The method of Lagrange multipliers says that the gradient of objective function should be proportional to the gradient of constraint. Hence,

with independent of . This leads to .

That is, the size of API queue should be proportional to the square root of the level of activity.

An excellent proxy for overall activity on a site is QPD, questions per day. For example, the QPD ratio of Mathematics to Computer Science is currently 452:11, so the ratio of queue sizes should be about (in reality, the queue size is currently and , respectively).

The value of is easily found from the condition (pushing the API quota to the limit), with the final result

In practice, spam is unevenly distributed. Let’s say that is the proportion of spam on the th site. Then the mean lifetime is proportional to

This time, the method of Lagrange multipliers yields

hence . That is, the size of API queue should be proportional to .

Theoretically, the optimal size is

In practice, one does not know beyond some general idea of how spammy a site is. Drupal Answers gets a lot more than Computer Science; so even though its QPD exceeds CS by the factor of about four, its API queue size is set to the minimal possible value of .

Nonlinear differential equations don’t necessarily have globally defined solutions, even if the equation is autonomous (no time is involved explicitly). The simplest example is with initial condition : the solution is , which ceases to exist at , escaping to infinity.

This kind of behavior can often be demonstrated without solving the ODE. Consider with , . I’ve no idea what the explicit solution is, but it’s clear that the quantity remains constant: indeed, . (Here, is analogous to the sum of kinetic and potential energy in physics.)

The solution is increasing and convex. Let be such that , e.g., . The invariance of yields . By the mean value theorem, for . Since the series on the right converges, the limit is finite; this is the blow-up time.

But no blow-up occurs for the equation , where the nonlinear term pushes back toward equilibrium. Indeed, the invariant energy is now , which implies that and stay bounded. In the phase space the solution with initial values , traces out this curve:

Accordingly, the solution is a periodic function of (although this is not a trigonometric function):

Everything so far has been pretty straightforward. But here is a stranger animal: . As in the previous example, nonlinear term pushes toward equilibrium. Using initial conditions , , I get this numerical solution up to time :

As in the previous example, oscillates. But the speed and amplitude of oscillation are increasing.

Rapidly increasing:

In the plane the solution spirals out:

The plots make it clear that the solution ceases to exist in finite time, but I don’t have a proof. The issue is that the function does not escape to infinity in just one direction. Indeed, if , then regardless of the values of and at , the negative third derivative will eventually make the function decrease, and so will attain the value at some . After that, the third derivative is positive, guaranteeing the existence of time when returns to again. I haven’t succeeded in proving that the limit is finite, giving the time when oscillatory explosion occurs.

var('t y y1 y2')
P = desolve_system_rk4([y1,y2,-y^3],[y,y1,y2], ics=[0,1,0,0],ivar=t,end_points=5,step=0.01)
Q=[ [i,j] for i,j,k,l in P]
list_plot(Q, plotjoined=True)

Given some data points one can devise various functions that extract information from them. Such as

Regression line (considered in When the digits of go to 11): it detects a linear trend , minimizing the sum of squares of residuals .

Natural cubic spline (considered in Connecting dots naturally), which passes through every data point while minimizing the amount of wiggling, measured by the square of its second derivative. Like this:

A smoothing spline is something in between the above extremes: it insists on neither being a line (i.e., having zero second derivative) nor on passing through given points (i.e., having zero residuals). Instead, it minimizes a weighted sum of both things: the integral of second derivative squared, and the sum of residuals squared. Like this plot, where the red points are given but the spline chooses to interpolate the green ones:

I’ll demonstrate a version of a smoothing spline that might not be exactly canonical, but is very easy to implement in Matlab or Scilab (which I prefer to use). As in Connecting dots naturally, assume the knots equally spaced at distance . The natural cubic spline is determined by the values of its second derivative at , denoted . As explained earlier, these can be found from the linear system

where the column on the right contains the amounts by which the derivative of the piecewise linear interpolant through given points jumps at every knot. The notation means the second difference of , for example .

A smoothing spline is also a natural spline, but for a different set of points . One has to find that minimize a weighted sum of and of . The latter integral is easily computed in terms of : it is equal to . Since this quadratic form is comparable to , I’ll work with the latter instead.

The idea is to set up an underdetermined system for and , and let Scilab find a least squares solution of that. Let’s introduce a weight parameter that will determine the relative importance of curvature vs residuals. It is convenient to let , so that both and (second derivative) scale the same way. The terms contributes to the linear system for , since the right hand side now has instead of . This contribution is . Moving it to the left hand-side (since are unknowns) we obtain the following system.

where is the same tridiagonal matrix as above, and is the rectangular Laplacian-type matrix

All in all, the system has unknowns , and equations, reflecting the continuity of first derivative at each interior knot. The lsq command of Scilab finds the solution with the least sum of squares of the unknowns, which is what we are after.

Time for some examples. and can be seen above. Here are more:

As increases, the spline approaches the regression line:

Finally, the Scilab code. It is almost the same as for natural spline; the difference is in five lines from B=... to newy=... The code after that is merely evaluation and plotting of the spline.

a = 0; b = 10
y = [3 1 4 1 5 9 2 6 5 3 5]
lambda = 0.1
n = length(y)-1
h = (b-a)/n
jumps = diff(y,2)/h
A = (h/6)*(diag(4*ones(1,n-1))+diag(ones(1,n-2),1)+diag(ones(1,n-2),-1))
B = lambda/h*(diag(-2*ones(1,n+1))+diag(ones(1,n),1)+diag(ones(1,n),-1))
C = [A, B(2:$-1,:)]
sol = lsq(C,-jumps')'
z = [0,sol(1:n-1),0]
newy = y + lambda*h^2*sol(n:$)
allx = []
spl = []
for i=1:n
xL = a+h*(i-1)
xR = a+h*i
x = linspace(xL,xR,100)
linear = newy(i)*(xR-x)/h + newy(i+1)*(x-xL)/h
correction = ((z(i+1)+2*z(i))*(xR-x)+(2*z(i+1)+z(i))*(x-xL)).*(xR-x).*(x-xL)/(6*h)
allx = [allx, x]
spl = [spl, linear+correction]
end
plot(allx, spl)
plot(a:h:b, newy, 'g*')
plot(a:h:b, y, 'r*')

After a year, it is time to update the Hertzsprung–Russell diagram of Stack Exchange sites. Here is the new and much improved version: a bubble chart made with Google Spreadsheets. The data is imported with ImportXML function, which apparently means it will be automatically refreshed every two hours. Just in case, here is a (heavily zoomed out) static image. It’s not as usable as the interactive chart you see above, because one can’t read the text on obscured bubbles by hovering over them.

As a rule of thumb, the sites with at least 10000 visits/day and 10 questions/day are those that “made it”: they either graduated from beta or will probably graduate in foreseeable future (assuming the quality of content is decent and the community is somewhat capable of self-organization).

A year ago, I joked about Beer, Italian Language, and Expatriates being either closed or merged into one site. Neither thing happened yet. Of the three, Expatriates site now has the largest numbers of visits and questions, though the quality is often an issue. Italian Language caught up with Russian Language (not to be confused with Русский язык, which is a recently imported site from Hashcode.ru and differentiates itself by targeting native speakers rather than language learners). Of the three, Beer appears to have the least amount of energy at present.

Some of the sites at the bottom, around 100 visits/day, are very new and will not stay there for long. The future of Community Building seems less certain.

Here’s the technical part. The data is/are obtained from this list of sites with the command

The XPath parameter consists of two: //div[contains(@class,'category')]/@class picks up the class of every div element with “category” in its list of classes. This is later used to categorize as Technology, Science, Life/Arts, etc. The other part is //input/@value, which grabs all other data: number of questions, number of answers, number of users… most of which I have no use for. To sort this column by data type I put MOD(ROW()-2,9) next to it:

The columns C-F filter the content of A by item type. For example, D is the site name: =FILTER(A:A,B:B=8), etc. The Category column needs a bit of extra (routine) work to make it user-friendly. Otherwise, the table is finished:

+---------------------+-------------------+----------------+
| Name | Questions per day | Visits per day |
+---------------------+-------------------+----------------+
| Stack Overflow | 7956.3 | 7232805 |
| Server Fault | 103.1 | 353739 |
| Super User | 162.9 | 734077 |
| Meta Stack Exchange | 21.8 | 8680 |
| Web Applications | 12.7 | 44341 |
| Arqade | 36.5 | 247448 |
| Webmasters | 13.6 | 12433 |
| Seasoned Advice | 6.9 | 80308 |
| Game Development | 21.1 | 25836 |
| Photography | 8.5 | 26560 |
| Cross Validated | 84.4 | 63317 |
| Mathematics | 616.4 | 150744 |
| Home Improvement | 17.3 | 71148 |
+---------------------+-------------------+----------------+

The bubble chart uses this table for the log-log scale plot that you see above.

Fix two positive numbers and . The volume of the intersection of balls of radii and is a function of the distance between their centers. Is it a decreasing function?

Wolfram MathWorld gives a formula for this volume in the three-dimensional case

(Here and in the sequel it is assumed that .) From this formula it is not at all obvious that is decreasing. And this is just for three dimensions.

Let’s begin with the one-dimensional case, then. Consider the intervals and where . A point belongs to their intersection if and only if

Hence, the length of the intersection is . Even this simple formula does not quite make it evident that the function is decreasing for . If this is clear enough, but the case .

Fortunately, Fubini’s theorem reduces the general case to the one-dimensional one. Take any line parallel to the line connecting the centers. The intersection of each ball with is a line segment whose length is independent of . The distance between the midpoints of these segments is ; thus, the length of the intersection is a decreasing function of .

Gromov’s note Monotonicity of the volume of intersection of balls (1987) deals with the more general case of balls in : if two sets of balls an satisfy for all , then the volume of does not exceed the volume of .

The paper ends with

Question: Who is the author of [this result]? My guess is this was known to Archimedes. Undoubtedly the theorem can be located […] somewhere in the 17th century.

Meanwhile, the corresponding problem for the volume of the unionremains open.

Reading the Wolfram MathWorld™ article on the Möbius strip I came across an equation that was news to me.

After the familiar parametric form

it is said that “In this parametrization, the Möbius strip is therefore a cubic surface with equation…”

That’s a neat cubic equation for sure. But… wouldn’t the sign of the left hand side of (2) (call it ) distinguish the “positive” and “negative” sides of the surface, contrary to its non-orientability?

I went to SageMathCloud™ to check and got this plot of (2):

That’s… not exactly the Möbius strip as I know it. But it’s true that (1) implies (2): the cubic surface contains the Möbius strip. Here is the plot of (1) superimposed on the plot of (2).

The self-intersection arises where the “positive side” suddenly transitions to negative .

Trying to approximate a generic continuous function on with the Fourier trigonometric series of the form is in general not very fruitful. Here’s such an approximation to , with the sum over :

It’s better to make a linear change of variable: consider on the interval , and use the formula for the cosine series. This results in , which is approximated by the partial sum of its cosine Fourier series as follows.

But one can do much better with a different, nonlinear change of variable. Consider on the interval , and again use the formula for the cosine series. This results in , which is approximated by the partial sum of its cosine Fourier series as follows.

Yes, I can’t see any difference either: the error is less than .

The composition with cosine improves approximation because is naturally a periodic function, with no jumps or corners in its graph. Fourier series, which are periodic by nature, follow such functions more easily.

A practical implication of this approximation of is the Clenshaw-Curtis integration method. It can be expressed in one line:

The integral is approximated by summing , where are even-numbered cosine coefficients of . In the example with using just three coefficients yields

while the exact integral is .

At first this doesn’t look practical at all: after all, the Fourier coefficients are themselves found by integration. But since is so close to a trigonometric polynomial, one can sample it at equally spaced points and apply the Fast Fourier transform to the result, quickly obtaining many coefficients at once. This is what the Clenshaw-Curtis quadrature does (at least in principle, the practical implementation may streamline these steps.)