]> matita.cs.unibo.it Git - helm.git/commitdiff
New, much faster implementation of factorize.
authorClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Wed, 11 Jun 2008 18:00:20 +0000 (18:00 +0000)
committerClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Wed, 11 Jun 2008 18:00:20 +0000 (18:00 +0000)
helm/software/matita/library/nat/factorization2.ma [new file with mode: 0644]

diff --git a/helm/software/matita/library/nat/factorization2.ma b/helm/software/matita/library/nat/factorization2.ma
new file mode 100644 (file)
index 0000000..52a1b9a
--- /dev/null
@@ -0,0 +1,39 @@
+(**************************************************************************)
+(*       ___                                                               *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
+(*      ||A||       E.Tassi, S.Zacchiroli                                 *)
+(*      \   /                                                             *)
+(*       \ /        Matita is distributed under the terms of the          *)
+(*        v         GNU Lesser General Public License Version 2.1         *)
+(*                                                                        *)
+(**************************************************************************)
+
+include "nat/factorization.ma".
+
+let rec factorize_aux2 i n b on b ≝
+ match b with
+  [ O ⇒ nfa_zero
+  | S b' ⇒
+     let p ≝ nth_prime i in
+      match p_ord n p with
+       [ pair q r ⇒
+          match r with
+          [ O ⇒ nfa_zero
+          | S r' ⇒
+             match r' with
+             [ O ⇒
+               match q with
+               [ O ⇒ nfa_one
+               | _ ⇒ nfa_proper (nf_last (pred q))]
+             | S _ ⇒
+                let res ≝ factorize_aux2 (S i) r b' in
+                 match res with
+                 [ nfa_zero ⇒ nfa_zero (* impossible *)
+                 | nfa_one ⇒ nfa_proper (nf_last q)
+                 | nfa_proper l ⇒ nfa_proper (nf_cons q l)]]]]].
+
+definition factorize2 ≝ λn.factorize_aux2 0 n n.
\ No newline at end of file