Révision 197

pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage (revision 197)
663 663
        nbw = 0
664 664
        icAsInt = int(ic * toIntegerFactor)
665 665
        #### The following ratio is always >= 1. In case we may want to
666
        #  enlarge the interval
666
        #    enlarge the interval
667 667
        curTaylErrRat = polyApproxAccur / terr
668
        ## Make the  integral transformations.
669
        ### First for interval center and bounds.
668
        ### Make the  integral transformations.
669
        #### Bounds and interval center.
670 670
        intIc = int(ic * toIntegerFactor)
671 671
        intLb = int(lb * toIntegerFactor) - intIc
672 672
        intUb = int(ub * toIntegerFactor) - intIc
673 673
        #
674
        #### For polynomials
674
        #### Polynomials
675 675
        basisConstructionTime         = cputime()
676 676
        ##### To a polynomial with rational coefficients with rational arguments
677 677
        ratRatP = slz_float_poly_of_float_to_rat_poly_of_rat_pow_two(floatP)
678 678
        ##### To a polynomial with rational coefficients with integer arguments
679 679
        ratIntP = \
680 680
            slz_rat_poly_of_rat_to_rat_poly_of_int(ratRatP, precision)
681
        #####  Ultimately a polynomial with integer coefficients with integer 
682
        #      arguments.
681
        #####  Ultimately a multivariate polynomial with integer coefficients  
682
        #      with integer arguments.
683 683
        coppersmithTuple = \
684 684
            slz_rat_poly_of_int_to_poly_for_coppersmith(ratIntP, 
685 685
                                                        precision, 
......
695 695
        basisConstructionsFullTime        += cputime(basisConstructionTime)
696 696
        basisConstructionsCount           += 1
697 697
        reductionTime                     = cputime()
698
        # Compute the reduced polynomials.
698
        #### Compute the reduced polynomials.
699 699
        ccReducedPolynomialsList =  \
700 700
            slz_compute_coppersmith_reduced_polynomials(intIntP, 
701 701
                                                        alpha, 
......
727 727
        #### We have at least two polynomials.
728 728
        #    Let us try to compute resultants.
729 729
        #    For each resultant computed, go for the solutions.
730
        resultantsComputationTime      = cputime()
731
        resultantsInTTuplesList = []
732
        hasNonNullResultant     = False
733 730
        ##### Build the pairs list.
734 731
        polyPairsList           = []
735 732
        for polyOuterIndex in xrange(0, len(ccReducedPolynomialsList) - 1):
......
737 734
                                         len(ccReducedPolynomialsList)):
738 735
                polyPairsList.append((ccReducedPolynomialsList[polyOuterIndex],
739 736
                                      ccReducedPolynomialsList[polyInnerIndex]))
737
        #### Actual root search.
738
        rootsSet            = set()
739
        hasNonNullResultant = False
740 740
        for polyPair in polyPairsList:
741
            resultantTuple = \
742
            slz_resultant_tuple(polyPair[0],
743
                                polyPair[1],
744
                                t)
741
            if hasNonNullResultant:
742
                break
743
            resultantsComputationTime   = cputime()
744
            currentResultant = \
745
                slz_resultant(polyPair[0],
746
                              polyPair[1],
747
                              t)
745 748
            resultantsComputationsFullTime += cputime(resultantsComputationTime)
746 749
            resultantsComputationsCount    += 1
747
            if len(resultantTuple) > 2:                    
750
            if currentResultant is None:                    
751
                print "Nul resultant"
752
                continue # Next polyPair.
753
            else:
748 754
                hasNonNullResultant = True
749
                resultantsInTTuplesList.append(resultantTuple)
750
            else:
751
                print "Nul resultant"
752
        print len(resultantsInTTuplesList), "resultant(s) in t tuple(s) created."
753
        if len(resultantsInTTuplesList) == 0:
754
            print "Only null resultants, shrinking interval."
755
            resultCondFailed      =  True
756
            resultCondFailedCount += 1
757
            ### Shrink interval for next iteration.
758
            ub = lb + bw * onlyNullResultantsShrink
759
            if ub > sdub:
760
                ub = sdub
761
            nbw = 0
762
            continue
763
        #### Compute roots.
764
        rootsComputationTime       = cputime()
765
        reducedPolynomialsRootsSet = set()
766
        ##### Solve in the second variable since resultants are in the first
767
        #     variable.
768
        for resultantInTTuple in resultantsInTTuplesList:
769
            currentResultant = resultantInTTuple[2]
770
            ##### If the resultant degree is not at least 1, there are no roots.
755
            #### We have a non null resultant. From now on, whatever the
756
            #    root search yields, no extra root search is necessary.
757
            #### A constant resultant leads to no root. Root search is done.
771 758
            if currentResultant.degree() < 1:
772 759
                print "Resultant is constant:", currentResultant
773
                continue # Next resultantInTTuple
760
                continue # Next polyPair and should break.
761
            #### Actual roots computation.
762
            rootsComputationTime       = cputime()
774 763
            ##### Compute i roots
775 764
            iRootsList = Zi(currentResultant).roots()
776
            ##### For each iRoot, compute the corresponding tRoots and check 
777
            #     them in the input polynomial.
765
            ##### For each iRoot, compute the corresponding tRoots and 
766
            #     and build populate the .rootsSet.
778 767
            for iRoot in iRootsList:
779 768
                ####### Roots returned by roots() are (value, multiplicity) 
780 769
                #       tuples.
781 770
                #print "iRoot:", iRoot
782 771
                ###### Use the tRoot against each polynomial, alternatively.
783
                for indexInTuple in range(0,2):
784
                    currentPolynomial = resultantInTTuple[indexInTuple]
772
                for indexInPair in range(0,2):
773
                    currentPolynomial = polyPair[indexInPair]
785 774
                    ####### If the polynomial is univariate, just drop it.
786 775
                    if len(currentPolynomial.variables()) < 2:
787 776
                        print "    Current polynomial is not in two variables."
788
                        continue # Next indexInTuple
777
                        continue # Next indexInPair
789 778
                    tRootsList = \
790 779
                        Zt(currentPolynomial.subs({currentPolynomial.variables()[0]:iRoot[0]})).roots()
791 780
                    ####### The tRootsList can be empty, hence the test.
792 781
                    if len(tRootsList) == 0:
793 782
                        print "    No t root."
794
                        continue # Next indexInTuple
783
                        continue # Next indexInPair
795 784
                    for tRoot in tRootsList:
796
                        reducedPolynomialsRootsSet.add((iRoot[0], tRoot[0]))
797
        # End of roots computation
798
        rootsComputationsFullTime   =   cputime(rootsComputationTime)
799
        rootsComputationsCount      +=  1
800
        ##### Prepare for results.
785
                        rootsSet.add((iRoot[0], tRoot[0]))
786
            # End of roots computation.
787
            rootsComputationsFullTime   =   cputime(rootsComputationTime)
788
            rootsComputationsCount      +=  1
789
        # End loop for polyPair in polyParsList.  Will break at next iteration.
790
        # since a non null resultant was found.
791
        #### Prepare for results for the current interval..
801 792
        intervalResultsList = []
802 793
        intervalResultsList.append((lb, ub))
803 794
        #### Check roots.
804 795
        rootsResultsList = []
805
        for root in reducedPolynomialsRootsSet:
796
        for root in rootsSet:
806 797
            specificRootResultsList = []
807 798
            failingBounds = []
808 799
            intIntPdivN = intIntP(root[0], root[1]) / N
......
828 819
                specificRootResultsList.append(hardToRoundCaseAsFloat.n().str(base=2))
829 820
                # Check the root is in the bounds
830 821
                if abs(root[0]) > iBound or abs(root[1]) > tBound:
831
                    print "Root", root, "is out of bounds."
822
                    print "Root", root, "is out of bounds for modular equation."
832 823
                    if abs(root[0]) > iBound:
833 824
                        print "root[0]:", root[0]
834 825
                        print "i bound:", iBound
......
849 840
                rootsResultsList.append(specificRootResultsList)
850 841
        if len(rootsResultsList) > 0:
851 842
            intervalResultsList.append(rootsResultsList)
843
        ### Check if a non null resultant was found. If not shrink the interval.
844
        if not hasNonNullResultant:
845
            print "Only null resultants for this reduction, shrinking interval."
846
            resultCondFailed      =  True
847
            resultCondFailedCount += 1
848
            ### Shrink interval for next iteration.
849
            ub = lb + bw * onlyNullResultantsShrink
850
            if ub > sdub:
851
                ub = sdub
852
            nbw = 0
853
            continue
852 854
        #### An intervalResultsList has at least the bounds.
853 855
        globalResultsList.append(intervalResultsList)   
854 856
        #### Compute an incremented width for next upper bound, only

Formats disponibles : Unified diff