scala - Faster code for 'distinct' on lists -


This question refers to code generation with Isabel / HOL theorem project.

I get one of the following: code

  DIF member [ A: HOL.Agbabel] (X0: List [A], Y: A): Boolean = (x, y) match {case (blue, y) => False case (x :: x, y) => HOLC [A] (X, Y) || Member [A] (Xs, Y)} DIF specific [A: HOL.Egele] (X: List [A]): ​​Boolean = X Match {Case Neal => True case x :: xs = & gt; ! (Member [A] (xs, x)) & amp; Amp; Specific [a] (xs)}   

This code has quadratic runtime. Is there a fast version available? At the beginning of my theory, I think about something like import code and code for import and code for "~~ / src / HOL / Library / Codechar" for the list. Better implementations for specific must be sorted in the O (n log n) list and iterate over the list once. But I think someone can do better?

Anyway, there is a fast implementation for different and possibly available from main ? I do not know about any fast implementation in the Isabell 2013 library, but you can easily do it as follows:

  • Make sure that different_supported actually implements different
  • code> sorted lists
  • Prove a lemma that applies different through separate_list and sort, and it also New code for the name declares the form of equation. In essence, it seems:
      reference starts the funny lind: "'a list = & gt; bool" where "specific" [] = True "| "Specific_sourceed [x] = true" | "SpecificSorted (X # Y # Xs) = (X ~ = Y & amp; SeparatedSorted (y # xs))" Lemma SeparatedSorted: "Sorted Xs ==> Separated xs = distinct xs" (xs Apply rule: different   

    Next, you need an efficient sorting algorithm. By default, if the sorting entry uses the sort If you import multiset from HOL / Library, then apply sort via QuickSort If you import from the collection of formal books, you can get merge sort.

    Although it can improve efficiency, there is also a problem: after the above announcements, you only different can be executed on lists whose elements are examples of class linorder as if this refinement is only inside the code generator, your definitions and theorems are not affected in Isabel. For example, to apply different to the list of lists in any code equation, you first have to define a linear command on the lists:

    This is done by selecting a dictionary order in code> List_lexord in HOL / Library , but for this it requires a linear command on the elements. If you want to use the string , which condenses four list , char_ord , then on four Defines normal order. If you map the character type of the target language with the Code_Char , then you have to optimize the principle of Code_Char_ord for combining with four_ord Required.

  • Comments

    Popular posts from this blog

    excel vba - How to delete Solver(SOLVER.XLAM) code -

    github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

    ios - Replace text in UITextView run slowly -