Print[StyleForm[StringJoin[
        "UTA QUtil. Mathematica Version 7 Compatible. Updated: 2007/30/07."
        ]
  ,FontSize->9,FontFamily->"Times", FontColor->
  RGBColor[0., 0.25,0.25]
   ]];

(* Author: A.I. McLeod *)
(* Copyright (c), A.I. McLeod, 2001 *)
(* QUtil *)
(* Summary:
Utilties for checking types.
*)


BeginPackage["QUtil`"]


LogicalQ::usage=
"LogicalQ[x] returns True if x evaluates to either True or False.";

SymmetricPDMatrixQ::usage=
  "SymmetricPDMatrixQ[x] tests if x is a symmetric positive definite matrix.";

ToeplitzQ::usage=
  "ToeplitzQ[x] tests if x is a Toeplitz matrix.";

PersymmetricQ::usage=
   "PersymmetricQ[x] tests if the matrix x is symmetric about the
diagonal which is perpendicular to the main diagonal.";

DoublySymmetricMatrixQ::usage=
   "DoublySymmetricMatrixQ[x] tests if a matrix is symmetric about
both diagonals.";

NumberListQ::usage="NumberListQ[x] is true if x is a list containing numbers.";

NumberVectorQ::usage=
"NumberVectorQ[x] returns True if x is a numeric vector.";

NumberMatrixQ::usage=
"NumberMatrixQ[x] returns True if x is a numeric matrix.";

IntegerNumberVectorQ::usage=
"IntegerNumberVectorQ[x] returns True if x is a numeric vector or x
is an integer.";

ImaginaryQ::usage=
"ImaginaryQ[x] returns True if x is not a real number, that is,
it is symbolic or contains an imaginary component.";

(********************************************************************) 

Begin["`Private`"]

(********************************************************************) 

LogicalQ[x_] := TrueQ[x] || TrueQ[x == False];

ImaginaryQ[x_] :=  !And @@ (0 === #1 & ) /@ Im[x] || 
     And @@ Not /@ NumericQ /@ x;

IntegerNumberVectorQ[x_] := IntegerQ[x] || 
                          (VectorQ[x] && And @@ NumberQ /@ x);

NumberListQ[x_] := ListQ[x] && And @@ NumericQ /@ Flatten[x];

NumberVectorQ[x_] := VectorQ[x] && And @@ NumberQ /@ x;

NumberMatrixQ[x_] := MatrixQ[x] && And @@ NumberQ /@ x;

NumberVectorMatrixQ[x_] := (MatrixQ[x] || VectorQ[x]) && And @@ NumberQ /@ Flatten[x];

PanelTimeSeriesQ[z_] := ListQ[z] && And @@ VectorQ /@ z;

ToeplitzQ[x_] := SquareMatrixQ[x] && x == Toeplitz[x[[1]]];

InvertibleQ[phi_?NumberVectorQ] := 
  With[{Fuzz = 10^-14}, 
    Apply[And, Map[Less[Abs[#] + Fuzz, 1.0] &, ARToPacf[phi]]]];

InvertibleQ2[phi_?NumberVectorQ] := 
  Return[SymmetricPDMatrixQ[SiddiquiMatrix[phi, Length[phi]]]];

SymmetricPDMatrixQ[x_] := 	SquareMatrixQ[x] && 
                           SymmetricMatrixQ[x] && 
                           Apply[And, Positive[Eigenvalues[x]]];
   
SquareMatrixQ[x_] := MatrixQ[x] && Apply[Equal, Dimensions[x]];
 
PersymmetricQ[x_] := 
  x == Table[x[[Length[x] + 1 - j,Length[x] + 1 - i]], {i, Length[x]}, 
    {j, Length[x]}];
 
DoublySymmetricMatrixQ[x_] := 
   SquareMatrixQ[x] && SymmetricMatrixQ[x] && PersymmetricQ[x];

(**********************Local Functions*********************************) 

Toeplitz/: Toeplitz[m_] := 
   Return[Table[m[[1 + Abs[i - j]]], {i, Length[m]}, {j, Length[m]}]];


ARToPacf[phi_?VectorQ] := 
  Module[{pi, a, phikp1, phik = phi, L = Length[phi]}, 
   pi = Table[0, {L}]; Do[pi[[L + 1 - k]] = a = Last[phik]; 
      phikp1 = Drop[phik, -1]; phik = (phikp1 + a*Reverse[phikp1])/(1 - a^2)\
, {k, 1, L}]; pi];

End[];
EndPackage[];
