Skip to content

AWeirdDev/mathsq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

mathsq

Math sequence. Useful for calculations.

Note

This uses basic math and is incompatible with array frameworks like NumPy. We strive to keep it light.

from mathsq import MathSQ

array = MathSQ(
  a1=10,  # first item
  d=2,    # common difference
  ln=10   # length ($n$ sequence)
)

This yields a sequence:

$$ ( a_n ): 10, 12, 14, \ldots $$

We can also create a MathSQ from specifying the $n$-th element.

array = MathSQ.from_n_assignment(
  n=10,
  value=100,
  d=-1
)

Set array length

This returns the array itself.

>>> array = array.setln(100)

Get $n$-th element

Note

Out-of-bounds are not handled.

>>> array.n(5)

Get $n$ from value

Note

Out-of-index is not handled.

>>> array.n_of(10)

Get middle $n$

Note

May return a float.

>>> array.mid_n()

Get middle value

Note

Out-of-bounds are not handled.

>>> array.mid()
>>> # ...or
>>> array.M

Has middle?

Returns True if the middle index exists.

>>> array.has_mid()

Sum

>>> array.sum()
>>> # ...or
>>> array.S

Basic manipulations

Note

Implementation not fully covered.

>>> array1 = array0 + 10 # array +/- float
>>> array1 -= array0 # array +/- array
>>> array1.a1
10

>>> array1 * 10

Where 0 is at

Find the closest $n$ index to 0.

Restrictions:

$$ a_1 > 0, d < 0 $$

or

$$ a_1 < 0, d > 0 $$

or

$$ a_1 = 0 $$

>>> array0.where0()