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.Sun, 09 Aug 2020 15:49:52 +0200Latexing, showing or viewing a held integral triggers its evaluation ???https://ask.sagemath.org/question/52922/latexing-showing-or-viewing-a-held-integral-triggers-its-evaluation/*Note : for once, this will be cross-posted on [sage-support](https://groups.google.com/forum/#!forum/sage-support) for ticket advice...*
Exploring [this question](https://ask.sagemath.org/question/52913/error-during-integration-not-of-type-unsigned-byte-15/) led me to discover what I think is a serious bug : it seems that `latex`ing an expression *containing* a held (= unevaluated) integral triggers the latter's evaluation ; ditto for `view`ing or `show`ing...
Minimal case:
sage: Ig=sin(x)
sage: It=Ig.integrate(x,-pi,pi,hold=True)
sage: Cs=1/(2*pi)
sage: latex(It)
\int_{-\pi}^{\pi} \sin\left(x\right)\,{d x}
So far, so good. But :
sage: Ex=Cs*It
sage: Ex
1/2*integrate(sin(x), x, -pi, pi)/pi
sage: latex(Ex)
\frac{0}{2 \, \pi}
Aaaarghh ! And, of course :
sage: show(Ex)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{0}{2 \, \pi}
And `view(Ex` proudly displays this crap...
IMHO, this is a serious bug, entailing a risk of inadvertently triggering long, impossible or never ending computations.
Advice ?
**EDIT :** On [Cocalc](https://cocalc.com/projects/d9f9cc53-525c-4d92-a0a7-bc5941b8c734/files/?session=default), I have checked that the problem can be reproduced on all available Sage kernels back to 8.2.
Looks more like an error from me, rather than a bug...
Suggestions most welcome !
**EDIT :** One more data point: calling `latex` (or `show` or `view`) on such an expression containing a held integral **in a `hold` context** gives a `RecursionError`.
HTH,Emmanuel CharpentierSun, 09 Aug 2020 15:49:52 +0200https://ask.sagemath.org/question/52922/holding does not work as intendedhttps://ask.sagemath.org/question/52230/holding-does-not-work-as-intended/ Hello everyone,
I am not a native speaker, so I am not too sure about how to express the problem I have, although I will certainly give my best to do so.
I was experimenting with sage a bit and wanted it to generate an overview of a specific simplification of specific root expressions, namely `sqrt(a + sqrt(b)) == sqrt(c) + sqrt(d)` this simplification is possible under certain restraints for integers a and b, but that is not the point here.
For that matter I wanted to create a list of Tuples containing the expression **exactly** as written above and the corresponding boolean.
I therefore defined a function like this:
def test_cases(a):
bs_cs_ds = [\
(SR(4*n*m), SR(n), SR(m))\
for (n,m) in [(x, a-x)\
for x in [1..floor(a/2)]]]
expressions = [\
SR(a).add(sqrt(SR(b),hold=True),hold=True).sqrt(hold=True)\
== sqrt(SR(c), hold=True).add(sqrt(SR(d), hold=True), hold=True)\
for b,c,d in bs_cs_ds]
return [(expr, bool(expr)) for expr in expressions]
So in my opinion I hold the evaluations/simplification for all possible functions (add and sqrt). But for some reason sage will still try to simplify the expressions. For example the input
test_cases(4)[1]
returns `(sqrt(4 + 4) == sqrt(2) + sqrt(2), True)`, instead of `(sqrt(4 + sqrt(16)) == sqrt(2) + sqrt(2), True)`.
So I apparently do not understand how holding works. I was under the impression, that it stops the evaluation/simplification for the given function or expression?
tl;dr: `SR(a).add(SR(sqrt(SR(b), hold=True)), hold=True).sqrt(hold=True)` does not return the expression `sqrt(a + sqrt(b))` (one without any simplifications) for integers a,b, as I would expect for my input. But instead simplifies the inner root by factoring out etc.
To formulate a question: Can somebody correct my code to result in the intended behavior, or at least explain why Sage does not behave as expected from my point of view?Ti FeFri, 26 Jun 2020 23:32:33 +0200https://ask.sagemath.org/question/52230/how to turn off symbolic sum evaluationhttps://ask.sagemath.org/question/9649/how-to-turn-off-symbolic-sum-evaluation/I made some symbolic manipulation and finally... I want to save a 'sum()' in a input form (a evaluated version is horrible big). It is possible to turn off the sum evaluation in SAGE? F_RanekMon, 04 Nov 2013 10:15:35 +0100https://ask.sagemath.org/question/9649/Typesetting Simple Student Worksheet Question & need to defer computationhttps://ask.sagemath.org/question/24637/typesetting-simple-student-worksheet-question-need-to-defer-computation/ I have
eq1=2*(x+10)/5==3*(6-5*x)/7
the command
print latex(eq1)
simplifies the equation to $$\frac{2}{5} x + 4 = -\frac{15}{7} x + \frac{18}{7}$$
is there something like latex(eq1.hold()) that would produce
$$\frac{2(x+3)}{5}=\frac{3(6-5x)}{7}$$
edit:
I must apologize in advanced as my code may seem infantile but I am very new to this and trying to learn. That said, I was able to get something going but it seems to me there must be a million better ways to do this. Can you point me in the right direction to generalize this process and improve this code. Keep in mind the point of this is to write a student worksheet with problem sets and solutions. can be seen here [link text](https://sagecell.sagemath.org/?z=eJydUk2P2jAQvSPxHywXae18LeHrQJuVeqmE1ENBvREOXnDAlbFZ27Rmq_3vHQfYBKRKVS_O8ObNmzfDGIEKJNn-ecOQT05ThCqptSFGH9WGGKY2ek9oRE6pp7Gn9GO3s-EVVDjuvwrrZgSq6BQZ7o5GIZxlWYLjU_ZDC0VwD8fWGVKzCaM0BgRV2iCGhEKgiBMowCD6Lnhn51-VkABTXBFPn_qIS8sRwkqDLSaR1fLohFY2NGL2711QaBHU0X9JC7sIWCM9Rd_NkYf6WiCowwqLovmRGX6QbM0JFjhBWAiBW9gsYLPZDIOjuvEXBu_lL2CHg9GetJaPliwzO0topshGbIWzxYQ2k5xWUPkB5k1ei5_MEOzRCb1iWqPgej5fPviHVdbvdhbZJ_8E0DctT0rvBZMLobZkPg9kaSGzNIKk4yTNaQJRngzr7yDJx00Q-pkrGZB-nUqH16p0kqSDW3oYrD4ExZn5TFzrsnplWRm2_t0-BLfsr8ItlKXklSO3qbxOxbfgoAZ9WRqx3Tn6dic3rNNvPXzxYtmWt834y-Zga-9bDyaiul8c9CNPH4MQKHQ7_CWH-VsTSQv6BY5bkLFhq_xlAMx2P6AWRRu4EodABHok13sgQavEhPecHBVASH0E7-UY1ppXlVgLrhxcXE0aA2mUEngyGTg0s8dn64Q7Ok580acX8xPgjSOSP8LnzLxTOxO7nZ3bS5DLabdjd_oXhIMmHDbhqAnHTTihQeMPn4JaLg==&lang=sage)
ri = lambda x,y: floor(round(random()*(y-x)+x)); #random integer from x to y
ls = [ri(-5,-1),ri(1,3),ri(2,15),ri(2,15)];
rs = [ri(2,10),ri(-3,-1),ri(-6,-2),ri(2,15)];
def texLinearA(t): return "$\\frac{"+str(latex(t[0]))+"\\left("+str(latex(t[1]))+"+"+str(latex(t[2]))+"x\\right)}{"+str(latex(t[3]))+"}$";
def sageLinearA(t): x=var("x"); return t[0]*(t[1]+t[2]*x)/t[3];
eq1 = texLinearA(ls)+"="+texLinearA(rs);
eq2 = sageLinearA(ls)==sageLinearA(rs);
eq3 = eq2*lcm(ls[3],rs[3]);
eq4=eq3-x*eq3.rhs().coefficient(x);
eq5=eq4-(eq4.lhs()).substitute(x=0);
eq6=eq5*(1/eq5.lhs().coefficient(x));
html(eq1);
show(eq2);
show(eq3);
show(eq4);
show(eq5);userXMon, 27 Oct 2014 04:02:29 +0100https://ask.sagemath.org/question/24637/latex Function Prevent Simplificationhttps://ask.sagemath.org/question/9698/latex-function-prevent-simplification/Hi, I am trying to use the latex function without the subject simplifying before it converting to LaTeX. This is similar to the hold=True for algebra functions. For example, I want latex(x/x) to return \frac{x}{x} rather than 1. Thanks so much!bpeacockWed, 09 Jan 2013 00:42:24 +0100https://ask.sagemath.org/question/9698/converting expressions into latex codehttps://ask.sagemath.org/question/8064/converting-expressions-into-latex-code/latex(
(lim((sin(tan(x))-tan(sin(x)))/x^7,x=0)))
returns the latex code of the answer ie -1/30
but I want the latex code of the limit unevaluated so that I can generate an image of the question from it. How can I do this?ebsSat, 09 Apr 2011 07:36:47 +0200https://ask.sagemath.org/question/8064/