MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / _strip_string

Function _strip_string

eval/utils/math_equivalence.py:71–138  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

69 return new_string
70
71def _strip_string(string):
72 # linebreaks
73 string = string.replace("\n", "")
74 #print(string)
75
76 # remove inverse spaces
77 string = string.replace("\\!", "")
78 #print(string)
79
80 # replace \\ with \
81 string = string.replace("\\\\", "\\")
82 #print(string)
83
84 # replace tfrac and dfrac with frac
85 string = string.replace("tfrac", "frac")
86 string = string.replace("dfrac", "frac")
87 #print(string)
88
89 # remove \left and \right
90 string = string.replace("\\left", "")
91 string = string.replace("\\right", "")
92 #print(string)
93
94 # Remove circ (degrees)
95 string = string.replace("^{\\circ}", "")
96 string = string.replace("^\\circ", "")
97
98 # remove dollar signs
99 string = string.replace("\\$", "")
100
101 # remove units (on the right)
102 string = _remove_right_units(string)
103
104 # remove percentage
105 string = string.replace("\\%", "")
106 string = string.replace("\%", "")
107
108 # " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string
109 string = string.replace(" .", " 0.")
110 string = string.replace("{.", "{0.")
111 # if empty, return empty string
112 if len(string) == 0:
113 return string
114 if string[0] == ".":
115 string = "0" + string
116
117 # to consider: get rid of e.g. "k = " or "q = " at beginning
118 if len(string.split("=")) == 2:
119 if len(string.split("=")[0]) <= 2:
120 string = string.split("=")[1]
121
122 # fix sqrt3 --> sqrt{3}
123 string = _fix_sqrt(string)
124
125 # remove spaces
126 string = string.replace(" ", "")
127
128 # \frac1b or \frac12 --> \frac{1}{b} and \frac{1}{2}, etc. Even works with \frac1{72} (but not \frac{72}1). Also does a/b --> \\frac{a}{b}

Callers 1

is_equivFunction · 0.70

Calls 4

_remove_right_unitsFunction · 0.70
_fix_sqrtFunction · 0.70
_fix_fracsFunction · 0.70
_fix_a_slash_bFunction · 0.70

Tested by

no test coverage detected