Opened 2 years ago

Closed 13 months ago

#27986 closed enhancement (fixed)

Add function to return the nth s-gonal number

Reported by: gh-sheareralexj Owned by:
Priority: trivial Milestone: sage-9.2
Component: combinatorics Keywords:
Cc: Merged in:
Authors: Alex Shearer Reviewers: Jonathan Kliem
Report Upstream: N/A Work issues:
Branch: e10fd35 (Commits, GitHub, GitLab) Commit: e10fd35298dd5340dc38a0665c407370178e8610
Dependencies: Stopgaps:

Status badges

Description (last modified by gh-sheareralexj)

This ticket adds a function to return elements of the s-gonal sequences. For example, this enables:

sage: tri = [polygonal_number(3, n) for n in [0..9]]
sage: tri
[0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
sage: square = [polygonal_number(4, n) for n in [0..9]]
sage: square
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

Change History (31)

comment:1 Changed 2 years ago by gh-sheareralexj

  • Description modified (diff)

comment:2 Changed 2 years ago by embray

As the Sage-8.8 release milestone is pending, we should delete the sage-8.8 milestone for tickets that are not actively being worked on or that still require significant work to move forward. If you feel that this ticket should be included in the next Sage release at the soonest please set its milestone to the next release milestone (sage-8.9).

comment:3 Changed 2 years ago by embray

  • Milestone sage-8.8 deleted

As the Sage-8.8 release milestone is pending, we should delete the sage-8.8 milestone for tickets that are not actively being worked on or that still require significant work to move forward. If you feel that this ticket should be included in the next Sage release at the soonest please set its milestone to the next release milestone (sage-8.9).

comment:4 Changed 2 years ago by gh-sheareralexj

  • Owner changed from (none) to gh-sheareralexj

comment:5 Changed 2 years ago by gh-sheareralexj

  • Milestone set to sage-8.9

comment:6 Changed 2 years ago by gh-sheareralexj

  • Authors set to gh-sheareralexj

comment:7 Changed 2 years ago by gh-sheareralexj

  • Authors changed from gh-sheareralexj to sheareralexj

comment:8 Changed 2 years ago by gh-sheareralexj

  • Branch set to u/gh-sheareralexj/27986

comment:9 Changed 2 years ago by gh-sheareralexj

  • Branch changed from u/gh-sheareralexj/27986 to u/sheareralexj/27986

comment:10 Changed 2 years ago by gh-sheareralexj

  • Branch changed from u/sheareralexj/27986 to t/27986/add_function_to_return_the_nth_s_gonal_number

comment:11 Changed 2 years ago by gh-sheareralexj

  • Authors sheareralexj deleted
  • Branch t/27986/add_function_to_return_the_nth_s_gonal_number deleted
  • Owner changed from gh-sheareralexj to (none)
  • Priority changed from minor to trivial

comment:12 Changed 2 years ago by gh-sheareralexj

  • Branch set to u/gh-sheareralexj/add_function_to_return_the_nth_s_gonal_number

comment:13 Changed 2 years ago by gh-sheareralexj

  • Authors set to Alex Shearer
  • Commit set to b829a434d304f05bc6a3a9257604a3cfc901d3b9
  • Status changed from new to needs_review

New commits:

b829a4327986: Added function to return polygonal numbers

comment:14 Changed 2 years ago by git

  • Commit changed from b829a434d304f05bc6a3a9257604a3cfc901d3b9 to c3250281b530f2729e0e37951bbd102a49a4c224

Branch pushed to git repo; I updated commit sha1. New commits:

c32502827986: Removed restriction on n - can now find polygonal numbers for negative indices

comment:15 Changed 21 months ago by embray

  • Milestone changed from sage-8.9 to sage-9.1

Ticket retargeted after milestone closed

comment:16 Changed 18 months ago by gh-kliem

  • Reviewers set to Jonathan Kliem
  • Status changed from needs_review to needs_work

Three minor things.

-    OUTPUT:
-
-    integer
+    OUTPUT: an integer

and

-    - ``s`` -- integer; the size of the polygon. For example, s = 3
+    - ``s`` -- integer; the size of the polygon. For example, `s = 3`

and

-    return (((n**2) * (s-2)) - (n * (s-4))) / 2
+    return (((n**2) * (s-2)) - (n * (s-4))) // 2

(the output should be an integer and not a rational).

comment:17 Changed 18 months ago by mkoeppe

  • Milestone changed from sage-9.1 to sage-9.2

Batch modifying tickets that will likely not be ready for 9.1, based on a review of the ticket title, branch/review status, and last modification date.

comment:18 Changed 16 months ago by git

  • Commit changed from c3250281b530f2729e0e37951bbd102a49a4c224 to a616782708f55c17920909e3e00ea645112be405

Branch pushed to git repo; I updated commit sha1. New commits:

3ef7663Merge branch 'u/gh-sheareralexj/add_function_to_return_the_nth_s_gonal_number' of git://trac.sagemath.org/sage into test_27986
a61678227986: Updated documentation

comment:19 Changed 16 months ago by gh-sheareralexj

Made the changes above and updated the documentation

comment:20 Changed 16 months ago by gh-sheareralexj

  • Status changed from needs_work to needs_review

comment:21 Changed 16 months ago by gh-kliem

  • Status changed from needs_review to needs_work

Some more minor things I missed before.

  • I would propose the following:
-    - ``s`` -- integer; the size of the polygon. For example, `s = 3`
-      returns a 3-gonal (triangular) number. `s` must be greater than 1.
+    - ``s`` -- integer greater than 1; the number of sides of the polygon
  • The details from the input block about s are probably easier to read for a user on the example block as in:
EXAMPLES:

The triangular numbers::

    sage: [polygonal_number(3, n) for n in range(10)]
    [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]

The square numbers::

    sage: [polygonal_number(4, n) for n in range(10)]
    [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

The pentagonal numbers::

    sage: [polygonal_number(5, n) for n in range(10)]
    [0, 1, 5, 12, 22, 35, 51, 70, 92, 117]

The hexagonal numbers::

    sage: [polygonal_number(6, n) for n in range(10)]
    [0, 1, 6, 15, 28, 45, 66, 91, 120, 153]
  • It would be great if the other examples could be shortly illustrated by half a sentence or so. (Maybe something as The input is converted to an integer).

comment:22 Changed 16 months ago by git

  • Commit changed from a616782708f55c17920909e3e00ea645112be405 to 856d669955c7797ece5d6636cf3f698ab522840e

Branch pushed to git repo; I updated commit sha1. New commits:

856d66927986: Updated input block and example documentation

comment:23 Changed 16 months ago by gh-sheareralexj

  • Status changed from needs_work to needs_review

Thank you Jonathan, I made your suggested edits

comment:24 Changed 16 months ago by git

  • Commit changed from 856d669955c7797ece5d6636cf3f698ab522840e to cccb629145a38c604412986b010f6af4411c9da2

Branch pushed to git repo; I updated commit sha1. New commits:

cccb62927986: updated documentation

comment:25 Changed 16 months ago by gh-kliem

One last thing I noticed by the the bots:

-    EXAMPLES::
+    EXAMPLES:

    The triangular numbers::

comment:26 Changed 16 months ago by git

  • Commit changed from cccb629145a38c604412986b010f6af4411c9da2 to 1cbb3ac67ab822b4b41ad087889ca529b5d1cc41

Branch pushed to git repo; I updated commit sha1. New commits:

1cbb3ac27986: Updated examples block

comment:27 Changed 16 months ago by gh-sheareralexj

Fixed

comment:28 Changed 16 months ago by tscrim

One other trivial thing:

     REFERENCES:
 
-        :wikipedia:`Polygonal_number`
+    :wikipedia:`Polygonal_number`

(or possibly with a bullet point - :wikipedia:...).

comment:29 Changed 16 months ago by git

  • Commit changed from 1cbb3ac67ab822b4b41ad087889ca529b5d1cc41 to e10fd35298dd5340dc38a0665c407370178e8610

Branch pushed to git repo; I updated commit sha1. New commits:

e10fd3527986: updated references block

comment:30 Changed 14 months ago by gh-kliem

  • Status changed from needs_review to positive_review

Sorry, forgot about this. It has been fine for a while now.

comment:31 Changed 13 months ago by vbraun

  • Branch changed from u/gh-sheareralexj/add_function_to_return_the_nth_s_gonal_number to e10fd35298dd5340dc38a0665c407370178e8610
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.