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} ''')