# Making waves at your friendly function foundry

A friend of a friend has become known, among friends, for fabricating rococo mathematical functions. $\require{begingroup}\begingroup \def \sssfrac #1#2{ \dfrac {\raise -.5ex{\small #1}} { \raise .5ex{ \scriptsize #2}} } \def \ssfrac #1#2{ \dfrac { \raise -.5ex{ \scriptsize #1}} { \raise .5ex{ \scriptsize #2}} } \def \sfrac #1#2{ \dfrac{ \raise-.5ex{ \small #1}} { \raise.5ex{ \small #2}} } \def \f_#1#2{ f\kern-.1em\raise-#1ex{ \small #2} }$

So a friend asked my friend’s friend, “would you forge a wave function for my wrought- iron fence?”

“No problem, pal, what are friends for?” $\kern3em y = - \sfrac\pi4 \sin 2x$

The recipe above, $\boldsymbol{ {-}\sfrac\pi4 \sin 2x }$, has 7 ingredients:1 trigonometric function ($\sin$) and 6 other pieces (minus sign, $\pi$, division bar, $4$, $2$, $x$).

“Not sine waves, silly, water waves.”

“Oh.   Let’s just start over with an all-purpose mystery $\boldsymbol f$unction.” $\kern2em y = \f_{1}{\scriptsize 0}(x,y)$

The recipe for $~\boldsymbol{ \f_{.8}{a}(x,y) }~$ has 11 secret ingredients:4 trigonometric functions and 7 other pieces. (Left and right parentheses count as individual ingredients.)

“And stir it with a sea breeze.   All aboard, matey!” $\kern7em y = \f_{1.5}{\sssfrac\pi2}(x,y)$

“Seems a bit tame, chum, how about some tubular curls?”

“No sweat, sweetie, surf’s up.” $\kern14em y = \f_{1}{2\pi}(x,y) \raise-3ex\strut$

“Deadly!   Gulp.   Maybe just a lip, some spray, and one break would be just right.”

“Okay, Goldilocks. How’s this?” $\kern 8em y ~~ = ~~ \sfrac{10}{11} ~ + ~ \f_{1.5}{ {\large(} \normalsize\pi{+}\sssfrac{x}{6} {\large)} }(x,y) \raise-5ex\strut$

“Now, that’s one gnarly $f$ of a function, my friend, mind if I give it a turn, say, up to 12 ?”

“Be my guest, buddy, knock yourself out.” $\kern10em y = \f_{1}{12\pi}(x,y) \raise-3ex\strut$

“I’m catching on now, neighborino, those are nearly Fermat’s spirals spaced every $~ x=\pm \kern1mu n \kern1mu \pi \,$.
Safe to say that $~ y = \f_{.8}{a}(x,y) ~$ matches  $r = \pm\sqrt{ { 2 \over \large a } \theta ~ }$ ?”

“Say it, and see it, savant, a spiral match for $~ y = \f_{1}{2\pi}(x,y) \,$: ” $\kern3em r = \pm\sqrt{ \sfrac2{2\pi} \theta ~ } \raise-4ex\strut$

( Outer portions $~ | \kern1mu{\large r}\kern1mu | > \sfrac32{\large \pi} ~$ should appear solidly black but came out too psychedelic to retouch.)

So, dear solver . . .     What is that 11- ingredient recipe for $\boldsymbol{~ \f_{.8}{a}(x,y) \,}$?

In the spirit of experimentation, feel free to request any plot based on $\f_{.8}{a}(x,y)$.   Role reversal of $x$ and $y$, for example, can forge a slightly more traditional fence design. $\raise-3ex { \kern2em -\sin 2x = \f_{1.5}{\ssfrac52 \normalsize\pi}(y,x) \raise-5ex\strut }$

Notes

Portions of the x,y- plane not plotted above need not be empty.

These implicit plots were made by EquationExplorer at KevinMehall.net.
Also good for implicit function plots is MathGrapher at eMathHelp.

Plotting programs tend to create spurious features where components of $\f_{.8}{a}(x,y)$ swing through $1 \over 0$. As such, and as a free hint,  $y = \f_{1}{2\pi}(x,y)$  is likely to appear as:

Not bad aesthetically, but the following loops should be ignored for accuracy:

$\endgroup$

• What does the new graph represent? The "eye" shaped one right before the "So, dear solver..." thing. What's the value of $a$ there? – FrodCube Mar 12 '17 at 20:59
• Clarified, @FrodCube, thank you for the nudge. (Wasn't meant to be a secret: $~a=2\pi$ for that eye-shaped spiral.) – humn Mar 12 '17 at 23:07

If we write

$f_a(x,y) = -\sin x \tan(a \cos x \cos y)$

then we get exactly the results described in the question, and our definition has the required 11 elements.

I'd describe the reasoning that led me to this function but there really wasn't very much reasoning involved :-). My thinking, so far as you can call it such, was along the following lines.

First of all, we have this approximate Fermat spiral thing. So near to (0,0) we have something that looks like $ar^2=\theta$ or in other words $a(x^2+y^2)=\tan^{-1}\frac{y}{x}$. We can rearrange that to get $\tan a(x^2+y^2)=\frac{y}{x}$ or $x\tan a(x^2+y^2)=y$, which has $y$ separated out in just the way we see in the question. This yields, e.g., the following plot for $a=4\pi$ (and $x$-axis range only $\pm\frac{5\pi}2$ rather than $\pm\frac{9\pi}2$ as in the question).

But

this doesn't have the needed periodicity in $x,y$. The "obvious" thing to do is to replace $x,y$ with $\sin x,\sin y$ on the LHS. When we do this we get pretty pictures that "in spirit" resemble the ones we're after but are not quite correct; in particular, we find that the spirals live inside 45-degree "diamond" cells rather than the square ones we want. Here's a picture, parameters as before:

So then

a natural hack is to replace $x,y$ with $x+y,x-y$ or (as turns out better) $\frac{x+y}2,\frac{x-y}2$ inside the tangent. This gets closer still to what we want but still isn't right. Here's a picture, parameters as before: Looks good, no? But if we now take, say, the version with $a$ increasing with $x$, here's how it looks (x-range now as in OP): which has in some sense the right sort of shape but isn't quite the right thing. Also, things like $\sin^2\frac{x+y}2$ cry out for simplification. So we apply some standard trigonometric substitutions and end up with something like $f_a(x,y)=\sin x \tan a(1-\cos x\cos y)$. Then we find that changing the constant inside the parentheses changes the details but not the overall character of the result; and it doesn't take much further experimentation to arrive at the answer at the top.

(Note: my plots are actually all upside down for stupid technical reasons. Apologies for any confusion.)

OP has requested some more details about how the Fermat-ish spirals emerge. Well,

$$y=f_a(x,y) \\ \iff y = -\sin x \tan(a \cos x \cos y) \\ \iff \exists n : a \cos x \cos y = -\tan^{-1}\frac{y}{\sin x}+n\pi \\ \iff \exists n : a-\frac{ar^2}2 = -\tan^{-1}\frac yx+\phi(x,y) + n\pi \quad\textrm{where \phi(x,y)=o(r^2)} \\ \iff \exists n : a-\frac{ar^2}2 = -\theta+\phi(x,y) + n\pi \\ \iff \exists n : 2a-ar^2 = -2\theta+2\phi(x,y)+n\cdot2\pi \\ \iff ar^2 = 2(a+\theta)+o(r^2) \quad\textrm{where now we allow 2\pi-ambiguity in \theta}$$

so that (in the unlikely event that there are no mistakes in my algebraic manipulations)

when $r$ isn't too big we have approximately a Fermat spiral, with an angular offset of $a$ (which in the diagrams in the puzzle is usually a multiple of $2\pi$); compared with a "canonical" Fermat spiral, $r$ is scaled by a factor of $\sqrt{\frac a2}$.

I think that

if we write $u=\sin x$ and $v=\sin y$ then we have a better approximation to a Fermat spiral in $(u,v)$ coordinates, or something like that, which is why the spacing between the turns of the spiral is more equal than for an actual Fermat spiral and why each spiral is kinda squeezed into a square box; but it's about 2am local time and if I try to make this rigorous I will probably just make it wrong.

• Thank you for these gorgeous contributions to the Puzzling Pulchritude Project, Gareth McCaughan/McEscher! Neither you (by this puzzle) nor your software (by 1/0) were fooled. – humn Mar 13 '17 at 18:47
• OK, done, though what I've written about that probably consists mostly of careless mistakes. – Gareth McCaughan Mar 15 '17 at 1:53
• Thank you for spiraling in on the approximation, Gareth! The offset was both a surprise and surprisingly harmless. Pleasant dreams (you've improved mine) – humn Mar 15 '17 at 1:56