(* Face-value vs intended reading of IKV eq. (25).
   Companion script to the blog post
   "Verifying Physics Papers with Claude and Mathematica: The Refined Topological Vertex".

   Part 1: input a partition, build Ztilde from the two readings of eq. (25),
   and compare with the worked example printed in Appendix A, Figure 23.
   Part 2: the degree-2 coefficient of the conifold partition function,
   showing the (q-t)^2 structure of the difference. All output is symbolic. *)

(* ============ Part 1: a partition -> Ztilde ============ *)

nu = {4, 2, 1};

(* standard combinatorics of a Young diagram *)
conjugate[la_List] := Table[Count[la, _?(# >= j &)], {j, 1, Max[la]}];
boxes[la_List] := Flatten[Table[{i, j}, {i, Length[la]}, {j, la[[i]]}], 1];
arm[la_, {i_, j_}] := la[[i]] - j;                                (* boxes to the right *)
leg[la_, {i_, j_}] := conjugate[la][[j]] - i;                     (* boxes below *)

(* the two readings of eq. (25) *)
ZtildeFaceValue[la_, t_, q_] := Product[1/(1 - t^(arm[la, s] + 1) q^leg[la, s]), {s, boxes[la]}];
ZtildeIntended[la_, t_, q_]  := Product[1/(1 - t^(leg[la, s] + 1) q^arm[la, s]), {s, boxes[la]}];

Print["face-value Ztilde_", nu, " = ", ZtildeFaceValue[nu, t, q]];
Print["intended   Ztilde_", nu, " = ", ZtildeIntended[nu, t, q]];

(* the example printed in Figure 23 *)
fig23 = 1/((1 - t)^3 (1 - t q) (1 - t^2 q) (1 - t^2 q^2) (1 - t^3 q^3));
Print["Figure 23 == face-value: ", Simplify[ZtildeFaceValue[nu, t, q] - fig23] === 0];
Print["Figure 23 == intended:   ", Simplify[ZtildeIntended[nu, t, q] - fig23] === 0];

(* ============ Part 2: the conifold numbers quoted in the post ============ *)

normSq[la_List] := Total[la^2];
C00[zt_, la_, t_, q_] := q^(normSq[la]/2) zt[la, t, q];
coeff[zt_, d_] := Sum[(-1)^d C00[zt, p, t, q] C00[zt, conjugate[p], q, t], {p, IntegerPartitions[d]}];

(* degree 1: both readings agree with the product formula *)
Sn[n_] := q^(n/2)/(1 - q^n) t^(n/2)/(1 - t^n);
prodCoeff1 = -Sn[1];
Print["face-value, d=1 residual: ", FullSimplify[coeff[ZtildeFaceValue, 1] - prodCoeff1]];
Print["intended,   d=1 residual: ", FullSimplify[coeff[ZtildeIntended, 1] - prodCoeff1]];

(* degree 2: the error carries an explicit (q-t)^2 and vanishes at t=q *)
prodCoeff2 = (Sn[1]^2 - Sn[2])/2;
Print["intended, d=2 residual: ", FullSimplify[coeff[ZtildeIntended, 2] - prodCoeff2]];
err2 = FullSimplify[coeff[ZtildeFaceValue, 2] - prodCoeff2, Assumptions -> {0 < q < 1, 0 < t < 1}];
Print["face-value, d=2 error / (q-t)^2: ", FullSimplify[err2/(q - t)^2, Assumptions -> {0 < q < 1, 0 < t < 1}]];
Print["face-value, d=2 error at t=q: ", Simplify[err2 /. t -> q]];

(* ============ Part 3: eq. (149) for nu = (2) ============ *)

(* nu = (2) has nu^t = (1,1), and P_{(1,1)} = e_2 for all (q,t), so the
   right-hand side of eq. (149) is t^-2 e_2(t^(1/2), t^(3/2), ...),
   with e_2(t^(1/2), t^(3/2), ...) = t^2/((1-t)^2(1+t)). No q appears. *)
rhs149 = t^-2 t^2/((1 - t)^2 (1 + t));
Print["eq.(149) == face-value: ", Simplify[rhs149 - ZtildeFaceValue[{2}, t, q]] === 0];
Print["eq.(149) == intended:   ", Simplify[rhs149 - ZtildeIntended[{2}, t, q]] === 0];

