Opened 3 years ago

Closed 2 years 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 3 years ago by gh-sheareralexj

Description: modified (diff)

comment:2 Changed 3 years ago by Erik Bray

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 3 years ago by Erik Bray

Milestone: sage-8.8

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 3 years ago by gh-sheareralexj

Owner: set to gh-sheareralexj

comment:5 Changed 3 years ago by gh-sheareralexj

Milestone: sage-8.9

comment:6 Changed 3 years ago by gh-sheareralexj

Authors: gh-sheareralexj

comment:7 Changed 3 years ago by gh-sheareralexj

Authors: gh-sheareralexjsheareralexj

comment:8 Changed 3 years ago by gh-sheareralexj

Branch: u/gh-sheareralexj/27986

comment:9 Changed 3 years ago by gh-sheareralexj

Branch: u/gh-sheareralexj/27986u/sheareralexj/27986

comment:10 Changed 3 years ago by gh-sheareralexj

Branch: u/sheareralexj/27986t/27986/add_function_to_return_the_nth_s_gonal_number

comment:11 Changed 3 years ago by gh-sheareralexj

Authors: sheareralexj
Branch: t/27986/add_function_to_return_the_nth_s_gonal_number
Owner: gh-sheareralexj deleted
Priority: minortrivial

comment:12 Changed 3 years ago by gh-sheareralexj

Branch: u/gh-sheareralexj/add_function_to_return_the_nth_s_gonal_number

comment:13 Changed 3 years ago by gh-sheareralexj

Authors: Alex Shearer
Commit: b829a434d304f05bc6a3a9257604a3cfc901d3b9
Status: newneeds_review

New commits:

b829a4327986: Added function to return polygonal numbers

comment:14 Changed 3 years ago by git

Commit: b829a434d304f05bc6a3a9257604a3cfc901d3b9c3250281b530f2729e0e37951bbd102a49a4c224

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 3 years ago by Erik Bray

Milestone: sage-8.9sage-9.1

Ticket retargeted after milestone closed

comment:16 Changed 3 years ago by gh-kliem

Reviewers: Jonathan Kliem
Status: needs_reviewneeds_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 2 years ago by Matthias Köppe

Milestone: sage-9.1sage-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 2 years ago by git

Commit: c3250281b530f2729e0e37951bbd102a49a4c224a616782708f55c17920909e3e00ea645112be405

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 2 years ago by gh-sheareralexj

Made the changes above and updated the documentation

comment:20 Changed 2 years ago by gh-sheareralexj

Status: needs_workneeds_review

comment:21 Changed 2 years ago by gh-kliem

Status: needs_reviewneeds_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 2 years ago by git

Commit: a616782708f55c17920909e3e00ea645112be405856d669955c7797ece5d6636cf3f698ab522840e

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

856d66927986: Updated input block and example documentation

comment:23 Changed 2 years ago by gh-sheareralexj

Status: needs_workneeds_review

Thank you Jonathan, I made your suggested edits

comment:24 Changed 2 years ago by git

Commit: 856d669955c7797ece5d6636cf3f698ab522840ecccb629145a38c604412986b010f6af4411c9da2

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

cccb62927986: updated documentation

comment:25 Changed 2 years ago by gh-kliem

One last thing I noticed by the the bots:

-    EXAMPLES::
+    EXAMPLES:

    The triangular numbers::

comment:26 Changed 2 years ago by git

Commit: cccb629145a38c604412986b010f6af4411c9da21cbb3ac67ab822b4b41ad087889ca529b5d1cc41

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

1cbb3ac27986: Updated examples block

comment:27 Changed 2 years ago by gh-sheareralexj

Fixed

comment:28 Changed 2 years ago by Travis Scrimshaw

One other trivial thing:

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

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

comment:29 Changed 2 years ago by git

Commit: 1cbb3ac67ab822b4b41ad087889ca529b5d1cc41e10fd35298dd5340dc38a0665c407370178e8610

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

e10fd3527986: updated references block

comment:30 Changed 2 years ago by gh-kliem

Status: needs_reviewpositive_review

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

comment:31 Changed 2 years ago by Volker Braun

Branch: u/gh-sheareralexj/add_function_to_return_the_nth_s_gonal_numbere10fd35298dd5340dc38a0665c407370178e8610
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.