# Digit Math Application: Proving that all numbers ending with 5 are divisible by 5

Please read Digit Math: Introduction before you continue.

# The problem

It seems I have developed a fascination for the number 5, so here we go again. Here I would be using Digit Math to prove that all integers  which end with digit 5 are always divisible by 5.

# The proof

### Case 1:

Take a two digit number $$x\omega 5$$, i.e. $$x$$ has only one digit.

$$x\omega 5$$ is divisible by 5, if $$x\omega 5 \times \frac 1 5$$ (i.e. $$x \omega 5 \times 0.2$$) leave no remainder.

So, $$x\omega 5 \times 2$$ must end with one zero.

\begin{align} &x\omega5 \times 0\omega2\\ &= 0 \omega 2x \omega 10\tag{Using Bimultiplication}\\ &= (2x + 1) \omega 0\tag{1} \end{align}

Since (1) ends with zero so it is proved.

### Case 2:

$$x\omega 5$$ is a number where $$x$$ has $$n$$ digits.

Multiplying $$x\omega 5$$ by $$10^{(n-1)}$$ to make both sides of $$\omega$$ equal in number of digits.

So,

\begin{align} &x\omega (5 \times 10^{n-1}) \times 0 \omega (2\times 10^{n-1})\\ &= 0 \omega (2x\times 10^{n-1})\omega (10\times 10^{n-1})\\ &= (2x\times 10^{n-1})\omega 10^n\\ &= (2x\times 10^{n-1} + 1) \omega ]0[^n\tag{Moving extra 1 to left} \end{align}

In the above equation it is easy to see that the result ends with $$10$$ after we divide the $$10^{n-1}$$. Therefore, this is not going to leave any remainder. (Proved)

### Case 3:

$$\frac 5 5 = 1$$. (Proved)

Yeah, this is a trivial case, but for the sake of completeness.

# Check out other applications of Digit Math

Link to list of other applications of Digit Math.

# Digit Math Application: Proving the correctness of shortcut method to squaring numbers ending with 5

Please read Digit Math: Introduction before you continue.

# The problem

Someday, somewhere I came to know that any number which ends with the digit 5 can be easily squared. The trick can be easily demonstrate using an example. Suppose we want to find the square of 25.

Trick is to take the number before 5 (which will be 2 here), add one to it (2 + 1 = 3) and then multiply them together (2 x 3 = 6). Now the final answer would be the product followed by the number 25, i.e. 625 in this case.

Now let’s try it out yo find $$215^2$$.

\begin{align} 215^2 &= (21 \times (21 + 1)) \omega 25\\ &= (21 \times 22) \omega 25\\ &= 462\omega25\\ &= 46225\tag{Answer} \end{align}

This always seemed to work out very well. The problem was, can I trust this trick? Will this always hold true? I didn’t have answers to those questions, until I proved it myself using Digit Math. Good news is that this trick will always hold true.

# The proof

Let the number be $$x = a\omega 5$$.  $$a$$ can have any number of digits.

### Case 1:

$$a$$ has exactly one digit. So, $$]a[ = ]5[ = 1$$.

\begin{align} \therefore (a\omega 5)^2 &= aa\omega (5a+5a) \omega 5.5\tag{Using Bimultiplication formula}\\ &= a^2 \omega 10a \omega \underline{2}5\\ &= a^2 \omega (a\omega0) \omega \underline{2}5\\ &= a^2 \omega (a\omega2) \omega 5\\ &= (a^2 + a) \omega 2 \omega 5\\ &= \big(a(a+1)\big) \omega 25\tag{Proved} \end{align}

### Case 2:

$$a$$ has more than one digits. So, $$]a[ > (]5[ = 1)$$.

But to apply Bimultiplication formula $$a$$ must have the same number of digits in $$5$$, which is obviously not the case here. So, we will use one trick. We will pad $$5$$ with some number of zeroes on the right, so that, $$]a[ = ]5\omega c[$$, where, $$c$$ is all zeroes and $$]c[ = ]a[ – 1$$. So, if $$a = 123 \Rightarrow c = 00$$.

\begin{align} \therefore (a\omega 5)^2 &= \big(a \omega ]5 \omega c[^{]a[}\big)^2\\ &= a^2 \omega \big(a(5\omega c) + a(5\omega c)\big) \omega (5\omega c)^2\tag{Using Bimultiplication}\\ &= a^2 \omega 2a(5\omega c) \omega (5\omega c)^2\\ &= a^2 \omega (10a \omega 2ac) \omega (5\omega c)^2\\ &= a^2 \omega (10a \omega c) \omega (5\omega c)^2\tag{Since, c is all zeroes}\\ &= a^2 \omega (a \omega 0 \omega c) \omega (5\omega c)^2\\ &= a^2 \omega (a \omega 0 \omega c) \omega (25 \omega 10c \omega c^2)\\ &= a^2 \omega (a \omega 0 \omega c) \omega (25 \omega c \omega c)\tag{1} \end{align}

Since each digit group must have $$]a[$$ digits, so let us move one zero from the middle $$c$$ in $$25 \omega c \omega c$$ to the rightmost $$c$$. So, now that group becomes $$25\omega d\omega e$$, where $$]d[ = ]c[ – 1$$ and $$]e[ = ]c[ + 1$$.

\begin{align} \therefore (1) &= a^2 \omega \big( (a \omega 0 \omega c) + (25 \omega d)\big) \omega e\\ &= a^2 \omega \big( a \omega (0+25) \omega (c+d) \big) \omega e\\ &= a^2 \omega ( a \omega 25 \omega d ) \omega e\tag{2} \end{align}

Now,

\begin{align} ]25 \omega d[ &= ]25[ + ]d[\\ &= 2 + (]c[ – 1)\\ &= 2 + \big((]a[ – 1) – 1\big)\\ &= ]a[ \end{align}

So, in the group $$a \omega 25 \omega d$$, $$a$$ is excess.

\begin{align} \therefore (2) &= (a^2 + a) \omega (25 \omega d) \omega e\\ &= a(a+1) \omega 25 \omega d \omega e\\ &= a(a+1) \omega 25 \omega c \omega c\tag{Shifting a zero from e to d}\\ \end{align}

So finally,

\begin{align} &(a\omega 5 \omega c)^2 = a(a+1) \omega 25 \omega c \omega c\\ &\Rightarrow \big((a\omega 5) \times 10^c\big)^2 = \big(a(a+1) \omega 25 \omega c\big) \times 10^c\\ &\Rightarrow (a\omega 5)^2 \times 10^{2c} = \big(a(a+1) \omega 25\big) \times 10^{2c}\\ &\Rightarrow (a\omega 5)^2 = a(a+1) \omega 25\tag{Proved} \end{align}

So, we see that this trick is applicable for all kinds of whole numbers that end with 5.

# Check out other applications of Digit Math

Link to list of other applications of Digit Math.

# Digit Math Application: Proving that multiplying with 10**n puts n zeros at the end

Please read Digit Math: Introduction before you continue.

# The problem

This is a very fundamental concept that we were taught when we were in junior schools. Now, think of it, what it says. If you add $$x$$ ten times then you will get $$x\omega0$$. If you add $$x$$ hundred times then you will get $$x\omega00$$; and so on. How do we know that this will always be true? We know it since we have never seen one violation of it, but, anyway I will try to prove it know to rest the uneasy souls.

# The proof

Before I continue with this proof, I must make sure we understand another empirical rule.

When any number is multiplied by zero then the result is always zero. This is not hard to see why. When you multiply $$x$$ by $$2$$ then it is like adding $$x$$ twice. When you multiply $$x$$ by $$1$$ then it is like adding $$x$$ once. When you multiply $$x$$ by $$0$$ then it is like adding $$x$$ zero times, which in other words is that we never added $$x$$ in the first place so $$x$$ never existed, so we had nothing, and that nothing is zero.

Back to proof.

Let the number $$a\omega b$$ be multiplied by $$1\omega d$$, where $$d$$ is all all zeroes, $$n$$ times. To use Bimultiplication forumula we need to make sure that $$b$$ too has $$n$$ digits. We can always partition a number such that $$b$$ will always have $$n$$ digits. For example if $$d = 000$$ and $$a\omega b = 2$$ then we make $$a = 000$$ and $$b = 002$$.

So,

\begin{align} & a \omega b \times 10^d\\ &= a \omega b \times 1 \omega d\\ &= a.1 \omega (a.d + b.1) \omega b.d\tag{By Bimultiplication}\\ &= a \omega (d + b) \omega d\tag{Since d is all zeroes}\\ &= a \omega b \omega d\tag{Since d is all zeroes} \end{align}

So, in the above equations we see that multiplying a number by $$10^d$$ will give us the same number, but followed with $$d$$ zeroes. (Proved)

# Check out other applications of Digit Math

Link to list of other applications of Digit Math.

# Digit Math: Introduction

The person in the above image is Bertrand Russell. Famous Mathematician and Logician.  An excellent graphic novel, Logicomix, is based around his life. That is a must read.

First thing first. Even if you are not a Math demi-god, it is fine, Digit Math is still for you. In fact my academic track record shows that I barely survived Mathematics! I invented this thing when I was in standard eleventh while trying to create some shortcut formula, because I kept forgetting long formulae and was very slow in arithmetic. Digit Math is a slightly different approach to classical Math. To understand this all you need to know is how to add and multiply, and a little bit of logic. That is it.

# What is Digit Math?

Numbers are group of digits. Classical Mathematical operators is not meant to deal with part of the number. Digit Math allows that. You can interact with a single digit or a group of digits in a number. You might wonder, what is the use? Well, I would say, for fun. Like puzzles, this too forces you to think differently. It is not all nonsense fun though.

Can you prove that any number which ends with 5 must be divisible by 5? Well try that using classical Math. I have used Digit Math to prove the same. There some more empirical facts which I have proved using Digit Math. One of that is proving that multiplying any number by $$10^n$$ will indeed give us that number but followed by $$n$$ zeroes. This might look obvious to you, but think, why does adding $$6$$ $$100$$ times yields $$600$$.

# Before we begin…

Before we begin I must list out the notations and symbols I would be using. They were introduced specifically for this, since I know of no existing symbols which convey the same information.

## Symbols and Operators

I would be using these symbols throughout the articles on Digit Math, so pay attention to them.

### $$\omega$$ (With-operator)

This is the main operator, which delimits the digits or groups of digits. I call this ‘with-operator’. So, 251 can be written as $$2\omega51$$ (spoken as two-with-fifty-one) or $$25\omega1$$ (spoken as twenty-five-with-one) or $$2\omega5\omega1$$ (spoken as two-with-five-with-one) or even $$0\omega251$$. They all are the same, only the digit partitioning is different. How you partition depends on the problem at hand.

### $$]x[$$ (Digit Group operator)

This is used in multiple ways. Its primary use is to group digits into a digits group. While in $$2\omega51$$ it is quite clear that 2 and 51 are different digit groups of one and two digits respectively, but sometimes we need to convey more information about a digit group.

• $$]x[$$ – This is equal to the number of digits in x, when used on its own. So, $$]25[ = 2$$.
• $$]x[^y$$ – This means that x should have y digits. Note that I said ‘should’ have. So, it is possible that while problem solving, at intermediate steps we can have less or more digits. Eventually, the final result must have exactly y digits. This kind of notation is usually used when actual value of x is not known and x is part of a bigger number. So, $$2\omega]x[^2$$ means that this is a number which starts with 2 but ends with two digits.
• Underline notation – Take the example of $$2\omega]345[^2$$. Here 3 is the extra digit in this digit group which has the maximum capacity of two digits. In this case since all the digits are known, so here we can use a short-hand notation of underlining the excess digit in the group. So, $$2\omega]345[^2 = 2\omega\underline{3}45$$. (Note that 3 is underlined.)

### $$\omega\sum$$ (Digits summation operator)

So,$$\omega\sum_{i=1}^3a_i = a_3{\omega}a_2{\omega}a_1$$

Note that $$a_1$$ is the leftmost item and $$a_3$$ the rightmost. Maintaining the sequence in digitized equations is of massive importance.

## Precedence of With-operator

$$\omega$$ has lower precedence than multiply and division. So the full operator precedence would be

B – Bracket
O – Orders (powers, roots, etc.)
M – Multiply
D – Divide
W – With ($$\omega$$)
A – Add
S – Subtract

## Properties of With-operator

• This is not commutative. This is because, $$2\omega5 = 25 \neq 52 = 5\omega2$$.
• This is associative, but only when none of the digit groups have excess digits. That is, less number of digits than required is tolerated. So, $$a\omega(b{\omega}c) = (a{\omega}b){\omega}c$$.
• This is distributive, but only when all digit groups have the exact number of digits. So, less digits is not tolerated here. So, $$n \times (a{\omega}b) = (na)\omega(nb)$$.

## Some Important Formulae

### General formula of transformation

This provides the relation between a normal equation and a digitized equation.

So,$$\omega\sum_{i=1}^{n}a_i = \sum_{i=1}^{n}a_i \times {10}^{n-i}$$

Provided $$a_i$$ has one digit only (i.e. $$]a_i[ = 1$$). This is not hard to see, how the above is true.

### Bi-multiplication formula

This formula is vital. This describes how the groups of digits behave when they are multiplied. This starts with how we usually manually multiply two numbers.

\begin{align} x\omega y&\\ \underline{\times\hspace1em a\omega b}&\\ bx\omega by&\\ ax \omega ay\hspace1.5em&\\ \overline{ax\omega (ay+bx)\omega by}& \end{align}

So,

$$\underline{x \omega y \times a \omega b = ax \omega (ay+bx) \omega by}\tag{bi-multiplication formula}$$

The above relation is pretty easy to understand, but it does say how many digits should be in each group (digits separated by $$\omega$$). To understand this, try multiplying 12 by 34, the manual way. This would be like

\begin{align} 1\omega 2&\\ \underline{\times\hspace1em 3\omega 4}&\\ 4\omega 8&\\ 3 \omega 6\hspace1.5em&\\ \overline{3\omega (6+4)\omega 8}&\\ \Rightarrow 3\omega 10\omega 8&\\ \Rightarrow 4\omega 0\omega 8&\tag{adding carry over 1 from center to left group}\\ \Rightarrow 408& \end{align}

Now lets try multiplying 111 by 123.

\begin{align} 01\omega 11&\tag{prefixing with 0 to equate digit counts}\\ \underline{\times\hspace1em 01\omega 23}&\\ 23\omega 253&\\ 1 \omega 11\hspace1.5em&\\ \overline{1\omega (11+23)\omega 253}&\\ \Rightarrow 1\omega (11+23+2)\omega 53&\tag{2 is the carry over from 253}\\ \Rightarrow 1\omega 36\omega 53&\\ \Rightarrow 13653& \end{align}

So you can observe from the above scenarios that:-

$$]a\times b[ = n\hspace1em\ldots\text{where ]a[ = ]b[ = n}$$

Similarly,

$$]a + b[ = n\hspace1em\ldots\text{where ]a[ = ]b[ = n}$$

Any excess digits should be carried over to the digit group on the left and added there.

So,

\begin{align} 1&\\ \underline{+\hspace1em9}&\\ 0\omega\underline{1}0&\\ \Rightarrow (0+1)\omega0\\ \Rightarrow 1\omega0\\ \Rightarrow 10 \end{align}

If  $$]a[ \neq ]b[$$ then I am not sure what should be $$]a \times b[$$. So, we need to make sure that all digit groups have equal number of digits. This is restrictive but fortunately this does not cause problem as there is always a way around.

One more example. Let’s multiply 98 by 76.

\begin{align} 9\omega 8&\\ \underline{\times\hspace1em 7\omega 6}&\\ 54\omega 48&\\ 63 \omega 56\hspace1.5em&\\ \overline{63\omega (56+54)\omega 48}&\\ \Rightarrow 63\omega 110\omega 48&\\ \Rightarrow 63\omega (110+4)\omega 8&\tag{since max size of each group is 1}\\ \Rightarrow 63\omega 114\omega 8&\\ \Rightarrow (63+11)\omega 4\omega 8&\\ \Rightarrow 74\omega4\omega8&\\ \Rightarrow 7448& \end{align}

#### Rules for using the bi-multiplication formula

You have already witness many of the rules, but let me summarize them for clearly. For the following assume that we are multiplying $$a\omega b$$ by $$x\omega y$$.

• Make two fragments of both the numbers, by placing $$\omega$$ at the positions suitable for you. Remember, the number of digits in all the four fragments should be equal. That is, $$]a[ = ]b[ = ]x[ = ]y[$$.Partitioning $$255$$ as $$2\omega55$$ is perfectly fine, since $$]02[ = ]55[ = 2$$.
• If the number of digits in $$by$$ or $$ay+bx$$ terms are less than the required number then insert zeroes in front of them to get the exact number of digits.
• If the number of digits in $$by$$ or $$ay+bx$$ terms are more than the required number then remove the excess digits from the front (left) of them and add these excess digits to the group on left. Note, that shifting of excess digits (carry over) should started from the rightmost group and then progress towards left sequentially.
• When all the above conditions are met then you are good to remove the $$\omega$$ (with-operator).

So, finally the bi-multiplication formula can be precisely expressed as,

$$\boxed{x \omega y \times a \omega b = ax\hspace2pt\omega\hspace2pt]ax+by[^n\hspace2pt\omega\hspace2pt]by[^n}\hspace1em\ldots\text{where ]a[ = ]b[ = ]x[ = ]y[ = n}$$

### Squaring formula

This is directly derivable from bi-multiplication formula.

\begin{align} (a \omega b)^2&\\ \Rightarrow& a \omega b \times a \omega b\\ \Rightarrow& \boxed{a^2\omega ]2ab[^n \omega ]b^2[^n}\hspace1em\ldots\text{where ]a[ = ]b[ = n} \end{align}

### General Powering Formula

For now I will provide only the formula. The proof is provided later in this article. The way I derived it was to I manually find the values of $$(a\omega b)^2$$, $$(a\omega b)^3$$, $$(a\omega b)^4$$ and so on. I found a pattern in all these and from there I got this formula. It was later when it struck me as to how to prove it.

$$\boxed{(a\omega b)^n = \omega\sum_{r=0}^n\hspace1em{]^nC_r \times a^{(n-r)} \times b^r[}^d}\hspace1em\ldots\text{where ]a[ = ]b[ = d}$$

Notice that the above equation looks very similar to Binomial equation. In fact I found this to be true for many equations. If we replace $$+$$ by $$\omega$$ then we end up with a ‘digitized’ version of that equation.

Now let me demonstrate how to use this equation. Let’s find cube of 99, i.e. $$99^3$$.

\begin{align} &(9\omega9)^3\\ &= ]^3C_0 \times 9^3 \times 9^0[^1 \omega ]^3C_1 \times 9^2 \times 9^1[^1\\ &= 9^3 \omega 3\times9^3 \omega 3\times9^3 \omega 9^3\tag{for brevity removing ].[ operator}\\ &= 729 \omega \underline{218}7 \omega \underline{218}7 \omega \underline{72}9\\ &= 729 \omega \underline{218}7 \omega \underline{225}9 \omega 9\tag{adding carry overs}\\ &= 729 \omega \underline{241}2 \omega 9 \omega 9\\ &= 970 \omega 2 \omega 9 \omega 9\\ &= 970299 \end{align}

I didn’t underline the excess digits in leftmost group, since that is anyway not going to affect the result. Now let us find $$241^4$$.

\begin{align} &(02\omega41)^4\\ &= \omega\sum_{r=0}^4\hspace1em]^4C_r \times 2^{(4-r)} \times 41^r[^2\\ &= ^4C_0.2^4\hspace0.5em\omega\hspace0.5em^4C_1.2^3.41\hspace0.5em\omega\hspace0.5em^4C_2.2^2.41^2\hspace0.5em\omega\hspace0.5em^4C_3.2.41^3\hspace0.5em\omega\hspace0.5em^4C_4.41^4\\ &= 16\omega\underline{13}12\omega\underline{403}44\omega\underline{5513}68\omega\underline{28257}61\\ &= 16\omega\underline{13}12\omega\underline{403}44\omega\underline{5796}25\omega61\\ &= 16\omega\underline{13}12\omega\underline{461}40\omega25\omega61\\ &= 16\omega\underline{17}73\omega40\omega25\omega61\\ &= 33\omega73\omega40\omega25\omega61\\ &= 3373402561 \end{align}

Note, one important observation. Here you can immediately identify the last couple of digits of the final result by evaluating for the last term. Unlike in Binomial Theorem, where all the terms need to be added. So, there at least last few digits of all the terms need to be added to get the  last few digits of the final result. This is an advantage for General Powering formula, but unfortunately we cannot say the for other digit groups which are at higher place order. The reason is simple, they may have to be added with carry-overs from the groups (terms) on the right.

## A corollary of the General Formula of Transformation (for two digits)

### With to Plus form

$$a\omega b = 10a+b$$

The above equation is true only when $$b$$ has one digit. The more general equation is:-

$$\boxed{a\omega b = a.10^d+b}\hspace1em\text{where d}=]b[\hspace1em\ldots\text{Corollary 1}$$

### Plus to With form

$$a\omega b = 10a +b \Rightarrow a\omega b = 9a + a + b \Rightarrow \boxed{a+b = a\omega b -9a}\hspace1em\ldots\text{Corollary 2}$$

### Negative digits

We all are aware of negative numbers but in digit equations we might end up with negative digits! I see no physical significance of that but let’s try to find out some mathematical meaning of this.

\begin{align} a\omega(-b) &= 10a + (-b)\\ &= 10a -b\\ &= 10a + b -2b\\ &= a\omega b -2b \end{align}

Altire,

\begin{align} a\omega(-b) &= -(-10a + b)\\ &= -(10a+b -20a)\\ &= -(a\omega b – 20a)\\ &= -(a\omega b) +20a \end{align}

$$\therefore \boxed{a\omega(-b) = a\omega b-2b = -(a\omega b)+20a}$$

Remember, $$(-a)\omega b \neq -(a\omega b)$$. The former means that only the digit $$a$$ is negative. The later means that the complete number is negative.

Similarly,

$$\boxed{(-a)\omega b = a\omega b-20a = -(a\omega b)+2b}$$

Also similarly evaluating, we get,

$$\boxed{(-a)\omega(-b) = -(a\omega b)}\hspace1em\ldots\text{Corollary 3}$$

So, we see that in a negative number all the digits too are negative. Not surprising, since in a positive number all digits are positive.

## Proof of General Powering Formula

Since I already know this formula, so I just need to prove that it is correct. For this the best tool is Mathematical Induction. So, the formula to prove is

$$(a\omega b)^n = \omega\sum_{r=0}^n\hspace1em{]^nC_r \times a^{(n-r)} \times b^r[}^d$$

### Case 1: n = 0

So,

\begin{align} L.H.S. &= (a\omega b)^0 = 1\\ \\ \\ R.H.S. &= \omega\sum_{r=0}^0\hspace1em ^0C_r \times a^{(0-r)} \times b^r\\ &= 1\times a^0 \times b^0\\ &= 1\tag{Proved} \end{align}

### Case 2: n = 1

\begin{align} L.H.S.&= (a\omega b)^1 = a\omega b\\ \\ \\ R.H.S. &= \omega\sum_{r=0}^1\hspace1em ^1C_r \times a^{(1-r)} \times b^r\\ &= ^1C_0. a^1. b^0 \omega ^1C_1.a^0.b^1\\ &= a\omega b\tag{Proved} \end{align}

### Case 3: For n

Suppose that the formula is true for all values of $$n$$, then by Mathematical Induction, the formula must be valid for $$n+1$$ too.

So,

\begin{align} &(a\omega b)^{(n+1)}\\ &= (a\omega b)^n \times (a\omega b)\\ &= (a\omega b)^n \times (a\times 10^d+b)\hspace1em\ldots\text{where d}=]b[\tag{By Corollary 1}\\ &= 10^da\times(a\omega b)^n + b\times (a\omega b)^n\\ &= 10^da\times(\omega\sum_{r=0}^n\hspace1em ^nC_r\times a^{(n-r)} \times b^r) +\\ &\hspace2em b\times(\omega\sum_{r’=0}^n\hspace1em ^nC_{r’}\times a^{(n-r’)} \times b^{r’}) \tag{Since formula is correct for n}\\ &= 10^d\times(a^{(n+1)} \hspace2pt\omega\hspace2pt \omega\sum_{r=1}^n\hspace1em ^nC_r\times a^{(n+1-r)} \times b^r) +\\ &\hspace2em(\omega\sum_{r’=0}^{(n-1)}\hspace1em ^nC_{r’}\times a^{(n-r’)} \times b^{(r’+1)} \hspace2pt\omega\hspace2pt b^{(n+1)})\tag{1} \end{align}

Since $$]a[\hspace2pt=\hspace2pt]b[\hspace2pt=\hspace2pt d$$, so every term of $$\omega\sum$$ too will have $$d$$ digits, as per General Powering Formula. This implies that term $$b^{(n+1)}$$ in equation (1) too has $$d$$ digits. So, if we can rewrite (1) as below:-

\begin{align} a^{(n+1)} \hspace2pt\omega\hspace2pt&\omega\sum_{r=1}^n\hspace1em ^nC_r\times a^{(n+1-r)} \times b^r\tag{2}\\ +\hspace2em\hspace2em &\omega\sum_{r’=0}^{(n-1)}\hspace1em ^nC_{r’}\times a^{(n-r’)} \times b^{(r’+1)} \hspace2pt\omega\hspace2pt b^{(n+1)}\tag{3}\\ a^{n+1} \hspace2pt\omega\hspace2pt & \overline{\omega\sum_{r=1}^n\hspace1em {^nC_r\times a^{n+1-r} \times b^r \brace + ^nC_{(r-1)}\times a^{n-(r-1)} \times b^{(r-1)+1}} \hspace2pt\omega\hspace2pt b^{n+1}}\\ \Rightarrow a^{n+1} \hspace2pt\omega\hspace2pt &\bigg( \omega\sum_{r=1}^n\hspace1em ^nC_r\times a^{n+1-r} \times b^r + ^nC_{r-1}\times a^{n+1-r} \times b^{r}\bigg) \hspace2pt\omega\hspace2pt b^{n+1}\tag{4} \end{align}

Notice that in the above, I have removed the $$10^d$$ factor since all it did is to shift its term by $$d$$ digits to left, that is, by exact number of digits in the $$b^{(n+1)}$$ group. After removing the first digit group from equation (2) and last digit group from equation (3), $$\omega\sum$$ in both the equations have $$n-1$$ digit groups left. Each of these digit groups will get added term by term, i.e. group $$1$$ of (2) will get added to group $$0$$ of (3) and so on. So this implies $$r’ = r – 1$$.

Further simplifying,

\begin{align} (4)&= a^{n+1} \hspace2pt\omega\hspace2pt \bigg(\omega\sum_{r=1}^n\hspace1em a^{n+1-r}.b^r(\frac{n!}{r!(n-r)!}+\frac{n!}{(r-1)!(n-r+1)!})\bigg) \hspace2pt\omega\hspace2pt b^{n+1}\\ &= a^{n+1} \hspace2pt\omega\hspace2pt \bigg(\omega\sum_{r=1}^n\hspace1em a^{n+1-r}.b^r.\frac{(n+1)!}{r!(n+1-r)!}.(\frac{n+r-1}{n+1}+\frac{r}{n+1})\bigg) \hspace2pt\omega\hspace2pt b^{n+1}\\ &= a^{n+1} \hspace2pt\omega\hspace2pt \bigg(\omega\sum_{r=1}^n\hspace1em a^{n+1-r}.b^r.^{n+1}C_r.(1)\bigg) \hspace2pt\omega\hspace2pt b^{n+1}\\ &= \bigg(C_0^{n+1}.a^{n+1-0}.b^0\bigg) \hspace2pt\omega\hspace2pt \bigg(\omega\sum_{r=1}^n\hspace1em C_r^{n+1}.a^{n+1-r}.b^r\bigg) \hspace2pt\omega\hspace2pt \bigg(C_{n+1}^{n+1}.a{(n+1-(n+1))}.b{n+1}\bigg)\\ &= \omega\sum_{r=0}^{(n+1)}\hspace1em ^{(n+1)}C_r.a^{(n+1)-r}.b^r\\ \end{align}

So, proved that $$(a\omega b)^{(n+1)} = \omega\sum_{r=0}^{(n+1)}\hspace1em ^{(n+1)}C_r.a^{(n+1)-r}.b^r$$ when $$(a\omega b)^n = \omega\sum_{r=0}^n\hspace1em ^nC_r.a^{n-r}.b^r$$.

So, all cases proved.

# Application of Digit Math

Now time to see Digit Math in action. I will be using this to prove some empirical concepts.

Link to list of applications of Digit Math.

# CInk version 2 finally released!

Finally CInk version 2 has been released.

## Some key new things

• New website with complete API documentation and guides on how you can use CInk JS code.
• Finally released the full source code of CInk renderer and compiler. License – GPL v3.
• CInk finally supports all the features of original CFDG, including Paths.
• CInk has introduced support for texts which extends the capabilities of CFDG considerably. Check out the cool demo – Neon Letters. To learn more about it see – “Text transforms” section here.

Last but not the least, you can post comments on CInk website. The comments section is at the bottom of each page.

# Create your own Cyberoam client in Python!

This is a very old post. Reposting it since while migrating it from blogger.com to here it got lost. Found it recently. Not sure how relevant or correct is this now.

 Cyberthon updated to version 2.5 by Vinit and Siddhartha Sahu:- Get the latest code from https://github.com/siddharthasahu/Cyberthon-enhanced.
 Cyberthon updated to version 1.2:- Added a new feature in this version. Now Cyberthon won’t exit ever, once started, even when it can’t connect to Cyberoam server. If liked its old behavior then set never_quit to False
 Code fixed now. Sorry, I didn’t notice before (for 2 months since posting it here) that the code here was not working. I think it is fixed now. The problem was that the tabs were being expaded here differently. So, I just ran expand cyberthon.py command to expand all tabs in it beforehand.

My college uses the software Cyberoam for controlling the bandwidth and timing allocated to us for surfing the internet. If you don’t know what is it then visit here. So, to access the internet we all need to install the client software and login via that. But I don’t like to install it because it feels like a college spy on my computer, you may find it irrational but I can’t help being a paranoid. I have always used the web login page of Cyberoam but it is not a very good solution, first because I will always need to keep the browser open. (The Cyberoam page refreshes at a specific time periodically. If it fails to do so then you get logged out.) Second problem is that on my Linux platform if I work from console mode then I can’t login because no browser can run without GUI support (I know of Lynx but I haven’t been able to use it for it.)

Recently I thought of investigating the working of the web login page of Cyberoam. After bringing up the login page of Cyberoam I changed the value of attribute method of form tag to GET from POST. So after filling-up the username and password when I hit enter key, there it was all the details that are sent from my browser to Cyberoam server in my browser address bar. I thought of simulating the POST action using a Python code. It required only a pinch of Python to do this. I tried the following Python code to simulate that and it worked, as it should. You too can try the following code and login to Cyberoam.

Code:

[code lang=”python” wraplines=”false”]
import urllib
urllib.urlopen("http://192.168.5.10:8090/corporate/servlet/CyberoamHTTPClient","mode=191&isAccessDenied=null&url=null&message=&username=YourUserName&password=YourPassword&saveinfo=saveinfo&login=Login")[/code]

Be sure to substitute YourUserName and YourPasswordfor your username and password respectively. The above will get you logged in but won’t keep you logged it because you need to re-post the login data at every (usually) 3 minutes. So, I got down to work again. Below is quick and dirty shell script to get around this problem. Note the above code has been distorted and compressed into single line and passed via piping to Python in script below.

Code:

[code lang=”bash” wraplines=”false”]
while [[ 1 == 1 ]]
do
printf "%s\n%s\n" "import urllib" "urllib.urlopen(\"http://192.168.5.10:8090/corporate/servlet/CyberoamHTTPClient\",\"mode=191&isAccessDenied=null&url=null&message=&username=YourUserName&password=YourPassword&saveinfo=saveinfo&login=Login\")" |python
sleep 3m
done[/code]

Again in the above code do replace YourUserName and YourPassword for your actual username and password respectively. Well now it was working great. 🙂 As usual I was again not satisfied because how will I know if I have logged in successfully or not? The only way for that was by parsing the returned page after logging-in for the message. I noticed that returned page’s source code contained…

[code lang=”html”][/code]

Please notice the part message. The value after that is the message I was seeking. So, all I needed is to parse this page for the value of attribute src of the tag frame. Also, note this very string also contains some more very useful values, viz. – loginstatus and liverequesttime. I noticed that value of loginstatus becomes true when logged in otherwise it remains false, and the value of liverequesttimegiave the time (in seconds) in which to re-post the login data.

The HTML parsing class in the Python script (which I wrote) below is based on the code from the great HTML parsing tutorial located here. Note the script uses the zenity command to display GUI dialog boxes. If you do not have this installed or simply don’t want to display GUI dialog boxes then start the script with -nogui argument. If you want the script to remain completely silent then use the -silent argument. I call this script Cyberthon (=Cyberoam+Python) 😉

Requirement(s):-
1) Python 2.5 (may work with previous versions, but not tested)
2) Zenity (needed to show the dialog boxes, use -nogui switch if you want the messages to appear on the console.)
Code:

[code lang=”python” wraplines=”false”]#!/usr/bin/python
#!/usr/bin/python

#Program Name: Cyberthon (Python Cyberoam Client)
#Coder AppleGrew
#License GPL
#Version 1.2
cyberroamIP = "192.168.5.10" #The IP of the Cyberoam site.
cyberroamPort = "8090" #Set to "" if not using.
username = "your_username" #Your username
passwordFile = "/home/you/.passwd" #Path file containing a single string, your password.
sleeptime = 0 #in minutes or set to 0, it will then parse this value from the cyberoam returned page dynamically.
never_quit = True #Once started cyberthon will never, even when the cyberoam server cannot be connected.

import sys

silent = False
nogui = False
for arg in sys.argv:
if "-silent" == arg:
silent = True
if "-nogui" == arg:
nogui = True

#Parsing and logging in too.
import sgmllib

class MyCyberroamParser(sgmllib.SGMLParser):
"A simple parser class."

def parse(self, s):
"Parse the given string ‘s’."
self.feed(s)
self.close()

def __init__(self, verbose=0):
"Initialise an object, passing ‘verbose’ to the superclass."

sgmllib.SGMLParser.__init__(self, verbose)
self.required_entities = [‘message’,’loginstatus’,’liverequesttime’]
self.frames_attr = []
self.in_required_entity = False
self.current_entity = ""
self.entity_values = {}

def do_frame(self, attributes):
for name, value in attributes:
if name == "src":
self.frames_attr.append(value)

def unknown_entityref(self,ref):
self.current_entity = ref
if ref in self.required_entities:
self.in_required_entity=True

def handle_data(self, data):
"Try to get the value of entity &message. Used in 2nd pass of parsing."

if self.in_required_entity:
self.entity_values[self.current_entity] = data[1:] #To remove the preceeding =
self.in_required_entity = False

def get_src(self,index=-1):
"Return the list of src targets."
if index == -1:
return self.frames_attr
else:
return self.frames_attr[index]

import urllib, sgmllib,time,commands,os

pf = open(passwordFile)
passwd = pf.readline()
pf.close()
if passwd[-1] == ‘\n’: #Removing terminating newline character.
passwd = passwd[:-1]

cyberroamAddress = cyberroamIP
if cyberroamPort != "":
cyberroamAddress = cyberroamAddress+":"+cyberroamPort

sec2sleep = 60*sleeptime
lastmsg = ""
msgChanged = True
lastMsgWasFailMsg = False
sec2sleepOnError = 6
while True:
try:
# Logging in and fetching the Cyberroam login page.
f = urllib.urlopen("http://"+cyberroamAddress+"/corporate/servlet/CyberoamHTTPClient","mode=191&isAccessDenied=null&url=null&message=&username="+username+"&password="+passwd+"&saveinfo=saveinfo&login=Login")
sec2sleepOnError = 6
except IOError, (errno, strerror):
if not silent:
print "Connection to Cyberoam server timed out. Error(%s): %s" % (errno, strerror)

if sec2sleepOnError > 30:
if not silent:
if nogui:
print "Quitting program."
else:
if never_quit:
if not lastMsgWasFailMsg:
os.popen(‘zenity –info –text="Failed to connect to server, but I am NOT quitting." –title="Cyberthon" >/dev/null’)
lastMsgWasFailMsg = True
else:
commands.getoutput(‘zenity –info –text="Could not connect to the server. Quitting program." –title="Cyberthon"’)
if not never_quit:
sys.exit(1)
else:
sec2sleepOnError = 6

if not silent:
print "Retrying in %s seconds" % sec2sleepOnError

time.sleep(sec2sleepOnError)
sec2sleepOnError = sec2sleepOnError*2
continue

s = f.read()

# Try and process the page.
# The class should have been defined first, remember.
myparser = MyCyberroamParser()
myparser.parse(s)

# Get the the src targets. It contains the status message. And then parse it again for entity &message.
qindex = myparser.get_src(1).index(‘?’)
srcstr = myparser.get_src(1)[:qindex+1]+’&’+myparser.get_src(1)[qindex+1:]

myparser.parse(srcstr)

message = myparser.entity_values[‘message’]
if lastmsg != message or lastMsgWasFailMsg:
lastmsg = message
msgChanged = True
lastMsgWasFailMsg = False

if (not silent) and msgChanged:
msgChanged = False

msg=”
i=0
while i < len(message): #Converting hex nos. to characters. t=message[i] if message[i]==’%’: no=int(message[i+1:i+3],16) t=chr(no) i=i+2 msg=msg+t i=i+1 message = "" for x in msg:#Changing all + to space. if x == ‘+’: x = " " message=message+x if nogui: print message else: os.popen(‘zenity –info –text="From Cyberoam: ‘+message+’" –title="Cyberthon" >/dev/null’)

if myparser.entity_values[‘loginstatus’].lower()!="true":
break;

if sleeptime==0:
sec2sleep = int(myparser.entity_values[‘liverequesttime’])
time.sleep(sec2sleep)
[/code]

Please copy the file very carefully. A single extra space here and there may throw Python haywire, making it throw up all sorts of nasty syntax errors. Paste the contents of this code in a file and name it – Cyberthon.py.