(***********************************************************************

                    Mathematica-Compatible Notebook

This notebook can be used on any computer system with Mathematica 4.0,
MathReader 4.0, or any compatible application. The data for the notebook 
starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do one of 
the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing the 
word CacheID, otherwise Mathematica-compatible applications may try to 
use invalid cache data.

For more information on notebooks and Mathematica-compatible 
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info@wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from 
Wolfram Research.
***********************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[     10542,        333]*)
(*NotebookOutlinePosition[     11413,        361]*)
(*  CellTagsIndexPosition[     11369,        357]*)
(*WindowFrame->Normal*)



Notebook[{
Cell["\<\
QuarticPlot::usage = \"QuarticPlot[p] plots the family of conics \
which
intersect at points with x-coordinates which are the roots of p, a monic
polynomial of the fourth degree.\";

FindRealRoots::usage = \"FindRealRoots[p] finds the real roots of p.\";

CoefficientsReducedQuartic::usage = \"CoefficientsReducedQuartic[p] gives the
list of coefficients {a, b, c} of p[x - D / 4] = a + b x + c x ^ 2 + x ^ 4,
where p is A + B x + C x ^ 2 + D x  ^ 3 + x ^ 4.\";

Ellipse::usage = \"Ellipse[a, b, c, t] gives one of the ellipses in the \
family
of conics which intersect at points with x-coordinates which are the roots of
a + b x + c x ^ 2 + x ^ 4; t is a positive real number.\";

Parabolas::usage = \"Parabolas[a, b, c] gives a pair of parabolas in the \
family
of conics which intersect at points with x-coordinates which are the roots of
a + b x + c x ^ 2 + x ^ 4.\";

Hyperbola::usage = \"Hyperbola[a, b, c, t] gives one of the hyperbolas in the
family of conics which intersect at points with x-coordinates which are the
roots of a + b x + c x ^ 2 + x ^ 4; t is a negative real number.\";

Degenerates::usage = \"Degenerates[a, b, c] gives the pairs of lines that are
the degenerate cases in the family of conics which intersect at points with
x-coordinates which are the roots of a + b x + c x ^ 2 + x ^ 4.\";

XMinMax::usage = \"XMinMax[s] gives the range of x values {Xmin, Xmax} used \
by
Parabolas and Degenerates; s is a list of real numbers (the roots of the
quartic).\";

FindPlotRange::usage = \"FindPlotRange[s] gives the plot range for \
QuarticPlot;
s is a list of real numbers (the roots of the quartic).\";

RandomQuartic::usage = \"RandomQuartic[] gives a random monic quartic.\";

Purple  = RGBColor[.5, 0, .75];
Red     = RGBColor[1, 0, 0];
Green   = RGBColor[0, 1, 0];
Blue    = RGBColor[0, 0, 1];
Cyan    = RGBColor[0, 1, 1];

QuarticPlot[p_] := Module[
        {x, s, a, b, c},
        x = First @ Variables[p];
        If[
                ! (Exponent[p, x] == 4 && Coefficient[p, x ^ 4] == 1),
                Return[\"The argument is not a monic quartic!\"]
        ];
        s = FindRealRoots[p];
        If[
                Length[s] == 0,
                Return[\"The quartic does not have four real roots!\"]
        ];
        {a, b, c} = CoefficientsReducedQuartic[p];
        Show[Graphics
                [{
                        AbsoluteThickness[2],
                        Purple, Ellipse[a, b, c, #] & /@ Range[10],
                        Red, Parabolas[a, b, c, s],
                        Purple, Hyperbola[a, b, c, #] & /@ Range[-10, -1],
                        Thread @
                                {
                                        {Blue, Green, Cyan},
                                        Degenerates[a, b, c, s]
                                }
                }],
                PlotRange -> FindPlotRange[s],
                AspectRatio -> Automatic
        ]
]

FindRealRoots[p_] := Module[
        {x},
        x = First @ Variables[p];
        Flatten @ Select[
                x /. NSolve[p == 0, x],
                Im @ Chop @ # === 0 &
        ]
]

CoefficientsReducedQuartic[p_] := Module[
        {x},
        x = First @ Variables[p];
        Take[
                CoefficientList[
                        p /. x -> x - CoefficientList[p, x][[4]] / 4,
                        x
                ],
                3
        ]
]

Ellipse[a_, b_, c_, t_] := Module[
        {e, f, g, h, i},
        e = N @ Sqrt[b ^ 2 / (4 t) + (c - t) ^ 2 / 4 - a];
        f = N @ Sqrt[t];
        g = b / (2 f);
        h = (c - t) / 2;
        Line @ Map[
                        {(e Sin[#] - g) / f, e Cos[#] - h} &,
                        Table[i N @ Pi / 32, {i, 0, 64}]
                ]
]

Parabolas[a_, b_, c_, s_] := Module[
        {Xmin, Xmax, t, i, g},
        {Xmin, Xmax} = XMinMax[s];
        t = Table[i / 8, {i, 8 Xmin, 8 Xmax}];
        g = If[
                b == 0,
                {},
                (* else *)
                Line[{-(# ^ 2 + c # + a) / b, #} & /@ t]
        ];
        {g, Line[{#, # ^ 2} & /@ t]}
]

Hyperbola[a_, b_, c_, t_] := Module[
        {e, f, g, h, i, T, k},
        e = N @ Sqrt[-t];
        f = -b / (2 Sqrt[-t]);
        g = (c - t) / 2;
        h = b ^ 2 / (4 t) + (c - t) ^ 2 / 4 - a;
        T = Table[-i / 8, {i, -40, 40}];
        Which[
                Chop[h] < 0,
                k = N @ Sqrt[-h];
                Line /@
                        {
                                {( k Cosh[#] - f) / e,  k Sinh[#] - g} & /@ \
T,
                                {(-k Cosh[#] - f) / e, -k Sinh[#] - g} & /@ T
                        },

                Chop[h] > 0,
                k = N @ Sqrt[h];
                Line /@
                        {
                                {( k Sinh[#] - f) / e,  k Cosh[#] - g} & /@ \
T,
                                {(-k Sinh[#] - f) / e, -k Cosh[#] - g} & /@ T
                        },

                True,
                {}
        ]
]

Degenerates[a_, b_, c_, s_] := Module[
        {x, z, r},
        z = NSolve[b ^ 2 + (c ^ 2 - 4 a) x - 2 c x ^ 2 + x ^ 3 == 0, x];
        r = Last /@ Flatten[z];
        DegeneratesAux[s, r, #, a, b, c] & /@ {1, 2, 3}
]

DegeneratesAux[s_, r_, i_, a_, b_, c_] := Module[
        {d, Xmin, Xmax, e, f, g, v, w},
        d = Chop[- N @ r[[i]] ];
        If[Im @ d != 0, Return @ {}];
        {Xmin, Xmax} = XMinMax[s];
        Which[
                d > 0,
                e = Sqrt @ d;
                f = -b / (2 Sqrt @ d);
                g = (c + d) / 2;
                {
                        Line @ {
                                {Xmin,   e Xmin + f - g},
                                {Xmax,   e Xmax + f - g}
                        },
                        Line @ {
                                {Xmin, - e Xmin - f - g},
                                {Xmax, - e Xmax - f - g}
                        }
                },

                d == 0,
                v = (-c + N @ Sqrt[c ^ 2 - 4 a]) / 2;
                w = (-c - N @ Sqrt[c ^ 2 - 4 a]) / 2;
                {
                        Line @ {{Xmin, v}, {Xmax, v}},
                        Line @ {{Xmin, w}, {Xmax, w}}
                },

                d < 0,
                {}
        ]
]

XMinMax[s_] := Module[
        {a, b, xmin, xmax, dx},
        {a, b} = Round @ {Min[s], Max[s]};
        {xmin, xmax} = If[a == b, {xmin - 4, xmax}, {a, b}];
        dx = Abs[xmax - xmin];
        {xmin - 10 dx, xmax + 10 dx}
]

FindPlotRange[s_] := Module[
        {a, b, xmin, xmax, ymin, ymax, dx, dy},
        {a, b} = Round @ {Min[s], Max[s]};
        {xmin, xmax} = If[a == b, {xmin - 4, xmax}, {a, b}];
        {ymin, ymax} = If[a == b, {a ^ 2 - 4, b ^ 2 + 4},
                Round @ {Min[s ^ 2], Max[s ^ 2]}];
        {dx, dy} = {Abs[xmax - xmin], Max[Abs[ymax - ymin], 2]};
        If[
                2 dx < 10,
                {
                        {xmin - 2 dx, xmax + 2 dx},
                        {ymin - 2 dy, ymax + 2 dy}
                },
                (* else *)
                {
                        {xmin - dx/2, xmax + dx/2},
                        {ymin - dy/2, ymax + dy/2}
                }
        ]
]

RandomQuartic[] := Module[
        {i},
        Sum[Random[Integer, 5] x ^ i, {i, 0, 3}] + x ^ 4
]
\
\>", "Input",
  PageWidth->Infinity,
  InitializationCell->True,
  ShowSpecialCharacters->False],

Cell["\<\
\t
CubicResolvent::usage = \"CubicResolvent[f] determines the Galois group of a \
rational 
\t\t\t\t\t\tquartic f using its cubic resolvent.\";


CubicResolvent[f_] :=
\tModule[ {a,b,c,d,p,q,s,t,r,g,discr},
\t\tIf[!SameQ[Factor[f],f],
\t\t\tPrint[\"The quartic is reducible.\"],
\t\t\ta=Coefficient[f,x,3];
\t\t\tb=Coefficient[f,x,2];
\t\t\tc=Coefficient[f,x,1];
\t\t\td=Coefficient[f,x,0];
\t\t\tp=(-3*a^2)/8 + b;
\t\t\tq=a^3/8 - (a*b)/2 + c;
\t\t\tr=(-3*a^4)/256 + (a^2*b)/16 - (a*c)/4 + d;
\t\t\ts=p^2-4r;
\t\t\tt=-q^2;
\t\t\tg=x^3 + 2*p*x^2 + s*x + t;
\t\t\tPrint[\"The cubic resolvent is  \", g];
\t\t\tdiscr=4p^2*s^2 + 36p*s*t - 32p^3*t - 4s^3 - 27*t^2;
\t\t\tPrint[\"Its discriminant is  \", discr];
\t\t\tPrint[\"The square root of the discriminant is  \",
\t\t\t\t  Sqrt[discr] ];
\t\t\tIf[!SameQ[ Factor[g],g ],
\t\t\t\tPrint[\"The cubic resolvent factors.\"], 
\t\t\t\tPrint[\"The cubic resolvent does not factor.\"] ];
\t\t\tGaloisGroup[IntegerQ[Sqrt[discr]],SameQ[Factor[g],g]];
\t\t\t] \t
\t\t] 


GaloisGroup[v_,w_] :=
\tIf[ !v&&w, Print[\"So the Galois Group is S4.\"],
\t
\tIf[ v&&w, Print[\"So the Galois Group is A4.\"],
\t
\tIf[ v&&!w, Print[\"So the Galois Group is V.\"],
\t
\tIf[ !v&&!w,
\t Print[\"So the Galois Group is D4 or C4.\"]  ]]]];
\t
\
\>", "Input",
  PageWidth->Infinity,
  InitializationCell->True,
  ShowSpecialCharacters->False]
},
FrontEndVersion->"4.0 for Macintosh",
ScreenRectangle->{{0, 1152}, {0, 850}},
AutoGeneratedPackage->None,
WindowSize->{857, 721},
WindowMargins->{{Automatic, 1}, {Automatic, 8}},
MacintoshSystemPageSetup->"\<\
02P0001804P000000^L2D_ogooL33`9K8085:0?l0000005X0FP000003X<;VP5d
038;VTRX04/00@4100000BL?00400@000000000000000000000000000040I0<0
00000000000@X@404@000000000eC64P\>"
]


(***********************************************************************
Cached data follows.  If you edit this Notebook file directly, not using
Mathematica, you must remove the line containing CacheID at the top of 
the file.  The cache data will then be recreated when you save this file 
from within Mathematica.
***********************************************************************)

(*CellTagsOutline
CellTagsIndex->{}
*)

(*CellTagsIndex
CellTagsIndex->{}
*)

(*NotebookFileOutline
Notebook[{
Cell[1717, 49, 7442, 232, 3327, "Input",
  InitializationCell->True],
Cell[9162, 283, 1376, 48, 657, "Input",
  InitializationCell->True]
}
]
*)




(***********************************************************************
End of Mathematica Notebook file.
***********************************************************************)

