Skip to main content

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=[]
for i in range(m):
    t.circle(100,360/m)
    t.dot(5,"blue")
    s = t.position()
    t.write(i)
    a.append(s)
n = len(a)
t.penup()
t.setposition(a[0])
t.pendown()
i = 0
t.begin_fill()
while i <= m*r:
    t.setposition(a[i%m])
    i+=r
t.end_fill()

Output

A seven-pointed (r = 3) star 
 
A thirteen-pointed (r = 5) star



$(m,n)$ Residue Designs

To construct an $(m,n)$ residue design, where $1 \leq n < m$ and $(m,n) = 1$, select $m-1$ equally spaced points on a large circle. Label them 1 through $m -1$, and join each $x$ to point $nx$ modulo $m$. Then color in the various regions formed in a systematic way to create exciting designs.
The python program to do the same is given below. The program asks the user to input the values of $m$ and $n$.

Program

import turtle
m = int(input("Enter the value of m: "))
n = int(input("Enter the value of n: "))
t = turtle.Turtle()
t.speed(3)
t.color("black","cyan")
a = []
for i in range(1,m):
    t.circle(100,360/(m-1))
    t.dot(5,"blue")
    t.write(i)
    a.append(t.position())
t.penup()
t.setposition(a[0])
t.pendown()
a.append((0,0))
i = 0
t.begin_fill()
while i < m-1:
    t.goto(a[(((i+1)*n)%m)-1])
    t.penup()
    i += 1
    t.goto(a[i])
    t.pendown()
t.end_fill()

Output

The (19,9) reside design
The (21,10) residue design

Comments

Popular posts from this blog

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...

Generating Sexy Prime Pairs using Python

Sexy Primes, What are they? They are prime numbers that differ by 6. For example, 5 & 11,  7 & 13. The name comes from the Latin word for six; sex. What we are going to do is, write a program to generate all the sexy prime pairs within a given interval of natural numbers.  Sexy Prime Pairs This is a program to generate all the sexy prime pairs below 10000. Program def check_prime(n):     for i in range(2,n//2+1):         if n%i == 0:     return False     return True def primes_list(a,b):     primes_list = []     for i in range(a,b):         if check_prime(i):     primes_list.append(i)     return (primes_list) def sexy_list(primes_list):     sexy_list = []     for i in primes_list:         for j in primes_list:     if j-i == 6:         sexy_list.append((i,j))     return(sexy_...

Local Linear Approximation

You might have seen the famous approximation $\sin(x) \approx x$ for $x$ near 0. We can use derivatives to approximate non-linear functions by simpler linear functions. We can better understand this by looking at the graph a function $f$ under magnification. The blue curve is the graph of $f(x) = \sin(x)$ and the yellow line is its tangent at $x = 0$. We can see that, under magnification of the curve at the point $x = 0$, the tangent line to the curve at $x = 0$ is a close approximation of the function for $x$ near 0. In general, for a function $f$: if $f$ is differentiable at a point $x_0$, then stronger and stronger magnifications at $(x_0,f(x_0))$ eventually make the curve containing $(x_0,f(x_0))$ look more and more like a non-vertical line segment, that line being the tangent line to the graph of $f$ at $(x_0,f(x)_0))$. Thus, a function $f$ that is differentiable at $x_0$ is said to be locally linear  at the point $(x_0,f(x_0))$ .  By contrast, the graph of a functi...