wxMaxima: treat division as multiplication (gather overall divisions as multiplicative factor) - maxima

I'm wondering if there is any way to tell Maxima to return
1/2*x
instead of
x/2
I'm trying to handle u-substitutions using changevar however, it's returning expressions like:
\frac{\int \cos{u} \de{u}}{5}
whereas I'd like to have it display as
\frac{1}{5} \int \cos(u) \de{u}
or
\int \cos(u) \frac{1}{5} \de{u}
Is this possible? If so, any suggestions as to where to start?

I think the display option pfeformat has the effect you want. By default it's false. Here's what I get when it is enabled:
(%i2) pfeformat: true $
(%i3) 'integrate(cos(u),u)/5;
/
[
(%o3) (1/5) I cos(u) du
]
/
(%i4) tex(%);
$${{1}\over{5}}\,\int {\cos u}{\;du}$$
The internal form of the expression is the same -- you can call ?print to see what it is -- and pfeformat just changes the way it's displayed.

Related

How to make "at()" function evaluate en expression?

I tried function "at" with some function inside it and then give the output to some variable. Maxima successfully differentiated the expression, but then "at" fails and the output is "at( --some successfully done function--, z=l)=0". I need "at" to work properly, to give the result to a variable.
(%i34) a: 45*z^2*l-1; /*expression*/
eq1: at(diff(a, z, 1), z = l)=0; /*giving the meaning of the operations to eq1*/
at(diff(a, z, 1), z = l)=0; /*trying the same without giving the result to a variable*/
ev(eq1, eval); /*trying ev*/
(a) l*z^2* 45-1
(eq1)  at(2*l*z* 45,z=l)=0
(%o34) 2*l^2* 45=0
(%o35)  at(2*l*z* 45,z=l)=0
So when I don't give the result of at to other variables, it's fine but when I try to - it fails even with additional evaluation. How does that work? And also this was tried on Linux. On Windows I don't have the same problem.
I get the following output. Isn't %o3 what you are looking for?
(%i2) a: 45*z^2*l-1;
2
(%o2) 45 l z - 1
(%i3) eq1: at(diff(a, z, 1), z = l)=0;
2
(%o3) 90 l = 0
I am working w/ Maxima 5.42.2 on MacOS. What does build_info(); report on your Linux system? Some Linux distributions package an ancient version of Maxima; maybe you can get a newer version. It is actually pretty easy to build Maxima from a source tarball on a Linux system; I can help if you want to go down that road.

How do I tell Maxima about valid approximations of subexpressions of a large expression?

I have a fairly large expression that involves a lot of subexpressions of the form (100*A^3 + 200*A^2 + 100*A)*x or (-A^2 - A)*y or (100*A^2 + 100*A)*z
I know, but I don't know how to tell Maxima this, that it in this case is valid to make the approximation A+1 ~ A, thereby effectively removing anything but the highest power of A in each coefficient.
I'm now looking for functions, tools, or methods that I can use to guide Maxima in dropping various terms that aren't important.
I have attempted with subst, but that requires me to specify each and every factor separately, because:
subst([A+1=B], (A+2)*(A+1)*2);
subst([A+1=B], (A+2)*(A*2+2));
(%o1) 2*(A+2)*B
(%o2) (A+2)*(2*A+2)
(that is, I need to add one expression for each slightly different variant)
I tried with ratsimp, but that's too eager to change every occurrence:
ratsubst(B, A+1, A*(A+1)*2);
ratsubst(B, A+1, A*(A*2+2));
(%o3) 2*B^2-2*B
(%o4) 2*B^2-2*B
which isn't actually simpler, as I would have preferred the answer to have been given as 2*B^2.
In another answer, (https://stackoverflow.com/a/22695050/5999883) the functions let and letsimp were suggested for the task of substituting values, but I fail to get them to really do anything:
x:(A+1)*A;
let ( A+1, B );
letsimp(x);
(x)A*(A+1)
(%o6) A+1 --\> B
(%o7) A^2+A
Again, I'd like to approximate this expression to A^2 (B^2, whatever it's called).
I understand that this is, in general, a hard problem (is e.g. A^2 + 10^8*A still okay to approximate as A^2?) but I think that what I'm looking for is a function or method of calculation that would be a little bit smarter than subst and can recognize that the same substitution could be done in the expression A^2+A as in the expression 100*A^2+100*A or -A^2-A instead of making me create a list of three (or twenty) individual substitutions when calling subst. The "nice" part of the full expression that I'm working on is that each of these A factors are of the form k*A^n*(A+1)^m for various small integers n, m, so I never actually end up with the degenerate case mentioned above.
(I was briefly thinking of re-expressing my expression as a polynomial in A, but this will not work as the only valid approximation of the expression (A^3+A^2+A)*x + y is A^3*x + y -- I know nothing about the relative sizes of x and y.

is(unit_step(x)*unit_step(x) = unit_step(x)) evaluates to false

We are giving students some exercises, where their solutions are evaluated with maxima.
The answer involves the unit step function. The evaluation in maxima seems to go okay, except that there seems to be missing some algebraic rules on the unit_step functions.
For example is(unit_step(x)*unit_step(x) = unit_step(x)) evaluates to false. It is quite unlikely that the student gives the answer in such a form, but still we don't want to have the possibility that the student gives a good answer, that is evaluated as incorrect.
Below is a screenshot of an answer we try to evaluate with maxima involving the unit_step function (that we defined as u):
Maxima doesn't know much about unit_step at present (circa Maxima 5.41). This is just a shortcoming, there's no reason for it, except that nobody has gotten around to doing the work. That said, it's not too hard to make some progress.
The simplifier for multiplication merges identical terms into powers:
(%i3) unit_step(x)*unit_step(x);
2
(%o3) unit_step (x)
So let's define a simplifier rule which reduces positive powers of unit_step. (I was going to say positive integer powers, but a moment's thought shows that the same identity holds for noninteger positive powers as well.)
(%i4) matchdeclare (aa, lambda ([e], e > 0)) $
(%i5) matchdeclare (xx, all) $
(%i6) tellsimpafter (unit_step(xx)^aa, unit_step(xx));
(%o6) [^rule1, simpexpt]
Let's try it.
(%i7) unit_step(x)*unit_step(x);
(%o7) unit_step(x)
(%i8) is (unit_step(x)*unit_step(x) = unit_step(x));
(%o8) true
(%i9) unit_step(t - 5)^(1/4);
(%o9) unit_step(t - 5)
(%i10) assume (m > 0);
(%o10) [m > 0]
(%i11) unit_step(2*u + 1)^m;
(%o11) unit_step(2 u + 1)
So far, so good. Of course this is just one identity and there are others that could be useful. Since this rule is not built-in, one would have to load that definition in order to make use of it; that would be bothersome if you intend for others to use this.
For the record, the only simplification for unit_step which I found in the Maxima source code is in share/contrib/integration/abs_integrate.mac, which contains a function unit_step_mult_simp, which applies the identity unit_step(a)*unit_step(b) --> unit_step(min(a, b)).

Declare a variable to be a positive real number in maxima?

I have the following maxima code:
declare(p, real)$
declare(q, real)$
declare(m, real)$
is(-(4*p^2*q^2)/m^2-(4*p^4)/m^2 < 0);
This evaluates to unknown. Can I declare that p,q and m are positive real numbers?
Short answer to the question
Putting #Michael O.'s comment into the form of an answer:
The assume function can be used to set predicates on variables, in particular to tell maxima that a number is positive (this is also useful for calculating some integrals with integrate)
assume(p>0,q>0,m>0);
is(-(4*p^2*q^2)/m^2-(4*p^4)/m^2 < 0);
Some more functions for managing predicates
The list of predicates can be displayed using the facts function and removed using the forget function
kill(all); /*Clears many things, including facts*/
assume(a>0,b>0,c>0)$ /*Learn facts*/
facts();
forget(b>0)$ /*Forget one fact*/
facts();
forget(facts())$ /*Forget all known facts*/
facts();
Example of usage of assume with integrate function
Some mathematical results depends on e.g. the sign of some parameters. In particular, it is the case of some integrals.
(%i0) print("Without predicates: Maxima prompts the user")$
kill(all)$
L : sqrt(1 - 1/(R^2))$
facts();
integrate(x,x,0,L);
print("With predicates: Maxima does not need to prompt the user because it already knows the answer")$
kill(all)$
assume(R>0)$
L : sqrt(1 - 1/(R^2))$
facts();
integrate(x,x,0,L);
Without predicates: Maxima prompts the user
(%o0) []
Is "R" positive or negative? positive;
(%o1) (R^2-1)/(2*R^2)
With predicates: Maxima does not need to prompt the user because it already knows the answer
(%o2) [R>0]
(%o3) (R^2-1)/(2*R^2)

sequence absent in Maxima

I was trying to see if I can collect information from list based on the depth of nesting of sub-lists.
But I realized that it should be accomplish-able only by tree. I learned programming binary tree in lisp to some extent but it won't be helpful and I will have to try tree with any number of child nodes.
I also found out that there is 'sequence' function in lisp which can make the the work easier as I can do
li:[g,f,t,h,[a,b,c],[[t,y,u]]]
/*after filtering out non-list elements li=[[a,b,c],[[t,y,u]]]*/
IN::map(lambda([x],apply(sequence,[x]),li)
OUT:: [a,b,c,[t,y,u]]
/*Again filtering out and repeating the process will leave me with [t,y,u].*/
In this way I can collect sub-lists at different labels. I couldn't see this sequence function in Maxima. Is there any certain reason it wasn't included ?
Not sure what you want to accomplish. Maybe append has the desired effect?
(%i1) li : [[a, b, c], [[t, y, u]]] $
(%i2) apply (append, li);
(%o2) [a, b, c, [t, y, u]]

Resources