




import math_equivalence  # From: git+https://github.com/hendrycks/math.git

import datasets


__A        =    "\\n@article{hendrycksmath2021,\n  title={Measuring Mathematical Problem Solving With the MATH Dataset},\n  author={Dan Hendrycks\n    and Collin Burns\n    and Saurav Kadavath\n    and Akul Arora\n    and Steven Basart\n    and Eric Tang\n    and Dawn Song\n    and Jacob Steinhardt},\n  journal={arXiv preprint arXiv:2103.03874},\n  year={2021}\n}\n"


__A        =    "\\nThis metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.\nIt first canonicalizes the inputs (e.g., converting \"1/2\" to \"\\frac{1}{2}\") and then computes accuracy.\n"


__A        =    R"\nCalculates accuracy after canonicalizing inputs.\n\nArgs:\n    predictions: list of predictions to score. Each prediction\n        is a string that contains natural language and LaTex.\n    references: list of reference for each prediction. Each\n        reference is a string that contains natural language\n        and LaTex.\nReturns:\n    accuracy: accuracy after canonicalizing inputs\n        (e.g., converting \"1/2\" to \"\\frac{1}{2}\")\n\nExamples:\n    >>> metric = datasets.load_metric(\"competition_math\")\n    >>> results = metric.compute(references=[\"\\frac{1}{2}\"], predictions=[\"1/2\"])\n    >>> print(results)\n    {'accuracy': 1.0}\n"







@datasets.utils.file_utils.add_end_docstrings(_DESCRIPTION			,				_KWARGS_DESCRIPTION )
class     __lowerCAmelCase (       datasets.Metric ):

			"""simple docstring"""







			def       lowercase_    (      self							)    ->      Union[str, Any]:



							'''simple docstring'''
							return datasets.MetricInfo(
							    description=_DESCRIPTION			,						citation=_CITATION			,						inputs_description=_KWARGS_DESCRIPTION			,						features=datasets.Features(
							        {
							            'predictions': datasets.Value('string'							),
							            'references': datasets.Value('string'							),
							        }							)			,						homepage='https://github.com/hendrycks/math'			,						codebase_urls=['https://github.com/hendrycks/math']			,						)






			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      str:



							'''simple docstring'''
							__lowerCamelCase		       =    0.0
							for i, j in zip(lowerCamelCase__			,						lowerCamelCase__							):
											n_correct += 1.0 if math_equivalence.is_equiv(lowerCamelCase__			,						lowerCamelCase__							) else 0.0
							__lowerCamelCase		       =    n_correct / len(lowerCamelCase__							)
							return {
							    "accuracy": accuracy,
							}









"""simple docstring"""




from heapq import heappop, heappush

import numpy as np





def 						UpperCAmelCase__		(     _UpperCAmelCase ,					_UpperCAmelCase ,					_UpperCAmelCase ,					_UpperCAmelCase ,					):






  """simple docstring"""





  A_						,       A_  :       List[str]										=  grid.shape
  A_  :       Optional[int]										=  [-1, 1, 0, 0]
  A_  :       str										=  [0, 0, -1, 1]
  if allow_diagonal:
    dx += [-1, -1, 1, 1]
    dy += [-1, 1, -1, 1]

  A_						,       A_  :       List[Any]										=  [(0, source)], set()
  A_  :       Optional[Any]										=  np.full((rows, cols) ,					np.inf					)
  A_  :       int										=  0
  A_  :       Optional[int]										=  np.empty((rows, cols) ,					dtype=_UpperCAmelCase					)
  A_  :       Optional[int]										=  None

  while queue:
    ((A_)						,       (A_))  :       str										=  heappop(_UpperCAmelCase					)
    if (x, y) in visited:
      continue
    visited.add((x, y)					)

    if (x, y) == destination:
      A_  :       int										=  []
      while (x, y) != source:
        path.append((x, y)					)
        A_						,       A_  :       List[Any]										=  predecessors[x, y]
      path.append(_UpperCAmelCase					)  # add the source manually
      path.reverse()
      return matrix[destination], path

    for i in range(len(_UpperCAmelCase					)					):
      A_						,       A_  :       Tuple										=  x + dx[i], y + dy[i]
      if 0 <= nx < rows and 0 <= ny < cols:
        A_  :       Union[str, Any]										=  grid[nx][ny]
        if next_node == 1 and matrix[nx, ny] > dist + 1:
          heappush(_UpperCAmelCase ,					(dist + 1, (nx, ny))					)
          A_  :       Optional[Any]										=  dist + 1
          A_  :       Optional[Any]										=  (x, y)

  return np.inf, []


if __name__ == "__main__":
   import doctest

   doctest.testmod()