Skip links

“Cyclic” Function in Mathematica 14.3

“Cyclic” is a new function introduced in the recent Wolfram Mathematica 14.3 release. It represents a repeating sequence, something that we encounter often.

For example, how do we represent the sequence {1,2,3,4,1,2,3,4,1,2,3,4…}? “Cyclic” captures this idea. In other words “Cyclic[{1,2,3,4}]” denotes the same repeating sequence as above.

Other examples:

weekdays = Cyclic[{“Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”, “Sun”}];

musicnotes = Cyclic[{“C”, “D”, “E”, “F”, “G”, “A”, “B”}];

How do we access the elements of a Cyclic object? See the figure below.

Accessing Cyclic Elements
Accessing Cyclic Elements

We can use any positive or negative number to access the element.

Let us assume that we want to take some number of elements (in the same order) from a Cyclic object. Here is how we can do it:

Collecting Multiple Elements
Collecting Multiple Elements

Let us create a RandomTree:

RandomTree
RandomTree

How about generating musical tones?

Generating Musical Notes
Generating Musical Notes

Let us add some instruments to make it more colourful!

Multi-instrument Notes
Multi-instrument Notes

Yes, “Cyclic” is indeed a nice abstraction to walk through an ordered sequence. I hope this article gives a good overview.

Have a nice weekend!

Leave a comment