Laboratoire de Recherche en Informatique
Université Paris Sud
PyParis
Session Python pour l'Éducation
September 28rd of 2018
Ce document actif sur Binder:
https://tinyurl.com/pyparis18-education-sage
1 + 1
2
( 1 + 2 * (3 + 5)^2 ) * 2
258
2^1000
10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
20.0/14
1.42857142857143
numerical_approx(4*arctan(1), 10000)
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759009946576407895126946839835259570982582262052248940772671947826848260147699090264013639443745530506820349625245174939965143142980919065925093722169646151570985838741059788595977297549893016175392846813826868386894277415599185592524595395943104997252468084598727364469584865383673622262609912460805124388439045124413654976278079771569143599770012961608944169486855584840635342207222582848864815845602850601684273945226746767889525213852254995466672782398645659611635488623057745649803559363456817432411251507606947945109659609402522887971089314566913686722874894056010150330861792868092087476091782493858900971490967598526136554978189312978482168299894872265880485756401427047755513237964145152374623436454285844479526586782105114135473573952311342716610213596953623144295248493718711014576540359027993440374200731057853906219838744780847848968332144571386875194350643021845319104848100537061468067491927819119793995206141966342875444064374512371819217999839101591956181467514269123974894090718649423196156794521
p = next_prime(2^9);
p
521
550 % p
29
Zp = FiniteField(p)
a = Zp(550); a
29
a^(7^7^7)
226
Zp.category()
Join of Category of finite enumerated fields and Category of subquotients of monoids and Category of quotients of semigroups
Zp.category().axioms()
frozenset({'AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Associative', 'Commutative', 'Distributive', 'Division', 'Enumerated', 'Finite', 'NoZeroDivisors', 'Unital'})
var('x,y')
(x, y)
factor(x^100 - 1)
(x^40 - x^30 + x^20 - x^10 + 1)*(x^20 + x^15 + x^10 + x^5 + 1)*(x^20 - x^15 + x^10 - x^5 + 1)*(x^8 - x^6 + x^4 - x^2 + 1)*(x^4 + x^3 + x^2 + x + 1)*(x^4 - x^3 + x^2 - x + 1)*(x^2 + 1)*(x + 1)*(x - 1)
%display latex
factor(x^100 -1)
solve([x^2+y^2 == 1, y^2 == x^3 + x + 1], x, y)
f = (cos(pi/4-x)-tan(x)) / (1-sin(pi/4 + x)); f
f.derivative(y)
limit(f, x = pi/4, dir='minus')
f = cos(x)^6 + sin(x)^6 + 3 * sin(x)^2 * cos(x)^2; f
f.simplify_trig()
plot(x*sin(1/x))
n, l, x, y = 10000, 1, 0, 0
p = [[0, 0]]
for k in range(n):
theta = (2 * pi * random()).n(digits=5)
x, y = x + l * cos(theta), y + l * sin(theta)
p.append([x, y])
g = line(p, thickness=.4) + line([p[n], [0, 0]], color='red', thickness=2)
g.show(aspect_ratio=1)
var('x')
@interact
def g(f=x*sin(1/x),
c=slider(-1, 1, .01, default=-.5),
n=(1..30),
xinterval=range_slider(-1, 1, .1, default=(-8,8), label="x-interval"),
yinterval=range_slider(-1, 1, .1, default=(-3,3), label="y-interval")):
x0 = c
degree = n
xmin,xmax = xinterval
ymin,ymax = yinterval
p = plot(f, xmin, xmax, thickness=4)
dot = point((x0,f(x=x0)),pointsize=80,rgbcolor=(1,0,0))
ft = f.taylor(x,x0,degree)
pt = plot(ft, xmin, xmax, color='red', thickness=2, fill=f)
show(dot + p + pt, ymin=ymin, ymax=ymax, xmin=xmin, xmax=xmax)
html('$f(x)\;=\;%s$'%latex(f))
html('$P_{%s}(x)\;=\;%s+R_{%s}(x)$'%(degree,latex(ft),degree))
SW50ZXJhY3RpdmUgZnVuY3Rpb24gPGZ1bmN0aW9uIGcgYXQgMHg3Zjg1ZWE5ZWMzMjA+IHdpdGggNSB3aWRnZXRzCiAgZjogRXZhbFRleHQodmFsdWU9dSd4KnNpbigxL3gpJywgZGVzY3JpcHTigKY=
var('x,y')
plot3d(sin(pi*sqrt(x^2+y^2)) / sqrt(x^2+y^2), (x,-5,5), (y,-5,5), viewer="threejs")
polytopes.truncated_icosidodecahedron().plot(viewer="threejs")
%display ascii_art
Symboles = Set(["Coeur", "Carreau", "Pique", "Trefle"])
Valeurs = Set([2, 3, 4, 5, 6, 7, 8, 9, 10, "Valet", "Dame", "Roi", "As"])
Cartes = cartesian_product([Valeurs, Symboles])
Mains = Subsets(Cartes, 5)
Mains.random_element()
{(6, 'Trefle'), (6, 'Coeur'), ('As', 'Carreau'), ('Roi', 'Trefle'), (8, 'Carreau')}
Mains.cardinality()
2598960
Couleurs = cartesian_product([Subsets(Valeurs, 5), Symboles])
Couleurs.random_element()
( {8, 'Roi', 2, 6, 'Dame'}, Carreau )
float( Couleurs.cardinality() / Mains.cardinality() )
0.00198079231693
Mains.cardinality??
graphs.*?
g = graphs.PetersenGraph(); g
g.*?