Indices#

Index sets are of two types:

  1. collection, e.g. different types of planetary objects in our solar system.

  2. ordered, e.g. hours in a day, days in a year

from gana import Prg, I

p = Prg()

Declaring Sets#

Collections#

For a collection, elements are based as strings, with an optional tag.

p.giants = I('jupiter', 'saturn', 'uranus', 'neptune', tag='giant planets')
p.rocky = I('mercury', 'venus', 'earth', 'mars', tag='rocky planets')
p.gasgiants = I('jupiter', 'saturn', tag='gas giants')
p.minor = I('ceres', 'pluto', 'makemake', 'eris', tag='minor planets')
p.asteroid = I('ceres')
p.former = I('pluto', tag='used to be a planet :(')
p.voyager = I(
    'saturn',
    'neptune',
    'uranus',
    'titan',
    'earth',
    'jupiter',
    tag='visited by the Voyager program',
)

Ordered Sets#

Only the size is needed

p.days = I(size=365, tag="days in a year", mutable=True)
p.days.show()
\[\displaystyle {days} = \{ {{{{days}_{0}}}, \dots ,{{{days}_{364}}}} \}\]

Set Operations#

These only apply for Collections

Set Minus#

p.icegiants = p.giants - p.gasgiants
p.icegiants.show(True)
\[\displaystyle {icegiants} = \{ {{uranus}, {neptune}} \}\]

And#

p.hasheart = p.minor & p.former
# p.hasheart = p.minor and p.former
p.hasheart.show(True)
\[\displaystyle {hasheart} = \{ {{pluto}} \}\]

Or#

p.planets = p.gasgiants | p.icegiants | p.rocky
p.planets.show(True)
\[\displaystyle {planets} = \{ {{jupiter}, \dots ,{mars}} \}\]

Exclusive Or#

p.dense = p.voyager ^ p.giants
p.dense.show(True)
\[\displaystyle {dense} = \{ {{titan}, {earth}} \}\]

Cartesian Product#

p.i = I('a', 'b', 'c')
p.j = I('p')
p.k = I(size=2)
p.l = p.i * p.j * p.k
p.l
(i, j, k)

\(\LaTeX\)#

Use:

  • .latex() to return string

  • .show() to pretty print in console

With Elements#

Elements are shown for both types of sets, but upto a limit.

p.minor.show()
\[\displaystyle {minor} = \{ {{ceres}, {pluto}, {makemake}, {eris}} \}\]

Beyond a default length of 5 elements dots (\(\dots\)) are used.

p.voyager.show()
\[\displaystyle {voyager} = \{ {{saturn}, \dots ,{jupiter}} \}\]

This can however be extended

p.voyager.show(dots_limit=7)
\[\displaystyle {voyager} = \{ {{saturn}, {neptune}, {uranus}, {titan}, {earth}, {jupiter}} \}\]

Integer Notation#

This can only be used for ordered sets

p.days.show(True, int_not=True)
\[\displaystyle {days} = \{ \{ i = \mathbb{{days}} \mid {{{days}_{0}}} \leq i \leq {{{days}_{364}}} \} \}\]

Only Name#

For only the name, turn descriptive print off.

p.giants.show(False)
\[\displaystyle {giants}\]

Accessing Elements#

Irrespective of type, elements can be accessed by position. Thus, even collections are not truly sets in the strictest sense

p.voyager[3], p.days[33]
(titan, days[33])

Additionally, elements are set on the Program as index sets of size 1

p.titan, len(p.titan)
(titan, 1)

To return just the \(\LaTeX\) string, use .latex()

p.days.latex()
'{days} = \\{ {{{{days}_{0}}}, \\dots ,{{{days}_{364}}}} \\}'