Skip to content

Instantly share code, notes, and snippets.

@tueda
Last active September 20, 2017 12:11
Show Gist options
  • Select an option

  • Save tueda/97e11868b99de2a06957 to your computer and use it in GitHub Desktop.

Select an option

Save tueda/97e11868b99de2a06957 to your computer and use it in GitHub Desktop.
UF function on Mathics #mma
(*
* UF[] by A. Smirnov.
* U and F are obtained by computing the matrix determinant.
*)
UF[xx_, yy_, z_] := Module[{degree, coeff, i, t2, t1, t0, zz},
zz = Map[Rationalize[##,0]&, z, {0, Infinity}];
degree = -Sum[yy[[i]]*x[i], {i, 1, Length[yy]}];
coeff = 1;
For[i = 1, i <= Length[xx], i++,
t2 = Coefficient[degree, xx[[i]], 2];
t1 = Coefficient[degree, xx[[i]], 1];
t0 = Coefficient[degree, xx[[i]], 0];
coeff = coeff*t2;
degree = Together[t0 - ((t1^2)/(4 t2))];
];
degree = Together[-coeff*degree] //. zz;
coeff = Together[coeff] //. zz;
{coeff, Expand[degree], Length[xx]}
];
(*
* Rationalize[] is available in v1.0
*)
(*
(* XXX: Ignore it!!! *)
Rationalize[x_, y_] := x;
*)
(* XXX: Polynomial only!!! *)
Coefficient[expr_, x_, n_] := Module[{e},
e = expr;
Do[
e = D[e, x];
, {i, n}];
(e /. x -> 0) / n!
];
(* Test *)
UF[{p1, p2}, {p1^2, p2^2, (p2-q)^2, (p1-q)^2 ,(p1-p2)^2}, {}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment