Ask Your Question

Björn's profile - activity

2024-02-09 13:46:45 +0200 received badge  Famous Question (source)
2024-02-09 13:46:45 +0200 received badge  Notable Question (source)
2023-11-02 10:19:14 +0200 commented question Symbolic matrix inversion broken?

It works for me after updating SageMath from 10.0 to 10.1 via Homebrew. I still have no clue why this didn't work in 10.

2023-11-02 09:29:00 +0200 commented question Symbolic matrix inversion broken?

Good point. sage0_version says "'SageMath version 10.0, Release Date: 2023-05-20'". I'll update and report back.

2023-11-02 08:22:07 +0200 received badge  Autobiographer
2023-11-02 08:20:05 +0200 asked a question Symbolic matrix inversion broken?

Symbolic matrix inversion broken? The result of the following is a bit unexpected. sage: n=3; sage: D = matrix.diagona

2023-04-19 13:06:22 +0200 received badge  Famous Question (source)
2022-07-07 19:04:49 +0200 received badge  Famous Question (source)
2021-03-28 00:18:40 +0200 received badge  Nice Question (source)
2021-03-28 00:17:50 +0200 received badge  Notable Question (source)
2020-12-28 23:48:31 +0200 received badge  Popular Question (source)
2020-06-18 20:52:19 +0200 received badge  Notable Question (source)
2020-04-16 12:19:56 +0200 received badge  Nice Question (source)
2020-04-16 12:19:43 +0200 received badge  Self-Learner (source)
2020-01-17 14:13:56 +0200 received badge  Notable Question (source)
2019-12-24 19:19:21 +0200 received badge  Good Question (source)
2019-02-20 16:10:01 +0200 received badge  Popular Question (source)
2019-01-08 06:50:42 +0200 received badge  Notable Question (source)
2018-06-28 21:39:25 +0200 received badge  Famous Question (source)
2018-03-21 08:39:50 +0200 commented answer Code highlighting and execution in sagetex

It is a partial workaround, but does not solve the original question, really. The sage: is a bit in the way, and this doesn't seem to support block code like function definitions or loops. Sorry for not noticing your answer earlier, I haven't logged in in a while.

2018-02-16 00:32:07 +0200 received badge  Popular Question (source)
2018-02-16 00:32:07 +0200 received badge  Notable Question (source)
2018-01-29 16:36:14 +0200 received badge  Popular Question (source)
2017-12-16 12:58:19 +0200 received badge  Popular Question (source)
2017-09-06 03:47:27 +0200 received badge  Nice Question (source)
2017-09-05 14:44:22 +0200 asked a question Code highlighting and execution in sagetex

Is there a version of \begin{sageblock} my multiline code \end{sageblock} that has code highlighting and line numbering like the sagecommandline environment and code execution?

Of course typesetting with lstlistings and execution with sagesilent could be a workaround, but it would seem to require me to have the same code in my document twice. And that I find unacceptable.

2017-04-20 07:48:07 +0200 received badge  Nice Answer (source)
2017-04-19 18:52:52 +0200 commented answer Why does simplify break print_latex_func?

That's just perfect, thanks! latex(sexp2), latex(f) instead of sexp2 ; f really demonstrates the achievement of your recursive coercion. Very nice, I especially like that the code does not require a priori knowledge of the function to be substituted. This really should be built into sage's simplify() at the stage when it processes what comes back from maxima.

2017-04-19 18:52:52 +0200 received badge  Commentator
2017-04-19 18:46:17 +0200 commented answer Why does simplify break print_latex_func?

I guess will have to live with that ;) Thanks again for giving me the starting point, there wasn't much left to do after that.

2017-04-19 16:53:27 +0200 received badge  Self-Learner (source)
2017-04-19 16:20:07 +0200 commented answer Why does simplify break print_latex_func?

Not only that, to get the operator name, one somehow needs to find it by location in the sage expression, at least I am not aware of a better way to find a reference to the "maxima" a(). Maybe one could loop over all operators in the expression and somehow filter by a feature that identifies them as maxima operators... but that's messy.

2017-04-19 15:19:32 +0200 received badge  Organizer (source)
2017-04-19 15:15:37 +0200 commented answer Why does simplify break print_latex_func?

Thanks to kcrisman I figured the remaining bits out myself. Complete code as follows:

# [...]
print latex(sexp)
sexp2=simplify(sexp) # expand doesn't hurt it, so omit that
print latex(sexp2)
# observe they are different due to sexp2 being processed 
# via Maxima, as explained by kcrisman
# maxima replaces a() by a new a() that doesn't have the 
# print function:

print sexp2.operands()[0].operator().__class__ # maxima a()
print a.__class__ # the a() we have defined

# to coerce back, we need to replace the former by the latter:
print latex(sexp2.substitute_function(sexp2.operands()[0].operator(),a))

(And that does the intended.)

2017-04-19 14:38:07 +0200 commented answer Why does simplify break print_latex_func?

Aha, I see... At the end of the day I don't really mind Maxima, as long as I can coerce back, which I cannot seem to figure out how to achieve. Obvious (to me) candidates would seem to be latex(sexp2.subs({a(n):a(n)})) or even latex(sexp2.subs({a: a})). But they do not work as expected or throw errors when I use keywords in combination with arguments to a().

print sexp2.operands()[0].operator().__class__ # maxima a()
print a.__class__ # my a()

Reveals the functions a() are indeed different, the former function_factory.NewSymbolicFunction, the latter expression.Expression. Can't I just somehow retrospectively set the print_latex_func on the function_factory.NewSymbolicFunction?

2017-04-19 13:53:34 +0200 answered a question How to simplify fractions?

Use bool() like so

,var n
f1=((-1)^n-2*n-1)/4/(2*n+1)
f2=(-1)^n/4/(2*n+1)-1/4
show(f1==f2)
bool(f1==f2)
2017-04-19 13:50:49 +0200 commented question Why does simplify break print_latex_func?

I know it is simplify() and not expand() that causes the problem. But why and how?

2017-04-19 04:17:36 +0200 asked a question Why does simplify break print_latex_func?

Here's a minimal example of what I am talking about. Both print statements should return the same output in this scenario.

,var n x
def my_latex_print(self, *args): 
    return "a_{%s}" %(', '.join(map(latex, args)))
a=function('a',nargs=1,print_latex_func=my_latex_print)(n)

sexp=a(n=n+1)+a(n=n)
print latex(sexp)
sexp=simplify(expand(sexp))
print latex(sexp)

However, the outputs differ:

a_{n + 1} + a_{n}
a\left(n + 1\right) + a\left(n\right)

Of course simplify-expand may lead to a different expression, but that's not what I am concerned about. I am concerned about the representation of a(n) instead of a_n in the output.

My main question is: How can I recover a_n out of sexp at the end of my code?