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.
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 all close allBasic Examples (4)
Find the sublist that repeats to form a list:
FindRepeat[{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}]The last sublist does not need to be complete:
FindRepeat[{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3}]Find a sublist that repeats at least four times:
FindRepeat[{1, 2, 1, 2, 1, 2, 1, 2}, 4]An empty list is returned if no sublist satisfies the condition:
FindRepeat[{1, 2, 1, 2, 1, 2, 1, 2}, 5]Find the repeated block of a matrix:
mat = ArrayPad[{{a, b, c}, {d, e, f}}, 2, "Periodic"];
MatrixForm[mat]FindRepeat[mat]//MatrixFormFind the repeated substring of a string:
str = StringRepeat["hello", 10]FindRepeat[str]Scope (10)
One-Argument Form (8)
Find the repeated part of a list of any type of element:
FindRepeat[{a, b, a, b, a, b}]FindRepeat[{1, 2, 3, 4, 1, 2, 3, 4, 1}]The elements of the first argument can have different heads:
FindRepeat[{1, a, {}, f[2], 1, a, {}, f[2]}]Find the repeated block of a matrix:
(mat = Table[Mod[i, 3] + Mod[j, 4], {i, 0, 8}, {j, 0, 8}])//MatrixFormFindRepeat[mat]//MatrixFormFind the repeated block of an array of any depth:
arr = Table[Sin[i π] + Cos[j π / 3] + Sin[k π / 2], {i, 0, 10}, {j, 0, 10}, {k, 0, 10}];FindRepeat[arr]FindRepeat works with SparseArray:
sa = SparseArray[{{i_, j_} /; {Mod[i, 6], Mod[j, 4]} === {0, 0} -> 1}, {100, 100}]FindRepeat[sa]FindRepeat works with QuantityArray:
qa = QuantityArray[ArrayPad[{{1, 2, 3}, {4, 5, 6}}, 100, "Periodic"], "Meters"]FindRepeat[qa]Find the repeated part of an association:
FindRepeat[<|a -> 1, b -> 2, c -> 1, d -> 2, e -> 1, f -> 2|>]Find the repeated part of a string:
FindRepeat["abcdabcdabcdabcdabcd"]Two-Argument Form (2)
Find a sublist that repeats at least three times:
list = ArrayPad[{1, 2, 3}, 4, "Periodic"]FindRepeat[list, 3]FindRepeat returns an empty list if no sublist satisfies the condition:
FindRepeat[list, 4]Find the repeated part of an array at different levels:
arr = Table[Mod[i, 3] + Mod[j, 4] + Mod[k, 2], {i, 0, 7}, {j, 0, 7}, {k, 0, 7}];
Dimensions[arr]FindRepeat[arr, {1}] === Take[arr, 3]FindRepeat[arr, {1, 1}] === Take[arr, 3, 4]FindRepeat[arr, {1, 1, 1}] === Take[arr, 3, 4, 2]FindRepeat[arr] is equivalent to the deepest of those cases:
FindRepeat[arr]% === FindRepeat[arr, {1, 1, 1}]Options (4)
SameTest (4)
Use equivalence classes based on absolute value:
FindRepeat[{1, 2, -3, -1, 2, 3, -1, -2}, SameTest -> (Abs[#1] == Abs[#2]&)]Use equivalence classes based on Floor:
FindRepeat[{1, 2, 3, 1.5, 2.8, 3.7, 1.1, 2.6}, SameTest -> (Floor[#1] == Floor[#2]&)]Use Total of list elements:
FindRepeat[{{1, 2}, {5, -2}, {2, 1}, {0, 3}, {-1, 4}}, {1}, SameTest -> (Total[#1] == Total[#2]&)]In FindRepeat[list,{n1,…,nk},SameTest->test], the function test is applied on elements of list at level k:
mat = {{1, 2}, {1, 3}, {1, 4}};FindRepeat[mat, {1}, SameTest -> (Min[#1] == Min[#2]&)]FindRepeat[mat, {1, 1}, SameTest -> (Min[#1] == Min[#2]&)]Applications (6)
Find the repeated block of an array:
arr = Table[Mod[i, 2] + Mod[j, 5] + Mod[k, 4], {i, 20}, {j, 20}, {k, 20}];repeatedblock = FindRepeat[arr]Reconstruct the original array by specifying how many times the block is repeated:
repetitions = Dimensions[arr] / Dimensions[repeatedblock]KroneckerProduct[ConstantArray[1, repetitions], repeatedblock] === arrVisualize the repeated block of an array with MatrixPlot:
arr = ArrayPad[{{1, 2, 3}, {4, 5, 6}}, {6, 6}, "Periodic"];
MatrixPlot[arr]repeat = FindRepeat[arr];
MatrixPlot[repeat]The Metonic cycle of the Jewish calendar spans 235 months:
dates = DateRange[Today, Today + Quantity[100, "Years"], "Month", CalendarType -> "Jewish"];months = Comap[dates, "MonthName"];
Length[months]repeat = FindRepeat[months];
Length[repeat]This code gives the Julian calendar date of Julian Easter for a given year:
JulianEasterSunday[year_] := Module[{a, b, c, d, e, month, day},
a = Mod[year, 4];
b = Mod[year, 7];
c = Mod[year, 19];
d = Mod[19c + 15, 30];
e = Mod[2a + 4b - d + 34, 7];
month = Quotient[d + e + 114, 31];
day = Mod[d + e + 114, 31] + 1;
DateObject[{year, month, day}, CalendarType -> "Julian"]
]For the year 2017, it falls on April 3 in the Julian calendar, or April 16 in the Gregorian calendar:
JulianEasterSunday[2017]CalendarConvert[%, "Gregorian"]Compute the dates of Julian Easter for the years 1 to 2000, all falling between Julian March 22 and April 25:
RandomSample[dates = JulianEasterSunday /@ Range[2000], 4]The dates follow a cyclic pattern that repeats every 532 years:
FindRepeat[Rest /@ dates[[All, 1]]]//LengthFind the period of a continuous function:
ns = Range[0, 8π, π / 6];
repeat = FindRepeat[Cos[ns]]Length[repeat]π / 6Compare with FunctionPeriod:
FunctionPeriod[Cos[n], n]Recover the generator of a StringRepeat expression:
str = StringRepeat["world", 10]FindRepeat[str]Properties & Relations (5)
FindRepeat can detect an incomplete copy of the repeated sequence:
FindRepeat[{1, 2, 3, 1, 2, 3, 1, 2}]FindRepeat[list,1] returns list if no smaller repetition is found:
FindRepeat[{1, 2, 1, 2, 1, 2}, 1]FindRepeat[{a, b, c, d, e, f}, 1]When no repeated block satisfies the condition on the number of occurrences, FindRepeat returns an empty list:
FindRepeat[{1, 2, 1, 2, 1, 2}, 4]FindRepeat[{a, b, c, d, e, f}, 4]By default, the second argument of FindRepeat is a list of 1s of length given by the array depth of the first argument:
expr = {{1, 2, 3, 4}, {a, b, c, d}, {1, 2, 3, 4}, {a, b, c, d}};repeat = FindRepeat[expr]repeat === FindRepeat[expr, Table[1, ArrayDepth[expr]]]FindRepeat finds the repeated part of an expression:
FindRepeat[{1, 2, 1, 2, 1, 2}, 2]FindTransientRepeat allows the presence of a transient part:
FindTransientRepeat[{a, b, 1, 2, 1, 2, 1, 2}, 2]When an expression has no transient part, FindRepeat[expr,n] is identical to Last[FindTransientRepeat[expr,n]]:
expr = "abcabcabc"rep = FindRepeat[expr, 2]trep = FindTransientRepeat[expr, 2]rep === Last[trep]Related Guides
History
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_2026_findrepeat, author="Wolfram Research", title="{FindRepeat}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/FindRepeat.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_findrepeat, organization={Wolfram Research}, title={FindRepeat}, year={2017}, url={https://reference.wolfram.com/language/ref/FindRepeat.html}, note=[Accessed: 12-June-2026]}