File: curl.m2

package info (click to toggle)
macaulay2 1.21%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 133,096 kB
  • sloc: cpp: 110,377; ansic: 16,306; javascript: 4,193; makefile: 3,821; sh: 3,580; lisp: 764; yacc: 590; xml: 177; python: 140; perl: 114; lex: 65; awk: 3
file content (84 lines) | stat: -rw-r--r-- 2,585 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
ID=" $OpenXM: OpenXM/src/Macaulay2/m2/curl.m2,v 1.2 2015/08/19 07:20:27 takayama Exp $ "

-- curl interface for M2
-- BSD license without advertisements

curl = method()
curl(String,String) := (s,url) -> (
     try (F := get ("!curl " | s | " " | url))
     else ( error "Could not start curl " | s | " " | url);
     F
     )

test1 = method()
test1(ZZ) := (ttype) -> (
   ans1=
   curl("--data 'oxMessageBody=fd_hessian2(-2,[-3,-2],10,[1/2,1/3])'",
        "http://asir2.math.kobe-u.ac.jp/cgi-bin/cgi-asir-r-fd2.sh");
   print(ans1);
   ans2=
   curlPostMessage("oxMessageBody=fd_hessian2(-2,[-3,-2],10,[1/2,1/3])",
        "http://asir2.math.kobe-u.ac.jp/cgi-bin/cgi-asir-r-fd2.sh");
   ans2
)

-- --data-urlencode should be used for new curl.
curlPostMessage = method()
curlPostMessage(String,String) := (data,url) -> (
   curl("--data " | "'" | data | "'", url)
)

----------------------------------------------
-- Sample interface for cgi-asir.
---------------------------------------------
-- Translate list expressions among asir and M2
asir2m2 = method()
asir2m2(String):= (s) -> (
  s2=replace("\\[","{",s);
  replace("\\]","}",s2)
)
m22asir = method()
m22asir(String):= (s) -> (
  s2=replace("\\{","[",s);
  replace("\\}","]",s2)
)

-- Example: fdHessian2(-2,{-3,-2},10,{1/2,1/3})
fdHessian2 = method()
fdHessian2(ZZ,List,ZZ,List):= (a,b,c,x) -> (
 strategy = "asir2-cgi";
 url = "http://asir2.math.kobe-u.ac.jp/cgi-bin/cgi-asir-r-fd2.sh";
 if (strategy == "asir2-cgi") then (
  s = toString(a) | "," | m22asir(toString(b)) | "," |
      toString(c) | "," | m22asir(toString(x));
  s = "oxMessageBody=fd_hessian2(" | s | ")";
  ans = curlPostMessage(s,url);
  if (match("error",ans)) then error(ans);
  h=value(asir2m2(ans));
 );
 {h,ans}
)

-- s should be in the polynomial ring.
-- example: QQ[s,x,y,dx,dy,WeylAlgebra=>{x=>dx,y=>dy}]
--    genericBfct({x*dx+y*dy-3,x*dx-y*dy},{x,y},{dx,dy},{1,1})
genericBfct = method()
genericBfct(List,List,List,List):= (ideal,xvar,dvar,w) -> (
 strategy = "asir2-cgi";
 url = "http://asir2.math.kobe-u.ac.jp/cgi-bin/cgi-generic_bfct2.sh";
 if (strategy == "asir2-cgi") then (
  ss = m22asir(toString(ideal)) | "," | m22asir(toString(xvar)) | "," |
       m22asir(toString(dvar)) | "," | m22asir(toString(w));
  ss = "oxMessageBody=generic_bfct(" | ss | ")";
  ans = curlPostMessage(ss,url);
  if (match("error",ans)) then error(ans);
  h=value(asir2m2(ans));
 );
 {h,ans}
)

genericBfct(Ideal,List,List,List):= (ideal,xvar,dvar,w) -> (
  genericBfct(flatten(entries(gens(ideal))),xvar,dvar,w)
)
-- todo. Extract xvar,dvar. vars ring I