この質問は、Isabelle/HOL定理証明者によるコード生成に関するものです。
distinct
リスト上の関数のコードをエクスポートするとき
export_code distinct in Scala file -
次のコードを取得します
def member[A : HOL.equal](x0: List[A], y: A): Boolean = (x0, y) match {
case (Nil, y) => false
case (x :: xs, y) => HOL.eq[A](x, y) || member[A](xs, y)
}
def distinct[A : HOL.equal](x0: List[A]): Boolean = x0 match {
case Nil => true
case x :: xs => ! (member[A](xs, x)) && distinct[A](xs)
}
このコードには2次ランタイムがあります。より高速なバージョンはありますか?理論の最初に文字列をインポート"~~/src/HOL/Library/Code_Char"
するようなものを考えており、リストの効率的なコード生成が設定されています。のより良い実装はdistinct
、O(n log n)でリストをソートし、リストを1回繰り返すことです。しかし、私は人がもっとうまくいくことができると思いますか?
とにかく、利用可能なdistinct
他の関数のより高速な実装はありMain
ますか?