Re: Math::Pari 'factor' is wrong
- From: gamo <gamo@xxxxxxxxxxxx>
- Date: Sat, 18 Mar 2006 02:53:29 +0100
On Fri, 17 Mar 2006, gamo wrote:
#!/usr/local/bin/perl -w
# use Math::PariInit qw( primes=12000000 stack=1e8 );
# use Math::Pari qw(:all);
use Math::Pari 'factor';
# $i = PARI 0;
# $P = PARI 1;
for $i (0..1_000_000_000) {
$P = 5*$i**4-10*$i**3+20*$i*$i-15*$i+11;
$f = factor($P,0);
# print "$f\n";
# next if ($f =~ /-1/);
@fact= ($f =~ /[\[|\;](\d+)\,/g);
# print "@fact\n";
for $j (@fact){
if ($j%10!=1){
print "$f -> $j factor of P($i)=$P\n";
}
}
# last if $i==1000;
}
__END__
This code gives incorrects results as -1 as factor of a positive
integer or 5 as factor of a number not terminated in 5 or 0.
I do a sample calculation using 'echo "factor(number)" | gp' and this
gives correct results.
TIA, best regards
Well I have a workaround, but the speed is so slow that is impractical.
#!/usr/local/bin/perl -w
use Math::BigInt;
for $i (0..1_000_000_000) {
$P = 5*$i**4-10*$i**3+20*$i*$i-15*$i+11;
@f = `echo "factor($P)" | gp`;
# print "@f\n";
# @f2 = grep (/\[\d+\s/, @f);
# print "@f2\n";
@fact= map (/\[(\d+)\s/, @f);
# print "@fact\n";
for $j (@fact){
if ($j%10!=1){
print "$j factor of P($i)=$P\n";
}
}
if ($i % 10_000_000==0) { print "."; }
# last if $i==1000;
}
__END__
PS: use bignum; don't works here.
Best regards,
--
http://www.telecable.es/personales/gamo/
Sólo hay 10 tipos de personas, las que saben binario y las que no
perl -e 'print 111_111_111**2,"\n";'
- References:
- Math::Pari 'factor' is wrong
- From: gamo
- Math::Pari 'factor' is wrong
- Prev by Date: Re: Telnet to multiple systems, continue on failure
- Next by Date: Re: Math::Pari 'factor' is wrong
- Previous by thread: Math::Pari 'factor' is wrong
- Next by thread: Re: Math::Pari 'factor' is wrong
- Index(es):