Ask Your Question

Harald's profile - activity

2021-01-25 23:46:12 +0200 received badge  Popular Question (source)
2021-01-25 23:46:12 +0200 received badge  Notable Question (source)
2020-12-04 16:58:01 +0200 received badge  Popular Question (source)
2019-06-22 17:17:13 +0200 asked a question Best way to really simplify ugly formulas

As a casual user of sagemath I am always struggling to get my formulas simplified:

var('rg rs r');
dens = 1-r^2*rs/rg^3;
idens = 1-rs/rg;
ism = 1/4 *(3*sqrt(idens)-sqrt(dens))^2 * dens;
d = derivative(ism, r);
d.simplify_full();

The result has some potential for simplification, at least in terms of what think simplification might be. Can someone provide some hints as to how to get better results than from simplify_full()?

2018-08-27 07:37:16 +0200 commented answer Simplify vector vs. its norm

The minus sign in front of the definition of mrot is wrong in my original post, but given that originally I got a spaghetti plate full of formula, (-1, 0, 0) is great and easily fixed by removing the minus :-)

2018-08-26 19:58:04 +0200 answered a question Simplify vector vs. its norm

Here is how it works. In fact it is only slightly different from the above, but the two things that helped were canonicalize_radical() and mapping the simplify to the final vector.

v1 = var('v1');
v2 = var('v2');
v3 = var('v3');
e1 = vector([1,0,0]);
v = vector([v1, v2, v3]);
T=(v1^2 + v2^2 + v3^2);

u = v/sqrt(T); 
z=u.cross_product(e1);
c=u.dot_product(e1);

mat=Matrix( [[0, -z[3-1], z[2-1]], [z[3-1], 0, -z[1-1]], [-z[2-1], z[1-1], 0]] );
mrot=(matrix.identity(3) + mat + (1/(1+c)) * mat*mat);
mrot = mrot*sqrt(T);
mrot = mrot.apply_map(lambda e: e.canonicalize_radical());
view(["mrot*sqrt(T)", mrot])

e = mrot/sqrt(T)*u;
e = e.apply_map(lambda e: e.full_simplify())
e

Multiplying sqrt(T) into mrot and taking it out again when multiplying with u is only for better readability.

2018-08-26 19:06:35 +0200 asked a question How to help sage to group sum elements

When I run

var('a b');
T = a^2 + b^2;
e = a^2 + b^2 + sqrt(T);
e = e/sqrt(T);
print e

sage returns $$\frac{a^2+b^2+\sqrt{a^2+b^2}}{\sqrt{a^2 + b^2}} .$$

I cannot get it to simplify this to $\sqrt{a^2+b^2}+1$. How can I help sage to simplify the fraction? I assume it has difficulties to notice that it just needs to group the numerator in a certain way.

I tried to help out with

var('X');
e = e.subs(a^2+b^2==X);

but this just results in $(a^2+b^2 +\sqrt{X})/\sqrt{X}$.

2018-08-26 18:48:16 +0200 commented answer Simplify vector vs. its norm

Well, this is because full_simplify() is not what is needed. I am working on a solution and it starts with not using v.norm(), but explicitly defining T=v1^2 +v2^2 + v3^2 and using its sqrt(). This makes the result half understandable, but I need to find out more to get this solved.

2018-08-25 22:41:20 +0200 received badge  Supporter (source)
2018-08-25 22:40:11 +0200 asked a question Simplify vector vs. its norm

In the following I compute the matrix mrot which shall rotate the vector v to the unit vector pointing into the x-direction. This does indeed work, except that the last printout for verification, view(u*mrot), looks complicated, despite the fact that it should just be (1, 0, 0). How would I let sage reduce the enormous formulas for the vector components?

v1 = var('v1');
v2 = var('v2');
v3 = var('v3');
e1 = vector([1,0,0]);
v = vector([v1, v2, v3]);
u = v/v.norm();
#u = v;
view(["u=", u], sep=" ");
z=u.cross_product(e1);
#z=e1.cross_product(u);
view(["z=", z]);
c=u.dot_product(e1);
view(["c=",c]);
mat=Matrix( [[0, -z[3-1], z[2-1]], [z[3-1], 0, -z[1-1]], [-z[2-1], z[1-1], 0]] );
#view([mat, mat*mat]);
mrot=-(matrix.identity(3) + mat + (1/(1+c)) * mat*mat);
view(u*mrot);
2018-01-28 18:16:50 +0200 received badge  Student (source)
2018-01-28 18:16:27 +0200 asked a question What is the opposite of log_expand

log_expand does converts log(x*y) to log(x)+log(y). Is there a function which explicitly reverts this?

2018-01-28 13:10:30 +0200 received badge  Scholar (source)
2015-03-29 17:16:10 +0200 asked a question declare name of derivative

After defining a function depending on one variable as

v(t) = function('v', t);

Then v.diff() displays as

t ↦ D[0](v)(t)

Rather I would like to teach Sage that the derivative of v is a such that v.diff() is displayed as t↦a(t).

Can this be done?