Lists, Tuples, Strings, Dictionaries and Built-in Functions

Lists, Tuples, Strings, Dictionaries and Built-in Functions
According to python programming, it is possible to load various programs that are in various different pages into a sage. While making various data types in the sage, every data object is defined and its functions illustrated in the sage. Python programming is of significance importance to most programmers because there is a wide range of basic built in types. The sage library helps in adding many more of the built in types. The illustration below explains how the build in types in python works.
sage: s = “sage”; type(s)
<type ‘str’>
sage: s = ‘sage’; type(s) # you can use either single or double quotes
<type ‘str’>
sage: s = [1,2,3,4]; type(s)
<type ‘list’>
sage: s = (1,2,3,4); type(s)
<type ‘tuple’>
sage: s = int(2006); type(s)
<type ‘int’>
sage: s = float(2006); type(s)
<type ‘float’>
According to the above sage, there is a possibility of adding many more other features like the vectors space. The illustration below demonstrates on how to go.
sage: V = VectorSpace(QQ, 1000000); V
Vector space of dimension 1000000 over Rational Field
sage: type(V)
<class ‘sage.modules.free_module.FreeModule_ambient_field_with_category’>
Aprogrammer also ought to note that in the case of mathematical notations, the usual functional notational is supported. This is because the most of the mathematical expressions ouhght to lok confusing wjile using the object oriented notations. The following examples illustrate how to perform this operation in python programming.
sage: n = 2; n.sqrt()
sqrt(2)
sage: sqrt(2)
sqrt(2)
sage: V = VectorSpace(QQ,2)
sage: V.basis()
[
(1, 0),
(0, 1)
]
sage: basis(V)
[
(1, 0),
(0, 1)
]
sage: M = MatrixSpace(GF(7), 2); M
Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 7
sage: A = M([1,2,3,4]); A
[1 2]
[3 4]
sage: A.charpoly(‘x’)
x^2 + 2*x + 5
sage: charpoly(A, ‘x’)
x^2 + 2*x + 5
Examples on Lists, Tuples.
In most of the list data types, they tend to store the elements that contain the arbitrary data. The difference between most of the algebraic expressions in python programming with the one included in most of the standard computer programming is that the lists in python are normally started from 0. For example,
sage: v = [2, 3, 5, ‘x’, SymmetricGroup(3)]; v
[2, 3, 5, ‘x’, Symmetric group of order 3! as a permutation group]
sage: type(v)
<type ‘list’>
sage: v[0]
2
sage: v[2]
5
While indexing the values in to a list, the programmers are advised to make sure that the index should not be anything with a python Python int!. However, everything else with a –index-method tends to work well. For example,
sage: v = [1,2,3]
sage: v[2]
3
sage: n = 2 # SAGE Integer
sage: v[n] # Perfectly OK!
3
sage: v[int(n)] # Also OK.
3
Dictionaries
In pyton programming, a dictionary is anything thatb has a hashable objects. Most of this objects includes the strings, tuples and numbers. The following illustaration demonstrates how the operation of a dictionary.For example,
sage: d = {1:5, ‘sage’:17, ZZ:GF(7)}
sage: type(d)
<type ‘dict’>
sage: d.keys()
[1, ‘sage’, Integer Ring]
sage: d[‘sage’]
17
sage: d[ZZ]
Finite Field of size 7
sage: d[1]
5
Sequences
They are one of the types that most of the programmers use in the list-oriented Sage. Sequences are not built-in Python type. However, by default, the sequence is mutable. The following example illustrates how the sequence works in a pythin program operation.
sage: v = Sequence([1,2,3,4/5])
sage: v
[1, 2, 3, 4/5]
sage: type(v)
<class ‘sage.structure.sequence.Sequence_generic’>
sage: type(v[1])
<type ‘sage.rings.rational.Rational’>
sage: v.universe()
Rational Field
sage: v.is_immutable()
False
sage: v.set_immutable()
sage: v[0] = 3
Traceback (most recent call last):

ValueError: object is immutable; please change a copy instead.

Latest Assignments