Ask Your Question

Pretty Antlers's profile - activity

2021-07-03 17:39:25 +0200 received badge  Famous Question (source)
2020-03-09 10:30:51 +0200 received badge  Notable Question (source)
2019-12-13 02:22:24 +0200 received badge  Famous Question (source)
2019-02-01 18:49:16 +0200 received badge  Notable Question (source)
2018-05-19 05:27:51 +0200 received badge  Popular Question (source)
2017-07-13 11:27:36 +0200 received badge  Popular Question (source)
2016-03-20 18:30:53 +0200 received badge  Scholar (source)
2016-03-20 13:11:47 +0200 received badge  Student (source)
2016-03-20 05:26:35 +0200 asked a question Difference between RealField and numerical_approx

What is the difference between using RealField, as in

sage:  RealField(10).pi()
3.1

and numerical_approx, aka n, as in

sage: pi().n(10)
3.1

Are they actually the same function under the hood or should one be used over the other in some cases?

2016-03-20 03:13:33 +0200 commented answer How does SageMath assign to a function call without raising an exception?

The syntax f(x) = something is invalid in Python and SageMath uses iPython, so what kind of wizardry does SageMath use to make it valid?

2016-03-20 02:39:33 +0200 asked a question Implicit differentiation with respect to x and y

Given the function:

sage: F = x^2 + y^2 - 4*x - 1

If I differentiate with respect to x, I get:

sage: F.diff(x)
2*x - 4

And with respect to y, I get:

sage: F.diff(y)
2*y

When I perform implicit differentiation of y with respect to x, I get:

(2 - x) / y

So, it seems that this corresponds to:

sage: -F.diff(x)/F.diff(y)
-(x - 2)/y

But I still don't understand what SageMath is doing.

2016-03-20 02:39:33 +0200 asked a question How does SageMath assign to a function call without raising an exception?

I can assign some functions to a function call like this:

sage: f(x) = cos(x)

But I can't assign other functions like this:

sage: f(x) = lambda x: 1
...
TypeError

which happens to raise a different exception in Python:

>>> f(x) = lambda x: 1
...
SyntaxError: can't assign to function call

So, how does the SageMath interpreter change the behavior of Python?

2016-03-19 20:50:17 +0200 asked a question Plotting piecewise function returns `float() argument must be a string or a number`

I'm trying to plot this piecewise function, mostly for exploration purposes:

sage: f = piecewise([[(-5,0),sin],[(0,5),cos]])
sage: f(-1)
-sin(1)
sage: f(1)
cos(1)
sage: plot(f, (x,-5,5))
...
TypeError: float() argument must be a string or a number

However, there is no exception when plot is called without the (varname, min, max) argument or with the xmin=-5, xmax=5 arguments:

sage: plot(f)
Launched png viewer for Graphics object consisting of 2 graphics primitives
sage: plot(f, xmin=-5, xmax=5)
Launched png viewer for Graphics object consisting of 2 graphics primitives

As another workaround, there is no exception when the piecewise function is called as a lambda function:

sage: plot(lambda x: piecewise([[(-5,0),sin],[(0,5),cos]])(x), (x,-5,5))
Launched png viewer for Graphics object consisting of 2 graphics primitives

So, why is a TypeError raised when plotting a piecewise function with the (varname, min, max) argument and without the lambda workaround?