summaryrefslogtreecommitdiffstats
path: root/one.py
blob: 854164ea29693311ecc77f227601a20383d2c7a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from libsolve import *
from fractions import Fraction
import numpy as np

ONE_SIMEQ = '\\overset{{\\texttt{{one.py}}}}\\simeq'

# generate figure as plain file, so we can \input it
def gen_figure(figname, text):
    with open(f'figures/fig_one_{figname}.tex', 'w') as fd:
        fd.write('$$' + text + '$$')

m = Matrix([
    [-1, 4, 1, -2, 1, 3],
    [-1, 4, 1, -2, 1, 3],
    [1, -4, 3, -2, 7, 5]
])


vectors = [
    [3, 1, -7, -3, 3, -1],
    [2, 2, 5, 3, 1, -2],
]
for i, v in enumerate(vectors):
    v_t = Matrix([[i] for i in [3, 1, -7, -3, 3, -1]])
    gen_figure(f'proof_v{i}',
        f'''
            {m.to_tex()}
            \\times
            {v_t.to_tex()}
            =
            {(m @ v_t).to_tex()}
        ''')

init = m.to_tex()
m.make_S(0, 1, -1)
m.make_S(1, 2, 1)
m.make_D(1, Fraction(1, 4))
m.make_S(2, 1, -3)

init_triang = m.to_tex()

gen_figure('init_to_triang',
f'''
    {init}
    {ONE_SIMEQ}
    {init_triang}
''')





# steps are the same every time, cause we change only last col
def convert_steps(mat, mat_no):
    before = mat.to_tex()
    mat.make_S(0, 1, -4)
    mat.make_S(2, 0, 1)
    mat.make_S(3, 0, 1)
    mat.make_D(0, -1)
    mat.make_S(0, 4, -1)
    mat.make_S(2, 4, 3)
    mat.make_S(3, 4, 1)

    mat.make_S(0, 5, 1)
    mat.make_S(2, 5, 1)
    mat.make_S(3, 5, -1)
    after = mat.to_tex()

    gen_figure(f'convert_v{mat_no}',
    f'''
        {before}
        {ONE_SIMEQ}
        {after}
    ''')

convert_steps(Matrix([
    [4,-1,-1,1,3],
    [1,0,0,0,1],
    [0,1,-2,-2,-7],
    [0,1,0,0,-3],
    [0,0,1,0,3],
    [0,0,0,1,-1]
]), 1)


convert_steps(Matrix([
    [4,-1,-1,1,2],
    [1,0,0,0,2],
    [0,1,-2,-2,5],
    [0,1,0,0,3],
    [0,0,1,0,1],
    [0,0,0,1,-2]
]), 2)






m = Matrix([
    [1, -3, 3, 1],
    [2, 3, 1, -2]
])

before = m.to_tex()
m.make_S(1, 0, -2)
after = m.to_tex()

gen_figure('solve_last',
f'''
    {before}
    {ONE_SIMEQ}
    {after}
''')