Math::NumSeq::ProthNumbers -- Proth number sequence
use Math::NumSeq::Squares; my $seq = Math::NumSeq::Squares->new; my ($i, $value) = $seq->next;
The Proth numbers 3, 5, 9, 13, 17, etc, being integers k*2^n+1 where k < 2^n.
The condition k < 2^n means the values in binary have low half 00..01 and high half some value k,
binary 3 11 5 101 9 1001 13 1101 17 10001 25 11001 33 100001 ^^ || k part --++-- low part
$seq = Math::NumSeq::ProthNumbers->new()
Create and return a new sequence object.
$value = $seq->ith($i)
Return the $i'th Proth number. The first number is 3 at $i==1.
$i
$i==1
$bool = $seq->pred($value)
Return true if $value is a Proth number, meaning is equal to k*2^n+1 for some k and n.
$value
Taking the values by their length in bits, the values are
11 1 value i=1 101 1 value i=2 1x01 2 values i=3,4 1x001 2 values i=5,6 1xx001 4 values i=7 to 10 1xx0001 4 values 1xxx0001 8 values 1xxx00001 8 values
For a given 1xxx high part the low zeros, which is the 2^n factor, is the same length and then repeated 1 bigger. That doubling can be controlled by a high bit of the i, so in the following Z is either a zero bit or omitted,
1Z1 1xZ01 1xxZ001 1xxxZ0001
The ith Proth number can be formed from the bits of the index
i+1 = 1zxx..xx binary k = 1xx..xx n = z + 1 + number of x's
The first 1zxxx desired is 10, which is had from i+1 starting from i=1. The z second highest bit makes n bigger, giving the Z above present or omitted.
For example i=9 is bits i+1=1010 binary which as 1zxx is k=0b110=6, n=0+1+2=3, for value 6*2^3+1=49, or binary 110001.
It can be convenient to take the two highest bits of the index i together, so hhxx..xx so hh=2 or 3, then n = hh-1 + number of x's.
Math::NumSeq, Math::NumSeq::CullenNumbers, Math::NumSeq::WoodallNumbers
http://user42.tuxfamily.org/math-numseq/index.html
Copyright 2010, 2011 Kevin Ryde
Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
To install Math::NumSeq, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::NumSeq
CPAN shell
perl -MCPAN -e shell install Math::NumSeq
For more information on module installation, please visit the detailed CPAN module installation guide.