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.Fri, 17 Mar 2017 00:38:37 +0100Echo input in output.https://ask.sagemath.org/question/36945/echo-input-in-output/I'm trying to use sage for documentation purposes, and I'm looking for a way to do some of the following.
Enter an equation
`f(x) = 2x`
Input `f(2)` or something close
and get back `f(2) = 4` instead of just 4.
I'm also looking for a way to input
`f(x) = 2x^2`
Input diff(f(x),x), or an equivalent command and get
`f'(x) = 4x` or `d(f(x)/dx = 4x`.
And an icing on the cake would being able to input `integrate(f(x)dx)`
and return `∫f(x)dx => 4x + 15 + c`
Bassically, if there is a way to the output more verbose, I'd love to know how.
I just started using Sage and I love it, thank you!
**Edit:**
Thank you so much for the response @paulmasson
Your word "typesetting" was new to me and helped me find some other posts.
[This](https://ask.sagemath.org/question/30975/present-sage-output-as-normal-mathematics/) seems to be my exact question:
[This](https://ask.sagemath.org/question/7826/latex-typesetting-for-derivatives-like-g) one seemed to answer my question, but I don't know if I'm supposed to do this.
It gave me the idea of using `f = function('f',x) == 2*x`
I have no clue what `function()` is, but I'm working on it.
I have no idea how or why this is different from `f(x) = 2*x`, but it's pretty cool because now `diff(f,x)` evaulates to `d(f(x)/dy = 2`
However, it doesn't do `diff(f)` so well when there are two variables like `f(x,y) = x^2 + y^2` .
I also really enjoyed this [one](https://ask.sagemath.org/question/24039/showing-both-input-and-output/):
*Edit:* Links, and I'm sorry to the moderator that has to keep approving my edits. Thank you for your time. I promise this will be my last edit.Wed, 15 Mar 2017 09:05:02 +0100https://ask.sagemath.org/question/36945/echo-input-in-output/Comment by paulmasson for <p>I'm trying to use sage for documentation purposes, and I'm looking for a way to do some of the following.</p>
<p>Enter an equation
<code>f(x) = 2x</code>
Input <code>f(2)</code> or something close
and get back <code>f(2) = 4</code> instead of just 4.</p>
<p>I'm also looking for a way to input
<code>f(x) = 2x^2</code>
Input diff(f(x),x), or an equivalent command and get
<code>f'(x) = 4x</code> or <code>d(f(x)/dx = 4x</code>.</p>
<p>And an icing on the cake would being able to input <code>integrate(f(x)dx)</code>
and return <code>∫f(x)dx => 4x + 15 + c</code></p>
<p>Bassically, if there is a way to the output more verbose, I'd love to know how.</p>
<p>I just started using Sage and I love it, thank you!</p>
<p><strong>Edit:</strong>
Thank you so much for the response <a href="/users/19915/paulmasson/">@paulmasson</a>
Your word "typesetting" was new to me and helped me find some other posts.</p>
<p>https://ask.sagemath.org/question/30975/present-sage-output-as-normal-mathematics/ (This) seems to be my exact question:</p>
<p>https://ask.sagemath.org/question/7826/latex-typesetting-for-derivatives-like-g (This) one seemed to answer my question, but I don't know if I'm supposed to do this.</p>
<p>It gave me the idea of using <code>f = function('f',x) == 2*x</code></p>
<p>I have no clue what <code>function()</code> is, but I'm working on it.</p>
<p>I have no idea how or why this is different from <code>f(x) = 2*x</code>, but it's pretty cool because now <code>diff(f,x)</code> evaulates to <code>d(f(x)/dy = 2</code>
However, it doesn't do <code>diff(f)</code> so well when there are two variables like <code>f(x,y) = x^2 + y^2</code> .</p>
<p>I also really enjoyed this https://ask.sagemath.org/question/24039/showing-both-input-and-output/ (one):</p>
<p><em>Edit:</em> Links, and I'm sorry to the moderator that has to keep approving my edits. Thank you for your time. I promise this will be my last edit.</p>
https://ask.sagemath.org/question/36945/echo-input-in-output/?comment=36966#post-id-36966I didn't realize myself that derivatives will now appear typeset if entered as fully symbolic functions, so you taught me something! As a former Mathematica user, I myself still don't quite get all the different ways Sage processes functions, symbolic or merely callable, so welcome to the club. That whole process could be made clearer.
P.S. if you put square brackets around the first URL in each pair and leave the parentheses around the second URL, they should the work like proper links for future readers.Fri, 17 Mar 2017 00:38:37 +0100https://ask.sagemath.org/question/36945/echo-input-in-output/?comment=36966#post-id-36966Answer by paulmasson for <p>I'm trying to use sage for documentation purposes, and I'm looking for a way to do some of the following.</p>
<p>Enter an equation
<code>f(x) = 2x</code>
Input <code>f(2)</code> or something close
and get back <code>f(2) = 4</code> instead of just 4.</p>
<p>I'm also looking for a way to input
<code>f(x) = 2x^2</code>
Input diff(f(x),x), or an equivalent command and get
<code>f'(x) = 4x</code> or <code>d(f(x)/dx = 4x</code>.</p>
<p>And an icing on the cake would being able to input <code>integrate(f(x)dx)</code>
and return <code>∫f(x)dx => 4x + 15 + c</code></p>
<p>Bassically, if there is a way to the output more verbose, I'd love to know how.</p>
<p>I just started using Sage and I love it, thank you!</p>
<p><strong>Edit:</strong>
Thank you so much for the response <a href="/users/19915/paulmasson/">@paulmasson</a>
Your word "typesetting" was new to me and helped me find some other posts.</p>
<p>https://ask.sagemath.org/question/30975/present-sage-output-as-normal-mathematics/ (This) seems to be my exact question:</p>
<p>https://ask.sagemath.org/question/7826/latex-typesetting-for-derivatives-like-g (This) one seemed to answer my question, but I don't know if I'm supposed to do this.</p>
<p>It gave me the idea of using <code>f = function('f',x) == 2*x</code></p>
<p>I have no clue what <code>function()</code> is, but I'm working on it.</p>
<p>I have no idea how or why this is different from <code>f(x) = 2*x</code>, but it's pretty cool because now <code>diff(f,x)</code> evaulates to <code>d(f(x)/dy = 2</code>
However, it doesn't do <code>diff(f)</code> so well when there are two variables like <code>f(x,y) = x^2 + y^2</code> .</p>
<p>I also really enjoyed this https://ask.sagemath.org/question/24039/showing-both-input-and-output/ (one):</p>
<p><em>Edit:</em> Links, and I'm sorry to the moderator that has to keep approving my edits. Thank you for your time. I promise this will be my last edit.</p>
https://ask.sagemath.org/question/36945/echo-input-in-output/?answer=36959#post-id-36959Typesetting for objects like derivatives, integrals and limits is not yet fully implemented in Sage, so the icing isn't available. You can however do something manually like this,
show( "f(2)=", f(2) )
show( "f'(x)=", diff(f(x),x) )
show( "∫f(x)dx=", integrate(f(x),x) )
which gives the sort of output you want.Wed, 15 Mar 2017 21:29:45 +0100https://ask.sagemath.org/question/36945/echo-input-in-output/?answer=36959#post-id-36959