aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/nsatz
diff options
context:
space:
mode:
authorGravatar Pierre-Marie Pédrot <pierre-marie.pedrot@inria.fr>2016-09-26 01:53:13 +0200
committerGravatar Pierre-Marie Pédrot <pierre-marie.pedrot@inria.fr>2016-09-26 15:57:40 +0200
commit3d9a1378adc3c7cd7a3013c80ea565792486b679 (patch)
tree445b638133aff9933a70ca7023fe5f25da95f126 /plugins/nsatz
parentc8ca50f0cf961c9e31489f095463a99fc005c5de (diff)
Partial fix for bug #5085: nsatz_compute stack overflows.
This fixes the stack overflow part of the bug, even if the tactic is still quite slow. The offending functions have been written in a tail-recursive way.
Diffstat (limited to 'plugins/nsatz')
-rw-r--r--plugins/nsatz/ideal.ml44
1 files changed, 20 insertions, 24 deletions
diff --git a/plugins/nsatz/ideal.ml b/plugins/nsatz/ideal.ml
index 482ce5053..1d74ee12b 100644
--- a/plugins/nsatz/ideal.ml
+++ b/plugins/nsatz/ideal.ml
@@ -402,29 +402,25 @@ let polconst d c =
[(c,m)]
let plusP p q =
- let rec plusP p q =
- match p with
- [] -> q
- |t::p' ->
- match q with
- [] -> p
- |t'::q' ->
- match compare_mon (snd t) (snd t') with
- 1 -> t::(plusP p' q)
- |(-1) -> t'::(plusP p q')
- |_ -> let c=P.plusP (fst t) (fst t') in
- match P.equal c coef0 with
- true -> (plusP p' q')
- |false -> (c,(snd t))::(plusP p' q')
- in plusP p q
+ let rec plusP p q accu = match p, q with
+ | [], [] -> List.rev accu
+ | [], _ -> List.rev_append accu q
+ | _, [] -> List.rev_append accu p
+ | t :: p', t' :: q' ->
+ let c = compare_mon (snd t) (snd t') in
+ if c > 0 then plusP p' q (t :: accu)
+ else if c < 0 then plusP p q' (t' :: accu)
+ else
+ let c = P.plusP (fst t) (fst t') in
+ if P.equal c coef0 then plusP p' q' accu
+ else plusP p' q' ((c, (snd t)) :: accu)
+ in
+ plusP p q []
(* multiplication by (a,monomial) *)
let mult_t_pol a m p =
- let rec mult_t_pol p =
- match p with
- [] -> []
- |(b,m')::p -> ((P.multP a b),(mult_mon m m'))::(mult_t_pol p)
- in mult_t_pol p
+ let map (b, m') = (P.multP a b, mult_mon m m') in
+ CList.map map p
let coef_of_int x = P.of_num (Num.Int x)
@@ -451,11 +447,11 @@ let emultP a p =
in emultP p
let multP p q =
- let rec aux p =
+ let rec aux p accu =
match p with
- [] -> []
- |(a,m)::p' -> plusP (mult_t_pol a m q) (aux p')
- in aux p
+ [] -> accu
+ |(a,m)::p' -> aux p' (plusP (mult_t_pol a m q) accu)
+ in aux p []
let puisP p n=
match p with