Skip to main content

math_utils

solve_problem

def solve_problem(problem: str, **config) -> str

(openai<1) Solve the math problem.

Arguments:

  • problem str - The problem statement.
  • config Optional, dict - The configuration for the API call.

Returns:

  • str - The solution to the problem.

remove_boxed

def remove_boxed(string: str) -> Optional[str]

Source: https://github.com/hendrycks/math Extract the text within a \boxed{...} environment.

Example:

remove_boxed("\boxed{\frac{2}{3}}")

\frac{2}{3}

last_boxed_only_string

def last_boxed_only_string(string: str) -> Optional[str]

Source: https://github.com/hendrycks/math Extract the last \boxed{...} or \fbox{...} element from a string.

is_equiv

def is_equiv(str1: Optional[str], str2: Optional[str]) -> float

Returns (as a float) whether two strings containing math are equivalent up to differences of formatting in

is_equiv_chain_of_thought

def is_equiv_chain_of_thought(str1: str, str2: str) -> float

Strips the solution first before calling is_equiv.

eval_math_responses

def eval_math_responses(responses, solution=None, **args)

Select a response for a math problem using voting, and check if the response is correct if the solution is provided.

Arguments:

  • responses list - The list of responses.
  • solution str - The canonical solution.

Returns:

  • dict - The success metrics.