Example #1
0
int main()
{
    double complex v, z;
    double a = 0.0, b = 0.0;

    puts("Calculate the inverse hyperbolic cosine of a complex number,"
         " cacosh(z)\n");
    puts("Enter the real and imaginary parts of a complex number:");
    if ( scanf("%lf %lf", &a, &b) == 2)
    {
       z = a + b * I;
       printf( "z = %.2f %+.2f*I.\n", creal(z), cimag(z) );

       v = cacosh(z);
       printf( "The cacosh(z) function yields %.2f %+.2f*I.\n",
               creal(v), cimag(v) );
       printf( "The inverse function, ccosh(cacosh(z)),"
               " yields %.2f %+.2f*I.\n",
               creal( ccosh(v)), cimag( ccosh(v)) );
    }
    else
       printf("Invalid input.\n");

    return 0;
}
Example #2
0
double complex
ccos(double complex z)
{

	/* ccos(z) = ccosh(I * z) */
	return (ccosh(CMPLX(-cimag(z), creal(z))));
}
Example #3
0
//## Complex Complex.ccoshf();
static KMETHOD Complex_ccoshf(KonohaContext *kctx, KonohaStack *sfp)
{
	kComplex *kc = (kComplex *) sfp[0].asObject;
	float _Complex zf = (float _Complex)kc->z;
	float ret = ccosh(zf);
	KReturnFloatValue(ret);
}
Example #4
0
//## Complex Complex.ccoshl();
static KMETHOD Complex_ccoshl(KonohaContext *kctx, KonohaStack *sfp)
{
	kComplex *kc = (kComplex *) sfp[0].asObject;
	long double _Complex zl = (long double _Complex)kc->z;
	long double ret = ccosh(zl);
	KReturnFloatValue(ret);
}
Example #5
0
dcomplex
ccos(dcomplex z) {
	double x, y;

	x = D_RE(z);
	y = D_IM(z);
	D_RE(z) = y;
	D_IM(z) = -x;
	return (ccosh(z));
}
Example #6
0
void
cmplx (double _Complex z)
{
  cabs (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 129 } */
  cacos (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 131 } */
  cacosh (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 133 } */
  carg (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 135 } */
  casin (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 137 } */
  casinh (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 139 } */
  catan (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 141 } */
  catanh (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 143 } */
  ccos (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 145 } */
  ccosh (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 147 } */
  cexp (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 149 } */
  cimag (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 151 } */
  clog (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 153 } */
  conj (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 155 } */
  cpow (z, z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 157 } */
  cproj (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 159 } */
  creal (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 161 } */
  csin (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 163 } */
  csinh (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 165 } */
  csqrt (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 167 } */
  ctan (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 169 } */
  ctanh (z); /* { dg-warning "incompatible implicit" } */
  /* { dg-message "include ..complex.h.." "" { target *-*-* } 171 } */
}
Example #7
0
double complex Heston::logCF(const double &S, const double complex &u) const {
  double complex temp1,temp2,temp3, v1, v2,v3, gamma, result;
 
  v1 = kappa-I*rho*sigma*u;
  v2 = u*u+I*u;
  v3 = kappa*theta/(sigma*sigma);
  gamma = sigma*sigma*v2+v1*v1;
  gamma = cpow(gamma,.5);
  
  temp1 = cexp(I*u*(log(S)+(r-q)*T)+v3*T*v1);
  temp2 = ccosh(gamma*T/2.0)+v1/gamma*csinh(gamma*T/2.0);
  
  result = temp1/cpow(temp2,2.0*v3);

  temp1 = v0*v2; //v0 is class variable defined in .h file
  temp2 = gamma/ctanh(gamma*T/2.0)+v1;
  temp3 = cexp(-temp1/temp2);

  result = result*temp3;

  return result;
  
  }
Example #8
0
int main()
{
    double x,y;
    double complex result;
#ifdef XXXXX
    for (x = -10; x < 10; x += 0.5)
        for (y=-10; y < 10; y += 0.5) {
            result = ccosh(x + I *y);
            printf("%f %f %f %f %f %f\n",x,y,(double)cosh(x)*cos(y),(double)creal(result),(double)sinh(x)*sin(y),(double)cimag(result));
        }
    for (x = -10; x < 10; x += 0.5)
        for (y=-10; y < 10; y += 0.5) {
            result = csinh(x + I *y);
            printf("%f %f %f %f %f %f\n",x,y,(double)sinh(x)*cos(y),(double)creal(result),(double)cosh(x)*sin(y),(double)cimag(result));
        }
#endif
    for (x = -10; x < 10; x += 0.5)
        for (y=-10; y < 10; y += 0.5) {
            double d = coshl( 2.0L * x ) + cosl( 2.0L * y );
            result = ctanh(x + I *y);
            printf("%f %f %f %f %f %f\n",x,y,(double)sinh(2.0*x)/d,(double)creal(result),(double)sin(2.0*y)/d,(double)cimag(result));
        }
}
TEST(complex, ccosh) {
  ASSERT_EQ(1.0, ccosh(0));
}
Example #10
0
double complex ccos(double complex z)
{
	return ccosh(CMPLX(-cimag(z), creal(z)));
}
Example #11
0
 f = ctanf(f);
 ld = ctanl(ld);
 TEST_TRACE(C99 7.3.6.1)
 d = cacosh(d);
 f = cacoshf(f);
 ld = cacoshl(ld);
 TEST_TRACE(C99 7.3.6.2)
 d = casinh(d);
 f = casinhf(f);
 ld = casinhl(ld);
 TEST_TRACE(C99 7.3.6.3)
 d = catanh(d);
 f = catanhf(f);
 ld = catanhl(ld);
 TEST_TRACE(C99 7.3.6.4)
 d = ccosh(d);
 f = ccoshf(f);
 ld = ccoshl(ld);
 TEST_TRACE(C99 7.3.6.5)
 d = csinh(d);
 f = csinhf(f);
 ld = csinhl(ld);
 TEST_TRACE(C99 7.3.6.6)
 d = ctanh(d);
 f = ctanhf(f);
 ld = ctanhl(ld);
 TEST_TRACE(C99 7.3.7.1)
 d = cexp(d);
 f = cexpf(f);
 ld = cexpl(ld);
 TEST_TRACE(C99 7.3.7.2)
Example #12
0
void
docomplex  (void)
{
#ifndef NO_DOUBLE
  complex double ca, cb, cc;
  double f1;

  ca = 1.0 + 1.0 * I;
  cb = 1.0 - 1.0 * I;

  f1 = cabs  (ca);
  fprintf (stdout, "cabs   : %f\n", f1);

  cc = cacos  (ca);
  fprintf (stdout, "cacos  : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = cacosh  (ca);
  fprintf (stdout, "cacosh : %f %fi\n", creal  (cc),
	   cimag  (cc));

  f1 = carg  (ca);
  fprintf (stdout, "carg   : %f\n", f1);

  cc = casin  (ca);
  fprintf (stdout, "casin  : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = casinh  (ca);
  fprintf (stdout, "casinh : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = catan  (ca);
  fprintf (stdout, "catan  : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = catanh  (ca);
  fprintf (stdout, "catanh : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = ccos  (ca);
  fprintf (stdout, "ccos   : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = ccosh  (ca);
  fprintf (stdout, "ccosh  : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = cexp  (ca);
  fprintf (stdout, "cexp   : %f %fi\n", creal  (cc),
	   cimag  (cc));

  f1 = cimag  (ca);
  fprintf (stdout, "cimag  : %f\n", f1);

  cc = clog  (ca);
  fprintf (stdout, "clog   : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = conj  (ca);
  fprintf (stdout, "conj   : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = cpow  (ca, cb);
  fprintf (stdout, "cpow   : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = cproj  (ca);
  fprintf (stdout, "cproj  : %f %fi\n", creal  (cc),
	   cimag  (cc));

  f1 = creal  (ca);
  fprintf (stdout, "creal  : %f\n", f1);

  cc = csin  (ca);
  fprintf (stdout, "csin   : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = csinh  (ca);
  fprintf (stdout, "csinh  : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = csqrt  (ca);
  fprintf (stdout, "csqrt  : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = ctan  (ca);
  fprintf (stdout, "ctan   : %f %fi\n", creal  (cc),
	   cimag  (cc));

  cc = ctanh  (ca);
  fprintf (stdout, "ctanh  : %f %fi\n", creal  (cc),
	   cimag  (cc));
#endif
}
Example #13
0
//FIXME
long double complex ccoshl(long double complex z)
{
	return ccosh(z);
}
Example #14
0
File: exp.c Project: daschaich/qhmc
/*
void 
traceless_herm_M_evalues(QLA_ColorMatrix *Q, double *u, double *w, 
			   double *q1, double *q2, double *q3) {
  
  QLA_Complex c0, c1;

  QLA_ColorMatrix Q2;
  QLA_M_eq_M_times_M(&Q2, Q, Q);
  printf("Q^2 = \n"); printm(&Q2);

  QLA_C_eq_det_M    (&c0, Q);     // c0 = det(Q)
  QLA_C_eq_trace_M  (&c1, &Q2);     // c1 = tr(Q^2)
  

  double athird = 1.0/3.0;
  double cc0, cc1, cc0max;
  cc0 = QLA_real(c0);     
  cc1 = 0.5 * QLA_real(c1);
  cc0max = 2*sqrt(cc1 * athird)*(cc1 * athird);  //c_0^max = 2 * (c1/3)^{3/2}
  printf("c0 = %f\n", cc0);
  printf("c1 = %f\n", cc1);
  printf("c0_max = %f\n", cc0max);

  double theta;
  
  theta =acos(cc0/cc0max);
  *u = sqrt(athird * cc1) * cos(athird * theta);
  *w = sqrt(cc1) * sin(athird * theta);
  *q1 = 2 * *u;
  *q2 = -*u + *w;
  *q3 = -*u - *w;

  printf("u = %f, w = %f, q1 = %f, q2 = %f, q3 = %f\n", *u, *w, *q1, *q2, *q3);
}

void 
get_f_coeffs(QLA_ColorMatrix *Q, double _Complex *f0, double _Complex *f1, double _Complex *f2){
  double u, w, q1, q2, q3;
  traceless_herm_M_evalues(Q, &u, &w, &q1, &q2, &q3);
  printf("q1=\n"); printc99(&q1);

  double _Complex e2iu, e_iu;
  e2iu = cexp(2 * _Complex_I * u);
  e_iu = cexp(-1.0 * _Complex_I * u);
  
  double u2 = u*u;
  double w2 = w*w;

  double _Complex zeta0w;
  if (fabs(w) > 0.05) {
    zeta0w = sin(w)/w;
  }
  else {
    zeta0w = 1 - w2/6. * (1-w2/20. * (1 - w2/42.));
  }
  
  double _Complex h0, h1, h2;
  h0 = (u2 - w2) * e2iu + e_iu * ( 8 * u2 *cos(w) + 2*_Complex_I*u * (3*u2+w2)*zeta0w);
  h1 = 2*u*e2iu - e_iu * (2 * u * cos(w) - _Complex_I * (3*u2-w2)*zeta0w);
  h2 = e2iu - e_iu * ( cos(w) + 3*_Complex_I*u * zeta0w);

  double fac = 1.0/(9*u2-w2);
  *f0 = h0 * fac;
  *f1 = h1 * fac;
  *f2 = h2 * fac;
}

void
get_Bs(QLA_ColorMatrix *Q, QLA_ColorMatrix *Q2, QLA_ColorMatrix *B1, QLA_ColorMatrix *B2, double _Complex *f0, double _Complex *f1, double _Complex *f2) {
  double u, w, q1, q2, q3;
  traceless_herm_M_evalues(Q, &u, &w, &q1, &q2, &q3);
  printf("q1=\n"); printc99(&q1);

  double _Complex e2iu, e_iu;
  e2iu = cexp(2 * _Complex_I * u);
  e_iu = cexp(-1.0 * _Complex_I * u);
  
  double u2 = u*u;
  double w2 = w*w;

  double _Complex zeta0w, zeta1w;
  if (fabs(w) > 0.05) {
    zeta0w = sin(w)/w;
    zeta1w = (cos(w)-zeta0w)/w2;
  }
  else {
    zeta0w = 1 - w2/6. * (1-w2/20. * (1 - w2/42.));
    zeta1w = -(1 - w2/10. * (1 - w2/28.*(1 - w2/54.)))/3.0;
  }
  
  double _Complex h0, h1, h2; 
  h0 = (u2 - w2) * e2iu + e_iu * ( 8 * u2 *cos(w) + 2*_Complex_I*u * (3*u2+w2)*zeta0w);
  h1 = 2*u*e2iu - e_iu * (2 * u * cos(w) - _Complex_I * (3*u2-w2)*zeta0w);
  h2 = e2iu - e_iu * ( cos(w) + 3*_Complex_I*u * zeta0w);

  double fac = 1.0/(9*u2-w2);
  *f0 = h0 * fac;
  *f1 = h1 * fac;
  *f2 = h2 * fac;

  double _Complex r01, r11, r21, r02, r12, r22, iu;
  double cosw = cos(w);

  iu = _Complex_I * u;

  r01 = 2*(u + _Complex_I * (u2 - w2)) * e2iu 
	   + 2 * e_iu * ( 4*u*(2 - iu) * cosw + _Complex_I * (9 * u2 + w2 - iu * (3*u2 + w2))*zeta0w);

  r11 = 2*(1 + 2*iu) * e2iu 
    + e_iu * ( -2 * (1-iu) * cosw + _Complex_I * (6*u + _Complex_I * (w2 - 3*u2)) * zeta0w);

  r21 = 2 * _Complex_I * e2iu + _Complex_I * e_iu * (cosw - 3*(1-iu)*zeta0w);

  r02 = -2 * e2iu + 2 * iu * e_iu * (cosw + (1+4*iu) * zeta0w + 3 * u2 * zeta1w);

  r12 = -_Complex_I * e_iu * ( cosw + (1+2*iu) * zeta0w - 3*u2 * zeta1w);

  r22 = e_iu * (zeta0w - 3 * iu * zeta1w);

  double _Complex b10, b11, b12, b20, b21, b22;
  
  double fac1, fac2, fac3;
  
  double mult = 0.5 * fac * fac;
  fac1 = 2 * u;
  fac2 = 3*u2 - w2;
  fac3 = 2*(15*u2+w2);

  b10 = fac1 * r01 + fac2 * r02 - fac3 * (*f0);
  b10 *= mult;

  b11 = fac1 * r11 + fac2 * r12 - fac3 * (*f1);
  b11 *= mult;

  b12 = fac1 * r21 + fac2 * r22 - fac3 * (*f2);
  b12 *= mult;

  fac2 = 3*u;
  fac3 = 24*u;
  b20 = r01 - fac2 * r02 - fac3 * (*f0);
  b20 *= mult;

  b21 = r11 - fac2 * r12 - fac3 * (*f1);
  b21 *= mult;

  b22 = r21 - fac2 * r22 - fac3 * (*f2);
  b22 *= mult;

  QLA_Complex qb10, qb11, qb12, qb20, qb21, qb22;
  QLA_c_eq_c99(qb10, b10);
  QLA_c_eq_c99(qb11, b11);
  QLA_c_eq_c99(qb12, b12);
  QLA_c_eq_c99(qb20, b20);
  QLA_c_eq_c99(qb21, b21);
  QLA_c_eq_c99(qb22, b22);

  QLA_M_eq_c(B1, &qb10);
  QLA_M_peq_c_times_M(B1, &qb11, Q); 
  QLA_M_peq_c_times_M(B1, &qb12, Q2);
  
  QLA_M_eq_c(B2, &qb20);
  QLA_M_peq_c_times_M(B2, &qb21, Q); 
  QLA_M_peq_c_times_M(B2, &qb22, Q2);
  
}

*/
int
main(void) {
  QLA_ColorMatrix O, iQ, matI;
  QLA_M_eq_zero(&matI);

  for(int i=0; i<QLA_Nc; i++) {
    QLA_c_eq_r_plus_ir(QLA_elem_M(matI,i,i), 1.0, 0.0);
  }

  printm(&matI);

  //QLA_Complex tr;
  //QLA_Real half = 0.5;

  for(int i=0; i<QLA_Nc; i++) {
    for(int j=0; j<QLA_Nc; j++) {
      QLA_c_eq_r_plus_ir(QLA_elem_M(O,i,j), i+1, QLA_Nc*(j+1));
    }
    QLA_c_eq_r_plus_ir(QLA_elem_M(O,i,i), 2+1, 1);
  }
  printm(&O);

#if QDP_Colors == 3
  QLA_ColorMatrix A;
  QLA_M_eq_zero(&A);

  for ( int m = 0; m < QLA_Nc; m++) {
    for ( int n = 0; n < QLA_Nc; n++) {
      QLA_c_eq_r_plus_ir(QLA_elem_M(A, m, n), 3+m, 2-n);
    }
    QLA_c_eq_r_plus_ir(QLA_elem_M(A,m,m), 2+1, 1);

  }
  QLA_M_eq_antiherm_M(&A, &A);
  printm(&A);
  
  QLA_M_eq_zero(&A);

  QLA_c_eq_r_plus_ir(QLA_elem_M(A,0,0),0,-1);
  QLA_c_eq_r_plus_ir(QLA_elem_M(A,1,1),0,0.4);
  QLA_c_eq_r_plus_ir(QLA_elem_M(A,2,2),0,0.6);
  printm(&A);
  
  QLA_Complex minus_i;
  QLA_c_eq_r_plus_ir(minus_i, 0, -1);
  QLA_ColorMatrix Q, Q2, expiQ, qla_expA;

  QLA_M_eq_C_times_M(&Q, &minus_i, &matI);
  QLA_M_eq_M_times_M(&Q2, &Q, &Q);

  printf("Q=\n"); printm(&Q);

  double _Complex f0, f1, f2;
  QLA_ColorMatrix B1, B2;
  
  get_Bs(&Q, &Q2, &B1, &B2, &f0, &f1, &f2);
  printf("f0, f1, f2=\n");
  printc99(&f0);
  printc99(&f1);
  printc99(&f2);

  QLA_Complex qf0, qf1, qf2;

  QLA_c_eq_c99(qf0, f0);
  QLA_c_eq_c99(qf1, f1);
  QLA_c_eq_c99(qf2, f2);
    
  QLA_M_eq_c(&expiQ, &qf0);
  QLA_M_peq_c_times_M(&expiQ, &qf1, &Q);
  QLA_M_peq_c_times_M(&expiQ, &qf2, &Q2);

  QLA_M_eq_exp_M(&qla_expA, &matI);

  printf("my expiQ = \n");
  printm(&expiQ);
  
  printf("qla expA = \n");
  printm(&qla_expA);

  // derivative
   
  QLA_Complex trB1M, trB2M;
  QLA_ColorMatrix prod, deriv;

  //tr(B_1 M)
  QLA_M_eq_M_times_M (&prod, &B1, &matI); //B_1 M
  QLA_C_eq_trace_M   (&trB1M, &prod);
  
  //tr(B_2 M);
  QLA_M_eq_M_times_M (&prod, &B2, &matI); //B_2 M
  QLA_C_eq_trace_M   (&trB2M, &prod);
  
  // deriv = Tr(B_1 M) Q
  QLA_M_eq_c_times_M (&deriv, &trB1M, &Q);
  
  // deriv += Tr(B_2 M) Q^2
  QLA_M_peq_c_times_M (&deriv, &trB2M, &Q2);
  
  // deriv += f1 M
  QLA_M_peq_c_times_M (&deriv, &qf1, &matI);
  
  // deriv += f2 Q M
  QLA_M_eq_M_times_M  (&prod, &Q, &matI); // Q M
  QLA_M_peq_c_times_M (&deriv, &qf2, &prod); 
  
  // deriv += f2 M Q
  QLA_M_eq_M_times_M  (&prod, &matI, &Q); // M Q
  QLA_M_peq_c_times_M (&deriv, &qf2, &prod);

  QLA_M_eq_c_times_M  (&deriv, &minus_i, &deriv);
  
  printf("M = \n");
  printm(&matI);

  printf("deriv = \n");
  printm(&deriv);
  

  QLA_M_meq_M(&deriv, &expiQ);
  printf("diff = \n");
  printm(&deriv);
  /*
  printf("2/3f0 = \n");
  f0 *= 2.0/3;
  printc99(&f0);

  printc(&qf0);
  printc(&qf1);
  printc(&qf2);
  */

#endif

#if QDP_Colors == 2
  QLA_ColorMatrix expO;
  QLA_Complex Tr, det;
  QLA_c_eq_c_times_c(det, QLA_elem_M(O,0,0),QLA_elem_M(O,1,1));
  QLA_c_meq_c_times_c(det, QLA_elem_M(O,0,1), QLA_elem_M(O,1,0));

  QLA_C_eq_trace_M(&Tr, &O);
  QLA_Complex qs, qt;
  QLA_c_eq_r_times_c(qs, 0.5, Tr); // s=TrA/2

  QLA_Complex qs2;
  QLA_c_eq_c_times_c(qs2, qs, qs); //s2 = s^2
  QLA_c_meq_c(qs2, det); //s2 = s^2 - detA

  double _Complex t = QLA_real(qs2) + QLA_imag(qs2) * _Complex_I;
  t = csqrt(t); // sqrt(s^2 - det A)
  QLA_c_eq_r_plus_ir(qt, creal(t), cimag(t)); // t = sqrt(s^2 - det A)

  printf(" Matrix O = \n"); printm(&O);
  printf("TrO = ");         printc(&Tr);
  printf("detO = ");        printc(&det); 
  printf("s = ");           printc(&qs);
  printf("t^2 = ");         printc(&qs2);
  printf("t = ");           printc(&qt);

  //use the QLA exp function
  QLA_ColorMatrix qla_exp;
  QLA_M_eq_exp_M(&qla_exp, &O); //exp(O)
  
  double _Complex exps, cosht, sinht, sinht_t;
  double _Complex s = QLA_real(qs) + QLA_imag(qs) * _Complex_I;
  exps = cexp(s);

  if(creal(t) == 0 && cimag(t) == 0) {
    cosht = 1;
    sinht = 0;
    sinht_t = 1;	
  } else {
    cosht = ccosh(t);
    sinht = csinh(t);
    sinht_t = sinht/t;
  }

  double _Complex f0, f1;
  f1 = exps * sinht_t;  
  f0 = exps * cosht - s * f1;;

  //derivative of the exponential
  double _Complex f0s, f1s, f1t, f0t2, f1t2, t2;
  t2 = t*t;

  f0s = f0 - f1;
  f1s = f1;
  if (cabs(t) > 0.05) { 
    f1t = ((f0-f1) + s*f1)/t;
    f1t2 = f1t/t;
  }
  else { //when |t| < 0.05, the error is O(10^{-14})
    f1t = exps * t/3 * (1+t2/10*(1+t2/28));
    f1t2 = exps / 3 * (1+t2/10*(1+t2/28));
  }
 
  //  f0t = t * f1 - s * f1t;
  f0t2 = f1 - s * f1t2;
  
  printf("f0   = \n"); printc99(&f0);
  printf("f1   = \n"); printc99(&f1);
  printf("f0s  = \n"); printc99(&f0s);
  printf("f1s  = \n"); printc99(&f1s);

  printf("f1t  = \n"); printc99(&f1t);
  printf("f0t2 = \n"); printc99(&f0t2);
  printf("f1t2 = \n"); printc99(&f1t2);



  QLA_Complex qf0, qf1;
  QLA_c_eq_r_plus_ir(qf0, creal(f0), cimag(f0));
  QLA_c_eq_r_plus_ir(qf1, creal(f1), cimag(f1));

  QLA_M_eq_c_times_M(&expO, &qf1, &O);
  QLA_M_peq_c(&expO, &qf0);
  printf("QLA exp = \n"); printm(&qla_exp);
  printf("my expO = \n"); printm(&expO);

  /*
    QLA_Complex qf0s, qf0t, qf1s, qf1t;
    QLA_c_eq_r_plus_ir(qf0s, creal(f0s), cimag(f0s));
    QLA_c_eq_r_plus_ir(qf0t, creal(f0t), cimag(f0t));
    QLA_c_eq_r_plus_ir(qf1s, creal(f1s), cimag(f1s));
    QLA_c_eq_r_plus_ir(qf1t, creal(f1t), cimag(f1t));
  */

  QLA_ColorMatrix deriv;
  QLA_M_eq_zero(&deriv);

  QLA_ColorMatrix B, AB;
  QLA_M_eq_M(&B, &matI);

  //QLA_c_eq_r_plus_ir(QLA_elem_M(B,1,0), 0.1, 0.2);
  //QLA_c_eq_r_plus_ir(QLA_elem_M(B,0,1), 0.2, 0.1);
  
  printf("B=\n");  printm(&B);

  QLA_M_eq_M_times_M(&AB, &O, &B);
  printf("AB=\n"); printm(&AB);
  
  QLA_M_eq_c_times_M(&deriv, &qf1, &B); //f1 * B
  printf("f1 B = \n"); printm(&deriv);

  QLA_Complex trB, trAB;
  QLA_C_eq_trace_M(&trB,  &B); 
  QLA_C_eq_trace_M(&trAB, &AB);
  
  double _Complex ctrB  = QLA_real(trB) + _Complex_I * QLA_imag(trB);
  double _Complex ctrAB = QLA_real(trAB) + _Complex_I * QLA_imag(trAB);
  double _Complex coeff;
  
  coeff  = (f0s - f0t2 * s) * ctrB;
  coeff += (f1s - f1t2 * s) * ctrAB;
  coeff *= 0.5;
  
  printf("coeff = "); printc99(&coeff);
  QLA_Complex qc;
  QLA_D_c_eq_c99(qc, coeff);

  printc(&qc);

  QLA_M_peq_c_times_M(&deriv, &qc, &matI); // f1 * B + () I
  printf("f1B+()I=\n"); printm(&deriv);
  
  coeff = 0.5 * (f0t2 * ctrB + f1t2 * ctrAB);
  QLA_D_c_eq_c99(qc, coeff);

  printc(&qc);

  QLA_M_peq_c_times_M(&deriv, &qc, &O);

  printm(&deriv);

  exp_deriv_site(&deriv, &expO, &O, &B);
  printm(&deriv);

#endif

  return 0;
}
Example #15
0
CAMLprim value math_ccosh(value x) {
  CAMLparam1(x);
  CAMLreturn(caml_copy_complex(ccosh(Complex_val(x))));
}
Example #16
0
void test06 ( )

/******************************************************************************/
/*
  Purpose:

    TEST06: intrinsic functions for double complex variables.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    07 November 2010

  Author:

    John Burkardt
*/
{
    double complex a = {1.0 + 2.0 * I};

    printf ( "\n" );
    printf ( "TEST06\n" );
    printf ( "  Apply intrinsic functions to DOUBLE COMPLEX variables\n" );
    /*
      Print them.
    */
    printf ( "\n" );
    /*
      Note that "I" by itself is NOT a complex number, nor is it the
      imaginary unit.  You have to cast it to ( complex ) or ( double complex )
      or multiply it by a float or double before it results in a numerical
      result.
    */
    printf ( "  ( double complex ) I =  (%14.6g,%14.6g)\n", ( double complex ) I );
    printf ( "  a =                     (%14.6g,%14.6g)\n", a );
    printf ( "  - a =                   (%14.6g,%14.6g)\n", - a );
    printf ( "  a + 3 =                 (%14.6g,%14.6g)\n", a + 3 );
    printf ( "  a + (0,5) =             (%14.6g,%14.6g)\n", a + ( 0, 5 ) );
    printf ( "  4 * a =                 (%14.6g,%14.6g)\n", 4 * a );
    printf ( "  a / 8 =                 (%14.6g,%14.6g)\n", a / 8 );
    printf ( "  a * a =                 (%14.6g,%14.6g)\n", a * a );
    printf ( "  cpow ( a, 2 ) =         (%14.6g,%14.6g)\n", cpow ( a, 2 ) );
    printf ( "  cpow ( 2, a ) =         (%14.6g,%14.6g)\n", cpow ( 2, a ) );
    printf ( "  cpow ( a, a ) =         (%14.6g,%14.6g)\n", cpow ( a, a ) );
    printf ( "  1/a =                   (%14.6g,%14.6g)\n", 1.0 / a );
    printf ( "\n" );
    printf ( "  cabs(a) =                %14.6g\n",         cabs ( a ) );
    printf ( "  cacos(a) =              (%14.6g,%14.6g)\n", cacos ( a ) );
    printf ( "  cacosh(a) =             (%14.6g,%14.6g)\n", cacosh ( a ) );
    printf ( "  carg(a) =                %14.6g\n",         carg ( a ) );
    printf ( "  casin(a) =              (%14.6g,%14.6g)\n", casin ( a ) );
    printf ( "  casinh(a) =             (%14.6g,%14.6g)\n", casinh ( a ) );
    printf ( "  catan(a) =              (%14.6g,%14.6g)\n",
             creal ( catan ( a ) ), cimag ( catan ( a ) ) );
    printf ( "  catanh(a) =             (%14.6g,%14.6g)\n",
             creal ( catanh ( a ) ), cimag ( catanh ( a ) ) );
    printf ( "  ccos(a) =               (%14.6g,%14.6g)\n",
             creal ( ccos ( a ) ), cimag ( ccos ( a ) ) );
    printf ( "  ccosh(a) =              (%14.6g,%14.6g)\n",
             creal ( ccosh ( a ) ), cimag ( ccosh ( a ) ) );
    printf ( "  cexp(a) =               (%14.6g,%14.6g)\n",
             creal ( cexp ( a ) ), cimag ( cexp ( a ) ) );
    printf ( "  cimag(a) =               %14.6g\n",         cimag ( a ) );
    printf ( "  clog(a) =               (%14.6g,%14.6g)\n",
             creal ( clog ( a ) ), cimag ( clog ( a ) ) );
    printf ( "  (double complex)(1) =   (%14.6g,%14.6g)\n",
             creal ( ( double complex ) ( 1 ) ), cimag ( ( double complex ) ( 1 ) ) );
    printf ( "  (double complex)(4.0) = (%14.6g,%14.6g)\n",
             creal ( ( double complex ) ( 4.0 ) ), cimag ( ( double complex ) ( 4.0 ) ) );
    printf ( "  conj(a) =               (%14.6g,%14.6g)\n",
             creal ( conj ( a ) ), cimag ( conj ( a ) ) );
    printf ( "  cproj(a) =              (%14.6g,%14.6g)\n",
             creal ( cproj ( a ) ), cimag ( cproj ( a ) ) );
    printf ( "  creal(a) =               %14.6g\n",         creal ( a ) );
    printf ( "  csin(a) =               (%14.6g,%14.6g)\n",
             creal ( csin ( a ) ), cimag ( csin ( a ) ) );
    printf ( "  csinh(a) =              (%14.6g,%14.6g)\n",
             creal ( csinh ( a ) ), cimag ( csinh ( a ) ) );
    printf ( "  csqrt(a) =              (%14.6g,%14.6g)\n",
             creal ( csqrt ( a ) ), cimag ( csqrt ( a ) ) );
    printf ( "  ctan(a) =               (%14.6g,%14.6g)\n",
             creal ( ctan ( a ) ), cimag ( ctan ( a ) ) );
    printf ( "  ctanh(a) =              (%14.6g,%14.6g)\n",
             creal ( ctanh ( a ) ), cimag ( ctanh ( a ) ) );
    printf ( "  (int)(a) =               %10d\n",           ( int ) ( a ) );

    return;
}
Example #17
0
File: exp.c Project: daschaich/qhmc
int
main(void) {
  QLA_ColorMatrix O, iQ, tmp, matI;
  QLA_M_eq_zero(&matI);

  for(int i=0; i<QLA_Nc; i++) {
    QLA_c_eq_r_plus_ir(QLA_elem_M(matI,i,i), 1.0, 0.0);
  }
  printm(&matI);

  QLA_Complex tr;
  QLA_Real half = 0.5;

  for(int i=0; i<QLA_Nc; i++) {
    for(int j=0; j<QLA_Nc; j++) {
      QLA_c_eq_r_plus_ir(QLA_elem_M(O,i,j), i+1, QLA_Nc*(j+1));
    }
    QLA_c_eq_r_plus_ir(QLA_elem_M(O,i,i), 2+1, 1);
  }

#if QDP_Colors == 3
  QLA_Complex ci;
  QLA_c_eq_r_plus_ir(ci, 0, 1);

  //use my own implementation
  QLA_ColorMatrix expiQ;
  QLA_ColorMatrix QQ;
  QLA_ColorMatrix QQQ;
  QLA_M_eq_M_times_M(&QQ, &iQ, &iQ); //-Q^2
  QLA_M_eq_M_times_M(&QQQ, &QQ, &iQ); //-iQ^3
  QLA_M_eq_c_times_M(&QQQ, &ci, &QQQ); //Q^3
 
  QLA_Complex c0, c1;
  QLA_C_eq_trace_M(&c0, &QQQ);
  QLA_c_eq_r_times_c(c0, 0.3333333, c0);

  QLA_C_eq_trace_M(&c1, &QQ);
  QLA_c_eq_r_times_c(c1, -0.5, c1);

  double _Complex tf0, tf1, tf2;
  getfs(&tf0, &tf1, &tf2, QLA_real(c0), QLA_real(c1));

  QLA_Complex f0, f1, f2;
  f0 = tf0; 
  f1 = tf1;
  f2 = tf2;

  printm(&O);
  printf("iQ = \n");
  printm(&iQ);
  printf("QLA: exp(iQ) = \n");
  printm(&qla_exp);
  printf("Q^3 = \n");
  printm(&QQQ);
  printf("c0 = "); printc(&c0);
  printf("c1 = "); printc(&c1);  
#endif

#if QDP_Colors == 2
  QLA_ColorMatrix expO;
  QLA_Complex Tr, det;
  QLA_c_eq_c_times_c(det, QLA_elem_M(O,0,0),QLA_elem_M(O,1,1));
  QLA_c_meq_c_times_c(det, QLA_elem_M(O,0,1), QLA_elem_M(O,1,0));

  QLA_C_eq_trace_M(&Tr, &O);
  QLA_Complex s, t;
  QLA_c_eq_r_times_c(s, 0.5, Tr); // s=TrA/2

  QLA_Complex s2;
  QLA_c_eq_c_times_c(s2, s, s); //s2 = s^2
  QLA_c_meq_c(s2, det); //s2 = s^2 - detA

  double _Complex dc_t = QLA_real(s2) + QLA_imag(s2) * _Complex_I;
  dc_t = csqrt(dc_t); // sqrt(s^2 - det A)
  QLA_c_eq_r_plus_ir(t, creal(dc_t), cimag(dc_t)); // t = sqrt(s^2 - det A)

  printf(" Matrix O = \n"); printm(&O);
  printf("TrO = ");         printc(&Tr);
  printf("detO = ");        printc(&det); 
  printf("s = ");           printc(&s);
  printf("t^2 = ");         printc(&s2);
  printf("t = ");           printc(&t);

  //use the QLA exp function
  QLA_ColorMatrix qla_exp;
  QLA_M_eq_exp_M(&qla_exp, &O); //exp(O)
  
  double _Complex cosht, sinht, sinht_t;

  if(QLA_real(t) == 0 && QLA_imag(t) == 0) {
    cosht = 1;
    sinht = 0;
    sinht_t = 1;	
  } else {
    cosht = ccosh(dc_t);
    sinht = csinh(dc_t);
    sinht_t = sinht/dc_t;
  }

  double _Complex dc_s = QLA_real(s) + QLA_imag(s) * _Complex_I;
  double _Complex dc_f0, dc_f1;
  
  dc_f0 = cexp(dc_s) * (cosht - dc_s * sinht_t);
  dc_f1 = cexp(dc_s) * sinht_t;

  QLA_Complex f0, f1;
  QLA_c_eq_r_plus_ir(f0, creal(dc_f0), cimag(dc_f0));
  QLA_c_eq_r_plus_ir(f1, creal(dc_f1), cimag(dc_f1));

  QLA_M_eq_c_times_M(&expO, &f1, &O);
  QLA_M_peq_c(&expO, &f0);
  printf("QLA exp = \n"); printm(&qla_exp);
  printf("my expO = \n"); printm(&expO);


#endif

  return 0;
}