pupy.maths

Module Contents

partitions_gen(numero, min_p=1, max_p=None)

Partitions generator

Adapted from: code.activestate.com/recipes/218332-generator-for-integer-partitions/min_p

Parameters:
  • numero (int) – number for which to yield partiton tuples
  • min_p (int) – smallest part size (Default value = 1)
  • max_p (int) – largest part size (Default value = None)
rfactorial(n)

Recursive factorial function

Parameters:n
radians_2_degrees(rads)

Converts radians to degrees

Parameters:rads
degrees_2_radians(degs)

Converts degrees to radians

Parameters:degs
power_mod(number, exponent, mod)
Parameters:
  • number
  • exponent
  • mod
divisors_gen(n)

Divisors generator

Parameters:n (int) – number w/ divisors to be generated
gcd_it(a, b)

iterative gcd

Parameters:
  • a
  • b
gcd_r(a, b)

recursive greatest common divisor

Parameters:
  • a
  • b
reverse(n)

Reverses a number

Parameters:n (int) – number to be reversed
Returns:reversed of a number
Return type:int
fib_r(n)

Recursively the nth fibonacci number

Parameters:n (int) – nth fibonacci sequence number
Returns:the nth fibonacci number
Return type:int
expo(d, n)

greatest exponent for a divisor of n

Parameters:
  • d (int) – divisor
  • n (int) – number be divided
Returns:

number of times a divisor divides n

Return type:

int

pytriple_gen(max_c)

primative pythagorean triples generator

special thanks to 3Blue1Brown’s video on pythagorean triples https://www.youtube.com/watch?v=QJYmyhnaaek&t=300s

Parameters:max_c (int) – max value of c to yeild triples up to
repermutations(toop)
Parameters:toop
disjoint(a, b)
Parameters:
  • a
  • b
n_choose_r(n, r)
Parameters:
  • n
  • r
pytriple_gen_2()
get_pythag_triple(real, imag)
Parameters:
  • real
  • imag
class Trigon(pt1, pt2, pt3)

Bases:object

Trigon object composed of three points connected by lines.

classmethod from_points(cls, pts)
Parameters:pts – return:
__str__(self)
__contains__(self, point)
inner_triangles(self, point)

Triangle funk that returns the three triangles w/ a point

The point (p) is connected to each point of a triangle. with points, a, b, and c. The three triangles are t1=(a, b, p), t2=(a, c, p), and t3 = (b, c, p).

Parameters:point (tuple or Vuple) – point to connect to Triangle Vertices
Returns:t1, t2, t3-> Three triangles
is_perimeter_point(self, point)
Parameters:point
points(self)
contains_origin(self)

True if the origin (0,0) lies within the Triangle

area(self)
static area_from_points(pt1, pt2, pt3)
Parameters:
  • pt1
  • pt2
  • pt3
class Vuple

Bases:tuple

VUPLE == Vector+Tuple

classmethod __new__(cls, *args)
Parameters:args
Returns:
__gt__(self, other)
__eq__(self, other)
__add__(self, k)
>>> va = Vuple((8, 13))
>>> vb = Vuple((26, 7))
>>> va + vb
(34, 20)
__iadd__(self, k)
__sub__(self, k)
__isub__(self, k)
__mul__(self, k)

Multiply by a scalar for each element or cross product if also iterable of same length

Parameters:k – scalar ot other iterable to do the cross producting with
Returns:A Vuple or a sum as a cost product
__imul__(self, k)
_mul_scalar(self, k)
Parameters:k
__truediv__(self, k)
_truediv_scalar(self, k)
Parameters:k
__itruediv__(self, k)
__floordiv__(self, k)
__ifloordiv__(self, k)
_floordiv_scalar_int(self, k)
Parameters:k
normalize(self)

Normalizes the Vuple ST self.magnitude == 1

Returns:Unit Vuple
static unit_vuple(voop)
Parameters:voop
get_mag_sqrd(self)
static mag_sqrd(voop)
Parameters:voop
get_mag(self)
static mag(voop)
Parameters:voop
static dot(a, b)
Parameters:
  • a
  • b
static cross(v1, v2)

Cross product of two 2d vectors

Parameters:
  • v1 – first vector
  • v2 – second vector
Returns:

cross product of v1 and v2

static angle(v1, v2, radians=False)
Parameters:
  • v1
  • v2
  • radians – (Default value = False)
is_disjoint(self, them)
Parameters:them
product(self)

Multiplies all elements in the Vuple

Returns: