#!/usr/bin/python -Wall

# ================================================================
# John Kerl
# kerl.john.r@gmail.com
# 2007-01-12
#
# Uses Householder transformations twice to create a matrix
# sending u hat to v hat.
# ================================================================
# This software is released under the terms of the GNU GPL.
# Please see LICENSE.txt in the same directory as this file.
# ================================================================

from __future__ import division # 1/2 = 0.5, not 0.
import sys
from sackmat_m import *

argc = len(sys.argv)
if (argc != 3):
	print >> sys.stderr, "Usage: %s {u file name} {w file name}" % (sys.argv[0])
	sys.exit(1)

u = read_column_vector(float, sys.argv[1])
w = read_column_vector(float, sys.argv[2])

uhat = vechat(u)
what = vechat(w)
vhat = vechat(vecadd(uhat, what))

a1  = vecsub(uhat, vhat)
a2  = vecsub(vhat, what)

[Q1, sign] = householder_vector_to_Q(a1)
[Q2, sign] = householder_vector_to_Q(a2)
R  = Q2 * Q1
print_matrix(R)
