Exemplo n.º 1
0
int term1(big_int *a)
{
    big_int *b = NULL;
    int n;
    int result = 0;

    b = big_int_create(1);
    if (b == NULL) {
        printf("error when creating [b]\n");
        result = 1;
        goto done;
    }

    if (term2(a)) {
        result = 2;
        goto done;
    }

    while (1) {
        switch ((int) curr_lex.token) {
            case '^' :
                match('^');
                if (term2(b)) {
                    result = 3;
                    goto done;
                }
                if (is_mod) {
                    if (big_int_powmod(a, b, module, a)) {
                        printf("error during big_int_powmod()\n");
                        result = 4;
                        goto done;
                    }
                } else {
                    if (big_int_to_int(b, &n)) {
                        printf("error when converting number [b] to int [n]\n");
                        result = 5;
                        goto done;
                    }
                    if (big_int_pow(a, n, a)) {
                        printf("error during big_int_pow()\n");
                        result = 6;
                        goto done;
                    }
                }
                continue;
            default :
                goto done;
        }
    }

done:
    big_int_destroy(b);
    return result;
}
Exemplo n.º 2
0
bool   parserCls::term1(void)
{ bool s1 = term2();
  if(s1==false) return false ;
  EtokenType et1=getTokenType();tokenContainCls t1 ;
  while( (et1== And )||(et1 == Or )|| (et1 == ExOr))
  {
	  t1 =getCurToken();getToken();bool s2 = term2();
	  if(s2==false) return false ;
	  addOperator(t1);et1 = getTokenType();
  }
  return  s1 ;
}
Exemplo n.º 3
0
void term(int level)
{
    int this_line = line_cnt;
    push_child(this_line,FACTOR);
    factor(level);
    push_child(this_line,TERM);
    term2(level+1);
}
const Real GreensFunction2DAbs::p_int_theta_first(const Real r,
                                                  const Real theta,
                                                  const Real t) const
{
    const Real r_0(this->getr0());
    const Real a(this->geta());
    const Real minusDt(-1e0 * this->getD() * t);

    const Integer num_term_use(100);
    const Real threshold(CUTOFF);

    Real sum(0e0);
    Real term(0e0);
    Real term1(0e0);
    Real term2(0e0);
    Real term3(0e0);

    Real a_alpha_n(0e0);
    Real alpha_n(0e0);
    Real J0_r_alpha_n(0e0);
    Real J0_r0_alpha_n(0e0);
    Real J1_a_alpha_n(0e0);

    Integer n(1);
    for(; n < num_term_use; ++n)
    {
        a_alpha_n = gsl_sf_bessel_zero_J0(n);
        alpha_n = a_alpha_n / a;
        J0_r_alpha_n  = gsl_sf_bessel_J0(r * alpha_n);
        J0_r0_alpha_n = gsl_sf_bessel_J0(r_0 * alpha_n);
        J1_a_alpha_n  = gsl_sf_bessel_J1(a_alpha_n);

        term1 = std::exp(alpha_n * alpha_n * minusDt);
        term2 = J0_r_alpha_n * J0_r0_alpha_n;
        term3 = J1_a_alpha_n * J1_a_alpha_n;

        term = term1 * term2 / term3;
        sum += term;

//             std::cout << "sum " << sum << ", term" << term << std::endl;

        if(fabs(term/sum) < threshold)
        {
//                 std::cout << "normal exit. n = " << n << " first term" << std::endl;
            break;
        }
    }
    if(n == num_term_use)
        std::cout << "warning: use term over num_term_use" << std::endl;

//         return (sum / (M_PI * a * a));
    return (theta * sum / (M_PI * a * a));
}
const Real GreensFunction2DAbs::p_int_r(const Real r, const Real t) const
{
    //speed of convergence is too slow
    if(r == 0e0) return 0e0;

    const Real r_0(this->getr0());
    const Real a(this->geta());
    const Real Dt(this->getD() * t);
    const Integer num_term_use(100);
    const Real threshold(CUTOFF);

    Real sum(0e0);
    Real term(0e0);
    Real term1(0e0);
    Real term2(0e0);
    Real term3(0e0);

    Real a_alpha_n(0e0);
    Real alpha_n(0e0);
    Real J0_r0_alpha_n(0e0);
    Real J1_r_alpha_n(0e0);
    Real J1_a_alpha_n(0e0);

    Integer n(1);
    for(; n < num_term_use; ++n)
    {
        a_alpha_n = gsl_sf_bessel_zero_J0(n);
        alpha_n = a_alpha_n / a;
        J0_r0_alpha_n = gsl_sf_bessel_J0(r_0 * alpha_n);
        J1_r_alpha_n  = gsl_sf_bessel_J1(r * alpha_n);
        J1_a_alpha_n  = gsl_sf_bessel_J1(a_alpha_n);

        term1 = std::exp(-1e0 * alpha_n * alpha_n * Dt);
        term2 = r * J1_r_alpha_n * J0_r0_alpha_n;
        term3 = (alpha_n * J1_a_alpha_n * J1_a_alpha_n);

        term = term1 * term2 / term3;
        sum += term;

//             std::cout << "sum " << sum << ", term" << term << std::endl;

        if(fabs(term/sum) < threshold)
        {
//                 std::cout << "normal exit. " << n << std::endl;
            break;
        }
    }
    if(n == num_term_use)
        std::cout << "warning: use term over num_term_use" << std::endl;

    return (2e0 * sum / (a*a));
}
const Real GreensFunction2DAbs::p_survival(const Real t) const
{
    // when t == 0.0, return value become eventually 1.0,
    // but the speed of convergence is too slow.
    if(t == 0.0) return 1.0;

    const Real r_0(this->getr0());
    const Real a(this->geta());
    const Real Dt(this->getD() * t);
    const Integer num_term_use(100);
    const Real threshold(CUTOFF);

    Real sum(0e0);
    Real term1(0e0);
    Real term2(0e0);
    Real term(0e0);

    Real a_alpha_n(0e0);
    Real alpha_n(0e0);
    Real J0_r0_alpha_n(0e0);
    Real J1_a_alpha_n(0e0);

    Integer n(1);
    for(; n < num_term_use; ++n)
    {
        a_alpha_n = gsl_sf_bessel_zero_J0(n);
        alpha_n = a_alpha_n / a;
        J0_r0_alpha_n = gsl_sf_bessel_J0(r_0 * alpha_n);
        J1_a_alpha_n  = gsl_sf_bessel_J1(a_alpha_n);

        term1 = std::exp(-1e0 * alpha_n * alpha_n * Dt) * J0_r0_alpha_n;
        term2 = alpha_n * J1_a_alpha_n;
        term = term1 / term2;
        sum += term;

//             std::cout << "sum " << sum << ", term" << term << std::endl;

        if(fabs(term/sum) < threshold)
        {
//                 std::cout << "normal exit. " << n << std::endl;
            break;
        }
    }
    if(n == num_term_use)
        std::cout << "warning: use term over num_term_use" << std::endl;
    return (2e0 * sum / a);
}
Exemplo n.º 7
0
void term2(int level)
{
    int this_line = line_cnt;
    if(strcmp(tokenPos->textOfLine,"*") == 0 || strcmp(tokenPos->textOfLine,"/") == 0 )
    {
		int else_to_go = push_child_else(this_line,MULOP);
        push(MULOP,else_to_go);
		pTreeType[else_to_go][0] = MULOP;
		pTreeType[else_to_go][1] = level;
        //push(MULOP, this_line);
        push_child(this_line,FACTOR);
        factor(level);
        push_child(this_line,TERM);
        term2(level+1);
    }
    else
    {
        
    }

}