29 December 2013

Prime Factorial

While doing some random computing I accidently found out something.
(2!+1)/3=1
(3!+1)/4=Fraction
(4!+1)/5=5
(5!+1)/6=Fraction
(6!+1)/7=103
Only when the denominator is a prime the quotient will be an integer.
Let n be prime
Then ((n-1)!+1)/n will be an integer.
I computed it to really large numbers and seemed to hold.
Don't yet know if its generally true.

Update: This theorem is called Wilson's Thoerem.

21 December 2013

[C++][Project] Calculator + Automatic Syntax Checking + Complex Analysis


This is my first ever C++ coding project.The main motivation behind it was a Casio scientific calculator I once owned and I had a hard time figuring out the syntax.

I have only 2 year experience studying Borland C++ in school.So please don't go too technical in comments. This is a genuine piece of work and no code has been borrowed from anywhere.I am open to suggestions and you are free to use the code in any way you please.


Overview:

This is a scientific calculator with support for complex analysis.(support calculations and functions of complex numbers)
It automatically check for syntax errors.You can only enter valid syntax.
The program is written entirely using basic input and output manipulation techniques and inbuilt math functions.Thus it has limitations when it comes to precision and possible logical workarounds are implemented wherever possible.

Changelog:

V4.5
+Rewrote in GCC compiler

V4.4
+Very tiny Bugfix

V4.3
+Very tiny bugfix

V4.2
+Removed Gamma function for computing factorial.
+Bugfix: Inverse Cos.
+Error handling: 0th root.

V4.1
+Fixed approximation bug in complex power function.
+Changed the way evaluation code handle 'i' and '-'.

V4.0
+Optimised evaluation technique(Functions are evaluated first).
+Minor Tweaks in Syntax checking.
+Optimised code converting string to long double.
+Bugfix in complex log function.
+Bugfix: i^x bug.
+Tweak: Precise ambiguity.
+Cleaned up the code.

V3.7
+Temporary bugfix for i^x bug.

V3.6
+Complex Math By GenX introduced.
+Support for complex functions.
+Redid evaluation code.

V3.5
+Added support for complex numbers.
+ -,+,*,/ operations on complex numbers supported.
+Tweaks in syntax checking
+Tweaks in evaluation

V3.2
+Redid a major part of the program to remove bugs.
+ √ function added

V3.1
+Added support for inverse functions.
+Tweaks in syntax checking.
+Tweaks in evaluation.

V3.0
+Added support for functions: cos, sin, tan, log .....
+Tweaks in syntax checking.
+Tweaks in evaluation.

V2.9
+Bugfix: Backspace handling in syntax checking.

V2.8
+Added Help
+Syntax checking calls help after a number of invalid entries.

V2.7
+Added nCr , nPr and factorial operations.
+Tweaks in syntax checking.
+Tweaks in evaluation.

V2.6
+Compiled as independent program.
+Bugfix in syntax checking.

V2.5 and earlier
+The program was part of X Shell a dos like command prompt written in C++.
+Supports only +,-,/,*,(,) operators.

23 November 2013

Only Perfect Squares Have Odd Number Of Factors

One day I came across a brain teaser,

There are 100 rooms in a hostel numbered 1,2...100.At first the hostel warden opens every room.Then he closes every 2nd room i.e. 2,4,6...100.In the next round he goes to every 3rd room 3,6,..99, if the room is already open he closes it and open closed rooms.This goes on and after the 100th round how many rooms will be open??

To solve this I tried using many methods.One of the methods was to find the number with odd number of factors. If the number had odd number of factors, it will stay opened after all the rounds been complete. Let's say 26. Factors are 1,2,13,26. It'll be opened in round 1, round 2, round 13 and round 26. After that it'll remain untouched. Now let's say a number $n$ has odd number of factors, then it'll remain open after $n$th round.

I tried other combinatorial methods.But all these seemed too long to yield an answer in a reasonable amount of time.After an hour or two one of my friends gave an answer 10.On asking how he arrived at the solution he said he tried upto 10 rounds and only the perfect squares 1, 4 & 9 remained open.

Frankly, I didn't like his answer.It was like mere guess work. And it was not yet conclusive. So the question was do all perfect squares actually have odd number of factors, do other numbers have odd number of factors as well?On factorizing random numbers only perfect squares seemed to have this property.

So we can vaguely say all perfect squares and only perfect squares have odd number of factors.
But I was never a fan of uncertainty, and the fact seemed too elementary to present itself in the form of a proof. After burning tons of glucose in my brain, the proof seemed pretty silly......

Counting Partitions Of a Set

Then I was studying at 11th std when we were being introduced to 'Sets' my maths tutor at P.C.Thomas Classes told me that there was no 'real' formula for finding the number of partitions for a set of $x$ elements.But then I came across the Bell number which gave the number of partitions as a recurrence series.
But still I was not satisfied, Bell number was not really a formula and there was no explanation why it represent the number of partitions.

Nearly  a year passed by, I learned many new things which included functions. Suddenly I had a insight that Surjective funtions beared a close relationship with set partitions.

Finally I arrived a the summation formula:

Where $x$ is the number of elements in the set.

Proof:
A function $f:X->Y$ is said to be surjective if every element of $Y$ is a image of some element of $X$ .
($x$ & $y$ are respectively the number of elements in $X$ & $Y$).$\left ( x\geq y \right )$

17 November 2013

Proving: Method Of Electrical Images

So first of all what is 'Method of electrical images'.


Suppose you place a charge $Q$ in front of a infinitely large plane conducting sheet which is earthed.The sheet gets an induced charge $-Q$.This would attract the original charge.

The force of attraction is given by $F=\frac{-1}{4\pi \varepsilon}\frac{Q^2}{(2x)^2}$

The force is as if the conducting sheet acts as a mirror and forms a mirror image of the original charge $Q$.


Well the interpretation is beautiful and so is the equation.So how do we prove this.
Initially I raised this question to my physics teacher at P.C Thomas Classes.Failing to get a satisfactory answer I sat upon this problem that night.And finally........

Summing Dice Throws

What is the probability of getting a particular sum after a dice is thrown n times??

During the 1st terminal exam(class 12), I came across a problem in probability wherein a die is thrown twice and finding the probability that the sum obtained is 6. Well the solution was arrived at by finding out the sample space(I actually hate that method, just computation no logic). So naturally a question arose, what if the die is thrown n times........

It preoccupied me the whole evening.Finally I got a formula for finding the number of ways in which a sum can be obtained.
Let the sum of the outcomes be s=(n + 6k + x)
Where, 
n=>number of throws
k=>arbitrary constant
ϵ {0,1,2,3,4,5}

Then number of ways the sum can be obtained is given by:


Using this formula you can easily find the probability..

This formula can also be extended to a die with 'f' faces
s=(n+fk+x)
Where, 
n=>number of throws
k=>arbitrary constant
ϵ {0,1,2,3,...,f-1}
No. of ways = $\sum_{i=0}^{k}(-1)^i.\binom{n}{i}.\binom{n+(k-i)f+y-1}{(k-i)f+y}$


Uh.Oh Forgot one important thing.