(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



BeginPackage["FusionAtlas`CyclotomicTest`",{"FusionAtlas`","FusionAtlas`Bigraphs`"}~Join~If[$VersionNumber<6,{"NumberTheory`AlgebraicNumberFields`"},{}]];


Begin["`Private`"];


LeadingTerm[polynomial_,x_]:=
Coefficient[polynomial,x^(Exponent[polynomial,x])]


If[$VersionNumber<6.0,
Discriminant[polynomial_,x_]:=
Together[Resultant[polynomial, D[polynomial,x],x]/LeadingTerm[polynomial,x]]
]


GoodPrimes[polynomial_,x_,n_]:=
Module[{Discriminant=Abs[Discriminant[polynomial,x]]}, Select[Table[Prime[k],{k,1,n}],Not[Mod[Discriminant,#]==0]&]]


FactorPowersModp[polynomial_,p_Integer,x_]:=
Exponent[#[[1]],x]&/@Rest[FactorList[polynomial,Modulus->p]]


AllTheSame[a_]:=Length[Union[a]]==1


PolynomialCyclotomicTest[polynomial_,n_Integer, x_] :=
Module[{j,goodprimes=GoodPrimes[polynomial,x,n]},
If[Exponent[polynomial,x]==1,Return[True];,
For[j=1,j<=Length[goodprimes],j++,
If[Not[AllTheSame[FactorPowersModp[polynomial,goodprimes[[j]],x]]],
Return[False];
];
];
];
Return[True];
];


CyclotomicTest[g_GradedBigraph,n_:200]:=
Module[{x,index=GraphIndex[g]},
PolynomialCyclotomicTest[MinimalPolynomial[index,x],n,x]
]


End[];


EndPackage[];
