(*Ex 1*)

CylindricalDecomposition[ForAll[x,a x^2+ b x +c>=0],{x,a,b,c}]

CylindricalDecomposition[ForAll[{a,b,c},Implies[a>=0&&(b^2)≤4 a c&&c≥0,(a==0&&b==0&&c≥0)||(a>0&&c≥((b^2)/(4 a)))]],{a,b,c}]
CylindricalDecomposition[ForAll[{a,b,c},Implies[(a==0&&b==0&&c≥0)||(a>0&&c≥((b^2)/(4 a))),a>=0&&(b^2)≤4 a c&&c≥0]],{a,b,c}]

RegionPlot3D[a>=0&&(b^2)≤4 a c&&c≥0,{a,-2,8},{b,-5,5},{c,-2,8}]

(*Ex 2: Motzkin polynomial*)
Plot3D[x^4y^2+x^2y^4-3x^2y^2+1,{x,-1,1},{y,-1,1}]
Plot3D[x^4y^2+x^2y^4-3x^2y^2+1,{x,-1.5,1.5},{y,-1.5,1.5}]
Plot3D[x^4y^2+x^2y^4-3x^2y^2+1,{x,-4,4},{y,-4,4}]

(*Ex 3*)
Eigensystem[{{c,b/2},{b/2,a}}]

P=CholeskyDecomposition[{{c,b/2},{b/2,a}}];
Simplify[P,Assumptions->a>=0&&(b^2)≤4 a c&&c≥0]//MatrixForm
Simplify[Transpose[Inverse[P]].{{c,b/2},{b/2,a}}.Inverse[P],Assumptions->a>=0&&(b^2)≤4 a c&&c≥0]==IdentityMatrix[2]

P=(({{(Sqrt[c]), (b/(2 (Sqrt[c])))}, {0, ((Sqrt[4 a c-(b^2)])/(2(Sqrt[c]))) }}));
Expand[FullSimplify[Transpose[P.{1,x}].(P.{1,x}),Assumptions->a>=0&&(b^2)≤4 a c&&c≥0]]
FullSimplify[Transpose[P].P,Assumptions->a>=0&&(b^2)≤4 a c&&c≥0]

P.{1,x}

{(Sqrt[c])+((b x)/(2 (Sqrt[c]))),(((Sqrt[-(b^2)+4 a c]) x)/(2 (Sqrt[c])))}.{(Sqrt[c])+((b x)/(2 (Sqrt[c]))),(((Sqrt[-(b^2)+4 a c]) x)/(2 (Sqrt[c])))}

Expand[(((-(b^2)+4 a c) (x^2))/(4 c))+((((Sqrt[c])+((b x)/(2 (Sqrt[c])))))^2)]

(*Ex 4*)

Plot[x^4+4x^3+6x^2+4x+5,{x,-3,2},PlotRange->{0,20}]
Minimize[x^4+4x^3+6x^2+4x+5,x]

Collect[{1,x,x^2}.{{a00,a01,a02},{a01,a11,a12},{a02,a12,a22}}.{1,x,x^2},x]

sol=SolveAlways[a00+2 a01 x+(2 a02+a11) (x^2)+2 a12 (x^3)+a22 (x^4)==x^4+4x^3+6x^2+4x+5,x]

M={{a00,a01,a02},{a01,a11,a12},{a02,a12,a22}}/.sol[[1]];
M//MatrixForm

(*Auxiliary function to compute all principal minors of a matrix*)
princminors[X_]:=(
minors={};
For[k=1,k<=Length[X],k++,
ktuples=Subsets[Range[Length[X]],{k}];
For[i=1,i<=Length[ktuples],i++,
minors=AppendTo[minors,Det[X[[ktuples[[i]],ktuples[[i]]]]]];
];
];
Return[minors];
);

Mpsd=And@@Thread[princminors[M]>=0];(*Lists that all principal minors are nonnegative*)
Reduce[Mpsd]

M0=M/.{a11->6};
M0//MatrixForm

P=CholeskyDecomposition[M0];
Simplify[P]//MatrixForm
Simplify[Transpose[Inverse[P]].M0.Inverse[P]]==IdentityMatrix[3]

Transpose[P.{1,x,x^2}].(P.{1,x,x^2})
Expand[FullSimplify[Transpose[P.{1,x,x^2}].(P.{1,x,x^2})]]

(*Alternative decomposition*)
P={{0,2,1},{Sqrt[2],Sqrt[2],0},{Sqrt[3],0,0}};
P//MatrixForm

Simplify[Transpose[Inverse[P]].(({{5, 2, 0}, {2, 6, 2}, {0, 2, 1}})).Inverse[P]]==IdentityMatrix[3]
Expand[FullSimplify[Transpose[P.{1,x,x^2}].(P.{1,x,x^2})]]

P.{1,x,x^2}

{2 x+(x^2),(Sqrt[2])+(Sqrt[2]) x,(Sqrt[3])}.{2 x+(x^2),(Sqrt[2])+(Sqrt[2]) x,(Sqrt[3])}

Simplify[(x^2+2x)^2+(Sqrt[2](1+x))^2+Sqrt[3]^2]