Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Examples of using latex in cocalc

Views: 1132
1
## -*- encoding: utf-8 -*-
2
## This file (sagetex.sagetex.sage) was *autogenerated* from sagetex.tex with sagetex.sty version 2015/08/26 v3.0-92d9f7a.
3
import sagetex
4
_st_ = sagetex.SageTeXProcessor('sagetex', version='2015/08/26 v3.0-92d9f7a', version_check=True)
5
try:
6
_st_.current_tex_line = 35
7
_st_.inline(0, latex(2+2))
8
except:
9
_st_.goboom(35)
10
try:
11
_st_.current_tex_line = 36
12
_st_.inline(1, latex(mod(2018, 100)))
13
except:
14
_st_.goboom(36)
15
try:
16
_st_.current_tex_line = 38
17
_st_.inline(2, latex(Integer(mod(2018, 100))^21))
18
except:
19
_st_.goboom(38)
20
try:
21
_st_.current_tex_line = 39
22
_st_.inline(3, latex(2018%42))
23
except:
24
_st_.goboom(39)
25
_st_.current_tex_line = 42
26
_st_.blockbegin()
27
try:
28
1+1
29
var('a,b,c')
30
eqn = [a+b*c==1, b-a*c==0, a+b==5]
31
s = solve(eqn, a,b,c)
32
except:
33
_st_.goboom(47)
34
_st_.blockend()
35
try:
36
_st_.current_tex_line = 49
37
_st_.inline(4, latex(eqn))
38
except:
39
_st_.goboom(49)
40
try:
41
_st_.current_tex_line = 51
42
_st_.inline(5, latex(s[0]))
43
except:
44
_st_.goboom(51)
45
try:
46
_st_.current_tex_line = 54
47
_st_.inline(6, latex(s[1]))
48
except:
49
_st_.goboom(54)
50
_st_.current_tex_line = 58
51
_st_.blockbegin()
52
try:
53
E = EllipticCurve("37a")
54
except:
55
_st_.goboom(60)
56
_st_.blockend()
57
try:
58
_st_.current_tex_line = 63
59
_st_.inline(7, latex(E))
60
except:
61
_st_.goboom(63)
62
try:
63
_st_.current_tex_line = 64
64
_st_.inline(8, latex(E.discriminant()))
65
except:
66
_st_.goboom(64)
67
_st_.current_tex_line = 68
68
_st_.blockbegin()
69
try:
70
try:
71
E = load('E2')
72
except IOError:
73
E = EllipticCurve([1,2,3,4,5])
74
E.anlist(100000)
75
E.save('E2')
76
except:
77
_st_.goboom(75)
78
_st_.blockend()
79
try:
80
_st_.current_tex_line = 77
81
_st_.inline(9, latex(E))
82
except:
83
_st_.goboom(77)
84
try:
85
_st_.current_tex_line = 78
86
_st_.inline(10, latex(E.anlist(100000)[9999]))
87
except:
88
_st_.goboom(78)
89
_st_.current_tex_line = 81
90
_st_.blockbegin()
91
try:
92
e = 2
93
e = 3*e + 1
94
except:
95
_st_.goboom(84)
96
_st_.blockend()
97
try:
98
_st_.current_tex_line = 85
99
_st_.inline(11, latex(e))
100
except:
101
_st_.goboom(85)
102
_st_.current_tex_line = 87
103
_st_.blockbegin()
104
try:
105
var('x')
106
f(x) = log(sin(x)/x)
107
except:
108
_st_.goboom(90)
109
_st_.blockend()
110
try:
111
_st_.current_tex_line = 91
112
_st_.inline(12, latex( f.taylor(x, 0, 10) ))
113
except:
114
_st_.goboom(91)
115
try:
116
_st_.current_tex_line = 97
117
_st_.plot(0, format='notprovided', _p_=E.plot(-3,3))
118
except:
119
_st_.goboom(97)
120
_st_.current_tex_line = 99
121
_st_.blockbegin()
122
try:
123
# the var line is unecessary unless you've defined x to be something
124
# other than a symbolic variable
125
var('x')
126
f(x) = -x^3+3*x^2+7*x-4
127
except:
128
_st_.goboom(104)
129
_st_.blockend()
130
_st_.current_tex_line = 107
131
_st_.blockbegin()
132
try:
133
p = plot(f, x, -5, 5)
134
except:
135
_st_.goboom(109)
136
_st_.blockend()
137
try:
138
_st_.current_tex_line = 113
139
_st_.plot(1, format='notprovided', _p_=p)
140
except:
141
_st_.goboom(113)
142
try:
143
_st_.current_tex_line = 118
144
_st_.plot(2, format='notprovided', _p_=p, axes=False)
145
except:
146
_st_.goboom(118)
147
_st_.current_tex_line = 122
148
_st_.blockbegin()
149
try:
150
f = maxima('sin(x)^2*exp(x)')
151
g = f.integrate('x')
152
except:
153
_st_.goboom(125)
154
_st_.blockend()
155
_st_.current_tex_line = 127
156
_st_.blockbegin()
157
try:
158
# g is a Maxima thingy, it needs to get converted into a Sage object
159
plot1 = plot(g.sage(),x,-1,2*pi)
160
except:
161
_st_.goboom(130)
162
_st_.blockend()
163
try:
164
_st_.current_tex_line = 136
165
_st_.plot(3, format='png', _p_=plot1)
166
except:
167
_st_.goboom(136)
168
try:
169
_st_.current_tex_line = 146
170
_st_.plot(4, format='notprovided', _p_=plot1 + plot(f.sage(),x,-1,2*pi,rgbcolor=hue(0.4)), figsize=[1,2])
171
except:
172
_st_.goboom(146)
173
_st_.current_tex_line = 151
174
_st_.blockbegin()
175
try:
176
p = plot(x, 0, 1) + circle((0,0), 1)
177
p.set_aspect_ratio(1)
178
except:
179
_st_.goboom(154)
180
_st_.blockend()
181
try:
182
_st_.current_tex_line = 158
183
_st_.plot(5, format='notprovided', _p_=p)
184
except:
185
_st_.goboom(158)
186
_st_.current_tex_line = 161
187
_st_.blockbegin()
188
try:
189
s = 7
190
s2 = 2^s
191
P.<x> = GF(2)[]
192
M = matrix(parent(x),s2)
193
for i in range(s2):
194
p = (1+x)^i
195
pc = p.coefficients(sparse=False)
196
a = pc.count(1)
197
for j in range(a):
198
idx = pc.index(1)
199
M[i,idx+j] = pc.pop(idx)
200
201
matrixprogram = matrix_plot(M,cmap='Greys')
202
except:
203
_st_.goboom(175)
204
_st_.blockend()
205
try:
206
_st_.current_tex_line = 178
207
_st_.plot(6, format='notprovided', _p_=matrixprogram)
208
except:
209
_st_.goboom(178)
210
try:
211
_st_.current_tex_line = 181
212
_st_.inline(13, latex(var('x')))
213
except:
214
_st_.goboom(181)
215
try:
216
_st_.current_tex_line = 253
217
_st_.inline(14, latex(var('x')))
218
except:
219
_st_.goboom(253)
220
_st_.current_tex_line = 337
221
_st_.blockbegin()
222
try:
223
x, y = var('x y')
224
except:
225
_st_.goboom(339)
226
_st_.blockend()
227
try:
228
_st_.current_tex_line = 345
229
_st_.plot(7, format='notprovided', _p_=plot3d(sin(pi*(x^2+y^2))/2,(x,-1,1),(y,-1,1)))
230
except:
231
_st_.goboom(345)
232
_st_.current_tex_line = 349
233
_st_.blockbegin()
234
try:
235
G = graphs.CubeGraph(5)
236
except:
237
_st_.goboom(351)
238
_st_.blockend()
239
try:
240
_st_.current_tex_line = 355
241
_st_.plot(8, format='png', _p_=G.plot3d())
242
except:
243
_st_.goboom(355)
244
print 'SageTeX paused on sagetex.tex line 365'
245
"""
246
try:
247
_st_.current_tex_line = 367
248
_st_.inline(15, latex(factor(2^325 + 1)))
249
except:
250
_st_.goboom(367)
251
_st_.current_tex_line = 370
252
_st_.blockbegin()
253
try:
254
import time
255
time.sleep(15)
256
except:
257
_st_.goboom(373)
258
_st_.blockend()
259
try:
260
_st_.current_tex_line = 375
261
_st_.plot(9, format='notprovided', _p_=plot(2*sin(x^2) + x^2, (x, 0, 5)))
262
except:
263
_st_.goboom(375)
264
"""
265
print 'SageTeX unpaused on sagetex.tex line 377'
266
_st_.current_tex_line = 389
267
_st_.blockbegin()
268
try:
269
def pascals_triangle(n):
270
# start of the table
271
s = [r"\begin{tabular}{cc|" + "r" * (n+1) + "}"]
272
s.append(r" & & $k$: & \\")
273
# second row, with k values:
274
s.append(r" & ")
275
for k in [0..n]:
276
s.append("& {0} ".format(k))
277
s.append(r"\\")
278
# the n = 0 row:
279
s.append(r"\hline" + "\n" + r"$n$: & 0 & 1 & \\")
280
# now the rest of the rows
281
for r in [1..n]:
282
s.append(" & {0} ".format(r))
283
for k in [0..r]:
284
s.append("& {0} ".format(binomial(r, k)))
285
s.append(r"\\")
286
# add the last line and return
287
s.append(r"\end{tabular}")
288
return ''.join(s)
289
290
# how big should the table be?
291
n = 8
292
except:
293
_st_.goboom(413)
294
_st_.blockend()
295
try:
296
_st_.current_tex_line = 420
297
_st_.inline(16, pascals_triangle(n))
298
except:
299
_st_.goboom(420)
300
try:
301
_st_.current_tex_line = 426
302
_st_.doctest(17, r"""
303
sage: 2+2
304
4
305
sage: print 'middle'
306
middle
307
sage: factor(x^2 + 2*x + 1)
308
(x + 1)^2
309
""", globals(), locals(), False)
310
except:
311
_st_.goboom(433)
312
try:
313
_st_.current_tex_line = 448
314
_st_.doctest(18, r"""
315
sage: print 'middle'
316
middle
317
""", globals(), locals(), True)
318
except:
319
_st_.goboom(451)
320
try:
321
_st_.current_tex_line = 455
322
_st_.doctest(19, r"""
323
sage: is_prime(57)
324
toothpaste
325
""", globals(), locals(), True)
326
except:
327
_st_.goboom(458)
328
try:
329
_st_.current_tex_line = 463
330
_st_.doctest(20, r"""
331
sage: gcd([5656565656,
332
....: 4747474747,
333
....: 123456789])
334
1
335
sage: mystr = '''my
336
....: string
337
....: has
338
....: several
339
....: lines.'''
340
sage: len(mystr)
341
28
342
sage: def f(a):
343
....: '''This function is really quite nice,
344
....: although perhaps not very useful.'''
345
....: print "f called with a = ", a
346
....: y = integrate(SR(cyclotomic_polynomial(10)) + a, x)
347
....: return y + 1
348
sage: f(x)
349
f called with a = x
350
1/5*x^5 - 1/4*x^4 + 1/3*x^3 + x + 1
351
""", globals(), locals(), False)
352
except:
353
_st_.goboom(484)
354
try:
355
_st_.current_tex_line = 512
356
_st_.doctest(21, r"""
357
sage: 1; 2; a=4; 3; a
358
1
359
2
360
3
361
4
362
""", globals(), locals(), False)
363
except:
364
_st_.goboom(518)
365
try:
366
_st_.current_tex_line = 519
367
_st_.inline(22, latex(a))
368
except:
369
_st_.goboom(519)
370
try:
371
_st_.current_tex_line = 521
372
_st_.doctest(23, r"""
373
sage: f(a)
374
f called with a = 4
375
1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + 5*x + 1
376
""", globals(), locals(), False)
377
except:
378
_st_.goboom(525)
379
try:
380
_st_.current_tex_line = 622
381
_st_.commandline(0, r"""
382
sage: 1+1
383
sage: is_prime(57)
384
sage: if is_prime(57):
385
....: print 'prime'
386
....: else:
387
....: print 'composite'
388
""", globals(), locals(), True)
389
except:
390
_st_.goboom(629)
391
try:
392
_st_.current_tex_line = 639
393
_st_.commandline(1, r"""
394
sage: x = 2010; len(x.divisors())
395
sage: print 'Hola, mundo!'
396
""", globals(), locals(), True)
397
except:
398
_st_.goboom(642)
399
try:
400
_st_.current_tex_line = 651
401
_st_.commandline(2, r"""
402
sage: l = matrix([[1,0,0],[3/5,1,0],[-2/5,-2,1]])
403
sage: d = diagonal_matrix([15, -1, 4]) #@\label{diagonal}
404
sage: u = matrix([[1,0,1/3],[0,1,2],[0,0,1]]) #@\label{anotherlabel} \# foo
405
sage: l*d*u # this is a comment
406
""", globals(), locals(), True)
407
except:
408
_st_.goboom(656)
409
try:
410
_st_.current_tex_line = 667
411
_st_.commandline(3, r"""
412
sage: l*d*u
413
sage: x = var('x')
414
sage: (1-cos(x)^2).trig_simplify()
415
""", globals(), locals(), False)
416
except:
417
_st_.goboom(671)
418
try:
419
_st_.current_tex_line = 683
420
_st_.commandline(4, r"""
421
sage: pi.n(100)
422
""", globals(), locals(), True)
423
except:
424
_st_.goboom(685)
425
try:
426
_st_.current_tex_line = 693
427
_st_.commandline(5, r"""
428
sage: plot(sin(x), (x, 0, 2*pi))
429
""", globals(), locals(), True)
430
except:
431
_st_.goboom(695)
432
try:
433
_st_.current_tex_line = 709
434
_st_.commandline(6, r"""
435
sage: factor(x^2 + 2*x + 1)
436
(x + 999)^2
437
""", globals(), locals(), True)
438
except:
439
_st_.goboom(712)
440
_st_.endofdoc()
441
442