I’ve built a straightforward capture system in emacs for storing links in a designated file. Lately, however, I’ve ventured into the world of Obsidian, a note-taking application, to explore its capabilities.
To make link capturing effortless, I initially experimented with Instapaper. The ease of capturing web content with Instapaper is genuinely remarkable—simply click a button in your browser, and voila, the content is saved for offline reading. It’s equally efficient on an iPad; just share a link with Instapaper, and it’s saved. But despite this convenience, I prefer not to rely on third-party apps and sought to create a similar workflow within Obsidian.
Capture web links efficiently and store them in an Obsidian vault. The collected links will be treated as a “reading list” and appended to a specific Obsidian file. Be as distraction-free as possible.
To create a new note in Obsidian, you can do the following:
obsidian://new?vault=name&filepath=Reading%20List/Untitled.md&content=content
This approach is too clunky, it requires URL encoding, making sure content parameter is constructed properly. Too much work.
Using AppleScript, we can begin by verifying if the file already exists:
set obsidianFilePath to POSIX file "Valut/Reading List.md"
tell application "Finder"
set fileExists to exists file obsidianFilePath
end tell
If it does, appending new content is straightforward:
set fileDescriptor to open for access file obsidianFilePath with write permission
write obsidianContent to fileDescriptor starting at eof
close access fileDescriptor
To know if the capture was successful or not, create a system notification:
display notification "Item captured in Obsidian" with title "Quick Capture - Obsidian"
And the most important thing: get the current safari tab’s URL and title:
tell application "Safari"
set currentURL to URL of current tab of window 1
set currentTitle to name of current tab of window 1
end tell
Equipped with these, we can write a complete script that:
In Apple Automator, we create a new “Quick Action” and select “Run AppleScript”:

To make this process even more effortless, associate this Automator action with a keyboard shortcut. Navigate to System Settings → Keyboard → Shortcuts → General, find the Automator Quick Action you’ve saved, and assign your desired key combination. I’ve set mine to Ctrl+c.

Now, capturing links is as simple as pressing Ctrl+c while browsing in Safari, instantly adding them to your Obsidian reading list.
I have been collecting water usage data for three years. The way home-assistant collects data, I get hourly mean, mix and max values for the water level in a sqlite database.
To set the context:
Plot of all the points:

Negative values come from malfunctioning sensors. A lot of jitter from earlier sensors as well. Cleaning up negative values, assuming they’re sensor noise, here is a plot of data from 2021:

You might notice four conspicuous gaps in the dataset. The first two correspond to periods when I was tinkering with different sensors to improve system accuracy. The large gap in August-September was due to system failure during the rainy season. This event led me to thoroughly waterproof the sensor setup, resulting in visibly more consistent data collection thereafter.
To understand usage patterns, the following plot is mean values from Sept’23:

And this is Min, Mean, Max:

To see the pattern more clearly, here is a plot of mean values bucketed by hour through the month of Sept’23

Key observations:
Further insights can be derived from a histogram focusing on readings below 30:

Taking 1000 random samples out of total data for mean values, for 10000 times gives us the nice bell curve!

When compared with a standard Normal Distribution curve, the resemblance is uncanny:

To verify if the distribution really follows Normal Distribution, we can check it with Quantile-Quantile Plot showing strong correlation:

I conducted a frequency spectrum analysis to look for any recurring patterns or cycles in water usage:

Alternative: accept that markets are efficient
What are the common issues faced by other people? What are the repair costs for these parts? Find this information online and perhaps even talk to local repair shops.
How much do people around you usually end up spending on repairs? How often does this happen? This data will provide you with insight into the likelihood of your laptop getting damaged. Think of it in terms of Bayesian base rates.
Reflect on your own experiences with damaged laptops. How many times have you damaged your laptops in the past, and what were the causes? This can help you gauge your personal risk.
Consider the ways you’ve damaged your laptops in the past. Were they due to accidents like water spills or drops, or were they related to wear and tear issues? Different types of damage may have varying insurance coverage.
Be aware of your cognitive biases, such as overestimating the likelihood of rare events or underestimating common risks. Try to make objective judgments by gathering data and considering all possibilities. Cognitive biases are not always bad. But important to know keep them in mind.
Think about potential lifestyle changes that might affect your laptop’s risk. For example, having a child might increase the chances of accidents, while transitioning to a more stable work environment could reduce risks.
Account for the depreciation of your laptop’s value over time. Electronics typically lose value as they age, which can affect the amount you’d want to insure it for. This data is easily obtainable online.
Summarize all the information and factors you’ve gathered. This can include estimated repair costs, your personal risk history, lifestyle changes, and depreciation. Trust your gut feeling to some extent, as it’s important to feel comfortable with your decision.
With all this information in hand, you can start comparing insurance premiums from different providers. It might be more cost-effective to self-insure by setting aside a “repair fund” for potential laptop issues instead of paying for insurance with a high deductible! You should now have a better feeling about it.
Of course you could just accept that the markets are mostly efficient and therefore most of the factors that you can and cannot think are already factored in, skip the whole exercise and start comparing the premiums.
]]>The music is their instrument to assert control. The reverberating air carries the commands. They turn up the heat and ice cube starts melting slowly. They know what they’re doing, they are turning us into water, for the rill is our destiny.
Before long, they succeed. We are one with the rill. We flow, we dance, we are euphoric. We fall and rise. Sun rays kissing us, dancing along. It is the metamorphosis accomplished!
We are transformed to the extreme. We hear crows cawing and wind wailing. We are lost, there is no ice cube left. We are abandoned, the Master Musicians have left us. There is no control, there is no direction, what will become of us? The dark dream has swallowed us.
Like the gentle touch of flower on a girl’s cheeks, a guitar note wakes us up. They have not left us! Through sheer magic, they have kept control. We were not lost, but willed into feeling lost. They didn’t just have control over the heat source, they were puppeteering the rill. They had absolute will on the very rays of the Sun reflecting and dancing on the rill! We are caressed back to our natural state of calm and relaxation.
Echoes is where time seems to stand still, and the boundaries between musician, listener, and the music itself dissolve into pure harmony.
]]>One winter morning, as I tended to the trees and plants, Arvinddas arrived on his platina, after months of being absent. His arrival felt ordinary, and we exchanged no pleasantries. “Come! Come!” was my only invitation, met with his eager response, “Yes! What are you doing? Do you need help?” Despite his weak lungs and age above 60, he was eager to assist me in pruning trees and removing weeds.
He went inside and took his place on the sofa. In a few minutes my father happened to enter the hall and saw Arvinddas sitting. They exchanged conventional pleasantries. I heard only bits of what they were talking about. Putting pieces together, I gathered this time he went to Haridwar first and from there to somewhere in MP. It took him many days to reach Haridwar because he had no plans, no train tickets, and no money. He said he woke up one morning, did not feel like being in Bhuj and took his bike. I don’t know how he managed to pay for fuel and food, but apparently in about 15 days he reached Haridwar.
Somewhere in Rajasthan, he found himself in a kerfuffle. Having spent the night beneath the sheltering branches of a banyan tree along the highway, he washed his face near a roadside dhaba the next morning, unintentionally causing the dhaba owner’s wife to erupt in anger. Unfazed, Arvinddas requested soap, which only further enraged her, threatening him with a beating. Her husband intervened, leading Arvinddas away, calming his wife in the process. The husband shared his own tales of aiding people like Arvinddas, finding ways to help without stirring trouble with his wife. He even offered financial support.
Arvinddas regaled us with marvelous stories from his recent time in Madhya Pradesh while a glass of chhaas was prepared to welcome him. Soon he requested lunch. Despite being advised by a doctor to avoid certain dishes, Arvinddas opted for khakhra, khichdi, and a specific dish designed by my mother just for him. He always ate alone, and after finishing his meal, requested a cold drink. We happened to have a few forbidden, sugar-filled bottles of coke.
He rummaged through his bag, assessing if he had enough clothes. Finding the answer to be in the negative, we offered him a dhoti and a tote bag. He sat beneath the fan for a quarter of an hour, sharing rambling tales of politics, however incoherent. He expressed the pain of his deteriorating health, only to declare it no longer mattered to his liberated mind. This launched him further into the exploration of his philosophical ideas on human body’s purposes, techniques to shape and control both the body and mind.
As he prepared to leave, he inspected my garden work and offered tips. He possessed a knack for it. I always maintained my concern about the risks he faced on the road, both for himself and others. He should not have been driving a motorcycle.
I have known Arvinddas living in huts devoid of running water and electricity, in large two-story houses entrusted to him by absent tenants. I have seen him construct makeshift shelters in remote locations and settle amidst decaying farmlands. He lived in ashrams at Dhinodhar, Haridwar, Rishikesh and other obscure places. I recall his repeated pilgrimages of “Narmada Parikrama”, each time catching one disease or another. I have known him to be a man striving for independence—repairing houses, gardens, roads, experimenting with his own health, and abandoning places at whim. His religious beliefs underwent countless transformations, each iteration a new blend of the previous.
My family observed Arvinddas’s unconventional ideas from a distance, refraining from expressing opinions on his views. He held some questionable—and sometimes offensive—beliefs regarding women, one of which I take credit of breaking him away from by uttering the simple statement, “Is that what you think of my mother, who is cooking for you right now?” I vividly recall the flow of changing expressions as he pondered my words. Eventually he said “You are right, that is wrong”. It was a small victory, having swayed an old man grappling with religions and his internal dialogues.
Some months ago, the carefree ascetic departed from this world, his lungs succumbing to the passage of time. He was at the Kachchhi Ashram in Haridwar, and his body was hastily flown back to Bhuj. His passing went unnoticed by those unaware of his existence. But for us, it feels as though an infinite period stretches out ahead before he unexpectedly returns, seeking sustenance once again.
]]>
Listen to Interstellar OST as you read this.
As the hour approached, the young boy shouldered his schoolbag and made his way down the stairs. His friends awaited him three stories below, their bicycles ready. During the long summer break, he had eagerly flipped through the pages of the new textbooks, his eyes fixated on the captivating, crude black-and-white line drawings that adorned the science book.
The group of boys reached their classroom, a familiar space that would be their home for the next academic year. Among them, the boy found his place in the second row, occupying the middle column bench. It was his designated spot for the year.
Just as the anticipation settled in, Miss Kusum gracefully entered the classroom for their first science lesson. Dressed in a deep green sari with delicate gray patterns, she wore round spectacles with thin metallic frames. Her slender figure radiated grace and warmth. Unlike the other teachers that day, she urged the students to put away their textbooks and listen.
With a warm smile gracing her lips, Miss Kusum embarked on her storytelling journey. Her voice carried a melodic tone, drawing the young mind in. As she spoke of the extraordinary creation known as the Voyager spacecraft, the boy’s imagination ignited like a flickering flame. Vivid images danced before his mind’s eye, painting a vibrant tapestry of the spacecraft, the planets, and the limitless wonders of the universe. The walls of the classroom melted away, replaced by the vast expanse of a mysterious and captivating darkness, where celestial bodies twinkled like distant beacons. The boy found himself floating amidst the cosmos, it was as if he stood beneath a vast, star-studded sky, where countless dots of light twinkled like celestial beacons.
Miss Kusum described how the Voyager had been meticulously built by humans, a product of tireless effort, unwavering dedication, and absolute genius. It was launched into space with a mission to explore the planets. The boy’s mind raced with excitement as he envisioned the spacecraft journeying through the solar system, capturing stunning images of distant worlds. Saturn, with its majestic rings, would be the Voyager’s next destination, followed by Uranus, Neptune, and even Pluto.
The boy was enthralled, transported to a realm where scientific discovery knew no bounds. The spacecraft traveled through the vastness of space, venturing far beyond the planets. Miss Kusum explained that it would eventually escape the confines of the solar system, venturing into interstellar space. The boy marveled at the idea of a machine venturing where no human had gone before, witnessing sights that had never been seen.
As Miss Kusum concluded her tale, the classroom gradually brightened, returning the boy to reality. Science, she proclaimed, was the pursuit of such remarkable knowledge and the ability to create marvels like the Voyager spacecraft. The rest of the class proceeded with the mundane contents of the first chapter in the textbook.
That was remembrance of a day from my childhood. I often think of this day. I do not remember the exact words of the teacher, but it captures my feelings well.
That single story shared by Miss Kusum had a profound impact on me, leaving a lasting impression that has shaped my life. It sparked a deep curiosity within me, driving my fascination with the mysteries of the universe. I vividly recall buying many issues of the magazine called “Safari”. From then on, I used to tell everyone “I want to be a scientist!” on every opportunity.
Looking back now, that story remains one of my most cherished childhood memories.
]]>Chapter is about sums of the general form:
\[\begin{equation} a_1+a_2+a_3+ \dotsm +a_n \text{,} \end{equation}\]Where each \(a_k\) is called a term.
Sigma notation
\[\begin{equation} \sum_{k=1}^n a_k \end{equation}\]We called it a “term” in previous notation. Here they’re called summand.
Another way to write in Sigma notation
\[\begin{equation} \sum_{1 \leq k \leq n} a_k \end{equation}\]For any recurrence of the form
\[\begin{equation} a_nT_n = b_nT_{n-1}+c_n \end{equation}\]The solution is
\[\begin{equation} T_n = \frac{1}{s_na_n} \left( s_1b_1T_0 + \sum_{k=1}^ns_kc_k \right) \end{equation}\]If we can find a summation factor of the form
\[\begin{equation} s_n = \frac{a_{n-1}a_{n-2} \dots a_1 }{b_nb_{n-1} \dots b_2 } \end{equation}\]Harmonic numbers appear everywhere.
\[\begin{equation} H_n = 1 + \frac{1}{2} + \dotsm + \frac{1}{n} = \sum_{k=1}^n \frac{1}{k} \end{equation}\]Distributive law
\[\begin{equation} \sum_{k \in K}ca_k = c \sum_{k \in K}a_k \end{equation}\]Associative law
\[\begin{equation} \sum_{k \in K} (a_k + b_k) = \sum_{k \in K}a_k + \sum_{k \in K}b_k \end{equation}\]Commutative law (permutative law)
\[\begin{equation} \sum_{k \in K}a_k = \sum_{p(k) \in K}a_{p(k)} \end{equation}\]To combine different sets of indices
\[\begin{equation} \sum_{k \in K}a_k + \sum_{k \in K’}a_k = \sum_{k \in K \cap K’}a_k + \sum_{k \in K \cup K’}a_k \end{equation}\]Perturbation method
\[\begin{equation} S_n + a_{n+1} = \sum_{0 \leq k \leq n+1}a_k = a_0 + \sum_{0 \leq k \leq n}a_{k+1} \end{equation}\]Interchanging the order of summation
\[\begin{equation} \sum_j\sum_k a_{j,k}[P(j,k)] = \sum_{P(j,k)}a_{j,k} = \sum_k\sum_j a_{j,k}[P(j,k)] \end{equation}\]Variation “vanilla” of interchanging the order of summation
\[\begin{equation} \sum_{j \in J}\sum_{k \in K}a_{j,k} = \sum_{\substack{j \in J \\ k \in K}}a_{j,k} = \sum_{k \in K}\sum_{j \in J} a_{j,k} \end{equation}\]Variation “rocky road” \begin{equation} \sum_{j \in J}\sum_{k \in K(j)}a_{j,k} = \sum_{k \in K’}\sum_{j \in J’(k)}a_{j,k} \end{equation}
\begin{equation} \left( \sum_{k=1}^na_k \right) \left( \sum_{k=1}^nb_k \right) = n \sum_{1 \leq j < k \leq n} (a_k - a_j)(b_k-b_j) \end{equation}
In commutative law, when \(p(k)\) is instead any arbitrary function \(f\)
\[\begin{equation} \sum_{j \in J}a_{f(j)} = \sum_{k \in K}a_k \# f^-(k) \end{equation}\] \[\begin{equation} \sum_{j \in J}a_{f(j)} = \sum_{f(j) \in K}a_{f(j)} = \sum_{k \in K}a_k \end{equation}\]These rules applied, give
\[\begin{equation} \sum_{0 \leq k < n}k^{\underline{m}} = \frac{k^{\underline{m+1}}}{m+1}\bigg\rvert_0^n = \frac{n^{\underline{m+1}}}{m+1} \end{equation}\]Summation by parts
\[\begin{equation} \sum u \Delta v = uv - \sum Ev \Delta u \end{equation}\]]]>A Double Tower of Hanoi contains \(2n\) disks of \(n\) different sizes, two of each size. As usual, we’re required to move only one disk at a time, without putting a larger one over a smaller one.
We will always have even number of disks. Let’s run the double tower manually. Pick up some objects and transfer the tower, write the results down:
| \(\textbf{n}\) | \(\textbf{D(n)}\) |
|---|---|
| 2 | 2 |
| 4 | 6 |
| 6 | 22 |
| 8 | 30 |
That is odd, why is it jumping at 6? If we disregard \(D(6)\) then there seems to be a pattern. We need to play more with this. Let’s note the results again (I was indeed making mistake with \(D(6)\) for some reason!):
| \(\textbf{n}\) | \(\textbf{D(n)}\) |
|---|---|
| 2 | 2 |
| 4 | 6 |
| 6 | 14 |
| 8 | 30 |
Let’s remind ourselves of the original Tower of Hanoi problem. The results were:
| \(\textbf{n}\) | \(\textbf{T(n)}\) |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 7 |
| 4 | 15 |
| 5 | 31 |
| 6 | 63 |
The recurrence was:
\[\begin{equation} T_n = 2T_{n-1} + 1 \end{equation}\]There does not seem to be any correlation between \(T(n)\)’s results and \(D(n)\). You can try various things, such as checking if adding or subtracting between \(T(n)\) and \(D(n)\) results into someting interesting. Or perhaps some offset of \(n\) might work. I couldn’t find anything.
Going forward, should we think in terms of \(n\) disks or \(2n\) disks? Not sure… Anyway, let’s still move on.
To move a tower of \(4\) disks, first \(2\) disks must be transferred to the middle peg. Then \(2\) more moves to transfer bottom two disks. Then \(2\) more moves to transfer \(2\) upper disks.
To transfer \(n\) disks, \(n-2\) disks must first be transferred to the middle peg. Requiring \(D_{n-2}\) moves. Next, \(2\) moves for the bottom \(2\) disks. Finally we need \(D_{n-2}\) more moves.
It seems that
\[\begin{equation} D_n = 2D_{n-2} + 2 \quad \text{for $n>1$.} \end{equation}\]Does it fit our data?
\[\begin{align*} D_2 & = 2D_0 + 2 \\ & = 2 \\ D_4 & = 2D_2 + 2 \\ & = 6 \\ D_6 & = 2D_4 + 2 \\ & = 14 \\ D_8 & = 2D_6 + 2 \\ & = 30 \end{align*}\]Yes! It fits, and is already shown to be minimum (perhaps it could be a bit more rigorous).
Now we have to solve the recurrence. Instead of trying induction, let’s try “non-clairvoyant” ways similar to “adding \(1\)” that was tried in the chapter. In the graffito, we find an interesting remark: “Interesing: We get rid of the \(+1\) in \((1.1)\) by adding, not subtracting.” Hmm, we would like to get rid of the \(+2\) and so let’s add \(2\) and see where it goes.
\[\begin{align*} D_n & = 2D_{n-2} + 2 \\ \therefore D_n + 2 & = 2D_{n-2} + 4 \end{align*}\]Let \(U_n = D_n + 2\).
\[\begin{align*} \therefore U_n & = 2(D_{n-2}+2) \\ \therefore U_n & = 2U_{n-2} \end{align*}\]Does it take a genius to discover that this is \(2^n - 2\)? Probably not.
]]>I seem to have been infected with some seasonal virus. When such an infection is accompanied with a fluctuation in temperature, the tonsils swell. Swollen tonsils make my life quite rough for a few days. The body starts signalling well in advance that things are going to wrong.
Not just food, it is tough to swallow saliva, to turn the neck. Under these circumstances, speech has a cost.
Marvellous side effect! Every word I speak has been carefully evaluated for the cost about to be incurred. If the set of organs are to be actuated, knowing it is absolutely bound to cause pain that will be felt for a few seconds after the vibrations of the organs have subsided, they better be substantial, meaningful, absolutely necessary, short, concise…
The pain makes me aware of the great benefits of not speaking, not reacting, paying attention, thinking before speaking. So much is better left unsaid, so much can be conveyed by gestures, so much is worth just a smile and a nod!
Pain is the first proper step to real compassion; it can be a foundation for understanding all those who struggle with their existence. ~ David Whyte
The pain will fade away soon. Eventually the memory of the pain. After that, it will be hard to imagine “the pain it used to cause”. I will revert back to speaking without having to pay the cost. Perhaps I should have a switch that penalizes for speaking. An efficient reminder to be exceedingly nice to people, avoid most of the dialogues, just sigh and move on, have space to be compassionate. At least, I get this switch turned on often enough to be reminded once a year.
I shall therefore unburden myself of the labor of words and leave you with (listen):
Pain is the doorway to the here and now. Physical or emotional pain is an ultimate form of ground, saying, to each of us, in effect, there is no other place than this place, no other body than this body, no other limb or joint or pang or sharpness or heartbreak but this searing presence. Pain asks us to heal by focusing not only on the place the pain is felt but also the actual way the pain is felt. Pain is a form of alertness and particularity; pain is a way in.
Through the radical undoing and debilitation of repeated pain we are reacquainted with the essentialities of place and time and existence itself; in deep pain we have energy only for what we can do wholeheartedly and then, only within a narrow range of motion, metaphorically or physically, from tying our shoelace to holding the essential core conversations that are reciprocal and reinforcing within the close-in circle of those we love. Pain teaches us a fine economy, in movement, in the heart’s affections, in what we ask of ourselves and eventually in what we ask in others.
Pain’s beautiful humiliations make us naturally humble and force us to put aside the guise of pretense. In real pain we have no other choice but to learn to ask for help and on a daily basis. Pain tells us we belong and cannot live forever alone or in isolation. Pain makes us understand reciprocation. In real pain we often have nothing to give back other than our own gratitude, a smile that perhaps looks half like a grimace or the passing friendship of the thankful moment to a helpful stranger, and pain can be an introduction to real friendship, it tests those friends we think we already have but also introduces us to those who newly and surprisingly come to our aid.
Pain is the first proper step to real compassion; it can be a foundation for understand all those who struggle with their existence. Experiencing real pain ourselves, our moral superiority comes to an end; we stop urging others to get with the program, to get their act together or to sharpen up, and start to look for the particular form of debilitation, visible or invisible that every person struggles to overcome. In pain, we suddenly find our understanding and compassion engaged as to why others may find it hard to fully participate.
Strangely, the narrow focus that is the central difficult invitation of bodily pain, calls for a greater perspective, for a bigger, more generous sense of humor. With the grand perspective real pain is never far from real laughter - at ourself or for another watching that self-laughter at the predicament or the physical absurdity that has become a daily experience. Pain makes drama of an everyday life with our body and our presence firmly caught on stage and in the spotlight, we are visible to others in a way over which we have no choice, limping here or leaning there.
Lastly, pain is appreciation; for most of all the simple possibility and gift of a pain-free life - all the rest is a bonus. Others do not know the gift in simply being healthy, of being unconsciously free to move or walk or run. Pain is a lonely road, no one can know the measure of our particular agonies, but through pain we have the possibility, just the possibility, of coming to know others as we have, with so much difficulty come to know ourselves.
]]>We hope to find the following by playing with the problem:
\[\begin{equation*} T_n \leq 2 T_{n-1} + 1 \quad \text{for $n > 0$.} \end{equation*}\]We must move \(n-1\) disks before being able to move \(n^{th}\) disk
\[\begin{equation*} \therefore T_n \geq 2 T_{n-1} + 1 \quad \text{for $n > 0$.} \end{equation*}\]By looking at many cases \(n\), we might guess at closed-form:
\[\begin{equation}\label{hanoiclosed} T_n = 2^n - 1\text{,} \quad \text{for $n \geq 0$.} \end{equation}\]We proceed using induction.
Base Case: \(n=0\). The equation is simply
\[\begin{align*} n & = 0 \\ \therefore T_0 & = 2^0 - 1 \\ & = 0 \end{align*}\]Inductive Hypothesis: Assume \(\eqref{hanoiclosed}\) is true for \(n-1\).
\[\begin{align*} T_n & = 2 T_{n-1} + 1 \\ & = 2(2^{n-1} - 1) + 1 \\ & = 2^n - 2 + 1 \\ \therefore T_n & = 2^n - 1 \end{align*}\]By induction, we have shown that the hypothesis \(\eqref{hanoiclosed}\) holds for \(n+1\).
The recurrence can be solved usuing other methods. The one shown in the chapter (of adding \(1\) to each side etc) leaves some open questions:
Prove that the closed-form for the recurrence is
\[\begin{align}\label{linesclosed} L_n = \frac{n(n-1)}{2} + 1 \text{,} \quad \text{for $n \geq 0$.} \end{align}\]Base Case: \(n=0\).
\[\begin{align*} L_0 & = \frac{0(0 + 1)}{2} + 1 \\ \therefore L_0 & = 1 \end{align*}\]Inductive Hypothesis: Assume \(\eqref{linesclosed}\) to be true \(n-1\).
Inductive Step: From recurrence
\[\begin{align*} L_n & = L_{n-1} + n \\ & = \biggl(\frac{n(n-1)}{2} + 1\biggr) + n \\ & = \frac{n^2}{2} - \frac{n}{2} + 1 + n \\ & = \frac{n^2}{2} + \frac{n}{2} + 1 \\ & = \frac{n(n-1)}{2} + 1 \end{align*}\]Thus, by induction we prove that the hypothesis holds for \(n+1\).
We have to tackle even \(n\) and odd \(n\) separately. We set \(2n\) people in even case because integers multiplied by \(2\) always result in even number. Adding \(1\) to an even integer always results in odd, hence we set \(2n+1\) for the other case. It might take some effort to see that \(J(5 \cdot 2^m) = 2^{m+1} + 1\).
We want to prove the following for both — odd and even — cases.
\[\begin{equation}\label{josclosed} J(2^m + \ell) = 2\ell + 1 \end{equation}\]We proceed with induction on two separate cases.
Base Case: \(n=1\).
\[\begin{equation*} \therefore m = 0 \text{,} \quad \ell = 0\text{.} \end{equation*}\] \[\begin{align*} J(2^m + \ell) & = 2^0 + 0 \\ & = 1 \end{align*}\]Inductive Step: Suppose that for all \(n\) such that \(n = 2^k + r\), we have \(J(n) = J(2^k + r) = 2r + 1\)
Suppose \(m > 0\) and \(n = 2^m + r = 2\ell\). That is, \(n\) is even. From recurrence:
\[\begin{align*} J(2n) & = 2J(n) - 1 \\ \therefore J(n) & = 2J(\frac{n}{2}) - 1 \\ \therefore J(2^m + \ell) & = 2J\biggl( \frac{2^{m-1}+\ell}{2} \biggr) - 1 \end{align*}\]Now, assuming the hypothesis to be true for smaller \(n\):
\[\begin{align*} J\biggl(\frac{2^{m-1}+\ell}{2}\biggr) & = \frac{2\ell}{2} + 1 \end{align*}\] \[\begin{align*} \therefore J(2^m + \ell) & = 2\biggl(\frac{2\ell}{2} + 1 \biggr) - 1 \\ & = \frac{4\ell}{2} + 2 - 1 \\ \therefore J(2^m + \ell) & = 2\ell + 1 \end{align*}\]Suppose \(m > 0\) and \(n = 2^m + r = 2\ell + 1\). That is, \(n\) is odd. Similar to the even case,
\[\begin{align*} J(n) & = 2J\biggl(\frac{n}{2} - 1 \biggr) + 1 \end{align*}\]Assuming the hypothesis to be true, we get
\[\begin{align*} J(2^{m-1}+\frac{\ell}{2} - 1) & = 2J(2^{m-1}+\frac{\ell}{2} - 1) + 1 \end{align*}\] \[\begin{align*} \therefore J(n) & = 2 \biggl(\frac{2\ell}{2} + 1 - 1 \biggr) + 1 \\ & = 2\biggl(\frac{2\ell}{2} \biggr) + 1 \\ & = 2\ell + 1 \end{align*}\]Thus by induction we prove the closed-form for both odd and even cases of \(n\).
We convert constants in the recurrence into variables:
\[\begin{equation} \label{eq:josephus:gen} \begin{split} f(1) & = \alpha\text{,} \\ f(2n) & = 2f(n) + \beta\text{,} \quad \text{for $n \geq 1$;} \\ f(2n + 1) & = 2f(n) + \gamma\text{,} \quad \text{for $n \geq 1$.} \end{split} \end{equation}\]Equations in (1.12) of the chapter tells us that \(f(n)\) can be written as:
\[\begin{equation} \label{eq:josephus:gen:2} f(n) = A(n)\alpha + B(n)\beta + C(n)\gamma \end{equation}\]We find settings for general parameters (in our case \(\alpha,\beta,\gamma\)) for which we know the solution. This gives us repertoire of special cases that we can solve. Usually, we need as many special cases as there are parameters.
\[\begin{equation} \label{eq:josephus:rep:2} \begin{split} A(n) & = 2^m\text{;} \\ B(n) & = 2^m-1-\ell\text{;} \\ C(n) & = \ell\text{.} \end{split} \end{equation}\]We proceed with repertoire method.
Special case \(\alpha=1\text{,}\beta=\gamma=0\).
\[\begin{align*} f(n) & = A(n)\alpha + B(n)\beta + C(n)\gamma \end{align*}\] \[\begin{align*} f(1) & = A(1)\cdot 1 + B(1)\cdot 0 + C(1)\cdot 0 \\ \therefore f(1) & = A(1) \\ \therefore A(1) & = 1 \quad \text{from recurrence.} \end{align*}\] \[\begin{align*} f(2n) & = 2A(n)\alpha + B(n)\beta + C(n)\gamma \\ & = 2A(n) + 1 \cdot \beta \\ & = 2A(n) \end{align*}\] \[\begin{align*} f(2n+1) & = 2A(n)\alpha + B(n)\beta + C(n)\gamma \\ & = 2A(n)\cdot 1 + 0 \cdot 0 + 1 \cdot 0 \\ & = 2A(n) \end{align*}\]Let’s show \(A(n) = 2^m\). We proceed with proof by induction to show:
\[\begin{equation} \label{eq:josephus:rep:1} A(2^m+\ell) = 2^m \end{equation}\]Base Case: \(n=1\).
\[\begin{equation*} \therefore m = 0 \text{,} \quad \ell = 0\text{.} \end{equation*}\] \[\begin{align*} A(2^0+0) & = 1 \\ \therefore A(1) & = 1 \end{align*}\]Inductive Step: Assume the hypothesis \eqref{eq:josephus:rep:1} to be true for smaller \(n\) like we did for recurrence solution the previous section.
\[\begin{align*} A(2n) & = 2A(n) \\ \therefore A(n) & = 2A\biggl(\frac{n}{2}\biggr) \\ \therefore A(n) & = 2A\biggl(\frac{2^{m-1}+\ell}{2}\biggr) \end{align*}\]Assuming the hypothesis \(\eqref{eq:josephus:rep:1}\) for \(n-1\)
\[\begin{align*} A(2^{m-1}+\frac{\ell}{2}) & = 2^{m-1} \\ \quad \\ \therefore A(n) & = 2 \cdot 2^{m-1} \\ \therefore A(n) & = 2^m \end{align*}\]Similarly,
\[\begin{align*} A(2n+1) & = 2A(n) \\ \therefore A(n) & = 2A\biggl(\frac{n}{2} - 1\biggr) \\ \therefore A(n) & = 2A\biggl(\frac{2^{m-1}+\ell}{2} - 1\biggr) \\ & = 2 \cdot 2^{m-1} \\ \therefore A(n) & = 2^m \end{align*}\]Thus, we show by induction that \(A(n) = 2^m\).
Are there any constants (\(\alpha,\beta,\gamma\)) that give the general equation?
Take \(f(n) = 1\). Since \(f\) always gives \(1\), it is called a “constant function”.
\[\begin{align*} f(n) & = 1 \\ \therefore \alpha & = 1 \\ \text{And,} \\ 1 & = 2\cdot f(n) + \beta \\ \therefore 1 & = 2 \cdot 1 + \beta \\ \therefore \beta & = -1 \\ \text{And,} \\ 1 & = 2 \cdot f(n) + \gamma \\ \therefore 1 & = 2 + \gamma \\ \therefore \gamma & = -1 \end{align*}\]Plugging these values of \(\alpha,\beta,\gamma\) in \(\eqref{eq:josephus:gen:2}\), we get
\[\begin{align*} f(n) & = A(n)\cdot 1 + B(n)\cdot (-1) + C(n)\cdot (-1) \\ & = A(n) - B(n) - C(n) \\ \quad \\ B(n) & = A(n) - 1 - C(n) \\ \therefore B(n) & = 2^m - 1 - \ell \end{align*}\]Let’s set \(f(n) = n\)
\[\begin{align*} 1 & = \alpha \\ \text{And,} \\ 2n & = 2f(n) + \beta \\ \therefore 2n & = 2n + \beta \\ \therefore \beta & = 0 \\ \text{And,} \\ 2n + 1 & = 2f(n) + \gamma \\ \therefore 2n + 1 & = 2n + \gamma \\ \therefore \gamma & = 1 \end{align*}\]Plugging these values of \(\alpha,\beta,\gamma\) into \(\eqref{eq:josephus:gen:2}\), we get:
\[\begin{align*} f(n) & = A(n)\alpha + B(n)\beta + C(n)\gamma \\ \therefore n & = A(n)\cdot 1 + B(n)\cdot 0 + C(n)\cdot 1 \\ \therefore n & = A(n) + C(n) \end{align*}\]With the three cases, we now have
\[\begin{align*} A(n) & = 2^m \\ A(n) - B(n) - C(n) & = 1 \\ A(n) + C(n) & = n \end{align*}\]Now,
\[\begin{align*} C(n) & = n - A(n) \\ & = n - 2^m \\ \therefore C(n) & = \ell \\ \text{And,} \\ B(n) & = A(n) - 1 - C(n) \\ \therefore B(n) & = 2^m - 1 - \ell \end{align*}\]Thus we have our hypothesis from \(\eqref{eq:josephus:rep:2}\) proven.
Equation \(\eqref{eq:josephus:radix}\) is not strictly binary radix. Instead of allowing \(0\) and \(1\) values for \(\beta\), we are allowing any values. This is because our parameters \((\alpha,\beta,\gamma)\) are general and can take any value.
For \(n=100\) in Josephus Problem, we have \(\alpha =1,\beta = -1, \gamma = 1\). Also note that \(\beta_{b_{m-1}}=\beta_{1}=1\), \(\beta_{b_{m-3}}=\beta_{0}=-1\) and so on. The cyclic left bit-shift propery from earlier holds in the generalised form as well:
\[\begin{align*} 100 & = (1100100)_2 \\ 73 & = (1001001)_2 \end{align*}\]]]>