Math-NumSeq

 view release on metacpan or  search on metacpan

devel/lib/Math/NumSeq/Padovan.pm  view on Meta::CPAN


This is the Padovan sequence,

    1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, ...

which is the recurrence

    P[i] = P[i-2] + P[i-3]

starting from 1,1,1.  So for example 28 is 12+16.

    12, 16, 21, 28

     |   |       ^
     |   |       |
     +---+---add-+

The recurrence is the same as the Perrin sequence (L<Math::NumSeq::Perrin>)
but with different staring values.

=head2 Triangles

There's an attractive geometric interpretation of these numbers.

    +-----------------------------------+
     \                                 / \
      \                               /   \
       \                             /     \
        \                           /       \
         \                         /         \
          \                       /           \
           \         9           /             \
            \                   /       7       \
             \                 /                 \
              \               /                   \
               \             /                     \
                \           /                       \
                 \         /                         \
                  \       +-------+-------------------+
                   \     / \  2  /1\                 /
                    \   / 2 \   +---+               /
                     \ /     \ /1\1/ \             /
                      +-------+---+   \     5     /
                       \         /     \         /
                        \   3   /       \       /
                         \     /    4    \     /
                          \   /           \   /
                           \ /             \ /
                            +---------------+

The pattern starts from an equilateral triangle of side length 1, the lower
left one shown above.  Then put a new triangle successively to the right,
left and lower sides, each time the side length of the triangle is the width
of the figure so far.

The effect is to add the immediately preceding triangle side and the side of
the 5th previous,

    P[i] = P[i-1] + P[i-5]

This is the same as the i-2,i-3 formula shown above since

    P[i] = P[i-2] + P[i-3]          # formula above
         = P[i-4]+P[i-5] + P[i-3]
         = P[i-3]+P[i-4] + P[i-5]
         = P[i-1] + P[i-5]          # geometric form

=head1 FUNCTIONS

See L<Math::NumSeq/FUNCTIONS> for behaviour common to all sequence classes.

=over 4

=item C<$seq = Math::NumSeq::Padovan-E<gt>new ()>

=item C<$seq = Math::NumSeq::Padovan-E<gt>new (language =E<gt> $str)>

Create and return a new sequence object.

=back

=head2 Random Access

=over

=item C<$value = $seq-E<gt>ith($i)>

Return the number of letters in C<$i> written out in the selected language.

=back

=head1 SEE ALSO

L<Math::NumSeq>,
L<Math::NumSeq::Perrin>

=head1 HOME PAGE

L<http://user42.tuxfamily.org/math-numseq/index.html>

=head1 LICENSE

Copyright 2012, 2013, 2014, 2016, 2019, 2020 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/>.

=cut



( run in 0.449 second using v1.01-cache-2.11-cpan-e1769b4cff6 )