So I wanted to try to rewrite my pivot routine in haskell, but I got stuck right away...
Here is my original python routine (i've commented it heavily to compensate for the lack of types):
def pivot(entering, leaving, B, A, Z):
"""
@param entering integer indicating the entering col #
@param leaving integer indicating the leaving col #
@param B vector/array of integers, representing the basis
@param A matrix of floating point numbers
@param Z vector/array of floating point numbers
returns tuple:
(B, A, Z) with pivoted tableau
"""
# Copy A
M = [row for row in A]
# Append Z row to the matrix
M.append(Z)
# Find the main row
eq_no = B.index(leaving)
col = entering
# Go through all other rows and do Gaussian elimination on them:
for i in range(len(M)):
if i == eq_no:
continue
# Do pivot - ignore "zero_out" function for now
# assume it returns a vector same size as row M[i]
M[i] = zero_out(M[i], M[eq_no], col)
# Reassign B's
Bprime = [b for b in B] # copy B
Bprime[eq_no] = entering # replace
# return new B, matrix M (less 1 row), and last row of M
return (Bprime, M[:len(M)-1], M[len(M)-1])
Here is how far I got...
type Matrix = [ [Double] ]
type Vector = [ [Vector] ]
matrix = [ [1, 2, 3], [2, 3, 4]]
hello:: Matrix -> Int
hello m = length m
pivot:: Int -> Int -> Vector -> Matrix -> Matrix -> Matrix
pivot entering leaving b a z =
let m = a::z
eq_no = elemIndex leaving b
case eq_no of
Just no -> no
Nothing -> 1
col = entering
in ????
I am very interested in how people might implement the "matrix" and "vector" types, and also how they will manipulate the arrays - like replacing elements in them or rows in a matrix.
Let me know if something is not clear, and thanks!
Vectortype is correct?[ foo | x <- gen, baz], tuple syntax(foo, bar), array indexingarr ! index, guard syntax| predicate = expression. These are all fairly basic Haskell; perhaps give earlier sections of the tutorial a read, or start with LYAH