Ejemplo n.º 1
0
void rotnumber(long double xi1, long double yi1, int time) {
    __float128 x = xi1;
    __float128 y = yi1;
    __float128 xn;
    __float128 yn;
    __float128 xav=0.Q;
    __float128 yav=0.Q;
    __float128 cosval=0.Q;
    __float128 dot, mo, mn, theta;
    __float128 rho=0.Q; 
    __float128 wsum=0.Q;
    for(int t=0; t< time; t++) {
        wsum+=weight((__float128)t/(__float128)time);
    }


    for(int t=0; t < time; t++) {
        xav+=x*weight((__float128)t/(__float128)time);
        yav+=y*weight((__float128)t/(__float128)time);
        xn = smod(x+y,2.Q*M_PIq);
        yn = smod(y+1.4Q*sinq(x+y),2.Q*M_PIq);
        x=xn;
        y=yn;
    }
    xav/=wsum;
    yav/=wsum;
    mn = sqrtq((x-xav)*(x-xav) + (y-yav)*(y-yav));
    for(int t=0; t< time; t++) {
        xn = smod(x+y,2.Q*M_PIq);
        yn = smod(y+1.4Q*sinq(x+y),2.Q*M_PIq);

        dot = (xn-xav)*(x-xav) + (yn-yav)*(y-yav);
        mo = mn;
        mn = sqrtq((xn-xav)*(xn-xav) + (yn-yav)*(yn-yav));
        cosval = dot/(mo*mn);
        theta = acosq(cosval);
        rho += theta*weight((__float128)t/(__float128)time);
        x=xn;
        y=yn;
    }
    rho/=wsum*2.Q*M_PIq;

    printf("The rotation number at (xi=%Lf, yi=%Lf) is %.20Lf\n",xi1,yi1,(long double)rho);
}
void test() {
  for (ll a = -20; a < 20; a++) {
    for (ll b = 2; b < 40; b++) {
      if (gcd(a, b) == 1) {
        assert_equal(1LL, smod((a * mod_inv(a, b)), b));
      } else {
        assert_equal(-1LL, mod_inv(a, b));
      }
    }
  }
}
pair<ll,ll> linear_congruence(ll a, ll b, ll n) {
  ll x, y, d = egcd(smod(a,n), n, x, y);
  if ((b = smod(b,n)) % d != 0) return ii(0,0);
  return make_pair(smod(b / d * x, n),n/d); }
Ejemplo n.º 4
0
void curve_convergence(long double ax1, long double ay1, long double bx1, long double by1, long double anonlin, int numpoints, int time, int fnum, int preshift, double (*points)[2]) {

    FILE *f;

    const char name[] = "outputs/text_quasi_curve_t%u_np%u_ax%.2Lf_ay%.2Lf_bx%.2Lf_by%.2Lf.txt";
    char fname[100];
    sprintf(fname, name, time,numpoints,ax1,ay1,bx1,by1);
    f= fopen(fname,"w");

    int t, v;
    __float128 wsum=0;
    for(t=0; t<time; t++) {
        wsum += weight((__float128)t/(__float128)time);
    }

    __float128 ax = ax1;
    __float128 bx = bx1;
    __float128 ay = ay1;
    __float128 by = by1;

    __float128 x,y, xn, yn;
    __float128 first[fnum];
    __float128 second[fnum];
    __float128 diff[fnum];
    __float128 diff_mag;
    __float128 numzeros;
    __float128 wvar;

    __float128 nonlin=anonlin;
    
    for(int p=0; p < numpoints; p++) {
        x = ax + (bx-ax)*((__float128)p/(__float128)numpoints);
        y = ay + (by-ay)*((__float128)p/(__float128)numpoints);
        fprintf(f,"x: %.10Lf, y: %.10Lf, ", (long double)x, (long double)y);
        for(int s=0; s < preshift; s++) {
            for(t=0; t< time; t++) {
                xn = smod(x+y,2.Q*M_PIq);
                yn = smod(nonlin*sinq(x+y)+y,2.Q*M_PIq);
                x = xn;
                y = yn;
            }
        }

        memset(first, 0, sizeof(__float128)*fnum);
        for( t=0; t<time; t++) {
            wvar = weight((__float128)t/(__float128)time);

            for(v=0; v<fnum;v++) {
                first[v] += (*fvec[v])(x,y)*wvar;
            }
            xn = smod(x+y,2.Q*M_PIq);
            yn = smod(nonlin*sinq(x+y)+y,2.Q*M_PIq);
            x = xn;
            y = yn;
        }

        memset(second,0,sizeof(__float128)*fnum);

        for( t=0; t <time; t++) {
            wvar = weight((__float128)t/(__float128)time);


            for(v=0; v<fnum;v++) {
                second[v]+= (*fvec[v])(x,y)*wvar;
            }
            xn = smod(x+y,2.Q*M_PIq);
            yn = smod(nonlin*sinq(x+y)+y,2.Q*M_PIq);
            x = xn;
            y = yn;
        }
        diff_mag=0.Q;
        for(v=0; v<fnum; v++) {
            diff[v]=(second[v]-first[v])/wsum;
            diff_mag+=diff[v]*diff[v];
        }
        diff_mag = sqrtq(diff_mag);
        numzeros = (__float128)(-1.Q*log10q(diff_mag));
        fprintf(f,"numzeros: %.12Lf\n",(long double)numzeros);
        points[p][0] = (double)p/(__float128)numpoints;
        points[p][1] = (double)numzeros;
        printf("numzeros: %.20Lf\n",(long double)numzeros);
    }

}
Ejemplo n.º 5
0
void convergence(int rows, int cols, int time, long double aleastx, long double aleasty,
        long double adeltax, long double adeltay, int fnum, char (*m)[cols]) {
    printf("Running Optimized Version of Quasiperiodicity\n");
    unsigned int i, j, t, v;
    
    FILE *f;
    const char name[] = "outputs/text_optquasi_conv_t%u_g%u_xs%.2Lf_ys%.2Lf_xb%.2Lf_yb%.2Lf.txt";
    char fname[100];
    sprintf(fname, name, time,rows, aleastx, aleasty, aleastx+rows*adeltax,aleasty+cols*adeltay);
    f= fopen(fname,"w");
    fprintf(f,"ONLY BOX IS CERTAIN\n\n");
    unsigned int** traj = (unsigned int**) malloc(sizeof(unsigned int*)*time);
    int ntraj=0;
    for(int o=0; o < time; o++) {
        traj[o] = (unsigned int*) malloc(sizeof(unsigned int)*2);
    }
    __float128  wsum=0;
    for(t=0; t<time; t++) {
        wsum += weight((__float128)t/(__float128)time);
    }

    __float128  x,y, xn, yn;
    __float128  first[fnum];
    __float128  second[fnum];
    __float128  diff[fnum];
    __float128  diff_mag;
    char numzeros;
    __float128  wvar;


    __float128 leastx = aleastx;
    __float128 leasty = aleasty;
    __float128 deltax = adeltax;
    __float128 deltay = adeltay;



    for(i=0; i < rows; i++) {
        printf("i is: %u\n", i);
        for(j=0; j < cols; j++) {
            if(m[i][j]==-1) {
                ntraj++;
                x = leastx + j*deltax+0.5*deltax;
                y = leasty + i*deltay+0.5*deltay;
                memset(first, 0, sizeof(__float128)*fnum);
                for( t=0; t<time; t++) {
                    wvar = weight((__float128)t/(__float128)time);

                    for(v=0; v<fnum;v++) {
                        first[v] += (*fvec[v])(x,y)*wvar;
                    }
                    xn = smod(x+y,2.Q*M_PIq);
                    yn = smod(1.4Q*sinq(x+y)+y,2.Q*M_PIq);
                    traj[t][0] = floorq((x-leastx)/deltax);
                    traj[t][1] = floorq((y-leasty)/deltay);
                    x = xn;
                    y = yn;
                }

                memset(second,0,sizeof(__float128)*fnum);

                for( t=0; t <time; t++) {
                    wvar = weight((__float128)t/(__float128)time);


                    for(v=0; v<fnum;v++) {
                        second[v]+= (*fvec[v])(x,y)*wvar;
                    }
                    xn = smod(x+y,2.Q*M_PIq);
                    yn = smod(1.4Q*sinq(x+y)+y,2.Q*M_PIq);
                    x = xn;
                    y = yn;
                }
                diff_mag=0.Q;
                for(v=0; v<fnum; v++) {
                    diff[v]=(second[v]-first[v])/wsum;
                    diff_mag+=diff[v]*diff[v];
                }
                diff_mag = sqrtq(diff_mag);
                numzeros = (char)(-1.Q*log10q(diff_mag));
                for(t=0;t<time;t++) {
                    m[(int)fmin(fmax(traj[t][1],0),rows-1)][(int)fmin(fmax(traj[t][0],0),cols-1)] = numzeros;
                }
                //m[i][j]=(unsigned char)numzeros; (old way)
            }
        }
    }
    for(int o=0; o< time; o++) {
        free(traj[o]);
    }
    free(traj);
    for(int i=0; i<rows; i++) {
        for(int j=0; j<cols; j++) {
            fprintf(f, "m[%u][%u] is %d",i,j,m[i][j]);
        }
    }

    printf("%u\n",m[8][8]);
}
Ejemplo n.º 6
0
void partition(int weighted, int rows, int cols, int time, long double aleastx, long double aleasty,
        long double adeltax, long double adeltay, int kgrid, unsigned long (*m)[cols]) {

    FILE *f;
    
    const char name[] = "outputs/text_birkhoff_fvals_t%u_g%u_xs%.2Lf_ys%.2Lf_xb%.2Lf_yb%.2Lf_%s_2.txt";
    char fname[100];
    if(weighted) {
        sprintf(fname, name, time,rows, aleastx, aleasty, aleastx+rows*adeltax,aleasty+cols*adeltay,"weighted");
    } else {
        sprintf(fname, name, time,rows, aleastx, aleasty, aleastx+rows*adeltax,aleasty+cols*adeltay,"unweighted");
    }
    __float128 leastx = aleastx;
    __float128 leasty = aleasty;
    __float128 deltax = adeltax;
    __float128 deltay = adeltay;

    f= fopen(fname,"w");
    clock_t begin,end;
    begin = clock();
    int i, j, t, v;
    __float128 x,y, xn, yn;
    __float128 wsum=0.;
    __float128* weights = (__float128*) malloc(sizeof(__float128)*time);
    for(t=0; t<time; t++) {
        weights[t]=weight((__float128)t/(__float128)time);
        wsum += weights[t];
    }
    __float128 ***evecs = (__float128***) malloc(sizeof(__float128**)*rows);
    for(int i=0; i < rows; i++) {
        evecs[i] = (__float128 **) malloc(sizeof(__float128*)*cols);
        for(int j=0; j < cols; j++) {
            evecs[i][j] = calloc(sizeof(__float128),2);
        }
    }
    for(i=0; i < rows; i++) {
        for(j=0; j < cols; j++) {
            if(m[i][j]==1) {
                x = leastx + j*deltax + 0.5Q*deltax;
                y = leasty + i*deltay + 0.5Q*deltay;
                for( t=0; t <time; t++) {
                    for( v=0; v<2;v++) {
                        if(weighted) {
                            evecs[i][j][v]+= (*hvec[v])(x,y)*weights[t];
                        } else {
                            evecs[i][j][v]+= (*hvec[v])(x,y);
                        }
                    }
                    xn = smod(x+y,2.Q*M_PIq);
                    yn = smod(.5*sin(x+y)+y,2.Q*M_PIq);
                    x = xn;
                    y = yn;
                }
                for( v=0; v<2;v++) {
                    if(weighted) {
                        evecs[i][j][v]/=wsum;
                    } else {
                        evecs[i][j][v]/=(__float128)time;
                    }
                }

            }
        }
    }
    //__float128 fdelta = 1.Q/(__float128)kgrid;
    for(i=0; i < rows; i++) {
        for(j=0; j < cols; j++) {

            fprintf(f,"i: %u, j: %u,x: %.2f, y: %.2f, h1: %.2f, h2: %.2f, h2/h1: %.2f\n", i, j, (double)leastx+j*(double)deltax,(double)leasty+i*(double)deltay,(double)evecs[i][j][0],(double)evecs[i][j][1],(double)evecs[i][j][1]/(double)evecs[i][j][0]);
            if(m[i][j]==1) {
                m[i][j]=0;
                //for(v=0; v<2; v++) {
                printf("evecs[%u][%u][0] = %f\n",i,j,(double)evecs[i][j][0]);
                printf("evecs[%u][%u][1] = %f\n",i,j,(double)evecs[i][j][1]);
                m[i][j] = floor(100000.Q*evecs[i][j][1]/evecs[i][j][0]);//+= floor(evecs[i][j][v]/fdelta) * pow(kgrid,v);

                //}
            }
        }
    }
    fclose(f);
    end=clock();
    double runtime = (double)(end-begin)/(double)CLOCKS_PER_SEC;
    printf("run time: %f\n",runtime);
    /*for(i=0; i <rows; i++) {
        for(j=0; j<cols; j++) {
            printf("%u", m[i][j]);
        }
        printf("\n");
    }*/

}