Tonelli–Shanks algorithm

The Tonelli–Shanks algorithm (referred to by Shanks as the RESSOL algorithm) is used in modular arithmetic to solve for r in a congruence of the form r2n (mod p), where p is a prime: that is, to find a square root of n modulo p.

Tonelli–Shanks cannot be used for composite moduli: finding square roots modulo composite numbers is a computational problem equivalent to integer factorization.[1]

An equivalent, but slightly more redundant version of this algorithm was developed by Alberto Tonelli[2][3] in 1891. The version discussed here was developed independently by Daniel Shanks in 1973, who explained:

My tardiness in learning of these historical references was because I had lent Volume 1 of Dickson's History to a friend and it was never returned.[4]

According to Dickson,[3] Tonelli's algorithm can take square roots of x modulo prime powers pλ apart from primes.

Core ideas

Given a non-zero and a prime (which will always be odd), Euler's criterion tells us that has a square root (i.e., is a quadratic residue) if and only if:

.

In contrast, if a number has no square root (is a non-residue), Euler's criterion tells us that:

.

It is not hard to find such , because half of the integers between 1 and have this property. So we assume that we have access to such a non-residue.

By (normally) dividing by 2 repeatedly, we can write as , where is odd. Note that if we try

,

then . If , then is a square root of . Otherwise, for , we have and satisfying:

  • ; and
  • is a -th root of 1 (because ).

If, given a choice of and for a particular satisfying the above (where is not a square root of ), we can easily calculate another and for such that the above relations hold, then we can repeat this until becomes a -th root of 1, i.e., . At that point is a square root of .

We can check whether is a -th root of 1 by squaring it times and check whether it is 1. If it is, then we do not need to do anything, as the same choice of and works. But if it is not, must be -1 (because squaring it gives 1, and there can only be two square roots 1 and -1 of 1 modulo ).

To find a new pair of and , we can multiply by a factor , to be determined. Then must be multiplied by a factor to keep . So, when is -1, we need to find a factor so that is a -th root of 1, or equivalently is a -th root of -1.

The trick here is to make use of , the known non-residue. The Euler's criterion applied to shown above says that is a -th root of -1. So by squaring repeatedly, we have access to a sequence of -th root of -1. We can select the right one to serve as . With a little bit of variable maintenance and trivial case compression, the algorithm below emerges naturally.

The algorithm

Operations and comparisons on elements of the multiplicative group of integers modulo p are implicitly mod p.

Inputs:

  • p, a prime
  • n, an element of such that solutions to the congruence r2 = n exist; when this is so we say that n is a quadratic residue mod p.

Outputs:

  • r in such that r2 = n

Algorithm:

  1. By factoring out powers of 2, find Q and S such that with Q odd
  2. Search for a z in which is a quadratic non-residue
  3. Let
  4. Loop:
    • If t = 0, return r = 0
    • If t = 1, return r = R
    • Otherwise, use repeated squaring to find the least i, 0 < i < M, such that
    • Let , and set

Once you have solved the congruence with r the second solution is . If the least i such that is M, then no solution to the congruence exists, i.e. n is not a quadratic residue.

This is most useful when p ≡ 1 (mod 4).

For primes such that p ≡ 3 (mod 4), this problem has possible solutions . If these satisfy , they are the only solutions. If not, , n is a quadratic non-residue, and there are no solutions.

Proof

We can show that at the start of each iteration of the loop the following loop invariants hold:

Initially:

  • (since z is a quadratic nonresidue, per Euler's criterion)
  • (since n is a quadratic residue)

At each iteration, with M' , c' , t' , R' the new values replacing M, c, t, R:

    • since we have that but (i is the least value such that )

From and the test against t = 1 at the start of the loop, we see that we will always find an i in 0 < i < M such that . M is strictly smaller on each iteration, and thus the algorithm is guaranteed to halt. When we hit the condition t = 1 and halt, the last loop invariant implies that R2 = n.

Order of t

We can alternately express the loop invariants using the order of the elements:

  • as before

Each step of the algorithm moves t into a smaller subgroup by measuring the exact order of t and multiplying it by an element of the same order.

Example

Solving the congruence r2 ≡ 5 (mod 41). 41 is prime as required and 41 ≡ 1 (mod 4). 5 is a quadratic residue by Euler's criterion: (as before, operations in are implicitly mod 41).

  1. so ,
  2. Find a value for z:
    • , so 2 is a quadratic residue by Euler's criterion.
    • , so 3 is a quadratic nonresidue: set
  3. Set
  4. Loop:
    • First iteration:
      • , so we're not finished
      • , so
    • Second iteration:
      • , so we're still not finished
      • so
    • Third iteration:
      • , and we are finished; return

Indeed, 282 ≡ 5 (mod 41) and (−28)2 ≡ 132 ≡ 5 (mod 41). So the algorithm yields the two solutions to our congruence.

Speed of the algorithm

The Tonelli–Shanks algorithm requires (on average over all possible input (quadratic residues and quadratic nonresidues))

modular multiplications, where is the number of digits in the binary representation of and is the number of ones in the binary representation of . If the required quadratic nonresidue is to be found by checking if a randomly taken number is a quadratic nonresidue, it requires (on average) computations of the Legendre symbol.[5] The average of two computations of the Legendre symbol are explained as follows: is a quadratic residue with chance , which is smaller than but , so we will on average need to check if a is a quadratic residue two times.

This shows essentially that the Tonelli–Shanks algorithm works very well if the modulus is random, that is, if is not particularly large with respect to the number of digits in the binary representation of . As written above, Cipolla's algorithm works better than Tonelli–Shanks if (and only if) . However, if one instead uses Sutherland's algorithm to perform the discrete logarithm computation in the 2-Sylow subgroup of , one may replace with an expression that is asymptotically bounded by .[6] Explicitly, one computes such that and then satisfies (note that is a multiple of 2 because is a quadratic residue).

The algorithm requires us to find a quadratic nonresidue . There is no known deterministic algorithm that runs in polynomial time for finding such a . However, if the generalized Riemann hypothesis is true, there exists a quadratic nonresidue ,[7] making it possible to check every up to that limit and find a suitable within polynomial time. Keep in mind, however, that this is a worst-case scenario; in general, is found in on average 2 trials as stated above.

Uses

The Tonelli–Shanks algorithm can (naturally) be used for any process in which square roots modulo a prime are necessary. For example, it can be used for finding points on elliptic curves. It is also useful for the computations in the Rabin cryptosystem and in the sieving step of the quadratic sieve.

Generalizations

Tonelli–Shanks can be generalized to any cyclic group (instead of ) and to kth roots for arbitrary integer k, in particular to taking the kth root of an element of a finite field.[8]

If many square-roots must be done in the same cyclic group and S is not too large, a table of square-roots of the elements of 2-power order can be prepared in advance and the algorithm simplified and sped up as follows.

  1. Factor out powers of 2 from p − 1, defining Q and S as: with Q odd.
  2. Let
  3. Find from the table such that and set
  4. return R.

Tonelli's algorithm will work on mod p^k

According to Dickson's "Theory of Numbers"[3]

A. Tonelli[9] gave an explicit formula for the roots of [3]

The Dickson reference shows the following formula for the square root of .

when , or (s must be 2 for this equation) and such that
for then
where

Noting that and noting that then

To take another example: and

Dickson also attributes the following equation to Tonelli:

where and ;

Using and using the modulus of the math follows:

First, find the modular square root mod which can be done by the regular Tonelli algorithm:

and thus

And applying Tonelli's equation (see above):

Dickson's reference[3] clearly shows that Tonelli's algorithm works on moduli of .

Notes

  1. ^ Oded Goldreich, Computational complexity: a conceptual perspective, Cambridge University Press, 2008, p. 588.
  2. ^ Volker Diekert; Manfred Kufleitner; Gerhard Rosenberger; Ulrich Hertrampf (24 May 2016). Discrete Algebraic Methods: Arithmetic, Cryptography, Automata and Groups. De Gruyter. pp. 163–165. ISBN 978-3-11-041632-9.
  3. ^ a b c d e Leonard Eugene Dickson (1919). History of the Theory of Numbers. Vol. 1. Washington, Carnegie Institution of Washington. pp. 215–216.
  4. ^ Daniel Shanks. Five Number-theoretic Algorithms. Proceedings of the Second Manitoba Conference on Numerical Mathematics. Pp. 51–70. 1973.
  5. ^ Tornaría, Gonzalo (2002). "Square Roots Modulo P". LATIN 2002: Theoretical Informatics. Lecture Notes in Computer Science. Vol. 2286. pp. 430–434. doi:10.1007/3-540-45995-2_38. ISBN 978-3-540-43400-9.
  6. ^ Sutherland, Andrew V. (2011), "Structure computation and discrete logarithms in finite abelian p-groups", Mathematics of Computation, 80 (273): 477–500, arXiv:0809.3413, doi:10.1090/s0025-5718-10-02356-2, S2CID 13940949
  7. ^ Bach, Eric (1990), "Explicit bounds for primality testing and related problems", Mathematics of Computation, 55 (191): 355–380, doi:10.2307/2008811, JSTOR 2008811
  8. ^ Adleman, L. M., K. Manders, and G. Miller: 1977, `On taking roots in finite fields'. In: 18th IEEE Symposium on Foundations of Computer Science. pp. 175-177
  9. ^ "Accademia nazionale dei Lincei, Rome. Rendiconti, (5), 1, 1892, 116-120."

References

Read other articles:

Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada Desember 2022. Nichifor Crainic Menteri Propaganda NasionalMasa jabatan4 Juli 1940 – 14 September 1940Perdana MenteriIon Gigurtu Ion Antonescu PendahuluTeofil SidoroviciPenggantiJabatan ditangguhkan secara temporerMasa jabatan27 Januari 1941 – ...

 

 

Semua karena CintaAlbum studio karya SyahriniDirilis10 Desember 2012Direkam2010-2012GenrePopLabelPelangiKronologi Syahrini Jangan Memilih Aku(2010)Jangan Memilih Aku2010 Semua Karena Cinta (2012) Princess Syahrini(2016)Princess Syahrini2016 Singel dalam album Semua Karena Cinta Aku tak BiasaDirilis: November 2010 Kau Yang Memilih AkuDirilis: April 2011 Taubatlah TaubatDirilis: Agustus 2011 SesuatuDirilis: Januari 2012 Semua Karena CintaDirilis: Juli 2012 Semua karena Cinta merupakan album...

 

 

Chronologies Cérémonie d'ouverture des Jeux olympiques de Paris au stade olympique de Colombes, le 5 juillet 1924.Données clés 1921 1922 1923  1924  1925 1926 1927Décennies :1890 1900 1910  1920  1930 1940 1950Siècles :XVIIIe XIXe  XXe  XXIe XXIIeMillénaires :-Ier Ier  IIe  IIIe Chronologies géographiques Afrique Afrique du Sud, Algérie, Angola, Bénin, Botswana, Burkina Faso, Burundi, Cameroun, Cap-Vert, République centrafrica...

For the other Senate election in California held in parallel, see 1992 United States Senate election in California. For related races, see 1992 United States Senate elections. 1992 United States Senate special election in California ← 1988 November 3, 1992 1994 →   Nominee Dianne Feinstein John Seymour Party Democratic Republican Popular vote 5,853,651 4,093,501 Percentage 54.29% 37.96% County resultsFeinstein:      40–50%  ...

 

 

For other uses, see Orašac. Village in Federation of Bosnia and Herzegovina, Bosnia and HerzegovinaOrašacVillageOrašacCoordinates: 43°46′04″N 17°30′48″E / 43.7676669°N 17.5132643°E / 43.7676669; 17.5132643CountryBosnia and HerzegovinaEntityFederation of Bosnia and HerzegovinaCantonHerzegovina-NeretvaMunicipalityProzorArea • Total16.69 sq mi (43.23 km2)Population (2013) • Total456 • Density27/sq ...

 

 

Marcelo Salas Salas pada tahun 2015Informasi pribadiNama lengkap José Marcelo Salas Melinao[1]Tanggal lahir 24 Desember 1974 (umur 49)Tempat lahir Temuco, ChiliTinggi 1,74 m (5 ft 8+1⁄2 in)[2]Posisi bermain PenyerangKarier junior1989–1991 Deportes Temuco1991–1993 Universidad de ChileKarier senior*Tahun Tim Tampil (Gol)1993–1996 Universidad de Chile 77 (50)1996–1998 River Plate 53 (24)1998–2001 Lazio 79 (34)2001–2006 Juventus 18 (2)2003�...

Office skyscraper in Manhattan, New York This article is about the building at 200 Park Avenue in Midtown Manhattan. For the buildings near Madison Square Park, see Metropolitan Life Insurance Company Tower and Metropolitan Life North Building. For the building at 200 Park Avenue South, see Everett Building (Manhattan). MetLife BuildingSeen from the south in 2005Former namesPan Am BuildingGeneral informationTypeOfficeArchitectural styleInternationalLocation200 Park AvenueManhattan, New York 1...

 

 

Newnham College, Cambridge. Aula Sidgwick dan Taman Sunken. Newnham College adalah kolese wanita dari Universitas Cambridge. Perguruan ini didirikan pada tahun 1871 oleh sebuah kelompok yang menyelenggarakan Kuliah untuk Para Wanita, yang anggota-anggotanya termasuk filsuf Henry Sidgwick dan juru kampanye suffragist Millicent Garrett Fawcett. Kolese ini merupakan kolese wanita kedua yang didirikan di Cambridge, setelah Kolese Girton. Sejarah Sejarah Newnham dimulai dengan pembentukan Asosiasi...

 

 

 NE14 Stasiun MRT Hougang后港地铁站ஹவ்காங்Angkutan cepatPeron mengarah HarbourFront di Stasiun MRT HougangLokasi80 Hougang CentralSingapore 538758Koordinat1°22′17″N 103°53′32″E / 1.371292°N 103.892161°E / 1.371292; 103.892161Jalur  Jalur Timur Laut Jumlah peronPulauJumlah jalur2LayananBus, TaksiKonstruksiJenis strukturBawah tanahTinggi peron2Akses difabelYesInformasi lainKode stasiunNE14SejarahDibuka20 Juni 2003Operasi...

This is a List of Wales international rugby union footballers killed in the World Wars: First World War Johnnie Williams the most capped player to be killed Thirteen were killed in the First World War (Palenski also includes Hopkin Maddock who died on 15 December 1921 from war wounds)[1] Billy Geen (3 caps) Bryn Lewis (2 caps) Fred Perrett (5 caps) Lou Phillips (4 caps) Charlie Pritchard (14 caps) C. G. Taylor (9 caps) E.J. Thomas (4 caps) Horace Thomas (2 caps) Phil Waller (6 caps) ...

 

 

本條目存在以下問題,請協助改善本條目或在討論頁針對議題發表看法。 此條目需要擴充。 (2013年1月1日)请協助改善这篇條目,更進一步的信息可能會在討論頁或扩充请求中找到。请在擴充條目後將此模板移除。 此條目需要补充更多来源。 (2013年1月1日)请协助補充多方面可靠来源以改善这篇条目,无法查证的内容可能會因為异议提出而被移除。致使用者:请搜索一下条目的...

 

 

City in Florida, US City in FloridaCocoa, FloridaCityCity of Cocoa Top: Cocoa welcome sign; Bottom: Cocoa City Hall SealLocation in Brevard County and the state of FloridaCoordinates: 28°22′10″N 80°44′38″W / 28.36944°N 80.74389°W / 28.36944; -80.74389Country United States of AmericaState FloridaCounty BrevardGovernment • TypeCouncil-Manager • MayorMichael Blake • City ManagerStockton WhittenArea[1] ...

本條目存在以下問題,請協助改善本條目或在討論頁針對議題發表看法。 此條目需要編修,以確保文法、用詞、语气、格式、標點等使用恰当。 (2013年8月6日)請按照校對指引,幫助编辑這個條目。(幫助、討論) 此條目剧情、虛構用語或人物介紹过长过细,需清理无关故事主轴的细节、用語和角色介紹。 (2020年10月6日)劇情、用語和人物介紹都只是用於了解故事主軸,輔助�...

 

 

Емблема УСЦАК Українська Спортова Централя Америки і Канади (УСЦАК; англ. The Ukrainian Sports Federation of USA and Canada; USCAK) — надрядна організація спортивних клубів і секцій США і Канади, об'єднаних у трьох Делеґатурах (США-Схід, США-Північ, Канада), заснована 1955; 1981 гуртувала 20 клубів і с...

 

 

Paul WeigelLila Leslie dengan Weigel, 1921Lahir(1867-02-18)18 Februari 1867Halle, Saxony-Anhalt, JermanMeninggal25 Mei 1951(1951-05-25) (umur 84)Los Angeles, California, Amerika SerikatPekerjaanPemeranTahun aktif1916-1945 Paul Weigel (18 Februari 1867 – 25 Mei 1951) adalah seorang pemeran Jerman-Amerika.[1] Ia tampil dalam 114 film antara 1916 dan 1945. Filmografi pilihan Naked Hearts (1916) Each Pearl a Tear (1916) The Intrigue (1916) Witchcraft (1916) Each...

  المجموعة الاقتصادية الأوروآسيوية المجموعة الاقتصادية الأوروآسيوية‌ الخريطة المقر الرئيسي موسكو تاريخ التأسيس 10 أكتوبر 2000 مكان التأسيس أستانا  تاريخ الحل 1 يناير 2015 النوع منظمة دولية حكومية العضوية  بيلاروس كازاخستان قيرغيزستان روسيا طاجيكستان أ�...

 

 

Stadium in Moscow, Russia Irina Viner-Usmanova Gymnastics PalaceLocationLuzhniki Olympic Complex, Moscow, RussiaCoordinates55°43′03″N 37°33′45″E / 55.71750°N 37.56250°E / 55.71750; 37.56250Public transit Moscow Central CircleOperatorElena SmirnovaCapacity4,000Field size130 by 80 metres (142.2 yd × 87.5 yd)ConstructionBuilt2017–2019Opened18 June 2019ArchitectPride ООО[1]Structural engineerSergey Kuznetsov The Irina Viner-Usmanova...

 

 

Greek politician This biography of a living person needs additional citations for verification. Please help by adding reliable sources. Contentious material about living persons that is unsourced or poorly sourced must be removed immediately from the article and its talk page, especially if potentially libelous.Find sources: Vasilis Leventis – news · newspapers · books · scholar · JSTOR (September 2017) (Learn how and when to remove this message) Vasil...

Book by Ion Idriess The Great Trek: One of the Greatest Feats in Australian Exploration First editionAuthorIon IdriessLanguageEnglishPublisherAngus and RobertsonPublication date1940Publication placeAustralia The Great Trek: One of the Greatest Feats in Australian Exploration is a 1940 book by Ion Idriess about Francis and Alex Jardine's 1864 trek in the northern Cape York Peninsula, from Rockhampton to Somerset in 1864.[1][2] References ^ BOOKS of the WEEK. The News. Vol. ...

 

 

Lesley Ann Warren nel 2009 Lesley Ann Warren (New York, 16 agosto 1946[1]) è un'attrice statunitense. Attrice di teatro, cinema e televisione, Lesley venne candidata nel 1983 all'Oscar alla miglior attrice non protagonista per il film Victor Victoria. Indice 1 Biografia 1.1 Carriera 2 Filmografia 2.1 Cinema 2.2 Televisione 3 Riconoscimenti 4 Doppiatrici italiane 5 Note 6 Altri progetti 7 Collegamenti esterni Biografia Lesley Ann Warren nasce in una famiglia ebraica il cui cognome ori...