Ask Your Question

Jason021's profile - activity

2023-07-15 19:04:46 +0200 received badge  Notable Question (source)
2023-03-20 04:06:59 +0200 received badge  Famous Question (source)
2022-03-21 02:35:47 +0200 received badge  Notable Question (source)
2022-03-21 02:35:47 +0200 received badge  Popular Question (source)
2021-12-08 22:23:42 +0200 received badge  Notable Question (source)
2021-03-18 03:33:37 +0200 received badge  Popular Question (source)
2020-11-11 05:22:24 +0200 received badge  Popular Question (source)
2020-05-13 19:45:09 +0200 received badge  Famous Question (source)
2018-08-08 10:25:58 +0200 received badge  Notable Question (source)
2018-07-24 23:19:26 +0200 asked a question simplifying out negative signs in exponents

Hello all!

I can't for the life of me find a way to force sage to return terms with only positive coefficient variable exponents. For example, if I enter something like

assume(n, 'integer', n>10)
c = 2^(-n)

I would like the output to be something like 1/(2^n), but instead I can only get something like 2^(-n). Is there a way to force the output to display only positive coefficients in front of the n?

In general I'd like some magicFunc function which I could feed some expression g(x,n) and have it return a rational expression with no negatives; eg.

var('x,n')
assume(x,'real')
assume(n,'integer',n>10)
g(x,n) = 2^(-n)*x^(-3*n)*3^n
magicFunc(g(x,n))

Would return 3^n/(2^n*x^(3n))

Is this possible? This seems like it should be an existent simplification method, but nothing I've tried seems to work.

Thanks!

2018-02-11 15:30:29 +0200 received badge  Notable Question (source)
2017-01-24 14:55:51 +0200 received badge  Popular Question (source)
2016-10-18 13:53:29 +0200 received badge  Nice Question (source)
2016-10-15 19:33:36 +0200 asked a question Converting sin(x)^n to sin^n(x)

Hello all!

I am trying to figure out how to change the sage output when it has certain trig functions to a power. For example, if I do the following;

f(x) = sin(x)
g(x) = f(x)^5

I get out

g(x) = sin(x)^5

This can be a bit ambiguous, as someone not paying attention might read that as sin(x^5). Instead I would like to make it output;

g(x) = sin^5(x)

I have tried using wildcards as was suggested to me in another post here: https://ask.sagemath.org/question/347... But it doesn't seem to like that (probably because it thinks I'm interrupting a math call function and it's getting syntax errors, which I expected when I tried it originally).

Is there any nice way of reformatting the output? I suspect wildcards would probably be capable if I were more adept at them? I would like it specifically for the basic trig functions. I don't mind if I need to write a "simplify" function to run on an expression to convert it (even if it converts everything to a string), but I can't seem to get anything to work correctly.

Thanks.

2016-09-18 17:50:25 +0200 received badge  Popular Question (source)
2016-09-09 16:24:17 +0200 asked a question Displaying mathematical notation as "strings"

Hello!

I can't seem to find if there is a command (or if sage is even capable) to display mathematical notation as a string to be printed, rather than evaluated.

For example, if I try;

foo = exp(x)
foo2 = str(foo)

Then using "foo2" displays e^x, rather than the actual superscript x. Although this isn't terribly surprising to me, I'm curious if there is a way to get the actual correct notation?

An even more important one would be limit notation. I can't figure out how to display the text "Lim" with "x -> 0" underneath the text "Lim" at all in sage.

If these features aren't possible that would be good to know, but it seems like a common and straight forward issue. Unfortunately googling gets drown in irrelevant hits and I don't know the appropriate term to search for. A pointer in the right direction would be much appreciated.

2016-09-08 02:08:20 +0200 commented answer Replacing mathematical functions of expressions with different mathematical functions of the same expression

Ah, that's probably a good bet, seems like in the line (in that link):

performance: GiNaC functions for coth/sech/csch/acoth/asech/acsch (R. Stephan, A. Thakkar)

That seems to target exactly the functions I have issue with, so whatever happened in there is probably the problem. Oh well, I can work around it I think, thanks for the help!

2016-09-07 22:28:08 +0200 commented answer Replacing mathematical functions of expressions with different mathematical functions of the same expression

I ran into an oddity, which is that the above method works great for sinh, cosh, tanh, arcsinh, arccosh, arctanh, arcsech, arccsch, and arccoth. But sech, coth, and csch get rejected for some reason. Even something as trivial as test1 = test2.substitute(coth(w0) == 5) fails. (I also tried the formal definition, that also failed). It's baffling because you can literally take the tanh code and just flip the fraction in the definition. Works for tanh. Fails for coth. Any idea what gives?

2016-09-07 20:55:55 +0200 commented answer Replacing mathematical functions of expressions with different mathematical functions of the same expression

Yep, that's exactly what I needed, thanks!

2016-09-07 20:43:50 +0200 commented question Replacing mathematical functions of expressions with different mathematical functions of the same expression

Unless I am being dumb (which is definitely possible) both those solutions seem to require that I know the argument of arcsinh before I replace it. Which I don't.

What I need is some way to capture the argument of arcsinh (which is one term in a larger function, say f(x) ) assign it a dummy variable, then use subs to replace that with the expanded form using the dummy variable, and then compose back in the original argument. But I have no idea how to capture the original argument. Especially if there is more than one arcsinh with different arguments in the same equation that I would like to replace.

Edit: Yep, I'm being dumb. Situation normal. Wildcards were it, thanks kcrisman!

2016-09-07 19:00:03 +0200 received badge  Scholar (source)
2016-09-07 19:00:02 +0200 received badge  Supporter (source)
2016-09-07 18:16:13 +0200 asked a question Replacing mathematical functions of expressions with different mathematical functions of the same expression

Hello!

I am trying to replace hyperbolic trig with it's expanded form. As a concrete example I would like to replace

arcsinh(z) = ln( z + sqrt(z^2 + 1) )

Now I can do this if I knew that it was actually arcsinh(z) using subs, specifically using the command;

test = arcsinh(z)
test2 = test.subs_expr(arcsinh(z) == (log (z + sqrt((z^2 + 1))) )

The problem is that this seems to work only if it's an exact string match. Meaning if I tried;

test = arcsinh(1/3*x + 1/3)
test2 = test.subs_expr(arcsinh(z) == (log (z + sqrt((z^2 + 1))) )

I get

test2 = arcsinh(1/3*x + 1/3)

Is there a way to replace anything of the form

arcsinh(stuff) -> log (stuff + sqrt((stuff)^2 + 1))

Or does sage have this built in somewhere? I want to ideally make a sage function that I can pass a (randomly generated) mathematical expression to and have it expand the hyperbolic pieces for me. Thus I won't know the argument of the hyperbolic beforehand most of the time.

To give a concrete example, I would like to have something along the following:

a = random(1,1000)
b = random(1,1000)
f = a*arcsinh(b*x + a^2) - b
f2 = f.magicsimplifyfunction()

and get out

f2 = a*log (b*x + a^2 + sqrt((b*x + a^2)^2 + 1)) - b

Where the magicsimplifyfunction is the function that will work on any such f, not tailored to that specific f.

Thanks!

Edit for clarity:

I need a solution that doesn't require me to know the argument of arcsinh beforehand. So the magicsimplyfunction would work something like this:

f = 5*arcsinh(3*x + 1) - 2*e^x + 6*x*arcsinh(x^2)

Applying the simplify function would then "capture" the arguments 3*x+1 and x^2 as dummy variable z1 and z2 respectively and replace them so it would look like the following:

f = 5*arcsinh(z1) - 2*e^x + 6*x*arcsinh(z2)
z1 = 3*x + 1
z2 = x^2

Then I would apply subs_expr to get the following:

f = 5*(log(z1 + sqrt(z1^2 + 1))) - 2*e^x +6*x*(log(z2 + sqrt(z2^2 + 1)))

Then compose back in (or more accurately use another subs_expr) z1 and z2 to finally get

f = 5*(log(3*x+1 + sqrt((3*x+1)^2 + 1))) - 2*e^x +6*x*(log(x^2 + sqrt(x^4 + 1)))

The important thing here is nowhere in the process of executing the "magicsimplifyfunction" command did I specify 3x+1 or x^2. Because in most cases I won't know that's the argument before I am trying to expand it.

2016-07-26 20:15:05 +0200 received badge  Nice Question (source)
2016-06-03 00:26:35 +0200 received badge  Popular Question (source)
2016-05-04 15:12:26 +0200 received badge  Popular Question (source)
2015-12-28 09:10:20 +0200 received badge  Nice Question (source)
2015-12-23 19:15:59 +0200 asked a question Prevent sage from calculating a function?

So I have some code where I would like to formally plug in a number value into a symbolic function without having sage calculate it.

For example, if I have;

var(x)
f(x) = x^2 
c = 2

And then I put in f(c), I'd like it to return 2^2 and not 4. I imagine there must be a way to do this, but I can't seem to find it with googling. Any suggestions would be appreciated.

2015-12-09 15:45:26 +0200 received badge  Editor (source)
2015-12-08 18:56:43 +0200 received badge  Student (source)
2015-12-08 17:05:53 +0200 asked a question Converting sage output into static latex function

Hello!

I want to be able to use sagetex to do some work in sage, and then create a latex function with the result of that sage work, but without calling sage every time the function is called.

Here is an example of the current pseudo-code

\begin{sagesilent}
func1 = x - 3
func2 = x + 1
f = expand(func1*func2)
\end{sagesilent}

\newcommand{\foo}{\sage{f}}

Here, what would normally happen is sage silent runs sage, and creates the correct f = x^2 - 2x - 3. Then every time \foo is called, it reruns an instance of sage to go locate the definition of f in the sage file, and then sage will spit out the definition in text to \foo which then will display f. This is taking a lot of compute time unnecessarily, and when things get randomized it all goes to hell.

Is there any way to force a command to take in the (sage) definition when it's defined, and then save that definition as straight up text so that I don't have to rerun sage to go find the definition of f every time I want to call \foo?

Edit: It seems this could be accomplished if there is a way to define a latex command inside the sagesilent environment? From reading the sage doc it seems that this should be possible (there are examples doing it from a sage prompt) but I can't seem to figure out the correct syntax. Suggestions?

2015-12-07 23:22:35 +0200 commented answer Sage code appears in different places on different compiles

Well, you're sort of right. The doc class is designed to store the content and then reorder it randomly in blocks, then redisplay it. The problem is that the sagetex doesn't move with the blocks as one would like because of that middle step of writing the location of the sage lines to an external file, then having stuff move around. Even more confusing is that this is still a problem with fixed randomizing seed (so it "randomly" puts everything in the same place) A possible solution to my problem might be if there is a way to write a latex command to store the result of the sage code without having to recall the sage code each time that command is called. i.e. if I do \newcommand{\foo}{\sage{function}} it will call \sage{function} each time, not the content of \sage{function} directly.

2015-11-25 19:03:40 +0200 commented question Sage code appears in different places on different compiles

I uploaded it to sagemathcloud and it does still have the same issue. I have shared it here: https://cloud.sagemath.com/projects/7...

2015-11-25 17:27:29 +0200 commented question Sage code appears in different places on different compiles

This occurred to me a while back and I looked into it (admittedly briefly) as I am not sure how to load a cls file into sagemathcloud, does it support cls files? If so I'll go back and see if I can figure it out. I hadn't thought about this recently though, and revisiting it seems like a pretty good idea, thanks!