# What is the significance of "." other than in a file name?

I continue to stumble over the "." in structures other than in filenames. For example,

Dr(t) = sol[0].rhs

where D is the first derivative of r and "sol" has been defined as the Sagemath function "solve" in lines before this one.

edit retag close merge delete

Sort by » oldest newest most voted

This is the way to apply a method to an object.

Very often, instead of f(x), the notation in Python, and therefore in SageMath, will be x.f().

In the example you mention, sol[0] is an equation, and to extract its right-hand side, you apply the method "rhs" to it, by doing sol[0].rhs().

This is very efficient, especially when you need to apply several operations in a row.

For example, starting from a graph, say you want to compute its adjacency matrix, then get the characteristic polynomial of this matrix, then factor this polynomial.

You can do g.adjacency_matrix().charpoly().factor(), which maybe better shows the sequence of operations, and avoids nested parenthesis, if you compare to writing factor(charpoly(adjacency_matrix(g))).

more

THANK YOU, THANK YOU!! I'm just starting out using SageMath. Even at this early stage it's been a real time-saver. There are some structures, however, that are confusing and trying to find answers can be difficult. This one is a case in point. I scrolled through the Python codes but I can see I need to invest time in the tutorial(s). Thanks again for pointing towards the resources I'll need.

( 2018-04-12 04:48:11 +0100 )edit