Termination analysis

def f(n):
   while n > 1:
      if n % 2 == 0:
          n = n / 2
      else:
          n = 3 * n + 1
As of 2024, it is still unknown
whether this Python program
terminates for every input;
see Collatz conjecture.

In computer science, termination analysis is program analysis which attempts to determine whether the evaluation of a given program halts for each input. This means to determine whether the input program computes a total function.

It is closely related to the halting problem, which is to determine whether a given program halts for a given input and which is undecidable. The termination analysis is even more difficult than the Halting problem: the termination analysis in the model of Turing machines as the model of programs implementing computable functions would have the goal of deciding whether a given Turing machine is a total Turing machine, and this problem is at level of the arithmetical hierarchy and thus is strictly more difficult than the Halting problem.

Now as the question whether a computable function is total is not semi-decidable,[1] each sound termination analyzer (i.e. an affirmative answer is never given for a non-terminating program) is incomplete, i.e. must fail in determining termination for infinitely many terminating programs, either by running forever or halting with an indefinite answer.

Termination proof

A termination proof is a type of mathematical proof that plays a critical role in formal verification because total correctness of an algorithm depends on termination.

A simple, general method for constructing termination proofs involves associating a measure with each step of an algorithm. The measure is taken from the domain of a well-founded relation, such as from the ordinal numbers. If the measure "decreases" according to the relation along every possible step of the algorithm, it must terminate, because there are no infinite descending chains with respect to a well-founded relation.

Some types of termination analysis can automatically generate or imply the existence of a termination proof.

Example

An example of a programming language construct which may or may not terminate is a loop, as they can be run repeatedly. Loops implemented using a counter variable as typically found in data processing algorithms will usually terminate, demonstrated by the pseudocode example below:

i := 0
loop until i = SIZE_OF_DATA
    process_data(data[i])) // process the data chunk at position i
    i := i + 1 // move to the next chunk of data to be processed

If the value of SIZE_OF_DATA is non-negative, fixed and finite, the loop will eventually terminate, assuming process_data terminates too.

Some loops can be shown to always terminate or never terminate through human inspection. For example, the following loop will, in theory, never stop. However, it may halt when executed on a physical machine due to arithmetic overflow: either leading to an exception or causing the counter to wrap to a negative value and enabling the loop condition to be fulfilled.

i := 1
loop until i = 0
    i := i + 1

In termination analysis one may also try to determine the termination behaviour of some program depending on some unknown input. The following example illustrates this problem.

i := 1
loop until i = UNKNOWN
    i := i + 1

Here the loop condition is defined using some value UNKNOWN, where the value of UNKNOWN is not known (e.g. defined by the user's input when the program is executed). Here the termination analysis must take into account all possible values of UNKNOWN and find out that in the possible case of UNKNOWN = 0 (as in the original example) the termination cannot be shown.

There is, however, no general procedure for determining whether an expression involving looping instructions will halt, even when humans are tasked with the inspection. The theoretical reason for this is the undecidability of the Halting Problem: there cannot exist some algorithm which determines whether any given program stops after finitely many computation steps.

In practice one fails to show termination (or non-termination) because every algorithm works with a finite set of methods being able to extract relevant information out of a given program. A method might look at how variables change with respect to some loop condition (possibly showing termination for that loop), other methods might try to transform the program's calculation to some mathematical construct and work on that, possibly getting information about the termination behaviour out of some properties of this mathematical model. But because each method is only able to "see" some specific reasons for (non)termination, even through combination of such methods one cannot cover all possible reasons for (non)termination.[citation needed]

Recursive functions and loops are equivalent in expression; any expression involving loops can be written using recursion, and vice versa. Thus the termination of recursive expressions is also undecidable in general. Most recursive expressions found in common usage (i.e. not pathological) can be shown to terminate through various means, usually depending on the definition of the expression itself. As an example, the function argument in the recursive expression for the factorial function below will always decrease by 1; by the well-ordering property of natural numbers, the argument will eventually reach 1 and the recursion will terminate.

function factorial (argument as natural number)
    if argument = 0 or argument = 1
        return 1
    otherwise
        return argument * factorial(argument - 1)

Dependent types

Termination check is very important in dependently typed programming language and theorem proving systems like Coq and Agda. These systems use Curry-Howard isomorphism between programs and proofs. Proofs over inductively defined data types were traditionally described using induction principles. However, it was found later that describing a program via a recursively defined function with pattern matching is a more natural way of proving than using induction principles directly. Unfortunately, allowing non-terminating definitions leads to logical inconsistency in type theories[citation needed], which is why Agda and Coq have termination checkers built-in.

Sized types

One of the approaches to termination checking in dependently typed programming languages are sized types. The main idea is to annotate the types over which we can recurse with size annotations and allow recursive calls only on smaller arguments. Sized types are implemented in Agda as a syntactic extension.

Current research

There are several research teams that work on new methods that can show (non)termination. Many researchers include these methods into programs[2] that try to analyze the termination behavior automatically (so without human interaction). An ongoing aspect of research is to allow the existing methods to be used to analyze termination behavior of programs written in "real world" programming languages. For declarative languages like Haskell, Mercury and Prolog, many results exist[3][4][5] (mainly because of the strong mathematical background of these languages). The research community also works on new methods to analyze termination behavior of programs written in imperative languages like C and Java.

See also

References

  1. ^ Rogers, Jr., Hartley (1988). Theory of recursive functions and effective computability. Cambridge (MA), London (England): The MIT Press. p. 476. ISBN 0-262-68052-1.
  2. ^ "Category:Tools - Termination-Portal.org". termination-portal.org.
  3. ^ Giesl, J.; Swiderski, S.; Schneider-Kamp, P.; Thiemann, R. Pfenning, F. (ed.). Automated Termination Analysis for Haskell: From Term Rewriting to Programming Languages (invited lecture) (postscript). Term Rewriting and Applications, 17th Int. Conf., RTA-06. LNCS. Vol. 4098. pp. 297–312. (link: springerlink.com).
  4. ^ Compiler options for termination analysis in Mercury
  5. ^ Nguyen, Manh Thang; Giesl, Jürgen; Schneider-Kamp, Peter; De Schreye, Danny. "Termination Analysis of Logic Programs based on Dependency Graphs" (PDF). verify.rwth-aachen.de.

Research papers on automated program termination analysis include:

System descriptions of automated termination analysis tools include:

Read other articles:

Cari artikel bahasa  Cari berdasarkan kode ISO 639 (Uji coba)  Kolom pencarian ini hanya didukung oleh beberapa antarmuka Halaman bahasa acak Bahasa Swabia Schwäbisch,[1] der schwäbische Dialekt[2] Dituturkan diJerman[1]EtnisOrang SwabiaPenutur820 (2006)[3] Rincian data penutur Jumlah penutur beserta (jika ada) metode pengambilan, jenis, tanggal, dan tempat.[4] 820.000 (Bahasa ibu, 2006) Rumpun bahasaIndo-Eropa JermanikJermanik Bar...

 

US television program Where in Time Is Carmen Sandiego?GenreGeographyCrimeGame showBased onWhere in Time Is Carmen Sandiego?Published by BroderbundDirected byDavid TurnerPresented byKevin ShinickLynne ThigpenStarringThe Engine CrewAlaine KashianJohn LathanOwen Taylor (season 1)Jamie Gustis (season 2)Theme music composerSean AltmanDavid YazbekRandy Vancourt (French Version)Opening themeWhere in Time Is Carmen Sandiego? by The Engine CrewCountry of originUnited StatesOriginal languageEnglishNo....

 

ميكائيل لاندرو (بالفرنسية: Mickaël Landreau)‏  معلومات شخصية الميلاد 14 مايو 1979 (العمر 44 سنة)[1] الطول 1.84 م (6 قدم 1⁄2 بوصة) مركز اللعب حارس مرمى الجنسية فرنسي مسيرة الشباب سنوات فريق 1993–1996 نانت 1992–1993 GS Saint-Sébastien-sur-Loire 1993–1996 نانت المسيرة الاحترافية1 سنوات فريق مشاركات...

Cloud gaming service StadiaMobile device running Mortal Kombat 11 on Stadia with official controllerDeveloperGoogleTypeCloud gaming serviceLaunch dateNovember 19, 2019 (2019-11-19)DiscontinuedJanuary 18, 2023 (2023-01-18)Operating system(s)Cross-platformWebsitestadia.google.com Stadia was a cloud gaming service developed and operated by Google. Known in development as Project Stream, the service debuted through a closed beta in October 2018, and publicly launched...

 

Si ce bandeau n'est plus pertinent, retirez-le. Cliquez ici pour en savoir plus. Cet article ne cite pas suffisamment ses sources (janvier 2010). Si vous disposez d'ouvrages ou d'articles de référence ou si vous connaissez des sites web de qualité traitant du thème abordé ici, merci de compléter l'article en donnant les références utiles à sa vérifiabilité et en les liant à la section « Notes et références ». En pratique : Quelles sources sont attendues ? C...

 

Jerman, menunjukan perbatasan modern. Daerah yang berwarna biru muda adalah Baden-Württemberg. Ke timur dari B-W adalah Bavaria, dengan Swabia dalam warna pink. Swabia, Suabia, atau Svebia (bahasa Jerman: Schwaben or Schwabenland) adalah daerah yang terletak di Jerman. Pada abad pertengahan, Baden, Vorarlberg, wilayah modern di Liechtenstein, Swiss, dan Elsas (sekarang dimiliki Prancis) juga merupakan bagian dari Swabia. Pranala luar Swabian history and culture on Swabia.org Diarsipkan 2007-...

ماري إل    علم شعار الاسم الرسمي (بالروسية: Марий Эл)‏    الإحداثيات 56°42′00″N 47°52′00″E / 56.7°N 47.866666666667°E / 56.7; 47.866666666667   [1] تاريخ التأسيس 12 يناير 1993  تقسيم إداري  البلد روسيا[2]  التقسيم الأعلى روسيا  العاصمة يوشكار-أولا  خصائص جغر...

 

This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: There's Always Woodstock – news · newspapers · books · scholar · JSTOR (July 2014) (Learn how and when to remove this message) 2014 American filmThere's Always WoodstockDirected byRita MersonWritten byRita MersonProduced byPeter SchaferStarring Allison Miller Jason Ritter Britta...

 

4Q175 4Q175 (atau 4QTest; 4QTestimonia) adalah potongan naskah kuno bertulisan bahasa Ibrani yang ditemukan dalam gua ke-4 di Qumran, di antara sejumlah naskah lain yang secara keseluruhan disebut Naskah Laut Mati yang diperkirakan dari abad ke-2 SM. Berbentuk surat satu halaman, yang berisi kutipan sejumlah ayat Alkitab Ibrani dan Perjanjian Lama dalam Alkitab Kristen berkaitan dengan figur Mesias. Tulisannya bercorak Hasmonean yang populer pada abad ke-1 SM.[1][2] Isi Testim...

Italian architect This article may require copy editing for grammar, style, cohesion, tone, or spelling. You can assist by editing it. (December 2023) (Learn how and when to remove this message) Scarpa studying the drawings of Frank Lloyd Wright in Venice, 1954 Carlo Scarpa (2 June 1906 – 28 November 1978) was an Italian architect and designer. He was influenced by the materials, landscape, and history of Venetian culture, as well as that of Japan.[1] Scarpa translated his interests...

 

Wasp-class amphibious assault ship For other ships with the same name, see USS Bataan. USS Bataan underway in 1999 History United States NameBataan NamesakeUSS Bataan (CVL-29) Ordered20 December 1991 BuilderIngalls Shipbuilding Laid down22 June 1994 Launched15 March 1996 Christened18 May 1996 Commissioned20 September 1997 HomeportNorfolk Identification MMSI number: 368958000 Callsign: NBAT Hull number: LHD-5 MottoCourage, Commitment, Honor Statusin active service Badge General characteristics...

 

Town in Victoria, AustraliaApsleyVictoriaApsleyLocation in Shire of West WimmeraCoordinates36°58′S 141°05′E / 36.967°S 141.083°E / -36.967; 141.083Population277 (2016 census)[1]Established1841Postcode(s)3319Location 417 km (259 mi) W of Melbourne 369 km (229 mi) SE of Adelaide 115 km (71 mi) W of Horsham 21 km (13 mi) W of Edenhope 30 km (19 mi) E of Naracoorte LGA(s)Shire of West WimmeraState elec...

يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (ديسمبر 2018) ← 1828 1827 1826 1829 في فرنسا → 1830 1831 1832 عقود: فيما يلي قوائم الأحداث التي وقعت خلال عام 1829 في فرنسا. سياسة تعيين ف...

 

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 Januari 2023. Gua Orient di gua-gua Jenolan Gua Lucas di gua-gua Jenolan Gua-gua Jenolan adalah serangkaian gua kapur yang berada di Pegunungan Biru, New South Wales, Australia (sekitar 175 kilometer sebelah barat Sydney). Jaringan gua ini sangat besar. Beberapa kil...

 

Cet article est une ébauche concernant la Nouvelle-France, l’histoire des États-Unis, le Canada et l’économie. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Si ce bandeau n'est plus pertinent, retirez-le. Cliquez ici pour en savoir plus. Le fond de cet article d'histoire est à vérifier (avril 2017). Améliorez-le ou discutez des points à vérifier. Si vous venez d’apposer le bandeau, merci d’indi...

Town and civil parish in the North Lincolnshire district, of Lincolnshire, England Not to be confused with Kirton in Holland. Human settlement in EnglandKirton in LindseyKirton LindseyMount Pleasant MillKirton in LindseyLocation within LincolnshirePopulation2,694 (2001 Census)DemonymKirtonianOS grid referenceSK936986• London135 mi (217 km) SSEUnitary authorityNorth LincolnshireCeremonial countyLincolnshireRegionYorkshire and the HumberCountryEngl...

 

Questa voce sull'argomento società calcistiche statunitensi è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Portland Timbers 2Calcio Segni distintiviUniformi di gara Casa Trasferta Colori sociali Verde, bianco SimboliCasa Dati societariCittàPortland Nazione Stati Uniti ConfederazioneCONCACAF Federazione USSF CampionatoMLS Next Pro Fondazione2014 Proprietario Merritt Paulson Allenatore Cameron Knowles StadioHillsboro Stadium(7.600 posti) Sito we...

 

DzoungarsKhanat dzoungar mongol Зүүн гарын хаант улс 1634–1756 L’empire dzoungar (1750) (en ligne bleue)Informations générales Statut Monarchie Capitale Ghulja[1]. Langue(s) Oïrate Religion Bouddhisme Monnaie Pūl (en) Histoire et événements 1619 Le premier rapport russe de Khara Khula 1678 Galdan reçoit le titre de Boshogtu khan du 5e Dalai Lama 1688 Invasion dzoungare de Khalkha 1755 L'armée Qing occupe la Dzoungarie Khan ou Khong Tayiji Khara Khula Erdeni ...

Questa voce o sezione sull'argomento competizioni calcistiche non è ancora formattata secondo gli standard. Commento: Voce da adeguare al corrispondente modello di voce. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. A lyga 2009NFKA A lyga 2009 Competizione A lyga Sport Calcio Edizione 20ª Organizzatore LFF Date dal 4 aprile 2009al 31 ottobre 2009 Luogo  Lituania Partecipanti 8 Risultati Vincitore Ekranas(...

 

Questa voce sull'argomento società calcistiche norvegesi è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Flekkefjord F.K.Calcio Segni distintiviUniformi di gara Casa Trasferta Colori sociali Rosso, bianco Dati societariCittàFlekkefjord Nazione Norvegia ConfederazioneUEFA Federazione NFF Campionato4. divisjon Fondazione1905 StadioUenes Stadion(? posti) Sito webwww.flekkefjordfk.no/ PalmarèsSi invita a seguire il modello di voce Il Flekkefjord F...