Skip to content

Instantly share code, notes, and snippets.

@saschatimme
Last active April 18, 2019 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saschatimme/02faf68103d639eb31f5706760b974d4 to your computer and use it in GitHub Desktop.
Save saschatimme/02faf68103d639eb31f5706760b974d4 to your computer and use it in GitHub Desktop.
parsePolynomial = p -> replace("ii","im",replace("p[0-9]+","0",toExternalString p))
writeSystem = method(Options=>{})
writeSystem (List, File) := o -> (P,f) -> (
R := ring first P;
vars := apply(gens R, toString);
concatenate(mingle(vars, (#vars-1):1));
f << "# This file was auto generated from Macaulay2.\n";
f << "# For more information about HomotopyContinuation.jl visit:\n";
f << "# https://www.JuliaHomotopyContinuation.org\n";
f << "using HomotopyContinuation";
f << "\n\n";
f << "@polyvar " | concatenate(mingle(vars, #vars:1));
eqnCommas:=(#P-1):", ";
f << "\n";
f <<"f = [" | concatenate mingle(
apply(P,e->parsePolynomial e), eqnCommas)| "];\n";
f << "\n";
f << "result = solve(f)";
)
writeSystem (List, String) :=o -> (P,filename) -> (
f := openOut filename;
writeSystem(P,f);
close f;
)
writeSystem (Ideal, String) := o -> (I,f) -> (
writeSystem(first entries gens I, f)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment