Révision 69

pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage (revision 69)
1
def lcmm(rationalList = None):
2
    """ 
3
    Compute the lcm of an sequence (list, tuple) of numbers
4
    """
5
    # No argument.
6
    if rationalList is None:
7
        raise TypeError('lcmm takes a list of rationals')
8
    # Try the len function.
9
    try:
10
        listLength = len(rationalList)
11
    except Exception:
12
        print "lcmm:", rationalList, "does not understand the len() function."
13
        return(0)
14
    # An empty list: return 0
15
    if listLength == 0:
16
        return(0)
17
    # Only one element, return it, wahtever it is.
18
    if listLength == 1:
19
        return(rationalList[0])
20
    try:
21
        return(reduce(lcm, rationalList))
22
    except Exception:
23
        print "Exception raised in lcmm!"
24
        return(0)
25
    
26
def denominators(rationalList = None):
27
    """
28
    Compute the list of the denominators of a rational numbers list.
29
    """
30
    # No argument.
31
    if rationalList is None:
32
        raise TypeError('numerators takes a list of rationals.')
33
    try:
34
        listLength = len(rationalList)
35
    except Exception:
36
        print "denominators:", rationalList, \
37
                "does not understand the len() function."
38
        return([])
39
    if listLength == 0:
40
        return([])
41
    if listLength == 1:
42
        try:
43
            return(QQ(rationalList[0]).denominator())
44
        except Exception:
45
            print "denominators:", rationalList[0], \
46
                    "has no \"denominator()\" member." 
47
            return([])
48
    denominatorsList = []    
49
    for i in xrange(listLength):
50
        try:
51
            denominatorsList.append(QQ(rationalList[i]).denominator())
52
        except Exception:
53
            print "denominators:", rationalList[i], \
54
                    "has no \"denominator()\" member." 
55
            return([])
56
    return(denominatorsList)
57

  
58
def numerators(rationalList = None):
59
    """
60
    Compute the list of the numerators of a rational numbers list.
61
    """
62
    # No argument.
63
    if rationalList is None:
64
        raise TypeError('numerators takes a list of rationals.')
65
    try:
66
        listLength = len(rationalList)
67
    except Exception:
68
        print "numerators:", rationalList, \
69
                "does not understand the len() function."
70
        return([])
71
    if listLength == 0:
72
        return([])
73
    if listLength == 1:
74
        try:
75
            return(QQ(rationalList[0]).numerator())
76
        except Exception:
77
            print "denominators:", rationalList[0], \
78
                    "has no \"numerator()\" member." 
79
            return([])
80
    numeratorsList = []    
81
    for i in xrange(listLength):
82
        try:
83
            numeratorsList.append(QQ(rationalList[i]).numerator())
84
        except Exception:
85
            print "numerators:", rationalList[i], \
86
                    "has no \"numerator()\" member." 
87
            return([])
88
    return(numeratorsList)
pobysoPythonSage/src/sageSLZ/sageSLZ-Notes.html (revision 69)
321 321
<p>The naive approach is to:</p>
322 322
<ol>
323 323
  <li>give it a try with the initial data;</li>
324
  <li>you get a too large error, reduce (e. g. divide by 2) the interval by
325
    lowering the upper bound until the computed error matches the expected
324
  <li>when you get a too large error, reduce (e. g. divide by 2) the interval by
325
    lowering the upper bound until the computed error matches the target
326 326
    error;</li>
327
  <li>use this upper bound as the lower bound of the next interval, always
327
  <li>this upper bound becomes the lower bound of the next interval, always
328 328
    using the orginal upper bound and repeat the process until you can cover
329 329
    the all initial interval with the computed sub-interval.</li>
330 330
</ol>
331 331

  
332 332
<p>In step 2 you may have to compute several polynomials until the computed
333 333
error is below or equal to the expected error. You must not decrease the
334
interval width too agressively since it multiplies the number of interval (and
335
lengtens the subsequent manipulations that are made on each sub-interval).</p>
334
interval width too agressively.  There is no point in getting a too small approximation error since it multiplies the number of interval (and
335
lengthens the subsequent manipulations that are made on each sub-interval).</p>
336 336

  
337
<p>In step 3 you probably unutily compute polynomials for too large interval
337
<p>In step 3 you probably inutily compute polynomials for too large intervals
338 338
and you could know it from the previous computations.</p>
339 339

  
340
<p>The whole idea is to reduce the number of polynomila computation and get the
341
maximum width (compatibile with the expected approwimaiton error).</p>
340
<p>The whole idea is to reduce the number of polynomial computations and get the
341
maximum width (compatible with the expected approwimaiton error).</p>
342 342

  
343 343
<p>This process has different aspects:</p>
344 344
<ol>
......
352 352

  
353 353
<p>For point 2, can some type of data structure keep the informations (which
354 354
ones ?) and allow for an efficient reuse.</p>
355

  
356
<p>Adjacent question: is it possible, given a the result of a previous
357
computation, to forecast the effect on the approximation precision of a degree
358
in(de)crease?</p>
355 359
</body>
356 360
</html>

Formats disponibles : Unified diff