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, 26 Jun 2020 23:32:33 +0200holding 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/contour plot not working as expectedhttps://ask.sagemath.org/question/8958/contour-plot-not-working-as-expected/Hi all,
I am looking at ways to determine the sign of an angle between a reference vector (a,b) and any other vector(x,y) of the plane. To do so, I have decided to use the determinant of the matrix: [[a b],[x y]] which equals ax-by.
I wanted then to check that the formula works by displaying the plane area which positive and negative signs using the contour_plot.
Here is my question:
Why is the 3rd graph not showing 2 horizontal areas instead of the vertical displayed?
var('x y')
f(x,y,a,b)=(a*y-b*x)/abs(a*y-b*x)
plota1b1=contour_plot(f(x,y,1,1),(-10,10),(-10,10),cmap='jet',colorbar=true)
plota0b1=contour_plot(f(x,y,0,1),(-10,10),(-10,10),cmap='jet',colorbar=true)
plota1b0=contour_plot(f(x,y,1,0),(-10,10),(-10,10),cmap='jet',colorbar=true)
show(plota1b1)
show(plota0b1)
show(plota1b0)
Thanks
sagembMon, 07 May 2012 04:34:12 +0200https://ask.sagemath.org/question/8958/