Skip to content

Instantly share code, notes, and snippets.

View LemonPi's full-sized avatar

Sheng Zhong (Johnson) LemonPi

View GitHub Profile
@LemonPi
LemonPi / rnf.py
Created November 16, 2013 17:56
Reduced normal form in python
# Naive implementation of reduce normal form with some helper functions
from fractions import *
# helper functions
def row_sub(reduceby, reduceto, index):
"""
Take row to reduce and row to reduce by with the index of the element to
reduce to 0. Assume reduce by has value 1 in the index of reduceto.
"""
row_merged = []
@LemonPi
LemonPi / roots.py
Created October 12, 2013 01:10
Newton's method for finding nth root of number r to p decimal places correct
def newton(n, r, p = 0):
"""
(int(n), num(r), int(p)) -> float
Return the nth root of a positive number r displaying p correct decimals.
"""
x = 1 # start with guess = 1
while True:
fx = x**n - r # function of this form solves all roots