Math Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/category/physics-math/math-science-stuff/ Production Grade Technical Solutions | Data Encryption and Public Cloud Expert Fri, 28 Nov 2025 01:56:09 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 https://www.anujvarma.com/wp-content/uploads/anujtech.png Math Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/category/physics-math/math-science-stuff/ 32 32 Running Sum of Randomly Generated Numbers https://www.anujvarma.com/running-sum-of-randomly-generated-numbers/ https://www.anujvarma.com/running-sum-of-randomly-generated-numbers/#respond Thu, 27 Nov 2025 15:17:43 +0000 http://www.anujvarma.com/?p=3152 Integers from 1 to N are randomly generated . Each integer has an equal probability of being selected and unlimited repetition is permitted. A running sum is maintained. Given any […]

The post Running Sum of Randomly Generated Numbers appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>

Integers from 1 to N are randomly generated . Each integer has an equal probability of being selected and unlimited repetition is permitted. A running sum is maintained.

Given any integer k, such that 1 <= k <= n , what is the probability that a sum of EXACTLY n will be reached?

Probabilities of Partial Sums

Let P(n,k) be the probability that a run using the integer n will produce a sum of exactly k.



 

Probability of Hitting Exactly n

Integers from 1 to k are repeatedly drawn uniformly at random (with replacement) and a running sum is maintained. We ask:
for a fixed target integer n, what is the probability that some partial sum equals exactly n?

1. Interpretation

At each step you add an independent uniform draw from the set \(\{1,2,\dots,k\}\) (each with probability \(1/k\)). If, at any time, the running sum equals \(n\) we say the target is hit. If the running sum exceeds \(n\) that trial has failed to hit exactly \(n\).

2. Recurrence (computational)

Let \(P(n)\) denote the probability that the process will reach exactly \(n\) starting from sum 0. Then

\[ P(0)=1,\qquad P(n)=\frac{1}{k}\sum_{i=1}^{k} P(n-i)\quad\text{for }n\ge1,\]
with the convention \(P(m)=0\) for \(m<0\).

This recurrence follows by conditioning on the first draw: if the first draw is \(i\) (probability \(1/k\)), we then need to reach \(n-i\) from there.

3. Generating function

Define \(G(x)=\sum_{n\ge0} P(n)x^n\). The recurrence implies

\[ G(x)=\frac{1}{1-\dfrac{x}{k}\cdot\dfrac{1-x^{k}}{1-x}}. \]

Equivalently,

\[ G(x)=\frac{1-x}{1-x-\dfrac{x}{k}(1-x^{k})}. \]

4. Combinatorial (closed-form finite sum)

Let \(a(n,m)\) be the number of ordered sequences (compositions) of length \(m\) whose parts lie in \(\{1,\dots,k\}\) and that sum to \(n\). Then

\[ P(n)=\sum_{m=\lceil n/k\rceil}^{n} a(n,m)\left(\frac{1}{k}\right)^m. \]

The integer counts \(a(n,m)\) have an inclusion–exclusion formula (bounded-compositions / stars-and-bars with upper bounds):

\[ a(n,m)=\sum_{j=0}^{\left\lfloor\dfrac{n-m}{k}\right\rfloor} (-1)^j \binom{m}{j} \binom{n-kj-1}{m-1}. \]

Combining gives the finite-sum closed form

\[ P(n)=\sum_{m=\lceil n/k\rceil}^{n} \left(\frac{1}{k}\right)^m \sum_{j=0}^{\left\lfloor\dfrac{n-m}{k}\right\rfloor} (-1)^j \binom{m}{j} \binom{n-kj-1}{m-1}. \]

5. Special checks

  • k=1: then the only draw is 1, so \(P(n)=1\) for every \(n\).
  • Small k: for k=2 the recurrence becomes \(P(n)=(P(n-1)+P(n-2))/2\) with \(P(0)=1,P(-1)=0\), etc.

6. Small numerical example (corrected)

Take \(k=6\) (uniform on \(\{1,\dots,6\}\)) and compute \(P(n)\) up to \(n=10\) using the recurrence \(P(n)=\tfrac{1}{6}\sum_{i=1}^{6}P(n-i)\) with \(P(0)=1\) and \(P(m)=0\) for \(m<0\).

Exact rational values and decimals

P(0) = 1 = 1.0000000000

The post Running Sum of Randomly Generated Numbers appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/running-sum-of-randomly-generated-numbers/feed/ 0
Some great graduate math problems https://www.anujvarma.com/some-great-graduate-math-problems/ https://www.anujvarma.com/some-great-graduate-math-problems/#respond Wed, 30 Sep 2020 23:38:53 +0000 https://www.anujvarma.com/?p=7841 Prof. W.H Steeb – collection of problems Berkeley Problems in Mathematics

The post Some great graduate math problems appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Prof. W.H Steeb – collection of problems

Berkeley Problems in Mathematics

The post Some great graduate math problems appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/some-great-graduate-math-problems/feed/ 0
Graph of Dirichlet Function https://www.anujvarma.com/graph-of-dirichlet-function/ https://www.anujvarma.com/graph-of-dirichlet-function/#respond Mon, 11 Feb 2019 05:41:33 +0000 http://www.anujvarma.com/?p=5555   I often wondered what the graph of this weird function would look like…A function that equates to 1 for all rational x and equates to 0 for all irrational […]

The post Graph of Dirichlet Function appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
 

I often wondered what the graph of this weird function would look like…A function that equates to 1 for all rational x and equates to 0 for all irrational x. Aka Salt and Pepper Function.

Here is a good enough representation…it is a bunch of close dots on y=0 and y=1.

Dirichlet

The post Graph of Dirichlet Function appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/graph-of-dirichlet-function/feed/ 0
The Historical Context of Data, Using Data for Decision Making https://www.anujvarma.com/the-historical-context-of-data/ https://www.anujvarma.com/the-historical-context-of-data/#respond Wed, 02 Aug 2017 16:06:00 +0000 http://www.anujvarma.com/?p=4979 This is still in draft mode The Historical Context of Data Collected Unless we look at the ‘context’ of the data that we collect, we may be missing the big […]

The post The Historical Context of Data, Using Data for Decision Making appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
This is still in draft mode

The Historical Context of Data Collected

Unless we look at the ‘context’ of the data that we collect, we may be missing the big picture.

The Case of the top ranked Universities in the U.S.

The Case of the ‘Best Chess Player in the world’

The Case of the SAT Scores as a predictor of STEM graduation rates

The post The Historical Context of Data, Using Data for Decision Making appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/the-historical-context-of-data/feed/ 0
Statistical Fallacies https://www.anujvarma.com/statistical-fallacies/ https://www.anujvarma.com/statistical-fallacies/#respond Sun, 30 Jul 2017 21:41:17 +0000 http://www.anujvarma.com/?p=4911 Selecting a truly RANDOM Sample If you choose every person who passes you on the sidewalk, that would not be a random sample, since you would miss out the people […]

The post Statistical Fallacies appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Selecting a truly RANDOM Sample

If you choose every person who passes you on the sidewalk, that would not be a random sample, since you would miss out the people moving in vehicles. If you, likewise, stop every car on the highway, your sample will miss out on those people who do not have cars.

A truly RANDOM sample of the entire population is necessary, though hard to produce. In Statistics, RANDOM does not mean haphazard or carelessly chosen.  In fact, Random means quite the opposite – a sample that is carefully chosen to reflect the parent population.

The Size of the Sample

As discussed above, a truly random sample ensures that the information gathered, or test conducted, will be reliable.  Of course, if you only have TWO items in your random sample, that will not work. So, in addition to randomness, you also need a good SIZED sample. What’s a good size? Shouldn’t that depend on the size of the population being examined? For e.g. – for a million strong population, shouldn’t the sample size be LARGER than for a 1000 strong population?

Turns out, surprisingly, that the size (for getting a reliable sample) does not depend on the total population size. In other words, a 1000 size sample will serve equally well whether examining a 5000 strong parent population or a million strong parent population. Huh? How is that possible?

Sampling for rarely occurring events

Say – you need to provide an estimate for the number of blades of grass in a desert.  Or for the amount of rainwater that is part of the total water in the ocean.  Sounds pretty impossible right?

As long as you know a previously established AVERAGE for these measures, you can actually predict, with accuracy, what the expected outcome will be. You can predict whether you will find 1 blade or 2 blades of grass in a given area, provided the average from a previous year was provided to you. This is the poisson distribution.

Medical Test Success Rates, What sounds like 95% success (rates) is actually just 9% success rates

Suppose, a medical test was found for detecting a disease (say Alzheimer’s), which was 95% reliable. If this test was applied to a group of people where approximately 0.5% actually had Alzheimer’s, what do you think is the probability that a patient with a positive test result ACTUALLY has Alzheimer’s? If you said 95%, you would be off. The actual probability of a positive test correlating to an actual Alzheimer patient, is 9% ! i.e. Out of a 100 people who test positive, only 9 will actually have the disease! How is that you ask?

The Gambler’s Fallacy, I am due to win!

In a roulette roll, a gambler notices that 19 of the last 19 rolls have all landed on RED. He reasons that BLACK is due on the next roll – since the probability of 20 consecutive RED rolls is (0.5) ^ 20 (approximately, one in a million).  So, he puts all his money on BLACK.

Of course, his reasoning is flawed. The outcome of any single roll is always 50% for RED or BLACK.  And he is betting on the outcome of a SINGLE roll.  Had he been betting (at the very start), on the chances of 20 consecutive RED rolls, he might have had a point. That chance would be 1 in a million. But now that 19 rolls have already taken place, all he is doing is betting on the chance of the next roll – a SINGLE roll. And that chance is still 50%.

The post Statistical Fallacies appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/statistical-fallacies/feed/ 0
Some Cool Proofs (Books and Resources) in Math https://www.anujvarma.com/some-cool-proofs-in-math/ https://www.anujvarma.com/some-cool-proofs-in-math/#respond Sat, 10 Jun 2017 20:15:09 +0000 http://www.anujvarma.com/?p=4765 Also see my – Problem Books for Pure Math, Physics and Mathematical Physics If you are looking for some of the most important, yet elegant math proofs, look no further […]

The post Some Cool Proofs (Books and Resources) in Math appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Also see my – Problem Books for Pure Math, Physics and Mathematical Physics

If you are looking for some of the most important, yet elegant math proofs, look no further than these two books.

  • The first one – Proofs from the book –  The book is dedicated to the mathematician Paul Erdős, who often referred to “The Book” in which God keeps the most elegant proof of each mathematical theorem.
  • The second one – 100 great problems of Elementary Math – This interesting book covers 100 of the most famous historical problems of elementary mathematics. The book provides insight into the extraordinary ingenuity of some of the greatest mathematical minds of history — Archimedes, Isaac Newton, Leonhard Euler, Augustin Cauchy, Pierre Fermat, Carl Friedrich Gauss, Gaspard Monge, Jakob Steiner, and many others…

If you have any other books or online resources you would like to contribute to this list (book containing elegant proofs only), feel free to comment.

   

Web Resources

How to write proofs – with some cool examples

The post Some Cool Proofs (Books and Resources) in Math appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/some-cool-proofs-in-math/feed/ 0
Nash equilibrium, Prisoner dilemma https://www.anujvarma.com/nash-equilibrium-prisoner-dilemma/ https://www.anujvarma.com/nash-equilibrium-prisoner-dilemma/#respond Mon, 29 May 2017 22:16:45 +0000 http://www.anujvarma.com/?p=4721 Under Construction Check out also Advanced Problem Books in Math and Physics and Rare Finds in Relativity Two prisoners have been accused of the same crime and are kept in […]

The post Nash equilibrium, Prisoner dilemma appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Under Construction

Check out also Advanced Problem Books in Math and Physics and Rare Finds in Relativity

Two prisoners have been accused of the same crime and are kept in separate rooms for questioning.

  • If both confess to the crime, they both go to jail for 1 year 
  • If  only one prisoner confesses  while the other remains silent, the silent one goes to jail for 5 years – while the player who confessed goes home scot-free.
  • If both players remain silent, they are both let go without any jail time.

The post Nash equilibrium, Prisoner dilemma appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/nash-equilibrium-prisoner-dilemma/feed/ 0
Continuous (Smooth) vs Differentiable versus Analytic https://www.anujvarma.com/continuous-smooth-vs-differentiable-versus-analytic/ https://www.anujvarma.com/continuous-smooth-vs-differentiable-versus-analytic/#respond Thu, 13 Apr 2017 01:59:35 +0000 http://www.anujvarma.com/?p=4637 I had a lot of trouble distinguishing between continuous and differentiable and analytic functions… Analytic An analytic function is a function that is smooth (in the sense that it is […]

The post Continuous (Smooth) vs Differentiable versus Analytic appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
I had a lot of trouble distinguishing between continuous and differentiable and analytic functions…

Analytic

An analytic function is a function that is smooth (in the sense that it is continuous and infinitely times differentiable), and the Taylor series around a point converges to the original function in the neighbourhood of that point.

Continuous – but NOT analytic (taylor series does not converge)

A smooth function is a continuous function with a continuous derivative. Some texts use the term smooth for a continuous function that is infinitely many times differentiable (all the n-th derivatives are thus continuous, since differentiability implies continuity). The existence of all derivatives doesn’t imply that the Taylor series converges. A famous example is the function

    \[f(x)=\exp\left(\frac{-1}{x^2}\right) \text{ if } x \neq 0\]

    \[f(0)=0\]

This function is continuous and infinitely many times differentiable in x=0. The Taylor series around this point is the constant function T(x)=0, so the Taylor series doesn’t converge to the function f(x) in the neighborhood of 0.

Complex Sequences and Analytic Approximations thereof

Suppose we know the values of a complex analytic function f at all x+iy, for x,y\in\mathbb{Z}. Can we uniquely determine f?

 

The Weierstrass factorization theorem asserts that for any sequence \{a_n\} of nonzero complex numbers with |a_n| \to \infty, there is a nontrivial analytic function f whose zero set is precisely \{a_n\}. Clearly we can enumerate all the nonzero points a_n of the integer lattice in such a way that |a_n| \to \infty, so there is a nontrivial analytic f vanishing at all those points. Then the function z f(z) is also not the zero function, but vanishes at all those points and 0 as well.<

The post Continuous (Smooth) vs Differentiable versus Analytic appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/continuous-smooth-vs-differentiable-versus-analytic/feed/ 0
The magic of Complex numbers https://www.anujvarma.com/the-magic-of-complex-numbers/ https://www.anujvarma.com/the-magic-of-complex-numbers/#respond Sun, 12 Mar 2017 18:51:32 +0000 http://www.anujvarma.com/?p=4589 Check out also – Problems In Advanced Math and Physics and Rare Finds in Special and General Relativity Why are complex numbers so useful in the natural sciences? Analyticity (harder […]

The post The magic of Complex numbers appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Check out also – Problems In Advanced Math and Physics and Rare Finds in Special and General Relativity

Why are complex numbers so useful in the natural sciences?

Analyticity (harder to do without complex numbers)

Analytic functions can be expanded in Taylor series in their region of analyticity. Which means that, in that region, derivatives of all orders exist. This is important to physicists and applied mathematicians. With an expansion, one can find the co-efficients and arrive at a ‘number’ for the value of the function at a point (which, in the general case, is not always easy).

Now, prior to complex numbers, analyticity was difficult to establish. There was no consistent way except calculating all the order derivatives and seeing if they existed. With complex numbers, the magic is that if the FIRST order derivative of the complex function exists, then, the function is guaranteed to be analytic! So – all you do is – take your real function – write it’s complex equivalent – and check for the first derivative (which is essentially checking for two real derivatives via the Cauchy Riemann equations). If these two real derivatives exist – life is good – and you can safely expand the function around a point in the region of analyticity.

\frac {df}{dz}(z_0) = lim_{h->0} \frac{f(z_0 + h) - f(z)}{h}

Integration (also harder to do without complex numbers)

Certain integrals like \int_{-\infty}^{\infty} \frac{sin(x)}{x} are difficult to do in the real number system. In the complex world, thanks to contour integration, you can simply ‘extend’ the real function into complex space – and use the following useful theorems to calculate the integral.

  1. Closed Loop Theorem – \oint f(z) dz = 0
  2. Residue Theorem – \oint f(z) dz = 2\pi i \Sigma Residues

The connection with \exp and \pi

This is probably the most magical thing about complex numbers. e^{i\pi} = -1 which is a specific case of Euler’s identity, e^{ix} = \cos(x) + i\sin(x) somehow connects two of the most important natural constants – e and \pi – with the simple introduction of an imaginary exponent.

This has far reaching consequences – and one can find infinite roots of unity using this identity. Infinite Roots! Of the innocent looking number 1 – which, as per REAL analysis, should have just one root – 1!

Summary

Next time someone asks you – What’s the big deal about complex numbers, throw this at them.  It has magically solved some of the toughest challenges facing physicists and applied mathematicians. It also magically connects completely unrelated natural constants.

The post The magic of Complex numbers appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/the-magic-of-complex-numbers/feed/ 0
pigeonhole principle problem solving https://www.anujvarma.com/pigeonhole-principle-problem-solving/ https://www.anujvarma.com/pigeonhole-principle-problem-solving/#respond Sat, 11 Mar 2017 18:26:53 +0000 http://www.anujvarma.com/?p=4574 Suppose 82 students are enrolled in a college – offering only 4 courses. Suppose that each course has 3 sections – and a student can choose any one of three […]

The post pigeonhole principle problem solving appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Suppose 82 students are enrolled in a college – offering only 4 courses. Suppose that each course has 3 sections – and a student can choose any one of three sections. Show that at least TWO students have to share a section!

Solution

The solution is simple if we use the Pigeon Hole Principle. If you have 10 pigeons and only 9 pigeon holes, then two pigeons must share a hole. Sounds obvious – but it has some cool implications.

4 courses with 3 sections each – means that the total possible combinations that a student can make for a section are (one of 3 sections) x (one of 3 sections) x (one of 3 sections) x (one of 3 sections).

That’s 3 ^ 4 = 81 possible picks. So – each student has 81 possible picks – even if 81 students pick distinct sections – there will still be a section left over.

Thus, two students MUST share a section.

The post pigeonhole principle problem solving appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/pigeonhole-principle-problem-solving/feed/ 0