Maxima returns false when comparing two equal list elements - maxima

I'm trying to check if the increment from one number to the next is the same from the second to it's next and so on but found that it returns "false" when it should say "true". Here is what i found out after an hour of tinkering. Does anyone know why this happens and if it's possible to fix?
(%i1) kill(all)$;
(%i1) pointsx:[0.1,0.2,0.3,0.4,0.65,0.9]$;
(%i2) pointsx[2]-pointsx[1]; pointsx[3]-pointsx[2];
(%o2) 0.1
(%o3) 0.1
(%i4) is(pointsx[2]-pointsx[1]=pointsx[3]-pointsx[2]);
(%o4) false
(%i5) is(pointsx[2]-pointsx[1]>pointsx[3]-pointsx[2]);
(%o5) true

Related

Wrong limit with Maxima CAS

This very simple limit:
(%i1) limit((z^(2*n)-1)/(z^2-1),z,-1);
(%o1) infinity
goes catastrophically wrong. We can think that a reasonable solution will be
(%i1) declare(n,integer);
(%o1) done
(%i2) limit((z^(2*n)-1)/(z^2-1),z,-1);
(%o2) 0
And wrong again! BTW all (well, actually I haven't checked all, :-)) the particular cases are correct:
(%i1) limit((z^(2*99)-1)/(z^2-1),z,-1);
(%o1) 99
More mystery: the function is even and the other limit
(%i1) limit((z^(2*n)-1)/(z^2-1),z,1);
(%o1) n
Is OK! (even without the declare) Why?

differentiation dependencies

I want to understand how dependencies in Maxima for differentiation work
for iterated cases.
I tried here:
(%i1) depends([f],[x,y]);
(%o1) [f(x,y)]
(%i2) depends([g],[x,y]);
(%o2) [g(x,y)]
(%i3) depends([x,y],[ε]);
(%o3) [x(ε),y(ε)]
(%i4) diff(g,ε);
(%o4) (g[y])*(y[ε])+(g[x])*(x[ε])
(%i5) h(x,y):=f(x,y)+g(x,y);
(%o5) h(x,y):=f(x,y)+g(x,y)
(%i6) diff(h(x,y),ε);
(%o6) g(x,y)[ε]+f(x,y)[ε]
(%i7) diff(h,ε);
(%o7) 0
In (%o4) I get the total derivative with respect to \epsilon. Whereas in (%o6) the derivatives of x and y with respect to \epsilon are not shown. Why?
And can I make Maxima to show these derivatives in the result?
Dependencies declared by depends are only recognized for symbolic, undefined functions. The dependency is associated with the function name (a symbol).
A function with an actual definition, as defined by := or define, is not recognized. The body of the function could contain any combination of other functions, so the only way to know on which other functions the function depends is to evaluate the function body. That is what is happening when you write diff(h(x, y), ε).

how to avoid sign error in symbolic integration

In the script below gg(t) is the standard Gaussian function, and hh(u) is its Fourier transform. I am calculating the energy both in t and u domains and try to verify that wxmaxima (17.10.01) gives the same. When calculating the energy in u domain the magnitude is correct (the same as in 't', %o4) but the sign is negative (%o6), which is wrong. How can I avoid the error?
(%i1) gg(t):=1/(σ*sqrt(2*%pi))*exp(-(t-t_0)^2/(2*σ^2));
(%o1) gg(t):=1/(σ*sqrt(2*%pi))*exp((-(t-t_0)^2)/(2*σ^2))
(%i2) ee(t):=exp(-%i*2*%pi*u*t);
(%o2) ee(t):=exp((-%i)*2*%pi*u*t)
(%i3) hh:integrate(gg(t)*ee(t), t, -∞,∞);
"Is "σ" positive or negative?"p;
(hh) %e^(-2*%pi^2*u^2*σ^2-2*%i*%pi*t_0*u)
(%i4) integrate(abs(gg(t))^2, t, -∞,∞);
"Is "σ" positive or negative?"p;
(%o4) 1/(2*sqrt(%pi)*σ)
(%i6) kk:abs(hh)^2;
integrate(kk, u, -∞,∞);
(kk) %e^(-4*%pi^2*u^2*σ^2)
"Is "σ" zero or nonzero?"n;
(%o6) -1/(2*sqrt(%pi)*σ)
--> ;

side-effects using declare(var,constant) in Maxima

In maxima, is the following behavior intended?
First example:
(%i1) declare(a,constant);
(%o1) done
(%i2) constantp(a);
(%o2) true
(%i3) square(a):=a^2;
define: in definition of square, found bad argument a
-- an error. To debug this try: debugmode(true);
(%i4) load("linearalgebra.mac");
define: in definition of dotproduct, found bad argument a
-- an error. To debug this try: debugmode(true);
Second example:
(%i1) a:5;
(%o1) 5
(%i2) constantp(a);
(%o2) true
(%i3) square(a):=a^2;
2
(%o3) square(a) := a
(%i4) square(a);
(%o4) 25
Third example:
(%i1) declare(a,scalar);
(%o1) done
(%i2) mat_f(a,b):=a.b - b.a;
(%o2) mat_f(a, b) := a . b - b . a
(%i4) mat_f(matrix([1,2],[3,4]),matrix([3,4],[1,2]));
[ - 10 - 14 ]
(%o4) [ ]
[ 6 10 ]
It seems like declare(a,constant) has a global effect which to me seems strange in maxima. The second and third example work exactly how I would expect it.
Also are there any similar cases where something like this happens in maxima?
Maxima has a very weak notion of scope. Essentially all symbols are in the same scope, so when you make a declaration about a, it is about all instances of a, even the ones which are function arguments.
Maxima is actually a very old program and this is one of those aspects which has never been updated. There is discussion about giving Maxima a stronger notion of scope, but that will take some time.

How to force 0^0 be 1 in Maxima?

It is suitable in many series and polynomials to treat 0^0 as 1.
Unfortunately, Maxima think it is expt.
How to force?
Try this. Use tellsimp to define a different rule for the simplification of 0^0.
(%i1) display2d : false $
(%i2) simp : false $
(%i3) tellsimp (0^0, 1);
(%o3) [\^rule1,simpexpt]
(%i4) simp : true $
(%i5) 0^0;
(%o5) 1
(%i6) sum (k^k, k, 0, 5);
(%o6) 3414
Note that you must disable simplification (via simp:false$) before defining the rule, otherwise the default simplification (which triggers an error) is applied.

Resources