View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000505 | ascend | compiler | public | 2011-04-06 16:48 | 2011-04-16 11:44 |
Reporter | john | ||||
Assigned To | |||||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | new | Resolution | open | ||
Product Version | 0.9.7 | ||||
Target Version | 1.0 | Fixed in Version | |||
Summary | 0000505: Add support for missing trigonometric functions cot, cosec, etc. | ||||
Description | These functions occasionally appear in textbooks etc, and implementing equations with minimal change from published form makes checking and usability easier. These functions could be added easily, it's just a bit drudge work. Key files: ascParse.y scanner.l (maybe?) func.h func.c safe.h safe.c A complete implementation would include testing via CUnit (both direct calls and evaluation via ASCEND language code) | ||||
Tags | No tags attached. | ||||
|
ujjaval-505.patch (35,346 bytes)
Index: ascend/system/system.c =================================================================== --- ascend/system/system.c (revision 3377) +++ ascend/system/system.c (working copy) @@ -88,12 +88,7 @@ slv_set_instance(sys,inst); #if DOTIME - comptime = tm_cpu_time() - comptime; - if(comptime >= 1e-3){ - CONSOLE_DEBUG("System built (time %5.3f s)",comptime); - }else{ - CONSOLE_DEBUG("System built (time <1ms)"); - } + FPRINTF(stderr,"Time to build system = %g s (outputs zero for build time < 1ms )\n", ((tm_cpu_time() - comptime)>=0.00001)?(tm_cpu_time()-comptime):0); #endif return(sys); } Index: ascend/compiler/func.c =================================================================== --- ascend/compiler/func.c (revision 3377) +++ ascend/compiler/func.c (working copy) @@ -121,6 +121,58 @@ return ldexp(tan(d)/(t*t),1); } +double cosec(register double d) +{ + enum safe_err *safe = safe_range_error; + d = (d==0)?2*F_PI:d; + return safe_rec(sin(d),safe); +} + +double dcosec(register double d) +{ + register double t; + enum safe_err *safe = safe_range_error; + t = -safe_rec(tan(d),safe); + return cosec(d)*t; +} +double dcosec2(register double d) +{ + return cube(cosec(d)) - dcosec(d)/tan(d) ; +} + +double sec(register double d) +{ + enum safe_err *safe = safe_range_error; + + return safe_rec(cos(d),safe); +} + +double dsec(register double d) +{ + return sec(d)*tan(d); +} +double dsec2(register double d) +{ + return sec(d)*dtan(d) + tan(d)*dsec(d); +} + +double cot(register double d) +{ + enum safe_err *safe = safe_range_error; + d = (d==0)? 2.0*F_PI:d; + return cos(d)*safe_rec(sin(d),safe); +} + +double dcot(register double d) +{ + return -sqr(cosec(d)); +} +double dcot2(register double d) +{ + return -2.0*cosec(d)*dcosec(d); +} + + double sqr(register double d) { return d*d; @@ -291,6 +343,86 @@ return -ldexp(d/(1.0+d*d),1); } +double acosec(register double d) +{ + if (fabs(d) < 1.0 ) { + FPRINTF(stderr,"ERROR:\t(calc) acosec\n"); + FPRINTF(stderr, + "\tacosec(%g) undefined.\n",d); + FPRINTF(stderr,"\tReturning %g.\n",0.0); + return(0.0); + } + + return asin(1/d); +} + +double dacosec(register double d) +{ + if (fabs(d) <= 1.0 ) { + FPRINTF(stderr,"ERROR:\t(calc) dacosec\n"); + FPRINTF(stderr, + "\tdacosec(%g) undefined.\n",d); + FPRINTF(stderr,"\tReturning %g.\n",0.0); + return(0.0); + } + enum safe_err *safe = safe_range_error; + return safe_rec(d*sqrt(d*d - 1) ,safe); +} + +double dacosec2(register double d) +{ + if (fabs(d) <= 1.0 ) { + FPRINTF(stderr,"ERROR:\t(calc) dacosec2\n"); + FPRINTF(stderr, + "\tdacosec2(%g) undefined.\n",d); + FPRINTF(stderr,"\tReturning %g.\n",0.0); + return(0.0); + } + return (2*d*d - 1)/(d*d*(d*d - 1)*sqrt(d*d - 1)); +} + +double asec(register double d) +{ + if (fabs(d) < 1 ) { + FPRINTF(stderr,"ERROR:\t(calc) asec\n"); + FPRINTF(stderr, + "\tasec(%g) undefined.\n",d); + FPRINTF(stderr,"\tReturning %g.\n",0.0); + return(0.0); + } + + return acos(1/d); +} + +double dasec(register double d) +{ + return -dacosec(d) ; +} + +double dasec2(register double d) +{ + return -dacosec2(d); +} + +double acot(register double d) +{ + if(d >=0 && d <= 1.0e-08) + return F_PI_HALF; + else if (d < 0 && d >= -1.0e-08) + return - F_PI_HALF ; + return atan(1/d); +} + +double dacot(register double d) +{ + return -datan(d); +} + +double dacot2(register double d) +{ + return -datan2(d); +} + #ifdef HAVE_ERF double derf(register double d) { @@ -317,7 +449,60 @@ c = cosh(d); return -ldexp(tanh(d),1)/(c*c); } +/////////////////////////////////// +double cosech(register double d) +{ + enum safe_err *safe = safe_range_error; + d = (d==0)? 1.0e-06:d; + return safe_rec(sinh(d),safe); +} + +double dcosech(register double d) +{ + register double t; + enum safe_err *safe = safe_range_error; + t = -safe_rec(tanh(d),safe); + return cosech(d)*t; +} +double dcosech2(register double d) +{ + return cube(cosech(d)) - dcosech(d)/tanh(d) ; +} + +double sech(register double d) +{ + enum safe_err *safe = safe_range_error; + + return safe_rec(cosh(d),safe); +} + +double dsech(register double d) +{ + return -sech(d)*tanh(d); +} +double dsech2(register double d) +{ + return - (sech(d)*dtanh(d) + tanh(d)*dsech(d) ); +} + +double coth(register double d) +{ + enum safe_err *safe = safe_range_error; + d = (d==0)? 1.0e-06:d; + return cosh(d)*safe_rec(sinh(d),safe); +} + +double dcoth(register double d) +{ + return -sqr(cosech(d)); +} +double dcoth2(register double d) +{ + return -2.0*cosech(d)*dcosech(d); +} + +/////////////////////////////////// double arcsinh(register double d) { return log(d+sqrt(d*d+1.0)); @@ -376,6 +561,76 @@ return ldexp( d/(c*c) ,1); } +double arccosech(register double d) +{ + if(d >= 0 && d < 1.0e-09) + return 30; + if(d < 0 && d > -1.0e-09) + return -30; + return arcsinh(1/d); +} + +double darccosech(register double d) +{ + enum safe_err *safe = safe_range_error; + return -(safe_rec(fabs(d)*sqrt(1 + d*d),safe)); +} + +double darccosech2(register double d) +{ + enum safe_err *safe = safe_range_error; + double term = (2*d*d + 1)*(safe_rec(d*d*(sqrt(1 + d*d))*(1 + d*d),safe)); + if(d<0) term = -term; + return term; +} + +double arcsech(register double d) +{ + if(d > 0 && d < 1.0e-09) + return 30; + if (d <= 0 || d > 1) { + FPRINTF(stderr,"ERROR:\t(calc) arcsech\n"); + FPRINTF(stderr, + "\tarcsech(%g) undefined.\n",d); + FPRINTF(stderr,"\tReturning %g.\n",0.0); + return(0.0); + } + + return arccosh(1/d); +} + +double darcsech(register double d) +{ + enum safe_err *safe = safe_range_error; + return -(safe_rec(d*sqrt(1 - d*d),safe)); +} + +double darcsech2(register double d) +{ + enum safe_err *safe = safe_range_error; + return safe_rec(d*d*(sqrt(1 - d*d))*(1 - d*d),safe); +} + +double arccoth(register double d) +{ + if (fabs(d) <= 1.0 ) { + FPRINTF(stderr,"ERROR:\t(calc) arccoth\n"); + FPRINTF(stderr, + "\tarccoth(%g) undefined.\n",d); + FPRINTF(stderr,"\tReturning %g.\n",0.0); + return(0.0); + } + return arctanh(1/d); +} +double darccoth(register double d) +{ + return darctanh(d); +} +double darccoth2(register double d) +{ + return darctanh2(d); +} + #ifdef CHRIS_FUNC void ExpSlope(unsigned long int nvar, struct Interval *center, struct Interval *range, @@ -780,6 +1035,83 @@ #endif }; +struct Func g_cosec_f = { + "cosec", + "cosec", + "Cosec", + "dcosec", + "dcosec2", + F_COSEC, + cosec, + dcosec, + dcosec2, + safe_cosec_D0, + safe_cosec_D1, + safe_cosec_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; +struct Func g_sec_f = { + "sec", + "sec", + "Sec", + "dsec", + "dsec2", + F_SEC, + sec, + dsec, + dsec2, + safe_sec_D0, + safe_sec_D1, + safe_sec_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + +struct Func g_cot_f = { + "cot", + "cot", + "Cot", + "dcot", + "dcot2", + F_COT, + cot, + dcot, + dcot2, + safe_cot_D0, + safe_cot_D1, + safe_cot_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + struct Func g_sqr_f = { "sqr", "sqr", @@ -962,6 +1294,84 @@ #endif }; +struct Func g_arccosec_f = { + "arccosec", + "acosec", + "ArcCosec", + "dacosec", + "dacosec2", + F_ARCCOSEC, + acosec, + dacosec, + dacosec2, + safe_arccosec_D0, + safe_arccosec_D1, + safe_arccosec_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + +struct Func g_arcsec_f = { + "arcsec", + "asec", + "ArcSec", + "dasec", + "dasec2", + F_ARCSEC, + asec, + dasec, + dasec2, + safe_arcsec_D0, + safe_arcsec_D1, + safe_arcsec_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + +struct Func g_arccot_f = { + "arccot", + "acot", + "ArcCot", + "dacot", + "dacot2", + F_ARCCOT, + acot, + dacot, + dacot2, + safe_arccot_D0, + safe_arccot_D1, + safe_arccot_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + #ifdef HAVE_ERF struct Func g_erf_f = { "erf", @@ -1062,6 +1472,84 @@ #endif }; +struct Func g_cosech_f = { + "cosech", + "cosech", + "Cosech", /** FIXME Yacas does not have an equivalent for Cosech??? */ + "dcosech", + "dcosech2", + F_COSECH, + cosech, + dcosech, + dcosech2, + safe_cosech_D0, + safe_cosech_D1, + safe_cosech_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + +struct Func g_sech_f = { + "sech", + "sech", + "sech", /** FIXME Yacas does not have an equivalent for Sech??? */ + "dsech", + "dsech2", + F_SECH, + sech, + dsech, + dsech2, + safe_sech_D0, + safe_sech_D1, + safe_sech_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + +struct Func g_coth_f = { + "coth", + "coth", + "Coth", /** FIXME Yacas does not have an equivalent for Coth??? */ + "dcoth", + "dcoth2", + F_COSECH, + coth, + dcoth, + dcoth2, + safe_coth_D0, + safe_coth_D1, + safe_coth_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + struct Func g_arcsinh_f = { "arcsinh", "arcsinh", @@ -1140,6 +1628,85 @@ #endif }; +struct Func g_arccosech_f = { + "arccosech", + "arccosech", + "ArcCosech", /** FIXME Yacas does not have an equivalent for ArcCosech??? */ + "darccosech", + "darccosech2", + F_ARCCOSECH, + arccosech, + darccosech, + darccosech2, + safe_arccosech_D0, + safe_arccosech_D1, + safe_arccosech_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + +struct Func g_arcsech_f = { + "arcsech", + "arcsech", + "ArcSech", /** FIXME Yacas does not have an equivalent for ArcCosech??? */ + "darcsech", + "darcsech2", + F_ARCSECH, + arcsech, + darcsech, + darcsech2, + safe_arcsech_D0, + safe_arcsech_D1, + safe_arcsech_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + +struct Func g_arccoth_f = { + "arccoth", + "arccoth", + "ArcCoth", /** FIXME Yacas does not have an equivalent for ArcCosh??? */ + "darccoth", + "darccoth2", + F_ARCCOTH, + arccoth, + darccoth, + darccoth2, + safe_arccoth_D0, + safe_arccoth_D1, + safe_arccoth_D2, +#ifdef CHRIS_FUNC + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +#endif +}; + + struct Func g_cube_f = { "cube", "cube", @@ -1200,11 +1767,17 @@ &g_sin_f, &g_cos_f, &g_tan_f, + &g_cosec_f, + &g_sec_f, + &g_cot_f, &g_sqr_f, &g_sqrt_f, &g_arcsin_f, &g_arccos_f, &g_arctan_f, + &g_arccosec_f, + &g_arcsec_f, + &g_arccot_f, #ifdef HAVE_ERF &g_erf_f, #endif /* HAVE_ERF */ @@ -1212,9 +1785,15 @@ &g_sinh_f, &g_cosh_f, &g_tanh_f, + &g_cosech_f, + &g_sech_f, + &g_coth_f, &g_arcsinh_f, &g_arccosh_f, &g_arctanh_f, + &g_arccosech_f, + &g_arcsech_f, + &g_arccoth_f, &g_cube_f, &g_cbrt_f, &g_abs_f, @@ -1288,6 +1867,8 @@ case F_ARCSIN: case F_ARCCOS: case F_ARCTAN: + case F_ARCCOSEC: + case F_ARCSEC: case F_SINH: case F_COSH: case F_TANH: @@ -1305,6 +1886,8 @@ case F_SIN: case F_COS: case F_TAN: + case F_COSEC: + case F_SEC: return TrigDimension(); default: return Dimensionless(); } Index: ascend/compiler/func.h =================================================================== --- ascend/compiler/func.h (revision 3377) +++ ascend/compiler/func.h (working copy) @@ -89,11 +89,17 @@ * "sin" sine of x * "cos" cosine of x * "tan" tangent of x + * "cosec" cosecant of x + * "sec" secant of x + * "cot" cotangant of x * "sqr" x*x * "sqrt" the square root of x * "arcsin" the inverse sine of x * "arccos" the inverse cosine of x * "arctan" the inverse tangent of x + * "arccosec" the inverse cosecant of x + * "arcsec" the inverse secant of x + * "arccot" the inverse cotangent of x * * "erf" the error function * "lnm" modified natural log: @@ -101,9 +107,15 @@ * "sinh" hyperbolic sine * "cosh" hyperbolic cosine * "tanh" hyperbolic tangent + * "cosech" hyperbolic cosecant + * "sech" hyperbolic secant + * "coth" hyperbolic cotangent * "arcsinh" inv hyperbolic sine * "arccosh" inv hyperbolic cosine * "arctanh" inv hyperbolic tangent + * "arccosech" inv hyperbolic cosecant + * "arcsech" inv hyperbolic secant + * "arccoth" inv hyperbolic cotangent * * "cube" the cube of x * "cbrt" the cube root of x @@ -202,15 +214,36 @@ ASC_DLLSPEC double dtanh(double x); ASC_DLLSPEC double dtanh2(double x); + +ASC_DLLSPEC double cosech(register double d); +ASC_DLLSPEC double dcosech(register double d); +ASC_DLLSPEC double dcosech2(register double d); +ASC_DLLSPEC double sech(register double d); +ASC_DLLSPEC double dsech(register double d); +ASC_DLLSPEC double dsech2(register double d); +ASC_DLLSPEC double coth(register double d); +ASC_DLLSPEC double dcoth(register double d); +ASC_DLLSPEC double dcoth2(register double d); + ASC_DLLSPEC double arcsinh(double x); ASC_DLLSPEC double arccosh(double x); ASC_DLLSPEC double arctanh(double x); +ASC_DLLSPEC double arccosech(double x); +ASC_DLLSPEC double arcsech(double x); +ASC_DLLSPEC double arccoth(double x); ASC_DLLSPEC double darcsinh(double x); ASC_DLLSPEC double darcsinh2(double x); ASC_DLLSPEC double darccosh(double x); ASC_DLLSPEC double darccosh2(double x); ASC_DLLSPEC double darctanh(double x); ASC_DLLSPEC double darctanh2(double x); +ASC_DLLSPEC double darccosech(double x); +ASC_DLLSPEC double darccosech2(double x); +ASC_DLLSPEC double darcsech(double x); +ASC_DLLSPEC double darcsech2(double x); +ASC_DLLSPEC double darccoth(double x); +ASC_DLLSPEC double darccoth2(double x); + /**< * Zero, first and second partials of (inverse) hyperbolic functions. */ @@ -276,6 +309,26 @@ ASC_DLLSPEC double dtan2(double x); ASC_DLLSPEC double datan(double x); ASC_DLLSPEC double datan2(double x); + +ASC_DLLSPEC double cosec(register double d); +ASC_DLLSPEC double dcosec(register double d); +ASC_DLLSPEC double dcosec2(register double d); +ASC_DLLSPEC double sec(register double d); +ASC_DLLSPEC double dsec(register double d); +ASC_DLLSPEC double dsec2(register double d); +ASC_DLLSPEC double cot(register double d); +ASC_DLLSPEC double dcot(register double d); +ASC_DLLSPEC double dcot2(register double d); + +ASC_DLLSPEC double arccosec(register double d); +ASC_DLLSPEC double darccosec(register double d); +ASC_DLLSPEC double darccosec2(register double d); +ASC_DLLSPEC double arcsec(register double d); +ASC_DLLSPEC double darcsec(register double d); +ASC_DLLSPEC double darcsec2(register double d); +ASC_DLLSPEC double arccot(register double d); +ASC_DLLSPEC double darccot(register double d); +ASC_DLLSPEC double darccot2(register double d); /**< * First and second partials of the cosine, tangent, arctangent functions */ Index: ascend/compiler/functype.h =================================================================== --- ascend/compiler/functype.h (revision 3377) +++ ascend/compiler/functype.h (working copy) @@ -63,14 +63,14 @@ /** Function enumeration. */ enum Func_enum { F_LOG10, F_LN, F_EXP, - F_SIN, F_COS, F_TAN, - F_ARCSIN, F_ARCCOS, F_ARCTAN, + F_SIN, F_COS, F_TAN, F_COSEC,F_SEC,F_COT, + F_ARCSIN, F_ARCCOS, F_ARCTAN, F_ARCCOSEC, F_ARCSEC, F_ARCCOT, F_SQR, F_SQRT, #ifdef HAVE_ERF F_ERF, #endif - F_LNM, F_SINH, F_COSH, F_TANH, - F_ARCSINH, F_ARCCOSH, F_ARCTANH, + F_LNM, F_SINH, F_COSH, F_TANH, F_COSECH, F_SECH, F_COTH, + F_ARCSINH, F_ARCCOSH, F_ARCTANH, F_ARCCOSECH, F_ARCSECH, F_ARCCOTH, F_CUBE, F_CBRT, F_ABS, F_HOLD }; Index: ascend/compiler/relation.c =================================================================== --- ascend/compiler/relation.c (revision 3377) +++ ascend/compiler/relation.c (working copy) @@ -401,6 +401,9 @@ } else { return -1; /* dimensional incompatibility */ } + case F_COSEC: + case F_SEC: + case F_COT: case F_COS: if (IsWild(TermDimensions(arg)) || SameDimen(TermDimensions(arg),TrigDimension())) { @@ -429,6 +432,13 @@ case F_ARCSINH: case F_TANH: case F_ARCTANH: + case F_COTH: + case F_ARCCOTH: + case F_SECH: + case F_ARCSECH: + case F_COSECH: + case F_ARCCOSECH: + if (IsWild(TermDimensions(arg)) || SameDimen(TermDimensions(arg),Dimensionless())) { arg->t = e_nop; @@ -492,6 +502,8 @@ } case F_ARCSIN: case F_ARCTAN: + case F_ARCCOSEC: + case F_ARCCOT: if (IsWild(TermDimensions(arg)) || SameDimen(TermDimensions(arg),Dimensionless())) { arg->t = e_nop; @@ -503,6 +515,7 @@ return -1; /* dimensional incompatibility */ } case F_ARCCOS: + case F_ARCSEC: if (IsWild(TermDimensions(arg)) || SameDimen(TermDimensions(arg),Dimensionless())) { arg->t = e_nop; @@ -639,6 +652,9 @@ return -1; /* dimensional incompatibility */ } case F_ARCTAN: + case F_ARCCOSEC: + case F_ARCSEC: + case F_ARCCOT: if (IsWild(TermDimensions(arg)) || SameDimen(TermDimensions(arg),Dimensionless())) { newdim = TrigDimension(); Index: ascend/compiler/exprsym.c =================================================================== --- ascend/compiler/exprsym.c (revision 3377) +++ ascend/compiler/exprsym.c (working copy) @@ -602,8 +602,12 @@ switch(id) { case F_SIN: case F_SINH: /* these are the odd functions */ case F_TAN: case F_TANH: /* sin (-x) = - sin (x) */ + case F_COSEC: case F_COSECH: + case F_COT: case F_COTH: case F_ARCSIN: case F_ARCSINH: case F_ARCTAN: case F_ARCTANH: + case F_ARCCOSEC: case F_ARCCOSECH: + case F_ARCCOT: case F_ARCCOTH: #ifdef HAVE_ERF case F_ERF: #endif /* HAVE_ERF */ @@ -612,8 +616,10 @@ result = CreateDTermFunc(TermUniLeft(term),fptr); result = MakeUMinus(result); return result; - case F_COS: case F_COSH: /* these are the even functions */ + case F_COS: case F_COSH: + case F_SEC: case F_SECH: /* these are the even functions */ case F_ARCCOS: case F_SQR: /* cos (-x) = cos(x) */ + case F_ARCSEC: case F_ARCSECH: result = CreateDTermFunc(TermUniLeft(term),fptr); return result; default: @@ -865,6 +871,41 @@ e = MakeFunc(F_SQR,e); e = MakeDivide(du_dx,e); return e; + case F_COSEC: + e = MakeFunc(F_TAN,left); + e = MakeDivide(du_dx,e); + e = MakeMultiply(F_COSEC,e); + e = MakeNegation(e); + return e; + case F_COSECH: + e = MakeFunc(F_TANH,left); + e = MakeDivide(du_dx,e); + e = MakeMultiply(F_COSECH,e); + e = MakeNegation(e); + return e; + case F_SEC: + e = MakeFunc(F_SEC,left); + e = MakeMultiply(F_TAN,e); + e = MakeMultiply(du_dx,e); + return e; + case F_SECH: + e = MakeFunc(F_SECH,left); + e = MakeMultiply(F_TANH,e); + e = MakeMultiply(du_dx,e); + e = MakeNegation(e); + return e; + case F_COT: + e = MakeFunc(F_COSEC,left); + e = MakeFunc(F_SQR,e); + e = MakeNegation(e); + e = MakeMultiply(du_dx,e); + return e; + case F_COTH: + e = MakeFunc(F_COSECH,left); + e = MakeFunc(F_SQR,e); + e = MakeNegation(e); + e = MakeMultiply(du_dx,e); + return e; case F_ARCSIN: e = MakeFunc(F_SQR,left); e = MakeSubtract(K_TERM(&One),e); @@ -896,10 +937,50 @@ e = MakeDivide(du_dx,e); return e; case F_ARCTANH: + case F_ARCCOTH: e = MakeFunc(F_SQR,left); e = MakeSubtract(K_TERM(&One),e); e = MakeDivide(du_dx,e); return e; + case F_ARCCOSEC: + e = MakeFunc(F_SQR,left); + e = MakeSubtract(e,K_TERM(&One)); + e = MakeFunc(F_SQRT,e); + e = MakeMultiply(e,left); + e = MakeDivide(du_dx,e); + e = MakeNegation(e); + return e; + case F_ARCCOSECH: + e = MakeFunc(F_SQR,left); + e = MakeAdd(K_TERM(&One),e); + e = MakeFunc(F_SQRT,e); + e = MakeMultiply(e,left); + e = MakeDivide(du_dx,e); + e = MakeNegation(e); + return e; + + case F_ARCSECH: + e = MakeFunc(F_SQR,left); + e = MakeSubtract(K_TERM(&One),e); + e = MakeFunc(F_SQRT,e); + e = MakeMultiply(e,left); + e = MakeDivide(du_dx,e); + e = MakeNegation(e); + return e; + + case F_ARCSEC: + e = MakeFunc(F_SQR,left); + e = MakeSubtract(e,K_TERM(&One)); + e = MakeFunc(F_SQRT,e); + e = MakeMultiply(e,left); + e = MakeDivide(du_dx,e); + return e; + case F_ARCCOT: + e = MakeFunc(F_SQR,left); + e = MakeAdd(K_TERM(&One),e); + e = MakeDivide(du_dx,e); + e = MakeNegation(e); + return e; #ifdef HAVE_ERF case F_ERF: e = MakeFunc(F_SQR,left); Index: ascend/compiler/safe.c =================================================================== --- ascend/compiler/safe.c (revision 3377) +++ ascend/compiler/safe.c (working copy) @@ -377,6 +377,72 @@ return( tanh(x) ); } +double safe_cosec_D0(double x,enum safe_err *safe) +{ + if(sin(x) == 0 ) { + double bogus = BIGNUM; + + *safe = safe_range_error; + return(bogus); + } + return( 1.0/sin(x) ); +} + +double safe_cosech_D0(double x,enum safe_err *safe) +{ + if(sinh(x) == 0 ) { + double bogus = BIGNUM; + + *safe = safe_range_error; + return(bogus); + } + return( 1.0/sinh(x) ); +} + +double safe_sec_D0(double x,enum safe_err *safe) +{ + if(cos(x) == 0 ) { + double bogus = BIGNUM; + + *safe = safe_range_error; + return(bogus); + } + return( 1.0/cos(x) ); +} + +double safe_sech_D0(double x,enum safe_err *safe) +{ + if(cosh(x) == 0 ) { + double bogus = BIGNUM; + + *safe = safe_range_error; + return(bogus); + } + return( 1.0/cosh(x) ); +} + +double safe_cot_D0(double x,enum safe_err *safe) +{ + if(tan(x) == 0 ) { + double bogus = BIGNUM; + + *safe = safe_range_error; + return(bogus); + } + return( 1.0/tan(x) ); +} + +double safe_coth_D0(double x,enum safe_err *safe) +{ + if(tanh(x) == 0 ) { + double bogus = BIGNUM; + + *safe = safe_range_error; + return(bogus); + } + return( 1.0/tanh(x) ); +} + double safe_arcsin_D0(double x,enum safe_err *safe) { if( x < -1.0 || 1.0 < x ) { @@ -442,6 +508,42 @@ return( arctanh(x) ); } +double safe_arccosec_D0(double x,enum safe_err *safe) +{ + (void)safe; + return( acosec(x) ); +} + +double safe_arcsec_D0(double x,enum safe_err *safe) +{ + (void)safe; + return( asec(x) ); +} + +double safe_arccot_D0(double x,enum safe_err *safe) +{ + (void)safe; + return( acot(x) ); +} + +double safe_arccosech_D0(double x,enum safe_err *safe) +{ + (void)safe; + return( arccosech(x) ); +} + +double safe_arcsech_D0(double x,enum safe_err *safe) +{ + (void)safe; + return( arcsech(x) ); +} + +double safe_arccoth_D0(double x,enum safe_err *safe) +{ + (void)safe; + return( arccoth(x) ); +} + #ifdef HAVE_ERF double safe_erf_D0(double x,enum safe_err *safe) { @@ -570,6 +672,60 @@ return( dtanh(x) ); } +double safe_cosec_D1(double x,enum safe_err *safe) +{ + return ( safe_mul_D0(-cosec(x),safe_rec(tan(x),safe),safe) ); +} + +double safe_cosech_D1(double x,enum safe_err *safe) +{ + if(sinh(x) == 0 ) { + double bogus = BIGNUM; + + *safe = safe_range_error; + return(bogus); + } + + else if (x < -200 || x > 200) { + return 0.0; + } + return( dcosech(x) ); +} + +double safe_sec_D1(double x,enum safe_err *safe) +{ + return ( safe_mul_D0(sec(x),tan(x),safe) ); +} + +double safe_sech_D1(double x,enum safe_err *safe) +{ + (void)safe; + if (x < -200 || x > 200) { + return 0.0; + } + return( dsech(x) ); +} + +double safe_cot_D1(double x,enum safe_err *safe) +{ + return ( -safe_sqr_D0(safe_cosec_D0(x,safe),safe) ); +} + +double safe_coth_D1(double x,enum safe_err *safe) +{ + if(sinh(x) == 0 ) { + double bogus = BIGNUM; + + *safe = safe_range_error; + return(bogus); + } + + else if (x < -200 || x > 200) { + return 0.0; + } + return( dcoth(x) ); +} + double safe_arcsin_D1(double x,enum safe_err *safe) { return( safe_rec(safe_sqrt_D0(1.0 - safe_sqr_D0(x,safe),safe),safe) ); @@ -592,8 +748,7 @@ } double safe_arctan_D1(double x,enum safe_err *safe) -{ - (void)safe; +{ (void)safe; return( datan(x) ); } @@ -602,6 +757,42 @@ return( safe_rec(1.0 - safe_sqr_D0(x,safe),safe) ); } +double safe_arccosec_D1(double x,enum safe_err *safe) +{ + (void)safe; + return( dacosec(x) ); +} + +double safe_arccosech_D1(double x,enum safe_err *safe) +{ + (void)safe; + return( darccosech(x) ); +} + +double safe_arcsec_D1(double x,enum safe_err *safe) +{ + (void)safe; + return(- dacosec(x) ); +} + +double safe_arcsech_D1(double x,enum safe_err *safe) +{ + (void)safe; + return( darcsech(x) ); +} + +double safe_arccot_D1(double x,enum safe_err *safe) +{ + (void)safe; + return(- datan(x) ); +} + +double safe_arccoth_D1(double x,enum safe_err *safe) +{ + (void)safe; + return( darccoth(x) ); +} + #ifdef HAVE_ERF double safe_erf_D1(double x,enum safe_err *safe) { @@ -709,6 +900,59 @@ return( dtanh2(x) ); } +double safe_cosec_D2(double x,enum safe_err *safe) +{ + double t1,t2; + t1 = cube(safe_cosec_D0(cosec(x),safe)); + t2 = safe_cosec_D1(x,safe) * safe_rec(tan(x),safe); + return safe_add_D0(t1,-t2,safe); +} + +double safe_cosech_D2(double x,enum safe_err *safe) +{ + if( fabs(sinh(x)) == 0.0 ) { + double bogus = BIGNUM; + if( safe_print_errors ) { + ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"cosech_D2: Infinite at %g: returning %g.",x,bogus); + } + *safe = safe_range_error; + return(bogus); + } + return( dcosech2(x) ); +} + +double safe_sec_D2(double x,enum safe_err *safe) +{ + double t1,t2; + t1 = tan(x)*safe_sec_D1(x,safe); + t2 = safe_sec_D0(x,safe)*safe_tan_D1(x,safe); + return safe_add_D0(t1,t2,safe); +} + +double safe_sech_D2(double x,enum safe_err *safe) +{ + (void)safe; + return( dsech2(x) ); +} + +double safe_cot_D2(double x,enum safe_err *safe) +{ + return -2.0 * safe_cosec_D0(x,safe) * safe_cosec_D1(x,safe); +} + +double safe_coth_D2(double x,enum safe_err *safe) +{ + if( fabs(sinh(x)) == 0.0 ) { + double bogus = BIGNUM; + if( safe_print_errors ) { + ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"coth_D2: Infinite at %g: returning %g.",x,bogus); + } + *safe = safe_range_error; + return(bogus); + } + return( dcoth2(x) ); +} + double safe_arcsin_D2(double x,enum safe_err *safe) { register double t; @@ -759,6 +1003,42 @@ return( darctanh2(x) ); } +double safe_arccosec_D2(double x,enum safe_err *safe) +{ + (void)safe; + return( dacosec2(x) ); +} + +double safe_arccosech_D2(double x,enum safe_err *safe) +{ + (void)safe; + return( darccosech2(x) ); +} + +double safe_arcsec_D2(double x,enum safe_err *safe) +{ + (void)safe; + return(- dacosec2(x) ); +} + +double safe_arcsech_D2(double x,enum safe_err *safe) +{ + (void)safe; + return( darcsech2(x) ); +} + +double safe_arccot_D2(double x,enum safe_err *safe) +{ + (void)safe; + return(- datan2(x) ); +} + +double safe_arccoth_D2(double x,enum safe_err *safe) +{ + (void)safe; + return( darccoth2(x) ); +} + #ifdef HAVE_ERF double safe_erf_D2(double x,enum safe_err *safe) { Index: ascend/compiler/safe.h =================================================================== --- ascend/compiler/safe.h (revision 3377) +++ ascend/compiler/safe.h (working copy) @@ -119,12 +119,25 @@ extern double safe_cosh_D0(double x, enum safe_err *safe); extern double safe_tan_D0(double x, enum safe_err *safe); extern double safe_tanh_D0(double x, enum safe_err *safe); +extern double safe_cosec_D0(double x, enum safe_err *safe); +extern double safe_cosech_D0(double x, enum safe_err *safe); +extern double safe_sec_D0(double x, enum safe_err *safe); +extern double safe_sech_D0(double x, enum safe_err *safe); +extern double safe_cot_D0(double x, enum safe_err *safe); +extern double safe_coth_D0(double x, enum safe_err *safe); extern double safe_arctan_D0(double x, enum safe_err *safe); extern double safe_arcsin_D0(double x, enum safe_err *safe); extern double safe_arcsinh_D0(double x, enum safe_err *safe); extern double safe_arccos_D0(double x, enum safe_err *safe); extern double safe_arccosh_D0(double x, enum safe_err *safe); extern double safe_arctanh_D0(double x, enum safe_err *safe); +extern double safe_arccosec_D0(double x, enum safe_err *safe); +extern double safe_arcsec_D0(double x, enum safe_err *safe); +extern double safe_arccot_D0(double x, enum safe_err *safe); +extern double safe_arccosech_D0(double x, enum safe_err *safe); +extern double safe_arcsech_D0(double x, enum safe_err *safe); +extern double safe_arccoth_D0(double x, enum safe_err *safe); + #ifdef HAVE_ERF extern double safe_erf_D0(double x, enum safe_err *safe); #endif /* HAVE_ERF */ @@ -151,12 +164,25 @@ extern double safe_cosh_D1(double x, enum safe_err *safe); extern double safe_tan_D1(double x, enum safe_err *safe); extern double safe_tanh_D1(double x, enum safe_err *safe); +extern double safe_cosec_D1(double x, enum safe_err *safe); +extern double safe_cosech_D1(double x, enum safe_err *safe); +extern double safe_sec_D1(double x, enum safe_err *safe); +extern double safe_sech_D1(double x, enum safe_err *safe); +extern double safe_cot_D1(double x, enum safe_err *safe); +extern double safe_coth_D1(double x, enum safe_err *safe); extern double safe_arcsin_D1(double x, enum safe_err *safe); extern double safe_arcsinh_D1(double x, enum safe_err *safe); extern double safe_arccos_D1(double x, enum safe_err *safe); extern double safe_arccosh_D1(double x, enum safe_err *safe); extern double safe_arctan_D1(double x, enum safe_err *safe); extern double safe_arctanh_D1(double x, enum safe_err *safe); +extern double safe_arccosec_D1(double x, enum safe_err *safe); +extern double safe_arcsec_D1(double x, enum safe_err *safe); +extern double safe_arccot_D1(double x, enum safe_err *safe); +extern double safe_arccosech_D1(double x, enum safe_err *safe); +extern double safe_arcsech_D1(double x, enum safe_err *safe); +extern double safe_arccoth_D1(double x, enum safe_err *safe); + #ifdef HAVE_ERF extern double safe_erf_D1(double x, enum safe_err *safe); #endif /* HAVE_ERF */ @@ -185,12 +211,25 @@ extern double safe_cosh_D2(double x, enum safe_err *safe); extern double safe_tan_D2(double x, enum safe_err *safe); extern double safe_tanh_D2(double x, enum safe_err *safe); +extern double safe_cosec_D2(double x, enum safe_err *safe); +extern double safe_cosech_D2(double x, enum safe_err *safe); +extern double safe_sec_D2(double x, enum safe_err *safe); +extern double safe_sech_D2(double x, enum safe_err *safe); +extern double safe_cot_D2(double x, enum safe_err *safe); +extern double safe_coth_D2(double x, enum safe_err *safe); extern double safe_arcsin_D2(double x, enum safe_err *safe); extern double safe_arcsinh_D2(double x, enum safe_err *safe); extern double safe_arccos_D2(double x, enum safe_err *safe); extern double safe_arccosh_D2(double x, enum safe_err *safe); extern double safe_arctan_D2(double x, enum safe_err *safe); extern double safe_arctanh_D2(double x, enum safe_err *safe); +extern double safe_arccosec_D2(double x, enum safe_err *safe); +extern double safe_arcsec_D2(double x, enum safe_err *safe); +extern double safe_arccot_D2(double x, enum safe_err *safe); +extern double safe_arccosech_D2(double x, enum safe_err *safe); +extern double safe_arcsech_D2(double x, enum safe_err *safe); +extern double safe_arccoth_D2(double x, enum safe_err *safe); + #ifdef HAVE_ERF extern double safe_erf_D2(double x, enum safe_err *safe); #endif /* HAVE_ERF */ Index: ascend/compiler/relation_util.c =================================================================== --- ascend/compiler/relation_util.c (revision 3377) +++ ascend/compiler/relation_util.c (working copy) @@ -242,9 +242,15 @@ case F_SINH: case F_COSH: case F_TANH: + case F_COSECH: + case F_SECH: + case F_COTH: case F_ARCSINH: case F_ARCCOSH: case F_ARCTANH: + case F_ARCCOSECH: + case F_ARCSECH: + case F_ARCCOTH: /** *** first must now be dimensionless. It will *** end up dimensionless as well. @@ -272,6 +278,9 @@ case F_SIN: case F_COS: + case F_COSEC: + case F_COT: + case F_SEC: case F_TAN: { /** *** first must now be of dimension D_PLANE_ANGLE. @@ -304,6 +313,9 @@ case F_ARCSIN: case F_ARCCOS: case F_ARCTAN: + case F_ARCCOSEC: + case F_ARCSEC: + case F_ARCCOT: /** *** first must now be dimensionless. It will *** end up with dimension D_PLANE_ANGLE @@ -3814,6 +3826,9 @@ break; case F_ARCSINH: + case F_ARCCOSEC: + case F_ARCSEC: + case F_ARCCOT: soln_list->soln[ndx] = safe_sinh_D0(soln_list->soln[ndx],not_safe); if( *not_safe != safe_ok) { Index: pygtk/listExtend.py =================================================================== --- pygtk/listExtend.py (revision 0) +++ pygtk/listExtend.py (revision 0) @@ -0,0 +1,31 @@ +############################## +# Modified list class that enables assigning values to a range of elements +# Submited by : Ujjaval +# Addresses Issue 459 +############################## + +class myList(list): + def __setslice__(self, i, j, sequence): + if(isinstance(sequence,list)): + list.__setslice__(self, i, j, sequence) + else: + try: + for x in range(i,j): + self.__setitem__(x,sequence) + except: + print "Unexpected error:", sys.exc_info()[0] + +################################# +# SAMPLE USAGE : +# +# 1.Extended Syntax : +#a = myList('123456789'); +#print a; +#a[1:4] = 5; +#print a; +# 2.Original Syntax : +#b = myList('123456789'); +#print b; +#b[1:4] = [34,65]; +#print b; +################################# |
|
I have submitted a patch that adds support for the following 12 functions : Cosec, Sec, Cot Cosech, Sech, Coth ArcCosec, ArcSec, ArcCot ArcCosech, ArcSech, ArcCoth |
Date Modified | Username | Field | Change |
---|---|---|---|
2011-04-06 16:48 | john | New Issue | |
2011-04-06 16:49 | john | Description Updated | View Revisions |
2011-04-16 11:42 | ujjavalverma10 | File Added: ujjaval-505.patch | |
2011-04-16 11:44 | ujjavalverma10 | Note Added: 0000736 |