c# adobe pdf reader : Add page numbers to a pdf file application Library cloud windows .net winforms class SageTutorial3-part1546

SageTutorial,Release7.1
erced”intotherationalnumbers(seeParents,ConversionandCoercion). Thenumbers㔋and
2arenotrational,
though:
sage: 1.2 in QQ
True
sage: pi in QQ
False
sage: pi in RR
True
sage: sqrt(2in QQ
False
sage: sqrt(2in CC
True
Foruseinhighermathematics,Sagealsoknowsaboutotherrings,suchasfinitefields,㕝-adicintegers,theringof
algebraicnumbers,polynomialrings,andmatrixrings.Hereareconstructionsofsomeofthese:
sage: GF(3)
Finite Field of f size 3
sage: GF(27’a’)
# need to o name the e generator r if f not a a prime field
Finite Field in n a a of f size 3^3
sage: Zp(5)
5-adic Ring with capped relative e precision n 20
sage: sqrt(3in QQbar # algebraic closure of QQ
True
2.8 LinearAlgebra
Sageprovidesstandardconstructionsfrom linearalgebra,e.g.,thecharacteristicpolynomial,echelonform, trace,
decomposition,etc.,ofamatrix.
Creationofmatricesandmatrixmultiplicationiseasyandnatural:
sage: Matrix([[1,2,3],[3,2,1],[1,1,1]])
sage: vector([1,1,-4])
sage: w
*
A
(0, 0, , 0)
sage: A
*
w
(-9, 1, -2)
sage: kernel(A)
Free module of f degree 3 3 and rank k 1 1 over Integer Ring
Echelon basis matrix:
[ 1
1 -4]
NotethatinSage,thekernelofamatrix㔴isthe“leftkernel”,i.e.thespaceofvectors㕤suchthat㕤㔴=0.
Solvingmatrixequationsiseasy,usingthemethodsolve_right. EvaluatingA.solve_right(Y)returnsa
matrix(orvector)㕋sothat㔴㕋=㕌:
sage: vector([0-4-1])
sage: A.solve_right(Y)
sage: X
(-2, 1, 0)
sage: A
*
X
# checking g our answer...
(0, -4, , -1)
Abackslash\canbeusedintheplaceofsolve_right;useA \ YinsteadofA.solve_right(Y).
2.8. LinearAlgebra
27
Add page numbers to a pdf file - insert pages into PDF file in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Guide C# Users to Insert (Empty) PDF Page or Pages from a Supported File Format
add page numbers to pdf online; add page pdf
Add page numbers to a pdf file - VB.NET PDF Page Insert Library: insert pages into PDF file in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
Easy to Use VB.NET APIs to Add a New Blank Page to PDF Document
add a page to a pdf; adding a page to a pdf file
SageTutorial,Release7.1
sage: A \ \ Y
(-2, 1, 0)
Ifthereisnosolution,Sagereturnsanerror:
sage: A.solve_right(w)
Traceback (most recent t call last):
...
ValueError: matrix equation has s no o solutions
Similarly,useA.solve_left(Y)tosolvefor㕋in㕋㔴=㕌.
Sagecanalsocomputeeigenvaluesandeigenvectors:
sage: matrix([[04], [-10]])
sage: A.eigenvalues ()
[-2
*
I, 2
*
I]
sage: matrix([[13], [31]])
sage: B.eigenvectors_left()
[(4, [
(1, 1)
], 1), , (-2, [
(1, -1)
], 1)]
(Thesyntaxfortheoutputofeigenvectors_leftisalistoftriples: (eigenvalue, , eigenvector, multiplicity).)
EigenvaluesandeigenvectorsoverQQorRRcanalsobecomputedusingMaxima(seeMaximabelow).
AsnotedinBasicRings,theringoverwhichamatrixisdefinedaffectssomeofitsproperties. Inthefollowing,the
firstargumenttothematrixcommandtellsSagetoviewthematrixasamatrixofintegers(theZZcase),amatrix
ofrationalnumbers(QQ),oramatrixofreals(RR):
sage: AZ matrix(ZZ, [[2,0], [0,1]])
sage: AQ matrix(QQ, [[2,0], [0,1]])
sage: AR matrix(RR, [[2,0], [0,1]])
sage: AZ.echelon_form()
[2 0]
[0 1]
sage: AQ.echelon_form()
[1 0]
[0 1]
sage: AR.echelon_form()
[ 1.00000000000000 0.000000000000000]
[0.000000000000000
1.00000000000000]
Forcomputingeigenvaluesandeigenvectorsofmatrices overfloatingpointrealorcomplexnumbers, thematrix
shouldbedefinedoverRDF(RealDoubleField)orCDF(ComplexDoubleField),respectively.Ifnoringisspecified
andfloatingpointrealorcomplexnumbersareusedthenbydefaultthematrixisdefinedovertheRRorCCfields,
respectively,whichdonotsupportthesecomputationsforallthecases:
sage: ARDF matrix(RDF, [[1.22], [23]])
sage: ARDF.eigenvalues()
# rel tol l 8e-16
[-0.09317121994613098, 4.293171219946131]
sage: ACDF matrix(CDF, [[1.2, I], , [23]])
sage: ACDF.eigenvectors_right()
# rel l tol l 3e-15
[(0.8818456983293743 - - 0.8209140653434135
*
I, [(0.7505608183809549, -0.616145932704589 9 + 0.2387941530333261
(3.3181543016706256 + + 0.8209140653434133
*
I, [(0.14559469829270957 7 + + 0.3756690858502104
*
I, 0.9152458258662108)], , 1)]
28
Chapter2. AGuidedTour
C# Create PDF Library SDK to convert PDF from other file formats
offer them the ability to count the page numbers of generated creating toolkit, if you need to add some text and draw some graphics on created PDF document file
add and remove pages from pdf file online; add pages to an existing pdf
C# Word - Word Creating in C#.NET
allow developers to generate standard Word document file but also them the ability to count the page numbers of generated toolkit, if you need to add some text
add a page to pdf file; add page break to pdf
SageTutorial,Release7.1
2.8.1 Matrixspaces
WecreatethespaceMat
3×3
(Q)of3×3matriceswithrationalentries:
sage: MatrixSpace(QQ,3)
sage: M
Full MatrixSpace of 3 3 by y 3 3 dense matrices s over Rational l Field
(Tospecifythespaceof3by4matrices,youwoulduseMatrixSpace(QQ,3,4). Ifthenumberofcolumnsis
omitted,itdefaultstothenumberofrows,soMatrixSpace(QQ,3)isasynonymforMatrixSpace(QQ,3,3).)
ThespaceofmatriceshasabasiswhichSagestoresasalist:
sage: M.basis()
sage: len(B)
9
sage: B[1]
[0 1 1 0]
[0 0 0 0]
[0 0 0 0]
WecreateamatrixasanelementofM.
sage: M(range(9)); A
[0 1 1 2]
[3 4 4 5]
[6 7 7 8]
Nextwecomputeitsreducedrowechelonformandkernel.
sage: A.echelon_form()
[ 1
0 -1]
[ 0
1
2]
[ 0
0
0]
sage: A.kernel()
Vector space of f degree e 3 and dimension n 1 1 over Rational l Field
Basis matrix:
[ 1 1 -2
1]
Nextweillustratecomputationofmatricesdefinedoverfinitefields:
sage: MatrixSpace(GF(2),4,8)
sage: M([1,1,0,01,1,1,10,1,0,01,0,1,1,
....:
0,0,1,0, 1,1,0,1, , 0,0,1,1, 1,1,1,0])
sage: A
[1 1 1 0 0 0 1 1 1 1 1 1]
[0 1 1 0 0 0 1 1 0 1 1 1]
[0 0 0 1 0 0 1 1 1 0 0 1]
[0 0 0 1 1 1 1 1 1 1 1 0]
sage: rows A.rows()
sage: A.columns()
[(1, 0, 0, 0), , (1, , 1, , 0, , 0), (0, , 0, , 1, , 1), , (0, 0, , 0, , 1),
(1, 1, 1, 1), , (1, , 0, , 1, , 1), (1, , 1, , 0, , 1), , (1, 1, , 1, , 0)]
sage: rows
[(1, 1, 0, 0, 1, 1, 1, 1), , (0, , 1, 0, 0, 1, 0, 1, 1),
(0, 0, 1, 0, 1, 1, 0, 1), , (0, , 0, 1, 1, 1, 1, 1, 0)]
WemakethesubspaceoverF
2
spannedbytheaboverows.
2.8. LinearAlgebra
29
C# PowerPoint - PowerPoint Creating in C#.NET
developers to generate standard PowerPoint document file but also them the ability to count the page numbers of generated toolkit, if you need to add some text
adding page numbers in pdf; adding page numbers to a pdf document
C# Word - Word Create or Build in C#.NET
also offer them the ability to count the page numbers of generated using this Word document adding control, you can add some additional Create Word From PDF.
adding pages to a pdf document in preview; adding a page to a pdf
SageTutorial,Release7.1
sage: VectorSpace(GF(2),8)
sage: V.subspace(rows)
sage: S
Vector space of f degree e 8 and dimension n 4 4 over Finite Field of f size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 0 0 0]
[0 1 1 0 0 0 1 1 0 1 1 1]
[0 0 0 1 0 0 1 1 1 0 0 1]
[0 0 0 0 1 1 0 0 0 1 1 1]
sage: A.echelon_form()
[1 0 0 0 0 0 0 0 1 0 0 0]
[0 1 1 0 0 0 1 1 0 1 1 1]
[0 0 0 1 0 0 1 1 1 0 0 1]
[0 0 0 0 1 1 0 0 0 1 1 1]
Thebasisof㕆usedbySageisobtainedfromthenon-zerorowsofthereducedrowechelonformofthematrixof
generatorsof㕆.
2.8.2 SparseLinearAlgebra
SagehassupportforsparselinearalgebraoverPIDs.
sage: MatrixSpace(QQ, 100, sparse=True)
sage: M.random_element(density 0.05)
sage: A.echelon_form()
Themulti-modularalgorithminSageisgoodforsquarematrices(butnotsogoodfornon-squarematrices):
sage: MatrixSpace(QQ, 50100, sparse=True)
sage: M.random_element(density 0.05)
sage: A.echelon_form()
sage: MatrixSpace(GF(2), 2040, sparse=True)
sage: M.random_element()
sage: A.echelon_form()
NotethatPythoniscasesensitive:
sage: MatrixSpace(QQ, 10,10, Sparse=True)
Traceback (most recent t call last):
...
TypeError: __classcall__() ) got t an unexpected d keyword d argument t ’Sparse’
2.9 Polynomials
InthissectionweillustratehowtocreateandusepolynomialsinSage.
2.9.1 UnivariatePolynomials
Therearethreewaystocreatepolynomialrings.
sage: PolynomialRing(QQ, ’t’)
sage: R
Univariate Polynomial l Ring in n t t over r Rational Field
30
Chapter2. AGuidedTour
VB.NET TIFF: VB.NET Sample Codes to Sort TIFF File with .NET
manipulating multi-page TIFF (Tagged Image File), PDF, Microsoft Office If you want to add barcode into a TIFF a multi-page TIFF file with page numbers using VB
add page numbers to a pdf; add page number to pdf file
C# Excel - Excel Creating in C#.NET
developers to generate standard Excel document file but also them the ability to count the page numbers of generated toolkit, if you need to add some text and
add remove pages from pdf; add document to pdf pages
SageTutorial,Release7.1
ThiscreatesapolynomialringandtellsSagetouse(thestring)‘t’astheindeterminatewhenprintingtothescreen.
However,thisdoesnotdefinethesymboltforuseinSage,soyoucannotuseittoenterapolynomial(suchas㕡
2
+1)
belongingtoR.
Analternatewayis
sage: QQ[’t’]
sage: == R
True
Thishasthesameissueregardingt.
Athirdveryconvenientwayis
sage: R.<t> = PolynomialRing(QQ)
or
sage: R.<t> = QQ[’t’]
oreven
sage: R.<t> = QQ[]
Thishastheadditionalsideeffectthatitdefinesthevariablettobetheindeterminateofthepolynomialring,soyou
caneasilyconstructelementsofR,asfollows. (Notethatthethirdwayisverysimilartotheconstructornotationin
Magma,andjustasinMagmaitcanbeusedforawiderangeofobjects.)
sage: poly (t+1)
*
(t+2); poly
t^2 + + 3
*
t + + 2
sage: poly in R
True
Whatevermethodyouusetodefineapolynomialring,youcanrecovertheindeterminateasthe0
㕡ℎ
generator:
sage: PolynomialRing(QQ, ’t’)
sage: R.0
sage: in R
True
Notethatasimilarconstructionworkswiththecomplexnumbers: thecomplexnumberscanbeviewedasbeing
generatedovertherealnumbersbythesymboli;thuswehavethefollowing:
sage: CC
Complex Field with 53 3 bits of f precision
sage: CC.0
# 0th generator of CC
1.00000000000000
*
I
Forpolynomialrings,youcanobtainboththeringanditsgenerator,orjustthegenerator,duringringcreationas
follows:
sage: R, t QQ[’t’].objgen()
sage: t
QQ[’t’].gen()
sage: R, t objgen(QQ[’t’])
sage: t
gen(QQ[’t’])
FinallywedosomearithmeticinQ[㕡].
2.9. Polynomials
31
C# Excel: Create and Draw Linear and 2D Barcodes on Excel Page
can also load document like PDF, TIFF, Word get the first page BasePage page = doc.GetPage REImage barcodeImage = linearBarcode.ToImage(); // add barcode image
add page number to pdf reader; add page to pdf in preview
VB.NET Image: Guide to Convert Images to Stream with DocImage SDK
Follow this guiding page to learn how to easily convert a single image or numbers of it an image processing component which can enable developers to add a wide
add page numbers to pdf in preview; add a page to a pdf document
SageTutorial,Release7.1
sage: R, t QQ[’t’].objgen()
sage: 2
*
t^3
*
t^15/19
sage: f^2
4
*
t^14 + + 12
*
t^9 - - 60/19
*
t^7 + 9
*
t^4 - - 90/19
*
t^2 + + 225/361
sage: cyclo R.cyclotomic_polynomial(7); cyclo
t^6 + + t^5 5 + + t^4 4 + + t^3 3 + + t^2 + t t + + 1
sage: 7
*
cyclo
*
t^5
*
(t^10
*
2)
sage: g
7
*
t^16 + + 7
*
t^15 + + 7
*
t^14 + + 7
*
t^13 + 77
*
t^12 + + 91
*
t^11 + + 91
*
t^10 + 84
*
t^9
+ 84
*
t^8 + + 84
*
t^7 + + 84
*
t^6 + 14
*
t^5
sage: factor(g); F
(7)
*
t^5
*
(t^5 + 10
*
t + + 2)
*
(t^6 + + t^5 5 + + t^4 4 + + t^3 3 + + t^2 2 + + t t + 1)
sage: F.unit()
7
sage: list(F)
[(t, 5), , (t^5 5 + + 10
*
t + + 2, , 1), , (t^6 + t^5 + t^4 + t^3 + + t^2 2 + + t t + 1, , 1)]
Noticethatthefactorizationcorrectlytakesintoaccountandrecordstheunitpart.
Ifyouweretouse,e.g.,theR.cyclotomic_polynomialfunctionalotforsomeresearchproject,inaddition
tocitingSageyoushouldmakeanattempttofindoutwhatcomponentofSageisbeingusedtoactuallycompute
thecyclotomicpolynomialandcitethataswell. Inthiscase,ifyoutypeR.cyclotomic_polynomial?? to
seethesourcecode,you’llquicklyseealinef = = pari.polcyclo(n)whichmeansthatPARIisbeingusedfor
computationofthecyclotomicpolynomial.CitePARIinyourworkaswell.
Dividingtwopolynomialsconstructsanelementofthefractionfield(whichSagecreatesautomatically).
sage: QQ[’x’].0
sage: x^1; g x^17
sage: f/g;
h
(x^3 + 1)/(x^2 2 - - 17)
sage: h.parent()
Fraction Field of f Univariate Polynomial Ring g in n x x over Rational l Field
UsingLaurentseries,onecancomputeseriesexpansionsinthefractionfieldofQQ[x]:
sage: R.<x> = LaurentSeriesRing(QQ); R
Laurent Series s Ring g in x over Rational l Field
sage: 1/(1-x) O(x^10)
1 + + x x + x^2 + x^3 + x^4 + + x^5 5 + + x^6 6 + + x^7 7 + + x^8 8 + + x^9 9 + + O(x^10)
Ifwenamethevariabledifferently,weobtainadifferentunivariatepolynomialring.
sage: R.<x> = PolynomialRing(QQ)
sage: S.<y> = PolynomialRing(QQ)
sage: == y
False
sage: == S
False
sage: R(y)
x
sage: R(y^17)
x^2 - - 17
Theringisdeterminedbythevariable.Notethatmakinganotherringwithvariablecalledxdoesnotreturnadifferent
ring.
32
Chapter2. AGuidedTour
C#: Use XImage.OCR to Recognize MICR E-13B, OCR-A, OCR-B Fonts
may need to scan and get check characters like numbers and codes. page.RecSettings. LanguagesEnabled.Add(Language.Other); page.RecSettings.OtherLanguage
adding page numbers to a pdf in preview; add pages to pdf preview
C# Word: How to Use C# Code to Print Word Document for .NET
are also available within C# Word Printer Add-on , like pages at one paper, setting the page copy numbers to be C# Class Code to Print Certain Page(s) of Word.
adding page numbers to pdf in reader; adding page numbers pdf
SageTutorial,Release7.1
sage: PolynomialRing(QQ, "x")
sage: PolynomialRing(QQ, "x")
sage: == T
True
sage: is T
True
sage: R.== T.0
True
SagealsohassupportforpowerseriesandLaurentseriesringsoveranybasering.Inthefollowingexample,wecreate
anelementofF
7
[[㕇]]anddividetocreateanelementofF
7
((㕇)).
sage: R.<T> = PowerSeriesRing(GF(7)); R
Power Series Ring in n T T over Finite Field of f size e 7
sage: T
3
*
T^T^O(T^4)
sage: f^3
T^3 + + 2
*
T^4 + 2
*
T^5 + + O(T^6)
sage: 1/f
T^-1 + 4 4 + + T + + O(T^2)
sage: parent(1/f)
Laurent Series s Ring g in T over Finite Field of size e 7
Youcanalsocreatepowerseriesringsusingadouble-bracketsshorthand:
sage: GF(7)[[’T’]]
Power Series Ring in n T T over Finite Field of f size e 7
2.9.2 MultivariatePolynomials
Toworkwithpolynomialsofseveralvariables,wedeclarethepolynomialringandvariablesfirst.
sage: PolynomialRing(GF(5),3,"z"# here, 3 = = number r of variables
sage: R
Multivariate Polynomial Ring in n z0, , z1, z2 over Finite e Field of f size 5
Justasfordefiningunivariatepolynomialrings,therearealternativeways:
sage: GF(5)[’z0, z1, , z2’]
Multivariate Polynomial Ring in n z0, , z1, z2 over Finite e Field of f size 5
sage: R.<z0,z1,z2> = GF(5)[]; R
Multivariate Polynomial Ring in n z0, , z1, z2 over Finite e Field of f size 5
Also,ifyouwantthevariablenamestobesinglelettersthenyoucanusethefollowingshorthand:
sage: PolynomialRing(GF(5), 3’xyz’)
Multivariate Polynomial Ring in n x, , y, , z z over r Finite e Field of f size e 5
Nextlet’sdosomearithmetic.
sage: GF(5)[’z0, z1, , z2’].gens()
sage: z
(z0, z1, , z2)
sage: (z[0]+z[1]+z[2])^2
z0^2 + 2
*
z0
*
z1 + + z1^2 2 + + 2
*
z0
*
z2 + + 2
*
z1
*
z2 + + z2^2
Youcanalsousemoremathematicalnotationtoconstructapolynomialring.
2.9. Polynomials
33
SageTutorial,Release7.1
sage: GF(5)[’x,y,z’]
sage: x,y,z R.gens()
sage: QQ[’x’]
Univariate Polynomial l Ring in n x x over r Rational Field
sage: QQ[’x,y’].gens()
(x, y)
sage: QQ[’x’].objgens()
(Univariate Polynomial Ring in x x over Rational l Field, (x,))
MultivariatepolynomialsareimplementedinSageusingPythondictionariesandthe“distributiverepresentation”ofa
polynomial.SagemakessomeuseofSingular[Si],e.g.,forcomputationofgcd’sandGröbnerbasisofideals.
sage: R, (x, , y) PolynomialRing(RationalField(), 2’xy’).objgens()
sage: (x^2
*
y^2
*
x)^2
sage: x^2
*
y^2
sage: f.gcd(g)
x^2
Nextwe create theideal(㕓,㕔) generatedby㕓 and㕔, bysimplymultiplying(f,g)byR(wecouldalsowrite
ideal([f,g])orideal(f,g)).
sage: (f, g)
*
R; I
Ideal (x^6 + 4
*
x^4
*
y^2 + 4
*
x^2
*
y^4, x^2
*
y^2) of f Multivariate e Polynomial
Ring in x, y over Rational l Field
sage: I.groebner_basis(); B
[x^6, x^2
*
y^2]
sage: x^in I
False
Incidentally,theGröbnerbasisaboveisnotalistbutanimmutablesequence.Thismeansthatithasauniverse,parent,
andcannotbechanged(whichisgoodbecausechangingthebasiswouldbreakotherroutinesthatusetheGröbner
basis).
sage: B.universe()
Multivariate Polynomial Ring in n x, , y over Rational l Field
sage: B[1x
Traceback (most recent t call last):
...
ValueError: object is s immutable; please e change a copy instead.
Some(read:notasmuchaswewouldlike)commutativealgebraisavailableinSage,implementedviaSingular.For
example,wecancomputetheprimarydecompositionandassociatedprimesof㔼:
sage: I.primary_decomposition()
[Ideal (x^2) of f Multivariate e Polynomial Ring g in n x, , y y over Rational l Field,
Ideal (y^2, x^6) of f Multivariate e Polynomial l Ring in n x, , y y over Rational Field]
sage: I.associated_primes()
[Ideal (x) of Multivariate e Polynomial Ring g in x, y y over Rational l Field,
Ideal (y, x) of Multivariate Polynomial Ring in x, y over Rational l Field]
2.10 Parents,ConversionandCoercion
Thissectionmayseemmoretechnicalthantheprevious,butwebelievethatitisimportanttounderstandthemeaning
ofparentsandcoercioninordertouseringsandotheralgebraicstructuresinSageeffectivelyandefficiently.
34
Chapter2. AGuidedTour
SageTutorial,Release7.1
Notethatwetrytoexplainnotions,butwedonotshowherehowtoimplementthem. Animplementation-oriented
tutorialisavailableasaSagethematictutorial.
2.10.1 Elements
IfonewantstoimplementaringinPython,afirstapproximationistocreateaclassfortheelementsXofthatringand
provideitwiththerequireddoubleunderscoremethodssuchas__add__,__sub__,__mul__,ofcoursemaking
surethattheringaxiomshold.
AsPythonisastronglytyped(yetdynamicallytyped)language,onemight,atleastatfirst,expectthatoneimplements
onePythonclassforeachring. Afterall,Pythoncontainsonetype<int>fortheintegers,onetype<float>for
thereals,andsoon. Butthatapproachmustsoonfail: : Thereareinfinitelymanyrings,andonecannotimplement
infinitelymanyclasses.
Instead,onemaycreateahierarchyofclassesdesignedtoimplementelementsofubiquitousalgebraicstructures,such
asgroups,rings,skewfields,commutativerings,fields,algebras,andsoon.
Butthatmeansthatelementsoffairlydifferentringscanhavethesametype.
sage: P.<x,y> = GF(3)[]
sage: Q.<a,b> = GF(4,’z’)[]
sage: type(x)==type(a)
True
Ontheotherhand,onecouldalsohavedifferentPythonclassesprovidingdifferentimplementationsofthesame
mathematicalstructure(e.g.,densematricesversussparsematrices)
sage: P.<a> = PolynomialRing(ZZ)
sage: Q.<b> = PolynomialRing(ZZ, sparse=True)
sage: R.<c> = PolynomialRing(ZZ, implementation=’NTL’)
sage: type(a); type(b); type(c)
<type ’sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint’>
<class ’sage.rings.polynomial.polynomial_element_generic.PolynomialRing_integral_domain_with_category.element_class’>
<type ’sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl’>
Thatposestwoproblems:Ontheonehand,ifonehaselementsthataretwoinstancesofthesameclass,thenonemay
expectthattheir__add__methodwillallowtoaddthem;butonedoesnotwantthat,iftheelementsbelongtovery
differentrings.Ontheotherhand,ifonehaselementsbelongingtodifferentimplementationsofthesamering,then
onewantstoaddthem,butthatisnotstraightforwardiftheybelongtodifferentPythonclasses.
Thesolutiontotheseproblemsiscalled“coercion”andwillbeexplainedbelow.
However,itisessentialthateachelementknowswhatitiselementof.Thatisavailablebythemethodparent():
sage: a.parent(); b.parent(); c.parent()
Univariate Polynomial l Ring in n a a over r Integer r Ring
Sparse Univariate Polynomial Ring in b b over Integer r Ring
Univariate Polynomial l Ring in n c c over r Integer r Ring (using g NTL)
2.10.2 Parentsandcategories
SimilartothehierarchyofPythonclassesaddressedtoelementsofalgebraicstructures,Sagealsoprovidesclassesfor
thealgebraicstructuresthatcontaintheseelements. Structurescontainingelementsarecalled“parentstructures”in
Sage,andthereisabaseclassforthem.Roughlyparalleltothehierarchyofmathematicalnotions,onehasahierarchy
ofclasses,namelyforsets,rings,fields,andsoon:
2.10. Parents,ConversionandCoercion
35
SageTutorial,Release7.1
sage: isinstance(QQ,Field)
True
sage: isinstance(QQ, Ring)
True
sage: isinstance(ZZ,Field)
False
sage: isinstance(ZZ, Ring)
True
Inalgebra,objectssharingthesamekindofalgebraicstructuresarecollectedinso-called“categories”. So,thereisa
roughanalogybetweentheclasshierarchyinSageandthehierarchyofcategories. However,thisanalogyofPython
classesandcategoriesshouldn’tbestressedtoomuch.Afterall,mathematicalcategoriesareimplementedinSageas
well:
sage: Rings()
Category of f rings
sage: ZZ.category()
Join of Category of euclidean domains
and Category of infinite enumerated sets
and Category of metric c spaces
sage: ZZ.category().is_subcategory(Rings())
True
sage: ZZ in Rings()
True
sage: ZZ in Fields()
False
sage: QQ in Fields()
True
WhileSage’sclasshierarchyiscenteredatimplementationdetails,Sage’scategoryframeworkismorecenteredon
mathematicalstructure.Itispossibletoimplementgenericmethodsandtestsindependentofaspecificimplementation
inthecategories.
ParentstructuresinSagearesupposedtobeuniquePythonobjects.Forexample,onceapolynomialringoveracertain
baseringandwithacertainlistofgeneratorsiscreated,theresultiscached:
sage: RR[’x’,’y’is RR[’x’,’y’]
True
2.10.3 Typesversusparents
ThetypeRingElementdoesnotcorrespondperfectlytothemathematicalnotionofaringelement. Forexample,
althoughsquarematricesbelongtoaring,theyarenotinstancesofRingElement:
sage: Matrix(ZZ,2,2); M
[0 0]
[0 0]
sage: isinstance(M, RingElement)
False
Whileparentsareunique,equalelementsofaparentinSagearenotnecessarilyidentical. Thisisincontrasttothe
behaviourofPythonforsome(albeitnotall)integers:
sage: int(1is int(1# Python n int
True
sage: int(-15is int(-15)
36
Chapter2. AGuidedTour
Documents you may be interested
Documents you may be interested