# Chakravala method

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Chakravala_method
> Markdown URL: https://mediated.wiki/source/Chakravala_method.md
> Source: https://en.wikipedia.org/wiki/Chakravala_method
> Source revision: 1353884030
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Cyclic algorithm to solve indeterminate quadratic equations}}
The '''''chakravala'' method''' ({{langx|sa|चक्रवाल विधि}}) is a cyclic [algorithm](/source/algorithm) to solve [indeterminate](/source/Indeterminate_equation) [quadratic equation](/source/quadratic_equation)s, including [Pell's equation](/source/Pell's_equation). It is commonly attributed to [Bhāskara II](/source/Bh%C4%81skara_II), (c. 1114 – 1185 CE)<ref name=SBI200>Hoiberg & Ramchandani – Students' Britannica India: Bhaskaracharya II, page 200</ref><ref name=Kumar23>Kumar, page 23</ref> although some attribute it to [Jayadeva](/source/Jayadeva_(mathematician)) (c.  950 ~ 1000 CE).<ref name=Plofker474>Plofker, page 474{{full citation needed|date=April 2026}}</ref> Jayadeva pointed out that [Brahmagupta](/source/Brahmagupta)'s approach to solving equations of this type could be generalized, and he then described this general method, which was later refined by Bhāskara II in his ''[Bijaganita](/source/Bijaganita)'' treatise. He called it the Chakravala method: ''chakra'' meaning "wheel" in [Sanskrit](/source/Sanskrit), a reference to the cyclic nature of the algorithm.<ref name= Goonatilake127>Goonatilake, page 127 &ndash; 128</ref> C.-O. Selenius held that no European performances at the time of Bhāskara, nor much later, exceeded its marvellous height of mathematical complexity.<ref name=SBI200/><ref name= Goonatilake127/>

This method is also known as the '''cyclic method''' and contains traces of [mathematical induction](/source/mathematical_induction).<ref>Cajori (1918), p. 197<blockquote>"The process of reasoning called "Mathematical Induction" has had several independent origins. It has been traced back to the Swiss Jakob (James) Bernoulli, the Frenchman B. Pascal and P. Fermat, and the Italian F. Maurolycus. [...] By reading a little between the lines one can find traces of mathematical induction still earlier, in the writings of the Hindus and the Greeks, as, for instance, in the "cyclic method" of Bhaskara, and in Euclid's proof that the number of primes is infinite."</blockquote></ref>

== History ==
''Chakra'' in Sanskrit means cycle. As per popular legend, Chakravala indicates a mythical range of mountains which orbits around the Earth like a wall and not limited by light and darkness.<ref name=Madan>{{cite book|title=India through the ages|url=https://archive.org/details/indiathroughages00mada|last=Gopal|first=Madan|year= 1990| page= [https://archive.org/details/indiathroughages00mada/page/79 79]|editor=K.S. Gautam|publisher=Publication Division, Ministry of Information and Broadcasting, Government of India}}</ref>

[Brahmagupta](/source/Brahmagupta) in 628 CE studied indeterminate quadratic equations, including [Pell's equation](/source/Pell's_equation)

:<math>\,x^2 = Ny^2 + 1,</math>

for minimum integers ''x'' and ''y''. Brahmagupta could solve it for several ''N'', but not all.

Jayadeva  and Bhaskara  offered the first complete solution to the equation, using the ''chakravala'' method to find for <math>\,x^2 = 61y^2 + 1,</math> the solution

:<math>\,x = 1 766 319 049, y = 226 153 980.</math>

This case was notorious for its difficulty, and was first solved in [Europe](/source/Europe) by [Brouncker](/source/William_Brouncker%2C_2nd_Viscount_Brouncker) in 1657–58 in response to a challenge by [Fermat](/source/Pierre_de_Fermat), using continued fractions. A method for the general problem was first completely described rigorously by [Lagrange](/source/Lagrange) in 1766.<ref>{{MacTutor|class=HistTopics|id=Pell|title=Pell's equation}}</ref> Lagrange's method, however, requires the calculation of 10 iterations (not the 21 often claimed, since 10 iterations gives the solution <math>\,29718^2 = 61*3805^2 - 1,</math> which can be squared to eliminate the remaining 11 iterations) for  successive convergents of the [simple continued fraction](/source/simple_continued_fraction) for the [square root](/source/square_root) of 61, while the ''chakravala'' method is much simpler. Selenius, in his assessment of the ''chakravala'' method, states

:"The method represents a best approximation algorithm of minimal length that, owing to several minimization properties, with minimal effort and avoiding large numbers automatically produces the best solutions to the equation. The ''chakravala'' method anticipated the European methods by more than a thousand years. But no European performances in the whole field of [algebra](/source/algebra) at a time much later than Bhaskara's, nay nearly equal up to our times, equalled the marvellous complexity and ingenuity of ''chakravala''."<ref name=SBI200/><ref name= Goonatilake127/>

[Hermann Hankel](/source/Hermann_Hankel) calls the ''chakravala'' method
:"the finest thing achieved in the theory of numbers before Lagrange."<ref>Kaye (1919), p. 337.</ref>

==The method==
From [Brahmagupta's identity](/source/Brahmagupta's_identity), we observe that for given ''N'',

:<math>(x_1x_2 + Ny_1y_2)^2 - N(x_1y_2 + x_2y_1)^2 = (x_1^2 - Ny_1^2)(x_2^2 - Ny_2^2)</math>

For the equation <math>x^2 - Ny^2 = k</math>, this allows the "composition" (''samāsa'') of two solution triples <math>(x_1, y_1, k_1)</math> and <math>(x_2, y_2, k_2)</math> into a new triple

:<math>(x_1x_2 + Ny_1y_2 \,,\, x_1y_2 + x_2y_1 \,,\, k_1k_2).</math>

In the general method, the main idea is that any triple <math>(a,b,k)</math> (that is, one which satisfies <math>a^2 - Nb^2 = k</math>) can be composed with the trivial triple <math>(m, 1, m^2 - N)</math> to get the new triple <math>(am + Nb, a+bm, k(m^2-N))</math> for any ''m''. Assuming we started with a triple for which <math>\gcd(a,b)=1</math>, this can be scaled down by ''k'' (this is [Bhaskara's lemma](/source/Bhaskara's_lemma)):

:<math>a^2 - Nb^2 = k \Rightarrow \left(\frac{am+Nb}{k}\right)^2 - N\left(\frac{a+bm}{k}\right)^2 = \frac{m^2-N}{k}</math>

Since the signs inside the squares do not matter, the following substitutions are possible:

:<math>a\leftarrow\frac{am+Nb}{|k|}, b\leftarrow\frac{a+bm}{|k|}, k\leftarrow\frac{m^2-N}{k}</math>

When a positive integer ''m'' is chosen so that (''a''&nbsp;+&nbsp;''bm'')/''k'' is an integer, so are the other two numbers in the triple. Among such ''m'', the method chooses one that minimizes the absolute value of ''m''<sup>2</sup>&nbsp;&minus;&nbsp;''N'' and hence that of (''m''<sup>2</sup>&nbsp;&minus;&nbsp;''N'')/''k''. Then the substitution relations are applied for ''m'' equal to the chosen value. This results in a new triple (''a'', ''b'', ''k''). The process is repeated until a triple with <math>k=1</math> is found. This method always terminates with a solution, as proved by Lagrange in 1768.<ref name=stillwell>{{citation | year=2002 | title = Mathematics and its history | author1=John Stillwell | author-link=John Stillwell | edition=2 | publisher=Springer | isbn=978-0-387-95336-6 | pages=72–76 | url=https://books.google.com/books?id=WNjRrqTm62QC&pg=PA72}}</ref> Optionally, we can stop when ''k'' is ±1, ±2, or ±4, as Brahmagupta's approach gives a solution for those cases.{{Citation needed|date=September 2025}}

== Brahmagupta's composition method ==
In AD 628, Brahmagupta discovered a general way to find <math>x</math> and <math>y</math> of <math>x^2 = Ny^2 + 1,</math> when given <math>a^2 = Nb^2 + k</math>, when k is ±1, ±2, or ±4.<ref>{{Cite web|title=Pell's equation|url=https://mathshistory.st-andrews.ac.uk/HistTopics/Pell/|access-date=2021-06-14|website=Maths History|language=en}}</ref> 

=== ''k'' = ±1 ===
Using [Brahmagupta's identity](/source/Brahmagupta's_identity) to compose the triple <math>(a,b,k)</math> with itself:

: <math>(a^2+Nb^2)^2-N(2ab)^2=k^2</math> <math>\Rightarrow</math> <math>(2a^2-k)^2-N(2ab)^2=k^2</math>

The new triple can be expressed as <math>(2a^2-k,2ab,k^2)</math>.

Substituting <math>k=-1</math> gives a solution:

: <math>x=2a^2+1,  y=2ab</math>

For <math>k=1</math>, the original <math>(a,b)</math> was already a solution. Substituting <math>k=1</math> yields a second:

: <math>x=2a^2-1,  y=2ab</math>

=== ''k'' = ±2 ===
Again using the equation, <math>(2a^2-k)^2-N(2ab)^2=k^2</math><math>\Rightarrow</math><math> \left( \frac{2a^2-k}{k} \right)^2-N \left (\frac{2ab}{k} \right)^2=1</math>

Substituting <math>k=2</math>,

: <math>x=a^2-1, y=ab</math>

Substituting <math>k=-2</math>,

: <math>x=a^2+1, y=ab</math>

=== ''k'' = 4 ===
Substituting <math>k=4</math> into the equation <math> \left(\frac{2a^2-k}{k}\right)^2-N\left(\frac{2ab}{k}\right)^2=1</math> creates the triple <math> \left(\frac{a^2-2}{2},\frac{ab}{2},1\right),</math>

which is a solution if <math>a</math> is even:

: <math>x=\frac{a^2-2}{2}, y=\frac{ab}{2}. </math>

If ''a'' is odd, start with the equations <math>\left(\frac{a}{2}\right)^2-N\left(\frac{b}{2}\right)^2=1</math> and <math>\left(\frac{2a^2-4}{4})^2-N(\frac{2ab}{4} \right)^2=1</math>.

Leading to the triples <math>\left(\frac{a}{2},\frac{b}{2},1\right)</math> and <math> \left(\frac{a^2-2}{2},\frac{ab}{2},1\right)</math>. Composing the triples gives <math> \left(\frac{a}{2}(a^2-3)\right)^2-N\left(\frac{b}{2}(a^2-1)\right)^2=1</math>

When <math>a</math> is odd,

: <math>x=\frac{a}{2}(a^2-3), y=\frac{b}{2}(a^2-1)</math>

=== ''k'' = &minus;4 ===
When <math>k=-4</math>, then <math>\left(\frac{a}{2}\right)^2-N\left(\frac{b}{2}\right)^2=-1</math>. Composing with itself yields <math>\left(\frac{a^2+Nb^2}{4}\right)^2-N\left(\frac{ab}{2}\right)^2=1</math><math>\Rightarrow</math><math> \left(\frac{a^2+2}{2}\right)^2-N\left(\frac{ab}{2}\right)^2=1</math>.

Again composing itself yields <math>(\frac{(a^2+2)^2+Na^2b^2}{4})^2-N(\frac{ab(a^2+2)}{2})^2=1</math><math>\Rightarrow</math> <math>(\frac{a^4+4a^2+2}{2})^2-N(\frac{ab(a^2+2)}{2})^2=1</math>

Finally, from the earlier equations, compose the triples <math>(\frac{a^2+2}{2},\frac{ab}{2},1)</math> and <math>(\frac{a^4+4a^2+2}{2},\frac{ab(a^2+2)}{2},1)</math>, to get

: <math>(\frac{(a^2+2)(a^4+4a^2+2)+Na^2b^2 (a^2+2)}{4})^2-N(\frac{ab(a^4+4a^2+3)}{2})^2=1</math><math>\Rightarrow</math>

: <math>(\frac{(a^2+2)(a^4+4a^2+1)}{2})^2-N(\frac{ab(a^2+3)(a^2+1)}{2})^2=1</math><math>\Rightarrow</math><math>(\frac{(a^2+2)[(a^2+1)(a^2+3)-2)]}{2})^2-N(\frac{ab(a^2+3)(a^2+1)}{2})^2=1</math>. 

This gives us the solutions

: <math>x=\frac{(a^2+2)[(a^2+1)(a^2+3)-2]}{2}, \qquad y=\frac{ab(a^2+3)(a^2+1)}{2}</math><ref>{{Cite book|last=Datta and Singh|title=History of Hindu Mathematics : A Source Book Parts I and II|publisher=Asia Publishing House|year=1962|isbn=8180903907|pages=157–160}}</ref>

(Note, <math>k=-4</math> is useful to find a solution to [Pell's Equation](/source/Pell's_equation), but it is not always the smallest integer pair. e.g. <math>36^2-52\cdot5^2=-4</math>. The equation will give you <math>x=1093435849, y=151632270</math>, which when put into Pell's Equation yields <math>1195601955878350801-1195601955878350800 = 1</math>, which works, but so does <math>x = 649,y=90</math> for <math>N=52</math>.

==Examples ==
===''n'' = 61===
The ''n''&nbsp;=&nbsp;61 case (determining an integer solution satisfying <math>a^2 - 61b^2 = 1</math>), issued as a challenge by Fermat many centuries later, was given by Bhaskara as an example.<ref name=stillwell/>

We start with a solution <math>a^2 - 61b^2 = k</math> for any ''k'' found by any means. In this case we can let ''b'' be 1, thus, since <math>8^2 - 61\cdot1^2 = 3</math>, we have the triple <math>(a,b,k) = (8, 1, 3)</math>. Composing it with <math>(m, 1, m^2-61)</math> gives the triple <math>(8m+61, 8+m, 3(m^2-61))</math>, which is scaled down (or [Bhaskara's lemma](/source/Bhaskara's_lemma) is directly used) to get:
: <math>\left( \frac{8m+61}{3}, \frac{8+m}{3}, \frac{m^2-61}{3} \right).</math>

For 3 to divide <math>8+m</math> and <math>|m^2-61|</math> to be minimal, we choose <math>m=7</math>, so that we have the triple <math>(39, 5, -4)</math>. Now that ''k'' is &minus;4, we can use Brahmagupta's idea: it can be scaled down to the rational solution <math>(39/2, 5/2, -1)\,</math>, which composed with itself three times, with <math>m={7,11,9}</math> respectively, when k becomes square and scaling can be applied, this gives <math>(1523/2, 195/2, 1)\,</math>. Finally, such procedure can be repeated until the solution is found (requiring 9 additional self-compositions and 4 additional square-scalings): <math>(1766319049,\, 226153980,\, 1)</math>. This is the minimal integer solution.

===''n'' = 67===
Suppose we are to solve <math>x^2 - 67y^2 = 1</math> for ''x'' and ''y''.<ref>The example in this section is given (with notation <math>Q_n</math> for ''k'', <math>P_n</math> for ''m'', etc.) in: {{citation | year=2009 | title = Solving the Pell equation | author1=Michael J. Jacobson | author2=Hugh C. Williams | publisher=Springer | isbn=978-0-387-84922-5 | page=31 | url=https://books.google.com/books?id=2INzqrEUGzAC&pg=PA31}}</ref>

We start with a solution <math>a^2 - 67b^2 = k</math> for any ''k'' found by any means; in this case we can let ''b'' be 1, thus producing <math>8^2 - 67\cdot1^2 = -3</math>. At each step, we find an ''m''&nbsp;>&nbsp;0 such that ''k'' divides ''a''&nbsp;+&nbsp;''bm'', and |''m''<sup>2</sup>&nbsp;&minus;&nbsp;67| is minimal. We then update ''a'', ''b'', and ''k'' to <math>\frac{am+Nb}{|k|}, \frac{a+bm}{|k|}</math> and <math>\frac{m^2-N}{k}</math> respectively.

;First iteration
We have <math>(a,b,k) = (8,1,-3)</math>. We want a positive integer ''m'' such that ''k'' divides ''a''&nbsp;+&nbsp;''bm'', i.e. 3 divides 8 + m, and |''m''<sup>2</sup>&nbsp;&minus;&nbsp;67| is minimal. The first condition implies that ''m'' is of the form 3''t'' + 1 (i.e. 1, 4, 7, 10,… etc.), and among such ''m'', the minimal value is attained for ''m'' = 7. Replacing (''a'',&nbsp;''b'',&nbsp;''k'') with <math>\left(\frac{am+Nb}{|k|}, \frac{a+bm}{|k|}, \frac{m^2-N}{k}\right)</math>, we get the new values <math>a = (8\cdot7+67\cdot1)/3 = 41, b = (8 + 1\cdot7)/3 = 5, k = (7^2-67)/(-3) = 6</math>. That is, we have the new solution:
: <math>41^2 - 67\cdot(5)^2 = 6.</math>

At this point, one round of the cyclic algorithm is complete.

;Second iteration
We now repeat the process. We have <math>(a,b,k) = (41,5,6)</math>. We want an ''m''&nbsp;>&nbsp;0 such that ''k'' divides ''a''&nbsp;+&nbsp;''bm'', i.e. 6 divides 41&nbsp;+&nbsp;5''m'', and |''m''<sup>2</sup>&nbsp;&minus;&nbsp;67| is minimal. The first condition implies that ''m'' is of the form 6''t''&nbsp;+&nbsp;5 (i.e. 5, 11, 17,… etc.), and among such ''m'', |''m''<sup>2</sup>&nbsp;&minus;&nbsp;67| is minimal for ''m''&nbsp;=&nbsp;5. This leads to the new solution 
<math>\frac{41\cdot5 + 61\cdot5}{6}</math>

:<math>90^2 - 67 \cdot 11^2 = -7.</math>

;Third iteration
For 7 to divide 90 + 11''m'', we must have ''m'' = 2&nbsp;+&nbsp;7''t'' (i.e. 2, 9, 16,… etc.) and among such ''m'', we pick ''m'' = 9.

:<math>221^2 - 67\cdot 27^2 = -2.</math>

;Final solution
At this point, we could continue with the cyclic method (and it would end, after seven iterations), but since the right-hand side is among ±1, ±2, ±4, we can also use Brahmagupta's observation directly. Composing the triple (221, 27, &minus;2) with itself, we get
:<math> \left(\frac{221^2 + 67\cdot27^2}{2}\right)^2 - 67\cdot(221\cdot27)^2 = 1,</math>

that is, we have the integer solution:
:<math> 48842^2 - 67 \cdot 5967^2 = 1.</math>

This equation approximates <math>\sqrt{67}</math>  as  <math> \frac{48842}{5967}</math> to within a margin of about <math> 2 \times 10^{-9}</math>.

==Notes==
{{Reflist}}

==References==
*[Florian Cajori](/source/Florian_Cajori) (1918), Origin of the Name "Mathematical Induction", ''[The American Mathematical Monthly](/source/The_American_Mathematical_Monthly)'' '''25''' (5), pp.&nbsp;197–201.
*George Gheverghese Joseph, ''[The Crest of the Peacock: Non-European Roots of Mathematics](/source/The_Crest_of_the_Peacock%3A_Non-European_Roots_of_Mathematics)'' (1975).
*G. R. Kaye, "Indian Mathematics", ''Isis'' '''2''':2 (1919), pp.&nbsp;326–356.
*Clas-Olaf Selenius, [http://www.msc.uky.edu/sohum/ma330/files/Rationale-of-the-chakrav-la-process-of-Jayadeva-and-Bh-skara-II_1975_Historia-Mathematica.pdf "Rationale of the chakravala process of Jayadeva and Bhaskara II"] {{Webarchive|url=https://web.archive.org/web/20211130203434/http://www.msc.uky.edu/sohum/ma330/files/Rationale-of-the-chakrav-la-process-of-Jayadeva-and-Bh-skara-II_1975_Historia-Mathematica.pdf |date=2021-11-30 }}, ''Historia Mathematica'' '''2''' (1975), pp.&nbsp;167–184.
*Clas-Olaf Selenius, "Kettenbruchtheoretische Erklärung der zyklischen Methode zur Lösung der Bhaskara-Pell-Gleichung", ''Acta Acad. Abo. Math. Phys.'' '''23''' (10) (1963), pp.&nbsp;1–44.
*Hoiberg, Dale & Ramchandani, Indu (2000). ''Students' Britannica India''. Mumbai: Popular Prakashan. {{isbn|0-85229-760-2}}
*Goonatilake, Susantha (1998). ''Toward a Global Science: Mining Civilizational Knowledge''. Indiana: Indiana University Press. {{isbn|0-253-33388-1}}.
*Kumar, Narendra (2004). ''Science in Ancient India''. Delhi: Anmol Publications Pvt Ltd. {{isbn|81-261-2056-8}}
*Ploker, Kim (2007) "Mathematics in India". ''The Mathematics of Egypt, Mesopotamia, China, India, and Islam: A Sourcebook'' New Jersey: Princeton University Press. {{isbn|0-691-11485-4}}
*{{cite book
  | last = Edwards
  | first = Harold
  | title = Fermat's Last Theorem
  | publisher = [Springer](/source/Springer_Science%2BBusiness_Media)
  | location = New York
  | date = 1977
  | isbn = 0-387-90230-9}}

==External links==
*[https://web.archive.org/web/20110707120031/http://www-groups.dcs.st-and.ac.uk/~history/Miscellaneous/Pearce/Lectures/Ch8_6.html Introduction to chakravala]

{{number theoretic algorithms}}

Category:Brahmagupta
Category:Diophantine equations
Category:Number theoretic algorithms
Category:Indian mathematics

---
Adapted from the Wikipedia article [Chakravala method](https://en.wikipedia.org/wiki/Chakravala_method) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Chakravala_method?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
