-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
39 lines (31 loc) · 1.35 KB
/
utils.py
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
from sage.all import *
def vector_simplify(vector, use_canonical_form=False):
# Applies simplify_full to each element
if use_canonical_form == True:
# Uses Canonical Form of Multi-Valued Functions
return vector.apply_map(lambda x: x.simplify_full().canonicalize_radical())
else:
# Uses Standard Simplification
return vector.apply_map(lambda x: x.simplify_full())
def get_vector_arguments(vector):
# Obtains arguments of vector or parametric curve
parameters = set()
for coordinate in vector:
parameters.update(list(coordinate.arguments()))
return parameters
def pretty_results(*argv, use_colon=False, centered=True):
expressions = ""
# Use Colon or Equal Sign for Separating Expression Names and Values?
if use_colon:
separator = LatexExpr(r":& \quad")
else:
separator = LatexExpr(r"&=")
# Generate LaTeX Representations for Expressions
for (latex_name, value) in argv:
expressions += LatexExpr(latex_name) + separator + latex(value) + LatexExpr(r"\\")
# Wrap Expressions with LaTeX align Enviroment
formatted_string = LatexExpr(r"\begin{align*}") + expressions + LatexExpr(r"\end{align*}")
# Center Expressions or Use Default Left-align?
if centered:
formatted_string += LatexExpr(r"\\")
return formatted_string