Open in CoCalc with one click!
y=3/5
y.n()
0.600000000000000
type(y)
<type 'sage.rings.rational.Rational'>
load("test_integers.py")
3/5 = 0
x
0
A = [[0 for j in range(15180)] for i in range(26620)]
#I am interpolating the uniformly space points, chevyshev and legendre polynomial over the interval [-1,2] with the lagrange form then finding the l^2 and l^inf norms to find the error. I am not sure what is going wrong.... OP0=-1 OP1=0 OP2=1 OP3=2 ONUME0=(x-OP1)*(x-OP2)*(x-OP3) ONUME1=(x-OP0)*(x-OP2)*(x-OP3) ONUME2=(x-OP0)*(x-OP1)*(x-OP3) ONUME3=(x-OP0)*(x-OP1)*(x-OP3) ODENO0=(OP0-OP1)*(OP0-OP2)*(OP0-OP3) ODENO1=(OP1-OP0)*(OP1-OP2)*(OP1-OP3) ODENO2=(OP2-OP0)*(OP2-OP1)*(OP2-OP3) ODENO3=(OP3-OP0)*(OP3-OP1)*(OP3-OP2) a=-1 b=2 n=3 i0=0 i1=1 i2=2 i3=3 A=((a+b)/2) B=((b-a)/2) E=(e^(-x)) OCLagr0=(ONUME0/ODENO0) OCLagr1=B*(ONUME1/ODENO1) OCLagr2=B*(ONUME2/ODENO2) OCLagr3=B*(ONUME3/ODENO3) Op0=(e^(-OCLagr0)) Op1=(e^(-OCLagr1)) Op2=(e^(-OCLagr2)) Op3=(e^(-OCLagr3)) Uniformly=((Op0*OCLagr0)+(OP1*OCLagr1)+(Op2*OCLagr2)+(Op3*OCLagr3)) #Lagrange Cheveyshev C0= numerical_approx(cos((pi)*((2*i0+1)/(2*n+2)))) C1= numerical_approx(cos((pi)*((2*i1+1)/(2*n+2)))) C2= numerical_approx(cos((pi)*((2*i2+1)/(2*n+2)))) C3= numerical_approx(cos((pi)*((2*i3+1)/(2*n+2)))) CV0=((B*C0)+A) CV1=((B*C1)+A) CV2=((B*C2)+A) CV3=((B*C3)+A) xo=CV0 xi=CV1 xii=CV2 xiii=CV3 NUME0=(x-xi)*(x-xii)*(x-xiii) NUME1=(x-xo)*(x-xii)*(x-xiii) NUME2=(x-xo)*(x-xi)*(x-xiii) NUME3=(x-xo)*(x-xi)*(x-xii) DENO0=(xo-xi)*(xo-xii)*(xo-xiii) DENO1=(xi-xo)*(xi-xii)*(xi-xiii) DENO2=(xii-xo)*(xii-xi)*(xii-xiii) DENO3=(xiii-xo)*(xiii-xi)*(xiii-xii) CLagr0=(NUME0/DENO0) CLagr1=(NUME1/DENO1) CLagr2=(NUME2/DENO2) CLagr3=(NUME3/DENO3) P0=numerical_approx(e^(-(C0))) P1=numerical_approx(e^(-(C1))) P2=numerical_approx(e^(-(C2))) P3=numerical_approx(e^(-(C3))) F0=P0*CLagr0 F1=P1*CLagr1 F2=P2*CLagr2 F3=P3*CLagr3 Chevyshev=F0+F1+F2+F3 ##Legendre LP0=1 LP1=x LP2=(1/2)*(3*((x)^2)-1) LP3=(((1/2)*(((5)*x^2)-((3)*x)))) LP4=((1/8)*(((35)*x^4)-((30)*x^2)+3)) f=7*LP0 g=8*LP4 h=20*LP2 j=3*LP1 k=2*LP3 X1=numerical_approx(-sqrt(2/35*sqrt(30) + 3/7)) X2=numerical_approx(sqrt(2/35*sqrt(30) + 3/7)) X3=numerical_approx(-sqrt(-2/35*sqrt(30) + 3/7)) X4=numerical_approx(sqrt(-2/35*sqrt(30) + 3/7)) LOV0=((B*X1)+A) LOV1=((B*X2)+A) LOV2=((B*X3)+A) LOV3=((B*X4)+A) lxo=LOV0 lxi=LOV1 lxii=LOV2 lxiii=LOV3 LNUME0=(x-lxi)*(x-lxii)*(x-lxiii) LNUME1=(x-lxo)*(x-lxii)*(x-lxiii) LNUME2=(x-lxo)*(x-lxi)*(x-lxiii) LNUME3=(x-lxo)*(x-lxi)*(x-lxii) LDENO0=(lxo-lxi)*(lxo-lxii)*(lxo-lxiii) LDENO1=(lxi-lxo)*(lxi-lxii)*(lxi-lxiii) LDENO2=(lxii-lxo)*(lxii-lxi)*(lxii-lxiii) LDENO3=(lxiii-lxo)*(lxiii-lxi)*(lxiii-lxii) LLagr0=(LNUME0/LDENO0) LLagr1=(LNUME1/LDENO1) LLagr2=(LNUME2/LDENO2) LLagr3=(LNUME3/LDENO3) LP0=numerical_approx(e^(-(X1))) LP1=numerical_approx(e^(-(X2))) LP2=numerical_approx(e^(-(X3))) LP3=numerical_approx(e^(-(X4))) LF0=LP0*LLagr0 LF1=LP1*LLagr1 LF2=LP2*LLagr2 LF3=LP3*LLagr3 Legendere=LF0+LF1+LF2+LF3 f = (0.116167595984182*(x + 0.791704467391079)*(x + 0.00997156537728427)*(x - 1.00997156537728) - 0.495492470126893*(x + 0.791704467391079)*(x + 0.00997156537728427)*(x - 1.79170446739108) + 0.978004473650812*(x + 0.791704467391079)*(x - 1.00997156537728)*(x - 1.79170446739108) - 0.650217267384311*(x + 0.00997156537728427)*(x - 1.00997156537728)*(x - 1.79170446739108))^2 g=(e^-x)^2 h=(0.0900243711092997*(x + 0.885819298766930)*(x + 0.0740251485476346)*(x - 1.07402514854763) - 0.373399955130276*(x + 0.885819298766930)*(x + 0.0740251485476346)*(x - 1.88581929876693) + 0.802728841958563*(x + 0.885819298766930)*(x - 1.07402514854763)*(x - 1.88581929876693) - 0.571257167284918*(x + 0.0740251485476346)*(x - 1.07402514854763)*(x - 1.88581929876693))^2 u=-3/4*(x + 1)*(x - 2)*x*e^(3/4*(x + 1)*(x - 2)*x) + 1/4*(x + 1)*(x - 2)*x*e^(-1/4*(x + 1)*(x - 2)*x) - 1/6*(x - 1)*(x - 2)*x*e^(1/6*(x - 1)*(x - 2)*x) asw=sum(f,x,(-1/1),(2/1))#Chevy ert=numerical_approx(sum(g,x,-1,2/1))#e^-x cvb=sum(h,x,-1/1,2/1)#Leg plm=sum(u,x,-1,2/1)#Uni l2C=norm(vector([ert-asw])) l2L=norm(vector([ert-cvb])) l2O=norm(vector([ert-plm])) l2E=norm(vector([ert])) linfC=abs(max([asw])) linfL=abs(max([cvb])) linfO=abs(max([plm])) linfE=abs(max([ert])) l2C l2L l2O linfC linfL linfO
1.37065555196861 1.39852837567751 sqrt((1/2*(e^2 - 2*e^(1/2) - 3)*e^(-3/2) + 8.54270702105600)^2) 9.913362573024607 9.941235396733509 1/2*abs(e^2 - 2*e^(1/2) - 3)*e^(-3/2)
var("x") OP0=-1 OP1=0 OP2=1 OP3=2 ONUME0=(x-OP1)*(x-OP2)*(x-OP3) ONUME1=(x-OP0)*(x-OP2)*(x-OP3) ONUME2=(x-OP0)*(x-OP1)*(x-OP3) ONUME3=(x-OP0)*(x-OP1)*(x-OP3) ODENO0=(OP0-OP1)*(OP0-OP2)*(OP0-OP3) ODENO1=(OP1-OP0)*(OP1-OP2)*(OP1-OP3) ODENO2=(OP2-OP0)*(OP2-OP1)*(OP2-OP3) ODENO3=(OP3-OP0)*(OP3-OP1)*(OP3-OP2) OCLagr0=(ONUME0/ODENO0) OCLagr1=(ONUME1/ODENO1) OCLagr2=(ONUME2/ODENO2) OCLagr3=(ONUME3/ODENO3) Op0=(e^(-OP0)) Op1=(e^(-OP1)) Op2=(e^(-OP2)) Op3=(e^(-OP3)) Uniformly=((Op0*OCLagr0)+(OP1*OCLagr1)+(Op2*OCLagr2)+(Op3*OCLagr3))
x
Uniformly
-1/6*(x - 1)*(x - 2)*x*e - 1/2*(x + 1)*(x - 2)*x*e^(-1) + 1/6*(x + 1)*(x - 2)*x*e^(-2)
plot(Uniformly,(-1,2))+plot(e^(-x),-1,2,color="red")
OP0=-1 OP1=0 OP2=1 OP3=2 ONUME0=(x-OP1)*(x-OP2)*(x-OP3) ONUME1=(x-OP0)*(x-OP2)*(x-OP3) ONUME2=(x-OP0)*(x-OP1)*(x-OP3) ONUME3=(x-OP0)*(x-OP1)*(x-OP3) ODENO0=(OP0-OP1)*(OP0-OP2)*(OP0-OP3) ODENO1=(OP1-OP0)*(OP1-OP2)*(OP1-OP3) ODENO2=(OP2-OP0)*(OP2-OP1)*(OP2-OP3) ODENO3=(OP3-OP0)*(OP3-OP1)*(OP3-OP2) OCLagr0=(ONUME0/ODENO0) OCLagr1=(ONUME1/ODENO1) OCLagr2=(ONUME2/ODENO2) OCLagr3=(ONUME3/ODENO3) Op0=(e^(-OP0)) Op1=(e^(-OP1)) Op2=(e^(-OP2)) Op3=(e^(-OP3)) Uniformly=((Op0*OCLagr0)+(OP1*OCLagr1)+(Op2*OCLagr2)+(Op3*OCLagr3)) #Lagrange Cheveyshev a=-1 b=2 n=3 i0=0 i1=1 i2=2 i3=3 A=((a+b)/2) B=((b-a)/2) E=(e^(-x)) C0= numerical_approx(cos((pi)*((2*i0+1)/(2*n+2)))) C1= numerical_approx(cos((pi)*((2*i1+1)/(2*n+2)))) C2= numerical_approx(cos((pi)*((2*i2+1)/(2*n+2)))) C3= numerical_approx(cos((pi)*((2*i3+1)/(2*n+2)))) CV0=((B*C0)+A) CV1=((B*C1)+A) CV2=((B*C2)+A) CV3=((B*C3)+A) xo=CV0 xi=CV1 xii=CV2 xiii=CV3 NUME0=(x-xi)*(x-xii)*(x-xiii) NUME1=(x-xo)*(x-xii)*(x-xiii) NUME2=(x-xo)*(x-xi)*(x-xiii) NUME3=(x-xo)*(x-xi)*(x-xii) DENO0=(xo-xi)*(xo-xii)*(xo-xiii) DENO1=(xi-xo)*(xi-xii)*(xi-xiii) DENO2=(xii-xo)*(xii-xi)*(xii-xiii) DENO3=(xiii-xo)*(xiii-xi)*(xiii-xii) CLagr0=(NUME0/DENO0) CLagr1=(NUME1/DENO1) CLagr2=(NUME2/DENO2) CLagr3=(NUME3/DENO3) P0=numerical_approx(e^(-(C0))) P1=numerical_approx(e^(-(C1))) P2=numerical_approx(e^(-(C2))) P3=numerical_approx(e^(-(C3))) F0=P0*CLagr0 F1=P1*CLagr1 F2=P2*CLagr2 F3=P3*CLagr3 Chevyshev=F0+F1+F2+F3 ##Legendre LP0=1 LP1=x LP2=(1/2)*(3*((x)^2)-1) LP3=(((1/2)*(((5)*x^2)-((3)*x)))) LP4=((1/8)*(((35)*x^4)-((30)*x^2)+3)) f=7*LP0 g=8*LP4 h=20*LP2 j=3*LP1 k=2*LP3 solve(LP4,x) X1=numerical_approx(-sqrt(2/35*sqrt(30) + 3/7)) X2=numerical_approx(sqrt(2/35*sqrt(30) + 3/7)) X3=numerical_approx(-sqrt(-2/35*sqrt(30) + 3/7)) X4=numerical_approx(sqrt(-2/35*sqrt(30) + 3/7)) LOV0=((B*X1)+A) LOV1=((B*X2)+A) LOV2=((B*X3)+A) LOV3=((B*X4)+A) lxo=LOV0 lxi=LOV1 lxii=LOV2 lxiii=LOV3 LNUME0=(x-lxi)*(x-lxii)*(x-lxiii) LNUME1=(x-lxo)*(x-lxii)*(x-lxiii) LNUME2=(x-lxo)*(x-lxi)*(x-lxiii) LNUME3=(x-lxo)*(x-lxi)*(x-lxii) LDENO0=(lxo-lxi)*(lxo-lxii)*(lxo-lxiii) LDENO1=(lxi-lxo)*(lxi-lxii)*(lxi-lxiii) LDENO2=(lxii-lxo)*(lxii-lxi)*(lxii-lxiii) LDENO3=(lxiii-lxo)*(lxiii-lxi)*(lxiii-lxii) LLagr0=(LNUME0/LDENO0) LLagr1=(LNUME1/LDENO1) LLagr2=(LNUME2/LDENO2) LLagr3=(LNUME3/LDENO3) LP0=numerical_approx(e^(-(X1))) LP1=numerical_approx(e^(-(X2))) LP2=numerical_approx(e^(-(X3))) LP3=numerical_approx(e^(-(X4))) LF0=LP0*LLagr0 LF1=LP1*LLagr1 LF2=LP2*LLagr2 LF3=LP3*LLagr3 Legendere=LF0+LF1+LF2+LF3 f = (0.116167595984182*(x + 0.791704467391079)*(x + 0.00997156537728427)*(x - 1.00997156537728) - 0.495492470126893*(x + 0.791704467391079)*(x + 0.00997156537728427)*(x - 1.79170446739108) + 0.978004473650812*(x + 0.791704467391079)*(x - 1.00997156537728)*(x - 1.79170446739108) - 0.650217267384311*(x + 0.00997156537728427)*(x - 1.00997156537728)*(x - 1.79170446739108))^2 g=(e^-x)^2 h=(0.0900243711092997*(x + 0.885819298766930)*(x + 0.0740251485476346)*(x - 1.07402514854763) - 0.373399955130276*(x + 0.885819298766930)*(x + 0.0740251485476346)*(x - 1.88581929876693) + 0.802728841958563*(x + 0.885819298766930)*(x - 1.07402514854763)*(x - 1.88581929876693) - 0.571257167284918*(x + 0.0740251485476346)*(x - 1.07402514854763)*(x - 1.88581929876693))^2 u=-3/4*(x + 1)*(x - 2)*x*e^(3/4*(x + 1)*(x - 2)*x) + 1/4*(x + 1)*(x - 2)*x*e^(-1/4*(x + 1)*(x - 2)*x) - 1/6*(x - 1)*(x - 2)*x*e^(1/6*(x - 1)*(x - 2)*x) asw=sum(f,x,(-1/1),(2/1))#Chevy ert=numerical_approx(sum(g,x,-1,2/1))#e^-x cvb=sum(h,x,-1/1,2/1)#Leg plm=sum(u,x,-1,2/1)#Uni l2C=norm(vector([ert-asw])) l2L=norm(vector([ert-cvb])) l2O=norm(vector([ert-plm])) l2E=norm(vector([ert])) linfC=abs(max([asw])) linfL=abs(max([cvb])) linfO=abs(max([plm])) linfE=abs(max([ert])) l2C l2L l2O linfC linfL linfO Chevyshev Uniformly Legendere plot(Legendere) l2L linfL print'The first root is %s'%X1 print'The second root is %s'%X2 print'The third root is %s'%X3 print'The forth root is %s'%X4 Chevyshev plot(Chevyshev) l2C linfC print'The first Chevyshev point is %s'%CV0 print'The second Chevyshev point is %s'%CV1 print'The third Chevyshev point is %s'%CV2 print'The forth Chevyshev point is %s'%CV3 Uniformly plot(Uniformly) l2O linfO
[x == -sqrt(2/35*sqrt(30) + 3/7), x == sqrt(2/35*sqrt(30) + 3/7), x == -sqrt(-2/35*sqrt(30) + 3/7), x == sqrt(-2/35*sqrt(30) + 3/7)] 1.37065555196861 1.39852837567751 sqrt((1/2*(e^2 - 2*e^(1/2) - 3)*e^(-3/2) + 8.54270702105600)^2) 9.913362573024607 9.941235396733509 1/2*abs(e^2 - 2*e^(1/2) - 3)*e^(-3/2) 0.0900243711092997*(x + 0.885819298766930)*(x + 0.0740251485476346)*(x - 1.07402514854763) - 0.373399955130276*(x + 0.885819298766930)*(x + 0.0740251485476346)*(x - 1.88581929876693) + 0.802728841958563*(x + 0.885819298766930)*(x - 1.07402514854763)*(x - 1.88581929876693) - 0.571257167284918*(x + 0.0740251485476346)*(x - 1.07402514854763)*(x - 1.88581929876693) -1/6*(x - 1)*(x - 2)*x*e - 1/2*(x + 1)*(x - 2)*x*e^(-1) + 1/6*(x + 1)*(x - 2)*x*e^(-2) 0.116167595984182*(x + 0.791704467391079)*(x + 0.00997156537728427)*(x - 1.00997156537728) - 0.495492470126893*(x + 0.791704467391079)*(x + 0.00997156537728427)*(x - 1.79170446739108) + 0.978004473650812*(x + 0.791704467391079)*(x - 1.00997156537728)*(x - 1.79170446739108) - 0.650217267384311*(x + 0.00997156537728427)*(x - 1.00997156537728)*(x - 1.79170446739108)
1.39852837567751 9.941235396733509 The first root is -0.861136311594053 The second root is 0.861136311594053 The third root is -0.339981043584856 The forth root is 0.339981043584856 0.0900243711092997*(x + 0.885819298766930)*(x + 0.0740251485476346)*(x - 1.07402514854763) - 0.373399955130276*(x + 0.885819298766930)*(x + 0.0740251485476346)*(x - 1.88581929876693) + 0.802728841958563*(x + 0.885819298766930)*(x - 1.07402514854763)*(x - 1.88581929876693) - 0.571257167284918*(x + 0.0740251485476346)*(x - 1.07402514854763)*(x - 1.88581929876693)
1.37065555196861 9.913362573024607 The first Chevyshev point is 1.88581929876693 The second Chevyshev point is 1.07402514854763 The third Chevyshev point is -0.0740251485476346 The forth Chevyshev point is -0.885819298766930 -1/6*(x - 1)*(x - 2)*x*e - 1/2*(x + 1)*(x - 2)*x*e^(-1) + 1/6*(x + 1)*(x - 2)*x*e^(-2)
sqrt((1/2*(e^2 - 2*e^(1/2) - 3)*e^(-3/2) + 8.54270702105600)^2) 1/2*abs(e^2 - 2*e^(1/2) - 3)*e^(-3/2)
#want 200 equally spaced points from -1 to 2 delta=(2-(-1))/200
points = [-1+i*delta.n(digits=3) for i in range(0,200)]
points
[-1.00, -0.985, -0.970, -0.955, -0.940, -0.925, -0.910, -0.895, -0.880, -0.865, -0.850, -0.835, -0.820, -0.805, -0.790, -0.775, -0.760, -0.745, -0.730, -0.715, -0.700, -0.685, -0.670, -0.655, -0.640, -0.625, -0.610, -0.595, -0.580, -0.565, -0.550, -0.535, -0.520, -0.505, -0.490, -0.475, -0.460, -0.445, -0.430, -0.415, -0.400, -0.385, -0.370, -0.355, -0.340, -0.325, -0.310, -0.295, -0.280, -0.265, -0.250, -0.235, -0.220, -0.205, -0.190, -0.175, -0.160, -0.145, -0.130, -0.115, -0.100, -0.0850, -0.0700, -0.0550, -0.0400, -0.0250, -0.00995, 0.00500, 0.0200, 0.0350, 0.0500, 0.0651, 0.0801, 0.0950, 0.110, 0.125, 0.140, 0.155, 0.170, 0.185, 0.200, 0.215, 0.230, 0.245, 0.260, 0.275, 0.290, 0.305, 0.320, 0.335, 0.350, 0.365, 0.380, 0.395, 0.410, 0.425, 0.440, 0.455, 0.470, 0.485, 0.500, 0.515, 0.530, 0.545, 0.560, 0.575, 0.590, 0.605, 0.620, 0.635, 0.650, 0.665, 0.680, 0.695, 0.710, 0.725, 0.740, 0.755, 0.770, 0.785, 0.800, 0.815, 0.830, 0.845, 0.860, 0.875, 0.890, 0.905, 0.920, 0.935, 0.950, 0.965, 0.980, 0.995, 1.01, 1.03, 1.04, 1.05, 1.07, 1.08, 1.10, 1.11, 1.13, 1.15, 1.16, 1.18, 1.19, 1.21, 1.22, 1.24, 1.25, 1.27, 1.28, 1.30, 1.31, 1.32, 1.34, 1.35, 1.37, 1.39, 1.40, 1.42, 1.43, 1.45, 1.46, 1.48, 1.49, 1.51, 1.52, 1.54, 1.55, 1.56, 1.58, 1.59, 1.61, 1.62, 1.64, 1.66, 1.67, 1.69, 1.70, 1.72, 1.73, 1.75, 1.76, 1.78, 1.79, 1.81, 1.82, 1.83, 1.85, 1.86, 1.88, 1.90, 1.91, 1.93, 1.94, 1.96, 1.97, 1.99]
type(points[1])
<type 'sage.rings.real_mpfr.RealNumber'>
pp=points[1]
pp.n(prec=10)
-0.99
delta.n() abs
0.0150000000000000 <built-in function abs>
L=[3,4,5] L2norm_of_l=sqrt(sum([x^2 for x in L]))
max(L)
5
L2norm_of_l
5*sqrt(2)
norm?
File: /projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/misc/functional.py Signature : norm() Docstring : Returns the norm of "x". For matrices and vectors, this returns the L2-norm. The L2-norm of a vector *v* = (v_1, v_2, ..., v_n), also called the Euclidean norm, is defined as |*v*| = sqrt{sum_{i=1}^n |v_i|^2} where |v_i| is the complex modulus of v_i. The Euclidean norm is often used for determining the distance between two points in two- or three-dimensional space. For complex numbers, the function returns the field norm. If c = a + bi is a complex number, then the norm of c is defined as the product of c and its complex conjugate norm(c) = norm(a + bi) = c * overline{c} = a^2 + b^2. The norm of a complex number is different from its absolute value. The absolute value of a complex number is defined to be the square root of its norm. A typical use of the complex norm is in the integral domain ZZ[i] of Gaussian integers, where the norm of each Gaussian integer c = a + bi is defined as its complex norm. See also: * "sage.matrix.matrix2.Matrix.norm()" * "sage.modules.free_module_element.FreeModuleElement.norm()" * "sage.rings.complex_double.ComplexDoubleElement.norm()" * "sage.rings.complex_number.ComplexNumber.norm()" * "sage.symbolic.expression.Expression.norm()" EXAMPLES: The norm of vectors: sage: z = 1 + 2*I sage: norm(vector([z])) sqrt(5) sage: v = vector([-1,2,3]) sage: norm(v) sqrt(14) sage: _ = var("a b c d", domain='real') sage: v = vector([a, b, c, d]) sage: norm(v) sqrt(a^2 + b^2 + c^2 + d^2) The norm of matrices: sage: z = 1 + 2*I sage: norm(matrix([[z]])) 2.23606797749979 sage: M = matrix(ZZ, [[1,2,4,3], [-1,0,3,-10]]) sage: norm(M) # abs tol 1e-14 10.690331129154467 sage: norm(CDF(z)) 5.0 sage: norm(CC(z)) 5.00000000000000 The norm of complex numbers: sage: z = 2 - 3*I sage: norm(z) 13 sage: a = randint(-10^10, 100^10) sage: b = randint(-10^10, 100^10) sage: z = a + b*I sage: bool(norm(z) == a^2 + b^2) True The complex norm of symbolic expressions: sage: a, b, c = var("a, b, c") sage: assume((a, 'real'), (b, 'real'), (c, 'real')) sage: z = a + b*I sage: bool(norm(z).simplify() == a^2 + b^2) True sage: norm(a + b).simplify() a^2 + 2*a*b + b^2 sage: v = vector([a, b, c]) sage: bool(norm(v).simplify() == sqrt(a^2 + b^2 + c^2)) True sage: forget()
solns=solve(x^2==1,x)
type(solns)
<class 'sage.structure.sequence.Sequence_generic'>
solns
[x == -1, x == 1]
list(solns)
[x == -1, x == 1]
solns[0]
x == -1
type(solns[0])
<type 'sage.symbolic.expression.Expression'>
solns[0].rhs()
-1
[solns[x].rhs() for x in range(0,len(solns))]
[-1, 1]