ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 12 Apr 2018 04:48:11 +0200What is the significance of "." other than in a file name?https://ask.sagemath.org/question/41937/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.Mon, 09 Apr 2018 04:36:59 +0200https://ask.sagemath.org/question/41937/what-is-the-significance-of-other-than-in-a-file-name/Answer by slelievre for <p>I continue to stumble over the "." in structures other than in filenames. For example,</p>
<p>Dr(t) = sol[0].rhs</p>
<p>where D is the first derivative of r and "sol" has been defined as the Sagemath function "solve" in lines before this one.</p>
https://ask.sagemath.org/question/41937/what-is-the-significance-of-other-than-in-a-file-name/?answer=41944#post-id-41944This 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()`.
Follow a Python tutorial or a Sage tutorial to learn more.
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)))`.
Mon, 09 Apr 2018 09:31:53 +0200https://ask.sagemath.org/question/41937/what-is-the-significance-of-other-than-in-a-file-name/?answer=41944#post-id-41944Comment by wxman112 for <p>This is the way to apply a method to an object.</p>
<p>Very often, instead of <code>f(x)</code>, the notation in Python, and therefore in SageMath,
will be <code>x.f()</code>.</p>
<p>Follow a Python tutorial or a Sage tutorial to learn more.</p>
<p>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 <code>sol[0].rhs()</code>.</p>
<p>This is very efficient, especially when you need to apply several operations in a row.</p>
<p>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.</p>
<p>You can do <code>g.adjacency_matrix().charpoly().factor()</code>, which maybe better
shows the sequence of operations, and avoids nested parenthesis, if you compare
to writing <code>factor(charpoly(adjacency_matrix(g)))</code>.</p>
https://ask.sagemath.org/question/41937/what-is-the-significance-of-other-than-in-a-file-name/?comment=41989#post-id-41989THANK 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.Thu, 12 Apr 2018 04:48:11 +0200https://ask.sagemath.org/question/41937/what-is-the-significance-of-other-than-in-a-file-name/?comment=41989#post-id-41989