Ask Your Question

cav24's profile - activity

2024-03-05 20:40:50 +0200 received badge  Notable Question (source)
2024-03-05 20:38:03 +0200 received badge  Famous Question (source)
2023-12-07 01:03:09 +0200 received badge  Notable Question (source)
2023-07-19 15:35:09 +0200 received badge  Notable Question (source)
2023-07-19 15:35:09 +0200 received badge  Popular Question (source)
2023-06-29 09:31:43 +0200 received badge  Popular Question (source)
2023-01-30 03:03:19 +0200 received badge  Popular Question (source)
2023-01-16 10:28:49 +0200 received badge  Nice Question (source)
2022-11-18 20:24:18 +0200 edited answer Running Sage on WSL2 doesn't open jupyter notebook

The following solved the problem for me: (1) In the Ubuntu command line, run sage --jupyter notebook --generate-config

2022-11-18 20:23:11 +0200 edited answer Running Sage on WSL2 doesn't open jupyter notebook

The following solved the problem for me: (1) In the Ubuntu command line, run sage --jupyter notebook --generate-config

2022-11-18 20:21:50 +0200 edited answer Running Sage on WSL2 doesn't open jupyter notebook

The following solved the problem for me: (1) In the Ubuntu command line, run sage --jupyter notebook --generate-config

2022-11-18 20:04:20 +0200 edited answer Running Sage on WSL2 doesn't open jupyter notebook

The following solved the problem for me: (1) In the Ubuntu command line, run sage --jupyter notebook --generate-config

2022-11-18 20:02:05 +0200 answered a question Running Sage on WSL2 doesn't open jupyter notebook

The following solved the problem for me: (1) In the Ubuntu command line, run sage --jupyter notebook --generate-config

2022-06-28 00:37:22 +0200 commented answer Limit of piecewise function

Wow, thanks for the edit, that's a great idea and I've learned a lot! I imagine we can construct examples where even th

2022-06-28 00:25:33 +0200 received badge  Supporter (source)
2022-06-22 14:04:06 +0200 commented answer Limit of piecewise function

Thanks for your answer! I'm not sure I understand but I'll research "simpy" and expression_at. However: It seems like ne

2022-06-22 13:39:11 +0200 commented answer Delayed evaluation (equivalent to := in Mathematica)?

I love it. So my mistake was to write myplot(x) instead of just myplot. Thank you!

2022-06-22 13:37:49 +0200 marked best answer Delayed evaluation (equivalent to := in Mathematica)?

In Sage, is there a way to define a function such that the expressions used are evaluated only when the function is called with specific values replacing its arguments? (In Mathematica, this is done by defining f(x_) : = some function(x).)

As an example, here is some otherwise useless code which is intended to give back a plot of x^r for arbitrary integer r.

myplot(r) = lambda r: plot(x^r,(x,-1,1))

Executing this line causes the errors copied below, which are identical to those produced if I simply execute plot(x^r,(x,-1,1)) by itself. So my interpretation is that Sage is immediately trying to evaluate the RHS of the function I'm defining. In Mathematica, this evaluation can be delayed using the ":=" syntax, so that if I then call "my plot(3)" it would go and evaluate plot(x^3,(x,-1,1)) which of course would produce the desired result. So, again, my question is whether there is something analogous in Sage?

(And yes, I have heard that Sage is short for "Sage is not Mathematica". But it's so great! Sage I mean.)

Thanks!

 ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.var (build/cythonized/sage/ext/fast_callable.c:6657)()
    688         try:
--> 689             ind = self._vars.index(var_name)
    690         except ValueError:

ValueError: 'x' is not in list

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
/var/folders/mt/4xjm_x515mxdjkm49zmplt240000gq/T/ipykernel_91376/380259859.py in <module>
----> 1 __tmp__=var("r"); myplot = symbolic_expression(lambda r: plot(x**r,(x,-Integer(1),Integer(1)))).function(r)

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/calculus/all.py in symbolic_expression(x)
    223                    for param in s.parameters.values()):
    224                 vars = [SR.var(name) for name in s.parameters.keys()]
--> 225                 result = x(*vars)
    226                 if isinstance(result, (tuple, list)):
    227                     return vector(SR, result).function(*vars)

/var/folders/mt/4xjm_x515mxdjkm49zmplt240000gq/T/ipykernel_91376/380259859.py in <lambda>(r)
----> 1 __tmp__=var("r"); myplot = symbolic_expression(lambda r: plot(x**r,(x,-Integer(1),Integer(1)))).function(r)

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/misc/decorators.py in wrapper(*args, **kwds)
    489                 options['__original_opts'] = kwds
    490             options.update(kwds)
--> 491             return func(*args, **options)
    492 
    493         #Add the options specified by @options to the signature of the wrapped

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/plot/plot.py in plot(funcs, *args, **kwds)
   1981 
   1982     if hasattr(funcs, 'plot'):
-> 1983         G = funcs.plot(*args, **original_opts)
   1984 
   1985         # If we have extra keywords already set, then update them

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.plot (build/cythonized/sage/symbolic/expression.cpp:94285)()
  12857                     param = A[0]
  12858                     try:
> 12859                         f = self._plot_fast_callable(param)
  12860                     except NotImplementedError:
  12861                         return self.function(param)

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._plot_fast_callable (build/cythonized/sage/symbolic/expression.cpp:94693)()
  12892         from sage.ext.fast_callable import fast_callable
  12893         from sage.rings.complex_double import CDF
> 12894         return fast_callable(self, vars=vars, expect_one_var=True, domain=CDF)
  12895 
  12896     ############

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.fast_callable (build/cythonized/sage/ext/fast_callable.c:4638)()
    463 
    464         etb = ExpressionTreeBuilder(vars=vars, domain=domain)
--> 465         et = x._fast_callable_(etb)
    466 
    467     if isinstance(domain, sage.rings.abc.RealField):

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_callable_ (build/cythonized/sage/symbolic/expression.cpp:93534)()
  12719         """
  12720         from sage.symbolic.expression_conversions import fast_callable
> 12721         return fast_callable(self, etb)
  12722 
  12723     def show(self):

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression_conversions.py in fast_callable(ex, etb)
   1866 
   1867     """
-> 1868     return FastCallableConverter(ex, etb)()
   1869 
   1870 class RingConverter(Converter):

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression_conversions.py in __call__(self, ex)
    204                 div = self.get_fake_div(ex)
    205                 return self.arithmetic(div, div.operator())
--> 206             return self.arithmetic(ex, operator)
    207         elif operator in relation_operators:
    208             return self.relation(ex, operator)

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression_conversions.py in arithmetic(self, ex, operator)
   1794         elif operator == mul_vararg:
   1795             operator = _operator.mul
-> 1796         return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
   1797 
   1798     def symbol(self, ex):

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression_conversions.py in <lambda>(x, y)
   1794         elif operator == mul_vararg:
   1795             operator = _operator.mul
-> 1796         return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
   1797 
   1798     def symbol(self, ex):

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.call (build/cythonized/sage/ext/fast_callable.c:7094)()
    741         if fn is operator.pow:
    742             base, exponent = args
--> 743             return self(base)**exponent
    744         else:
    745             return ExpressionCall(self, fn, [self(a) for a in args])

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.__call__ (build/cythonized/sage/ext/fast_callable.c:6236)()
    617             return self.constant(x)
    618 
--> 619         return fc(self)
    620 
    621     def _clean_var(self, v):

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_callable_ (build/cythonized/sage/symbolic/expression.cpp:93534)()
  12719         """
  12720         from sage.symbolic.expression_conversions import fast_callable
> 12721         return fast_callable(self, etb)
  12722 
  12723     def show(self):

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression_conversions.py in fast_callable(ex, etb)
   1866 
   1867     """
-> 1868     return FastCallableConverter(ex, etb)()
   1869 
   1870 class RingConverter(Converter):

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression_conversions.py in __call__(self, ex)
    198         operator = ex.operator()
    199         if operator is None:
--> 200             return self.symbol(ex)
    201 
    202         if operator in arithmetic_operators:

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/symbolic/expression_conversions.py in symbol(self, ex)
   1815             ValueError: Variable 'z' not found...
   1816         """
-> 1817         return self.etb.var(SR(ex))
   1818 
   1819     def composition(self, ex, function):

/private/var/tmp/sage-9.6-current/local/var/lib/sage/venv-python3.10.3/lib/python3.10/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.ExpressionTreeBuilder.var (build/cythonized/sage/ext/fast_callable.c:6736)()
    689             ind = self._vars.index(var_name)
    690         except ValueError:
--> 691             raise ValueError(f"Variable '{var_name}' not found in {self._vars}")
    692         return ExpressionVariable(self, ind)
    693 

ValueError: Variable 'x' not found in ['r']
2022-06-22 12:04:28 +0200 asked a question Delayed evaluation (equivalent to := in Mathematica)?

Delayed evaluation (equivalent to := in Mathematica)? In Sage, is there a way to define a function such that the express

2022-06-22 10:47:29 +0200 commented answer Limit of piecewise function

Further evidence that this is what's happening: f(x) = piecewise([[(0,1),x],[(1,2),x]]) limit(f(x).expression_at(1),x=1

2022-06-22 10:45:17 +0200 commented answer Limit of piecewise function

Thanks for your answer! I'm not sure I understand but I'll research "simpy" and expression_at. However: It seems like ne

2022-06-22 10:44:56 +0200 commented answer Limit of piecewise function

Further evidence that this is what's happening: f(x) = piecewise([[(0,1),x],[(1,2),x]]) limit(f(x).expression_at(1),x=1

2022-06-22 10:43:59 +0200 commented answer Limit of piecewise function

Further evidence that this is what's happening: f(x) = piecewise([[(0,1),x],[(1,2),x]]) limit(f(x).expression_at(1),x=1

2022-06-22 10:43:32 +0200 commented answer Limit of piecewise function

Further evidence that this is what's happening: f(x) = piecewise([[(0,1),x],[(1,2),x]]) limit(f(x).expression_at(1),x=1

2022-06-22 10:43:22 +0200 commented answer Limit of piecewise function

Further evidence that this is what's happening: f(x) = piecewise([[(0,1),x],[(1,2),x]]) limit(f(x).expression_at(1),x=1

2022-06-22 10:43:08 +0200 commented answer Limit of piecewise function

Further evidence that this is what's happening: f(x) = piecewise([[(0,1),x],[(1,2),x]]) limit(f(x).expression_at(1),x=1

2022-06-22 10:40:31 +0200 commented answer Limit of piecewise function

Thanks for your answer! I'm not sure I understand but I'll research "simply" and expression_at. However: It seems like n

2022-06-22 10:39:24 +0200 commented answer Limit of piecewise function

Thanks for your answer! I'm not sure I understand but I'll research "simply" and expression_at. However: It seems like n

2022-06-21 22:00:56 +0200 edited question Limit of piecewise function

Limit of piecewise function This exact question has been asked before (8 years ago, 2 years ago). So here goes, perhaps

2022-06-21 21:58:55 +0200 edited question Limit of piecewise function

Limit of piecewise function This exact question has been asked before (8 years ago, 2 years ago). So here goes, perhaps

2022-06-21 21:58:50 +0200 received badge  Editor (source)
2022-06-21 21:58:50 +0200 edited question Limit of piecewise function

Limit of piecewise function This exact question has been asked before (8 years ago, 2 years ago). So here goes, perhaps

2022-06-21 21:55:55 +0200 asked a question Limit of piecewise function

Limit of piecewise function This exact question has been asked before (8 years ago, 2 years ago). So here goes, perhaps

2022-06-20 11:00:56 +0200 asked a question sagetex in Lyx on Mac: Can't compile using latex(pdflatex)

sagetex in Lyx on Mac: Can't compile using latex(pdflatex) I am trying to use Sagetex within Lyx (Version 2.3) on an M1

2022-06-16 17:42:31 +0200 received badge  Student (source)
2022-06-16 16:12:54 +0200 commented answer Correct syntax for "solve(f.derivative(x1,x2)==(0,0))"

Brilliant! I have learned a lot. Thank you so much!

2022-06-16 16:10:17 +0200 marked best answer Correct syntax for "solve(f.derivative(x1,x2)==(0,0))"

I am trying to create simple code to identify critical points of a multivariate function. For pedagogical reasons, I want to do this completely manually. That is, I first want to compute the gradient, and then I want to solve for points where the gradient is zero. Here is my code:

var('x1 x2')
f(x1,x2) = x1^2 + x2^2
Df=f.derivative()
solve(Df(x1,x2)==(0,0),(x1,x2))

The third step returns what I want. If I evaluate Df(x1,x2), Sage returns (2*x1, 2*x2) as expected. However the final step returns the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-33-bc76a33e3a15> in <module>
----> 1 solve(Df(x1,x2)==(Integer(0),Integer(0)),(x1,x2))

/var/tmp/sage-jc4b6yulaujayb9sr94ia88eourzeqip0oidmas3/local/lib/python3.8/site-packages/sage/symbolic/relation.py in solve(f, *args, **kwds)
   1045 
   1046     if not isinstance(f, (list, tuple)):
-> 1047         raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.")
   1048 
   1049     # f is a list of such expressions or equations

TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.
2022-06-16 16:10:17 +0200 received badge  Scholar (source)
2022-06-15 18:58:40 +0200 asked a question Correct syntax for "solve(f.derivative(x1,x2)==(0,0))"

Correct syntax for "solve(f.derivative(x1,x2)==(0,0))" I am trying to create simple code to identify critical points of