Lattices with transforms

This commit is contained in:
jude 2023-05-29 17:13:54 +01:00
parent 76ef7492ba
commit 9b5c6c82bc
4 changed files with 146 additions and 0 deletions

25
.idea/watcherTasks.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectTasksOptions">
<TaskOptions isEnabled="true">
<option name="arguments" value="$FilePath$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="py" />
<option name="immediateSync" value="false" />
<option name="name" value="Black" />
<option name="output" value="" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="$PROJECT_DIR$/venv/bin/black" />
<option name="runOnExternalChanges" value="false" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="" />
<envs />
</TaskOptions>
</component>
</project>

14
components.py Normal file
View File

@ -0,0 +1,14 @@
from manim import *
from consts import *
class TitledScene(Scene):
def add_title(self, title_text):
title = Tex(title_text, font_size=LARGE_FONT)
title.set_z_index(100)
title.to_edge(LEFT + UP)
self.add(title)
self.play(Write(title))
return title

3
consts.py Normal file
View File

@ -0,0 +1,3 @@
LARGE_FONT = 48
MEDIUM_FONT = 40
SMALL_FONT = 32

104
main.py
View File

@ -0,0 +1,104 @@
from consts import *
from components import *
import numpy as np
from manim import *
class Introduction(TitledScene):
def construct(self):
self.add_title("Goldreich--Goldwasser--Halevi")
self.wait()
text_1 = Tex(
r"""
\begin{itemize}
\item Lattice-based cryptosystem.
\item Devised in 1997 by Goldreich, Goldwasser, and Halevi.
\item Broken in 1999 by Nguyen.
\end{itemize}
""",
font_size=MEDIUM_FONT,
)
self.add(text_1)
self.play(Write(text_1, run_time=4.0))
self.wait()
class Premise(TitledScene):
def construct(self):
self.add_title("Lattices")
# A lattice is a subspace of a vector space that is constructed by taking integer multiples of some basis
# vectors.
# For example, take the real plane R2.
plane = NumberPlane(axis_config={"stroke_width": 0.0})
plane.set_z_index(-10)
plane.set_opacity(0.75)
dot = Dot(ORIGIN)
self.add(dot, plane)
self.play(Create(dot), Create(plane))
self.wait()
# We can construct the 2D grid of integers with the elementary basis
lattice_1 = VGroup()
arrow_1 = Arrow(ORIGIN, [1, 0, 0], buff=0)
arrow_2 = Arrow(ORIGIN, [0, 1, 0], buff=0)
self.play(Create(arrow_1), Create(arrow_2))
self.wait()
for i in range(-7, 8):
for j in range(-6, 7):
lattice_1.add(Dot([i, j, 0]))
self.play(Create(lattice_1))
# By moving these basis vectors but maintaining their linear independency, other lattices can be formed
self.play(
Transform(arrow_1, Arrow(ORIGIN, [1.5, 0, 0], buff=0)),
*[
Transform(
dot,
Dot(
dot.get_center()
* np.matrix([[1.5, 0, 0], [0, 1, 0], [0, 0, 1]])
),
)
for dot in lattice_1
]
)
self.wait()
self.play(
Transform(arrow_1, Arrow(ORIGIN, [1, -0.5, 0], buff=0)),
*[
Transform(
dot,
Dot(
dot.get_center()
* np.matrix([[2 / 3, 0, 0], [0, 1, 0], [0, 0, 1]])
* np.matrix([[1, -0.5, 0], [0, 1, 0], [0, 0, 1]])
),
)
for dot in lattice_1
]
)
self.wait()
self.play(
Transform(arrow_1, Arrow(ORIGIN, [1, -1, 0], buff=0)),
Transform(arrow_2, Arrow(ORIGIN, [1, 1, 0], buff=0)),
*[
Transform(
dot,
Dot(
dot.get_center()
* np.matrix([[1, 0.5, 0], [0, 1, 0], [0, 0, 1]])
* np.matrix([[1, -1, 0], [1, 1, 0], [0, 0, 1]])
),
)
for dot in lattice_1
]
)
self.wait()