FindRepeat

FindRepeat[list]

finds the minimal sublist or subarray that repeats to give list.

FindRepeat[list,n]

requires that the sublist be repeated at least n times in list.

FindRepeat[list,{n1,n2,}]

requires ni to repeat at level i in list.

FindRepeat["string"]

finds the minimal substring that repeats to give string.

FindRepeat["string",n]

requires that the substring be repeated at least n times.

Details and Options

  • FindRepeat[expr] gives expr if no repeat is found.
  • FindRepeat[list,2] gives {} if no repeat is found. FindRepeat["string",2] gives "".
  • FindRepeat[expr] allows incomplete repeats at the end of expr.
  • FindRepeat[expr,n] requires at least n complete repeats.
  • FindRepeat[list] is equivalent to FindRepeat[list,Table[1,ArrayDepth[list]]].
  • The length of the list {n1,n2,} must be less than or equal to ArrayDepth[list].
  • FindRepeat works on SparseArray and structured array objects.
  • FindRepeat works on associations, effectively ignoring their keys and returning an association with keys corresponding to the first occurrence of the repeated block.
  • FindRepeat[list,{n1,n2,,nk},SameTest->test] applies test to each pair of elements at level k to determine whether they should be considered the same.

Examples

open allclose all

Basic Examples  (4)

Find the sublist that repeats to form a list:

The last sublist does not need to be complete:

Find a sublist that repeats at least four times:

An empty list is returned if no sublist satisfies the condition:

Find the repeated block of a matrix:

Find the repeated substring of a string:

Scope  (10)

One-Argument Form  (8)

Find the repeated part of a list of any type of element:

The elements of the first argument can have different heads:

Find the repeated block of a matrix:

Find the repeated block of an array of any depth:

FindRepeat works with SparseArray:

FindRepeat works with QuantityArray:

Find the repeated part of an association:

Find the repeated part of a string:

Two-Argument Form  (2)

Find a sublist that repeats at least three times:

FindRepeat returns an empty list if no sublist satisfies the condition:

Find the repeated part of an array at different levels:

FindRepeat[arr] is equivalent to the deepest of those cases:

Options  (4)

SameTest  (4)

Use equivalence classes based on absolute value:

Use equivalence classes based on Floor:

Use Total of list elements:

In FindRepeat[list,{n1,,nk},SameTest->test], the function test is applied on elements of list at level k:

Applications  (6)

Find the repeated block of an array:

Reconstruct the original array by specifying how many times the block is repeated:

Visualize the repeated block of an array with MatrixPlot:

The Metonic cycle of the Jewish calendar spans 235 months:

This code gives the Julian calendar date of Julian Easter for a given year:

For the year 2017, it falls on April 3 in the Julian calendar, or April 16 in the Gregorian calendar:

Compute the dates of Julian Easter for the years 1 to 2000, all falling between Julian March 22 and April 25:

The dates follow a cyclic pattern that repeats every 532 years:

Find the period of a continuous function:

Compare with FunctionPeriod:

Recover the generator of a StringRepeat expression:

Properties & Relations  (5)

FindRepeat can detect an incomplete copy of the repeated sequence:

FindRepeat[list,1] returns list if no smaller repetition is found:

When no repeated block satisfies the condition on the number of occurrences, FindRepeat returns an empty list:

By default, the second argument of FindRepeat is a list of 1s of length given by the array depth of the first argument:

FindRepeat finds the repeated part of an expression:

FindTransientRepeat allows the presence of a transient part:

When an expression has no transient part, FindRepeat[expr,n] is identical to Last[FindTransientRepeat[expr,n]]:

Wolfram Research (2017), FindRepeat, Wolfram Language function, https://reference.wolfram.com/language/ref/FindRepeat.html.

Text

Wolfram Research (2017), FindRepeat, Wolfram Language function, https://reference.wolfram.com/language/ref/FindRepeat.html.

CMS

Wolfram Language. 2017. "FindRepeat." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/FindRepeat.html.

APA

Wolfram Language. (2017). FindRepeat. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FindRepeat.html

BibTeX

@misc{reference.wolfram_2024_findrepeat, author="Wolfram Research", title="{FindRepeat}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/FindRepeat.html}", note=[Accessed: 25-April-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_findrepeat, organization={Wolfram Research}, title={FindRepeat}, year={2017}, url={https://reference.wolfram.com/language/ref/FindRepeat.html}, note=[Accessed: 25-April-2024 ]}