KU = PD[X[1,4,2,3]X[2,4,1,3]];
K=K31=PD[X[3,1,4,6],X[1,5,2,4], X[5,3,6,2]];
KB=PD[X[1,4,2,5],X[3,6,4,1],X[5,2,6,3]];
K51=PD[X[1,6,2,7],X[3,8,4,9],X[5,10,6,1],X[7,2,8,3],X[9,4,10,5]];
K10132 = PD[X[4,2,5,1],X[8,4,9,3],X[5,12,6,13],X[15,18,16,19],X[9,16,10,17],X[17,10,18,11],X[13,20,14,1],X[19,14,20,15],X[11,6,12,7],X[2,8,3,7]];
Hp = PD[X[2,3,1,4]X[4,2,3,1]];
Hp1 = PD[X[2,3,1,4]X[3,2,4,1]];

Edge maps-------------

EdgeMap[(c[i_]c[j_]->c[k_]) S[l_]][bv_]:= {vp[i]vp[j]->vp[k], vp[i]vm[j]->vm[k], vm[i]vp[j]->vm[k], vm[i]vm[j]->0,If[Head[(List@@bv)[[1]]]===B,0,bv]};
EdgeMap[(be_B)(c[i_]c[j_]->c[k_])S[l_]][bv_] :=
{vp[i]vp[j]->vp[k], vp[i]vm[j]->vm[k], vm[i]vp[j]->vm[k], vm[i]vm[j]->0,If[Head[(List@@bv)[[1]]]===B,bv/.b_B:>If[b=!=be, 0, (((-1))^(Count[be, q_/;q<l]))],0]}
EdgeMap[(be_B)cs_(c[i_]c[j_]->c[k_])S[l_]][bv_] :=
{vp[i]vp[j]->vp[k], vp[i]vm[j]->vm[k], vm[i]vp[j]->vm[k], vm[i]vm[j]->0,If[Head[(List@@bv)[[1]]]===B,bv/.b_B:>If[b=!=be, 0, (((-1))^(Count[be, q_/;q<l]))],0]};
(* ###################################################### *)
EdgeMap[(c[k_]-> c[i_]c[j_]) S[l_]][bv_]:= {vp[k]-> vp[i]vm[j]+vm[i]vp[j], vm[k]->vm[i]vm[j],If[Head[(List@@bv)[[1]]]===B,0,bv]}
EdgeMap[be_B (c[k_]-> c[i_]c[j_])S[l_]][bv_] :=
{vp[k]-> vp[i]vm[j]+vm[i]vp[j], vm[k]->vm[i]vm[j],If[Head[(List@@bv)[[1]]]===B,bv/.b_B:>If[b=!=be, 0, (((-1))^(Count[be, q_/;q<l]))],0]}
EdgeMap[be_B cs_(c[k_]-> c[i_]c[j_])S[l_]][bv_] :=
{vp[k]-> vp[i]vm[j]+vm[i]vp[j], vm[k]->vm[i]vm[j],If[Head[(List@@bv)[[1]]]===B,bv/.b_B:>If[b=!=be, 0, (((-1))^(Count[be, q_/;q<l]))],0]}

The generating functions from class

KHGroupBasis[K_PD]:= Module[{t,GF,EDS,Vs, Es, basis, FullBasis, ComBasis,sgn,w,n= Length[K]},
SetAttributes[P,Orderless];
SetAttributes[{B,P}, Orderless]; t=0; ϵ /: (ϵ^(p_))/;p>1:=0;
GF=(Expand[
Times@@(K /. X[i_,j_,k_,l_] :> (++t; P[i,j]P[k,l]+B[t] P[i,l]P[j,k]+ϵ S[t]X[i,j,k,l]))
] //. B[i__]B[j__]:> B[i,j] /.P[a_,b_] :> P[a,b][Min[a,b]]//. P[a_,b_][m1_]P[b_,c_][m2_] :> P[a,c][Min[m1,m2]] /. {P[i_, i_][m_] :> c[m], ((P[_,_][m_])^2):> c[m]})/.{X[i_,j_,k_,l_]P[i_,j_] [m1_]P[k_,l_] [m2_] :>Rule[c[m1]c[m2], c[Min[m1,m2]]], X[i_,j_,k_,l_]P[i_,l_] [m1_]P[j_,k_] [m2_] :>Rule[c[Min[m1,m2]], c[m1]c[m2]]};
{Vs,Es} =CoefficientList[GF, ϵ];
basis = List@@Expand[Vs/.c[m_]:> vp[m]+vm[m]];
EDS = GroupBy[If[Head[(List@@#)[[1]]]=== B,{#,Length[#[[1]]]}, {#,0}]&/@List@@Es, Last];
FullBasis=Merge[If[Head[(List@@#)[[1]]]=== B,<|Rule[Length[#[[1]]],#/.b_B:> 1]|>, <|0->#|>]&/@basis, Identity];
ComBasis=Merge[If[Head[(List@@#)[[1]]]=== B,<|Rule[Length[#[[1]]],#]|>, <|0->#|>]&/@basis, Identity];
w=List@@K/.{X[_,1,_,2n] ->1, X[_,2n,_,1]->-1, X[_,j_,_,l_]:>If[j>l,1,-1]};
sgn = GroupBy[w, Sign];
{EDS, FullBasis, ComBasis,Vs,sgn}
]

BE = KHGroupBasis[K]; (*Functions below depend on this varialble.*)

The differentials

(Subscript[d, n_])[bv_]:= Module[{ans, lst, rst,res,x},
If[n≥ Max[Keys[BE[[2]]]]∨n<Min[Keys[BE[[2]]]],Return[{0}]];
Union@@Table[
ans = EdgeMap[i[[1]]][bv];
x = If[Last[ans]===0, {0},List@@Last[ans]];
lst =Union[x,{Last[ans]}];
rst = Association@@Most[ans];
res = Select[lst, MemberQ[Keys[rst], #]&];
{If[res=!={},{Last[ans]}/.res[[1]]:> rst[res[[1]]]]},
{i,BE[[1]][n]}
]
]//Flatten

Matrix of the differentials

(Subscript[M, n_]):=Module[{v},
If[n≥ Max[Keys[BE[[2]]]]∨n<Min[Keys[BE[[2]]]],Return[{{0}}]];
Table[
v = (Subscript[d, n])[a]//Flatten;
Coefficient[Plus@@v,b],
{b, BE[[2]][n+1]},{a, BE[[3]][n]}
]
]

(Subscript[r, n_]):= MatrixRank[(Subscript[M, n])]; (*Rank of Matrix*)

Khovanov Homology

(Subscript[KHom, n_]):= (
If[n> Max[Keys[BE[[2]]]]∨n<Min[Keys[BE[[2]]]],Return[-1]];
Length[BE[[2]][n]]- (Subscript[r, n])-(Subscript[r, n-1])
)

KHomlologyTrefoilKnot = Module[{res},
Table[
res = (Subscript[KHom, i]);
If[res>0, Times@@ConstantArray[ℤ,res],
If[res ===0,{},{0}]
],
{i,0,2}
]
]

Jones Polynomial From the complex

JP=Module[{np, nm,sgn1,nom,j},
sgn1 = BE[[5]];
np=If[MemberQ[Keys[sgn1],1],Plus@@sgn1[1],0];
nm=If[MemberQ[Keys[sgn1],-1],Plus@@sgn1[-1],0];
nom = (((-1))^nm)(q^(np-2nm));
j = nom*Expand[If[Head[#[[1]]] === B, (((-1))^(Length[First[#]]))(q^(Length[First[#]]))(((q + (q^(-1))))^(Length[Rest[#]])), (((q + (q^(-1))))^(Length[#]))]&/@BE[[4]]] (((q+(q^(-1))))^(-1));
Simplify[Expand[j]]
]

(Subscript[M, 0])//MatrixForm

(Subscript[M, 1])//MatrixForm

(Subscript[M, 2])//MatrixForm