<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.xen.wiki/index.php?action=history&amp;feed=atom&amp;title=Brun%27s_algorithm</id>
	<title>Brun&#039;s algorithm - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://en.xen.wiki/index.php?action=history&amp;feed=atom&amp;title=Brun%27s_algorithm"/>
	<link rel="alternate" type="text/html" href="https://en.xen.wiki/index.php?title=Brun%27s_algorithm&amp;action=history"/>
	<updated>2026-10-17T12:14:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://en.xen.wiki/index.php?title=Brun%27s_algorithm&amp;diff=239905&amp;oldid=prev</id>
		<title>Naren: Create page</title>
		<link rel="alternate" type="text/html" href="https://en.xen.wiki/index.php?title=Brun%27s_algorithm&amp;diff=239905&amp;oldid=prev"/>
		<updated>2026-10-16T19:28:18Z</updated>

		<summary type="html">&lt;p&gt;Create page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Brun&amp;#039;s algorithm&amp;#039;&amp;#039;&amp;#039; is an extension of continued fractions to more than one number.&amp;lt;ref name=&amp;quot;brun1964euclidean&amp;quot;/&amp;gt;&amp;lt;ref name=&amp;quot;mandelbaum1961multiple&amp;quot;/&amp;gt;&lt;br /&gt;
It can be used to find [[EDO]]s that contain good approximations to given [[just]] ratios.&lt;br /&gt;
&lt;br /&gt;
== Algorithm ==&lt;br /&gt;
Say we would like to find EDOs which have good approximations of 5/4, 3/2, and 2/1.&lt;br /&gt;
First, write the corresponding cents values, largest to smallest, in a vector &amp;lt;math&amp;gt;A_{0}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;block&amp;quot;&amp;gt;&lt;br /&gt;
A_{0} =&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1200.00 \\&lt;br /&gt;
701.96 \\&lt;br /&gt;
386.31&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now write &amp;lt;math&amp;gt;XA = A_{0}&amp;lt;/math&amp;gt;, where to begin with &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the identity matrix and &amp;lt;math&amp;gt;A = A_{0}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;block&amp;quot;&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; 0 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 1 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; 1&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1200.00 \\&lt;br /&gt;
701.96 \\&lt;br /&gt;
386.31&lt;br /&gt;
\end{bmatrix} \\&lt;br /&gt;
  =&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1200.00 \\&lt;br /&gt;
701.96 \\&lt;br /&gt;
386.31&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each iteration of the algorithm transforms &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; such that&lt;br /&gt;
* We preserve &amp;lt;math&amp;gt;X A = A_{0}&amp;lt;/math&amp;gt;&lt;br /&gt;
* The elements of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; get smaller&lt;br /&gt;
* The first column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; gives a better EDO approximation of &amp;lt;math&amp;gt;A_{0}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do one iteration of the algorithm,&lt;br /&gt;
firstly subtract the second element from the first element in the cents vector &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;&lt;br /&gt;
and add the first column to the second column in the matrix &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;, giving&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;block&amp;quot;&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; 0 + 1 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 1 + 0  &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 + 0 &amp;amp; 1&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1200.00 - 701.96 \\&lt;br /&gt;
701.96 \\&lt;br /&gt;
386.31&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
  =&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; 1 &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 1  &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; 1&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
498.04 \\&lt;br /&gt;
701.96 \\&lt;br /&gt;
386.31&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Secondly, sort the cents vector &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; and rearrange the columns of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; in the corresponding order, giving&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;block&amp;quot;&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1 &amp;amp; 1 &amp;amp; 0 \\&lt;br /&gt;
1 &amp;amp; 0  &amp;amp; 0 \\&lt;br /&gt;
0 &amp;amp; 0 &amp;amp; 1&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
701.96 \\&lt;br /&gt;
498.04 \\&lt;br /&gt;
386.31&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Repeating this process gives:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; !! &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; !! Ratios&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}1200.00 \\ 701.96 \\ 386.31\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}2/1 \\ 3/2 \\ 5/4\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}1 &amp;amp; 1 &amp;amp; 0 \\ 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}701.96 \\ 498.04 \\ 386.31\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}3/2 \\ 4/3 \\ 5/4\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}2 &amp;amp; 0 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 1 &amp;amp; 0\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}498.04 \\ 386.31 \\ 203.91\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}4/3 \\ 5/4 \\ 9/8\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}2 &amp;amp; 1 &amp;amp; 2 \\ 1 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 0 &amp;amp; 0\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}386.31 \\ 203.91 \\ 111.73\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}5/4 \\ 9/8 \\ 16/15\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}3 &amp;amp; 2 &amp;amp; 2 \\ 2 &amp;amp; 1 &amp;amp; 1 \\ 1 &amp;amp; 1 &amp;amp; 0\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}203.91 \\ 182.40 \\ 111.73\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}9/8 \\ 10/9 \\ 16/15\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}5 &amp;amp; 2 &amp;amp; 3 \\ 3 &amp;amp; 1 &amp;amp; 2 \\ 2 &amp;amp; 0 &amp;amp; 1\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}182.40 \\ 111.73 \\ 21.51\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}10/9 \\ 16/15 \\ 81/80\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}7 &amp;amp; 5 &amp;amp; 3 \\ 4 &amp;amp; 3 &amp;amp; 2 \\ 2 &amp;amp; 2 &amp;amp; 1\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}111.73 \\ 70.67 \\ 21.51\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}16/15 \\ 25/24 \\ 81/80\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}12 &amp;amp; 7 &amp;amp; 3 \\ 7 &amp;amp; 4 &amp;amp; 2 \\ 4 &amp;amp; 2 &amp;amp; 1\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}70.67 \\ 41.06 \\ 21.51\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}25/24 \\ 128/125 \\ 81/80\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}19 &amp;amp; 12 &amp;amp; 3 \\ 11 &amp;amp; 7 &amp;amp; 2 \\ 6 &amp;amp; 4 &amp;amp; 1\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}41.06 \\ 29.61 \\ 21.51\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}128/125 \\ 3125/3072 \\ 81/80\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}31 &amp;amp; 3 &amp;amp; 19 \\ 18 &amp;amp; 2 &amp;amp; 11 \\ 10 &amp;amp; 1 &amp;amp; 6\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}29.61 \\ 21.51 \\ 11.45\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
| &amp;lt;math&amp;gt;\begin{bmatrix}3125/3072 \\ 81/80 \\ 393216/390625\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Here each row shows one iteration of the algorithm.&lt;br /&gt;
The Ratios column shows the ratios corresponding to the cents values in &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;&lt;br /&gt;
(from dividing ratios each time we subtract cents values).&lt;br /&gt;
&lt;br /&gt;
The first column of each matrix &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; gives an EDO approximation to &amp;lt;math&amp;gt;A_{0}&amp;lt;/math&amp;gt;.&lt;br /&gt;
For example, the matrix with first column &amp;lt;math&amp;gt;[31, 18, 10]&amp;lt;/math&amp;gt; gives&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;block&amp;quot;&amp;gt;&lt;br /&gt;
\begin{aligned}&lt;br /&gt;
\frac{1200}{31}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
31 \\&lt;br /&gt;
18 \\&lt;br /&gt;
10&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
  &amp;amp;=&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1200.00 \\&lt;br /&gt;
696.77 \\&lt;br /&gt;
387.10&lt;br /&gt;
\end{bmatrix} \\&lt;br /&gt;
  &amp;amp;\approx&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
1200.00 \\&lt;br /&gt;
701.96 \\&lt;br /&gt;
386.31&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\end{aligned}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
The following Python code implements Brun&amp;#039;s algorithm.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
target_ratios = [5/4, 3/2, 2/1]&lt;br /&gt;
&lt;br /&gt;
A = 1200 * np.log2(sorted(target_ratios, reverse=True))&lt;br /&gt;
X = np.identity(len(A), dtype=np.int64)&lt;br /&gt;
&lt;br /&gt;
while X.max() &amp;lt;= 100:&lt;br /&gt;
    print(f&amp;quot;{X}\n{A}\n&amp;quot;)&lt;br /&gt;
    A[0] -= A[1]&lt;br /&gt;
    X[:, 1] += X[:, 0]&lt;br /&gt;
    i = np.argsort(-A)&lt;br /&gt;
    A = A[i]&lt;br /&gt;
    X = X[:, i]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other applications ==&lt;br /&gt;
[[Erv Wilson]] used the intervals generated by Brun&amp;#039;s algorithm to construct scales.&amp;lt;ref name=&amp;quot;wilson1995brun&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;brun1964euclidean&amp;quot;&amp;gt;&lt;br /&gt;
Viggo Brun, [https://www.anaphoria.com/brun-euclideanalgo.pdf Euclidean Algorithms and Musical Theory]. L&amp;#039;Enseignement Mathématique 10, 1964.&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;mandelbaum1961multiple&amp;quot;&amp;gt;&lt;br /&gt;
[[Joel Mandelbaum]], [https://anaphoria.com/mandelbaum.html Multiple Division of the Octave and the Tonal Resources of 19-tone Temperament], Chapter 13, page 370. 1961.&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wilson1995brun&amp;quot;&amp;gt;&lt;br /&gt;
[[Erv Wilson]], [https://www.anaphoria.com/viggo3.pdf A Sequence of Constant Structures as Predicted by Brun&amp;#039;s Algorithm]. 1995.&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [https://narenratan.com/tools/bruntosaur/ bruntosaur] - Online Brun&amp;#039;s algorithm calculator&lt;/div&gt;</summary>
		<author><name>Naren</name></author>
	</entry>
</feed>