# ======================================================================== #
#
# Copyright 2012, Gabor Hegedus, Josef Schicho, and Hans-Peter Schroecker
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ======================================================================== #

# Maple implementation of Example 5 of Hegedus, Schicho, and
# Schroecker: Factorization of Rational Curves in the Study Quadric.

read "qf.mpl":

# Choose one translation quaternion and one rotation quaternion.
h1 := [1,   0,  e,   e];
h2 := [1, 1-e,  1, 1+e];

# Compute P = (t-h1)*(t-h2), its conjugate polynomial Pb, and multiply
# the two. The result is a real polynomial f of degree four with two
# irreducible quadratic factors M1, M2 that can be computed as minimal
# polynomials of h1 and h2, respectively.
P := PolMult([-h1], [-h2]);
Pb := map(Cj, P);       # conjugate quaternion
PPb := PolMult(P, Pb);  # a real polynomial
f := t^4:
for i from 1 to nops(PPb) do
  f := f + t^(4-i) * op(i, PPb)[1]:
od:
f := factor(f);

# Computing f is actually not necessary. We can compute the factors
# directly.
M1 := MinPol(h1);
M2 := MinPol(h2);

# Compute the two factorizations by means of procedures defined in
# qf.mpl.
h2 := Solution(P, M1);
h1 := -PolQuot(P, [-h2])[1];

k2 := Solution(P, M2);
k1 := -PolQuot(P, [-k2])[1];

# check results
PolMult([-h1], [-h2]) - P;
PolMult([-k1], [-k2]) - P;
PlugIn(P, [1, 0, 0, 0]);