






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

import datasets


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


__magic_name__   :  Dict        =							'''\
This metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.
It first canonicalizes the inputs (e.g., converting "1/2" to "\\frac{1}{2}") and then computes accuracy.
'''


__magic_name__   :  Tuple        =							r'''
Calculates accuracy after canonicalizing inputs.

Args:
    predictions: list of predictions to score. Each prediction
        is a string that contains natural language and LaTex.
    references: list of reference for each prediction. Each
        reference is a string that contains natural language
        and LaTex.
Returns:
    accuracy: accuracy after canonicalizing inputs
        (e.g., converting "1/2" to "\\frac{1}{2}")

Examples:
    >>> metric = datasets.load_metric("competition_math")
    >>> results = metric.compute(references=["\\frac{1}{2}"], predictions=["1/2"])
    >>> print(results)
    {\'accuracy\': 1.0}
'''





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

     '''simple docstring'''






     def   _SCREAMING_SNAKE_CASE     ( self      :    List[str] ):






           """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   _SCREAMING_SNAKE_CASE     ( self      :    str   ,						_SCREAMING_SNAKE_CASE      :    Dict   ,						_SCREAMING_SNAKE_CASE      :    int ):






           """simple docstring"""




           UpperCamelCase					       =  0.0
           for i, j in zip(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE ):
                 n_correct += 1.0 if math_equivalence.is_equiv(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE ) else 0.0
           UpperCamelCase					       =  n_correct / len(_SCREAMING_SNAKE_CASE )
           return {
               "accuracy": accuracy,
           }











def 		lowercase__  (				_UpperCamelCase) ->			list:
      """simple docstring"""

      if bit_count < 0:
            raise ValueError('The given input must be positive')

      # get the generated string sequence
      UpperCamelCase					       =  gray_code_sequence_string(_UpperCamelCase)
      #
      # convert them to integers
      for i in range(len(_UpperCamelCase)):
            UpperCamelCase					       =  int(sequence[i]       ,							2)

      return sequence
def 		lowercase__  (				_UpperCamelCase) ->			list:
      """simple docstring"""

      if bit_count == 0:
            return ["0"]

      if bit_count == 1:
            return ["0", "1"]

      UpperCamelCase					       =  1 << bit_count  # defines the length of the sequence
      # 1<< n is equivalent to 2^n

      # recursive answer will generate answer for n-1 bits
      UpperCamelCase					       =  gray_code_sequence_string(bit_count - 1)

      UpperCamelCase					       =  []

      # append 0 to first half of the smaller sequence generated
      for i in range(seq_len // 2):
            UpperCamelCase					       =  '0' + smaller_sequence[i]
            sequence.append(_UpperCamelCase)

      # append 1 to second half ... start from the end of the list
      for i in reversed(range(seq_len // 2)):
            UpperCamelCase					       =  '1' + smaller_sequence[i]
            sequence.append(_UpperCamelCase)

      return sequence


if __name__ == "__main__":
       import doctest

       doctest.testmod()



