Giter Site home page Giter Site logo

alreich / gaussian_integers Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 2.88 MB

Gaussian Integers and Gaussian Rational Numbers

License: MIT License

Jupyter Notebook 71.39% Python 28.61%
complex-numbers gaussian-integers gcd bezout-coefficients gaussian-primes gaussian-rationals modified-divmod euclidean-algorithm number-theory prime-numbers

gaussian_integers's Introduction

Gaussian Integers and Gaussian Rational Numbers

This module defines two classes, Zi and Qi, the Gaussian integers and Gaussian rational numbers, respectively.

Mathematically, the integers are denoted by $\mathbb{Z}$, the rational numbers by $\mathbb{Q}$, and the complex numbers by $\mathbb{C}$.

$\mathbb{C} \equiv \lbrace a + bi: a, b \in \mathbb{R} \rbrace$ where $\mathbb{R}$ is the set of real numbers and $i^2 = -1$.

The Gaussian integers are denoted by $\mathbb{Z}[i] \equiv \lbrace n + mi: n, m \in \mathbb{Z} \rbrace \subset \mathbb{C}$,

and the Gaussian rationals are denoted by $\mathbb{Q}[i] \equiv \lbrace r + si: r, s \in \mathbb{Q} \rbrace \subset \mathbb{C}$.

NOTE:

  • Python uses $j$ instead of $i$ to represent complex numbers
  • Although, both Zi and Qi are subclasses of numbers.Complex, and $\mathbb{Z}[i] \subset \mathbb{Q}[i] \subset \mathbb{C}$, the class Zi is not a subclass of the class Qi.

For more information, see the two Jupyter notebooks in the notebooks directory.

For a quick look, see the examples following the plot of Gaussian primes, below.

alt text

Quick Look

The examples below are from "The Gaussian Integers" by Keith Conrad

>>> from gaussians import Zi, Qi

The Division Theorem

>>> alpha = Zi(27, -23)
>>> beta = Zi(8, 1)

>>> quot, rem = Zi.modified_divmod(alpha, beta)

>>> print(f"{beta * quot + rem} = {beta} * {quot} + {rem}")
(27-23j) = (8+1j) * (3-3j) + -2j

The Euclidean Algorithm

>>> alpha = Zi(11, 3)
>>> beta = Zi(1, 8)

>>> gcd = Zi.gcd(alpha, beta, verbose=True)  # Prints intermediate results

>>> print(f"\ngcd({alpha}, {beta}) -> {gcd}")
   (11+3j) = (1+8j) * (1-1j) + (2-4j)
   (1+8j) = (2-4j) * (-2+1j) + (1-2j)
   (2-4j) = (1-2j) * (2+0j) + 0j

gcd((11+3j), (1+8j)) -> (1-2j)

Bezout's Theorem

>>> a, x, y = Zi.xgcd(alpha, beta)

>>> print(f"a = {a}")
>>> print(f"{alpha * x  + beta * y} = {alpha} * {x} + {beta} * {y}")
a = (1-2j)
(1-2j) = (11+3j) * (2-1j) + (1+8j) * 3j

True Division

If $\alpha, \beta \in \mathbb{Z}[i]$, then ${\large \frac{\alpha}{\beta}} \in \mathbb{Q}[i]$

>>> a = Zi(4, 5)
>>> b = Zi(1, -2)
>>> a / b
Qi('-6/5', '13/5')
>>> print(f"{a} / {b} -> {a / b}")
(4+5j) / (1-2j) -> (-6/5+13/5j)

gaussian_integers's People

Contributors

alreich avatar

Stargazers

Ioannis Konstantoulas avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.