cvp / src / functions_for_cvp.sage @ ada40619
Historique | Voir | Annoter | Télécharger (926 octet)
1 | ada40619 | Serge Torres | def common_scaling_factor(precision, floatBasis, precisionFraction = None): |
---|---|---|---|
2 | ada40619 | Serge Torres | """ |
3 | ada40619 | Serge Torres | Compute the common scaling factor (a power of 2). |
4 | ada40619 | Serge Torres | The exponent is made of: |
5 | ada40619 | Serge Torres | - a fraction of the precision; |
6 | ada40619 | Serge Torres | - an integer depending on the smallest norm of the vectors of the basis. |
7 | ada40619 | Serge Torres | """ |
8 | ada40619 | Serge Torres | ## Set a default value for the precisionFraction to 1/2. |
9 | ada40619 | Serge Torres | if precisionFraction is None: |
10 | ada40619 | Serge Torres | precisionFraction = 1/2 |
11 | ada40619 | Serge Torres | ## Compute the norms of the vectors and get the smallest one. |
12 | ada40619 | Serge Torres | # Start with "oo" (+Infinty) |
13 | ada40619 | Serge Torres | minBasisVectsNorm = oo |
14 | ada40619 | Serge Torres | currentNorm = 0 |
15 | ada40619 | Serge Torres | for vect in floatBasis.rows(): |
16 | ada40619 | Serge Torres | currentNorm = vect.norm() |
17 | ada40619 | Serge Torres | if currentNorm < minBasisVectNorm: |
18 | ada40619 | Serge Torres | minBasisVectNorm = currentNorm |
19 | ada40619 | Serge Torres | powerForMinNorm = floor(log(minBasisVectsNorm)/log2) |
20 | ada40619 | Serge Torres | if powerForMinNorm < 0: |
21 | ada40619 | Serge Torres | return 2^(ceil(precision*precisionFraction) - powerFromMinNorm) |
22 | ada40619 | Serge Torres | else: |
23 | ada40619 | Serge Torres | return 2^(ceil(precision*precisionFraction)) |
24 | ada40619 | Serge Torres |