Skip to main content

Posts

Showing posts from August, 2020

Monte Carlo Integration using Python

 Monte Carlo Integration Monte Carlo integration is a  powerful method of computing the value of complex integrals using probabilistic techniques. This technique uses random numbers to compute the definite integral of a function. Here we are going to use the python programs written in the  previous post  to generate pseudorandom numbers and approximate the value of the definite integral of a function. Consider a function to be integrated, as shown below: That is we need to evaluate the definite integral $\int_{a}^{b} f(x)\mathrm{d}x$. The integral is just the area under the curve. The width of the interval $(b- a)$ times the average value of the function is also the value of the integral, that is, $\int_{a}^{b}f(x)\mathrm{d}x = (b - a)f_{average} = (b-a)\langle f \rangle$ So if we had some independent way of calculating the average value of the integrand, then we could evaluate the integral. This is where random numbers come in. Imagine that we had a list of random n...

Generating Pseudorandom Numbers Using Congruence Theory In Python

Pseudorandom Numbers A sequence of random numbers, chosen from the interval between 1 and some fixed integer $M$, is a sequence of numbers $x_0, x_1, \ldots $ such that for each $i$, the values of $x_i$  has a $1/M$ chance of being any given number between 1 and $M$, independent of what values $x_0, x_1, \ldots ,x_{i-1}$ took on. For example, $M$ could be 6 and $x_i$ could be the number of dots showing on the $i^{th}$ throw of a fair die. Random numbers are useful in many contexts related to computing. For example, cryptography requires numbers that attackers can't guess. We can't just use the same numbers over and over. Thus it is crucial to generate these numbers in a very unpredictable way so that attackers can't guess them. We generally group the random numbers generated by computers into two types, depending on how they're generated: True random numbers and pseudorandom numbers. To generate a true random number, the computer measures some type of physical phenomeno...

Making an Encryption Application in Python Using the RSA Algorithm

 The RSA Cryptosystem RSA algorithm is an asymmetric cryptography algorithm. Asymmetric actually means that it works on two different keys i.e. Public Key and Private Key . As the name describes that the public key is given to everyone and the private key is kept private. The Idea: The idea of the RSA algorithm is based on the fact that it is difficult to factorize a large integer. The public key consists of two numbers where one number is the product of two large prime numbers. And private key is also derived from the same two prime numbers. So if somebody can factorize the large number, the private key is compromised. Therefore encryption strength totally lies on the key size and if we double or triple the key size, the strength of encryption increases exponentially. RSA keys can be typically 1024 or 2048 bits long, but experts believe that 1024 bit keys could be broken in the near future. But till now it seems to be an infeasible task. The mechanism behind the RSA algorithm Now ...

Modular Designs With Python (Congruence Theory)

Modular Designs Congruence theory can be used to generate beautiful designs. It is really a fun way to study congruences. Two such designs are created using python. $m$-pointed stars and $(m,n)$ residue designs. $m$ - Pointed Stars To construct an $m$-pointed star, mark $m$ equally spaced points on a large circle, and label them with the least residue 0 through $(m-1)$ modulo $m$. Choose a least residue $i$ modulo $m$, where ($i,m$) = 1. Join each point $x$ with the point  $x + r$ modulo $m$. Now colour in the various regions inside the circle with some solid colours. We should get a nice $m$-pointed star. A python program can be written to draw an $m$-pointed star, where the value of m and $r$ can be chosen by the user. Program import turtle from math import * m = int(input("Enter the value of m: ")) r = int(input("Enter the value of r: ")) t = turtle.Turtle() t.speed(3) t.penup() t.color("black","cyan") t.setposition(0,-100) t.pendown() a=[] fo...

Visualization of Collatz Conjecture using Python

The Collatz Conjecture The Problem The Collatz conjecture (a.k.a the hailstone problem or the $3n + 1$ problem) was proposed by Lother Collatz  in 1937. Although the problem on which the conjecture is based is really simple that even a fourth-grader can easily understand it, the behaviour of the conjecture makes it exceedingly difficult to prove(or disprove).  First of all, lets define the Collatz map . Let $T : \mathbb{Z}^+ \rightarrow \mathbb{Z}^+$ be defined by The conjecture is that for every positive integer $n$, there exists a $k$ such that  $T^k(n) = 1$. Let us consider an example. As mentioned above, the conjecture states that this is true for any positive integer n. But what makes this problem interesting is that even after 60  years since its proposal nobody has been able to prove (or disprove) it. Mathematicians say the "Mathematics is yet not ready to tackle such problems." So far the conjecture has been checked for all starting values up to $87 \times...