np.vectorize quirk

I was being lazy, and had to code up a piecewise function. Rather than use the proper array tools, I used np.vectorize instead but somehow got weird results:

import numpy as np
def f(x):
if x < .5:
return 1
return .4
points = np.linspace(0, 1, 5)
points_flipped = np.flip(points)
vec_f = np.vectorize(f)

returns [1 1 0 0 0]
[0.4 0.4 0.4 1. 1. ]

Tuorns out np.vectorize has the property that

The output type is determined by evaluating the first element of the input, unless it is specified

Took me a minute to figure this out. RTFM.


Trist sunk into the sagging loveseat immediately after throwing her keys onto the credenza. The air in the apartment was too warm, but she didn’t have the vim to stand back up to adjust the thermostat.

It had been a long day, with several of her clients being especially difficult. One wanted Trist to call his almost-estranged son and to convince him to visit him in the nursing home, threatening to leave him out of the large will. Another, unfortunately, was just never easy no matter the day.

It would be another hour or so before Luc, Trist’s husband, got home. Luc typically finishes his scheduled tennis coaching sessions around this time. “Scheduled” seems to be a suggested word. He was far too gregarious to just leave the kids at six sharp, and would stay after to talk and afford guidance in their personal lives. Luc and Trist agreed that kids for them were out of the equation, but Luc couldn’t help but pretend to be a dad for those on the courts.

Luc tore his ACL in the middle of qualifiers for a middling tournament, whilst figuratively also tearing any chance at tennis stardom. Since then, it had been difficult finding steady work in a field rife with athletes who flustered in the big leagues. Teaching kids at the high school made ends meet then.

For dinner, Trist had a table set with a large heaping pile of curried lentils with herbs, some sausages, and a bowlful of roasted root vegetables. All served on plain glassware as their precious china from the wedding sits unused. Festivities where elegant plates were appropriate just never arose in the year since their wedding.

The gibber jabber went as usual; Trist and Luc always loved their banter when together. A little light teasing here or there; a lot of complaining about their days recently. Usually, the nights ended with some light escapism. For Luc, it was scrolling through feeds while Trist enjoyed streaming dramatic series. Parallel play as the psychologist called it: the company itself was the entire point. That night though, they never stopped talking.

” … it’s just those people are so terrible. I know this makes me a terrible person, but I really want him to just… go away if you catch my drift.”

“Actually, you know what Trist? it’s been too long, we should go on a vacation. Maybe that’ll help? I know I need one too.”

“We’ve been through this. We don’t have the money for that yet. I don’t have the vacation days… your kids’ parents are gonna be mad if you have to cancel practice. So many things to plan. Maybe someday”

“Yeah I know….”

In that little exchange, the seed was planted. Several weeks later, Trist saw an advertisement in the nursing home promising the elderly the ability to travel like they were young again. No more of the shuffle onto coach buses, and being herded around the sights like animals. It promised adventuring with the vigor of youth.

The product Zephyr was a state-of-the-art implant alongside pills which loaded “experiences” to the implants. Essentially, it engaged the remaining senses that VR goggles ignored by interfacing directly with the brain to stream in what it feels like to surf the waves of Bondi beach, or zip line across a Costa Rica jungle. Fanfare for such a revolutionary product was massive.

It was also far cheaper than any physical journeys, and the implant was noninvasive. There was a catch though: after an experience, one must still pony up the monthly fee. It turns out the plasticity of the human brain means that it actively will seek and diffuse away those memories. After a few days, it would be as if the experiences never happened.

Trist showed Luc the website that night.

“Remember how we talked about taking a trip awhile ago? This is so much cheaper!”

“Yeah, but we’re not actually doing it. Does it really count?”

“It says it can pretend that days has passed and …”

“… And there’s a subscription cost. What exactly are we subscribing to anyways?”

“Oh that’s for making your brain remember the whole thing.”

“Pfft, so not even really remembering it.”

“Come on, it’s not even a hundred dollars, let’s just try it.”

A week after getting the implants, Luc and Trist opened the mail to discover the package has arrived. The two initially couldn’t decide on what they wanted to do, but ultimately chose the couples package to Belize. The box contained just two pills, one for each of them, and the remaining space where filled with brochures advertising this-or-that “trip.”

The actual experience was magical. The getaway was a “reservation” at a cabana on the beach for three days with all excursions included. There with other people on the shore, but they were AI generated and got out of the way when prompted. The weather was, in every sense of the word, optimal. Water, crystal blue. And best of all, the two were somehow able to interact while in this simulation.

It was legitimately a fun adventure for Trist and Luc. And oddly enough, the pictures they took while “in” Belize showed up on their doorsteps soon after. Truly unBelizeable as the trite T-shirts would say.

This became a tradition for them: every half year, they would pick out another adventure. It provided just enough glimmer in the rat race for them to push on.

Some time later, the cycle of capitalism hit a nadir. Trist’s nursing home laid her off, and Luc’s coaching gigs dried up. They struggled to stay afloat, even with the unemployment checks. Those also eventually shriveled up prompting the two to start cutting expenses.

By the fourth month, the Zephyr monthly cost came onto the chopping block. They knew that all those experiences would be erased, but figured it’s easy enough once things were better to do it again. After all, don’t many people wish they could re-experience a transformative movie or music for the first time?

Six months after the lay offs, the maintenance pills stopped coming. Unbeknownst to Luc and Trist, their implants also malfunctioned. One day, they woke up in bed, and stared blankly at each other’s eyes, waiting for the rush of memories to kick in.

It never did.

The memories wiped extended beyond their little vacations. Somehow, their entire relationship was among the trail of destruction left behind. The two kept on starring into each eyes inquisitively as if the act of looking could remove the hoarfrost that clearly was between the two strangers now.

As Trist and Luc individually got up and looked around their room, they realized how fragile love was. Just bits of neurons firing at the sight of a certain person triggering other portions of the brain to respond; a little hormone here or there too. Yet, from the photos of the two happily together in unknown lands, it was clear that it had meant everything to the two.

Terrific Trio

Pressure is trying to pass for four when you just turned seven, at the “Miss Toddler Panama city” pageant.

You’re crammed into the same five-inch heels you wore the year before, blood pooling in your toes.

But you know if you don’t win, mom can’t fix the hole in the gator fence, so you’ll be up all night, s*ab gators.

Pressure is performing on a party boat that catches on fire, your throat burning from the smoke.

You still sing so beautifully that it calms the passengers, so that you and the crew can escape.

Pressure is singing the Yemeni national anthem while a handsome but ruthless general pushes a scimitar into your neck, Kristin Chenoweth’s corpse at your feet.

That’s pressure. – Jenna Maroney

Pressure is trying to finish the New Yorker magazine before the next issue arrives.

STRFKR concert was dope.

I guess I’m a poet now:

The Flying Mattress

There was a mattress store near my apartment in Providence which never had people in it. Since it lies between where I lived and a popular local taquería, the storefront was actually quite familiar to me. There would always be a sign reminiscent of Word’s Pop Art announcing a sale, and several mattresses lied in the darkness through the dusty panes of glass.

Not once did I notice the lights turned on. All this convinced me that this was in fact a front for the notorious mafia in Providence. After all, Providence was renounced for their intimate ties with organized crime, College Hill was not the cheapest real estate, and, most importantly, there were no, nil, nada, zip customers.

For four years of my time in PVD, it just sat there. Seemingly abandoned. I don’t know if I preferred it to be a barren storefront, or just one with no character. But eventually an electric bike company peddling (get it?) their wares took over the lease.

But perhaps, I misunderstand the economics of a quality mattress. Maybe selling one a week was enough to go even, with its high prices justified by the substantial mass of a mattress.

After all, a mattress should be hefty in weight, able to withstand the tossing and turning of the, sadly, probably overweight sleeper for years on end. The mattress might even increase in weight as the various dandruff, hair and dust mites bury themselves into the seams and folds of the mattress.

This means that a mattress flying through the air would be surprising…

… which is exactly what happened today when a mattress nearly landed on the hood of my car tonight while commuting back home.

Moral of the story: don’t buy mattresses which can fly when blown by gusts of air, but if you do, please dispose of it properly.

Calvin’s Interesting Question

Calvin and Hobbes (October 19, 1989)

Given a set of positive integers $\{q_i\}_{i=1}^n$, describe the set $s_t \in S$ of positive integers such that there exists only one linear combination of $\sum_{i=1}^n a_i q_i = s_t$.

In the comic above, it’s pretty obvious with the amount of money given, that Calvin was hoping to get four “D”s. In fact, all integers from 1 to 9 can only be expressed in one permutation.

A satisfying answer to all sets of integers might be less trivial.

Cloud Cuckoo Land

The novel is a paean dedicated to books and libraries, painting five stories separated by time but connected via a singular, fictional book. Two tales follow children stuck on opposing sides during a siege of Constantinople in 15th century, two other resides in a fictional town in Idaho around the 20th century and beyond, while the final character lives in the near-future on an inter-planetary ship. Through dumb luck, the four who live in the past all end up preserving an antediluvian, fictional Greek codex called “Cloud Cuckoo Land.”

The eponymous Greek book itself plays as essential role throughout the novel, introducing themes and motifs which the reader can easily grasp onto. It’s really an AP Lit teacher’s dream come true with the deluge of overt themes like the power of knowledge and of those who controls the knowledge, the very human desire to reach too high, or simply the horrors of warfare.

But I think I connected with how time was treated in the novel. Depending on context, years, or even a whole lifetime, would pass in a single chapter. It reminds me of Gentleman in Moscow, where time accelerated through the chapters. Decades seemingly compressed into two sentences whilst the adventures as a child were so exquisitely detailed. Life seems diminutive as time marches on and destroys those that were not carefully preserved.

With that solemn conclusion, it still has a positive angle. No matter how meaningless an action now is, as long as humanity lives on, it might have a positive impact on someone down the line. We’ll be dust by then and our contributions will be lost to time, but posterity will nevertheless appreciate the bit of effort.

It’s a fairly well-written book overall. I thought there were several plot points missing and a bit too many deus ex machinas, but I did really enjoy it.


I’ve followed the League of Legends esports scene for more than a decade now, and playing on-and-off for longer. The lore videos and cinematics which Riot releases were also engaging to me, and sometimes I wish they were longer. Yet, I’ve only watched Arcane a week ago…

Boy, was it good. And not at at the “adaption of videogame” level good, but stands its ground against the vast ocean of television compendium level good.

Everything from character development to music to art design and the story lines, I found it airtight against most trite criticism. It shows rather than tells, and assumes the viewer is an adult. The detail in each frame of animation can only be fully appreciated only on a second or third time around. The trials and tribulations which Vi and Powder/Jinx goes through can be felt.

I wished I watched it sooner.

Putnam 2022 A1

Determine all ordered pairs of real numbers $(a, b)$ such that the line $y = ax + b$ intersects the curve $y = \ln(1 + x^2)$ in exactly one point.

I really liked this problem, and thought it makes for a good “research” problem for calculus classes. For notation purposes, let $g(x) = \ln(1 + x^2)$. The following is also very sketch-like, and conversational. We first note that logarithmic curve is even, and we can simply consider $a \ge 0$, since $y = -ax + b$ will have the same number of intersection points. Simply looking at the graph, it’s clear that $(a, b) = (0, 0)$ is such a solution, and for fixed $a = 0$, that no other $y$-intercept will work.

Intuitively, for large enough slope, a line will also only intersect $g(x)$ at one point, no matter the intercept since it “outgrows” the log. We can formalize this by noting that $g'(x) = \frac{2x}{1 + x^2}$ with

  1. $\lim_{x\to \pm \infty} g'(x) = 0$,
  2. $g'(0) = 0, g'(1) = 1$
  3. $g'(x) \le 1$ by trivial inequality.

Assume not, then there exists two or more zeros for the function $g(x) – (ax + b)$. By the mean value theorem, then there would exist a point $c$ such that $g'(c) – a = 0$, which cannot happen since $|g'(c)| \le |a|$.

Now, we need to examine the region where $1 > a > 0$. For $b > 0$, if the $y$-intercept is large enough then the logarithmic growth will not catch up with the linear growth. To find this “large enough” intercept, we set simply find the line where it intersects $g(x)$; this will occur where the derivatives equal.

Solving $g'(x) = a$, we have $\frac{2x}{1 + x^2} = a \implies x^*_{\pm} = \frac{1 \pm \sqrt{1 – a^2}}{a}$. The intersection $b$ will be $ax^*_{+} + b = \ln(1 + (x^*_p)^2) \implies b = \ln(1 + (x^*_p)^2) – ax^*_p$, hence any $b > \ln(1 + ((x^*_p)^2) – ax^*_p$ suffices.

On the other hand, the root $x^*_{-}$ corresponds to the cases where $b < 0$ where the line “ducks” underneath first before intersecting the log curve, and hence any $b < \ln(1 + (x^*_m)^2) – ax^*_m$ will work.

Finally,the case of $a = 1$ is left as an exercise because this is too long.

The Mandolin-ian.

Laziness prompted me to buy a mandolin. It did expedite the slicing of my potatoes, but at a cost of some dermis from the knuckle of my middle finger. Hubris lost me that piece of skin.

Wow, this is so easy to slice by using my hand. Why use the protector. Only dumb peo….

Worse of all, since I wasn’t done with the dish, I had to painstakingly finish the recipe with only one hand. Arranging the sliced potatoes vertically in the casserole dish can be a real spud in the butt as one might say.

For the Black Friends-day dinner the next day, I made the same potato gratin dish again. This time using the protector the entire time. I stayed whole. The dish stayed delicious (because how can it not be? It had two cups of heavy cream and another half pound of premium cheese. It’ll be difficult to make it not delicious), and life was joyous.

I guess the lesson here is that I should’ve bought a mandolin awhile ago, back when I was young, limber and heal from scrapes in half an hour rather than the six hours it took for the wound to congeal. Pride will never change.

On an tangent, I really cannot find the connection of the word mandolin the instrument versus mandolin the slicer. There is a website which claims that the tool was named because the action resembled the strumming movement of mandolin the instrument but that sounds bonkers to me.