| 1 | """ |
|---|
| 2 | q-expansions of Theta Series |
|---|
| 3 | |
|---|
| 4 | AUTHOR: |
|---|
| 5 | -- William Stein |
|---|
| 6 | """ |
|---|
| 7 | |
|---|
| 8 | from sage.rings.all import Integer, ZZ, PowerSeriesRing |
|---|
| 9 | |
|---|
| 10 | from math import ceil, sqrt |
|---|
| 11 | |
|---|
| 12 | def theta2_qexp(prec=10, var='q', K=ZZ, sparse=False): |
|---|
| 13 | r""" |
|---|
| 14 | Return the $q$-expansion of the series |
|---|
| 15 | $$ |
|---|
| 16 | \theta_2 = \sum_{n odd} q^n. |
|---|
| 17 | $$ |
|---|
| 18 | |
|---|
| 19 | INPUT: |
|---|
| 20 | prec -- integer; the absolute precision of the output |
|---|
| 21 | var -- (default: 'q') variable name |
|---|
| 22 | K -- (default: ZZ) base ring of answer |
|---|
| 23 | |
|---|
| 24 | OUTPUT: |
|---|
| 25 | a power series over K |
|---|
| 26 | |
|---|
| 27 | EXAMPLES: |
|---|
| 28 | sage: theta2_qexp(18) |
|---|
| 29 | q + q^9 + O(q^18) |
|---|
| 30 | sage: theta2_qexp(49) |
|---|
| 31 | q + q^9 + q^25 + O(q^49) |
|---|
| 32 | sage: theta2_qexp(100, 'q', QQ) |
|---|
| 33 | q + q^9 + q^25 + q^49 + q^81 + O(q^100) |
|---|
| 34 | sage: f = theta2_qexp(100, 't', GF(3)); f |
|---|
| 35 | t + t^9 + t^25 + t^49 + t^81 + O(t^100) |
|---|
| 36 | sage: parent(f) |
|---|
| 37 | Power Series Ring in t over Finite Field of size 3 |
|---|
| 38 | sage: theta2_qexp(200) |
|---|
| 39 | q + q^9 + q^25 + q^49 + q^81 + q^121 + q^169 + O(q^200) |
|---|
| 40 | sage: f = theta2_qexp(20,sparse=True); f |
|---|
| 41 | q + q^9 + O(q^20) |
|---|
| 42 | sage: parent(f) |
|---|
| 43 | Sparse Power Series Ring in q over Integer Ring |
|---|
| 44 | """ |
|---|
| 45 | prec = Integer(prec) |
|---|
| 46 | if prec <= 0: |
|---|
| 47 | raise ValueError, "prec must be positive" |
|---|
| 48 | if sparse: |
|---|
| 49 | v = {} |
|---|
| 50 | else: |
|---|
| 51 | v = [Integer(0)] * prec |
|---|
| 52 | one = Integer(1) |
|---|
| 53 | n = int(sqrt(prec)) |
|---|
| 54 | if n*n < prec: |
|---|
| 55 | n += 1 |
|---|
| 56 | for m in xrange(1, n, 2): |
|---|
| 57 | v[m*m] = one |
|---|
| 58 | R = PowerSeriesRing(K, sparse=sparse, names=var) |
|---|
| 59 | return R(v, prec=prec) |
|---|
| 60 | |
|---|
| 61 | def theta_qexp(prec=10, var='q', K=ZZ, sparse=False): |
|---|
| 62 | r""" |
|---|
| 63 | Return the $q$-expansion of the standard $\theta$ series |
|---|
| 64 | $$ |
|---|
| 65 | \theta = 1 + 2\sum_{n=1}{^\infty} q^{n^2}. |
|---|
| 66 | $$ |
|---|
| 67 | |
|---|
| 68 | INPUT: |
|---|
| 69 | prec -- integer; the absolute precision of the output |
|---|
| 70 | var -- (default: 'q') variable name |
|---|
| 71 | K -- (default: ZZ) base ring of answer |
|---|
| 72 | |
|---|
| 73 | OUTPUT: |
|---|
| 74 | a power series over K |
|---|
| 75 | |
|---|
| 76 | EXAMPLES: |
|---|
| 77 | sage: theta_qexp(25) |
|---|
| 78 | 1 + 2*q + 2*q^4 + 2*q^9 + 2*q^16 + O(q^25) |
|---|
| 79 | sage: theta_qexp(10) |
|---|
| 80 | 1 + 2*q + 2*q^4 + 2*q^9 + O(q^10) |
|---|
| 81 | sage: theta_qexp(100) |
|---|
| 82 | 1 + 2*q + 2*q^4 + 2*q^9 + 2*q^16 + 2*q^25 + 2*q^36 + 2*q^49 + 2*q^64 + 2*q^81 + O(q^100) |
|---|
| 83 | sage: theta_qexp(100, 't') |
|---|
| 84 | 1 + 2*t + 2*t^4 + 2*t^9 + 2*t^16 + 2*t^25 + 2*t^36 + 2*t^49 + 2*t^64 + 2*t^81 + O(t^100) |
|---|
| 85 | sage: theta_qexp(100, 't', GF(2)) |
|---|
| 86 | 1 + O(t^100) |
|---|
| 87 | sage: f = theta_qexp(20,sparse=True); f |
|---|
| 88 | 1 + 2*q + 2*q^4 + 2*q^9 + 2*q^16 + O(q^20) |
|---|
| 89 | sage: parent(f) |
|---|
| 90 | Sparse Power Series Ring in q over Integer Ring |
|---|
| 91 | |
|---|
| 92 | """ |
|---|
| 93 | prec = Integer(prec) |
|---|
| 94 | if prec <= 0: |
|---|
| 95 | raise ValueError, "prec must be positive" |
|---|
| 96 | if sparse: |
|---|
| 97 | v = {} |
|---|
| 98 | else: |
|---|
| 99 | v = [Integer(0)] * prec |
|---|
| 100 | v[0] = Integer(1) |
|---|
| 101 | two = Integer(2) |
|---|
| 102 | n = int(sqrt(prec)) |
|---|
| 103 | if n*n != prec: |
|---|
| 104 | n += 1 |
|---|
| 105 | for m in xrange(1, n): |
|---|
| 106 | v[m*m] = two |
|---|
| 107 | |
|---|
| 108 | R = PowerSeriesRing(K, sparse=sparse, names=var) |
|---|
| 109 | return R(v, prec=prec) |
|---|
| 110 | |
|---|