So I found a website that calculates polynomials that I need it intakes a word of a's and b's say aabba and outputs a polynomial. Here is the website: http://www.math.stonybrook.edu/~moira/NewApps/Fricke%20Polynomial/fricke.html

I do not know how to use javascript,html,css or anything like that so I am not sure how to import this into Mathematica. I have asked it on stackoverflow with hopes of putting jt into Mathematica but no answer thus far. Thus I was wondering if I can perhaps write code in Mathematica that goes on that website, inputs a word, and outputs the polynomial. An API of a sort. Is that possible?

  • 1
    $\begingroup$ You could try with WebExecute but it does not sound efficient. If you open the site and browser dev tools, navigate to Sources you can see Polynomial.js with function Fricke so you can try to rewrite it with mma. Another take would be to fetch those js sources and ExternalEvaluate it through NodeJS. $\endgroup$
    – Kuba
    Jun 22, 2022 at 7:19
  • $\begingroup$ @Kuba I have copied the js sources (all three of them) and made them into a single code. However, it does not work. I presume it has something to do with it being tied to the html code. I only know Mathematica so I trying things blindly here. $\endgroup$
    – 2132123
    Jun 22, 2022 at 7:30

1 Answer 1

ClearAll[x, y, z]

session = StartExternalSession@"NodeJS";

sources = Import[#, "Text"] & /@ {

ExternalEvaluate[session, sources];

fricke = ExternalEvaluate[session, "Fricke"];

frickeStringToExpr[str_String]:= str // 
  StringReplace[ x : LetterCharacter ~~ n : DigitCharacter .. :> ( StringTemplate[" ``^``"][x, n]) ] // 

string = "aabba";

fricke[string]["data"] // frickeStringToExpr

3 x - x^3 - x y^2 - y z + x^2 y z
  • $\begingroup$ You are a saint. It worked! (I did have to register the NodeJS manually for some reason). Dozgonna wdzięczność :) $\endgroup$
    – 2132123
    Jun 22, 2022 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.