Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 117
mod(31^(-1),192)
31
legendre_symbol(118,131)
-1
[r]+[mod(r^c,m) for c in [1..m]] mod(31^(-1),192)
Error in lines 1-1 Traceback (most recent call last): File "/projects/cec84faa-0c9f-4d53-a7fe-4962a22dc313/.sagemathcloud/sage_server.py", line 879, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'm' is not defined
m=7 headerRow=['x']+range(m) data=[headerRow] for r in range(m): data.append([r]+[mod(r*c,m) for c in range(m)]) table(data,header_row=True, header_column=True)
x | 0 1 2 3 4 5 6 +---+---+---+---+---+---+---+---+ 0 | 0 0 0 0 0 0 0 1 | 0 1 2 3 4 5 6 2 | 0 2 4 6 1 3 5 3 | 0 3 6 2 5 1 4 4 | 0 4 1 5 2 6 3 5 | 0 5 3 1 6 4 2 6 | 0 6 5 4 3 2 1
m=7 headerRow=['+']+range(m) data=[headerRow] for r in range(m): data.append([r]+[mod(r+c,m) for c in range(m)]) table(data,header_row=True, header_column=True)
+ | 0 1 2 3 4 5 6 +---+---+---+---+---+---+---+---+ 0 | 0 1 2 3 4 5 6 1 | 1 2 3 4 5 6 0 2 | 2 3 4 5 6 0 1 3 | 3 4 5 6 0 1 2 4 | 4 5 6 0 1 2 3 5 | 5 6 0 1 2 3 4 6 | 6 0 1 2 3 4 5
m=7 headerRow=['^']+[1..m-1] data=[headerRow] for r in [1..m-1]: data.append([r]+[mod(r^c,m) for c in [1..m-1]]) table(data,header_row=True, header_column=True)
^ | 1 2 3 4 5 6 +---+---+---+---+---+---+---+ 1 | 1 1 1 1 1 1 2 | 2 4 1 2 4 1 3 | 3 2 6 4 5 1 4 | 4 2 1 4 2 1 5 | 5 4 6 2 3 1 6 | 6 1 6 1 6 1
m=17 headerRow=['^']+[1..m-1] data=[headerRow] for r in [1..m-1]: data.append([r]+[mod(r^c,m) for c in [1..m-1]]) table(data,header_row=True, header_column=True)
^ | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ 1 | 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 | 2 4 8 16 15 13 9 1 2 4 8 16 15 13 9 1 3 | 3 9 10 13 5 15 11 16 14 8 7 4 12 2 6 1 4 | 4 16 13 1 4 16 13 1 4 16 13 1 4 16 13 1 5 | 5 8 6 13 14 2 10 16 12 9 11 4 3 15 7 1 6 | 6 2 12 4 7 8 14 16 11 15 5 13 10 9 3 1 7 | 7 15 3 4 11 9 12 16 10 2 14 13 6 8 5 1 8 | 8 13 2 16 9 4 15 1 8 13 2 16 9 4 15 1 9 | 9 13 15 16 8 4 2 1 9 13 15 16 8 4 2 1 10 | 10 15 14 4 6 9 5 16 7 2 3 13 11 8 12 1 11 | 11 2 5 4 10 8 3 16 6 15 12 13 7 9 14 1 12 | 12 8 11 13 3 2 7 16 5 9 6 4 14 15 10 1 13 | 13 16 4 1 13 16 4 1 13 16 4 1 13 16 4 1 14 | 14 9 7 13 12 15 6 16 3 8 10 4 5 2 11 1 15 | 15 4 9 16 2 13 8 1 15 4 9 16 2 13 8 1 16 | 16 1 16 1 16 1 16 1 16 1 16 1 16 1 16 1
m=11 headerRow=['^']+[1..m-1] data=[headerRow] for r in [1..m-1]: data.append([r]+[mod(r^c,m) for c in [1..m-1]]) table(data,header_row=True, header_column=True)
^ | 1 2 3 4 5 6 7 8 9 10 +----+----+---+----+---+----+---+----+---+----+----+ 1 | 1 1 1 1 1 1 1 1 1 1 2 | 2 4 8 5 10 9 7 3 6 1 3 | 3 9 5 4 1 3 9 5 4 1 4 | 4 5 9 3 1 4 5 9 3 1 5 | 5 3 4 9 1 5 3 4 9 1 6 | 6 3 7 9 10 5 8 4 2 1 7 | 7 5 2 3 10 4 6 9 8 1 8 | 8 9 6 4 10 3 2 5 7 1 9 | 9 4 3 5 1 9 4 3 5 1 10 | 10 1 10 1 10 1 10 1 10 1
len(prime_range(100)) prime_pi(10^2) Mod(5, 12)
25 25 5
sum([1,2])
3
sum(prime_range(100))
1060
12.divides(4)
False
[1, 3, 5, 7, 9]
[n for n in [1..10] if n.divides(100)]
[1, 2, 4, 5, 10]
(100.divisors())^2 [n^2 for n in 100.divisors()]
[1, 4, 16, 25, 100, 400, 625, 2500, 10000]
P=Primes()algebr
P=Primes()
P
Set of all prime numbers: 2, 3, 5, 7, ...
P.next(9)
11
P.unrank(1)
3
P.unrank?
File: /usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/sets/primes.py Signature : P.unrank() Docstring : Returns the n-th prime number. EXAMPLES:: sage: P = Primes() sage: P.unrank(0) 2 sage: P.unrank(5) 13 sage: P.unrank(42) 191
n=100000 i=99900 while i<n: p=P.unrank(i) q= p+2 if q.is_prime(): print p,q i = i+1 i =i+1
1298489 1298491 1298651 1298653 1298909 1298911 1299059 1299061 1299209 1299211 1299341 1299343 1299377 1299379 1299437 1299439 1299449 1299451
n.is_square()
False
n
100000
9.is_square()
True
def T(n): return sum([1..n])
T(4)
10
n=10000 for k in [1..n]: if T(k).is_square(): print k, T(k), sqrt(T(k))
1 1 1 8 36 6 49 1225 35 288 41616 204 1681 1413721 1189 9800 48024900 6930
2013.factor()
3 * 11 * 61
gcd(11,144)
1
xgcd(11,144)
(1, -13, 1)
g,x,y = xgcd(11,144)
g
1
x
-13
# Press the TAB key after 'graphs.' to see a list of predefined graphs. graphs.CompleteGraph(5).show(vertex_labels=False, vertex_size=0,edge_labels=True)
show(graphs.PetersenGraph())
d3-based renderer not yet implemented
g=graphs.CompleteGraph(7) label=1 for u,v,l in g.edges(): g.set_edge_label(u,v,str(label)) label +=1 show(g,vertex_labels=false,edge_labels=True)
d3-based renderer not yet implemented
a
from sage.plot.colors import rainbow C = graphs.CubeGraph(5) R = rainbow(5) edge_colors = {} for i in [0..4]: edge_colors[R[i]] = [] for u,v,l in C.edges(): for i in range(5): if u[i] != v[i]: edge_colors[R[i]].append((u,v,l)) C.graphplot(vertex_labels=False, vertex_size=0, edge_colors=edge_colors).show()
G = graphs.HeawoodGraph().copy(sparse=True) for u,v,l in G.edges(): G.set_edge_label(u,v,'(' + str(u) + ',' + str(v) + ')') G.graphplot(edge_labels=True).show()
x = 500000 prime_pi(x)
41538
def pnt(x): return float (x/log(x))
pnt(500000)
38102.89241501728
numerical_integral(1/log(x), 2,10) # [1] gives error bound
(0.6096462786402765, 0.0)
def li(x): var('t') return numerical_integral(1/log(t), 2,x)
li(500000)
(41605.243622658, 0.0009425010476448864)
prime_pi(500000)
41538
pnt(1000)
144.76482730108395
prime_pi(1000)
168
li(1000)
(176.5644942100379, 1.6446995671159058e-06)
7*log(7.)
13.6213710433872
[1; 1, 1, 3, 31, 1, 145, 1, 4, 2, 8, 1, 6, 1, 2, 3, 1, 4, 1, 5, ...]
cp.convergents()[4]
103993/33102
latex(7+1/9)
\frac{64}{9}
π=3+17+115\pi = 3 +\frac{1}{7+\frac{1}{15}}
π=3+17+115+11+1292\pi=3+\cfrac{1}{7+ \cfrac{1}{15+ \cfrac{1}{1+\cfrac{1}{292\dotsb }}}}
continued_fraction(e)
[2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1, 1, ...]
float(pi/2)
1.5707963267948966
float(1./sqrt(2)+1./sqrt(3))
1.2844570503761732
float(sqrt(2)+sqrt(3))
3.1462643699419726
factor(2015)
5 * 13 * 31
prime_pi(10^6)
78498
for t in [1..7]: a=prime_pi(10^t) b=prime_pi(10^(t-1)) print t, a,a-b, float(a/10^t)
1 4 4 0.4 2 25 21 0.25 3 168 143 0.168 4 1229 1061 0.1229 5 9592 8363 0.09592 6 78498 68906 0.078498 7 664579 586081 0.0664579
list = [prime_pi(2^t) for t in [1..18]]
list
[1, 2, 4, 6, 11, 18, 31, 54, 97, 172, 309, 564, 1028, 1900, 3512, 6542, 12251, 23000]
ratio=[float((list[t]-list[t-1])/(list[t-1]-list[t-2])) for t in [2..17]]
ratio
[2.0, 1.0, 2.5, 1.4, 1.8571428571428572, 1.7692307692307692, 1.8695652173913044, 1.744186046511628, 1.8266666666666667, 1.8613138686131387, 1.8196078431372549, 1.8793103448275863, 1.848623853211009, 1.879652605459057, 1.884158415841584, 1.882816605359958]
plot(1/log(x),(x,2,100))
P=Primes() def prod_primes(l): prod=1 for k in range(l): prod *= P.unrank(k) return prod
prod_primes(3)
30
for k in [1..30]: a = prod_primes(k) k, a, sigma(a),float(sigma(a)/a)
(1, 2, 3, 1.5) (2, 6, 12, 2.0) (3, 30, 72, 2.4) (4, 210, 576, 2.742857142857143) (5, 2310, 6912, 2.9922077922077923) (6, 30030, 96768, 3.2223776223776226) (7, 510510, 1741824, 3.4119292472233647) (8, 9699690, 34836480, 3.5915044707614365) (9, 223092870, 836075520, 3.7476568390554124) (10, 6469693230, 25082265600, 3.876886385229737) (11, 200560490130, 802632499200, 4.00194723636618) (12, 7420738134810, 30500034969600, 4.110107972484185) (13, 304250263527210, 1281001468723200, 4.210354508398433) (14, 13082761331670030, 56364064623820800, 4.308269729523978) (15, 614889782588491410, 2705475101943398400, 4.399935042918106) (16, 32589158477190044730, 146095655504943513600, 4.482952685237315) (17, 1922760350154212639070, 8765739330296610816000, 4.558934934139642) (18, 117288381359406970983270, 543475838478389870592000, 4.633671572404227) (19, 7858321551080267055879090, 36956357016530511200256000, 4.70283084960429) (20, 557940830126698960967415390, 2660857705190196806418432000, 4.769067903824069) (21, 40729680599249024150621323470, 196903470184074563674963968000, 4.834397601136727) (22, 3217644767340672907899084554130, 15752277614725965093997117440000, 4.89559250748023) (23, 267064515689275851355624017992790, 1323191319636981067895757864960000, 4.954575549739028) (24, 23768741896345550770650537601358310, 119087218767328296110618207846400000, 5.010244937938342) (25, 2305567963945518424753102147331756070, 11670547439198173018840584368947200000, 5.06189694760781) (26, 232862364358497360900063316880507363070, 1190395838798213647921739605632614400000, 5.112014739168283) (27, 23984823528925228172706521638692258396210, 123801167235014219383860918985791897600000, 5.16164595022817) (28, 2566376117594999414479597815340071648394470, 13370526061381535693456979250465524940800000, 5.209885632006003) (29, 279734996817854936178276161872067809674997230, 1470757866751968926280267717551207743488000000, 5.2576827478959665) (30, 31610054640417607788145206291543662493274686990, 167666396809724457595950519800837682757632000000, 5.30421091380655)
def h(n): prod = 1. for k in range(n): p = P.unrank(k) prod *= float((p+1)/p) return prod
h(1)
1.50000000000000
h(10)
3.87688638522974
h(100)
6.85163642192891
h(1000)
9.73215913491596
vals=[h(n) for n in [1..1000]]
list_plot(vals)
float(log(1000))
6.907755278982137
h(1000)-h(100)
2.88052271298704
h(100)-h(10)
2.97475003669918
h(10000)-h(1000)
2.78720754884904
163.is_prime()
True
def primeSum(n): sum =0 for p in prime_range(n): sum += 1./p return sum def primeSumList(n): list=[] sum =0 for p in prime_range(n): sum += 1./p list.append(sum) return list
primeSumList(100)
[0.500000000000000, 0.833333333333333, 1.03333333333333, 1.17619047619048, 1.26709956709957, 1.34402264402264, 1.40284617343441, 1.45547775238178, 1.49895601325134, 1.53343877187203, 1.56569683638816, 1.59272386341519, 1.61711410731763, 1.64036992127112, 1.66164651701580, 1.68051444154410, 1.69746359408647, 1.71385703670942, 1.72878240984375, 1.74286691688600, 1.75656554702299, 1.76922377487109, 1.78127196764218, 1.79250792269836, 1.80281720104887]
n=1000 psl=list_plot(primeSumList(n),plotjoined=True) lg = plot(log(x),(x,2,prime_pi(n)),color='red') lg2 = plot(log(log(x)),(x,2,prime_pi(n)),color='green') show(lg+psl+lg2)
n=10000000 psl=list_plot(primeSumList(n),plotjoined=True) lg = plot(log(x),(x,2,prime_pi(n)),color='red') lg2 = plot(log(log(x)),(x,2,prime_pi(n)),color='green') show(psl+lg2)
n=3 l=100 sum=0 for k in [2..l]: sum += 1./k^n sum
0.202007400659678
numerical_integral(1/x^3,1,100)[0] # [1] gives error bound
0.49995000000000006
n=100 prod=1 for k in [1..n]: prod *= 1.+1./2^k prod
2.38423102903137
binomial(9,3)
84
n=1000 p=17 k=110 bc = binomial(n,k)
bc
124418211871840133364593075107752735363117851087126726877571151388277607346819388158474302733831496092331114788214489789460593749920645314041529598400
factor(bc)
2^6 * 3^5 * 5^2 * 11 * 19 * 23 * 29 * 31^2 * 37 * 41 * 43 * 47 * 61 * 71 * 83 * 113 * 131 * 137 * 139 * 149 * 151 * 157 * 163 * 179 * 181 * 191 * 193 * 197 * 199 * 223 * 227 * 229 * 233 * 239 * 241 * 307 * 311 * 313 * 317 * 331 * 449 * 457 * 461 * 463 * 467 * 479 * 487 * 491 * 499 * 907 * 911 * 919 * 929 * 937 * 941 * 947 * 953 * 967 * 971 * 977 * 983 * 991 * 997
def sq(n): return n^2
5.sq()
Error in lines 1-1 Traceback (most recent call last): File "/projects/cec84faa-0c9f-4d53-a7fe-4962a22dc313/.sagemathcloud/sage_server.py", line 879, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "sage/structure/element.pyx", line 438, in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4406) return getattr_from_other_class(self, P._abstract_element_class, name) File "sage/structure/misc.pyx", line 257, in sage.structure.misc.getattr_from_other_class (build/cythonized/sage/structure/misc.c:1631) raise dummy_attribute_error AttributeError: 'sage.rings.integer.Integer' object has no attribute 'sq'
sq(5)
25
def star(f,g,n): sum=0 for d in n.divisors(): sum += f(d)*g(n/d) return sum
def one(n): return 1
moebius(9)
0
euler_phi(9)
6
star(moebius,moebius,12)
-2
for n in [1..29]: print n, star(moebius, euler_phi,n)
1 1 2 0 3 1 4 1 5 3 6 0 7 5 8 2 9 4 10 0 11 9 12 1 13 11 14 0 15 3 16 4 17 15 18 0 19 17 20 3 21 5 22 0 23 21 24 2 25 16 26 0 27 12 28 5 29 27
c=.7 c2=.5 for k in [1..10]: n = 10^k lg=float(log(n)) v1=c*n/lg-1 v2=c2*n/lg print n,v1, v2
10 2.04006137332276 2.17147240951626 100 14.2003068666138 10.8573620475813 1000 100.335379110759 72.3824136505420 10000 759.015343330691 542.868102379065 100000 6079.12274664553 4342.94481903252 1000000 50666.6895553794 36191.2068252710 10000000 434293.481903252 310210.344216608 100000000 3.80007571665345e6 2.71434051189532e6 1000000000 3.37784587035863e7 2.41274712168473e7 10000000000 3.04006136332276e8 2.17147240951626e8
float(log(10,2))
3.3219280948873626
n=1000 end= floor(log(n,2)) sum = 0 for k in [1..end]: term = float(log(2)*(n/2^k)/log((n/2^k))) sum += term print term print sum
55.7675696989 31.3842292317 17.9448565864 10.4764096417 6.29306433961 3.93995206961 2.63421046514 1.9871203725 2.02232012989 132.449732535
prime_pi(100)
25
star(euler_phi,moebius,17)
15
list_plot([euler_phi(n) for n in [1..1000]],aspect_ratio=1)
P=Primes()
P
Set of all prime numbers: 2, 3, 5, 7, ...
n=100 primes=prime_range(3,n) count1=0 count3=0 for p in primes: if mod(p,4)==1: count1 +=1 else: count3 +=1 print p,count1, count3
3 0 1 5 1 1 7 1 2 11 1 3 13 2 3 17 3 3 19 3 4 23 3 5 29 4 5 31 4 6 37 5 6 41 6 6 43 6 7 47 6 8 53 7 8 59 7 9 61 8 9 67 8 10 71 8 11 73 9 11 79 9 12 83 9 13 89 10 13 97 11 13
#density example #A is a subset of the natural numbers #we want to estimate d(A) #example where A is the even integers n = 1000 #this can be changed count = 0 for k in [1..n]: if mod(k,2) ==0: count += 1 print float(count/n)
0.5
P = Primes() len = 5 tests= 1000 for _ in range(tests): d = randint(3,100) start = P.unrank(randint(1,100)) prod=1 for k in range(len): prod *= (start + d*k).is_prime() if prod ==1: print start, d
103 90 277 30
439.is_prime()
True
for m in [1..1000]: if mod(11^(m-1),m)==1: if m.is_prime()==False: print m, factor(m)
1 1 10 2 * 5 15 3 * 5 70 2 * 5 * 7 133 7 * 19 190 2 * 5 * 19 259 7 * 37 305 5 * 61 481 13 * 37 645 3 * 5 * 43 703 19 * 37 793 13 * 61
mod(2^340,341)
1
341.is_prime()
False
n=10000 for x in [1..n]: y=floor(1.4*x) while y^2-2*x^2<=1: if y^2-2*x^2==1: print x,y y += 1
2 3 12 17 70 99 408 577 2378 3363
a=[[1,1],[2,1]]
u=exp(Matrix(a))
latex(u)
\left(\begin{array}{rr} \frac{1}{2} \, {\left(e^{\left(2 \, \sqrt{2}\right)} + 1\right)} e^{\left(-\sqrt{2} + 1\right)} & \frac{1}{4} \, {\left(\sqrt{2} e^{\left(2 \, \sqrt{2}\right)} - \sqrt{2}\right)} e^{\left(-\sqrt{2} + 1\right)} \\ \frac{1}{2} \, {\left(\sqrt{2} e^{\left(2 \, \sqrt{2}\right)} - \sqrt{2}\right)} e^{\left(-\sqrt{2} + 1\right)} & \frac{1}{2} \, {\left(e^{\left(2 \, \sqrt{2}\right)} + 1\right)} e^{\left(-\sqrt{2} + 1\right)} \end{array}\right)
n=1000 sum =0 sumlist=[] for p in prime_range(n): sum += float(1/p) sumlist.append(sum)
sumlist
[0.5, 0.8333333333333333, 1.0333333333333332, 1.176190476190476]
pp=list_plot(zip(prime_range(n),sumlist),plotjoined=true)
pl=plot(log(log(x)),(x,2,n),color='red') pl1=plot(log(x),(x,2,n),color='green')
n=1000 sum =0 harmlist=[] for k in [1..n]: sum +=float(1/k) harmlist.append(sum)
hp=list_plot(zip([1..n],harmlist),plotjoined=true,color='black')
show(pp+pl+pl1+hp)
n=1000 sum =0 wharmlist=[] for k in [2..n]: sum +=float(1/(log(k)*k)) wharmlist.append(sum)
whp=list_plot(zip([2..n],wharmlist),plotjoined=true,color='black')
show(pp+whp)
wharmlist[900]
2.7123610790269677
sumlist[prime_pi(900)]
2.1844657290250784
prime_range(900,1000)
[907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
for k in [900..950]: print wharmlist[k]-sumlist[prime_pi(k)]
0.527895350002 0.528058068905 0.528220581381 0.528382887923 0.528544989022 0.528706885171 0.528868576856 0.527932369726 0.528093653946 0.52825473516 0.528415613849 0.527488151212 0.527648626292 0.527808900283 0.527968973661 0.528128846899 0.52828852047 0.528447994844 0.52860727049 0.527689921609 0.527848801198 0.528007483455 0.528165968843 0.528324257823 0.528482350853 0.528640248392 0.528797950895 0.528955458816 0.52911277261 0.528202656868 0.528359583757 0.528516317869 0.528672859648 0.528829209541 0.528985367991 0.52914133544 0.52929711233 0.528389999843 0.52854539693 0.52870060477 0.528855623798 0.52795448824 0.528109130944 0.528263586132 0.528417854234 0.528571935676 0.528725830885 0.527830222343 0.527983746359 0.528137085412 0.528290239922
mangoldt(7)
Error in lines 1-1 Traceback (most recent call last): File "/projects/cec84faa-0c9f-4d53-a7fe-4962a22dc313/.sagemathcloud/sage_server.py", line 879, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'mangoldt' is not defined
von_mangoldt(7)
Error in lines 1-1 Traceback (most recent call last): File "/projects/cec84faa-0c9f-4d53-a7fe-4962a22dc313/.sagemathcloud/sage_server.py", line 879, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'von_mangoldt' is not defined
mangoldt_lambda(7)
Error in lines 1-1 Traceback (most recent call last): File "/projects/cec84faa-0c9f-4d53-a7fe-4962a22dc313/.sagemathcloud/sage_server.py", line 879, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'mangoldt_lambda' is not defined
mod(5^(-1),16)
13
n=62884891 e=7937 d=mod(e^(-1),euler_phi(n)) d
14859809
n
391
legendre_symbol(31,73)
-1
9973.is_prime()
True
for k in [33..36]: print k, legendre_symbol(k,73)
33 -1 34 -1 35 1 36 1
a=8 b=53 legendre_symbol(a,b)
-1
a=54 b=7 legendre_symbol(a,b)
-1
a=15 b=31 legendre_symbol(a,b)
-1
p=17 sum=0 h=(p-1)/2 for k in [1..(h-1)]: sum += legendre_symbol(k*(k+1),p) sum
-1
p=29 sum=0 h=(p-1)/2 for k in [1..h]: print k, legendre_symbol(k*(k+1),p), legendre_symbol(k,p)
1 -1 1 2 1 -1 3 -1 -1 4 1 1 5 1 1 6 1 1 7 -1 1 8 -1 -1 9 -1 1 10 1 -1 11 1 -1 12 -1 -1 13 -1 1 14 1 -1
p=11 sum=0 prod=1 h=(p-1) for k in [1..h]: prod *= legendre_symbol(k,p) print k, legendre_symbol(k*(k+1),p), prod,legendre_symbol(k,p)
1 -1 1 1 2 -1 -1 -1 3 1 -1 1 4 1 -1 1 5 -1 -1 1 6 1 1 -1 7 1 -1 -1 8 -1 1 -1 9 -1 1 1 10 0 -1 -1
p=11 for k in [1..(p-1)]: i2=mod(2^(-1),p) ki=mod(k^(-1),p) x = i2*(k+ki) y = i2*(k-ki) print k, ki, x,y, x^2, y^2
1 1 1 0 1 0 2 6 4 9 5 4 3 4 9 5 4 3 4 3 9 6 4 3 5 9 7 9 5 4 6 2 4 2 5 4 7 8 2 5 4 3 8 7 2 6 4 3 9 5 7 2 5 4 10 10 10 0 1 0
p=11 for k in [1..(p-1)]: print k, legendre_symbol(k,p)
1 1 2 -1 3 1 4 1 5 1 6 -1 7 -1 8 -1 9 1 10 -1
p=19 h=int((p+1)/2) #print h for k in [1..h]: i2=mod(2^(-1),p) ki=mod(k^(-1),p) x = i2*(k+ki) y = i2*(k-ki) print k,legendre_symbol(k,p),ki, x,y, x^2, y^2
1 1 1 1 0 1 0 2 -1 10 6 15 17 16 3 -1 13 8 14 7 6 4 1 5 14 9 6 5 5 1 4 14 10 6 5 6 1 16 11 14 7 6 7 1 11 9 17 5 4 8 -1 12 10 17 5 4 9 1 17 13 15 17 16 10 -1 2 6 4 17 16
p=17 m=3 headerRow=['k']+['QR?']+['1/k']+['3/k']+['sum']+['diff'] data=[headerRow] for r in [1..p-1]: kminv=m*mod(r^(-1),p) data.append([r]+[legendre_symbol(r,p)]+[mod(r^(-1),p)]+[kminv]+[]) table(data,header_row=True, header_column=True)
k | QR? 1/k 3/k +----+-----+-----+-----+ 1 | 1 1 3 2 | 1 9 10 3 | -1 6 1 4 | 1 13 5 5 | -1 7 4 6 | -1 3 9 7 | -1 5 15 8 | 1 15 11 9 | 1 2 6 10 | -1 12 2 11 | -1 14 8 12 | -1 10 13 13 | 1 4 12 14 | -1 11 16 15 | 1 8 7 16 | 1 16 14
5
5
%var x, y, z, w p=x^5+y^5+z^5+w^5+x^3*y*w+y^3*z*x+z^3*w*y+w^3*x*z+y^3*x*w+x^3*y*z+x^3+y^3+z^3+z^3*x*y+w^3*y*z+x^3*z*w+y^3*z*w+z^3*x*w+w^3+w^3*x*y
p
w^5 + x^5 + w^3*x*y + w*x^3*y + w*x*y^3 + y^5 + w^3*x*z + w*x^3*z + w^3*y*z + x^3*y*z + w*y^3*z + x*y^3*z + w*x*z^3 + w*y*z^3 + x*y*z^3 + z^5 + w^3 + x^3 + y^3 + z^3
s1=x+y+z+w s2=x*y+x*z+x*w+y*z+y*w+z*w s3=x*y*z+x*y*w+y*z*w+x*z*w s4=x*y*z*w
q=s1^3*s2^4*s3^3
q
(w*x + w*y + x*y + w*z + x*z + y*z)^4*(w + x + y + z)^3*w^3*x^3*y^3*z^3
expand(p-s1^5)
-5*w^4*x - 10*w^3*x^2 - 10*w^2*x^3 - 5*w*x^4 - 5*w^4*y - 19*w^3*x*y - 30*w^2*x^2*y - 19*w*x^3*y - 5*x^4*y - 10*w^3*y^2 - 30*w^2*x*y^2 - 30*w*x^2*y^2 - 10*x^3*y^2 - 10*w^2*y^3 - 19*w*x*y^3 - 10*x^2*y^3 - 5*w*y^4 - 5*x*y^4 - 5*w^4*z - 19*w^3*x*z - 30*w^2*x^2*z - 19*w*x^3*z - 5*x^4*z - 19*w^3*y*z - 60*w^2*x*y*z - 60*w*x^2*y*z - 19*x^3*y*z - 30*w^2*y^2*z - 60*w*x*y^2*z - 30*x^2*y^2*z - 19*w*y^3*z - 19*x*y^3*z - 5*y^4*z - 10*w^3*z^2 - 30*w^2*x*z^2 - 30*w*x^2*z^2 - 10*x^3*z^2 - 30*w^2*y*z^2 - 60*w*x*y*z^2 - 30*x^2*y*z^2 - 30*w*y^2*z^2 - 30*x*y^2*z^2 - 10*y^3*z^2 - 10*w^2*z^3 - 19*w*x*z^3 - 10*x^2*z^3 - 19*w*y*z^3 - 19*x*y*z^3 - 10*y^2*z^3 - 5*w*z^4 - 5*x*z^4 - 5*y*z^4 + w^3 + x^3 + y^3 + z^3
expand(p-s1^5+5*s1^3*s2)
5*w^3*x^2 + 5*w^2*x^3 + 16*w^3*x*y + 30*w^2*x^2*y + 16*w*x^3*y + 5*w^3*y^2 + 30*w^2*x*y^2 + 30*w*x^2*y^2 + 5*x^3*y^2 + 5*w^2*y^3 + 16*w*x*y^3 + 5*x^2*y^3 + 16*w^3*x*z + 30*w^2*x^2*z + 16*w*x^3*z + 16*w^3*y*z + 75*w^2*x*y*z + 75*w*x^2*y*z + 16*x^3*y*z + 30*w^2*y^2*z + 75*w*x*y^2*z + 30*x^2*y^2*z + 16*w*y^3*z + 16*x*y^3*z + 5*w^3*z^2 + 30*w^2*x*z^2 + 30*w*x^2*z^2 + 5*x^3*z^2 + 30*w^2*y*z^2 + 75*w*x*y*z^2 + 30*x^2*y*z^2 + 30*w*y^2*z^2 + 30*x*y^2*z^2 + 5*y^3*z^2 + 5*w^2*z^3 + 16*w*x*z^3 + 5*x^2*z^3 + 16*w*y*z^3 + 16*x*y*z^3 + 5*y^2*z^3 + w^3 + x^3 + y^3 + z^3
expand(p-s1^5+5*s1^3*s2-5*s1*s2^2)
6*w^3*x*y + 5*w^2*x^2*y + 6*w*x^3*y + 5*w^2*x*y^2 + 5*w*x^2*y^2 + 6*w*x*y^3 + 6*w^3*x*z + 5*w^2*x^2*z + 6*w*x^3*z + 6*w^3*y*z + 15*w^2*x*y*z + 15*w*x^2*y*z + 6*x^3*y*z + 5*w^2*y^2*z + 15*w*x*y^2*z + 5*x^2*y^2*z + 6*w*y^3*z + 6*x*y^3*z + 5*w^2*x*z^2 + 5*w*x^2*z^2 + 5*w^2*y*z^2 + 15*w*x*y*z^2 + 5*x^2*y*z^2 + 5*w*y^2*z^2 + 5*x*y^2*z^2 + 6*w*x*z^3 + 6*w*y*z^3 + 6*x*y*z^3 + w^3 + x^3 + y^3 + z^3
expand(p-s1^5+5*s1^3*s2-5*s1*s2^2-6*s1^2*s3)
-7*w^2*x^2*y - 7*w^2*x*y^2 - 7*w*x^2*y^2 - 7*w^2*x^2*z - 27*w^2*x*y*z - 27*w*x^2*y*z - 7*w^2*y^2*z - 27*w*x*y^2*z - 7*x^2*y^2*z - 7*w^2*x*z^2 - 7*w*x^2*z^2 - 7*w^2*y*z^2 - 27*w*x*y*z^2 - 7*x^2*y*z^2 - 7*w*y^2*z^2 - 7*x*y^2*z^2 + w^3 + x^3 + y^3 + z^3
expand(p-s1^5+5*s1^3*s2-5*s1*s2^2-6*s1^2*s3+7*s2*s3)
-6*w^2*x*y*z - 6*w*x^2*y*z - 6*w*x*y^2*z - 6*w*x*y*z^2 + w^3 + x^3 + y^3 + z^3
expand(p-s1^5+5*s1^3*s2-5*s1*s2^2-6*s1^2*s3+7*s2*s3+6*s1*s4)
w^3 + x^3 + y^3 + z^3
expand(p-s1^5+5*s1^3*s2-5*s1*s2^2-6*s1^2*s3+7*s2*s3+6*s1*s4-s1^3+3*s1*s2-3*s3)
0
expand(s1^2*s4)
w^3*x*y*z + 2*w^2*x^2*y*z + w*x^3*y*z + 2*w^2*x*y^2*z + 2*w*x^2*y^2*z + w*x*y^3*z + 2*w^2*x*y*z^2 + 2*w*x^2*y*z^2 + 2*w*x*y^2*z^2 + w*x*y*z^3
%var x, y,z p=x^3+y^3+z^3 e = SymmetricFunctions(QQ).elementary() #f = e.from_polynomial(p) #e(f)
e
Symmetric Functions over Rational Field in the elementary basis
e[1]
e[1]
e.from_polynomial?
File: /projects/sage/sage-6.7/local/lib/python2.7/site-packages/sage/combinat/sf/sfa.py Signature : e.from_polynomial(self, poly, check=True) Docstring : Convert polynomial to a symmetric function in the monomial basis and then to the basis "self". INPUT: * "poly" -- a symmetric polynomial * "check" -- (default: "True") boolean, specifies whether the computation checks that the polynomial is indeed symmetric EXAMPLES: sage: Sym = SymmetricFunctions(QQ) sage: h = Sym.homogeneous() sage: f = (h([]) + h([2,1]) + h([3])).expand(3) sage: h.from_polynomial(f) h[] + h[2, 1] + h[3] sage: s = Sym.s() sage: g = (s([]) + s([2,1])).expand(3); g x0^2*x1 + x0*x1^2 + x0^2*x2 + 2*x0*x1*x2 + x1^2*x2 + x0*x2^2 + x1*x2^2 + 1 sage: s.from_polynomial(g) s[] + s[2, 1]
a=sqrt(3); b=sqrt(5); c= a*b
c
sqrt(5)*sqrt(3)
d=(1-a)*(1-b)*(1-c)*(a-b)*(a-c)*(b-c)
d^2
(sqrt(5)*sqrt(3) - sqrt(5))^2*(sqrt(5)*sqrt(3) - sqrt(3))^2*(sqrt(5)*sqrt(3) - 1)^2*(sqrt(5) - sqrt(3))^2*(sqrt(5) - 1)^2*(sqrt(3) - 1)^2
n(d^2)
21.0854297480639
expand(d^2)
-46080*sqrt(5)*sqrt(3) + 40320*sqrt(5) - 107520*sqrt(3) + 274560
expand(d)
-56*sqrt(5)*sqrt(3) + 192*sqrt(5) - 120*sqrt(3)
[ 1 pi 3] [ e 5 6]
@interact(layout=[['A','Myvect']]) def _(A = matrix([[1,-1],[0,1]]),Myvect=matrix([[0,-1]])): V = vector([1,3]) W = A*V V1 = vector([-1,2]) W1 = A*V1 L = line([V,V1],linestyle='--') LW = line([W,W1],linestyle='--') Myvect = vector(Myvect[0]) Wyvect = A*Myvect show(graphics_array([[plot(V)+plot(V1,color='red')+plot(Myvect,color='green')+plot(L),plot(W)+plot(W1,color='red')+plot(Wyvect,color='green')+plot(LW)]]),aspect_ratio=1)
Interact: please open in CoCalc
var('x1,x2') @interact def _(M = matrix(RR,[[1,5],[-2,-7]]), V = matrix(RR,[[7,-5]]),range=(5,(1,100)),show_sol=False): a, b, c, d = M[0,0],M[0,1],M[1,0],M[1,1] e, f = V[0,0],V[0,1] E1 = a*x1+b*x2==e E2 = c*x1+d*x2==f eq1 = solve(E1,x2)[0].rhs() eq2 = solve(E2,x2)[0].rhs() html("Solving:") html('Eq 1: $'+latex(E1)+'$') html('Eq 2: $'+latex(E2)+'$') P = plot(eq1,(x1,-range,range))+plot(eq2,(x1,-range,range),color='red') show(P) if show_sol: try: html(solve([E1,E2],[x1,x2])[0])z except: html('No solution?')
(x1, x2)
Interact: please open in CoCalc
z=cos(2*pi/5)+i*sin(2*pi/5)
z
1/4*sqrt(5) + 1/4*I*sqrt(2*sqrt(5) + 10) - 1/4
z^5
1/1024*(sqrt(5) + I*sqrt(2*sqrt(5) + 10) - 1)^5
n(z^5)
1.00000000000000 - 5.55111512312578e-17*I
n(z)
0.309016994374947 + 0.951056516295154*I
def norm(coeffs): #coeffs is a list of 5 coefficients a_k*z^k z=cos(2*pi/5)+i*sin(2*pi/5) prod=1 for n in [1..4]: s=0 for j in range(5): s += coeffs[j]*z^(n*j) prod *= s return prod
n(norm([0, .5, .0, .5,.4]))
0.0341000000000002 - 3.81639164714898e-17*I
n(norm([2,2,2,2,2]))
3.89424627934904e-60 - 2.02734169599070e-60*I
n=50 s=0 for k in [0..n]: s += (-1)^k*(k+1)/factorial(k) float(s)
3.287949416633158e-65
def d(a,b): return abs(a-b) def delist(myList): output = [] leng = len(myList) for c in range(leng): output.append(d(myList[c],myList[(c+1)%leng])) return output def size(myList): output = 0 for a in myList: output += a*a return output mylist
Error in lines 14-14 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'mylist' is not defined
delist(mylist)
[5, 1, 2, 4, 6]
size(mylist)
180
len(mylist)
3
mylist[-1]
3
mylist[1:2]
[4]
mylist.mylist
Error in lines 1-1 Traceback (most recent call last): File "/projects/cec84faa-0c9f-4d53-a7fe-4962a22dc313/.sagemathcloud/sage_server.py", line 881, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> AttributeError: 'list' object has no attribute 'mylist'
n=20 trib=[0,1,1] for k in range(n): trib.append(trib[-1]+trib[-2]+trib[-3])
trib
[0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513, 35890, 66012, 121415, 223317]
mylist = [23, 11, 15, 10] while size(mylist)!= 0: print mylist mylist = delist(mylist)
[23, 11, 15, 10] [12, 4, 5, 13] [8, 1, 8, 1] [7, 7, 7, 7]
mylist = [7, 13, 24, 44] rows =1 while (size(mylist)!= 0)&(rows<40): print mylist rows += 1 mylist = delist(mylist)
[7, 13, 24, 44] [6, 11, 20, 37] [5, 9, 17, 31] [4, 8, 14, 26] [4, 6, 12, 22] [2, 6, 10, 18] [4, 4, 8, 16] [0, 4, 8, 12] [4, 4, 4, 12] [0, 0, 8, 8] [0, 8, 0, 8] [8, 8, 8, 8]
mylist = [1, 2, 4, 8] rows =1 while (size(mylist)!= 0)&(rows<40): print mylist rows += 1 mylist = delist(mylist)
[1, 2, 4, 8] [1, 2, 4, 7] [1, 2, 3, 6] [1, 1, 3, 5] [0, 2, 2, 4] [2, 0, 2, 4] [2, 2, 2, 2]
mylist = [1, 4, 9, 16] rows =1 while (size(mylist)!= 0)&(rows<40): print mylist rows += 1 mylist = delist(mylist)
[1, 4, 9, 16] [3, 5, 7, 15] [2, 2, 8, 12] [0, 6, 4, 10] [6, 2, 6, 10] [4, 4, 4, 4]
mylist = [16, 25, 36, 49] rows =1 while (size(mylist)!= 0)&(rows<40): print mylist rows += 1 mylist = delist(mylist)
[16, 25, 36, 49] [9, 11, 13, 33] [2, 2, 20, 24] [0, 18, 4, 22] [18, 14, 18, 22] [4, 4, 4, 4]
mylist = [81, 149, 274, 504] rows =1 while (size(mylist)!= 0)&(rows<40): print mylist rows += 1 mylist = delist(mylist)
[81, 149, 274, 504] [68, 125, 230, 423] [57, 105, 193, 355] [48, 88, 162, 298] [40, 74, 136, 250] [34, 62, 114, 210] [28, 52, 96, 176] [24, 44, 80, 148] [20, 36, 68, 124] [16, 32, 56, 104] [16, 24, 48, 88] [8, 24, 40, 72] [16, 16, 32, 64] [0, 16, 32, 48] [16, 16, 16, 48] [0, 0, 32, 32] [0, 32, 0, 32] [32, 32, 32, 32]
Interact: please open in CoCalc
6*7
42
67^67
5
5
67**67
222337020242360576812569226538683753874082408437758291741262115823894811650848346334502642370010973465496690788650052277723
4.5 %2
0.500000000000000
5.5%2
-0.500000000000000
mod(8,5)
3
mod(5,2)
1
abs(-4)
4
def h(x): r=x-2*floor(x/2) return abs(r)
h(17)
1
h(-3)
1
plot(h(x),x,-5,5)
3.
3.is_even()
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "sage/structure/element.pyx", line 418, in sage.structure.element.Element.__getattr__ (/projects/sage/sage-6.9/src/build/cythonized/sage/structure/element.c:4670) return getattr_from_other_class(self, P._abstract_element_class, name) File "sage/structure/misc.pyx", line 259, in sage.structure.misc.getattr_from_other_class (/projects/sage/sage-6.9/src/build/cythonized/sage/structure/misc.c:1771) raise dummy_attribute_error AttributeError: 'sage.rings.integer.Integer' object has no attribute 'is_even'
abs
int(9.9)
9
plot(s,.6,.602)
n=100 def h(x): x=abs(x) if int(x) %2 ==0: return x-int(x) else: return 1-(x-int(x)) def s(x): v=0 for i in [0..n]: v += h(x*2^i)/2^i return v @interact def _(x=slider(0,1,default=0.5),maglevel=selector([0..10],nrows=1),mag=checkbox(false,'mag on')): if mag: d=1/4^maglevel else: d=x/2 xmn=x-d ymn=s(x)-d xmx=x+d ymx = ymn+2*d p=plot(s,xmin=xmn, ymin=ymn, xmax=xmx, ymax=ymx) show(p)
Interact: please open in CoCalc
mlist=[1,2,3,4,5,6,7,8,9]
mlist
[1, 2, 3, 4, 5, 6, 7, 8, 9]
n=200000 myList=[1..n] sums=[0] for i in [1..10050]: s=sum(myList[:3]) myList=myList[3:] myList.remove(s) sums.append(s)
[sums[k]+2*k for k in [1..10]]
[8, 20, 33, 44, 56, 69, 80, 91, 105, 116]
lasts=[sums[k]%10000 for k in [0..10000]]
lasts.index(2015)
1202
sums[1202] sum([sums[k] for k in [1..29]])
12015 4241
lasts.index(75)
8
1202-8
1194
(2015-75)/30 sum([sums[k] for k in [1..u]])+sum([sums[k] for k in [1..3*u-1]]) (10*u-3)*(5*u-1)
194/3
Error in lines 2-2 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'u' is not defined
mlist[3:]
[4, 6, 7, 8, 9]
[sums[k] for k in [1..22]]
sums[8]
75
182+1138
1320
4
4
4
47*48
2256
2256/2
1128
plot((x-2)^2*(x+4)^3/((x-1)^6*(x+2)^3), (x,-6,-2.5))
p=15 q=1 n= p*q wf=float(cos(2*pi/n))+I*float(sin(2*pi/n)) w=cos(2*pi/n)+I*sin(2*pi/n) pr=1 for a in [1..n]: for b in [1..n]: pr *= 1.+w^(a*b) pr
-(3.19291469757126e-13005)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^225 - 1.56764265941035e203)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^210 - 4.45550841564668e189)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^196 - 1.01306532443384e177)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^195 - 1.26633165554230e176)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^182 - 2.30344386280612e164)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^180 - 3.59913103563456e162)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^169 - 4.18993997810706e152)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^168 - 5.23742497263383e151)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^165 - 1.02293456496754e149)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^156 - 7.62145642166990e140)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^154 - 1.19085256588592e139)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^150 - 2.90735489718243e135)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^144 - 1.10906787764833e130)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^143 - 1.38633484706041e129)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^140 - 2.70768524816486e126)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^135 - 8.26319960987811e121)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^132 - 1.61390617380432e119)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^130 - 2.52172839656925e117)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^126 - 6.15656346818664e113)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^121 - 1.87883406621907e109)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^120 - 2.34854258277383e108)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^117 - 4.58699723198014e105)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^112 - 1.39984046386113e101)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^110 - 2.18725072478301e99)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^108 - 3.41757925747346e97)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^105 - 6.67495948725284e94)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^104 - 8.34369935906606e93)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^100 - 2.03703597633449e90)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^99 - 2.54629497041811e89)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^98 - 3.18286871302263e88)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^96 - 4.97323236409787e86)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^91 - 1.51771007205135e82)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^90 - 1.89713759006419e81)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^88 - 2.96427748447529e79)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^84 - 7.23700557733226e75)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^81 - 1.41347765182271e73)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^80 - 1.76684706477838e72)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^78 - 2.76069853871623e70)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^77 - 3.45087317339528e69)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^75 - 5.39198933343013e67)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^72 - 1.05312291668557e65)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^70 - 1.64550455732121e63)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^66 - 4.01734511064748e59)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^65 - 5.02168138830934e58)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^64 - 6.27710173538668e57)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^63 - 7.84637716923335e56)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^60 - 1.53249554086589e54)^6*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^56 - 3.74144419156711e50)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^55 - 4.67680523945889e49)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^54 - 5.84600654932361e48)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^52 - 9.13438523331814e46)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^50 - 1.42724769270596e45)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^49 - 1.78405961588245e44)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^48 - 2.23007451985306e43)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^45 - 4.35561429658801e40)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^44 - 5.44451787073502e39)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^42 - 8.50705917302346e37)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^40 - 1.32922799578492e36)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^39 - 1.66153499473114e35)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^36 - 3.24518553658427e32)^5*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^35 - 4.05648192073033e31)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^33 - 6.33825300114115e29)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^32 - 7.92281625142643e28)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^30 - 1.23794003928538e27)^6*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^28 - 1.93428131138341e25)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^27 - 2.41785163922926e24)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^26 - 3.02231454903657e23)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^25 - 3.77789318629572e22)*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^24 - 4.72236648286965e21)^6*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^22 - 7.37869762948382e19)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^21 - 9.22337203685478e18)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^20 - 1.15292150460685e18)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^18 - 1.80143985094820e16)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^16 - 2.81474976710656e14)^3*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^15 - 3.51843720888320e13)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^14 - 4.39804651110400e12)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^13 - 5.49755813888000e11)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^12 - 6.87194767360000e10)^6*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^11 - 8.58993459200000e9)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^10 - 1.07374182400000e9)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^9 - 1.34217728000000e8)^3*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^8 - 1.67772160000000e7)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^7 - 2.09715200000000e6)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^6 - 262144.000000000)^4*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^5 - 32768.0000000000)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^4 - 4096.00000000000)^3*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^3 - 512.000000000000)^2*(-1.00000000000000*(sqrt(5) + 2*sqrt(-3/2*sqrt(5) + 15/2) + 8*I*sin(2/15*pi) + 1)^2 - 64.0000000000000)^2*(-1.00000000000000*sqrt(5) - 2.00000000000000*sqrt(-3/2*sqrt(5) + 15/2) - 8.00000000000000*I*sin(2/15*pi) - 9.00000000000000)
real(pr)
/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/functions/other.py:2108: RuntimeWarning: tp_compare didn't return -1 or -2 for exception return GinacFunction.__call__(self, x, **kwargs) Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/functions/other.py", line 2108, in __call__ return GinacFunction.__call__(self, x, **kwargs) File "sage/symbolic/function.pyx", line 847, in sage.symbolic.function.GinacFunction.__call__ (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/function.cpp:9814) res = super(GinacFunction, self).__call__(*args, **kwds) File "sage/symbolic/function.pyx", line 985, in sage.symbolic.function.BuiltinFunction.__call__ (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/function.cpp:11182) res = method() File "sage/symbolic/expression.pyx", line 6859, in sage.symbolic.expression.Expression.real_part (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/expression.cpp:38408) g_hold_wrapper(g_real_part, self._gobj, hold)) File "sage/rings/number_field/number_field_element.pyx", line 1763, in sage.rings.number_field.number_field_element.NumberFieldElement.__pow__ (/projects/sage/sage-6.9/src/build/cythonized/sage/rings/number_field/number_field_element.cpp:18215) return generic_power_c(base, exp, None) File "sage/structure/element.pyx", line 3637, in sage.structure.element.generic_power_c (/projects/sage/sage-6.9/src/build/cythonized/sage/structure/element.c:29598) elif n < 0: File "sage/symbolic/pynac.pyx", line 1014, in sage.symbolic.pynac.py_is_equal (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/pynac.cpp:10389) return bool(x==y) File "sage/symbolic/pynac.pyx", line 1014, in sage.symbolic.pynac.py_is_equal (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/pynac.cpp:10389) return bool(x==y) File "sage/symbolic/pynac.pyx", line 1014, in sage.symbolic.pynac.py_is_equal (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/pynac.cpp:10389) return bool(x==y) File "sage/symbolic/pynac.pyx", line 1014, in sage.symbolic.pynac.py_is_equal (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/pynac.cpp:10389) return bool(x==y) File "sage/symbolic/pynac.pyx", line 1014, in sage.symbolic.pynac.py_is_equal (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/pynac.cpp:10389) return bool(x==y) File "sage/symbolic/pynac.pyx", line 1014, in sage.symbolic.pynac.py_is_equal (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/pynac.cpp:10389) return bool(x==y) File "sage/symbolic/pynac.pyx", line 1045, in sage.symbolic.pynac.py_is_integer (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/pynac.cpp:10525) (x in ZZ)) File "sage/structure/parent.pyx", line 1285, in sage.structure.parent.Parent.__contains__ (/projects/sage/sage-6.9/src/build/cythonized/sage/structure/parent.c:10484) if P is self or P == self: File "sage/rings/integer_ring.pyx", line 365, in sage.rings.integer_ring.IntegerRing_class.__richcmp__ (/projects/sage/sage-6.9/src/build/cythonized/sage/rings/integer_ring.c:4212) return (<Parent>left)._richcmp(right, op) File "sage/structure/parent.pyx", line 1502, in sage.structure.parent.Parent._richcmp (/projects/sage/sage-6.9/src/build/cythonized/sage/structure/parent.c:11961) r = left._cmp_(right) File "sage/rings/integer_ring.pyx", line 383, in sage.rings.integer_ring.IntegerRing_class._cmp_ (/projects/sage/sage-6.9/src/build/cythonized/sage/rings/integer_ring.c:4391) return cmp(type(left), type(right)) File "sage/symbolic/pynac.pyx", line 1014, in sage.symbolic.pynac.py_is_equal (/projects/sage/sage-6.9/src/build/cythonized/sage/symbolic/pynac.cpp:10389) return bool(x==y) File "sage/rings/number_field/number_field_element_quadratic.pyx", line 672, in sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic.__richcmp__ (/projects/sage/sage-6.9/src/build/cythonized/sage/rings/number_field/number_field_element_quadratic.cpp:7860) return (<Element>left)._richcmp(right, op) File "sage/structure/element.pyx", line 1005, in sage.structure.element.Element._richcmp (/projects/sage/sage-6.9/src/build/cythonized/sage/structure/element.c:9888) left, right = coercion_model.canonical_coercion(self, other) File "sage/structure/coerce.pyx", line 1135, in sage.structure.coerce.CoercionModel_cache_maps.canonical_coercion (/projects/sage/sage-6.9/src/build/cythonized/sage/structure/coerce.c:10171) y_elt = (<Map>y_map)._call_(y) File "sage/structure/coerce_maps.pyx", line 104, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (/projects/sage/sage-6.9/src/build/cythonized/sage/structure/coerce_maps.c:4432) return C._element_constructor(x) File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/rings/number_field/number_field.py", line 1382, in _element_constructor_ def _element_constructor_(self, x, check=True): File "sage/ext/interrupt/interrupt.pyx", line 203, in sage.ext.interrupt.interrupt.sage_python_check_interrupt (/projects/sage/sage-6.9/src/build/cythonized/sage/ext/interrupt/interrupt.c:1890) sig_check() File "sage/ext/interrupt/interrupt.pyx", line 88, in sage.ext.interrupt.interrupt.sig_raise_exception (/projects/sage/sage-6.9/src/build/cythonized/sage/ext/interrupt/interrupt.c:924) raise KeyboardInterrupt KeyboardInterrupt
n(w^15)
0.999999999999999 - 1.38777878078145e-16*I
myl=[1,2,3,4]; myl[-2]
3
a=[1,2] for n in range(2500): a.append(4*a[-1]-a[-2])
a[3]
26
a[4]
97
a[5]
362
[a[n]%97 for n in [2011..2030]]
[71, 0, 26, 7, 2, 1, 2, 7, 26, 0, 71, 90, 95, 96, 95, 90, 71, 0, 26, 7]
100^2-99^2-98^2+97^2
4
len([1,2,3])
3
mylist1=[1,2,3] mylist2=[4,5,6] mylist1+mylist2
[1, 2, 3, 4, 5, 6]
mylist1[:-1]
[1, 2]
def outcomes(mylist): lth = len(mylist) if lth ==0: return [] else: if lth ==1: return [mylist[0],-mylist[0]] else: end = mylist[-1] first = mylist[:-1] temp=outcomes(first) outlist = [] #print outlist for v in temp: #print v outlist.append(v+end) outlist.append(v-end) #print outlist return outlist
c=[a%48 for a in outcomes([1,8,27,64,125,216])]
congs = [] m=7 cubes =[] for k in [1..m]: cubes.append(k^3) for v in outcomes(cubes): congs.append(v%48) union(congs)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]
18
len(union(congs))
48
for v in []: print 'l'
-(1)^3+2^3+3^3-4^3+5^3-6^3-7^3+8^3
48
s=0 coeffs=[-1,1,1,-1,1,-1,-1,1,1,-1,-1,1,-1,1,1,-1] total=0 for k in range(16): total += coeffs[k]*(s+k)^4 total
-32
folds= [1] f(x) = 1-x def backflip(myList): temp = copy(myList) temp.reverse() return map(f,temp) for level in range(12): previous=folds flipped = backflip(previous) folds=previous + [1] + flipped
len(folds)
8191
for k in range(13): print folds[2^k-1]
1 1 1 1 1 1 1 1 1 1 1 1 1
folds[2015]
mlst=[1,0,0,0,1,0] backflip(mlst)
[1, 0, 1, 1, 1, 0]
mlst
[0, 1, 0, 0, 0, 1]
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> TypeError: argument 2 to map() must support iteration
for k in range(24): print k, 7^k
0 1 1 7 2 49 3 343 4 2401 5 16807 6 117649 7 823543 8 5764801 9 40353607 10 282475249 11 1977326743 12 13841287201 13 96889010407 14 678223072849 15 4747561509943 16 33232930569601 17 232630513987207 18 1628413597910449 19 11398895185373143 20 79792266297612001 21 558545864083284007 22 3909821048582988049 23 27368747340080916343
401^5
10368641602001
var('a') expand((2000*a+1)^5)
a 32000000000000000*a^5 + 80000000000000*a^4 + 80000000000*a^3 + 40000000*a^2 + 10000*a + 1
521973756982990550719199214832958126198121700634846638398592035971765722435787955577804593232551231283468919250766283527579242260482601749889290826725419773851552215257265229938305244969325778738628201036689246273246528854636455945197843566563980378567456558709819621238303165000193416617274725798102234110658591910052267634510706428344516340271478685916960404145585637532327012905727948440551436513376507268061541499810103240257806551355247649156891452359802300657177149222465555301688499164889785395488845823246095892923714630835045456358397990676159773311725816731099440308591085181247212750938104741858370522286597138253543893150043466011612130002639170565743641621933185982688731336278306978131170896030399206747187146615676312653503152705984657867333249498550102237826331911677823704522930573071088299615343901871997962114518154362971166311352852419293587318821327910579860310770963718031815972854318090457698043744252565058078864349773329729872194802436701457281017132473678339929003139321304381497428883796330250687336130949242590503452360900122616992866873335095837908993163504185517957394228304806789601098035733232025570373145284903532292400612865549240753428531158555951619232035853131999862903452202266305564091809805881653610880442679966531140288555025538691780604446100023519241878814424788467460602292643098399301301597561676194009287243216438841925656212180765720469027007908064218550835559977920186197482618713916221783102641478017314936499238242725967667768668965345306766144131520836400377527346892310613598302099630024539336092586281860743378284816789775372168337490660000081669308109945179976300830377876262965625626831138222824795047561068653471967112062191243091976831915011769601
7^2016
521973756982990550719199214832958126198121700634846638398592035971765722435787955577804593232551231283468919250766283527579242260482601749889290826725419773851552215257265229938305244969325778738628201036689246273246528854636455945197843566563980378567456558709819621238303165000193416617274725798102234110658591910052267634510706428344516340271478685916960404145585637532327012905727948440551436513376507268061541499810103240257806551355247649156891452359802300657177149222465555301688499164889785395488845823246095892923714630835045456358397990676159773311725816731099440308591085181247212750938104741858370522286597138253543893150043466011612130002639170565743641621933185982688731336278306978131170896030399206747187146615676312653503152705984657867333249498550102237826331911677823704522930573071088299615343901871997962114518154362971166311352852419293587318821327910579860310770963718031815972854318090457698043744252565058078864349773329729872194802436701457281017132473678339929003139321304381497428883796330250687336130949242590503452360900122616992866873335095837908993163504185517957394228304806789601098035733232025570373145284903532292400612865549240753428531158555951619232035853131999862903452202266305564091809805881653610880442679966531140288555025538691780604446100023519241878814424788467460602292643098399301301597561676194009287243216438841925656212180765720469027007908064218550835559977920186197482618713916221783102641478017314936499238242725967667768668965345306766144131520836400377527346892310613598302099630024539336092586281860743378284816789775372168337490660000081669308109945179976300830377876262965625626831138222824795047561068653471967112062191243091976831915011769601
factor(14182439040)
2^7 * 3^4 * 5 * 7 * 11^2 * 17 * 19
P=Primes()
[P.unrank(k) for k in [100000..100100]]
[1299721, 1299743, 1299763, 1299791, 1299811, 1299817, 1299821, 1299827, 1299833, 1299841, 1299853, 1299869, 1299877, 1299887, 1299899, 1299917, 1299919, 1299941, 1299953, 1299979, 1299989, 1300021, 1300027, 1300031, 1300051, 1300073, 1300097, 1300111, 1300127, 1300129, 1300133, 1300139, 1300141, 1300147, 1300153, 1300181, 1300193, 1300199, 1300237, 1300253, 1300283, 1300289, 1300297, 1300307, 1300309, 1300319, 1300333, 1300339, 1300367, 1300391, 1300421, 1300423, 1300433, 1300451, 1300457, 1300463, 1300471, 1300477, 1300487, 1300501, 1300511, 1300553, 1300571, 1300573, 1300583, 1300597, 1300609, 1300613, 1300633, 1300639, 1300669, 1300681, 1300709, 1300711, 1300727, 1300751, 1300769, 1300771, 1300781, 1300813, 1300829, 1300837, 1300841, 1300843, 1300907, 1300921, 1300927, 1300931, 1300963, 1300967, 1300979, 1300997, 1301011, 1301017, 1301021, 1301023, 1301033, 1301057, 1301077, 1301081, 1301099]
1301021*1301023
1692658244483
1692658244483%9
8
u=0.5 u
0.500000000000000
sqrt(-u*sqrt(u)+u)/u^2
1.53073372946036
f=(1+sqrt(5))/2 a=f; b= -1/f; c= 1-a; d= 1-b
r
a=2+sqrt(3) b=2-sqrt(3) c=-1. d=-1
print a,b,c,d
1/2*sqrt(5) + 1/2 -2/(sqrt(5) + 1) -1/2*sqrt(5) + 1/2 2/(sqrt(5) + 1) + 1
a+b+c+d
2.00000000000000
float(1/a+1/b+1/c+1/d)
1.9999999999999987
float(1/(1-a)+1/(1-b)+1/(1-c)+1/(1-d))
2.0
float(a)
1.618033988749895
float(b)
-0.6180339887498948
float(c)
-0.6180339887498949
float(d)
1.618033988749895
for k in [1..7]: u=5^(2^k) print k, (u^2-u)/10^k
1 60 2 3900 3 152587500 4 2328306436523437500 5 5421010862427522170037031173706054687500 6 293873587705571876992184134305561419454666388650920794134435709565877914428710937500 7 8636168555094444625386351862800399571116000364436281385023703470168591803162427057971507474084929456003359594727736233040853153480193027391464966058265417814254760742187500
5^16-10000
152587880625
152587880625^2-152587880625
23283061313476662510000
for k in [1..17]: u=5^(2^k)%10^k print k, u, u^2
1 5 25 2 25 625 3 625 390625 4 625 390625 5 90625 8212890625 6 890625 793212890625 7 2890625 8355712890625 8 12890625 166168212890625 9 212890625 45322418212890625 10 8212890625 67451572418212890625 11 18212890625 331709384918212890625 12 918212890625 843114912509918212890625 13 9918212890625 98370946943759918212890625 14 59918212890625 3590192236006259918212890625 15 259918212890625 67557477392256259918212890625 16 6259918212890625 39186576032079756259918212890625 17 56259918212890625 3165178397321142256259918212890625
5^16
152587890625
for k in [1..20]: print k, 5^k
1 5 2 25 3 125 4 625 5 3125 6 15625 7 78125 8 390625 9 1953125 10 9765625 11 48828125 12 244140625 13 1220703125 14 6103515625 15 30517578125 16 152587890625 17 762939453125 18 3814697265625 19 19073486328125 20 95367431640625
for k in [1..30]: u=5^(2^k)%10^k print k, u
1 5 2 25 3 625 4 625 5 90625 6 890625 7 2890625 8 12890625 9 212890625 10 8212890625 11 18212890625 12 918212890625 13 9918212890625 14 59918212890625 15 259918212890625 16 6259918212890625 17 56259918212890625 18 256259918212890625 19 2256259918212890625 20 92256259918212890625 21 392256259918212890625 22 7392256259918212890625 23 77392256259918212890625 24 977392256259918212890625 25 9977392256259918212890625 26 19977392256259918212890625 27 619977392256259918212890625 28 6619977392256259918212890625 29 6619977392256259918212890625 30 106619977392256259918212890625
6619977392256259918212890625
5
5
6619977392256259918212890625^2
43824100673983991394155879106619977392256259918212890625
9625^2
92640625
62562
62562
625^2
390625
for k in [1..9]: print k, 5^(2^k)
1 25 2 625 3 390625 4 152587890625 5 23283064365386962890625 6 542101086242752217003726400434970855712890625 7 293873587705571876992184134305561419454666389193021880377187926569604314863681793212890625 8 86361685550944446253863518628003995711160003644362813850237034701685918031624270579715075034722882265605472939461496635969950989468319466936530037770580747746862471103668212890625 9 7458340731200206743290965315462933837376471534600406894271518333206278385070118304936174890400427803361511603255836101453412728095225302660486164829592084691481260792318781377495204074266435262941446554365063914765414217260588507120031686823003222742297563699265350215337206058336516628646003612927433551846968657326499008153319891789578832685947418212890625
106619977392256259918212890625^2
11367819579125235975036734004106619977392256259918212890625
625^2
390625
7^899
5535259332367700277978657326589927198133008107122538365354192538956547086422515910639636698316809405197004157588908165185273330066488585796724794051175182565589381565565900357737376274323429225672888525668572160105313219760532202235440837604994309541976321319719709618539837068646339433990033331721080114918303005889346193909637364851356692525890440460794334812083737004704271134457490656828562662159325676765590727941985516775771401780048062630125318459180313888360650125531477863690761630557251636930271428040920539024248699891536258196815401632705539823560804034267139224992033028692517856283003110131582042634439135577934405335297898262493410892234857848337092975960637469951317432992282890881496953958018946412622539699551286744074466684710433403136077143
plot(sin,0,pi)
factor(2016)
2^5 * 3^2 * 7
for k in range(8): print k, factor(10^(2^k)+1)
0 11 1 101 2 73 * 137 3 17 * 5882353 4 353 * 449 * 641 * 1409 * 69857 5 19841 * 976193 * 6187457 * 834427406578561 6 1265011073 * 15343168188889137818369 * 515217525265213267447869906815873 7 257 * 15361 * 453377 * 55871187633753621225794775009016131346430842253464047463157158784732544216230781165223702155223678309562822667655169
continued_fraction??
File: /projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/rings/continued_fraction.py Source: def continued_fraction(x, value=None): r""" Return the continued fraction of ``x``. INPUT: - `x` -- a number or a list of partial quotients (for finite development) or two list of partial quotients (preperiod and period for ultimately periodic development) EXAMPLES: A finite continued fraction may be initialized by a number or by its list of partial quotients:: sage: continued_fraction(12/571) [0; 47, 1, 1, 2, 2] sage: continued_fraction([3,2,1,4]) [3; 2, 1, 4] It can be called with elements defined from symbolic values, in which case the partial quotients are evaluated in a lazy way:: sage: c = continued_fraction(golden_ratio); c [1; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...] sage: c.convergent(12) 377/233 sage: fibonacci(14)/fibonacci(13) 377/233 sage: continued_fraction(pi) [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] sage: c = continued_fraction(pi); c [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] sage: a = c.convergent(3); a 355/113 sage: a.n() 3.14159292035398 sage: pi.n() 3.14159265358979 sage: continued_fraction(sqrt(2)) [1; 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ...] sage: continued_fraction(tan(1)) [1; 1, 1, 3, 1, 5, 1, 7, 1, 9, 1, 11, 1, 13, 1, 15, 1, 17, 1, 19, ...] sage: continued_fraction(tanh(1)) [0; 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, ...] sage: continued_fraction(e) [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1, 1, ...] If you want to play with quadratic numbers (such as ``golden_ratio`` and ``sqrt(2)`` above), it is much more convenient to use number fields as follows since preperiods and periods are computed:: sage: K.<sqrt5> = NumberField(x^2-5, embedding=2.23) sage: my_golden_ratio = (1 + sqrt5)/2 sage: cf = continued_fraction((1+sqrt5)/2); cf [(1)*] sage: cf.convergent(12) 377/233 sage: cf.period() (1,) sage: cf = continued_fraction(2/3+sqrt5/5); cf [1; 8, (1, 3, 1, 1, 3, 9)*] sage: cf.preperiod() (1, 8) sage: cf.period() (1, 3, 1, 1, 3, 9) sage: L.<sqrt2> = NumberField(x^2-2, embedding=1.41) sage: cf = continued_fraction(sqrt2); cf [1; (2)*] sage: cf.period() (2,) sage: cf = continued_fraction(sqrt2/3); cf [0; 2, (8, 4)*] sage: cf.period() (8, 4) It is also possible to go the other way around, build a ultimately periodic continued fraction from its preperiod and its period and get its value back:: sage: cf = continued_fraction([(1,1),(2,8)]); cf [1; 1, (2, 8)*] sage: cf.value() 2/11*sqrt5 + 14/11 It is possible to deal with higher degree number fields but in that case the continued fraction expansion is known to be aperiodic:: sage: K.<a> = NumberField(x^3-2, embedding=1.25) sage: cf = continued_fraction(a); cf [1; 3, 1, 5, 1, 1, 4, 1, 1, 8, 1, 14, 1, 10, 2, 1, 4, 12, 2, 3, ...] Note that initial rounding can result in incorrect trailing partial quotients:: sage: continued_fraction(RealField(39)(e)) [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 2] Note the value returned for floating point number is the continued fraction associated to the rational number you obtain with a conversion:: sage: for _ in xrange(10): ....: x = RR.random_element() ....: cff = continued_fraction(x) ....: cfe = QQ(x).continued_fraction() ....: assert cff == cfe, "%s %s %s"%(x,cff,cfe) TESTS: Fixed :trac:`18901`. For RealLiteral, continued_fraction calls continued_fraction_list:: sage: continued_fraction(1.575709393346379) [1; 1, 1, 2, 1, 4, 18, 1, 5, 2, 25037802, 7, 1, 3, 1, 28, 1, 8, 2] """ if isinstance(x, ContinuedFraction_base): return x try: return x.continued_fraction() except AttributeError: pass # input for finite or ultimately periodic partial quotient expansion from sage.combinat.words.finite_word import FiniteWord_class if isinstance(x, FiniteWord_class): x = list(x) if isinstance(x, (list, tuple)): if len(x) == 2 and isinstance(x[0], (list,tuple)) and isinstance(x[1], (list,tuple)): x1 = tuple(Integer(a) for a in x[0]) x2 = tuple(Integer(a) for a in x[1]) x1, x2 = check_and_reduce_pair(x1, x2) else: x1, x2 = check_and_reduce_pair(x) return ContinuedFraction_periodic(x1, x2) # input for infinite partial quotient expansion from sage.misc.lazy_list import lazy_list from sage.combinat.words.infinite_word import InfiniteWord_class if isinstance(x, (lazy_list, InfiniteWord_class)): return ContinuedFraction_infinite(x, value) from sage.combinat.words.abstract_word import Word_class if isinstance(x, Word_class): raise ValueError("word with unknown length can not be converted to continued fractions") # input for numbers #TODO: the approach used below might be not what the user expects as we # have currently in sage (version 6.8) # # sage: RR.random_element() in QQ # True # # But, be careful with real literals # # sage: a = 1.575709393346379 # sage: a in QQ # False from rational_field import QQ if x in QQ: return QQ(x).continued_fraction() is_real = False try: is_real = x.is_real() except AttributeError: pass from real_mpfi import RealIntervalField, RealIntervalFieldElement if is_real is False: # we can not rely on the answer of .is_real() for elements of the # symbolic ring. The thing below is a dirty temporary hack. RIF = RealIntervalField(53) try: RIF(x) is_real = True except (AttributeError,ValueError): pass if is_real is False: raise ValueError("the number %s does not seem to be a real number"%x) if x.parent().is_exact(): return ContinuedFraction_real(x) # we treat separatly the symbolic ring that holds all constants and # which is not exact from sage.symbolic.ring import SR if x.parent() == SR: return ContinuedFraction_real(x) return continued_fraction(continued_fraction_list(x))
ec1=plot(sqrt(x^3+17),(x,-17^(1/3),5),aspect_ratio=1) ec2=plot(-sqrt(x^3+17),(x,-17^(1/3),5),aspect_ratio=1) pt = point((-1,4)) (ec1+ec2+pt).show()
def newx(u): v=sqrt(u^3+17) m=3*u^2/(2*v) return m^2-2*u
newx(-1)
137/64
def twop(pt): return [2*pt[0],2*pt[1]]
twop([1,3])
[2, 6]
[3^k % 13 for k in range(12)]
[1, 3, 9, 1, 3, 9, 1, 3, 9, 1, 3, 9]
l2=log(2.,10)
l2*100000
30102.9995663981
2.^100000/10^30103
0.999002093014384
a =799
a.is_prime()
False
def twice(x): return x+x
twice(100)
200
twice('cat')
'catcat'
print 'hello world'
hello world
plot(x * sin(x), (x, -2, 10))
g = graphs.RandomGNM(15, 105) # 15 vertices and 20 edges show(g,size=1000) g.incidence_matrix()
d3-based renderer not yet implemented
15 x 105 sparse matrix over Integer Ring
m=7 headerRow=['x']+range(m) data=[headerRow] for r in range(m): data.append([r]+[mod(r*c,m) for c in range(m)]) table(data,header_row=True, header_column=True)
x | 0 1 2 3 4 5 6 +---+---+---+---+---+---+---+---+ 0 | 0 0 0 0 0 0 0 1 | 0 1 2 3 4 5 6 2 | 0 2 4 6 1 3 5 3 | 0 3 6 2 5 1 4 4 | 0 4 1 5 2 6 3 5 | 0 5 3 1 6 4 2 6 | 0 6 5 4 3 2 1
x=9
x.coprime_integers(9)
[1, 2, 4, 5, 7, 8]
m=8 cops = m.coprime_integers(m) headerRow=['x']+cops data=[headerRow] for r in cops: data.append([r]+[mod(r*c,m) for c in cops]) table(data,header_row=True, header_column=True)
x | 1 3 5 7 +---+---+---+---+---+ 1 | 1 3 5 7 3 | 3 1 7 5 5 | 5 7 1 3 7 | 7 5 3 1
m=11 cops = m.coprime_integers(m) print '&', for c in cops: print c,'&', print "lr" for r in cops: print r,'&', for c in cops: print mod(r*c,m),"&", print "lr"
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & lr 1 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & lr 2 & 2 & 4 & 6 & 8 & 10 & 1 & 3 & 5 & 7 & 9 & lr 3 & 3 & 6 & 9 & 1 & 4 & 7 & 10 & 2 & 5 & 8 & lr 4 & 4 & 8 & 1 & 5 & 9 & 2 & 6 & 10 & 3 & 7 & lr 5 & 5 & 10 & 4 & 9 & 3 & 8 & 2 & 7 & 1 & 6 & lr 6 & 6 & 1 & 7 & 2 & 8 & 3 & 9 & 4 & 10 & 5 & lr 7 & 7 & 3 & 10 & 6 & 2 & 9 & 5 & 1 & 8 & 4 & lr 8 & 8 & 5 & 2 & 10 & 7 & 4 & 1 & 9 & 6 & 3 & lr 9 & 9 & 7 & 5 & 3 & 1 & 10 & 8 & 6 & 4 & 2 & lr 10 & 10 & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 & lr
m=11 k=7 [mod(k^r,m) for r in range(m)]
[1, 7, 5, 2, 3, 10, 4, 6, 9, 8, 1]
mod(7^2016,11)
4
f=sin(tan(x))
f.taylor(x,0,15)
-571772647/100590336000*x^15 - 7000033/566092800*x^13 - 968167/39916800*x^11 - 143/3456*x^9 - 55/1008*x^7 - 1/40*x^5 + 1/6*x^3 + x
g=tan(sin(x)) g.taylor(x,0,15)
986527/37362124800*x^15 + 3027637/6227020800*x^13 + 41897/39916800*x^11 - 73/24192*x^9 - 107/5040*x^7 - 1/40*x^5 + 1/6*x^3 + x
(f-g).taylor(x,0,7)
-1/30*x^7
ff=arcsin(arctan(x)) ff.taylor(x,0,15)
-4043494549/145297152000*x^15 + 1087433/32947200*x^13 - 177761/4435200*x^11 + 18649/362880*x^9 - 341/5040*x^7 + 13/120*x^5 - 1/6*x^3 + x
gg=arctan(arcsin(x)) gg.taylor(x,0,15)
-889424791/435891456000*x^15 + 29518679/2075673600*x^13 - 123379/13305600*x^11 + 12409/362880*x^9 - 173/5040*x^7 + 13/120*x^5 - 1/6*x^3 + x
(ff-gg).taylor(x,0,7)
-1/30*x^7
# collatz (n) equals n/2 if n is even, 3n+1 if n is odd def collatz(n): if n%2 == 0: return n/2 else: return 3*n+1 # compute the inverse as a list (there may be one or two values) def collatzInv(n): if n%6==4: return [2*n, (n-1)/3] else: return [2*n] # give a list of successive iterations ending at 1 def collatzEvol(n): next = collatz(n) evol=[n,next] while next <> 1: next = collatz(next) evol.append(next) return evol # make a list of inverses up to length "level" def collatzInvEvol(n,level): evol = [n] while level>0: for a in evol: evol = union(evol, collatzInv(a)) level -= 1 return evol # compute the length of the iteration def collatzLength(n): return len(collatzEvol(n)) #compute the 'max hailstone height' def collatzMax(n): return max(collatzEvol(n))
heights = [collatzMax(a) for a in [1..1000]] list_plot(heights,ymax=10000)
lev = 12 vals = collatzInvEvol(1,lev) #vals=union(vals,collatzEvol(9)) #vals=union(vals, collatzEvol(576)) t=17 for i in [3..t]: vals=union(vals, collatzEvol(i)) vals.remove(1) G=DiGraph({a:[collatz(a)] for a in vals}) G.show(figsize=[10,10],vertex_size=700,layout='tree',tree_root=1,tree_orientation='up')