

function m_syn(a,f,q) {
// 1 --

  var x=1,y=0,z=0,t=0,b=0,n="0123456789)xyI"
  var c="",d="",e="",g="",h="",u="",v="",w="",i=0,j=0,a3="/^*"
//  do {i=a.indexOf("|"); if (i==-1) break; a=u_x(a,i,"")} while (true)
  a=u_rem(a,"|")
  if (a=="") return "E6" // ; a=m_bradd(a)
//this.status=a
// 2 --

/*
  g="HLAU"; h="m_h|m_l|m_a|m_u"
  for (i=0; i<4; i++) {d=g.charAt(i); e=u_pr(h,i+1); do {
    y=a.indexOf(d); if (y==-1) break
    x=y+1; z=m_arg(a,x); v=a.substr(x,z-x)
    v=u_sub(v,";",","); if (v.charAt(0)=="(") v=v.substr(1,v.length-2)
    a=a.substr(0,x)+"("+v+")"+a.substr(z); a=u_x(a,y,e)} while (true) }
*/

  a=m_mh(a)

//  y=0; a+="|"; x=a.indexOf("x"); do {y++; x=a.lastIndexOf(","); if (x==-1) break
    y=0; do {y++; x=a.lastIndexOf(","); if (x==-1) break; c="<x>"
    if (a.charAt(x-1)==",") c=""; else {if (y>1) c+="^"+y; c+="+"}
    a=u_x(a,x,c)} while (true); a=u_sub(a,"+-","-") // ; a=u_sub(a,"+|",""); a=u_sub(a,"|","")

  x=a.indexOf("="); if (x>0) a="("+a.substr(0,x)+")-("+a.substr(x+1)+")" 


//  do {y=a.indexOf("X"); if (y==-1) break; a=u_x(a,y,"x")} while (true)
      a=u_sub(a,"EXp","exp")

// 3 --
  x=0; do {y=a.indexOf("Usqrt",x); if (y==-1) break
    if (y>0 && n.indexOf(a.charAt(y-1))>=0) {x=y+1; continue}
    x=y+5; z=m_arg(a,x); v=a.substr(x,z-x)
    if (v.charAt(0)=="-") {c="-"; v=v.substr(1)} else c=""
    if (v.charAt(0)=="(") v=v.substr(1,v.length-2)

    a=a.substr(0,y)+c+"Math.pow("+v+",1/3)"+a.substr(z)} while (true)

  d="asin;acos;atan;sin;cos;tan;log;exp;lgZ;epZ;sqrt;ahsin;ahcos;ahtan;hsin;hcos;htan;"; i=0;z=-1
  d+="csc;sec;cot;acsc;asec;acot"
  do {i++; g=u_parse(d,";",i); x=0; if (g=="") break
    if (i<=6 || i>=18) e="(Math.PI/180)"; else e="Math.LN10"

  do {y=a.indexOf(g,x); if (y==-1) break; x=y
        if (y>0) {c=a.charAt(y-1); if (u_iO("ah.",c)) {x++;continue} }

      j=y+g.length; z=m_arg(a,j); if (z==-1) return "XXX"; h=g
      v=a.substr(j,z-j); w=v.charAt(0); if (w=="S" || w=="U") v=v.substr(1); else w=""
      if (v.charAt(0)=="(") v=v.substr(1,v.length-2); v="("+v+")"
      
      
      if (i>=12 && i<=17) v="("+i+","+v.substr(1)
      if (g=="lgZ") {h="log"; v+="/"+e+")"}; if (g=="epZ") {h="exp"; v="("+v+"*"+e+")"}
      if (f) {if (i<=3 || i>=21) v+="/"+e; if ((i>3 && i<=6) || (i>17 && i<21)) v="("+v+"*"+e+")"} 
      if (i<12 || i>=18) v="Math."+h+v; else v="m_hyp"+v
      if (g=="lgZ") v="("+v
      if (w!="") v="("+v+")"+w; a=a.substr(0,y)+v+a.substr(z) //; return a+" GOSH!"


    } while (true)
  } while (true)
  
// 4 --

//  do {y=a.indexOf("S"); if (y==-1) break; a=u_x(a,y,"^2")} while (true)
//  do {y=a.indexOf("U"); if (y==-1) break; a=u_x(a,y,"^3")} while (true)
//  do {y=a.indexOf("Q"); if (y==-1) break; a=u_x(a,y,"Math.PI")} while (true)
  a=u_mub(a,"S|U|Q|R","^2|^3|Math.PI|%")
  
  do {x=0
    for (i=0; i<=a.length-2; i++) {
//      if ("0123456789)jxyzI".indexOf(a.charAt(i))>=0 && "(jxyzMm".indexOf(a.charAt(i+1))>=0)
      if ("0123456789)>I".indexOf(a.charAt(i))>=0 && "(<Mm".indexOf(a.charAt(i+1))>=0)
        {a=a.substr(0,i+1)+"*"+a.substr(i+1);x=1}
      if (a.charAt(i)==")" && "0123456789".indexOf(a.charAt(i+1))>=0)
        {a=a.substr(0,i+1)+"*"+a.substr(i+1);x=1}
    }
  } while (x==1) 

  a=u_rem(a,"<>")
//  a=u_sub(a,"<",""); a=u_sub(a,">","")

  do {y=a.indexOf("^"); if (y==-1) break
    z=y; b=0; do {z++; if (z==a.length) break; c=a.charAt(z)
//      if (z==y+1 && c=="-") continue
      if ("+-/),".indexOf(c)>=0 && b==0 && z>y+1) break
      if (c=="(") b++; if (c==")") b--} while (true)
    x=y; b=0; do {x--; if (x<0) break; c=a.charAt(x)
      if ("*+-/(,".indexOf(c)>=0 && b==0) break
      if (c=="(") b++; if (c==")") b--} while (true)
    x+=1; d=m_ub(a.substr(x,y-x)); g=m_ub(a.substr(y+1,z-y-1))
    a=a.substr(0,x)+"Math.pow("+d+","+g+")"+a.substr(z)}
  while (true)

// 5 trig reciprocal functions
  i=0; d="csc;sec;cot"; e="sin;cos;tan"
  do {i++; if (i==4) break; g="a"+u_pn(d,i); h="a"+u_pn(e,i)
     y=a.indexOf(g); if (y==-1) continue; z=y+5; b=1
    do {c=a.charAt(z); if (c=="(") b++; if (c==")") b--
       if (b==0) break; z++} while (true)
    x=y+4; a=a.substr(0,y)+h+"(1/"+a.substr(x,z-x+1)+")"+a.substr(z+1); i--} while (true) 

  i=0; do {i++; if (i==4) break; g=u_pn(d,i); h=u_pn(e,i)
     y=a.indexOf(g); if (y==-1) continue; z=y+4; b=1
    do {c=a.charAt(z); if (c=="(") b++; if (c==")") b--
       if (b==0) break; z++} while (true)
    x=y+3; a=a.substr(0,y-5)+"(1/Math."+h+a.substr(x,z-x+1)+")"+a.substr(z+1); i--} while (true) 
  a=m_prec(a)
  return a+"|"+u
   
}
function m_sc(a) {
// finds position of semicolon where used as equation separator
  var z=-1,b=0,c=""
  do {z++; if (z==a.length) return -1; c=a.charAt(z)
    if (b==0 && c==";") return z
    if (c=="(") b++; if (c==")") b--} while (true)
}
function m_ub(a) {
  var x=a.length-1,b=0,i=0,c=""
  if (a.charAt(0)!="(" || a.charAt(x)!=")") return a
  for (i=0; i<x; i++) {c=a.charAt(i); if (c=="(") b++; if (c==")") b--; if (b==0) return a}
  return a.substr(1,x-1)
}
function m_prec(a) {
  var x=0, y=0, b=0, c="", f=false, v=false
  do {x=a.indexOf("/",x+1); if (x==-1) return a; b=0; y=x; v=false
    do {y++; if (y==a.length) break; c=a.charAt(y)
      if (c=="(") b++; if (c==")") b--
      if (b<=0) f=true; else {f=false; continue} if (b<0) break
      if (c=="*") v=true; if (u_iO("+-/",c)) break} while (true)
    if (v && f) {x++; a=a.substr(0,x)+"("+a.substr(x,y-x)+")"+a.substr(y)} } while (true)
}
function m_sif(a) {
  var c="",y=0
  x=u_pF(a); if (isNaN(x)) return a
  if (x<0) {x=-x; c="-"} if (x>=1 && x<10) return a
  if (x>=10) do {y++; x=x/10; if (x<10) return c+m_dp(x,9)+"e"+y} while (true)
  if (x<1) do {y--; x=x*1e1; if (x>=1) return c+m_dp(x,9)+"e"+y} while (true)
} 
function m_dp(t,n) {
  var a="",s="",c="",e=0,p=0,x=0,y=0; if (isNaN(t)) return "/-/"; a=t.toString()
  if (a.charAt(0)=="-") {a=a.substr(1); s="-"}
  if (a.charAt(0)=="+") a=a.substr(1)
  x=a.indexOf("e"); if (x!=-1) {e=parseInt(a.substr(x+1)); a=a.substr(0,x)}
  if (e>=20) if (s=="") return "e+"; else return "e-"
  if (e<=-20) return "0"
  p=a.indexOf("."); if (p==-1) p=a.length; else a=a.substr(0,p)+a.substr(p+1); p+=e
  a=u_str("0",20)+a+u_str("0",20); p+=20
  x=p+n; c=a.charAt(x); a=a.substr(0,x); if (parseInt(c)>=5) do {
    x-=1; y=parseInt(a.charAt(x)); y+=1
    if (y<=9) {a=a.substr(0,x)+y.toString()+a.substr(x+1); break}
    a=a.substr(0,x)+"0"+a.substr(x+1)} while (true)
  a=a.substr(0,p)+"."+a.substr(p); x=a.length
  do {x-=1; if (a.charAt(x)=="0") a=a.substr(0,x); else break} while (true)
  do {if (a.charAt(0)=="0") a=a.substr(1); else break} while (true) 
  x=a.length-1; if (a==".") return "0"
  if (a.charAt(x)==".") a=a.substr(0,x); if (a.charAt(0)==".") a="0"+a
  a=s+a; return a
}
function m_div(x,y) {return Math.floor(x/y)}
function m_lint(x1,y1,x2,y2) {
  if (y1==0 && y2==0) return (x1+x2)/2
  if (y2*y1>0) y2=-y2; return (x1*y2-x2*y1)/(y2-y1)
}
function m_diff(x) {
  var i=m_a(x/2e6)+1e-6, x1=x-i, x2=x+i; return (m_eval(x2)-m_eval(x1))/(x2-x1) 
}
function m_eval(x,y) {
  var t=0; t=eval(mf); if (t==Infinity) t=1e100; if (t==-Infinity) t=-1e100; return t
}
//  if (isNaN(t)) if (x<0) t=-987654321; else t=987654321; return t}
function m_a(x,y) {if (isNaN(y)) return Math.abs(x); if (y==0) return Math.round(x) 
    return m_b(x)%m_b(y)}
function m_b(x) {var t=1e8; return Math.round(x*t)/t}
function m_newt(x1,y1,v1,x2,y2,v2) {
  var x=0,y=0,v=0,p=0
  if (m_a(v1)>m_a(v2)) p=1; else p=2
  if (y1*v1>0) {p=2; if (y2*v2<0) p=0}
  if (p==0) return m_lint(x1,y1,x2,y2)
  if (p==1) {x=x1; y=y1; v=v1} else {x=x2; y=y2; v=v2}
  x=(v*x-y)/v; if (x<x1 || x>x2) {p=0; return m_lint(x1,y1,x2,y2)} else return x
}
function m_h(p,q) {
  var x=0,y=0,z=0
//  if (isNaN(q)) return Math.round(m_a(p))
  if (!isNaN(q)) {if (q==0) return Math.floor(p)
    p=Math.round(m_a(p)); q=Math.round(m_a(q))
    x=Math.max(p,q); if (x==0) return 0
    y=Math.min(p,q); if (y==1) return 1
//    y=Math.min(p,q); if (y<=1) return p
    if (y>1) {do {z=x%y; x=y; y=z} while (z>0); return x} }
  else {x=Math.round(m_a(p))
    t=1; for (y=2; y<=Math.floor(Math.sqrt(x)); y++) {z=x%y; if (z==0) {t=x/y; break}} return t}
}
function m_hs(a) {
  var i=0,p=0,q=NaN,z=u_c(a,"|")+1
  for (i=1; i<=z; i++) {p=u_j(a,i); if (p!=0) q=m_h(p,q)}
  if (isNaN(q)) return 1; return q
}
function m_l(p,q) {if (!isNaN(q)) return Math.log(q)/Math.log(p); return "XXX"}
function m_u(p,q,r) {
  var i=0,x=0,y=0,c="",d="",e="",f=false 
  if (isNaN(q)) {if (p>0) return 0; if (p==0) return 1; return p}
  d=p.toString(); x=d.length
  if (isNaN(r)) {if (x<q) return 0; d=d.charAt(x-q); return u_pI(d)}
  e=q.toString(); y=e.length; if (x<r || y<r) return NaN; d=d.charAt(x-r); e=e.charAt(y-r)
  if (e!="1" && e!="2") return NaN; x=u_pI(d); if (e=="1") return x; return -x
/*
  if (q<0) {f=true; q=-q} d=p.toString(); x=d.length; if (x<q) return 0
  d=d.charAt(x-q); if (!f) return u_pI(d)
  if (d=="2") return -1; if (d=="1") return 1
  return NaN
*/
}

function m_hyp(n,x) {
  if (n==12) return Math.log(x+Math.sqrt(x*x+1))
  if (n==13) return Math.log(x+Math.sqrt(x*x-1))
  if (n==14) return Math.log((1+x)/(1-x))/2
  if (n==15) return (Math.exp(x)-Math.exp(-x))/2
  if (n==16) return (Math.exp(x)+Math.exp(-x))/2
  if (n==17) return m_hyp(15,x)/m_hyp(16,x)
}
function m_ft(a,f) {
  var x=0,y=0,z=0,b=0,c="",d="",g="",f=false
  x=a.indexOf("tt"); if (x>0) return false; if (x==-1) return a
  x=a.indexOf("="); if (x!=2) return false
  x=m_bt(a,1,";"); if (x==-1) return false; d=a.substr(3,x-3); a=a.substr(x+1)
  x=d.length-1; if (m_bt(d,2)) {e=d.substr(1,x-1); f=true} else e="("+d+")"
  e=u_sub(e,";","?"); a=u_sub(a,"tt",e)
  x=0; do {b=1; y=a.indexOf("m_",x); x=y+1; if (y==-1) break; z=x+3
   do {z++; c=a.charAt(z); b=m_br(b,c); if (b==0) break
       if (b==1 && c=="?") a=u_x(a,z,",") }
     while (true)} while (true); a=u_sub(a,"?","*")      
  if (f || !isNaN(d)) return a; g=m_syn(d,f); return a+"|_"+g
}
function m_br(b,c) {if (c=="(") b++; if (c==")") b--; return b}
function m_bt(a,z,c) {
  var x=0,y=0,e="",b=0,f=false,t=true
  if (z==1) do {if (x==a.length) return -1; e=a.charAt(x); b=m_br(b,e)
    if (e==c && b==0) return x; x++} while (t)
  if (z==2) {x=a.length; if (a.charAt(0)!="(" || a.charAt(x-1)!=")") return f
    b=1; do {y++; if (y==x-1) return t; b=m_br(b,a.charAt(y)); if (b==0) return f} while (t) }
} 
function m_mh(a) {
  var x=0,y=0,z=0,b=0,c="",f=false
  do {x=a.indexOf("m_h(",x); if (x==-1) break; y=x+4; x++; b=1; f=false
   do {c=a.charAt(y); if (c=="," && b==1) {f=true; break}
     b=m_br(b,c); if (b==0) break; y++} while (true); if (!f) continue
   f=false; z=y+1; do {c=a.charAt(z); if (c=="," && b==1) {f=true; break}
     b=m_br(b,c); if (b==0) break; z++} while (true); if (!f) continue
   do {c=a.charAt(z); b=m_br(b,c); if (b==0 || z==a.length-1) break; z++} while (true)    
   a=a.substr(0,y+1)+"m_h("+a.substr(y+1,z-y)+")"+a.substr(z+1)
  } while (true); return a
}
function m_cy(a,y,f) {
  var x=0,z=0,d="",e="",b=0,c="",g="",h="",i=0, j=0, t=0,u="",v="", n="0123456789"
  x=m_sc(a) // ; if (z>=0) return false
  u=a.charAt(y+1); if ("+-=;x/()".indexOf(u)==-1) return "E8" // y to be linear
  d=a.substr(0,x); e=a.substr(x+1); z=d.indexOf("y",y+1); if (z>=0) return "E9"  // 1 y only e1
  z=d.indexOf("="); if (z==-1) {d+="=0"; z=d.length-2}
  if (z<y) {d=d.substr(z+1)+"="+d.substr(0,z); z=d.indexOf("=")}
  do {y=d.indexOf("y"); v=m_brex(d,y); if (v!="") {i=u_pIc(v,1); j=u_pIc(v,2)
        v=d.substr(i+1,j-i-1); d=d.substr(0,i)+"y"+d.substr(j+1); y=d.indexOf("y")}

    x=y; b=0; do {x++; if (x==d.length) break; c=d.charAt(x); if (b==0 && u_iO("+-=",c)) break
      if (c=="(") b++; if (c==")") b--} while (true)
    if (d.charAt(x-1)!="y") {
      if (d.charAt(y+1)=="/") {d=d.substr(0,y+1)+"(1"+d.substr(y+1,x-y-1)+")"+d.substr(x); x+=3}
      d=d.substr(0,y)+d.substr(y+1,x-y-1)+"y"+d.substr(x); y=x-1}

    x=y; b=0; do {x--; c=""; if (x<0) break; c=d.charAt(x)
      if ((n+"x.)SUQ").indexOf(c)==-1 && b==0) break
      if (c=="(") b++; if (c==")") b--} while (true)
    if (x>=0 && "+-".indexOf(c)==-1) return "E8"

    u=d.charAt(y+1); z=d.indexOf("=")    

    if (x>0) h="-("+d.substr(0,x)+")"
    if (u=="+") u=""; t=z-y-2; if (t>0) g="-("+u+d.substr(y+2,t)+")"
    g="("+d.substr(z+1)+h+g+")"
    if (c=="+") c=""; t=y-x-1; if (t>0) g="("+g+"/("+c+m_ub(d.substr(x+1,t))+"))"
    if (t==0 && c=="-") g="("+g+"/(-1))"
    
    if (v!="") {d=v+"="+g; g=""; h=""} else break } while (true)
  do {y=e.indexOf("y"); if (y==-1) break; e=u_x(e,y,g)} while (true)
  return e+"|"+m_syn(g,f)
}
function m_dy(a) {
  return a
//  var b="",c="",d="",e="",x=0
//  x=u_pr(ma,2).length; if (x==0) x=4; if (x==1) x=2; x=Math.floor(x/2)
//  b="1"+u_str("0",x); c="5"+u_str("0",x-1); d="m_h((x-"+c+")/"+b+")"; e="m_a(x,"+b+")"
//  a=u_sub(a,"y",d); a=u_sub(a,"z",e); return a
}
function m_check() {
  var z=19,x=0,y=0,q=0,d="",e=this.name.substr(0,3), g="", j=0
  var a="|1#234#8#(i) 1.25^L(ii) 7/9:ap1,ep1,cp1,op1,wp1|2#235#7#(ii) p=4, q=11:ap1,ep1,cp1,op1,wp1|3#236#12#(i) 3x^2 - 10^L(ii) P:(-2,17) Q:(2,-7)^L(iii) y = -6x + 5:ap1,ep1,cp1,op1,wp1|4#237#15#(i) 3^L(ii) 4x - 1^L(iii) 18:ap1,ep1,cp1,op1,wp1|5#238#4#(i) (py - 2x)/(2y - px)^L(ii) p = 3, q = 1:ap3,ep3,cp3,op3,wp3|6#239#3#(i) k = 4; (2, -4)^L(ii) ^r60 ^= 7.746:ap3,ep3,cp3,op3,wp3|7#637#8#(i) dV/dt = -k^rV^L(ii) A = 8, k = ^h:ap3,ep3,cp3,op3,wp3|8#638#8#(ii) OAB ^= 60.9^d^L(iii) 4i + 2j + 3k:ap3,ep3,cp3,op3,wp3|9#345#6#(i) p = 2^Lb = 192^Lc = 240^L(ii) q = 4:ap2,ep2,cp2,op2,wp2|10#346#4#(i) a/(x + 2)^L(ii) 0 < f(x) < 2:ap2,ep2,cp2,op2,wp2|11#347#6#(i) 2p^L(ii) 2 - p^L(iii) q - 1^L(iv) 3p - 2q - ^h:ap2,ep2,cp2,op2,wp2|12#348#12#a = 30^Lb = 12^Lc = 4:ap2,ep2,cp2,op2,wp2|13#653#3#(i) x > -3^L(ii) -3 < x < 7:ap1,ep1,cp1,op1,wp1|14#654#6#-4x^-^1 - ^hx^-^3:ap1,ep1,cp1,op1,wp1|15#655#7#(i) k = 7^L(ii) p = 4, q = 1 OR p = 1.2, q = -4.6:ap1,ep1,cp1,op1,wp1|16#191#5#(ii) 60 s:am1,cm1,em1,om1,wm1|17#192#6#(i) F = 4^r13 ^= 14.4 N^L(ii) v = 31i + 11j^L(iii) t = 2:am1,cm1,em1,om1,wm1|18#193#4#(i) T ^= 11.3 N^L(ii) W ^= 15.2 N:am1,cm1,em1,om1,wm1|19#194#8#(i) 50 N^L(ii) 1.5 m:am1,cm1,em1,om1,wm1"
  a=m_code(a); j=0
  do {q=u_ran(1,z); g=q.toString(); j++; if (j>2000) mh=""
    if (mh.indexOf(g+";")>=0 || g==u_parse(mq,"#",1)) continue
    x=a.indexOf("|"+q+"#"); if (x==-1) continue
    y=a.indexOf("|",x+1); if (y!=-1) d=a.substr(x,y-x); else d=a.substr(x)
    if (d.indexOf(e)>=0) break} while (true)
    mh+=g+";"; return u_parse(d,":",1).substr(1)
}
function m_code(a) {
  var i=0,e="",g="",h=""
  var d="L|000d\u000a;r|221a;=|2248;p|03c0;h|00bd;>|2265;<|2264;e|2261;d|00b0;1|00b9;2|00b2;3|00b3;-|02c9"
  do {i++; e=u_parse(d,";",i); if (e=="") break; g="^"+u_r(e,0)
    h=String.fromCharCode(parseInt(e.substr(2),16)); a=u_sub(a,g,h)
} while (true)
  return a
}
function m_merge(a) {
  var n=0,i=0,j=0,x=0,y=0,c="",d="",e="",g="",s="+",f1=true
  n=m_terms(a,-1,1)
  for (i=1; i<=n; i++) {
    c=m_terms(a,i,1); s=c.charAt(0); d=m_split(c,3); x=m_split(c,0)
    f1=true; if (s=="-") x=0-x
    for (j=1; j<i; j++) if (m_split(m_terms(a,j,1),3)==d) f1=false
    if (!f1) continue
    for (j=i+1; j<=n; j++) {g=m_terms(a,j,1); s=g.charAt(0)
      if (m_split(g,3)==d) {y=m_split(g,0); if (s=="-") y=0-y; x+=y}}
// WIP   if (x<0) {s="-"; x=0-x} else s="+"; x_form(s
    if (x==0) continue; if (x>0) e+="+"; else {e+="-"; x=0-x}
    if (x!=1) e+=x.toString(); if (x!=1 && d!="") e+="%"; e+=d
// OK if term is just 1?
  } return e
}
function x_mergem(a) {
  var n=0,i=0,j=0,x=0,y=0,c="",d="",e="",g="",s="+",f1=true
  n=m_terms(a,-1,2)
  for (i=1; i<=n; i++) {
    c="+"+m_terms(a,i,2); d=m_split(c,1); x=m_split(c,0); p=m_split(c,2)
    f1=true
    for (j=1; j<i; j++) if (m_split("+"+m_terms(a,j,2),1)==d) f1=false
    if (!f1) continue
    for (j=i+1; j<=n; j++) {g="+"+m_terms(a,j,2)
      if (m_split(g,1)==d) {x=x*m_split(g,0); p=p+m_split(g,2)}}
    if (e!="") e+="*"; e+=x.toString()+"%"+d+"~"+p
  } return e
}

function m_sort(a) {
  var i=0,j=0,k=0,n=0,c="",d="",e=""
  n=m_terms(a,-1,1)
  for (i=i; i<=n; i++) for (j=1; j<n; j++) {c=m_terms(a,j,1); d=m_terms(a,j+1,1)
    if (m_split(d,2)>m_split(c,2))
      {e=""; for (k=1; k<j; k++) e+=m_terms(a,k,1)
      e+=d+c; for (k=j+2; k<=n; k++) e+=m_terms(a,k,1); a=e}}
  return a
}
function m_mult(a1,a2) {
  var i=0,j=0,m=0,n=0,p=0,q=0,s="+",t="",u="",c="",d="",e="" 
  m=m_terms(a1,-1,1); n=m_terms(a2,-1,1)
  for (i=1;i<=m;i++) for (j=1;j<=n;j++) {
    c=m_terms(a1,i,1); d=m_terms(a2,j,1); if (c.charAt(0)==d.charAt(0)) s="+"; else s="-"
    q=m_split(c,0)*m_split(d,0); p=m_split(c,2)+m_split(d,2) 
    t=m_split(c,1); u=m_split(d,1); if (t==u) p=m_split(c,2)+m_split(d,2)
      else if (t=="") t=u
      else if (t!="" && u!="") {p=1; t=m_split(c,3)+"*"+m_split(d,3)}
    e+=m_form(s,q,t,p)
  }
  return e
}
function m_form(s,q,t,p) {
  var e=""
  if (q==0) return ""
  if (p!=0) {e=t; if (p!=1) e+="~"+p.toString()} else return s+q.toString()
  if (q!=1) e=s+q.toString()+"%"+e; else e=s+e
  return e
}
function m_split(a,c,k) {
  var j=0,p=0,q=1,s="+",z=1,y=c.length
  s=a.charAt(0); if (s=="-") z=-1; a=a.substr(1); j=a.indexOf("%")
  if (j>0) {q=parseInt(a.substr(0,j)); a=a.substr(j+1); p=1}
    else if (a.substr(0,y)==c) {q=1; p=1} else {q=parseInt(a); a=""}
  if (k==3) return a
  j=a.indexOf("~"); if (j>0) {p=parseInt(a.substr(j+1)); a=a.substr(0,j)}
  if (k==-1) return s; if (k==0) return z*q; if (k==1) return a; if (k==2) return p
}
function m_terms(a,n,z) {
  var i=1,j=0,k=0,l=1,e="",f1=true
  if (n<0) {f1=false; n=1}
  for (i=1; i<=n; i++) {j=k+1; k=a.indexOf("+",j); l=a.indexOf("-",j)
    if (k==-1) k=l; else if (l!=-1) k=Math.min(k,l)
    if (z==2) {k=a.indexOf("*",j); if (j>1) j+=1}
    if (!f1) {n+=1; if (k==-1) return i}
    if (k==-1) if (i<n) return ""; else return a.substr(j-1); }
  return a.substr(j-1,k-j+1)
}    
function m_linfac(a) {
  var i=0, j=0, k=0, x=0, y=0, d="", e="", f=false, g="", n=0,z=0,p=0,q=0
  do {f=false; n=u_c(a,"|"); z=n+1; p=u_i(a,"|",1); q=m_a(u_i(a,"|",z)); if (g!="") g+="*"
    for (i=1; i<=p; i++) {if (p%i>0) continue 
      for (j=-q; j<=q; j++) {if (j==0) continue; if (q%m_a(j)>0) continue; e=a; d=""
        for (k=1; k<=n; k++) {x=m_div(u_i(e,"|",1),i); d+=x.toString(); if (k<n) d+="|"
          y=u_i(e,"|",2)-x*j; if (m_a(y)%i!=0) break
          if (k<n) e=y.toString()+e.substr(u_pos(e,"|",2))}
    if (y==0) f=true; if (f) break} if (f) break}
    if (f) {g+=i+"|"+j; if (d.indexOf("|")==-1) f=false; a=d; d=""} else g+=a
  } while (f); return g
}  
function m_polyfac(a,t) {
  var i=0,j=0,k=0,x=0,y=0,d="",e="",f=false,g="",h="",n=0,z=0,p=0,q=0,l=0,u=0,v=0,w=0
  do {f=false; n=u_c(a,"|"); p=u_i(a,"|",1); q=m_a(u_i(a,"|",n+1)); if (g!="") g+="*"
    if (m_a(n*p*q)>80000) return a; u=2*q+1
do {x=p*Math.pow(u,t-1)*q*(n-t+1)*(t-1); if (x<5000) break; u=Math.floor(u*4/5)} while (true)
    for (i=1; i<=p; i++) {if (p%i>0) continue 
      for (j=1; j<=t; j++) A[j]=-u; A[t]=-q
      do {e=a; d=""; y=n-t+1
        for (k=1; k<=y; k++) {w=u_i(e,"|",1); if (w%i!=0) break; x=m_div(w,i)
          d+=x.toString(); if (k<y) d+="|"; h=""; v=0
          for (l=1; l<=t; l++) {w=u_i(e,"|",l+1)-x*A[l]; h+=w.toString()+"|"; v+=m_a(w)}
          if (k<y) h+=e.substr(u_pos(e,"|",t+1)+1); e=h}
        if (v==0) {f=true; break}
        j=t-1; if (t>1) do {A[j]+=1; if (A[j]<u) break; A[j]=-u; j--} while (j>0)
        if (j==0) {A[t]++; if (A[t]>q) break; while (q%m_a(A[t])!=0) A[t]++}
        } while (true)
      if (f) break}
    if (f) {g+=i; for (j=1; j<=t; j++) g+="|"+A[j]; a=d; d=""} else g+=a
    if (u_c(a,"|")<=t) {g+="*"+a; f=false}
  } while (f); return g
}  
function m_unifac(a) {
  var t=0,x=0,g=""
  do {t++; x=u_c(a,"*"); if (x>0) {x=u_pos(a,"*",x); g+="*"+a.substr(0,x); a=a.substr(x+1)}
    x=u_c(a,"|"); if (2*t>x) break; else a=m_polyfac(a,t)} while (true)
  if (g=="") g=a; else g=g.substr(1)+"*"+a; return g
}
function m_poly(a,c,z) {
  var n=0,b="",e="",g="",q=0,p=-1,i=0
  if (z==1) {do {i++; b=m_terms(a,i,1); if (b=="") break
      n=m_split(b,c,2); if (p!=-1) g+=u_str("|",p-n); p=n; g+=m_split(b,c,0)} while (true)
    if (p>0) g+=u_str("|",p)+"0"
    do {n=g.length; g=u_insert(g,"||","|0|"); if (n==g.length) break} while (true)
    return g}    
  if (z==2) {n=u_c(a,"|"); if (n==0) return a
    do {i++; b=u_parse(a,"|",i); e=b.charAt(0); if (e=="0") {n--; continue}
      if (e=="-") {g+="-"; b=b.substr(1)} else g+="+"; if (b!="1" || n==0) g+=b; if (n>0) g+=c;
      if (n>1) g+="^"+n; n--} while (n>=0)
    if (g.charAt(0)=="+") g=g.substr(1); return g}     
}
function m_monofac(a) {
  var y=a.length,x=0,z=0,i=0,p=0,q=0,g=""
  z=u_c(a,"|")+1; if (z==1) return a
  do {y-=2; if (a.substr(y,2)!="|0") break; else x+=1} while (true)
  y+=2; a=a.substr(0,y); z-=x
  p=m_a(u_i(a,"|",1)); for (i=2; i<=z; i++) {q=m_a(u_i(a,"|",i)); if (q>0) p=m_h(p,q)}
  for (i=1; i<=z; i++) {q=u_i(a,"|",i)/p; g+=q.toString(); if (i<z) g+="|"}
  g=p+"_"+x+"*"+g; return g
}
function m_maxcof(a) {
  var z=u_c(a,"|")+1,i=0,x=0,y=0
  for (i=1; i<=z; i++) {y=m_a(u_i(a,"|",i)); if (y>x) x=y} return x
}
function m_simul(a,z) {
//  solves n linear equations in z unknowns
  var b="",d="",e="",g="",h="",i=0,j=0,k=0,n=0,p=0,q=0,v=0,x=0,w=1,y=-1,   t=0
  n=u_c(a,"*")+1
  for (i=1; i<=n; i++) {b=u_parse(a,"*",i); x=u_c(b,"|")+1
    for (j=1; j<=x; j++) {e=u_pr(b,j); g=m_rat(u_parse(b,"|",j))
      if (g=="X" || g=="O") return g}
    if (d!="") d+="*"; d+=b; x-=1; if (x<z) d+=u_str("|",z-x) }
  if (n<z) d+=u_str("*"+u_str("|",z),z-n)
 a=""; for (i=1; i<=n; i++) {e=m_eqn(u_ps(d,i)); a+="*"+u_pu(e,1); w=w*u_pI(u_pu(e,2))}
  a=a.substr(1)
// a=""; for (i=1; i<=n; i++) a+="*"+u_parse(d,"*",i); a=a.substr(1)
  if (n<z) n=z
/*
  a=""; for (i=1; i<=z; i++) {h=u_ps(d,i); for (j=1; j<=z+1; j++)
    {e=u_pr(h,j); if (e=="") e="0"; if (j==1) e="*"+e; if (j!=z+1) e+="|"; a+=e} } a=a.substr(1) 
// inserts zeroes for blanks - why is it necessary?
*/

// n equations (but now = z), z components
  d=""
  for (i=1; i<=z; i++) {
    j=0; do {j++; b=u_parse(a,"*",1)
    if (j>n-i+1) {v++; i++; n++; j=0; if (i<=z) continue; else break} 
    p=u_i(b,"|",z-i+2)
      x=a.indexOf("*"); if (p!=0) break; if ((n-i)%2==1) {y=-y; t++}
      if (x>=0) a=a.substr(x+1)+"*"+a.substr(0,x)}     while (true)
    if (p==0) break
    d+=b+"*"; g=""; if (x>=0) a=a.substr(x+1)
    for (j=1; j<=n-i; j++) {h=u_parse(a,"*",j); q=u_i(h,"|",z-i+2); x=m_h(p,q); w=w*p/x
      for (k=1; k<=z-i+1; k++) g+=(p*u_i(h,"|",k)-q*u_i(b,"|",k))/x+"|"
      g=u_trunc(g,1)+"*"}
    g=u_trunc(g,1); a=g // ; if (i==4) return d+"___"+a
    } g="123456789"; x=a.length
// d is triangle form, a any remaining eqs now reduced to zero unl C=contr.
// this.status="this is d,w "+d+"___"+w


  x=1; for (i=1; i<=z; i++) x=x*u_i(u_ps(d,i),"|",z-i+2)
  q=m_h(x,w); x=x/q; w=w/q; if (w<0) {w=-w; x=-x} if (z%4<=1) y=-y; w=(y*x)+"/"+w

// this.status="this is d,w "+d+"___"+w+"____"+t

  x=a.length; for (i=0; i<x; i++) if (g.indexOf(a.charAt(i))>=0) return "C" 
  if (v>0) return "V"+v; e=""
  for (i=1; i<=z; i++) {
    g=""; h=u_parse(d,"*",z-i+1); p=u_i(h,"|",1); q=u_i(h,"|",2)
    e+=m_sf(p+"|"+q)+"*"; if (i==z) break
    for (j=1; j<=z-i; j++) {h=u_parse(d,"*",j);       g+=q*u_i(h,"|",1)-p*u_i(h,"|",2)+"|"
      for (k=3; k<=z-i-j+3; k++) g+=q*u_i(h,"|",k)+"|"; g=u_trunc(g,1);       g+="*"}
    d=g}
  return u_trunc(e,1)+"_"+w
}
function m_divrat(x,y) {
  var p=0,q=0,r=0,s=0,t=0,a=""
  p=u_i(x,"/",1); q=u_i(x,"/",2); r=u_i(y,"/",1); s=u_i(y,"/",2)
  if (p==0) return 0; if (q==0 || r==0 || s==0) return NaN; if (q==NaN) q=1; if (s==NaN) s=1
  a=m_sf(p*s+"|"+q*r) //; a=u_sub(a,"|","/"); return a
  return
}
function m_sf(a) {
  var p=0,q=0,x=0
  p=u_i(a,"|",1); q=u_i(a,"|",2); if (p==0) return 0; if (p==NaN || q==NaN || q==0) return NaN
  x=m_h(p,q); if (x>1) {p=p/x; q=q/x} if (q<0) {q=-q; p=-p}
  a=p; if (q>1) a+="/"+q; return a
}
function m_algdiv(a) {
  var d="",e="",b="",c="",g="",h="",n=0,t=0,y=0,i=0,j=0,k=0,x=0,z=0
  d=u_parse(a,"*",1); e=u_parse(a,"*",2)
  n=u_c(d,"|"); t=u_c(d,"|"); y=n-t+1; c=u_parse(e,"|",1)
  for (i=1; i<=y; i++) {h=""; b=m_divrat(u_parse(a,"|",i),c); g+=b+"|"
    x=u_i(b,"/",1); z=u_i(b,"/",2)
    for (j=1; j<=t; j++) {k=j+1; h+=u_i(d,"|",k)-x*u_i(e,"|",k); if (!isNaN(z)) h+="/"+z
      h+="|"} h=u_trunc(h,1); x=u_pos(d,"|",t); if (x>0) h+=d.substr(x); d=h}
  g=u_trunc(g,1)+"*"+d; return g
}
function m_rop(x,y,v) {
  var p=0,q=0,r=0,s=0,c="|",a="",g=""
  p=u_i(x,c,1); q=u_i(x,c,2); if (isNaN(q)) q=1; r=u_i(y,c,1); s=u_i(y,c,2); if (isNaN(s)) s=1
  if (v=="+") g=m_sf(p*s+q*r+c+q*s); if (v=="-") g=m_sf(p*s-q*r+c+q*s) 
  if (v=="*") g=m_sf(p*r+c+q*s); if (v=="/") g=m_sf(p*s+c+q*r); return g
}

function m_rat(a) {
  var y=0, z=0, c=""
  if (a.charAt(0)=="-") a=a.substr(1); z=a.length
  y=u_c(a,"/"); if (y+u_c(a,".")>1) return "X"
  c=a.charAt(z-1); if (a.charAt(0)=="/" || c=="/" || c==".") return "X"
  if (y==1) if (u_i(u_parse(a,"/",2))==0) return "O"
  for (y=0; y<a.length; y++)
    if ("0123456789/.".indexOf(a.charAt(y))==-1) return "X"; return "A"
}
function m_eqn(a) {
  var i=0, j=0, z=0, x=0, y=0, t=0, b="", n="", d="",w=1
  z=u_c(a,"|")+1
  for (i=1; i<=z; i++) {b=u_parse(a,"|",i); x=b.indexOf(".")
    if (x==-1) continue; t=b.length-x-1; if (t>y) y=t}
  t=y; y=1; for (i=1; i<=t; i++) y=y*10; w=w*y   
  for (i=1; i<=z; i++) {n+=u_k(a,i)*y+"|"
    b=u_parse(a,"|",i); x=b.indexOf("/")
    if (x>=0) d+=b.substr(x+1); else d+="1"; d+="|"} // n=m_hdiv(u_trunc(n,1))
  for (i=1; i<=z; i++) {x=u_j(d,i); b=""; w=w*x
    if (x>1) {for (j=1; j<=z; j++) {y=x; if (j==i) y=1; b+=u_j(n,j)*y+"|"}
      n=u_trunc(b,1)} } // hdiv not nec., affects w? ; n=m_hdiv(n)} }
  return n+"_"+w
}
function m_hdiv(a) {
  // simplifies |-delimited string of integers by dividing by hcf  
  var x=0, i=0, z=0, b=""
  z=u_c(a,"|")+1; x=m_hs(a)
  if (x>1) {for (i=1; i<=z; i++) b+=u_j(a,i)/x+"|"; b=u_trunc(b,1)
    return b} return a
}
function m_nf(x) {
  // returns |-delimited string of factors of absolute x
  var i=0, j=0, a="", b="", n=0
  x=Math.abs(x); n=Math.floor(Math.sqrt(x))
  for (i=1; i<=n; i++) if (x%i==0) {j=x/i; a+=i+"|"; if (i!=j) b=j+"|"+b}      return u_trunc(a+b,1)
}
function m_pd(a,b) {
  // returns "quotient*rem" of one poly by another
  var x=0,y=0,z=0,i=0,j=0,q="",r=""
  x=u_c(b,"|"); z=u_c(a,"|")-x+1
  for (i=1; i<=z; i++)  {
    y=u_j(a,1)/u_j(b,1); q+=y+"|"
    for (j=1; j<=x; j++) r+=u_j(a,j+1)-y*u_j(b,j+1)+"|"
    for (j=1; j<=(z-i); j++) r+=u_j(a,x+j+1)+"|"
    a=u_trunc(r,1); r="" }
  return u_trunc(q,1)+"*"+a
}
function m_zc(a) {
  // checks if poly completely zero (true)
  var i=0, b="123456789", x=a.length
  for (i=0; i<x; i++) if (b.indexOf(a.charAt(i))>=0) return false
  return true
}   
function m_fs(a) {
  var x=u_c(a,"|"), b=m_nf(u_pr(a,1)), c=m_nf(u_pr(a,x+1))
  var y=u_c(b,"|")+1, z=u_c(c,"|")+1
  var i=0, j=0, g="", d="", r=""
  for (j=1; j<=z; j++) g+=(0-u_j(c,j))+"|"; c=g+"0|"+c; z=2*z+1; g=""
  for (i=1; i<=y; i++)
    for (j=1; j<=z; j++) {d=u_pr(b,i)+"|"+u_pr(c,j)
      g=m_pd(a,d); if (m_zc(u_ps(g,2))) return u_ps(g,1)+"*"+d}
  return "X"
}
function m_fc(a) {
  var b="", g=""
  do {b=m_fs(a); if (b=="X") break; g+=u_ps(b,2)+"*"; a=u_ps(b,1)
    if (u_c(a,"|")==1) break} while (true)
  g+=a; return g
}  
function m_ev(a) {
  var i=0, z=u_c(a,"|"), g=""
  for (i=1; i<=z; i++) g+=u_pr(a,i)+u_str("*x",z-i+1)+"+"; g+=u_pr(a,z+1)
  return "("+g+")"
}
function m_pf(a) {
  var b=false, f="", g="", d=m_fc(u_ps(a,2)), i=0, j=0, c=""
  f=m_ev(u_ps(a,1))+"@", h=""
  if (u_ps(d,2)==u_ps(d,3)) d=u_ps(d,3)+"*"+u_ps(d,1)+"*"+u_ps(d,2)
  if (u_ps(d,1)==u_ps(d,2)) b=true
  f+=m_ev(u_ps(d,2))+"*"+m_ev(u_ps(d,3))+"@"
  f+=m_ev(u_ps(d,3)); if (!b) f+="*"+m_ev(u_ps(d,1)); f+="@"
  f+=m_ev(u_ps(d,1))+"*"+m_ev(u_ps(d,2))
  for (i=4; i<=6; i++) {c="x="+i+";"
    for (j=1; j<=4; j++) h+=eval(c+u_pa(f,j))+"|"; h=u_trunc(h,1)+"*"}
  h=u_trunc(h,1); a=m_simul(h,3)
  if (b) d=u_ps(d,1)+"*"+"("+u_ps(d,2)+")2"+"*"+u_ps(d,3)
  for (i=1; i<=3; i++) g+=u_ps(a,i)+"/"+u_ps(d,i)+"@"; g=u_trunc(g,1)
  return g 
}
function m_n(c) {if ("0123456789".indexOf(c)>=0) return true; return false}
function m_p(c) {if ("0123456789".indexOf(c)>0) return true; return false}
function m_pm(a,x) {
  var p=0, q=0
  p=a.indexOf("+",x); q=a.indexOf("-",x); if (p+q==-2) return -1
  if (p==-1) return q; if (q==-1) return p; if (p<q) return p; return q
}
function m_dt(a) {
  var c=a.charAt(0), f="", g="", h="", z=0, i=0, j=0
  if (c=="|") {a=a.substr(1); x=u_j(u_pc(a,1),1); y=u_j(u_pc(a,2),1)
    if (y==1) return x; return "|"+(x*y)+","+(y-1)+"|"}
  if (c=="M") {f=u_pr(a,2); return m_dt(f)+"*"+m_dm(u_pr(a,1),f)}
  if (a.indexOf("*")>=0) {z=u_c(a,"*")+1
    for (i=1; i<=z; i++) {h=m_dt(u_ps(a,i)); if (h=="0") continue
      for (j=z; j>=1; j--) if (i!=j) h=u_ps(a,j)+"*"+h
        g+=h+"+"} return "("+u_trunc(g,1)+")"}
  if (a.indexOf("/")>=0) {g=u_pd(a,1); h=u_pd(a,2)
    return "("+h+"*"+m_dt(g)+"-"+g+"*"+m_dt(h)+")/"+h+"^2"}
  if (c=="f") return "fnd"+a.substr(3)
  return "0"
}
function m_dm(a,f) {
  var h="Math."
  a=a.substr(5)    
  if (a=="sin") return h+"cos|"+f
  if (a=="cos") return "-"+h+"sin|"+f
  if (a=="tan") return "1/("+h+".cos|"+f+")^2"
}
function m_xt(a,b) {
  var x=m_pt(a,1)*m_pt(b,1), y=m_pt(a,2)+m_pt(b,2); return m_ot(x,y)
}
function m_at(a,b) {
  var x=m_pt(a,1)+m_pt(b,1), y=m_pt(a,2); return m_ot(x,y)
}
function m_ot(x,y) {if (y==0) return x.toString(); return "|"+x+","+y+"|"}
function m_pt(a,n) {
  var c=","; if (a.charAt(0)=="|") a=a.substr(1,a.length-2)
  if (n==1) return u_i(a,c,1); return u_i(a,c,2)
}
function m_xp(a,b) {
  var i=0, j=0, p=u_c(a,"+")+1, q=u_c(b,"+")+1, g=""
  for (i=1; i<=p; i++) for (j=1; j<=q; j++)
    g+=m_xt(u_pz(a,i),u_pz(b,j))+"+"; return u_trunc(g,1)
}
function m_sp(a) {
  var z=u_c(a,"+")+1, i=0, j=0, k=0, x=0, g=""
  for (i=1; i<=z; i++)
    for (j=1; j<=z-1; j++)
      if (m_pt(u_pz(a,j),2)<m_pt(u_pz(a,j+1),2))
        {g=""; for (k=1; k<=z; k++) {x=k; if (k==j) x=j+1; if (k==j+1) x=j
          g+=u_pz(a,x)+"+"} a=u_trunc(g,1)}
  return a
}
function m_mp(a) {
  var z=u_c(a,"+")+1, i=1, j=0, g=""
  do {if (i==z) break; g=u_pz(a,i); h=u_pz(a,i+1); if (m_pt(g,2)==m_pt(h,2))
    {h=m_at(g,h); g=""; for (j=1; j<=z; j++) if (j!=i) g+=u_pz(a,j)+"+"
      else {g+=h+"+"; j++} a=u_trunc(g,1); z-- } else i++} while (true)
  return a
}
function m_fm(a) {
  var z=u_c(a,"|")+1, i=0, j=0, n=1, x=0, q=2, t=1, u=1
  var b="",d="",e="",g="",h=""
  for (i=1; i<=z; i++) {x=m_a(u_pr(a,i)); if (x>n) n=x} n++
  b=m_nf(u_pr(a,1)); d=m_nf(u_pr(a,z))
  x=u_c(d,"|")+1; for (i=0; i<x; i++) e+="-"+u_pr(d,x-i)+"|"; e+="0|"; d=e+d
  do {if (2*(q-1)>z-1) return "XXX"
    u=1; g=u_pr(b,1)+"|"+u_str("-"+n+"|",q-2)+u_pr(d,1)
    do {h=m_pd(a,g); if (m_zc(u_ps(h,2))) return g+"_"+u_ps(h,1)
      t++; e=u_pr(b,t); if (e!="") {g=u_sb(g,e,1); continue}
      t=1; g=u_sb(g,u_pr(b,1),1); i=1
      do {i++; if (i<q) {x=u_j(g,i); x++; if (x<=n) {g=u_sb(g,x,i); break}
         g=u_sb(g,-n,i)} 
             if (i==q) {u++; e=u_pr(d,u); if (e=="") e="XXX"
         g=u_pr(b,1)+"|"+u_str("-"+n+"|",q-2)+e; break}
      } while (true); if (e=="XXX") break 
    } while (true)
//  return "WWWW"
  q++} while (true)
}
function m_pc(a) {
  var x=0,y=0,z=0,n=0,c="", e="", g="",q=0,p=0
  y=m_pm(a,0); if (y==0) c=a.charAt(0); else {c="+"; x==0}
  do {y=m_pm(a,x); if (y==-1) e=a.substr(x); else e=a.substr(x,y-x)
    if (e.charAt(0)!="|") {q=u_j(e,1); p=0} else {e=e.substr(1,e.length-2)
      q=u_i(e,",",1); p=u_i(e,",",2)} if (c=="-") q=-q
    if (p>z) {g=q+u_str("|",p-z)+g; z=p}
      else {n=z+1-p; q+=u_j(g,n); g=u_sb(g,q,n)}
    if (y>=0) {c=a.charAt(y); x=y+1} else break} while (true)
  return g
}
function m_bk(a) {
  var x=0, y=0, z=0, g="", h="", c="", i=0, j=0, f=true, u=""
  do {x=a.indexOf("Math.pow"); if (x==-1) break; y=x
    do {y++; c=a.charAt(y); if (c=="(") i++; if (c==")") {i--
      if (i==0) break} } while (true); a=a.substr(0,y)+"]"+a.substr(y+1)
    a=a.substr(0,x)+"P["+a.substr(x+9)} while (true)

  a=u_sub(a,"Math.pow","P")  // ???
  g="fny1="; x=1
  for (i=0; i<a.length; i++) {c=a.charAt(i)
    if (u_ct(c,"(M")) {x++
      u_stack(g+u+"fny"+x); g="fny"+x+"="
      u=""; if (c=="(") continue; u="|"}
    if (c==")") {h+=g+";"; g=u_stack("")
      if (u_pos(g,"M",1)>=0) {h+=g+";"; g=u_stack("")} continue}
    g+=c}
  h+=g

  a=h
  do {
  y=u_c(a,";")+1; f=false
  for (i=1; i<=y-1; i++) {g=u_pn(a,i); for (j=i+1; j<=y; j++) {h=u_pn(a,j)
    if (u_pe(g,2)==u_pe(h,2)) {z=h.length; h=u_pe(h,1); x=u_pos(a,";",j-1)
    a=a.substr(0,x)+a.substr(x+z+1); a=u_sub(a,h,u_pe(g,1)); f=true; break}}
    if (f) break}
  } while (f)
return a
}
function m_lu(a,b) {
  var z=u_c(a,";")+1, i=0, d="", g=""
  for (i=1; i<=z; i++) {d=u_pn(a,i); if (u_pe(d,1)==b) g=u_pe(d,2)} return g
}
function m_mo(a,b) {
  var z=u_c(b,"+")+1, i=0, g=""
  for (i=1; i<=z; i++) {d=u_pz(b,i); e=u_ps(d,2)
    if (e=="") {g+=d+"+"; continue} d=u_ps(d,1)
    if (d.charAt(0)=="f") d=m_lu(a,d); if (e.charAt(0)=="f") e=m_lu(a,e)
    g+=m_xp(d,e)+"+"}
  g=u_trunc(g,1); return g
}
function m_xn(a) {
  var z=u_c(a,";")+1, n=0,i=0,x=0
  for (i=1; i<=z; i++) {x=parseInt(u_pn(a,i).substr(3)); if (x>n) n=x}
  n++; return "fny"+n
}
function m_du(a,b) {
  var x=0, d="", g="", c="", p="/", h=""
  x=b.indexOf("/"); if (x==-1) return b
  d=b.substr(0,x); b=b.substr(x+1)
  do {c=u_xc(b,"*_/"); x=parseInt(c.substr(1)); c=c.charAt(0)
    if (c!="") {h=b.substr(0,x); b=b.substr(x+1)} else h=b
    if (p=="/") g+=h+"*"; else d+="*"+h; if (c=="") break; p=c} while (true)

  g=u_trunc(g,1); if (g.indexOf("*")<0) return d+"/"+g
  h=m_xn(a); a+=";"+h+"="+g; return a+"_"+d+"/"+h
}
function m_disc(a) {
  var x=0, y=0, b=0, c=""
  if (a.indexOf("H")>=0) return true
  do {y=a.indexOf("A",x); x++; if (y==-1) return false; y++
    do {y++; c=a.charAt(y); if (c=="(") b++; if (c==")") b--; if (b==0) break
      if (c==";" && b==1) return true} while (y<a.length) } while (true)
}
function m_dz(y) {if (m_a(y)<1e-10) return 0; else return 1}
function m_sep(a) {
  var e="+-±", c=a.charAt(0), g="", b="", x=0, i=0
  if (e.indexOf(c)==-1) g="+"; a=g+a; g=a.charAt(0); x=a.length
  for (i=1; i<x; i++) {c=a.charAt(i); if (e.indexOf(c)>=0 && b!=",") g+="|"; g+=c; b=c}
  return g
}
function m_pch(v,w) {
  var i=0,j=0,k=0,x=0,y=0,z=0,t=0,p=0, d="",e="",h=""
  v=m_sep(v); w=m_sep(w); x=u_c(v,"|")+1; y=u_c(w,"|")+1
  for (i=1; i<=x; i++) {t=0; d=u_pr(v,i)
    for (j=1; j<=y; j++) {e=u_pr(w,j); z=u_c(e,",")+1
      for (k=1; k<=z; k++) {h=u_pc(e,k); if (d==h) {t=1; w=u_sub(w,e,"")} }
    } p+=t }
  if (x==y && x==p) return 2
  if (x==y && x==p+1) return 1
  return 0
}
function m_mk(v,w,u) {
  var h="", d="", e="", i=0, x=0, z=0, t=0; if (v.charAt(0)=="+") v=v.substr(1)
  h=u; u=u_pn(u,1); w=m_char(w); x=w.indexOf("="); if (x>0) d=w.substr(x+1)+"="+w.substr(0,x)  
  if (!u_iO(u,"C")) {x=v.indexOf("="); if (x>=0) v=v.substr(x+1)
    x=w.indexOf("="); if (x>=0) w=w.substr(x+1)}
  if (v==w) return 2; if (!isNaN(v) && !isNaN(w) && u_pF(v)==u_pF(w)) return 2 
  if (d!="" && v==d) return 2
  // new N code to strip units from numbers? - R can do this (pound symbols?)
  if (u_iO(u,"I")) if (m_ide(v,w)) return 2
  if (u_iO(u,"R")) {v=u_pF(v); w=u_pF(w); if (isNaN(w+v)) return 0
    if (Math.abs(v-w)<1e-8) return 2 // ??
    if (w==0) return 0; if (Math.abs((v-w)/w)<=0.005) t=1}
  if (u_iO(u,"F")) if (m_ide(v,w)) t=1
//  if (u_iO(u,"P")) return m_pch(v,w)
  if (w.length*3<v.length) return 0; if (!isNaN(v)) v=v.toString()
  d=u_pn(h,2); z=u_c(d,",")+1
  if (d!="") for (i=1; i<=z; i++) {e=u_pc(d,i); if (v==m_char(e)) return 2}
  d=u_pn(h,3); z=u_c(d,",")+1
  if (d!="") for (i=1; i<=z; i++) {e=u_pc(d,i); if (u_iO(v,m_char(e))) return 1}
  return t
}
function m_ide(v,w) {
  var x=Math.PI+Math.sqrt(20),y=Math.PI+Math.E,z=x+y,u=0,i=0,f=true
  a="xyzmptnq"; for (i=0; i<a.length; i++) if (u_iO(w,a.charAt(i))) f=false
  for (i=0; i<=6; i++) v=u_sub(v,"mptinqj".charAt(i),"xxxxyyy".charAt(i))
  v=u_sub(v,"²","^2"); v=u_sub(v,"³","^3"); v=u_sub(v,"\u2212","-")
  v="("+u_pr(m_syn(v,true),1)+")"
  for (i=0; i<=6; i++) w=u_sub(w,"mptinqj".charAt(i),"xxxxyyy".charAt(i))
  w=u_sub(w,"²","^2"); w=u_sub(w,"³","^3"); w=u_sub(w,"\u2212","-")
  w="("+u_pr(m_syn(w,true),1)+")"
  if (!f && Math.abs(v.length-w.length)>1) return false
  try {u=eval(v+"-"+w)} catch(e) {return false}
  u=Math.abs(u); if (u<1e-8) return true; if (f && u<1e-3) return true; return false
}
function m_char(a) {a=u_sub(a,"~",","); a=u_sub(a,"-","\u2212"); return a}
function m_imp(a,z) {
  var x=0,y=0,i=0,j=0,k=0,b="",c="",d="",e="1e10",f=false,g="",h="",p=0,q=0

  if (isNaN(z)) {d=u_po(a,1); b=u_po(a,2); h=u_po(a,3)
    if (b!="") {p=eval(u_pc(b,1)); q=eval(u_pc(b,2))} // ; if (d!="-") d=m_imp(d+","+(-p),11)}
    a=d+":"+h
    do {a=m_imp(a,0); d=u_po(a,1); e=u_po(a,2); if (b=="") break
      if (e!=h) {e=m_imp(d+"|"+e+","+b,10); a=m_imp(e,5); d=u_po(a,1); e=u_po(a,2)} x=eval(d)
//    d=m_imp(d+","+p,11); if (x<=(q-p)) break; h=e} while (true)
    if (b=="" || (x>=p && x<=q)) break; h=e} while (true)

    return d+":"+b+":"+e }

  if (z==0) {d=u_po(a,1); e=u_po(a,2); if (d=="-") return "0:"+e; if (d=="0") return "1:"+e
    if (d.charAt(0)=="-") {c="-"; d=d.substr(1)}
    if (!u_iO(d,"/")) { 
      if (m_imp(d,4)) {e+=c+"2"+d.substr(1)+"|"+c+"11"+d.substr(2)+"|"; return m_imp(e,5)}
      x=u_pI(d); y=m_imp(d,3); g=(x+y).toString()
      if (m_imp(g,4)) if (x==y*9) return c+g+":"+e
         else {g=(x+2*y).toString(); return m_imp(e+c+g+"|",5)}
      if (m_imp(g,2)<m_imp(d,2)) g=(x+2*y).toString(); return c+g+":"+e}

    else {x=u_pI(u_pd(d,1)); y=u_pI(u_pd(d,2)); f=m_imp(u_pd(d,2),6)
      do {x++; g=x.toString(); if (m_imp(g,4)) break; if (m_h(x,y)==1) break} while (true)
      if (!m_imp(g,4)) return c+g+"/"+y.toString()+":"+e

      g="1"+g.substr(2)

      if (!f) {do {y++; h=y.toString(); if (m_imp(h,4)) break
        if (!m_imp(h,6)) {f=true; break} } while (true); if (f) return c+m_imp(g+"/"+h,9)+":"+e;
        e+=c+g+"/"+(y+1).toString()+"|"+c+g+"0"+"/"+m_imp("1"+h.substr(2),8)+"|"
          return m_imp(e,5) }

      else {h=y.toString(); f=m_imp(h,4)
        if (!f) {h=m_imp(h,7); if (g!="1") g=m_imp(g,8); return c+g+"/"+h+":"+e}
        else {e+=c+m_imp(g+"/"+m_imp(h,7),9)+"|"+c+g+"1/"+m_imp("1"+h.substr(2),7)+"|"
        return m_imp(e,5)} }
    }
  }

  if (z==1) {j=u_c(a,"|"); x=1e10; for (i=1; i<=j; i++) {d=u_pr(a,i)
    y=m_imp(d,2); if (y==x && m_a(eval(d))<m_a(eval(e))) {e=d; k=i} if (y<x) {x=y; e=d; k=i} } 
    return k}
  if (z==2) {x=a.length; y=x
    if (u_iO(a,"/")) {x-=0.7; if (u_iO(a,"-")) x-=0.4
      d=u_pd(a,2); y=d.length; if (m_imp(d,6)) x-=y*0.2}
    else do {y--; if (y<0) break; c=a.charAt(y); if (c!="0") break; x=x-0.6} while (true)
    return x; if (m_imp(a,4)) x-=0.4; return x}
  if (z==3) {x=a.length; y=x
    do {y--; if (y<0) break; c=a.charAt(y); if (c!="0") break; d+="0"} while (true)
    d="1"+d; return parseInt(d)}
  if (z==4) {if (a.charAt(0)=="-") a=a.substr(1); x=a.length
    if (a.charAt(0)!="1") return false
    x--; if (x<=0) return false; if (a.substr(1)==u_str("0",x)) return true; return false} 
  if (z==5) {x=m_imp(a,1); d=u_pr(a,x); j=u_c(a,"|")
    for (i=1; i<=j; i++) if (u_pr(a,i)==d) a=u_seg(a,"|",i,"")
    a=u_sub(a,"||","|"); if (a.charAt(0)=="|") a=a.substr(1); return d+":"+a}
  if (z==6) {x=u_pI(a); do {if (x%2>0) break; x=x/2} while (true); if (x==1) return true
      do {if (x%5>0) break; x=x/5} while (true); if (x==1) return true; return false}
  if (z==7) {x=u_pI(a); do {x++; a=x.toString(); if (m_imp(a,6)) return a} while (true)}
  if (z==8) {x=u_pI(a); do {x++; a=x.toString(); if (!m_imp(a,6)) return a} while (true)}
  if (z==9) {do {x=u_pI(u_pd(a,1)); y=u_pI(u_pd(a,2))
    if (m_h(x,y)==1) return a; x++; a=x.toString()+"/"+y.toString()} while (true) }
  if (z==10) {e=u_pc(a,1); p=u_pF(u_pc(a,2)); q=u_pF(u_pc(a,3)); j=u_c(e,"|")
//    q=q-p; p=0
    g=""; for (i=1; i<=j; i++) {d=u_pr(a,i); x=eval(d)
    if (p>=0 && x<0) continue; if (q<=0 && x>0) continue
    if (!u_iO(d,"/")) {if (q>0 && x>q) continue; if (p<0 && x<p) continue}
    else {if (q>0 && x>10*q) continue; if (p<0 && x<10*p) continue}
    g+=d+"|"} return g }
   if (z==11) {d=u_pc(a,1); p=u_pI(u_pc(a,2))
   if (!u_iO(d,"/")) d=u_pI(d)+p; else {e=u_pd(d,2); d=u_pd(d,1); d=(p*u_pI(e)+u_pI(d))+"/"+e}
   return d}
}
function m_arg(a,x) {
  var b=0,c="",d="=+-/();,ahsctleM",e="-SC",i=x-1, f=false
  do {i++; c=a.charAt(i); if (i==a.length) break
    if (c=="t" && a.charAt(i+1)=="t") {f=true; i++; continue} 
    if (b==0 && f && u_iO(d,c)) break; if (c=="(") b++; if (c==")") b--
      if (!u_iO(e,c)) f=true; if (c=="_") {i++; f=false} } while (true)
  return i
}
function m_comp(a,n) {
  var j=-1,i=0,k=0,l=0,c="",z=a.length,d="",e="",f=false,b=0,x=0,y=0,p=0,q=0,v=u_ch(39)
  if (n==0) {a=u_sub(a,"Math.PI","(4*Math.atan(1))") // ; a=u_sub(a,"Math.sqrt","Math.sQr")
    do {p++; j=a.indexOf(")"); l=j+1; if (j==-1) return m_comp(a,7)
      i=u_pI(u_pr(m_track(a,"(",j,-1),1)); i++; k=i-10; if (k<0) k=0; c=a.charAt(i-2)
      e=a.substr(k); x=e.indexOf("Math")
      if ((x==0 || x==1) && c!="(") {i=k+x; k=i; j++} else k=i-1
// if (a.substr(k,4)=="Math") i=k; i++
    a=a.substr(0,k)+m_comp(a.substr(i,j-i),2)+a.substr(l)} while (true) }


  if (n==1) {do {j++; if (j==a.length) break; c=a.charAt(j)
    if (u_iO("* /",c)) {d=m_track(a,"+-,(",j,-1); e=m_track(a,"+-* /,)",j,1); x=u_pI(u_pr(d,1))+1
      y=u_pI(u_pr(e,1)); d=u_pr(d,2); e=u_pr(e,2); if (true) // if (d!="(" || e!=")") 
        {a=a.substr(0,x)+"("+a.substr(x,y-x)+")"+a.substr(y); j++} } } while (true)
//          {a=a.substr(0,x)+m_comp(a.substr(x,y-x),2)+a.substr(y); j++} } } while (true)

      j=-1; do {j++; if (j==a.length) return u_sub(a,"(-","(0-"); c=a.charAt(j)
        if (u_iO("+-",c)) {d=m_track(a,",(",j,-1); e=m_track(a,"+-,)",j,1); x=u_pI(u_pr(d,1))+1
          y=u_pI(u_pr(e,1)); d=u_pr(d,2); e=u_pr(e,2); if (true) // (d!="(" || e!=")") 
        {a=a.substr(0,x)+"("+a.substr(x,y-x)+")"+a.substr(y); j++} } } while (true) }
//            {a=a.substr(0,x)+m_comp(a.substr(x,y-x),2)+a.substr(y); j++} } } while (true) }

  if (n==2) {// if (a.charAt(0)=="a") a="M"+a+")"; a=u_sub(a,"Math.sQr","Math.sqrt")
//    a=u_sub(a,"Math.at1()","Math.atan(1)")
    if (!u_iO(a,"|")) {x=eval(a); if (!isNaN(x)) return m_comp(x,10)}
    if (u_iO(a,"Math")) return m_comp(a,4); c=m_comp(a,3); if (c=="") return a
    x=u_pI(u_pr(c,1)); c=u_pr(c,2); d=m_comp(a.substr(0,x),6); e=m_comp(a.substr(x+1),6)
    if (!u_iO(d,"|")) d="|"+d+"|0"; if (!u_iO(e,"|")) e="|"+e+"|0"

    x=u_pF(u_pr(d,2)); y=u_pF(u_pr(d,3)); p=u_pF(u_pr(e,2)); q=u_pF(u_pr(e,3))
/*
    if (c=="+") return "|"+(x+p)+"|"+(y+q); if (c=="-") return "|"+(x-p)+"|"+(y-q)
    if (c=="*") return "|"+(x*p-y*q)+"|"+(x*q+y*p)
    if (c=="/") {z=p*p+q*q; return "|"+((x*p+y*q)/z)+"|"+((y*p-x*q)/z)} }
*/
    if (c=="+") {x+=p; y+=q} if (c=="-") {x-=p; y-=q} if (c=="*") {z=x*p-y*q; y=x*q+y*p; x=z}
    if (c=="/") {z=(x*p+y*q); y=(y*p-x*q); x=z; z=p*p+q*q; x=x/z; y=y/z }
    x=m_comp(x,10); y=m_comp(y,10); return "|"+x+"|"+y
 }

  if (n==3) do {j++; c=a.charAt(j); if (c=="") return c
    if ((j==0 && c=="-") || c=="|") {j++; continue}
    if (u_iO("+-* /",c)) return j+"|"+c} while (true)

  if (n==4) {if (u_iO(a,"sqrt")) {a=u_sub(a,"sqrt","pow"); a=u_trunc(a,1)+",0.5)"}
    e=a.substr(5,3); a=u_trunc(a.substr(9),1)
    if (e=="pow") {d=u_pc(a,1); p=u_pF(u_pc(a,2)); if (!u_iO(d,"|")) d="|"+d+"|0" // not whole ix
      x=u_pF(u_pr(d,2)); y=u_pF(u_pr(d,3)); z=Math.pow(x*x+y*y,p/2); q=Math.atan2(y,x)
      return "|"+m_comp(z*Math.cos(p*q),10)+"|"+m_comp(z*Math.sin(p*q),10)}
    if (e=="exp") {x=u_pF(u_pr(a,2)); y=u_pF(u_pr(a,3)); z=Math.exp(x)
      return "|"+m_comp(z*Math.cos(y),10)+"|"+m_comp(z*Math.sin(y),10)} }
/*
  if (n==5) do {j=a.indexOf("t"); if (j==-1) return a; j--; f=(a.charAt(j)=="*")
    if (!f) a=a.substr(0,j+1)+"|0|1"+a.substr(j+2)
    if (f) {d=m_track(a,"+-* /()",j,-1); x=u_pI(u_pr(d,1))+1
            a=a.substr(0,x)+"|0|"+a.substr(x,j-x)+"|"+a.substr(j+2)} } while (true)
*/
  if (n==5) {a=u_sub(a,"j","|0|1"); a=u_sub(a,"z","|x|y"); return a}
  if (n==6) {if (a=="") return "|0|0"; if (!u_iO(a,"|")) return "|"+a+"|0"; return a}    
  if (n==7) {x=u_pF(u_pr(a,2)); y=u_pF(u_pr(a,3)); return x*x+y*y}
//  if (n==9) {d="|tt|=|sqrt|"; if (u_iO(a,"z") || u_iO(a,d+";") || u_iO(a,d+"-|1|;")
//        || u_iO(a,d+"(|-|1|)|;") || u_iO(a,"j")) return true; return false}
  if (n==9) {a=u_sub(a,"lgz","lgZ"); if (u_iO(a,"z") || u_iO(a,"j")) return true
             x=a.indexOf("sqrt|(|-|1|)"); if (x>0 && a.charAt(x-2)!="C") return true; return false}
  if (n==10) {if (m_a(a)<1e-6) return 0; return a}
}
function m_track(a,e,n,z) {
  var b=0,j=n,c="",x=a.length
  if (z==-1) do {j--; if (j<0) return "-1|"; c=a.charAt(j); if (b==0 & u_iO(e,c)) return j+"|"+c
    if (c==")") b++; if (c=="(") b--} while (true)
  if (z==1) do {j++; if (j==x) return x+"|"; c=a.charAt(j); if (b==0 & u_iO(e,c)) return j+"|"+c
    if (c=="(") b++; if (c==")") b--} while (true)
}
function m_round(x,n) {return eval("Math.round("+x+"/1e"+n+")*1e"+n)}

function m_brex(a,y) {
  var j=-1, c="", x=-1, b=0; g=""
  do {j++; if (j==y) break; c=a.charAt(j); if (c=="(") {b++; if (x<0) x=j}
    if (c==")") {b--; if (b==0) x=-1} } while (true)
  if (x==-1) return ""; g=x+","
  do {j++; if (j==a.length) break; c=a.charAt(j); b=m_br(b,c); if (b==0) return g+j} while (true)
  return ""
}
function m_bradd(a) {var x=u_c(a,"(")-u_c(a,")"); if (x>0) a+=u_str(")",x); return a}
function m_getterm(a) {
  var j=-1, b=0, c=""
  do {j++; if (j==a.length) return a; c=a.charAt(j); if (c=="(") b++; if (c==")") b--
    if (u_iO("+-=",c) && b==0) return a.substr(0,x)} while (true)
}
function m_data() {
  return "bc|#fdf9ba;rc|red;rw|4;a;h;w|600;d|60;ff|tahoma;fy|italic;fs|16_GCSE|AS Level / A Level|Standard Grade / Intermediate (Sco)|Higher / Advanced Higher (Sco)|Junior Certificate (Irl)|Leaving Certificate (Irl)_0.15|8_400,20,0,80,0,0.2_<v:textbox>*</v:textbox>"

}

