UNPKG

@stemcmicro/core

Version:

Computer Algebra System in TypeScript

1 lines 291 kB
System.register(["@stemcmicro/native","@stemcmicro/atoms","@stemcmicro/diagnostics","@stemcmicro/helpers","@stemcmicro/tree","@stemcmicro/context","@stemcmicro/directive","@stemcmicro/stack","@stemcmicro/em-parse","@stemcmicro/eigenmath"],(function(t){"use strict";var e,n,r,i,s,o,a,u,c,l,f,h,d,p,m,g,x,w,y,v,E,b,_,S,O,q,M,F,L,k,D,A,P,T,N,I,$,B,C,U,R,z,H,V,X,K,Z,j,J,G,Y,Q,W,tt,et,nt,rt,it,st,ot,at,ut,ct,lt,ft,ht,dt,pt,mt,gt,xt,wt,yt,vt,Et,bt,_t,St,Ot,qt,Mt,Ft,Lt,kt,Dt,At,Pt,Tt,Nt,It,$t,Bt,Ct,Ut,Rt,zt,Ht,Vt,Xt,Kt,Zt,jt,Jt,Gt,Yt,Qt,Wt,te,ee,ne,re,ie,se,oe,ae,ue,ce,le,fe,he,de,pe,me,ge,xe,we,ye,ve,Ee,be,_e,Se,Oe,qe,Me,Fe,Le,ke,De,Ae,Pe,Te,Ne,Ie,$e,Be,Ce,Ue,Re,ze,He,Ve,Xe,Ke,Ze,je,Je,Ge,Ye,Qe,We,tn,en,nn,rn,sn,on,an,un,cn,ln,fn,hn,dn,pn,mn,gn,xn,wn,yn,vn,En,bn,_n,Sn,On,qn,Mn,Fn,Ln,kn,Dn,An,Pn,Tn,Nn,In,$n,Bn,Cn,Un,Rn,zn,Hn,Vn,Xn,Kn,Zn,jn,Jn,Gn,Yn,Qn,Wn,tr,er,nr,rr,ir,sr,or,ar,ur,cr,lr,fr;return{setters:[function(u){e=u.native_sym,n=u.Native,r=u.is_native,i=u.log,s=u.multiply,o=u.real,a=u.exp,t({NATIVE_MAX:u.NATIVE_MAX,NATIVE_MIN:u.NATIVE_MIN,Native:u.Native,code_from_native_sym:u.code_from_native_sym,is_native_sym:u.is_native_sym,native_sym:u.native_sym})},function(t){u=t.create_sym,c=t.is_boo,l=t.Flt,f=t.negOne,h=t.is_num,d=t.is_rat,p=t.imu,m=t.is_flt,g=t.Rat,x=t.bigInt,w=t.is_tensor,y=t.zero,v=t.one,E=t.Tensor,b=t.create_int,_=t.BigInteger,S=t.is_sym,O=t.is_str,q=t.is_err,M=t.is_uom,F=t.is_blade,L=t.is_hyp,k=t.is_keyword,D=t.is_imu,A=t.Err,P=t.Cell,T=t.Map,N=t.create_flt,I=t.create_str,$=t.create_tensor,B=t.et,C=t.booT,U=t.epsilon,R=t.Str,z=t.piAsFlt,H=t.eAsFlt,V=t.two,X=t.four,K=t.half,Z=t.negFour,j=t.three,J=t.nine,G=t.third,Y=t.eight,Q=t.Sym,W=t.Boo,tt=t.assert_tensor,et=t.Hyp,nt=t.create_tensor_elements_diagonal,rt=t.is_map,it=t.is_tag,st=t.is_jsobject,ot=t.create_boo,at=t.JsObject,ut=t.assert_jsobject,ct=t.assert_sym,lt=t.booU,ft=t.Uom,ht=t.QQ,dt=t.create_rat,pt=t.zeroAsFlt,mt=t.is_cell,gt=t.assert_str,xt=t.assert_map,wt=t.assert_cell,yt=t.assert_flt,vt=t.create_hyp,Et=t.booF,bt=t.assert_rat,_t=t.Keyword,St=t.create_tensor_elements,Ot=t.oneAsFlt},function(t){qt=t.diagnostic,Mt=t.Diagnostics,Ft=t.is_localizable,Lt=t.Localizable},function(e){kt=e.str_to_string,Dt=e.isone,At=e.is_add,Pt=e.is_multiply,Tt=e.is_power,Nt=e.guess,It=e.is_num_and_negative,$t=e.is_rat_and_integer,Bt=e.is_num_and_eq_rational,Ct=e.is_cons_opr_eq_power,Ut=e.is_num_and_eq_number,Rt=e.is_num_and_eq_one_half,zt=e.multiply_items,Ht=e.negate,Vt=e.subst,Xt=e.add,Kt=e.divide,Zt=e.is_mul_2_any_any,jt=e.num_to_number,Jt=e.multiply,Gt=e.power,Yt=e.inverse,Qt=e.subtract,Wt=e.iszero,te=e.is_negative,ee=e.is_cons_opr_eq_multiply,ne=e.compare_num_num,re=e.is_cons_opr_eq_add,ie=e.is_cons_opr_eq_sym,se=e.is_outer,oe=e.is_inner_or_dot,ae=e.lt_num_num,ue=e.is_cons_opr_eq_inv,ce=e.is_base_of_natural_logarithm,le=e.is_pi,fe=e.is_num_and_eq_two,he=e.count_factors,de=e.contains_single_blade,pe=e.abs,me=e.is_factorial,ge=e.is_rat_and_fraction,xe=e.convertMetricToNative,we=e.convert_tensor_to_strings,ye=e.create_algebra_as_tensor,ve=e.predicate_return_value,Ee=e.prolog_eval_varargs,be=e.float,_e=e.is_safe_integer_range,Se=e.is_opr_2_any_any,t("create_algebra_as_blades",e.create_algebra_as_blades)},function(t){Oe=t.is_atom,qe=t.nil,Me=t.is_nil,Fe=t.is_cons,Le=t.cadr,ke=t.caddr,De=t.cadnr,Ae=t.items_to_cons,Pe=t.cdr,Te=t.car,Ne=t.cons,Ie=t.assert_cons,$e=t.assert_U,Be=t.assert_cons_or_nil,Ce=t.cddr,Ue=t.cdddr,Re=t.caadr,ze=t.cadadr,He=t.is_cons2,Ve=t.cadddr,Xe=t.is_singleton},function(t){Ke=t.Lambda,Ze=t.SIGN_GT,je=t.SIGN_LT,Je=t.SIGN_EQ,Ge=t.is_lambda},function(t){Ye=t.Directive},function(t){Qe=t.StackU,We=t.Stack},function(t){tn=t.scan_meta},function(t){en=t.complexity,nn=t.conjfunc,rn=t.inner,sn=t.push_rational,on=t.power,an=t.make_stack_draw,un=t.value_of,cn=t.stopf,ln=t.pop_integer,fn=t.multiply,hn=t.expfunc,dn=t.add,pn=t.sqrtfunc,mn=t.subtract,gn=t.negate,xn=t.push_integer,wn=t.multiply_factors,yn=t.power_e_expo,vn=t.stack_infix,En=t.stack_kronecker,bn=t.stack_log,_n=t.stack_mag,Sn=t.stack_mod,On=t.stack_noexpand,qn=t.stack_outer,Mn=t.stack_rank,Fn=t.stack_arccosh,Ln=t.stack_arcsin,kn=t.stack_arcsinh,Dn=t.stack_arctan,An=t.stack_arctanh,Pn=t.stack_arg,Tn=t.stack_binding,Nn=t.stack_circexp,In=t.stack_clock,$n=t.stack_cos,Bn=t.stack_cosh,Cn=t.stack_exp,Un=t.stack_expcos,Rn=t.stack_expcosh,zn=t.stack_expsin,Hn=t.stack_expsinh,Vn=t.stack_exptan,Xn=t.stack_exptanh,Kn=t.stack_floor,Zn=t.stack_hadamard,jn=t.stack_imag,Jn=t.stack_index,Gn=t.stack_inv,Yn=t.stack_minor,Qn=t.stack_minormatrix,Wn=t.stack_nroots,tr=t.stack_polar,er=t.stack_rationalize,nr=t.stack_real,rr=t.stack_rect,ir=t.stack_sin,sr=t.stack_sinh,or=t.stack_sqrt,ar=t.stack_testlt,ur=t.stack_testge,cr=t.stack_testgt,lr=t.stack_transpose,fr=t.stack_unit}],execute:function(){t({assert_sym:Lh,create_env:qb,create_uom:Ud,directive_from_flag:yr,env_term:function(t){t.clearBindings(),t.clearOperators()},init_env:LE,render_as_ascii:Tf,render_as_human:ah,render_as_infix:Du,render_as_latex:uh,render_as_sexpr:au,roots:rl,simplify:$l,transform_tree:function(t,e,n){const r=[],i=[],s=n.getPrintHandler(),o=new Db;n.setPrintHandler(o);try{const s=function(t,e,n){n.pushDirective(Ye.useIntegersForPredicates,yr(e.useIntegersForPredicates));try{const r=function(t){const e=[];if(Fe(t)){let n=t;for(;Fe(n);){const t=n.opr;if(S(t)&&Cb(t)){e.push(t);const r=n.argList.head;if(Fe(r)){n=r;continue}}break}}return e}(t);r.reverse(),t=function(t){if(Fe(t)){let e=t;for(;Fe(e);){const t=e.opr;if(S(t)&&Cb(t)){const t=e.argList.head;if(Fe(t)){e=t;continue}}break}return e}return t}(t),ei(0);const i=new kb(t);if(e.autoExpand){n.pushDirective(Ye.expanding,1);try{i.push(Rb(Ub(i.pop(),r),n))}finally{n.popDirective()}}else i.push(Rb(Ub(i.pop(),r),n));if(e.autoFactor){n.pushDirective(Ye.factoring,1);try{i.push(Rb(Ub(i.pop(),r),n))}finally{n.popDirective()}}const s=i.pop();if(qe!==s){if(i.push(s),n.hasBinding(Bs,qe)&&n.isone(n.getBinding(Bs,qe))){let t=$u(i.pop(),n);t=Rb(t,n),i.push(t)}!function(t,e,n,r){if((Vs.equals(t)||Xs.equals(t))&&D(e))return;const i=r.getSymbolsInfo();for(const t of i){const e=t.sym,i=t.value;if(D(i)){const t=n.pop(),i=Vt(t,p,e,r);return void n.push(i)}}}(t,i.peek(),i,n)}else i.push(qe);return function(t,e){Me(t)||e.setBinding(Ya,t)}(i.peek(),n),i.pop()}finally{n.popDirective()}}(t,e,n);return r.push(...o.prints),{value:s,prints:r,errors:i}}finally{n.setPrintHandler(s)}}});const hr=-1,dr=0,pr=1,mr=0,gr=1;function xr(t){return(t&gr)===gr}const wr=t("ALL_FEATURES",["Blade","Boo","Cell","Flt","Imu","Map","Rat","Sym","Tensor","Uom"]);function yr(t){return"boolean"==typeof t&&t?1:0}const vr=1,Er=2,br=[vr,Er],_r=vr|Er,Sr=vr|Er;let Or=class{extension;constructor(t){this.extension=t}create(t){return new this.extension(t)}};function qr(t){return new Or(t)}function Mr(t,e){return t.equals(e)?(e.addRef(),[mr,e]):(t.addRef(),[gr,t])}class Fr extends Error{constructor(t){super(),this.name="ProgrammingError","string"==typeof t&&(this.message=t)}}class Lr{handler;#t;#e;constructor(t,e,n){this.handler=t,this.#t=e,this.#e=n}get hash(){return this.#t}get name(){return this.#t}iscons(){return!1}operator(){throw new Fr}isKind(t){return!!Oe(t)&&this.#e(t)}toHumanString(t,r){return kt(this.handler.dispatch(t,e(n.human),qe,r))}toInfixString(t,r){return kt(this.handler.dispatch(t,e(n.infix),qe,r))}toLatexString(t,r){return kt(this.handler.dispatch(t,e(n.latex),qe,r))}toListString(t,r){return kt(this.handler.dispatch(t,e(n.sexpr),qe,r))}evaluate(t,e,n){throw new Error("evaluate method not implemented.")}transform(t,e){const n=this.valueOf(t,e);try{return Mr(n,t)}finally{n.release()}}valueOf(t,e){return this.dispatch(t,u("valueof"),qe,e)}binL(t,e,n,r){return this.handler.binL(t,e,n,r)}binR(t,e,n,r){return this.handler.binR(t,e,n,r)}dispatch(t,e,n,r){const i=this.handler.dispatch(t,e,n,r);return Me(i)?qt(Mt.Property_0_does_not_exist_on_type_1,e,u(t.type)):i}subst(t,e,n,r){throw new Error("subst method not implemented.")}test(t,e,n){const r=this.handler.dispatch(t,e,qe,n);if(c(r))return r.isTrue();throw qt(Mt.Property_0_does_not_exist_on_type_1,e,u(t.type))}}t("AtomExtensionBuilderFromExprHandlerBuilder",class{builder;type;guard;constructor(t,e,n){this.builder=t,this.type=e,this.guard=n}create(t){return new Lr(this.builder.create(),this.type,this.guard)}});class kr{handler;constructor(t){this.handler=t}get hash(){throw new Error("Method not implemented.")}get name(){throw new Error("Method not implemented.")}phases;dependencies;iscons(){throw new Error("Method not implemented.")}operator(){throw new Error("Method not implemented.")}isKind(t,e){throw new Error("Method not implemented.")}subst(t,e,n,r){throw new Error("Method not implemented.")}toHumanString(t,e){throw new Error("Method not implemented.")}toInfixString(t,e){throw new Error("Method not implemented.")}toLatexString(t,e){throw new Error("Method not implemented.")}toListString(t,e){throw new Error("Method not implemented.")}evaluate(t,e,n){throw new Error("Method not implemented.")}transform(t,e){throw new Error("Method not implemented.")}valueOf(t,e){throw new Error("Method not implemented.")}test(t,e,n){return this.handler.test(t,e,n)}binL(t,e,n,r){return this.handler.binL(t,e,n,r)}binR(t,e,n,r){return this.handler.binR(t,e,n,r)}dispatch(t,e,n,r){return this.handler.dispatch(t,e,n,r)}}function Dr(t,e,n){return t===Ar.d?Ar:t===Pr.d?Pr:t===Ir.d?Ir:t===Tr.d?Tr:t===$r.d?$r:new l(t,e,n)}const Ar=new l(0),Pr=new l(1),Tr=new l(2),Nr=new l(Math.PI);new l(1e-6),new l(Math.E);const Ir=new l(-1),$r=new l(-2),Br=e(n.add),Cr=e(n.cos),Ur=e(n.tan);e(n.subtract);const Rr=e(n.multiply);e(n.divide);const zr=e(n.pow),Hr=e(n.outer),Vr=e(n.inner),Xr=e(n.inv),Kr=e(n.lco),Zr=e(n.rco),jr=e(n.sin);e(n.succ),e(n.pred),e(n.E);const Jr=e(n.PI),Gr=e(n.factorial);e(n.iszero),e(n.testlt),e(n.testgt),e(n.testle),u(":"),e(n.tau);const Yr=e(n.IMU);var Qr;!function(t){t[t.Ascii=0]="Ascii",t[t.Human=1]="Human",t[t.Infix=2]="Infix",t[t.LaTeX=3]="LaTeX",t[t.SExpr=4]="SExpr",t[t.EcmaScript=5]="EcmaScript"}(Qr||(Qr={}));const Wr=new class{constructor(){}tos=0;stack=[]};function ti(t){throw ei(0),new Error(`Stop: ${t}`)}function ei(t){if(Wr.tos<=t)Wr.tos=t;else for(;Wr.tos>t;)Wr.stack[Wr.tos]=null,Wr.tos--}function ni(t,e,n){n.pushDirective(Ye.expanding,0);try{return t(e,n)}finally{n.popDirective()}}function ri(t,e,n){n.pushDirective(Ye.expanding,1);try{return t(e,n)}finally{n.popDirective()}}function ii(t,e,n,r){r.pushDirective(Ye.expanding,1);try{return t(e,n,r)}finally{r.popDirective()}}class si{static NegOne(t){return t.getDirective(Ye.evaluatingAsFloat)?Ir:f}static PI(t){return t.getDirective(Ye.evaluatingAsFloat)?Nr:Jr}}function oi(t){return Fe(t)?[...t].length:0}const ai=!0,ui=e(n.add);u("adj"),u("algebra");const ci=u("and"),li=u("approxratio"),fi=u("arccos"),hi=u("arccosh"),di=u("arcsin"),pi=u("arcsinh"),mi=u("arctan"),gi=u("arctanh");u("atomize");const xi=u("besselj"),wi=u("bessely");u("binding");const yi=u("binomial"),vi=u("ceiling"),Ei=u("check"),bi=u("choose");e(n.circexp);const _i=u("clear");u("clearall"),u("clearpatterns");const Si=u("coeff");u("cofactor"),u("compare"),u("compare-factors"),u("compare-terms");const Oi=e(n.component),qi=e(n.condense),Mi=u("contract"),Fi=Cr,Li=u("cosh");u("decomp");const ki=u("defint");u("denominator");const Di=u("det"),Ai=u("dim"),Pi=u("dirac");u("divide"),u("divisors");const Ti=u("do"),Ni=u("dot");u("draw"),u("dsolve");const Ii=u("eigen"),$i=u("eigenval"),Bi=u("eigenvec");u("equal");const Ci=u("erf"),Ui=u("erfc"),Ri=u("eval"),zi=e(n.exp),Hi=e(n.expand);u("expcos"),e(n.factor);const Vi=Gr;u("factorpoly");const Xi=e(n.float),Ki=u("floor"),Zi=e(n.fn),ji=u("for"),Ji=e(n.function),Gi=u("gamma"),Yi=e(n.gcd),Qi=e(n.hermite);e(n.hilbert),u("if");const Wi=e(n.imag);e(n.inner);const ts=e(n.integral),es=Xr;u("invg"),u("isinteger");const ns=e(n.isprime),rs=u("laguerre");u("laplace");const is=u("lcm");e(n.lco);const ss=u("legendre"),os=u("let"),as=e(n.log),us=Rr;e(n.not),u("nroots"),u("number"),u("numerator");const cs=u("operator"),ls=u("or");e(n.outer);const fs=u("pattern");e(n.polar);const hs=zr,ds=u("printLeaveEAlone"),ps=u("printLeaveXAlone");u("print");const ms=u("product"),gs=u("quote");u("quotient");const xs=u("rank");e(n.rco);const ws=e(n.real),ys=e(n.isreal),vs=u("round");e(n.rect),u("roots");const Es=e(n.assign),bs=u("sgn"),_s=jr,Ss=u("sinh");u("shape");const Os=u("sqrt");u("stop"),e(n.subst),u("-");const qs=u("sum"),Ms=Ur,Fs=u("tanh"),Ls=e(n.taylor),ks=e(n.test),Ds=e(n.testge),As=e(n.testgt),Ps=e(n.testle),Ts=e(n.testlt),Ns=u("transpose"),Is=u("unit"),$s=u("uom");e(n.zero),u("lastPrint"),u("lastAsciiPrint"),u("lastInfixPrint"),u("lastLatexPrint"),u("lastSexprPrint"),u("lastHumanPrint"),u("autoexpand"),u("autofactor");const Bs=u("bake");u("trace");const Cs=u("$METAA"),Us=u("$METAB"),Rs=u("$METAX"),zs=u("$SECRETX");u("version"),u("a"),u("b"),u("c");const Hs=u("d"),Vs=u("i"),Xs=u("j");u("n"),u("r");const Ks=u("s"),Zs=u("t"),js=u("x"),Js=u("y"),Gs=u("z"),Ys=u("I");u("a_"),u("b_"),u("x_");u("$C1"),u("$C2"),u("$C3"),u("$C4"),u("$C5"),u("$C6");const Qs=1e4,Ws=24,to=function(){const t=[2];let e=3;for(;t.length<Qs;){let n=0;const r=Math.sqrt(e);for(;n<t.length&&t[n]<=r;){if(e%t[n]==0){n=-1;break}n++}-1!==n&&t.push(e),e+=2}return t[Qs]=0,t}();function eo(t){return t.isZero()?0:t.isPositive()?1:-1}function no(t,e){return t.equals(e)}function ro(t){return d(t)?1===eo(t.a):!!m(t)&&t.d>0}function io(t){return!!h(t)&&t.isMinusOne()}function so(t,e){return Dt(t,e)||io(t)}function oo(t,e){return null==e&&(e=Nt(t)),!(!function(t,e){return function(t,e){return Pt(t)?t.tail().every((t=>ao(t,e))):ao(t,e)}(t,e)}(t,e)||1!==function(...t){return t.reduce(((t,e)=>t+Number(e)),0)}(t.contains(js),t.contains(Js),t.contains(Gs)))&&e}function ao(t,e){if(Tt(t)){const n=t.base,r=t.expo;return d(r)&&r.isPositiveInteger()&&co(n,e)}return co(t,e)}function uo(t,e){return!!t.contains(e)&&co(t,e)}function co(t,e){return At(t)?t.tail().every((t=>lo(t,e))):lo(t,e)}function lo(t,e){return Pt(t)?t.tail().every((t=>fo(t,e))):fo(t,e)}function fo(t,e){if(t.equals(e))return!0;if(Tt(t)&&t.base.equals(e)){const e=t.expo;return d(e)&&e.isPositiveInteger()}return!t.contains(e)}function ho(t){if(Tt(t)){const e=t.expo;if(d(e)&&It(t.base))return!0}return!1}function po(t,e){return Pt(t)&&3===oi(t)&&m(De(t,1))&&ho(De(t,2))||e.equals(t,p)}function mo(t){if(Pt(t)&&3===oi(t)){if(h(Le(t))&&ke(t).equals(p))return!0;if(t.equals(p))return!0;if(ho(ke(t)))return!0}return!1}function go(t){if(At(t)){if(3===oi(t)){const e=Le(t);if(h(e)&&(mo(ke(t))||mo(t)))return!0}}return!1}function xo(t){return $t(t)&&t.a.isEven()}function wo(t){return d(t)&&t.isFraction()}function yo(t){return Bt(t,-1,2)}function vo(t){return!(!Fe(t)||!Ct(t))&&(Tt(t)&&Ut(Le(t),2)&&Bt(ke(t),-1,2))}function Eo(t){return Tt(t)&&Ut(Le(t),3)&&Rt(ke(t))}function bo(t){return!(!m(t)&&!Xi.equals(t))||!!Fe(t)&&[...t].some(bo)}function _o(t,e,n){return r=function(t,e,n,r){const i=Ae(t,e,n);try{return r.valueOf(i)}finally{i.release()}}(Rr,t,e,n),r;var r}function So(t,e,n){return function(t,e,n,r){r.pushDirective(Ye.expanding,0);try{return t(e,n,r)}finally{r.popDirective()}}(_o,t,e,n)}function Oo(t,e){e.pushDirective(Ye.factoring,1);try{return zt(t,e)}finally{e.popDirective()}}function qo(t,e){return t.multiply(e)}function Mo(t,e){return t.divide(e)}function Fo(t,e){return t.mod(e)}function Lo(t,e){const n=t.divmod(e);return[n.quotient,n.remainder]}function ko(t){return x(t)}function Do(t,e){if(t.isPositive()){if(e.isNegative())return t.multiply(x(-1))}else if(e.isPositive())return t.multiply(x(-1));return t}function Ao(t,e){return t.isPositive()?t:t.multiply(x(-1))}function Po(t){const e=Mo(t.a,t.b);return new g(e,x.one)}function To(t,e){return new g(x(t),x(e))}function No(t){return d(t)||m(t)?t.toNumber():0}function Io(t){return new g(function(t){let e;if(0===t||1===t)return e=x(1),e;e=x(2);let n=x(0);if(3<=t)for(let r=3;r<=t;r++)n=x(r),e=qo(e,n);return e}(t),x.one)}function $o(t,e){const n=Ht(e,p),r=Vt(t,p,n,e);return e.valueOf(r)}const Bo=e(n.testeq);function Co(t,e,n){const r=Ae(Bo,t,e);try{return n.valueOf(r)}finally{r.release()}}const Uo=e(n.rect);function Ro(t,e){const n=Ae(Uo,t);try{return e.valueOf(n)}finally{n.release()}}function zo(t,e,n){const r=Ht(n,e);return Xt(n,t,r)}function Ho(t,e){t=Pe(t);let n=e.valueOf(Te(t));return Fe(t)&&(n=t.tail().reduce(((t,n)=>Vo(t,e.valueOf(n),e)),n)),n}function Vo(t,e,n){return function(t,e,n){if(At(t))return function(t,e,n){return t.tail().reduce(((t,r)=>n.add(t,Vo(r,e,n))),y)}(t,e,n);if(w(t))return function(t,e,n){return t.map((t=>Vo(t,e,n)))}(t,e,n);if(t.contains(e))return y;return t}(t,e,n)}function Xo(t,e,n){n.pushDirective(Ye.expanding,1);try{return Kt(t,e,n)}finally{n.popDirective()}}function Ko(t,e,n){const r=new Qe;let i=t;for(;;){const t=n.valueOf(Vt(i,e,y,n));if(r.push(t),i=i.equals(t)?y:n.valueOf(zo(i,t,n)),i.equals(y))try{return r.elements}finally{r.release()}i.equals(e)?i=v:Fe(i)&&Zo(i,e)?i=i.lhs:(i=Xo(i,e,n),i=n.valueOf(i))}}function Zo(t,e){return!!Zt(t)&&t.rhs.equals(e)}function jo(t,r){const i=Jo(t,r),s=i.length;return new E([s],function(t,r){const i=t.map((function(t,e){return{value:t,index:e}}));i.sort((function(t,i){const s=r.compareFn(e(n.multiply))(t.value,i.value);return r.isscalar(t.value)||r.isscalar(i.value)?s:t.index-i.index}));const s=i.map((function(t){return t.value}));return s}(i,r))}function Jo(t,e){const n=[];if(h(t))n.push(...qa(jt(t)));else if(Fe(t)&&At(t))n.push(...function(t,e){const n=Fe(t)?t.tail().reduce((function(t,n){return Ma(t,n,e)})):Te(t),r=[];let i=n;if(Dt(i,e))return r.push(t,v),r;if(h(i))r.push(...qa(jt(i)));else if(Pt(i)){const t=Pe(i);h(Te(t))?r.push(...qa(jt(Te(t)))):r.push(Te(t),v),Fe(t)&&t.tail().forEach((t=>r.push(t,v)))}else r.push(i,v);i=Yt(i,e);const s=Fe(t)?t.tail().reduce(((t,n)=>Xt(e,t,Jt(e,i,n))),y):Pe(t);return r.push(s,v),r}(t,e));else if(Pt(t)){let e=Pe(t);if(h(Te(e))&&(n.push(...qa(jt(Te(e)))),e=Pe(e)),Fe(e)){const t=[...e].map((t=>Tt(t)?[Le(t),ke(t)]:[t,v]));n.push(...t.flat())}}else Tt(t)?n.push(Le(t),ke(t)):n.push(t,v);const r=n.length;return n.push(v),Go(n,0,r,e),n.slice(r)}function Go(t,e,n,r){const i=t.pop();if(e===n)return void t.push(i);const s=t[e+0],o=t[e+1],a=jt(o);if(!isNaN(a))for(let o=0;o<=Math.abs(a);o++)t.push(Jt(r,i,Gt(r,s,b(((u=a)<0?-1:u>0?1:0)*o)))),Go(t,e+2,n,r);var u}function Yo(t,e,n){return ii(Qo,t,e,n)}function Qo(t,e,n){const r=Ma(t,e,n),i=Kt(r,t,n),s=Kt(i,e,n);return Yt(s,n)}function Wo(t,e){const n=e.valueOf(t.item1),r=e.valueOf(t.item2),i=e.valueOf(t.item3);return i.isnil?ta(n,r,js,e):ta(n,r,i,e)}function ta(t,e,n,r){const i=Ko(t,n,r);let s=i.length-1;const o=Ko(e,n,r),a=o.length-1;let u=s-a,c=y;for(;u>=0;){const t=Kt(i[s],o[a],r);for(let e=0;e<=a;e++)i[u+e]=Qt(r,i[u+e],Jt(r,o[e],t));c=Xt(r,c,Jt(r,t,Gt(r,n,b(u)))),s--,u--}return c}class ea extends Error{name="SystemError";constructor(t){super(t),console.warn(t,(new Error).stack)}}function na(t){if(void 0===t)throw new Error("expr must be defined.");Wr.stack[Wr.tos++]=t}function ra(){if(0===Wr.tos)throw new ea("stack underflow");const t=Wr.stack[--Wr.tos];return Wr.stack[Wr.tos]=null,t}function ia(t){for(;t.length>0;)na(t.shift())}function sa(t,e,n){const r=function(t,e){return t};if(bo(t))throw new Error("floating point numbers in polynomial");const i=Ko(t,e,n);for(let t=0;t<i.length;t++);const s=function(t,e){let n=v;for(const r of t)n=Yo(Ca(r,e),n,e);for(let r=0;r<t.length;r++)t[r]=Jt(e,n,t[r]);const r=Yt(n,e);return r}(i,n);for(let t=0;t<i.length;t++);let o,a,u,c="ℝ",l=null,f=i.length-1,h=s;for(;f>0;){let t=!1,s=!1;if(Wt(i[0],n)?(o=v,a=y):"ℝ"===c?[s,o,a]=oa(i,f,e,o,a,n):"ℂ"===c&&([t,o]=aa(l,i,f,n)),"ℝ"===c){if(!1===s){c="ℂ";continue}{for(u=Xt(n,Jt(n,o,e),a),h=So(h,u,n),ua(o,a,i,f,n);f&&Wt(i[f],n);)f--;let t=y;for(let r=0;r<=f;r++)t=Xt(n,t,Jt(n,i[r],Gt(n,e,b(r))));l=t}}else if("ℂ"===c){if(!1===t)break;{const t=Qt(n,o,e),s=Qt(n,$o(o,n),e);u=Jt(n,t,s);const a=h;if(h=So(h,u,n),null==l){let t=y;for(let r=0;r<=f;r++)t=Xt(n,t,Jt(n,i[r],Gt(n,e,b(r))));l=t}const c=l;l=ta(c,u,e,n);if(!Co(Jt(n,l,u),c,n)){na(a);const t=ni(Ta,c,n);return r(So(ra(),t,n))}for(let t=0;t<=f;t++)i.pop();i.push(...Ko(l,e,n)),f-=2}}}let d=y;for(let t=0;t<=f;t++)d=Xt(n,d,Jt(n,i[t],Gt(n,e,b(t))));const p=ni(Ta,d,n);return f>0&&te(i[f])?r(So(ni((function(t,e){return Ht(e,t)}),h,n),Ht(n,p),n)):r(So(h,p,n))}function oa(t,e,n,r,i,s){const o=Wr.tos,a=Wr.tos;ia(Jo(t[e],s));const u=Wr.tos-a,c=Wr.tos;ia(Jo(t[0],s));const l=Wr.tos-c;for(let n=0;n<u;n++)for(let u=0;u<l;u++){r=Wr.stack[a+n],i=Wr.stack[c+u];const l=Ht(s,Kt(i,r,s)),f=ca(l,t,e,s);if(Wt(f,s))return ei(o),[!0,r,i];i=Ht(s,i);const h=ca(Ht(s,l),t,e,s);if(Wt(h,s))return ei(o),[!0,r,i]}return ei(o),[!1,r,i]}function aa(t,e,n,r){let i,s,o;if(n<=2)return[!1,i];const a=Wr.tos;if(i=Ro(Gt(r,f,To(2,3)),r),s=i,na(s),o=ca(s,e,n,r),Wt(o,r))return ei(a),[!0,i];if(i=Ro(Gt(r,v,To(2,3)),r),s=i,na(s),o=ca(s,e,n,r),Wt(o,r))return ei(a),[!0,i];for(let t=-10;t<=10;t++)for(let s=1;s<=5;s++){i=Ro(Xt(r,b(t),Jt(r,b(s),p)),r);const o=i;na(o);const u=ca(o,e,n,r);if(Wt(u,r))return ei(a),[!0,i]}return ei(a),[!1,i]}function ua(t,e,n,r,i){let s=y;for(let o=r;o>0;o--){const r=Kt(n[o],t,i);n[o]=s,s=r,n[o-1]=Qt(i,n[o-1],Jt(i,s,e))}n[0]=s}function ca(t,e,n,r){!function(t){const e=function(t){if(Number.isInteger(t))return t;throw new Fr}(t);if(e>=0)return e;throw new Fr}(n);let i=y;for(let s=n;s>=0;s--)i=Xt(r,Jt(r,i,t),e[s]);return i}const la=9007199254740992;function fa(t){return-la<t&&t<la}function ha(t){return t>0?Math.floor(t):Math.ceil(t)}const da=1<<30;function pa(t){if(t instanceof _){const e=t.value|BigInt(da);return e&-e}throw new Error}function ma(t,e){return t=ga(t),e=ga(e),t.lesser(e)?t:e}function ga(t){return"number"==typeof t?function(t){return new _(BigInt(t))}(t):"string"==typeof t?function(t){if(fa(+t)){const e=+t;if(e===ha(e))return new _(BigInt(e));throw new Error("Invalid integer: "+t)}const e="-"===t[0];e&&(t=t.slice(1));const n=t.split(/e/i);if(n.length>2)throw new Error("Invalid integer: "+n.join("e"));if(2===n.length){let e=n[1];"+"===e[0]&&(e=e.slice(1));let r=+e;if(r!==ha(r)||!fa(r))throw new Error("Invalid integer: "+r+" is not a valid exponent.");let i=n[0];const s=i.indexOf(".");if(s>=0&&(r-=i.length-s-1,i=i.slice(0,s)+i.slice(s+1)),r<0)throw new Error("Cannot include negative exponent part for integers");i+=new Array(r+1).join("0"),t=i}if(!/^([0-9][0-9]*)$/.test(t))throw new Error("Invalid integer: "+t);return new _(BigInt(e?"-"+t:t))}(t):"bigint"==typeof t?new _(t):t}const xa=[];for(let t=0;t<1e3;t++)xa[t]=ga(t),t>0&&(xa[-t]=ga(-t));function wa(t,e){return function(t,e){if(t=ga(t).abs(),e=ga(e).abs(),t.equals(e))return t;if(t.isZero())return e;if(e.isZero())return t;let n,r=xa[1];for(;t.isEven()&&e.isEven();)n=ma(pa(t),pa(e)),t=t.divide(n),e=e.divide(n),r=r.multiply(n);for(;t.isEven();)t=t.divide(pa(t));do{let n;for(;e.isEven();)e=e.divide(pa(e));t.greater(e)&&(n=e,e=t,t=n),e=e.subtract(t)}while(!e.isZero());return r.isUnit()?t:t.multiply(r)}(t,e)}let ya=x(0);function va(t){if(t.isZero()||t.isOne()||t.isMinusOne())return t;ya=t.a;const e=function(){const t=[];ya.isNegative()&&(ya=Ao(ya),t.push(f));for(let e=0;e<1e4;e++)if(t.push(...Ea(e)),0===ya.compare(1))return t;return t.push(...function(){const t=[],e=ko(1);let n=ko(5),r=ko(2),i=1,s=1;for(;;){if(ya.isProbablePrime())return t.push(ba(ya,1)),t;for(;;){let o=r.subtract(n);o=Ao(o);const a=wa(o,ya);if(!a.equals(1)){if(t.push(ba(a,1)),0===a.compare(ya))return t;o=Mo(ya,a),ya=o,o=Fo(n,ya),n=o,o=Fo(r,ya),r=o;break}0==--i&&(r=n,s*=2,i=s),o=qo(n,n),n=o.add(e),o=Fo(n,ya),n=o}}}()),t}();return e.length,1===e.length?e[0]:e.length>1?Ne(us,Ae(...e)):qe}function Ea(t){const e=[];let n;const r=ko(to[t]);let i=0;for(;;){if(0===ya.compare(1))return i&&e.push(ba(r,i)),e;let t;if([n,t]=Array.from(Lo(ya,r)),!t.isZero())break;i++,ya=n}return i&&e.push(ba(r,i)),-1===n.compare(r)&&(e.push(ba(ya,1)),ya=ko(1)),e}function ba(t,e){let n=new g(t,x.one);return e>1&&(n=Ae(hs,n,new g(ko(e),x.one))),n}function _a(t,e,n,r){const i=Oa(e,n,r);Fe(i)&&ee(i)?t.push(...i.tail()):t.push(i)}function Sa(t,e,n){return d(t)&&t.isInteger()?va(t):Oa(t,e,n)}function Oa(t,e,n){return t.contains(e)&&uo(t,e)&&S(e)?sa(t,e,n):t}function qa(t){if(isNaN(t))throw new Error("number too big to factor");const e=[];t<0&&(t=-t);for(let n=0;n<Qs;n++){const r=to[n];if(r>t/r)break;let i=0;for(;t%r==0;)t/=r,i++;i&&(e.push(b(r)),e.push(b(i)))}return t>1&&(e.push(b(t)),e.push(v)),e}function Ma(t,e,n){return ii(Fa,t,e,n)}function Fa(t,e,n){if(t.equals(e))return t;if(d(t)&&d(e))return t.gcd(e);const r=La(t,e);return r?function(t,e,n,r){let i=Oa(t,n,r),s=Oa(e,n,r);(Pt(i)||Pt(s))&&(Pt(i)||(i=Ae(us,i,v)),Pt(s)||(s=Ae(us,s,v)));if(Pt(i)&&Pt(s))return ka(i,s,r);return Da(i,s,r)}(t,e,r,n):At(t)&&At(e)?function(t,e,n){if(Ie(t),Ie(e),oi(t)!==oi(e))return v;const r=Fe(t)?t.tail().reduce((function(t,e){return Ma(t,e,n)})):Te(Pe(t)),i=Fe(e)?e.tail().reduce((function(t,e){return Ma(t,e,n)})):Te(Pe(e)),s=Kt(t,r,n),o=Kt(e,i,n);if(s.equals(o))return Jt(n,s,Ma(r,i,n));return v}(t,e,n):(At(t)&&(t=Aa(t,n)),At(e)&&(e=Aa(e,n)),Pt(t)?function(t,e,n){return t.tail().reduce(((t,r)=>Jt(n,t,Ma(r,e,n))),v)}(t,e,n):Pt(e)?function(t,e,n){return e.tail().reduce(((e,r)=>Jt(n,e,Ma(t,r,n))),v)}(t,e,n):Pt(t)&&Pt(e)?ka(t,e,n):Da(t,e,n))}function La(t,e){const n=oo(t,null);return!!n&&(!!oo(e,n)&&n)}function ka(t,e,n){const r=t.rest,i=e.rest;return[...r].reduce(((t,e)=>Jt(n,t,[...i].reduce(((t,r)=>Jt(n,t,Ma(e,r,n))),v))),v)}function Da(t,e,n){let r,i;if(Tt(t)?(r=ke(t),t=Le(t)):r=v,Tt(e)?(i=ke(e),e=Le(e)):i=v,!t.equals(e))return v;if(h(r)&&h(i)){const e=ne(r,i)<0?r:i;return Gt(n,t,e)}const s=Kt(r,i,n);if(h(s)){const e=Le(r),s=Pt(r)&&h(e)?e:v,o=Le(i),a=Pt(i)&&h(o)?o:v,u=ne(s,a)<0?r:i;return Gt(n,t,u)}const o=Qt(n,r,i);if(!h(o))return v;const a=It(o)?r:i;return Gt(n,t,a)}function Aa(t,e){return t.tail().reduce((function(t,n){return Ma(t,n,e)}))}function Pa(t,e){return ni(Ta,t,e)}function Ta(t,e){if(!At(t))return t;const n=t.tail().reduce((function(t,n){return Ma(t,n,e)})),r=Yt(n,e),i=function(t,e){return ri((function(t){return e.valueOf(t)}),t,e)}(t.tail().reduce(((t,n)=>Xt(e,t,So(r,n,e))),y),e);return Kt(i,r,e)}function Na(t,e){e.pushDirective(Ye.factoring,1);try{return function(t,e){if(w(t))return function(t,e){if(!w(t))return t;const n=t.mapElements((function(t){return Na(t,e)}));return t.withElements(n)}(t,e);if(!At(t))return t;const n=function(t,e){if(At(t))return t.tail().reduce(((t,n)=>Ia(n,t,e)),v);return Ia(t,v,e)}(t,e);let r=y;Fe(t)&&(r=t.tail().reduce(((t,r)=>Xt(e,t,Jt(e,n,r))),r));const i=Pa(r,e),s=Kt(i,n,e);return s}(t,e)}finally{e.popDirective()}}function Ia(t,e,n){return Pt(t)?t.tail().reduce(((t,e)=>$a(e,t,n)),e):$a(t,e,n)}function $a(t,e,n){if(!Tt(t))return e;const r=t;return t=ke(t),It(t)||Pt(t)&&It(Le(t))?Ba(e,Yt(r,n),n):e}function Ba(t,e,n){return Kt(Jt(n,t,e),Ma(t,e,n),n)}function Ca(t,e){if(d(t))return t.denom();if(Fe(t)&&At(t)&&(t=Na(t,e)),Fe(t)){const n=t.cdr;if(Pt(t)&&!Dt(Te(n),e)){const n=function(t,e){const n=function(t){return function(e){return Ca(e,t)}}(e),r=t.map(n);return r}(t.tail(),e);return zt(n,e)}if(Tt(t)&&te(t.expo))return Yt(t,e)}return v}function Ua(t,e){const n=t.argList;try{const t=n.head;try{const n=e.valueOf(t);try{return Ra(n,e)}finally{n.release()}}finally{t.release()}}finally{n.release()}}function Ra(t,e){return Fe(t)&&re(t)&&(t=Na(t,e)),Fe(t)&&ee(t)&&!Dt(Te(Pe(t)),e)?zt(t.tail().map((function(t){return Ra(t,e)})),e):d(t)?t.numer():Fe(t)&&Ct(t)&&te(t.expo)?v:t}const za=e(n.abs);function Ha(t){return Fe(t)&&ie(t,za)}function Va(t){return Fe(t)&&re(t)}function Xa(t){return Fe(t)&&ie(t,Rr)}function Ka(t){return Fe(t)&&S(t.opr)&&r(t.opr,n.pow)}function Za(t){return Fe(t)&&ie(t,Gr)}function ja(t){return Fe(t)&&ie(t,Ns)}function Ja(t){return!(!h(t)&&!Ys.equals(t))||!!w(t)&&t.everyElement(Ja)}function Ga(t){return Ys.equals(t)}const Ya=t("RESERVED_KEYWORD_LAST",u("last"));t("RESERVED_KEYWORD_TTY",u("tty"));function Qa(t){return Te(Te(t))}function Wa(t){return Te(Pe(t))}function tu(t){return Pe(Pe(t))}function eu(t){return Te(Te(Pe(t)))}function nu(t){return Te(Pe(Pe(t)))}function ru(t){return Te(Pe(Pe(Pe(t))))}function iu(t){return Te(Pe(Pe(Pe(Pe(t)))))}function su(t,e){let n;if(e.getDirective(Ye.printMode)===Qr.EcmaScript||e.getDirective(Ye.renderFloatAsEcmaScript))return`${t}`;if(e.getDirective(Ye.forceFixedPrintout)){const r=e.getDirective(Ye.maxFixedPrintoutDigits);n=t.toFixed(r),n=n.replace(/(\.\d*?[1-9])0+$/gm,"$1"),n=n.replace(/\.0+$/gm,""),-1===n.indexOf(".")&&(n+=".0"),parseFloat(n)!==t&&(n=t.toFixed(r)+"...")}else n=""+t,n=e.getDirective(Ye.printMode)===Qr.LaTeX?/\d*\.\d*e.*/gm.test(n)?n.replace(/e(.*)/gm,"\\mathrm{e}{$1}"):n.replace(/(\d+)e(.*)/gm,"$1.0\\mathrm{e}{$2}"):/\d*\.\d*e.*/gm.test(n)?n.replace(/e(.*)/gm,"*10^($1)"):n.replace(/(\d+)e(.*)/gm,"$1.0*10^($2)");return n}function ou(t,e,n){if(d(t)){let r="",i=t.a.toString();if(e||"-"===i[0]&&(i=i.substring(1)),n.getDirective(Ye.printMode)===Qr.LaTeX&&t.isFraction()&&(i="\\frac{"+i+"}{"),r+=i,t.isFraction()){n.getDirective(Ye.printMode)!==Qr.LaTeX&&(r+="/");let e=t.b.toString();n.getDirective(Ye.printMode)===Qr.LaTeX&&(e+="}"),r+=e}return r}if(m(t)){const r=su(t.d,n);return e?r:"-"===r[0]?r.substring(1):r}throw new Error(`print_number(p = ${t})`)}function au(t,r){if(Fe(t)){let e="";for(e+="(",e+=au(Te(t),r),t=Pe(t);Fe(t);)e+=" ",e+=au(Te(t),r),t=Pe(t);return t!==qe&&(e+=" . ",e+=au(t,r)),e+=")",e}if(!Oe(t)){if(t.isnil){const i=r.handlerFor(t);return kt(i.dispatch(t,e(n.sexpr),qe,r))}throw new Error}{const i=r.handlerFor(t).dispatch(t,e(n.sexpr),qe,r);try{return kt(i)}finally{i.release()}}}const uu=e(n.E),cu=e(n.IMU),lu=e(n.PI),fu=e(n.testeq),hu=e(n.component);function du(t,e){return function(t){if(d(t)&&(t.isNegative()||t.isFraction()))return!0;if(m(t)&&t.isNegative())return!0;if(Va(t))return!0;if(Xa(t))return!0;if(Ka(t))return!0;return!1}(t)?`(${gu(t,e)})`:gu(t,e)}function pu(t,e){return d(t)&&t.isFraction()||Va(t)||Xa(t)||Ka(t)?`(${gu(t,e)})`:gu(t,e)}function mu(t,e,n){let r="";const i=Wa(t);let s=nu(t);return io(s)?(r+=du(i,n),r):(1===e&&(r+="("),s=Ht(n,s),r+=Mu(i,s,n),1===e&&(r+=")"),r)}function gu(t,e){return $e(t),function(t,e){$e(t);let n="";if(Va(t))for(t=Pe(t),"-"===xu(Te(t))&&(n+="-"),n+=yu(Te(t),e),t=Pe(t);Fe(t);)"+"===xu(Te(t))?e.getDirective(Ye.printMode)===Qr.Human?n+=" + ":n+="+":e.getDirective(Ye.printMode)===Qr.Human?n+=" - ":n+="-",n+=yu(Te(t),e),t=Pe(t);else"-"===xu(t)&&(n+="-"),n+=yu(t,e);return n}(t,e)}function xu(t){if(Fe(t)&&Xa(t)){const e=Te(t.cdr);if(h(e)&&e.isNegative())return"-"}return h(t)&&t.isNegative()?"-":"+"}function wu(t,e){let n="",r="",i=Pe(t);io(Te(i))&&(i=Pe(i));let s=!1;h(Te(i))&&(s=!0);let o=!1;e.getDirective(Ye.printMode)===Qr.LaTeX&&Fe(Pe(i))&&function(t){return d(t)&&t.isFraction()&&no(t.a.abs(),1)}(Te(i))&&(o=!0,n=Te(i).b.toString());let a="";for(o?(r=a,a=""):a+=vu(Te(i),!1,!1,e),i=Pe(i);Fe(i);)e.getDirective(Ye.printMode)===Qr.LaTeX&&s&&Qa(i).equals(hs)&&h(Te(Pe(Te(i))))&&(wo(Te(Pe(Pe(Te(i)))))||(a+=" \\cdot ")),a+=Lu(e),a+=vu(Te(i),!1,!0,e),s=!1,h(Te(i))&&(s=!0),i=Pe(i);return o&&(a=r+"\\frac{"+a+"}{"+n+"}"),a}function yu(t,e){return $e(t),Fe(t)&&Xa(t)?function(t){let e=t.cdr;for(;Fe(e);){if(ku(e.car))return!0;e=e.cdr}return!1}(t)?function(t,e){let n,r,i="",s=0,o=0,a=0,u=t.cdr,c=Te(u);for(d(c)?(n=c.numer().abs(),r=c.denom(),Dt(n,e)||o++,Dt(r,e)||a++,u=Pe(u)):(n=v,r=v);Fe(u);)c=Te(u),ku(c)?a++:o++,u=Pe(u);if(e.getDirective(Ye.printMode)===Qr.LaTeX&&(i+="\\frac{"),0===o)i+="1";else for(s=0,u=Pe(t),d(Te(u))&&(u=Pe(u)),Dt(n,e)||(i+=Fu(n,!1,!1,e),s=1);Fe(u);)c=Te(u),ku(c)||(s&&(i+=Lu(e)),i+=Fu(c,!1,!1,e),s=1),u=Pe(u);for(e.getDirective(Ye.printMode)===Qr.LaTeX?i+="}{":e.getDirective(Ye.printMode)===Qr.Human?i+=" / ":i+="/",a>1&&e.getDirective(Ye.printMode)!==Qr.LaTeX&&(i+="("),s=0,u=Pe(t),d(Te(u))&&(u=Pe(u)),Dt(r,e)||(i+=Fu(r,!1,!1,e),s=1);Fe(u);)c=Te(u),ku(c)&&(s&&(i+=Lu(e)),i+=mu(c,a,e),s=1),u=Pe(u);return a>1&&e.getDirective(Ye.printMode)!==Qr.LaTeX&&(i+=")"),e.getDirective(Ye.printMode)===Qr.LaTeX&&(i+="}"),i}(t,e):wu(t,e):vu(t,!1,!1,e)}function vu(t,e,n,r){if($e(t),Fe(t)&&se(t)){let e=t.argList;if(Fe(e)){let t=bu(e.car,!1,!1,r);for(e=e.cdr;Fe(e);)t+=Eu(r),t+=bu(Te(e),!1,!0,r),e=e.cdr;return t}throw new Error}return bu(t,e,n,r)}function Eu(t){return t.getDirective(Ye.printMode)===Qr.LaTeX?" \\wedge ":t.getDirective(Ye.printMode)===Qr.Human?" ^ ":"^"}function bu(t,e,n,r){if($e(t),Fe(t)&&oe(t)){let e=t.argList;if(Fe(e)){let t=Fu(e.car,!1,!1,r);for(e=e.cdr;Fe(e);)t+=_u(r),t+=Fu(Te(e),!1,!0,r),e=e.cdr;return t}throw new Error}if(Fe(t)&&function(t){return Fe(t)&&ie(t,Kr)}(t)){let e=t.argList;if(Fe(e)){let t=Fu(e.car,!1,!1,r);for(e=e.cdr;Fe(e);)t+=Su(r),t+=Fu(Te(e),!1,!0,r),e=e.cdr;return t}throw new Error}if(Fe(t)&&function(t){return Fe(t)&&ie(t,Zr)}(t)){let e=t.argList;if(Fe(e)){let t=Fu(e.car,!1,!1,r);for(e=e.cdr;Fe(e);)t+=Ou(r),t+=Fu(Te(e),!1,!0,r),e=e.cdr;return t}throw new Error}return Fu(t,e,n,r)}function _u(t){return t.getDirective(Ye.printMode)===Qr.LaTeX?" \\mid ":t.getDirective(Ye.printMode)===Qr.Human?" | ":"|"}function Su(t){return t.getDirective(Ye.printMode)===Qr.LaTeX?" \\ll ":t.getDirective(Ye.printMode)===Qr.Human?" << ":"<<"}function Ou(t){return t.getDirective(Ye.printMode)===Qr.LaTeX?" \\gg ":t.getDirective(Ye.printMode)===Qr.Human?" >> ":">>"}function qu(t,e){let n="";return n+="(",n+=gu(t,e),n+=")",n}function Mu(t,e,n){let r="";if(Rt(e))if(Ut(t,2)){if(n.getDirective(Ye.printMode)===Qr.EcmaScript)return r+="Math.SQRT2",r}else{if(n.getDirective(Ye.printMode)===Qr.LaTeX)return r+="\\sqrt{",r+=gu(t,n),r+="}",r;if(n.getDirective(Ye.printMode)===Qr.EcmaScript)return r+="Math.sqrt(",r+=gu(t,n),r+=")",r}if(Ut(n.getBinding(ds,qe),1)&&ce(t))return n.getDirective(Ye.printMode)===Qr.EcmaScript?(r+="Math.exp(",r+=pu(e,n),r+=")",r):(n.getDirective(Ye.printMode)===Qr.LaTeX?(r+="e^{",r+=gu(e,n),r+="}"):(r+="exp(",r+=gu(e,n),r+=")"),r);if(n.getDirective(Ye.printMode)===Qr.EcmaScript)return r+="Math.pow(",r+=du(t,n),r+=", ",r+=pu(e,n),r+=")",r;if(function(t,e){if(S(t)){if(t.equals(u("x"))){const t=ps,n=e.getBinding(t,qe);return!(!n.equals(t)&&!n.isnil&&Ut(n,1))}return!0}return!0}(t,n)){if(!ce(t)){if(h(e)&&e.isMinusOne())return n.getDirective(Ye.printMode)===Qr.LaTeX?r+="\\frac{1}{":n.getDirective(Ye.printMode)===Qr.Human?r+="1 / ":r+="1/",Fe(t)&&n.getDirective(Ye.printMode)!==Qr.LaTeX?(r+="(",r+=gu(t,n),r+=")"):r+=gu(t,n),n.getDirective(Ye.printMode)===Qr.LaTeX&&(r+="}"),r;if(te(e)){n.getDirective(Ye.printMode)===Qr.LaTeX?r+="\\frac{1}{":n.getDirective(Ye.printMode)===Qr.Human?r+="1 / ":r+="1/";const i=Ht(n,e);return Fe(t)&&n.getDirective(Ye.printMode)!==Qr.LaTeX?(r+="(",r+=Mu(t,i,n),r+=")"):r+=Mu(t,i,n),n.getDirective(Ye.printMode)===Qr.LaTeX&&(r+="}"),r}}if(wo(e)&&n.getDirective(Ye.printMode)===Qr.LaTeX){r+="\\sqrt";const i=Ca(e,n);return fe(i)||(r+="[",r+=gu(i,n),r+="]"),r+="{",r+=Mu(t,e=Ra(e,n),n),r+="}",r}}return n.getDirective(Ye.printMode)===Qr.LaTeX&&Dt(e,n)?r+=gu(t,n):(Ka(t)?n.getDirective(Ye.printMode)!==Qr.LaTeX?(r+="(",r+=Fu(t,!0,!1,n),r+=")"):r+=Fu(t,!0,!1,n):It(t)||Va(t)?(r+="(",r+=gu(t,n),r+=")"):Xa(t)?n.getDirective(Ye.printMode)!==Qr.LaTeX?(r+="(",r+=Fu(t,!0,!1,n),r+=")"):r+=Fu(t,!0,!1,n):se(t)||oe(t)?(r+="(",r+=gu(t,n),r+=")"):h(t)&&(ae(t,y)||wo(t))?(r+="(",r+=Fu(t,!1,!1,n),r+=")"):r+=Fu(t,!1,!1,n),n.getDirective(Ye.printMode)===Qr.Human?n.getDirective(Ye.useCaretForExponentiation)?r+="^":r+="**":n.getDirective(Ye.printMode)===Qr.LaTeX||n.getDirective(Ye.useCaretForExponentiation)?r+="^":r+="**",n.getDirective(Ye.printMode)===Qr.LaTeX?gu(e,n).length>1?(r+="{",r+=gu(e,n),r+="}"):r+=gu(e,n):Fe(e)||wo(e)||h(e)&&ae(e,y)?(r+="(",r+=gu(e,n),r+=")"):r+=Fu(e,!1,!1,n)),r}function Fu(t,i=!1,s=!1,o){$e(t);const a=i;if(h(t)){if(s&&ae(t,y)){let e="";return e+="(",e+=ou(t,s,o),e+=")",e}return ou(t,s,o)}if(Oe(t)){const r=o.handlerFor(t);switch(o.getDirective(Ye.printMode)){case Qr.Human:return kt(r.dispatch(t,e(n.human),qe,o));case Qr.Infix:{const i=r.dispatch(t,e(n.infix),qe,o);if(O(i))return kt(i);throw q(i)?i:new Fr}case Qr.LaTeX:return kt(r.dispatch(t,e(n.latex),qe,o));case Qr.SExpr:return kt(r.dispatch(t,e(n.sexpr),qe,o));default:throw new Error(`${o.getDirective(Ye.printMode)}`)}}if(Fe(t)&&Xa(t)){let e="";return a||"-"!==xu(t)&&o.getDirective(Ye.printMode)===Qr.LaTeX||(o.getDirective(Ye.printMode)===Qr.LaTeX?e+=" \\left (":e+="("),e+=gu(t,o),a||"-"!==xu(t)&&o.getDirective(Ye.printMode)===Qr.LaTeX||(o.getDirective(Ye.printMode)===Qr.LaTeX?e+=" \\right ) ":e+=")"),e}if(Va(t)){let e="";return a||(e+="("),e+=gu(t,o),a||(e+=")"),e}if(Ka(t))return Mu(t.base,t.expo,o);if(Fe(t)){const e=t.opr,n=t.argList;try{if(e.equals(Zi)){let t="";const e=n.item(1);try{if(o.getDirective(Ye.printMode)!==Qr.EcmaScript){const e=n.item(0);try{t+="fn ";t+=au(e,o),t+=" -> "}finally{e.release()}}return t+=gu(e,o),t}finally{e.release()}}else if(e.equals(Ji)){let t="";const e=n.item(0);try{if(o.getDirective(Ye.printMode)!==Qr.EcmaScript){const e=n.item(1);try{t+="function ";t+=au(e,o),t+=" -> "}finally{e.release()}}return t+=gu(e,o),t}finally{e.release()}}}finally{e.release(),n.release()}}if(Te(t).equals(fs)){let e="";return e+=gu(eu(t),o),o.getDirective(Ye.printMode)===Qr.LaTeX?e+=" \\rightarrow ":o.getDirective(Ye.printMode)===Qr.Human?e+=" -> ":e+="->",e+=gu(Te(Pe(Wa(t))),o),e}if(Te(t).equals(hu)&&S(Wa(t))){let e="";return e+=function(t,e){let n="";if(Qa(t=Pe(t)).equals(ui)||Qa(t).equals(us)||Qa(t).equals(hs)||Qa(t).equals(Vi)?n+=qu(Te(t),e):n+=gu(Te(t),e),n+="[",t=Pe(t),Fe(t))for(n+=gu(Te(t),e),t=Pe(t);Fe(t);)n+=",",n+=gu(Te(t),e),t=Pe(t);return n+="]",n}(t,o),e}if(Fe(t)&&Za(t))return function(t,e){let n="";return wo(t=Wa(t))||Va(t)||Xa(t)||Ka(t)||Za(t)?n+=qu(t,e):n+=gu(t,e),n+="!",n}(t,o);if(Fe(t)&&Ha(t))switch(o.getDirective(Ye.printMode)){case Qr.Human:case Qr.Infix:return function(t,e){let n="";return n+="abs(",n+=gu(t.argList.head,e),n+=")",n}(t,o);case Qr.LaTeX:return function(t,e){let n="";return n+="\\left |",n+=gu(t.argList.head,e),n+=" \\right |",n}(t,o);default:throw new Fr}else{if(Te(t).equals(Os)&&o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="";return n+="\\sqrt{",n+=gu(Wa(t),e),n+="} ",n}(t,o),e}if(ja(t)){if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="";return n+="{",Fe(Wa(t))&&(n+="("),n+=gu(Wa(t),e),Fe(Wa(t))&&(n+=")"),n+="}",n+="^T",n}(t,o),e}if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="";return n+="transpose(",n+=gu(Wa(t),e),n+=")",n}(t,o),e}}else if(Te(t).equals(Is)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="";return n+="identity(",n+=gu(Wa(t),e),n+=")",n}(t,o),e}}else if(Fe(t)&&ue(t)){if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="";return n+="{",Fe(Wa(t))&&(n+="("),n+=gu(Wa(t),e),Fe(Wa(t))&&(n+=")"),n+="}",n+="^{-1}",n}(t,o),e}if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="";return n+="inv(",n+=gu(Wa(t),e),n+=")",n}(t,o),e}}else{if(Te(t).equals(yi)&&o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="";return n+="\\binom{",n+=gu(Wa(t),e),n+="}{",n+=gu(nu(t),e),n+="} ",n}(t,o),e}if(Te(t).equals(ki)&&o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="";const r=Te(Pe(t)),i=t=Pe(t);let s=0;for(;Fe(Pe(Pe(t)));){s++;const r=Pe(Pe(t));n+="\\int^{",n+=gu(Te(Pe(r)),e),n+="}_{",n+=gu(Te(r),e),n+="} \\! ",t=Pe(r)}n+=gu(r,e),n+=" \\,",t=i;for(let r=1;r<=s;r++){const i=Pe(t);n+=" \\mathrm{d} ",n+=gu(Te(i),e),r<s&&(n+=" \\, "),t=Pe(Pe(i))}return n}(t,o),e}if(oe(t)){if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="";return n+=gu(Wa(t),e),n+=" \\cdot ",n+=gu(nu(t),e),n}(t,o),e}if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="dot(";return n+=gu(Wa(t),e),n+=", ",n+=gu(nu(t),e),n+=")",n}(t,o),e}}else if(Te(t).equals(_s)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="Math.sin(";return n+=gu(Wa(t),e),n+=")",n}(t,o),e}}else if(Te(t).equals(Fi)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="Math.cos(";return n+=gu(Wa(t),e),n+=")",n}(t,o),e}}else if(Te(t).equals(Ms)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="Math.tan(";return n+=gu(Wa(t),e),n+=")",n}(t,o),e}}else if(Te(t).equals(di)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="Math.asin(";return n+=gu(Wa(t),e),n+=")",n}(t,o),e}}else if(Te(t).equals(fi)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="Math.acos(";return n+=gu(Wa(t),e),n+=")",n}(t,o),e}}else if(Te(t).equals(mi)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="Math.atan(";return n+=gu(Wa(t),e),n+=")",n}(t,o),e}}else if(Te(t).equals(qs)){if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="\\sum_{";return n+=gu(nu(t),e),n+="=",n+=gu(ru(t),e),n+="}^{",n+=gu(iu(t),e),n+="}{",n+=gu(Wa(t),e),n+="}",n}(t,o),e}if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){const n=Wa(t),r=nu(t),i=ru(t),s=iu(t);return"(function(){ var "+gu(r,e)+"; var holderSum = 0; var lowerlimit = "+gu(i,e)+"; var upperlimit = "+gu(s,e)+"; for ("+gu(r,e)+" = lowerlimit; "+gu(r,e)+" < upperlimit; "+gu(r,e)+"++) { holderSum += "+gu(n,e)+"; } return holderSum;})()"}(t,o),e}}else if(Te(t).equals(ms)){if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="\\prod_{";return n+=gu(nu(t),e),n+="=",n+=gu(ru(t),e),n+="}^{",n+=gu(iu(t),e),n+="}{",n+=gu(Wa(t),e),n+="}",n}(t,o),e}if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){const n=Wa(t),r=nu(t),i=ru(t),s=iu(t);return"(function(){ var "+gu(r,e)+"; var holderProduct = 1; var lowerlimit = "+gu(i,e)+"; var upperlimit = "+gu(s,e)+"; for ("+gu(r,e)+" = lowerlimit; "+gu(r,e)+" < upperlimit; "+gu(r,e)+"++) { holderProduct *= "+gu(n,e)+"; } return holderProduct;})()"}(t,o),e}}else if(Te(t).equals(ji)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){const n=Wa(t),r=nu(t),i=ru(t),s=iu(t);return"(function(){ var "+r+"; var lowerlimit = "+gu(i,e)+"; var upperlimit = "+gu(s,e)+"; for ("+r+" = lowerlimit; "+r+" < upperlimit; "+r+"++) { "+gu(n,e)+" } })()"}(t,o),e}}else if(Te(t).equals(Ti)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="";for(t=Pe(t);Fe(t);)n+=gu(Te(t),e),t=Pe(t);return n}(t,o),e}}else if(Te(t).equals(ks)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="(function(){";t=Pe(t);let r=0;for(;Fe(t);){if(Pe(t).isnil){n+="else {",n+="return ("+gu(Te(t),e)+");,$",n+="}";break}r&&(n+=" else "),n+="if ("+gu(Te(t),e)+"){,$",n+="return ("+gu(Wa(t),e)+");,$",n+="}",r++,t=tu(t)}return n+="})()",n}(t,o),e}if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="\\left\\{ \\begin{array}{ll}";for(t=Pe(t);Fe(t);){if(Pe(t).isnil){n+="{",n+=gu(Te(t),e),n+="} & otherwise ",n+=" \\\\\\\\";break}n+="{",n+=gu(Wa(t),e),n+="} & if & ",n+=gu(Te(t),e),n+=" \\\\\\\\",t=tu(t)}return n=n.substring(0,n.length-4),n+"\\end{array} \\right."}(t,o),e}}else if(Te(t).equals(Ts)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+="(("+gu(Wa(t),o)+") < ("+gu(nu(t),o)+"))",e}if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="{";return n+=gu(Wa(t),e),n+="}",n+=" < ",n+="{",n+=gu(nu(t),e),n+"}"}(t,o),e}}else if(Te(t).equals(Ps)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+="(("+gu(Wa(t),o)+") <= ("+gu(nu(t),o)+"))",e}if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="{";return n+=gu(Wa(t),e),n+="}",n+=" \\leq ",n+="{",n+=gu(nu(t),e),n+"}"}(t,o),e}}else if(Te(t).equals(As)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+="(("+gu(Wa(t),o)+") > ("+gu(nu(t),o)+"))",e}if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="{";return n+=gu(Wa(t),e),n+="}",n+=" > ",n+="{",n+=gu(nu(t),e),n+"}"}(t,o),e}}else if(Te(t).equals(Ds)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+="(("+gu(Wa(t),o)+") >= ("+gu(nu(t),o)+"))",e}if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="{";return n+=gu(Wa(t),e),n+="}",n+=" \\geq ",n+="{",n+=gu(nu(t),e),n+"}"}(t,o),e}}else if(Fe(t)&&t.opr.equals(fu)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+="(("+gu(Wa(t),o)+") === ("+gu(nu(t),o)+"))",e}if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=function(t,e){let n="{";return n+=gu(t.lhs,e),n+="}",n+=" = ",n+="{",n+=gu(t.rhs,e),n+"}"}(t,o),e}}else if(Te(t).equals(Ki)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+="Math.floor("+gu(Wa(t),o)+"),$",e}if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=" \\lfloor {"+gu(Wa(t),o)+"} \\rfloor ,$",e}}else if(Te(t).equals(vi)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+="Math.ceiling("+gu(Wa(t),o)+"),$",e}if(o.getDirective(Ye.printMode)===Qr.LaTeX){let e="";return e+=" \\lceil {"+gu(Wa(t),o)+"} \\rceil ,$",e}}else if(Te(t).equals(vs)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+="Math.round("+gu(Wa(t),o)+"),$",e}}else if(Te(t).equals(Es)){if(o.getDirective(Ye.printMode)===Qr.EcmaScript){let e="";return e+=function(t,e){let n="";return n+=gu(Wa(t),e),n+=" = ",n+=gu(nu(t),e),n+="; ",n}(t,o),e}{let e="";return e+=gu(Wa(t),o),e+="=",e+=gu(nu(t),o),e}}}}return function(t,i,s){if($e(t),Fe(t)){let e="";if(e+=Fu(t.car,!1,!1,s),(t=t.cdr).isnil)return e;if(i||(e+="("),Fe(t))for(e+=gu(Te(t),s),t=Pe(t);Fe(t);)e+=",",e+=gu(Te(t),s),t=Pe(t);return i||(e+=")"),e}if(Oe(t))if(q(t));else if(!Ft(t))throw new Fr(`${t}`);if(M(t)){let e="";return e+=t.toString(),e}if(F(t)){let e="";return e+=t.toString(),e}if(S(t)&&r(t,n.derivative))return"d";if(ce(t))return s.getDirective(Ye.printMode)===Qr.EcmaScript?"Math.E":s.getDirective(Ye.printMode)===Qr.LaTeX?"e":s.getSymbolPrintName(uu);if(le(t))return s.getDirective(Ye.printMode)===Qr.LaTeX?"\\pi":s.getSymbolPrintName(lu);if(S(t)){const r=s.handlerFor(t);return s.getDirective(Ye.printMode)===Qr.Infix?kt(r.dispatch(t,e(n.infix),qe,s)):s.getDirective(Ye.printMode)===Qr.LaTeX?kt(r.dispatch(t,e(n.latex),qe,s)):t.key()}if(L(t))return t.printname;if(k(t)){const r=s.handlerFor(t);return s.getDirective(Ye.printMode)===Qr.Infix?kt(r.dispatch(t,e(n.infix),qe,s)):s.getDirective(Ye.printMode)===Qr.LaTeX?kt(r.dispatch(t,e(n.latex),qe,s)):t.key()}if(q(t)){const r=s.handlerFor(t);return kt(r.dispatch(t,e(n.infix),qe,s))}if(D(t))return s.getDirective(Ye.printMode)===Qr.LaTeX?"i":s.getSymbolPrintName(cu);if(Oe(t)){switch(s.getDirective(Ye.printMode)){case Qr.Ascii:case Qr.Human:case Qr.Infix:case Qr.LaTeX:case Qr.SExpr:}throw new Fr(`${t}: ${t.type}`)}if(t.isnil)return s.getSymbolPrintName(e(n.NIL));throw new Fr(`${t} ??? is_cons: ${Fe(t)} is_atom: ${Oe(t)} is_nil: ${Me(t)}`)}(t,a,o)}function Lu(t){return t.getDirective(Ye.printMode)===Qr.LaTeX?"":t.getDirective(Ye.printMode)===Qr.Human?" ":"*"}function ku(t){if(Fe(t)&&Ka(t)){const e=t.cdr;if(Fe(e)){const t=e.car;if(!ce(t)){const t=e.cdr;if(Fe(t)){const e=t.car;return te(e)}}}}return!1}function Du(t,e){e.pushDirective(Ye.printMode,Qr.Infix);try{return gu(t,e).replace(/_/g,"\\_")}finally{e.popDirective()}}function Au(t){if(c(t))return t.isTrue();if(d(t)){if(t.isOne())return!0;if(t.isZero())return!1;throw new Fr(`${t}`)}throw new Fr(`${t}`)}function Pu(t){if(t instanceof Tu)return t.context;throw new Fr((new Error).stack)}class Tu{context;#n=1;constructor(t){if(!t)throw new Fr("ctxt MUST be defined.");this.context=t,t.addRef()}addRef(){this.#n++}release(){this.#n--,0===this.#n&&this.context.release()}hasState(t){return this.context.hasState(t)}getState(t){return this.context.getState(t)}setState(t,e){this.context.setState(t,e)}handlerFor(t){return this.context.handlerFor(t)}addAtomListener(t){throw new Error("Method not implemented.")}removeAtomListener(t){throw new Error("Method not implemented.")}getCellHost(){throw new Error("Method not implemented.")}setCellHost(t){throw new Error("Method not implemented.")}getProlog(){throw new Error("Method not implemented.")}getPrintHandler(){throw new Error("Method not implemented.")}setPrintHandler(t){throw new Error("Method not implemented.")}abs(t){const r=Ae(e(n.arg),t);try{return this.context.valueOf(r)}finally{r.release()}}algebra(t,e){throw new Error("Method not implemented.")}add(...t){const r=Ae(e(n.add),...t);try{return this.context.valueOf(r)}finally{r.release()}}arccos(t){const r=Ae(e(n.arccos),t);try{return this.context.valueOf(r)}finally{r.release()}}arcsin(t){const r=Ae(e(n.arcsin),t);try{return this.context.valueOf(r)}finally{r.release()}}arctan(t){const r=Ae(e(n.arctan),t);try{return this.context.valueOf(r)}finally{r.release()}}arg(t){const r=Ae(e(n.arg),t);try{return this.context.valueOf(r)}finally{r.release()}}clock(t){const r=Ae(e(n.clock),t);try{return this.context.valueOf(r)}finally{r.release()}}conj(t){const r=Ae(e(n.conj),t);try{return this.context.valueOf(r)}finally{r.release()}}cos(t){const r=Ae(e(n.cos),t);try{return this.context.valueOf(r)}finally{r.release()}}clearBindings(){throw new Error("Method not implemented.")}clearOperators(){throw new Error("Method not implemented.")}compareFn(t){return this.context.compareFn(t)}component(t,r){const i=Ae(e(n.component),t,r);try{return this.context.valueOf(i)}finally{i.release()}}defineEvalFunction(t,e){throw new Error("Method not implemented.")}defineFunction(t,e){throw new Error("Method not implemented.")}defineStackFunction(t,e){throw new Error("Method not implemented.")}defineExtension(t){throw new Error("Method not implemented.")}defineUserSymbol(t){throw new Error("Method not implemented.")}derivedEnv(){throw new Error("Method not implemented.")}divide(t,r){c