Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Subject
- Posted on
- David Christensen
February 22, 2005, 3:19 am
comp.languages.perl.modules:
I have written a Perl module to implement Triangular Numbers and am
considering signing up for PAUSE and uploading the module to CPAN using
the name Math::TriangularNumbers.
Here is the code:
http://www.holgerdanske.com/dpchrist/Math-TriangularNumbers-r0_01.tar.gz
Here is the POD:
http://www.holgerdanske.com/dpchrist/Math-TriangularNumbers-r0_01-README.txt
Any comments/ suggestions for a CPAN author wanna be?
TIA,
David
Re: proposal for new module -- Math::TriangularNumbers
> I have written a Perl module to implement Triangular Numbers and am
> considering signing up for PAUSE and uploading the module to CPAN using
> the name Math::TriangularNumbers.
Sign up for a PAUSE ID and upload your module to CPAN. It doesn't
cost much anymore. ;)
--
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com
Re: proposal for new module -- Math::TriangularNumbers
David Christensen wrote:
> comp.languages.perl.modules:
>
> I have written a Perl module to implement Triangular Numbers and am
> considering signing up for PAUSE and uploading the module to CPAN using
> the name Math::TriangularNumbers.
>
>
> Here is the code:
>
> http://www.holgerdanske.com/dpchrist/Math-TriangularNumbers-r0_01.tar.gz
>
> Here is the POD:
>
>
http://www.holgerdanske.com/dpchrist/Math-TriangularNumbers-r0_01-README.txt
>
>
Just a couple of trivialities:
Seems to me that 'index' might be more appropriate than 'inverse'.
(That's just the way it struck me, anyway.)
I think you could also get the inverse/index of x by taking int(sqrt(x *
2)).
Is there a simple test to determine whether a number is a triangular
number ? If so, maybe include that in the module, too. Or perhaps the
formula you used to determine the inverse/index also determines whether
x is a triangular number (by returning integer for triangular numbers
only.)
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
Re: proposal for new module -- Math::TriangularNumbers
comp.lang.perl.modules:
"Sisyphus" wrote:
> Just a couple of trivialities:
> Seems to me that 'index' might be more appropriate than 'inverse'.
> (That's just the way it struck me, anyway.)
Thanks for your comments. :-)
My background is ME/EE/CS -- I'm not very strong on math theory. Do you
know if "index" is the proper mathematical term? What about "order"?
> I think you could also get the inverse/index of x by taking int(sqrt(x
> * 2)).
I have observed that triangular numbers are O(n**2), but the equation I
am using does seem to be numerically correct (the regression test checks
a subset of the first 100 triangular numbers).
> Is there a simple test to determine whether a number is a triangular
> number ? If so, maybe include that in the module, too. Or perhaps the
> formula you used to determine the inverse/index also determines
> whether x is a triangular number (by returning integer for triangular
> numbers only.)
Currently there is no is_triangular_number() function, but should be
easy enough to add:
##### untested code:
sub is_triangular_number
{
my $A = shift;
return (triangular_number(inverse_triangular_number($A)) == $A);
}
Something that I haven't stated is that the inverse (index? order?)
function finds the inverse of the triangular number equal to or less
than the argument (equal to or larger, for negative arguments). This is
useful for my game applications.
Your observation about integer result in the inverse_triangular_number()
calculation sounds correct, but I'm unclear about floating point errors
in Perl. I should probably figure out how to force integer data types
and math operations. I should also figure out how to deal with overflow
(calling croak()?) and/or use arbitrary-precision numbers (?).
David
Re: proposal for new module -- Math::TriangularNumbers
David Christensen wrote:
> comp.lang.perl.modules:
>
> "Sisyphus" wrote:
>
>>Just a couple of trivialities:
>>Seems to me that 'index' might be more appropriate than 'inverse'.
>>(That's just the way it struck me, anyway.)
>
>
> Thanks for your comments. :-)
>
>
> My background is ME/EE/CS -- I'm not very strong on math theory. Do you
> know if "index" is the proper mathematical term? What about "order"?
>
Looks to me that 'index' is the correct term.
From http://mathworld.wolfram.com/TriangularNumber.html :
"The numbers 1, 36, 1225, 41616, 1413721, 48024900, ... (Sloane's
A001110) are square triangular numbers, i.e., numbers which are
simultaneously triangular and square (Pietenpol 1962). The corresponding
square roots are 1, 6, 35, 204, 1189, 6930, ... (Sloane's A001109), and
the indices of the corresponding triangular numbers are n = 1, 8, 49,
288, 1681, .."
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
Re: proposal for new module -- Math::TriangularNumbers
comp.languages.perl.modules:
I've updated Math::TriangularNumbers:
0.02 Sat Feb 26 2005
Renamed A() -> T() and AInv -> Ti().
Added is_T().
You can view the perldoc here:
http://www.holgerdanske.com/dpchrist/Math-TriangularNumbers-r0_02-README.txt
And get the code here:
http://www.holgerdanske.com/dpchrist/Math-TriangularNumbers-r0_02.tar.gz
Any suggestions for further changes or improvements before posting on
CPAN?
TIA,
David
Site Timeline
- » LWP, https and a proxy
- — Next thread in » PERL Modules Announcements
- » Callback from threaded c-library
- — Previous thread in » PERL Modules Announcements
- » Updating the hash across the files
- — Newest thread in » PERL Modules Announcements
- » need help creating a 404 file
- — The site's Newest Thread. Posted in » HTML Markup Language