





def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:int   ,   SCREAMING_SNAKE_CASE		:bool = False   )      ->   bool:
 if n == 2:
  return True
 if not n % 2 or n < 2:
  return False
 if n > 5 and n % 10 not in (1, 3, 7, 9):  # can quickly check last digit
  return False
 if n > 3_317_044_064_679_887_385_961_981 and not allow_probable:
  raise ValueError(
      """Warning: upper bound of deterministic test is exceeded. """
      """Pass allow_probable=True to allow probabilistic test. """
      """A return value of True indicates a probable prime."""   )
 # array bounds provided by analysis
 __lowerCAmelCase					:	str      =       [
     2_047,
     1_373_653,
     25_326_001,
     3_215_031_751,
     2_152_302_898_747,
     3_474_749_660_383,
     341_550_071_728_321,
     1,
     3_825_123_056_546_413_051,
     1,
     1,
     318_665_857_834_031_151_167_461,
     3_317_044_064_679_887_385_961_981,
 ]

 __lowerCAmelCase					:	Tuple      =       [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
 for idx, _p in enumerate(SCREAMING_SNAKE_CASE   ,   1   ):
  if n < _p:
   # then we have our last prime to check
   __lowerCAmelCase					:	Any      =       primes[:idx]
   break
 __lowerCAmelCase ,					__lowerCAmelCase					:	Any      =       n - 1, 0
 # break up n -1 into a power of 2 (s) and
 # remaining odd component
 # essentially, solve for d * 2 ** s == n - 1
 while d % 2 == 0:
  d //= 2
  s += 1
 for prime in plist:
  __lowerCAmelCase					:	List[Any]      =       False
  for r in range(SCREAMING_SNAKE_CASE   ):
   __lowerCAmelCase					:	List[Any]      =       pow(SCREAMING_SNAKE_CASE   ,   d * 2**r   ,   SCREAMING_SNAKE_CASE   )
   # see article for analysis explanation for m
   if (r == 0 and m == 1) or ((m + 1) % n == 0):
    __lowerCAmelCase					:	int      =       True
    # this loop will not determine compositeness
    break
  if pr:
   continue
  # if pr is False, then the above loop never evaluated to true,
  # and the n MUST be composite
  return False
 return True






def 	_SCREAMING_SNAKE_CASE		(      )      ->   None:
 assert not miller_rabin(561   )
 assert miller_rabin(563   )
 # 2047

 assert not miller_rabin(838_201   )
 assert miller_rabin(838_207   )
 # 1_373_653

 assert not miller_rabin(17_316_001   )
 assert miller_rabin(17_316_017   )
 # 25_326_001

 assert not miller_rabin(3_078_386_641   )
 assert miller_rabin(3_078_386_653   )
 # 3_215_031_751

 assert not miller_rabin(1_713_045_574_801   )
 assert miller_rabin(1_713_045_574_819   )
 # 2_152_302_898_747

 assert not miller_rabin(2_779_799_728_307   )
 assert miller_rabin(2_779_799_728_327   )
 # 3_474_749_660_383

 assert not miller_rabin(113_850_023_909_441   )
 assert miller_rabin(113_850_023_909_527   )
 # 341_550_071_728_321

 assert not miller_rabin(1_275_041_018_848_804_351   )
 assert miller_rabin(1_275_041_018_848_804_391   )
 # 3_825_123_056_546_413_051

 assert not miller_rabin(79_666_464_458_507_787_791_867   )
 assert miller_rabin(79_666_464_458_507_787_791_951   )
 # 318_665_857_834_031_151_167_461

 assert not miller_rabin(552_840_677_446_647_897_660_333   )
 assert miller_rabin(552_840_677_446_647_897_660_359   )
 # 3_317_044_064_679_887_385_961_981
 # upper limit for probabilistic test


if __name__ == "__main__":
      test_miller_rabin()






import sacrebleu as scb
from packaging import version
from sacrebleu import TER

import datasets


_UpperCAmelCase             =							'\\n@inproceedings{snover-etal-2006-study,\n    title = "A Study of Translation Edit Rate with Targeted Human Annotation",\n    author = "Snover, Matthew  and\n      Dorr, Bonnie  and\n      Schwartz, Rich  and\n      Micciulla, Linnea  and\n      Makhoul, John",\n    booktitle = "Proceedings of the 7th Conference of the Association for Machine Translation in the Americas: Technical Papers",\n    month = aug # " 8-12",\n    year = "2006",\n    address = "Cambridge, Massachusetts, USA",\n    publisher = "Association for Machine Translation in the Americas",\n    url = "https://aclanthology.org/2006.amta-papers.25",\n    pages = "223--231",\n}\n@inproceedings{post-2018-call,\n    title = "A Call for Clarity in Reporting {BLEU} Scores",\n    author = "Post, Matt",\n    booktitle = "Proceedings of the Third Conference on Machine Translation: Research Papers",\n    month = oct,\n    year = "2018",\n    address = "Belgium, Brussels",\n    publisher = "Association for Computational Linguistics",\n    url = "https://www.aclweb.org/anthology/W18-6319",\n    pages = "186--191",\n}\n'

_UpperCAmelCase             =							'\\nTER (Translation Edit Rate, also called Translation Error Rate) is a metric to quantify the edit operations that a\nhypothesis requires to match a reference translation. We use the implementation that is already present in sacrebleu\n(https://github.com/mjpost/sacreBLEU#ter), which in turn is inspired by the TERCOM implementation, which can be found\nhere: https://github.com/jhclark/tercom.\n\nThe implementation here is slightly different from sacrebleu in terms of the required input format. The length of\nthe references and hypotheses lists need to be the same, so you may need to transpose your references compared to\nsacrebleu\'s required input format. See https://github.com/huggingface/datasets/issues/3154#issuecomment-950746534\n\nSee the README.md file at https://github.com/mjpost/sacreBLEU#ter for more information.\n'

_UpperCAmelCase             =							'\nProduces TER scores alongside the number of edits and reference length.\n\nArgs:\n    predictions (list of str): The system stream (a sequence of segments).\n    references (list of list of str): A list of one or more reference streams (each a sequence of segments).\n    normalized (boolean): If `True`, applies basic tokenization and normalization to sentences. Defaults to `False`.\n    ignore_punct (boolean): If `True`, applies basic tokenization and normalization to sentences. Defaults to `False`.\n    support_zh_ja_chars (boolean): If `True`, tokenization/normalization supports processing of Chinese characters,\n                                    as well as Japanese Kanji, Hiragana, Katakana, and Phonetic Extensions of Katakana.\n                                    Only applies if `normalized = True`. Defaults to `False`.\n    case_sensitive (boolean): If `False`, makes all predictions and references lowercase to ignore differences in case. Defaults to `False`.\n\nReturns:\n    \'score\' (float): TER score (num_edits / sum_ref_lengths * 100)\n    \'num_edits\' (int): The cumulative number of edits\n    \'ref_length\' (float): The cumulative average reference length\n\nExamples:\n    Example 1:\n        >>> predictions = ["does this sentence match??",\n        ...                     "what about this sentence?",\n        ...                     "What did the TER metric user say to the developer?"]\n        >>> references = [["does this sentence match", "does this sentence match!?!"],\n        ...             ["wHaT aBoUt ThIs SeNtEnCe?", "wHaT aBoUt ThIs SeNtEnCe?"],\n        ...             ["Your jokes are...", "...TERrible"]]\n        >>> ter = datasets.load_metric("ter")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         case_sensitive=True)\n        >>> print(results)\n        {\'score\': 150.0, \'num_edits\': 15, \'ref_length\': 10.0}\n\n    Example 2:\n        >>> predictions = ["does this sentence match??",\n        ...                     "what about this sentence?"]\n        >>> references = [["does this sentence match", "does this sentence match!?!"],\n        ...             ["wHaT aBoUt ThIs SeNtEnCe?", "wHaT aBoUt ThIs SeNtEnCe?"]]\n        >>> ter = datasets.load_metric("ter")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         case_sensitive=True)\n        >>> print(results)\n        {\'score\': 62.5, \'num_edits\': 5, \'ref_length\': 8.0}\n\n    Example 3:\n        >>> predictions = ["does this sentence match??",\n        ...                     "what about this sentence?"]\n        >>> references = [["does this sentence match", "does this sentence match!?!"],\n        ...             ["wHaT aBoUt ThIs SeNtEnCe?", "wHaT aBoUt ThIs SeNtEnCe?"]]\n        >>> ter = datasets.load_metric("ter")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         normalized=True,\n        ...                         case_sensitive=True)\n        >>> print(results)\n        {\'score\': 57.14285714285714, \'num_edits\': 6, \'ref_length\': 10.5}\n\n    Example 4:\n        >>> predictions = ["does this sentence match??",\n        ...                     "what about this sentence?"]\n        >>> references = [["does this sentence match", "does this sentence match!?!"],\n        ...             ["wHaT aBoUt ThIs SeNtEnCe?", "wHaT aBoUt ThIs SeNtEnCe?"]]\n        >>> ter = datasets.load_metric("ter")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         ignore_punct=True,\n        ...                         case_sensitive=False)\n        >>> print(results)\n        {\'score\': 0.0, \'num_edits\': 0, \'ref_length\': 8.0}\n\n    Example 5:\n        >>> predictions = ["does this sentence match??",\n        ...                    "what about this sentence?",\n        ...                    "What did the TER metric user say to the developer?"]\n        >>> references = [["does this sentence match", "does this sentence match!?!"],\n        ...             ["wHaT aBoUt ThIs SeNtEnCe?", "wHaT aBoUt ThIs SeNtEnCe?"],\n        ...             ["Your jokes are...", "...TERrible"]]\n        >>> ter = datasets.load_metric("ter")\n        >>> results = ter.compute(predictions=predictions,\n        ...                         references=references,\n        ...                         ignore_punct=True,\n        ...                         case_sensitive=False)\n        >>> print(results)\n        {\'score\': 100.0, \'num_edits\': 10, \'ref_length\': 10.0}\n'






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION					,_KWARGS_DESCRIPTION						)
class        snake_case_    (		datasets.Metric						):






  def 				UpperCAmelCase__						(							self			:					Tuple      )->str:






   '''simple docstring'''

   if version.parse(scb.__version__      ) < version.parse("""1.4.12"""      ):
    raise ImportWarning(
        """To use `sacrebleu`, the module `sacrebleu>=1.4.12` is required, and the current version of `sacrebleu` doesn't match this condition.\n"""
        """You can install it with `pip install \"sacrebleu>=1.4.12\"`."""      )
   return datasets.MetricInfo(
       description=_DESCRIPTION       ,  citation=_CITATION       ,  homepage="""http://www.cs.umd.edu/~snover/tercom/"""       ,  inputs_description=_KWARGS_DESCRIPTION       ,  features=datasets.Features(
           {
               """predictions""": datasets.Value("""string"""       ,  id="""sequence"""      ),
               """references""": datasets.Sequence(datasets.Value("""string"""       ,  id="""sequence"""      )       ,  id="""references"""      ),
           }      )       ,  codebase_urls=["""https://github.com/mjpost/sacreBLEU#ter"""]       ,  reference_urls=[
           """https://github.com/jhclark/tercom""",
       ]       ,  )






  def 				UpperCAmelCase__						(							self			:					Dict       ,  _snake_case			:					List[Any]       ,  _snake_case			:					int       ,  _snake_case			:					bool = False       ,  _snake_case			:					bool = False       ,  _snake_case			:					bool = False       ,  _snake_case			:					bool = False       ,  )->str:






   '''simple docstring'''

   __lowerCAmelCase					:	List[str]      =       len(references[0]      )
   if any(len(_snake_case      ) != references_per_prediction for refs in references      ):
    raise ValueError("""Sacrebleu requires the same number of references for each prediction"""      )
   __lowerCAmelCase					:	str      =       [[refs[i] for refs in references] for i in range(_snake_case      )]

   __lowerCAmelCase					:	Tuple      =       TER(
       normalized=_snake_case       ,  no_punct=_snake_case       ,  asian_support=_snake_case       ,  case_sensitive=_snake_case       ,  )
   __lowerCAmelCase					:	List[Any]      =       sb_ter.corpus_score(_snake_case       ,  _snake_case      )

   return {"score": output.score, "num_edits": output.num_edits, "ref_length": output.ref_length}