00001
00002
00003
00004
00005
00006 using namespace nCenterFocus;
00007 using std::list;
00008
00009 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00010 CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::CFRandomExperiment(
00011 CenterFocusExperiment<variant> & cfExperiment,
00012 D_CenterfocusParams const* cfparams,
00013 TFrommer1 & frommer1,
00014 TFrommer2 & frommer2,
00015 RankStatistic & fullRankStatistic,
00016 RankStatistic & subRankStatistic,
00017 LiftAndQuadricsStatistic & fullQuadricsStatistic,
00018 LiftAndQuadricsStatistic & subQuadricsStatistic,
00019 FailedLiftStatistic &liftStatistic,
00020 TPolynomXY & randomMinusP_polynom,
00021 TPolynomXY & randomQ_polynom
00022 ):
00023 cfparams_m(cfparams),
00024 cfExperiment_m(cfExperiment),
00025 frommer1_m(frommer1),
00026 frommer2_m(frommer2),
00027 randomMinusP_polynom_m(randomMinusP_polynom),
00028 randomQ_polynom_m(randomQ_polynom),
00029 f1_ring_ref_m( frommer1.getRingRef() ),
00030 f2_ring_ref_m( frommer2.getRingRef() ),
00031 frommer1_field_ref( frommer1_m.getRing()->getFieldRef() ),
00032 polynomialRing_m(frommer1.getRingRef() ),
00033 st_m(NULL),
00034 fullRankStatistic_m(fullRankStatistic),
00035 subRankStatistic_m(subRankStatistic),
00036 fullQuadricsStatistic_m(fullQuadricsStatistic),
00037 subQuadricsStatistic_m(subQuadricsStatistic),
00038 liftStatistic_m(liftStatistic),
00039 v1_m ( performFormula23Step_construct_v1( ) ),
00040 v2_m ( performFormula23Step_construct_v2( ) ),
00041 coeffRandomVariablesOrder_m(initRandomVariablesOrder() ),
00042 randomCounter_m(0)
00043
00044
00045
00046 {
00047 #ifdef FORMULA23_TIMER
00048
00049 formula23_compute_bcd_a1_not_zero_count = 0;
00050 formula23_compute_bcd_a2_not_zero_count = 0;
00051 formula23_analyze_all_time_count = 0;
00052
00053 formula23_step_time_m=0;
00054 formula23_compute_a_time_m=0;
00055 compute_bcd_a1_not_zero_time_m=0;
00056 compute_bcd_a2_not_zero_time_m=0;
00057 computeSolutions_time_m=0;
00058 analyze_all_time_m = 0;
00059 random_trials_time_m=0;
00060
00061 formula23_compute_a_getFocalValues_time_m=0;
00062 compute_bcd_a1_not_zero_getFocalValues_time_m=0;
00063 compute_bcd_a2_not_zero_getFocalValues_time_m=0;
00064 tim1_m.clear();
00065 tim2_m.clear();
00066 tim3_m.clear();
00067
00068 #endif
00069
00070
00071 psolutions_m = new typename TFrommer1::RingType::ScalarType[frommer1_field_ref.getCharacteristic() ];
00072 pPointSolutions_m = new pair <TPolynomXY,TPolynomXY>[ frommer1_field_ref.getCharacteristic()*frommer1_field_ref.getCharacteristic() ];
00073
00074 drittel_m = f1_ring_ref_m.getField()->multInv(f1_ring_ref_m.getField()->Convert(3) ) ;
00075 zwei_m = f1_ring_ref_m.getField()->Convert(2) ;
00076
00077 initRandomExperiment();
00078
00079 }
00080
00081
00091
00094 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00095 void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::initRandomExperiment( )
00096 {
00097
00098
00099 bool bCoeff_Q_30isRandom = cfparams_m->getMonomsWithRandomCoefficients().containsEntry(QCoefficient, 3,0) ;
00100 bool bCoeff_P_30isRandom = cfparams_m->getMonomsWithRandomCoefficients().containsEntry(PCoefficient, 3,0) ;
00101
00102
00103 bUseFormula1_m = false;
00104 bUseFormula2_m = false;
00105 bUseFormula23_m = false;
00106
00107
00108 if ( cfparams_m->useFormula1() || cfparams_m->useFormula2() || cfparams_m->useFormula23() )
00109 {
00110 assert( cfparams_m->getPolynomialDegree()==3 ) ;
00111 }
00112
00113 if ( cfparams_m->useFormula1() )
00114 {
00115 assert (bCoeff_Q_30isRandom);
00116
00117
00118 bUseFormula1_m = true;
00119 assert(cfparams_m->requiredVanishedFocalValuesNum()>0);
00120 if (cfparams_m->getHamiltonianComponentSwitch()==1)
00121 assert(cfparams_m->requiredVanishedFocalValuesNum()>1);
00122 }
00123
00124 if ( cfparams_m->useFormula2() )
00125 {
00126 assert (bCoeff_P_30isRandom);
00127 assert( cfparams_m->useFormula1() );
00129
00130
00131
00132 bUseFormula2_m=true;
00133 assert(cfparams_m->requiredVanishedFocalValuesNum()>1);
00134
00135 if (cfparams_m->getHamiltonianComponentSwitch()==1)
00136 assert(cfparams_m->requiredVanishedFocalValuesNum()>2);
00137 }
00138
00139 if ( cfparams_m->useFormula23() )
00140 {
00141
00142 assert(cfparams_m->useFormula1() );
00144
00145
00146 assert(cfparams_m->getFieldCharacteristic()>=3 );
00147
00148
00149
00150
00151
00152
00153
00154
00155 const CoeffList & randomCoeffList = cfparams_m->getMonomsWithRandomCoefficients();
00156
00157
00158
00159 assert( cfparams_m->isCoefficientVariable( 3, 0, PCoefficient) );
00160
00161 assert(randomCoeffList.containsEntry( CoeffListEntry(PCoefficient, 0,3) ) );
00162 assert( cfparams_m->isCoefficientVariable( 1, 2, PCoefficient) );
00163 assert(randomCoeffList.containsEntry( CoeffListEntry(PCoefficient, 2,3) ) );
00164 assert( cfparams_m->isCoefficientVariable( 2, 1, PCoefficient) );
00165 assert(randomCoeffList.containsEntry( CoeffListEntry(PCoefficient, 1,3) ) );
00166 assert( cfparams_m->isCoefficientVariable( 0, 3, PCoefficient) );
00167 assert(randomCoeffList.containsEntry( CoeffListEntry(PCoefficient, 3,3) ) );
00168
00169 assert( cfparams_m->isCoefficientVariable( 3, 0, QCoefficient) );
00170 assert(randomCoeffList.containsEntry( CoeffListEntry(QCoefficient, 0,3) ) );
00171 assert( cfparams_m->isCoefficientVariable( 1, 2, QCoefficient) );
00172 assert(randomCoeffList.containsEntry( CoeffListEntry(QCoefficient, 2,3) ) );
00173 assert( cfparams_m->isCoefficientVariable( 2, 1, QCoefficient) );
00174 assert(randomCoeffList.containsEntry( CoeffListEntry(QCoefficient, 1,3) ) );
00175 assert( cfparams_m->isCoefficientVariable( 0, 3, QCoefficient) );
00176 assert(randomCoeffList.containsEntry( CoeffListEntry(QCoefficient, 3,3) ) );
00177 bUseFormula23_m = true;
00178
00179 assert(cfparams_m->requiredVanishedFocalValuesNum()>2);
00180 if (cfparams_m->getHamiltonianComponentSwitch()==1)
00181 assert(cfparams_m->requiredVanishedFocalValuesNum()>3);
00182
00183
00184
00185 }
00186
00187 if (! bUseFormula1_m && !bUseFormula2_m && !bUseFormula23_m)
00188 st_m=new DStatistic( cfparams_m->getMaxFocalValuesToCompute(), 0);
00189 else if (bUseFormula1_m && !bUseFormula2_m && !bUseFormula23_m)
00190 st_m=new DStatistic( cfparams_m->getMaxFocalValuesToCompute(), 1);
00191 else if (bUseFormula1_m && bUseFormula2_m )
00192 st_m=new DStatistic( cfparams_m->getMaxFocalValuesToCompute(), 2);
00193 else if (bUseFormula1_m && bUseFormula23_m )
00194 st_m=new DStatistic( cfparams_m->getMaxFocalValuesToCompute(), 3);
00195
00196 assert(st_m!=NULL);
00197
00198 }
00199
00203 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00204 list<CoeffListEntry> CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::initRandomVariablesOrder()
00205 {
00206 list<CoeffListEntry> coeffRandomVariablesOrder;
00207 list<CoeffListEntry>::const_iterator coeffIt;
00208 list<CoeffListEntry> allCoeffVariablesOrder = cfparams_m->getCoeffVariablesOrder();
00209 coeffIt =allCoeffVariablesOrder.begin();
00210 while (coeffIt!=allCoeffVariablesOrder.end() )
00211 {
00212 if ( cfparams_m->isRandomVariable( *coeffIt ) )
00213 coeffRandomVariablesOrder.push_back( *coeffIt );
00214 coeffIt++;
00215 }
00216 return coeffRandomVariablesOrder;
00217 }
00218
00219
00220 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00221 DStatistic& CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::getStatisticRef()
00222 {
00223 return *st_m;
00224 }
00225
00227 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00228 pair<TPolynomXY,TPolynomXY> CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::performFormula23Step_construct_v1( )
00229 {
00230
00231
00232 pair<TPolynomXY,TPolynomXY> v1 ( TPolynomXY ( cfparams_m->getPolynomialDegree() ), TPolynomXY ( cfparams_m->getPolynomialDegree() ) );
00233
00234 if (cfparams_m->getPolynomialDegree()<3)
00235
00236 return v1;
00237
00238 typename TPolynomXY::CoefficientType coeff;
00239
00240 coeff.setX(1) ;
00241 v1.first.setCoeff(3,0, f1_ring_ref_m.addInv( coeff) );
00242
00243 v1.second.setCoeff( 0,3, coeff ) ;
00244
00245 coeff.setX(3) ;
00246 v1.first.setCoeff(1,2, coeff );
00247
00248 v1.second.setCoeff( 2,1, f1_ring_ref_m.addInv( coeff ) );
00249
00250 return v1;
00251 }
00252
00253
00254
00255 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00256 pair<TPolynomXY,TPolynomXY> CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::performFormula23Step_construct_v2( )
00257 {
00258 pair<TPolynomXY,TPolynomXY> v2 ( TPolynomXY ( cfparams_m->getPolynomialDegree() ), TPolynomXY ( cfparams_m->getPolynomialDegree() ) );
00259
00260 if (cfparams_m->getPolynomialDegree()<3)
00261
00262 return v2;
00263
00264 typename TPolynomXY::CoefficientType coeff;
00265
00266
00267
00268
00269 coeff.setX(1);
00270 v2.first.setCoeff( 0,3, coeff );
00271
00272 v2.second.setCoeff( 3,0, coeff ) ;
00273 coeff.setX(3);
00274 v2.first.setCoeff( 2,1, f1_ring_ref_m.addInv(coeff) );
00275
00276 v2.second.setCoeff( 1,2, f1_ring_ref_m.addInv( coeff ) );
00277
00278 return v2;
00279 }
00280
00281
00285
00289 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00290 void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::initRandomCoefficients( TPolynomXY & p,
00291 TPolynomXY & q
00292 )
00293 {
00294 typename TPolynomXY::CoefficientType value(0);
00295
00296
00297 list<CoeffListEntry>::const_iterator coeffIt = coeffRandomVariablesOrder_m.begin();
00298 while (coeffIt!=coeffRandomVariablesOrder_m.end() )
00299 {
00300 value.setX( f1_ring_ref_m.getField()->ConvertScalar( random( cfparams_m->getRandomSeedPtr(),
00301 f1_ring_ref_m.getCharacteristic() -1
00302 )
00303 )
00304 );
00305
00306 if ((*coeffIt).porq == PCoefficient)
00307 {
00308
00309 p.setCoeff((*coeffIt).x_exp, (*coeffIt).y_exp, f1_ring_ref_m.addInv(value) );
00310 }
00311 else
00312 {
00313 q.setCoeff((*coeffIt).x_exp,(*coeffIt).y_exp, value);
00314 }
00315 coeffIt++;
00316 }
00317 }
00318
00321 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00322 void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::performSingleALLExperiment(TPolynomXY randomMinusP_polynom, TPolynomXY randomQ_polynom )
00323 {
00324
00325 bool finished = false;
00326 assert( cfparams_m->polynomsHaveCheckAllCoeff() );
00327 assert( ! bUseFormula23_m );
00328
00329 while (!finished)
00330 {
00331 #ifdef DEBUG
00332 TPolynomXY PE= polynomialRing_m.addInv(randomMinusP_polynom );
00333 cfExperiment_m.getResultPrinterConstRef().printPolynoms(std::cerr,PE, randomMinusP_polynom ,string("Testausgabe: performSingleALLExperiment \n "));
00334 getchar();
00335 #endif
00336
00337
00338 #ifdef SAFE
00339 for (int deg = randomMinusP_polynom.getDegree(); deg>=0; deg--)
00340 {
00341 for (int x_exp=deg; x_exp>=0; x_exp--)
00342 {
00343 assert( (int)randomQ_polynom.getCoeff (x_exp, deg-x_exp).getEps()==0 );
00344 assert( (int)randomMinusP_polynom.getCoeff(x_exp, deg-x_exp).getEps()==0 );
00345 }
00346 }
00347 #endif
00348 #ifdef MTCP
00349 mtcp_no();
00350 #endif
00351 correctStatistic();
00352 cfExperiment_m.performRegularExperiment( frommer1_m ,
00353 frommer2_m,
00354 polynomialRing_m,
00355 randomMinusP_polynom,
00356 randomQ_polynom,
00357 *st_m,
00358 fullRankStatistic_m,
00359 subRankStatistic_m,
00360 fullQuadricsStatistic_m,
00361 subQuadricsStatistic_m,
00362 liftStatistic_m );
00363
00364
00365 finished = setNextAllCoefficient( randomMinusP_polynom, randomQ_polynom );
00366 #ifdef MTCP
00367 MtcpManager_g.checkpointingTimeFrame();
00368 #endif
00369 }
00370 return;
00371 }
00372
00373
00375 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00376 void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::performSingleRandomTrial(const TPolynomXY & randomMinusP_polynom,const TPolynomXY &randomQ_polynom )
00377 {
00378
00379 if ( cfparams_m->polynomsHaveCheckAllCoeff() )
00380 {
00381 performSingleALLExperiment( randomMinusP_polynom, randomQ_polynom );
00382 }
00383 else
00384 {
00385 #ifdef DEBUG
00386 TPolynomXY PE= polynomialRing_m.addInv(randomMinusP_polynom );
00387 cfExperiment_m.getResultPrinterConstRef().printPolynoms(std::cerr,PE, randomMinusP_polynom ,string("Testausgabe: performSingleRandomExperiment \n "));
00388 getchar();
00389 #endif
00390
00391 #ifdef SAFE
00392 for (int deg = randomMinusP_polynom.getDegree(); deg>=0; deg--)
00393 {
00394 for (int x_exp=deg; x_exp>=0; x_exp--)
00395 {
00396 assert( (int)randomQ_polynom.getCoeff (x_exp, deg-x_exp).getEps()==0 );
00397 assert( (int)randomMinusP_polynom.getCoeff(x_exp, deg-x_exp).getEps()==0 );
00398 }
00399 }
00400 #endif
00401
00402
00403 cfExperiment_m.performRegularExperiment( frommer1_m ,
00404 frommer2_m,
00405 polynomialRing_m,
00406 randomMinusP_polynom,
00407 randomQ_polynom,
00408 *st_m,
00409 fullRankStatistic_m,
00410 subRankStatistic_m,
00411 fullQuadricsStatistic_m,
00412 subQuadricsStatistic_m,
00413 liftStatistic_m );
00414
00415
00416 }
00417 }
00418
00420 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00421 inline void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>:: correctStatistic()
00422 {
00423 #ifdef SAFE
00424 assert( (bUseFormula2_m &&bUseFormula1_m && !bUseFormula23_m )|| !bUseFormula2_m );
00425 assert( (bUseFormula23_m &&bUseFormula1_m && !bUseFormula2_m)|| !bUseFormula23_m );
00426 #endif
00427
00428 if (bUseFormula1_m )
00429 {
00430 if ( bUseFormula23_m)
00431 {
00432 st_m->addFormula1And23Try( cfparams_m->getFieldCharacteristic() );
00433
00434 }
00435 else if ( bUseFormula2_m && bUseFormula1_m )
00436 {
00437
00438 st_m->addFormula1And2Try( cfparams_m->getFieldCharacteristic() );
00439
00440 }
00441 else if ( ! bUseFormula2_m && ! bUseFormula23_m)
00442 st_m->addFormula1Try( cfparams_m->getFieldCharacteristic() );
00443
00444 }
00445 }
00446
00447
00459
00465 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00466 void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::performRandomExperiment( )
00467 {
00469
00470
00471 long64 randomExperimentsMaxNum = 0;
00472
00473 if ( cfparams_m->polynomsHaveRandomCoeff() )
00474 {
00475 randomExperimentsMaxNum = cfparams_m->getRequestedTrialsNum()-1;
00476 assert(randomExperimentsMaxNum>=0);
00477
00478 }
00479 else
00480 {
00481 cerr << "error: no randomCoeff detected" << endl;
00482 exit(0);
00483 }
00484
00485
00486 long64 startRandomcounter = cfparams_m->getRandomCounterStartValue();
00487
00488
00489 for ( randomCounter_m = 0; randomCounter_m <= randomExperimentsMaxNum; randomCounter_m++ )
00490 {
00491
00492 if (cfparams_m->polynomsHaveRandomCoeff() )
00493 {
00494 initRandomCoefficients( randomMinusP_polynom_m, randomQ_polynom_m);
00495 }
00496
00497
00498 if (randomCounter_m >= startRandomcounter )
00499 {
00500 #ifdef MTCP
00501 mtcp_no();
00502 #endif
00503 #ifdef DEBUG
00504 TPolynomXY PE= polynomialRing_m.addInv(randomMinusP_polynom_m );
00505 cfExperiment_m.getResultPrinterConstRef().printPolynoms(std::cerr,PE, randomQ_polynom_m ,string("Testausgabe: vor (compute p, q) \n "));
00506
00507 getchar();
00508 #endif
00509 correctStatistic();
00510
00511 if (bUseFormula1_m && ! bUseFormula2_m && ! bUseFormula23_m)
00512 {
00513 compute_q_coeff_x_3_y_0 (randomMinusP_polynom_m, randomQ_polynom_m );
00514 performSingleRandomTrial( randomMinusP_polynom_m,
00515 randomQ_polynom_m );
00516 }
00517
00518
00520 if ( bUseFormula2_m && bUseFormula1_m )
00521 {
00522 compute_q_coeff_x_3_y_0 (randomMinusP_polynom_m, randomQ_polynom_m );
00523
00524 compute_p_coeff_x_3_y_0(randomMinusP_polynom_m, randomQ_polynom_m );
00525 }
00526
00527 if ( bUseFormula23_m)
00528 {
00529
00530 compute_q_coeff_x_3_y_0 (randomMinusP_polynom_m, randomQ_polynom_m );
00531
00532 performFormula23Step(randomMinusP_polynom_m, randomQ_polynom_m );
00533 }
00534
00535 if (! bUseFormula1_m && ! bUseFormula2_m && ! bUseFormula23_m)
00536 {
00537
00538
00539 performSingleRandomTrial( randomMinusP_polynom_m,
00540 randomQ_polynom_m );
00541 }
00542 #ifdef MTCP
00543 MtcpManager_g.checkpointingTimeFrame();
00544 #endif
00545
00546
00547
00548
00549
00550 }
00551
00552 }
00553 }
00554
00555
00556
00557
00558
00561 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00562 inline bool CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::setNextAllCoefficient( TPolynomXY & allMinusP_polynom,
00563 TPolynomXY & allQ_polynom )
00564 {
00565 bool finished = false;
00566
00567 const CoeffListEntry * currentMonomWithAllCoefficients = cfparams_m->getMonomsWithAllCoefficients().getFirstConst();
00568
00569 typename TFrommer1::RingType::ElementType value = TFrommer1::RingType::ElementType::Zero;
00570
00571
00572 while (( value.getX()==0)&&( value.getEps()==0)&& (!finished) )
00573 {
00574 if (currentMonomWithAllCoefficients->porq == PCoefficient)
00575 {
00576 value = allMinusP_polynom.getCoeff(currentMonomWithAllCoefficients->x_exp, currentMonomWithAllCoefficients->y_exp);
00577
00578 f1_ring_ref_m.addInPlaceRef(value, TFrommer1::RingType::ElementType::One);
00579
00580 allMinusP_polynom.setCoeff(currentMonomWithAllCoefficients->x_exp, currentMonomWithAllCoefficients->y_exp, value);
00581 }
00582 else
00583 {
00584 value = allQ_polynom.getCoeff(currentMonomWithAllCoefficients->x_exp, currentMonomWithAllCoefficients->y_exp);
00585
00586 f1_ring_ref_m.addInPlaceRef(value, TFrommer1::RingType::ElementType::One);
00587
00588 allQ_polynom.setCoeff(currentMonomWithAllCoefficients->x_exp, currentMonomWithAllCoefficients->y_exp, value);
00589 }
00590
00591 if (( value.getX() == 0) && ( value.getEps()==0))
00592 {
00593 currentMonomWithAllCoefficients = currentMonomWithAllCoefficients->getNextConst();
00594 if ( currentMonomWithAllCoefficients == NULL )
00595 finished=true;
00596 }
00597 }
00598 return finished;
00599
00600 }
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00636 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00637 inline void
00638 CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::compute_q_coeff_x_3_y_0( const TPolynomXY & minusP_polynom,
00639 TPolynomXY & Q_polynom
00640 )
00641 {
00642
00643
00644
00645
00646 typename TFrommer1::RingType::ElementType formel1zw ( minusP_polynom.getCoeff(2,0) );
00647
00648 f1_ring_ref_m.addInPlaceRef(formel1zw, minusP_polynom.getCoeffConstRef(0,2));
00649 f1_ring_ref_m.multiplyInPlaceRef(formel1zw, minusP_polynom.getCoeffConstRef(1,1));
00650
00651 f1_ring_ref_m.addInPlaceRef(formel1zw, minusP_polynom.getCoeffConstRef(2,1) );
00652 f1_ring_ref_m.addInPlaceRef(formel1zw, Q_polynom.getCoeffConstRef(1,2) );
00653
00654 f1_ring_ref_m.addInvInPlace(formel1zw);
00655
00656
00657 f1_ring_ref_m.accMultRef(formel1zw, Q_polynom.getCoeffConstRef(2,0), Q_polynom.getCoeffConstRef(1,1) );
00658 f1_ring_ref_m.accMultRef(formel1zw, Q_polynom.getCoeffConstRef(1,1), Q_polynom.getCoeffConstRef(0,2) );
00659
00660
00661 typename TFrommer1::RingType::ElementType formel1erg( minusP_polynom.getCoeff(2,0) );
00662 f1_ring_ref_m.multiplyInPlaceRef(formel1erg, Q_polynom.getCoeffConstRef(2,0) );
00663 f1_ring_ref_m.addInvInPlace( formel1erg );
00664 f1_ring_ref_m.accMultRef(formel1erg, minusP_polynom.getCoeffConstRef(0,2), Q_polynom.getCoeffConstRef(0,2) );
00665
00666
00667 f1_ring_ref_m.scalarMultiplyInPlaceRef(zwei_m, formel1erg);
00668
00669 f1_ring_ref_m.addInPlaceRef(formel1erg,formel1zw);
00670
00671
00672
00673 f1_ring_ref_m.scalarMultiplyInPlaceRef(drittel_m, formel1erg);
00674
00675
00676 f1_ring_ref_m.addInPlace(formel1erg, f1_ring_ref_m.addInv( minusP_polynom.getCoeffConstRef(0,3) ) );
00677 #ifdef SAFE
00678 assert(formel1erg.getEps()==0);
00679 #endif
00680
00681 #ifdef CF_TEST
00682
00683 for (int i=0; i<f1_ring_ref_m.getCharacteristic(); i++)
00684 {
00685 if ( i != formel1erg.getX() )
00686 {
00687
00688 Q_polynom.setCoeff(3,0, i);
00689 frommer1_m.setPolynoms(&(minusP_polynom), &(Q_polynom) ) ;
00690
00691 frommer1_m.template doitx<1>(1);
00692
00693 assert(frommer1_m.getFocalValue(1)!=TFrommer1::RingType::ElementType::Zero);
00694
00695 }
00696 else
00697 {
00698 Q_polynom.setCoeff(3,0, i);
00699 frommer1_m.setPolynoms(&(minusP_polynom), &(Q_polynom) ) ;
00700
00701 frommer1_m.template doitx<1>(1);
00702
00703 assert(frommer1_m.getFocalValue(1)==TFrommer1::RingType::ElementType::Zero);
00704 }
00705
00706 }
00707 #endif
00708
00709 Q_polynom.setCoeff(3,0, formel1erg);
00710
00711 return;
00712 }
00713
00714
00715
00716
00717
00718
00726 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00727 inline void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::
00728 compute_p_coeff_x_3_y_0( TPolynomXY & randomMinusP_polynom,
00729 const TPolynomXY & randomQ_polynom
00730 )
00731 {
00732 typename TFrommer2::RingType::ElementType epsilon1(0,1);
00733
00734 typename TFrommer2::TPolynomXY randomMinusP_polynom_epsPrecision_1( randomMinusP_polynom.getDegree() ) ;
00735 typename TFrommer2::TPolynomXY randomQ_polynom_epsPrecision_1 ( randomQ_polynom.getDegree() );
00736
00737
00738 cfExperiment_m.copyPolynomWithGivenEpsPrecision(randomMinusP_polynom, randomMinusP_polynom_epsPrecision_1, 0);
00739 cfExperiment_m.copyPolynomWithGivenEpsPrecision(randomQ_polynom , randomQ_polynom_epsPrecision_1 , 0);
00740
00741
00742
00743
00744 assert(f2_ring_ref_m.getEpsPrecision() == 1 );
00745
00748
00749 randomMinusP_polynom_epsPrecision_1.setCoeff(3,0, f2_ring_ref_m.addInv( epsilon1 ) );
00750
00751 frommer2_m.setPolynoms (& randomMinusP_polynom_epsPrecision_1, & randomQ_polynom_epsPrecision_1);
00752
00753
00754 frommer2_m.template doitx<2>(2) ;
00755
00756 typename TFrommer2::RingType::ElementType focalValue_2 = frommer2_m.getFocalValue(2);
00757
00758
00759
00760
00761 typename TFrommer1::RingType::ElementType resCoeff(0);
00762
00763 if (focalValue_2.getEps() != 0)
00764 {
00765 typename TFrommer2::RingType::FieldType const & f2field_ref = f2_ring_ref_m.getFieldRef();
00766
00767 resCoeff.setX( (f2field_ref.addInv( f2field_ref.multiply( focalValue_2.getX(),
00768 f2field_ref.multInv(focalValue_2.getEps() )
00769 )
00770 )
00771 ).getX()
00772 );
00773 f1_ring_ref_m.addInvInPlace(resCoeff);
00774
00775
00776 }
00777 else
00778 {
00779
00780 }
00781
00782
00783 #ifdef CF_TEST
00784 for (int i=0; i<f1_ring_ref_m.getCharacteristic(); i++)
00785 {
00786 if ( typename TFrommer1::RingType::ElementType(i) != resCoeff )
00787 {
00788
00789 randomMinusP_polynom_m.setCoeff(3,0, i);
00790 frommer1_m.setPolynoms(&(randomMinusP_polynom), &(randomQ_polynom) ) ;
00791
00792 frommer1_m.template doitx<2>(2);
00793 if (frommer1_m.getFocalValue(2)==TFrommer1::RingType::ElementType::Zero)
00794 {
00795
00796
00797
00798 }
00799 if (focalValue_2 != 0)
00800 assert(frommer1_m.getFocalValue(2)!=TFrommer1::RingType::ElementType::Zero);
00801 }
00802 else
00803 {
00804 randomMinusP_polynom_m.setCoeff(3,0, i);
00805 frommer1_m.setPolynoms(&(randomMinusP_polynom), &(randomQ_polynom) ) ;
00806
00807 frommer1_m.template doitx<2>(2);
00808 if (focalValue_2.getEps() != 0)
00809 {
00810 assert(frommer1_m.getFocalValue(2)==TFrommer1::RingType::ElementType::Zero);
00811 }
00812 else
00813 {
00814 if (focalValue_2.getX() != 0)
00815 assert(frommer1_m.getFocalValue(2)!=TFrommer1::RingType::ElementType::Zero);
00816
00817
00819 }
00820 }
00821 }
00822
00823 #endif
00824 if (focalValue_2 != 0)
00825 {
00826 randomMinusP_polynom_m.setCoeff(3,0, resCoeff);
00827
00828
00829 assert(randomMinusP_polynom_m.getCoeff(3,0).getEps()==0);
00830 performSingleRandomTrial( randomMinusP_polynom_m, randomQ_polynom_m );
00831 }
00832 else
00833 {
00834 int characteristic = f1_ring_ref_m.getCharacteristic();
00835 for (int i=0; i< characteristic; i++)
00836 {
00837 randomMinusP_polynom_m.setCoeff(3,0, i);
00838 frommer1_m.setPolynoms(&(randomMinusP_polynom), &(randomQ_polynom) ) ;
00839
00840 frommer1_m.template doitx<2>(2);
00841 int solutionCounter=0;
00842 if (frommer1_m.getFocalValue(2)== typename TFrommer1::RingType::ElementType(0) )
00843 {
00844
00845 solutionCounter++;
00846 performSingleRandomTrial( randomMinusP_polynom_m,
00847 randomQ_polynom_m );
00848 }
00849 }
00850 }
00851
00852
00853 #ifdef DEBUG
00854 std::cerr << "compute_p_koeff_x_3_y_0 finished" << std::endl ;
00855 getchar();
00856 #endif
00857
00858 }
00859
00860
00861 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00862 typename TFrommer1::RingType::ScalarType
00863 CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::
00864 performFormula23Step_getThirdFocalValue ( const pair< TPolynomXY, TPolynomXY > & polynompair ) const
00865 {
00866 frommer1_m.setPolynoms(&(polynompair.first), &(polynompair.second) ) ;
00867
00868
00869 frommer1_m.template doitx < 3> ( 3 );
00870
00871 #ifdef SAFE
00872 typename TPolynomXY::CoefficientType firstFocalValue = frommer1_m.getFocalValue(1);
00873
00874 assert( firstFocalValue.isZero() );
00875 #endif
00876
00877
00878
00879
00880 return frommer1_m.getFocalValue(3);
00881 }
00882
00883
00884 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00885 typename TFrommer1::RingType::ScalarType
00886 CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::
00887 performFormula23Step_getSecondFocalValue ( const pair< TPolynomXY , TPolynomXY > & polynompair ) const
00888 {
00889 frommer1_m.setPolynoms(&(polynompair.first), &(polynompair.second) ) ;
00890
00891 frommer1_m.template doitx<2>(2);
00892
00893 #ifdef SAFE
00894 typename TPolynomXY::CoefficientType firstFocalValue = frommer1_m.getFocalValue(1);
00895 assert( firstFocalValue.isZero() );
00896 #endif
00897
00898
00899
00900 return frommer1_m.getFocalValue(2);
00901 }
00902
00903
00906 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00907 inline pair<TPolynomXY,TPolynomXY>
00908 CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::
00909 performFormula23Step_computePoint (typename TFrommer1::RingType::ScalarType v1coeff,
00910 typename TFrommer1::RingType::ScalarType v2coeff,
00911 const pair<const TPolynomXY ,const TPolynomXY > & PQPolynomPair
00912 ) const
00913 {
00914 pair<TPolynomXY,TPolynomXY> ret ( polynomialRing_m.scalarMultiply( v1coeff, v1_m.first ),
00915 polynomialRing_m.scalarMultiply( v1coeff, v1_m.second) );
00916
00917 polynomialRing_m.addInPlace( ret.first, PQPolynomPair.first );
00918 polynomialRing_m.addInPlace( ret.second, PQPolynomPair.second );
00919
00920 polynomialRing_m.addInPlace(ret.first, polynomialRing_m.scalarMultiply( v2coeff, v2_m.first ) );
00921 polynomialRing_m.addInPlace(ret.second, polynomialRing_m.scalarMultiply( v2coeff, v2_m.second) );
00922
00923
00924 return ret;
00925 }
00926
00927 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00928 inline void
00929 CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::
00930 performFormula23Step_computePointNew(typename TFrommer1::RingType::ScalarType v1coeff,
00931 typename TFrommer1::RingType::ScalarType v2coeff,
00932 const pair<const TPolynomXY ,const TPolynomXY > & PQPolynomPair,
00933 pair<TPolynomXY,TPolynomXY> & ret
00934 ) const
00935 {
00936 polynomialRing_m.scalarMultiplyInPlace( v1coeff, ret.first );
00937 polynomialRing_m.scalarMultiplyInPlace( v1coeff, ret.second) ;
00938
00939 polynomialRing_m.addInPlace( ret.first, PQPolynomPair.first );
00940 polynomialRing_m.addInPlace( ret.second, PQPolynomPair.second );
00941
00942 polynomialRing_m.addInPlace(ret.first, polynomialRing_m.scalarMultiply( v2coeff, v2_m.first ) );
00943 polynomialRing_m.addInPlace(ret.second, polynomialRing_m.scalarMultiply( v2coeff, v2_m.second) );
00944
00945 }
00946
00949 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
00950 void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::
00951 performFormula23Step_solveQ(unsigned int & solutions,typename TFrommer1::RingType::ScalarType * b )
00952 {
00953
00954
00955 typename TFrommer1::RingType::ScalarType frommer1_Null(0);
00956
00957 typename TFrommer1::RingType::ScalarType bp,bq;
00958
00959 solutions=0;
00960
00961 if ( b[2] != frommer1_Null)
00962 {
00963
00964
00965
00966
00967
00968 bq = frommer1_field_ref.multiply(b[0], frommer1_field_ref.multInv( b[2] ) );
00969
00970 bp = frommer1_field_ref.multiply( b[1],
00971 frommer1_field_ref.multiply( frommer1_field_ref.multInv( b[2] ),
00972 frommer1_field_ref.multInv(2)
00973 )
00974 );
00975
00976
00977
00978
00979 typename TFrommer1::RingType::ScalarType discriminant = frommer1_field_ref.multiply(bp,bp);
00980 frommer1_field_ref.addInPlace(discriminant, frommer1_field_ref.addInv( bq) );
00981
00982
00983
00984 if ( discriminant== frommer1_Null )
00985 {
00986 psolutions_m[0]=frommer1_field_ref.addInv( bp);
00987 solutions=1;
00988
00989
00990 return ;
00991 }
00992
00993 typename TFrommer1::RingType::sqrtInf_t sqrt=f1_ring_ref_m.sqrt( discriminant );
00994
00995
00996
00997
00998
00999
01000
01001 if ( sqrt.solutions ==2 )
01002 {
01003 psolutions_m[0]=frommer1_field_ref.add ( frommer1_field_ref.addInv( bp ),
01004 sqrt.sqrt
01005 ) ;
01006
01007 psolutions_m[1]=frommer1_field_ref.add ( frommer1_field_ref.addInv( bp),
01008 frommer1_field_ref.addInv( sqrt.sqrt )
01009 ) ;
01010 solutions=2;
01011 return ;
01012 }
01013
01014 #ifdef SAFE
01015 assert ( sqrt.solutions ==0 );
01016 #endif
01017 return ;
01018
01019 }
01020 else if ( b[1] != frommer1_Null)
01021 {
01022
01023
01024
01025
01026 solutions=1;
01027 psolutions_m[0]=frommer1_field_ref.addInv ( frommer1_field_ref.multiply( b[0],
01028 frommer1_field_ref.multInv(b[1] )
01029 )
01030 );
01031 return ;
01032 }
01033 else if ( b[0] == frommer1_Null )
01034 {
01035 solutions = frommer1_field_ref.getCharacteristic();
01036
01037
01038
01039 int characteristic=frommer1_field_ref.getCharacteristic();
01040 for (int i=0;i< characteristic; i++)
01041 psolutions_m[i] = i;
01042 return ;
01043 }
01044
01045
01046
01047
01048
01049 return ;
01050 }
01051
01052
01053
01062 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
01063 void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::performFormula23Step( TPolynomXY & minusP_polynom,
01064 TPolynomXY & Q_polynom )
01065 {
01066 #ifdef MTCP
01067 mtcp_no();
01068 #endif
01069
01070 #ifdef FORMULA23_TIMER
01071 tim1_m.start();
01072 tim2_m.start();
01073 #endif
01074
01075
01076
01077
01078
01079
01080 pair <TPolynomXY,TPolynomXY> PQpolynom_pair_refs(minusP_polynom, Q_polynom);
01081
01082 pair <TPolynomXY ,TPolynomXY > tmppolynoms (minusP_polynom, Q_polynom);
01083
01084
01085 typename TFrommer1::RingType::FieldType const & field_ref = frommer1_m.getRing()->getFieldRef();
01086
01087 typename TFrommer1::RingType::ScalarType a[3];
01088
01089
01090
01091 #ifdef FORMULA23_TIMER
01092 tim3_m.start();
01093 #endif
01094
01095 a[0] = performFormula23Step_getSecondFocalValue( tmppolynoms );
01096
01097 #ifdef FORMULA23_TIMER
01098 tim3_m.stop();
01099 formula23_compute_a_getFocalValues_time_m += tim3_m.realtime();
01100 tim3_m.clear();
01101 #endif
01102
01103 polynomialRing_m.addInPlace(tmppolynoms.first, v1_m.first);
01104 polynomialRing_m.addInPlace(tmppolynoms.second , v1_m.second);
01105
01106
01107
01108 #ifdef FORMULA23_TIMER
01109 tim3_m.start();
01110 #endif
01111
01112 a[1] = field_ref.add ( performFormula23Step_getSecondFocalValue( tmppolynoms ) , field_ref.addInv( a[0] ));
01113 #ifdef FORMULA23_TIMER
01114 tim3_m.stop();
01115 formula23_compute_a_getFocalValues_time_m += tim3_m.realtime();
01116 tim3_m.clear();
01117 #endif
01118 tmppolynoms.first = polynomialRing_m.add(minusP_polynom, v2_m.first);
01119 tmppolynoms.second = polynomialRing_m.add(Q_polynom, v2_m.second);
01120
01121 #ifdef FORMULA23_TIMER
01122 tim3_m.start();
01123 #endif
01124
01125
01126 a[2] = field_ref.add (performFormula23Step_getSecondFocalValue( tmppolynoms ) , field_ref.addInv( a[0] ));
01127
01128 #ifdef FORMULA23_TIMER
01129 tim3_m.stop();
01130 formula23_compute_a_getFocalValues_time_m += tim3_m.realtime();
01131 tim3_m.clear();
01132 #endif
01133
01134
01135
01136
01137
01138
01139
01140 #ifdef FORMULA23_TIMER
01141 tim2_m.stop();
01142 formula23_compute_a_time_m += tim2_m.realtime();
01143 tim2_m.clear();
01144 #endif
01145
01146
01147 typename TFrommer1::RingType::ScalarType b[3], c, d;
01148
01149 if (a[1] != TFrommer1::RingType::ScalarType::Zero )
01150 {
01151
01152
01153 #ifdef FORMULA23_TIMER
01154 formula23_compute_bcd_a1_not_zero_count ++;
01155 tim2_m.start();
01156 #endif
01157
01158
01159
01160 typename TFrommer1::RingType::ScalarType v1coeff, v2coeff , ma0_div_a1;
01161
01162
01163
01164
01165 ma0_div_a1 = field_ref.multiply( field_ref.addInv(a[0]), field_ref.multInv(a[1]) );
01166 v1coeff = ma0_div_a1;
01167 v2coeff = TFrommer1::RingType::ScalarType::Zero;
01168
01169
01170 pair<TPolynomXY,TPolynomXY> tmppoint (v1_m );
01171 performFormula23Step_computePointNew(v1coeff, v2coeff , PQpolynom_pair_refs, tmppoint);
01172
01173
01174
01175
01176 #ifdef FORMULA23_TIMER
01177 tim3_m.start();
01178 #endif
01179 b[0]= performFormula23Step_getThirdFocalValue(tmppoint);
01180
01181 #ifdef FORMULA23_TIMER
01182 tim3_m.stop();
01183 compute_bcd_a1_not_zero_getFocalValues_time_m += tim3_m.realtime();
01184 tim3_m.clear();
01185 #endif
01186
01187
01188 v1coeff = field_ref.add( ma0_div_a1,
01189 field_ref.multiply( field_ref.addInv(a[2]),
01190 field_ref.multInv(a[1])
01191 ));
01192
01193 v2coeff= typename TFrommer1::RingType::ScalarType(1);
01194
01195 #ifdef FORMULA23_TIMER
01196 tim3_m.start();
01197 #endif
01198
01199 tmppoint = v1_m;
01200 performFormula23Step_computePointNew(v1coeff, v2coeff , PQpolynom_pair_refs, tmppoint);
01201
01202
01203 c= performFormula23Step_getThirdFocalValue(tmppoint);
01204 #ifdef FORMULA23_TIMER
01205 tim3_m.stop();
01206 compute_bcd_a1_not_zero_getFocalValues_time_m += tim3_m.realtime();
01207 tim3_m.clear();
01208 #endif
01209
01210 v1coeff = field_ref.add( ma0_div_a1,
01211 field_ref.multiply( a[2],
01212 field_ref.multInv(a[1])
01213 )
01214 );
01215
01216 v2coeff= field_ref.addInv(v2coeff);
01217
01218 tmppoint = v1_m;
01219 performFormula23Step_computePointNew(v1coeff, v2coeff , PQpolynom_pair_refs, tmppoint);
01220
01221 #ifdef FORMULA23_TIMER
01222 tim3_m.start();
01223 #endif
01224
01225 d= performFormula23Step_getThirdFocalValue(tmppoint);
01226
01227 #ifdef FORMULA23_TIMER
01228 tim3_m.stop();
01229 compute_bcd_a1_not_zero_getFocalValues_time_m += tim3_m.realtime();
01230 tim3_m.clear();
01231
01232 tim2_m.stop();
01233 compute_bcd_a1_not_zero_time_m += tim2_m.realtime();
01234 tim2_m.clear();
01235 #endif
01236
01237 }else if ( a[2] != TFrommer1::RingType::ScalarType::Zero)
01238 {
01239
01240
01241 #ifdef FORMULA23_TIMER
01242 formula23_compute_bcd_a2_not_zero_count++;
01243 tim2_m.start();
01244 #endif
01245
01246
01247
01248
01249
01250
01251
01252
01253 typename TFrommer1::RingType::ScalarType v1coeff, v2coeff ;
01254
01255
01256 v2coeff = field_ref.multiply( field_ref.addInv(a[0]),
01257 field_ref.multInv(a[2])
01258 );
01259
01260 v1coeff = TFrommer1::RingType::ScalarType::Zero;
01261
01262
01263 pair<TPolynomXY,TPolynomXY> tmppoint ( v1_m );
01264 performFormula23Step_computePointNew(v1coeff, v2coeff , PQpolynom_pair_refs, tmppoint);
01265 #ifdef FORMULA23_TIMER
01266 tim3_m.start();
01267 #endif
01268
01269 b[0] = performFormula23Step_getThirdFocalValue(tmppoint);
01270 #ifdef FORMULA23_TIMER
01271 tim3_m.stop();
01272 compute_bcd_a2_not_zero_getFocalValues_time_m += tim3_m.realtime();
01273 tim3_m.clear();
01274 #endif
01275 v1coeff= typename TFrommer1::RingType::ScalarType(1);
01276
01277
01278 tmppoint = v1_m;
01279 performFormula23Step_computePointNew(v1coeff, v2coeff , PQpolynom_pair_refs, tmppoint);
01280
01281 #ifdef FORMULA23_TIMER
01282 tim3_m.start();
01283 #endif
01284
01285 c = performFormula23Step_getThirdFocalValue(tmppoint);
01286 #ifdef FORMULA23_TIMER
01287 tim3_m.stop();
01288 compute_bcd_a2_not_zero_getFocalValues_time_m += tim3_m.realtime();
01289 tim3_m.clear();
01290 #endif
01291 v1coeff= field_ref.addInv(v1coeff);
01292
01293 tmppoint = v1_m;
01294 performFormula23Step_computePointNew(v1coeff, v2coeff , PQpolynom_pair_refs, tmppoint);
01295
01296
01297 #ifdef FORMULA23_TIMER
01298 tim3_m.start();
01299 #endif
01300
01301 d = performFormula23Step_getThirdFocalValue(tmppoint);
01302 #ifdef FORMULA23_TIMER
01303 tim3_m.stop();
01304 compute_bcd_a2_not_zero_getFocalValues_time_m += tim3_m.realtime();
01305 tim3_m.clear();
01306 #endif
01307
01308 #ifdef FORMULA23_TIMER
01309 tim2_m.stop();
01310 compute_bcd_a2_not_zero_time_m += tim2_m.realtime();
01311 tim2_m.clear();
01312 #endif
01313 }
01314 else if ( a[0] != TFrommer1::RingType::ScalarType::Zero)
01315 {
01316
01317
01318
01319
01320 }
01321 unsigned int pPointSolutions=0;
01322
01323 if ( (a[1] != TFrommer1::RingType::ScalarType::Zero ) || (a[2] != TFrommer1::RingType::ScalarType::Zero ) )
01324 {
01325 #ifdef FORMULA23_TIMER
01326 tim2_m.start();
01327 #endif
01328
01329 st_m->correctSecondFocalValueStatistic( field_ref.getCharacteristic() );
01330
01331
01332
01333 b[1] = field_ref.multiply( field_ref.multInv(2),
01334 field_ref.add( c,
01335 field_ref.addInv(d)
01336 )
01337 );
01338
01339 b[2] = field_ref.add (field_ref.multiply( field_ref.multInv(2),
01340 field_ref.add( c,
01341 d
01342 )
01343 ),
01344 field_ref.addInv(b[0])
01345 );
01346
01347
01348
01349
01350 unsigned int solutions=0;
01351
01352 performFormula23Step_solveQ( solutions, & (b[0]) );
01353 pPointSolutions = solutions;
01354
01355 if ( a[1] != TFrommer1::RingType::ScalarType::Zero )
01356 {
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368 typename TFrommer1::RingType::ScalarType ma_2div_a1, ma0_div_a1;
01369 ma0_div_a1=field_ref.addInv(field_ref.multiply(a[0],
01370 field_ref.multInv( a[1] )
01371 )
01372 );
01373 ma_2div_a1=field_ref.addInv(field_ref.multiply(a[2],
01374 field_ref.multInv( a[1] )
01375 )
01376 );
01377
01378 for (size_t i=0; i<solutions; i++ )
01379 {
01380 typename TFrommer1::RingType::ScalarType v1coeff_= field_ref.add ( ma0_div_a1,
01381 field_ref.multiply( ma_2div_a1,
01382 psolutions_m[i]
01383 )
01384 );
01385
01386
01387
01388
01389
01390 pPointSolutions_m[i] = v1_m;
01391 performFormula23Step_computePointNew(v1coeff_, psolutions_m[i] , PQpolynom_pair_refs, pPointSolutions_m[i] );
01392
01393
01394
01395 }
01396
01397 }
01398 else if ( a[2] != TFrommer1::RingType::ScalarType::Zero )
01399 {
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411 typename TFrommer1::RingType::ScalarType v2coeff_ = field_ref.addInv(field_ref.multiply( a[0],
01412 field_ref.multInv(a[2])
01413 )
01414 );
01415 for (size_t i=0;i<solutions;i++)
01416 {
01417 pPointSolutions_m[i]= v1_m;
01418 performFormula23Step_computePointNew( psolutions_m[i], v2coeff_, PQpolynom_pair_refs, pPointSolutions_m[i]) ;
01419 }
01420
01421
01422 }
01423 #ifdef FORMULA23_TIMER
01424 tim2_m.stop();
01425 computeSolutions_time_m += tim2_m.realtime();
01426 tim2_m.clear();
01427 #endif
01428 }
01429 else if (a[0] == TFrommer1::RingType::ScalarType::Zero )
01430 {
01431
01432 #ifdef FORMULA23_TIMER
01433 formula23_analyze_all_time_count ++;
01434 tim2_m.start();
01435 #endif
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446 int pos=0;
01447 int characteristic = field_ref.getCharacteristic();
01448 for (int i=0; i< characteristic; i++)
01449 for (int j=0; j< characteristic; j++)
01450 {
01451 pair <TPolynomXY ,TPolynomXY > tmppoint (v1_m );
01452 performFormula23Step_computePointNew( i,j, PQpolynom_pair_refs, tmppoint) ;
01453
01454 frommer1_m.setPolynoms(&(tmppoint.first), &(tmppoint.second) ) ;
01455
01456 frommer1_m.template doitx<3>(3);
01457 typename TFrommer1::RingType::ScalarType s2,s3;
01458
01459 s2=frommer1_m.getFocalValue(2);
01460 s3=frommer1_m.getFocalValue(3);
01461
01462 if (s2==TFrommer1::RingType::ScalarType::Zero && s3==TFrommer1::RingType::ScalarType::Zero)
01463 {
01464 pPointSolutions_m[pos] = tmppoint ;
01465 pos++;
01466 pPointSolutions++;
01467 }
01468 if (s2==TFrommer1::RingType::ScalarType::Zero)
01469 st_m->correctSecondFocalValueStatistic(1);
01470 }
01471 #ifdef FORMULA23_TIMER
01472 tim2_m.stop();
01473 analyze_all_time_m += tim2_m.realtime();
01474 tim2_m.clear();
01475 #endif
01476 }
01477
01478 #ifdef CF_TEST
01479 int countSecondFocalValues=0;
01480 int characteristic = field_ref.getCharacteristic();
01481
01482 for (int i=0; i< characteristic; i++)
01483 { for (int j=0; j< characteristic; j++)
01484 {
01485 pair <TPolynomXY ,TPolynomXY > tmppoint (v1_m );
01486 performFormula23Step_computePointNew( i,j, PQpolynom_pair_refs, tmppoint) ;
01487
01488 bool isSolution=false;
01489 for (size_t currSolution=0; currSolution<pPointSolutions; currSolution++)
01490 {
01491 if ( tmppoint==pPointSolutions_m[currSolution] )
01492 isSolution=true;
01493 }
01494 typename TFrommer1::RingType::ScalarType s2,s3;
01495 s2 = performFormula23Step_getSecondFocalValue(tmppoint);
01496 s3 = performFormula23Step_getThirdFocalValue(tmppoint);
01497 if (s2==TFrommer1::RingType::ElementType::Zero) countSecondFocalValues++;
01498 if (!isSolution)
01499 {
01500
01501 assert( s2!=TFrommer1::RingType::ElementType::Zero || s3 !=TFrommer1::RingType::ElementType::Zero );
01502 }
01503 else
01504 {
01505
01506 assert( s2==TFrommer1::RingType::ElementType::Zero && s3 == TFrommer1::RingType::ElementType::Zero );
01507 }
01508 }
01509 }
01511 if (a[1] != TFrommer1::RingType::ElementType::Zero || a[2] != TFrommer1::RingType::ElementType::Zero )
01512 {
01513 assert(countSecondFocalValues == field_ref.getCharacteristic() );
01514 }
01515
01516
01517 #endif
01518
01519 #ifdef FORMULA23_TIMER
01520 tim1_m.stop();
01521 formula23_step_time_m += tim1_m.realtime() ;
01522 tim1_m.clear();
01523 tim1_m.start();
01524 #endif
01525
01526 for (size_t i=0; i<pPointSolutions; i++)
01527 {
01528 performSingleRandomTrial( pPointSolutions_m[i].first,
01529 pPointSolutions_m[i].second );
01530 }
01531
01532 #ifdef FORMULA23_TIMER
01533 tim1_m.stop();
01534 random_trials_time_m += tim1_m.realtime();
01535 tim1_m.clear();
01536 #endif
01537
01538 #ifdef MTCP
01539 MtcpManager_g.checkpointingTimeFrame();
01540 #endif
01541
01542 }
01543
01545 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
01546 void CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::printTimings(std::ostream & os) const
01547 {
01548 #ifdef FORMULA23_TIMER
01549 os << "---timer_formula23_step: " <<formula23_step_time_m << " sec." << std::endl;
01550 os << "---timer_formula23_compute_a: " << formula23_compute_a_time_m << " sec." << std::endl;
01551 os << "---timer_compute_bcd_a1_not_zero: " << compute_bcd_a1_not_zero_time_m << " sec." << std::endl;
01552 os << "---timer_compute_bcd_a2_not_zero: " << compute_bcd_a2_not_zero_time_m << " sec." << std::endl;
01553 os << "---timer_computeSolutions: " << computeSolutions_time_m << " sec." << std::endl;
01554 os << "---timer_analyze_all: " << analyze_all_time_m << " sec." << std::endl;
01555 os << "---timer_random_trials: " << random_trials_time_m << " sec." << std::endl;
01556
01557 os << "---timer_formula23_compute_a_getFocalValues: " << formula23_compute_a_getFocalValues_time_m << "sec." << std::endl;
01558 os << "---timer_compute_bcd_a1_not_zero_getFocalValues_time: " << compute_bcd_a1_not_zero_getFocalValues_time_m << "sec." << std::endl;
01559 os << "---timer_compute_bcd_a2_not_zero_getFocalValues_time: " << compute_bcd_a2_not_zero_getFocalValues_time_m << "sec." << std::endl;
01560
01561
01562 os << "---compute_bcd_a1_not_zero_count: \t" << formula23_compute_bcd_a1_not_zero_count << " " << std::endl;
01563 os << "---compute_bcd_a2_not_zero_count: \t" << formula23_compute_bcd_a2_not_zero_count << "" << std::endl;
01564 os << "---analyze_all_count: \t\t" << formula23_analyze_all_time_count << "" << std::endl;
01565
01566
01567 #endif
01568
01569 }
01570
01571 template <int variant, class TPolynomXY, class TFrommer1, class TFrommer2>
01572 CFRandomExperiment<variant, TPolynomXY, TFrommer1, TFrommer2>::~CFRandomExperiment()
01573 {
01574 if (st_m!=NULL) delete st_m;
01575 delete[] psolutions_m;
01576 delete[] pPointSolutions_m;
01577
01578 #ifdef FORMULA23_TIMER
01579 MtcpManager_g.disconnectTimer(tim1_m);
01580 MtcpManager_g.disconnectTimer(tim2_m);
01581 MtcpManager_g.disconnectTimer(tim3_m);
01582 #endif
01583 }
01584
01585
01586