_Maxim_

729 Reputation

12 Badges

8 years, 327 days

MaplePrimes Activity


These are replies submitted by _Maxim_

@ecterrab

Out of curiosity, can it be done by making the indexing function generate procedures?

`index/Vi` := (ind) -> (() -> ind(args));
V := table(Vi);

V[f, g];
                            V[f, g]
%(a, b);
                       [f(a, b), g(a, b)]

So the actions that need to be executed would go into the outer procedure (ind)->... .

 

@Firehawk120

Something like this, perhaps:

applyrule(p::polynom(numeric, w)^k::integer = 'expand(p/lcoeff(p, w))^k*lcoeff(p, w)^k',
  2177.835*cos(w*t)/(1000.*w^2-8118.)+96.6944*cos(1.971674416*t)/(80.*w^2-311.));

     2.177835000 cos(w t)       1.208680000 cos(1.971674416 t)
 ---------------------------- + ------------------------------
              2                               2               
 1.000000000 w  - 8.118000000    1.000000000 w  - 3.887500000 

Note that applyrule keeps doing the replacements until the result no longer changes. And, unfortunately, there is no function that would apply the replacements once. I tested it, but still there is a risk of a runaway evaluation for some particular input. So caveat usor.

 

P.S. ?lcoeff does say that the polynomial must be collected first wrt the variables, but that note seems to be obsolete.

 

@Carl Love

I'm seeing this:

proc (e) options remember, system;
assigned(`property/ParentTable`[e]) or
  type(e, {('And')('complexcons', ('Not')('infinity')), ('specfunc')('property', 'Non'), 'AndProp',
    'OrProp', 'type', 'EvalfableProp', 'LinearProp', 'ParamProp', 'PropRange', 'RealRange'}) or
  type(e, 'function') and map(type, {op(e)}, 'property') = {true} or e = 'natural' end proc

So it looks like type(e, `type`) is a sufficient condition, so acer is right and the ?property page is overcautious where it says "most types".

 

@Carl Love

How would you document the "rational as a property"? Is it going to be something like this: 1) all floating-point numbers with zero imaginary part are rational; 2) for exact numeric quantities Maple tries to deduce whether the quantity belongs to the field of rationals?

Perhaps Maple is trying to do something like that now, but it's very hard to figure out exactly what it does:

is(cos(Pi/5), rational);
                              FAIL

is((cos(Pi/5)-1/4)^2, rational);
                             false

 

@tomleslie

Well, let's be careful with our notation. type(x, anything) is a predicate, it cannot be used as a pattern that matches x. Maple does confuse things by allowing x::anything to work both as a predicate in is/evalb and as a pattern in patmatch.

type(x, `=`) is okay, but it's going to evaluate to false prematurely, when x is just the symbol x. You need _type, yet another of Maple's inert constructs.

So, putting it together, an example that works would be applyrule(conditional(x::anything, _type(x, `+`))=0,y+1). And exactly the same example with `=` instead of `+` and (y=1) instead of (y+1) doesn't work.

 

@vv

I don't think is(exp(1)+Pi,rational) giving false is wrong. type/rational isn't "belongs to the field of rational numbers". It checks for type/integer and type/fraction, which, from the documentation, seems more like a syntactic (structural) check, simply verifying that op(0, e)=Integer or op(0, e)=Fraction. So is(sin(1)^2+cos(1)^2,rational) gives false, but it doesn't contradict the documentation.

But Maple tries to do some simplifications, and this is where the issues begin, same as in my example with list(rational): is((2*sqrt(2)+2)/(sqrt(2)+1),rational) gives true, so, according to the documentation, I can use numer to get the integral numerator. No such luck, it gives 2*sqrt(2)+2.

 

@tomleslie

Right, if you fix the variable, say x, and treat the other variable as a parameter, then you just do lcoeff(poly, x). But if you want the multivariate case, then you have to say how you define the leading term. lcoeff(x^2+2*x*y^2, order = plex(x, y)) and lcoeff(x^2+2*x*y^2, order = tdeg(x, y)) are going to be different. (tdeg(x, y) and grlex(x, y) are always the same though.)

Unless you know everything is linear in x and y.

 

I think you want lcoeff(poly, var).

 

@acer

That's amazing. Documentation says only that Or can be used with properties, but now it works with predicates as well (I get the same results).

But Or(pred1, pred2) is different from `or`(pred1, pred2) and clearly different from Or(prop1, prop2).

So there is yet another construct with its own subtly different evaluation rules.

even/odd still fails though.

 

P.S. A way to simplify the arctans:

(simplify@expand@tan)(arctan(sqrt(-b)*v2y, sqrt(-a)*v1y)-arctan(sqrt(-b)*v2x, sqrt(-a)*v1x));
                 (1/2)                         (1/2)
             (-b)      (v1x v2y - v1y v2x) (-a)     
           - ---------------------------------------
                      a v1x v1y + b v2x v2y         

([v2x, v2y] = ±[-v1y, v1x], which is why using arctan(sqrt(-b)*v1y, sqrt(-a)*v1x) also worked, ignoring the sticky issues with the signs and with how we know we're integrating from v1 to v2 in the correct direction).

v1x*v2y-v1y*v2x is Determinant(vv), which is ±1. So the numerator is ± sqrt(Determinant(mm)). The denominator can be written as

<v1x, v2x>+ .<<a|0>, <0|b>>.<v1y, v2y> =

<1, 0>+ .vv.<<a|0>, <0|b>>.vv+.<0, 1> =

<1,0>+.mm.<0,1> = B.

 

@Carl Love

Another attempt to decipher prop1..prop2 then:

"describes a set of objects that includes the set prop1 and is included in the set prop2."

So prop1 ⊆ X ⊆ prop2, but nothing else is known about X. For instance, is((1/2)::(integer .. rational)) gives FAIL.

 

@acer

Thanks, found the page ("description of properties used by assume"). It's more evasive about types being properties though, it says: "(2) most types" :).

The bullet point 8 though...

  • (8) property ranges:  prop1 .. prop2 (where prop1 and prop2 are properties and prop1 is included in prop2.  This property means that the object has at least prop2 but not less than prop1.  For example, integer .. rational properly describes the integers/2.  If A = prop1 .. prop2 then all possible y in prop1 have property A, and all possible z in A have property prop2.

This is beyond insane. Does it simply mean to say "the object has prop2 but not prop1"?

 

@Preben Alsholm

Let m = <<A|B>,<B|C>>. Rotate the axes so that exp(<x,y>+.m.<x,y>) becomes exp(a*x2+b*y2). a and b are the eigenvalues of m.

Then make the change of variables x=r/sqrt(-a)*cos(t), y=r/sqrt(-b)*sin(t). The jacobian is r/(sqrt(-a)*sqrt(-b)) = r/sqrt(Determinant(m)).

Integrating exp(-r^2)*r from 0 to infinity is trivial. The question is the t range. The Pi/2 sector of integration lies between the eigenvectors v1 and v2 of m, but t is not the polar angle. Rather, for the endpoint t1, [r/sqrt(-a)*cos(t1), r/sqrt(-b)*sin(t1)] = [v1x, v1y]. So t1=arctan(v1y*sqrt(-b), v1x*sqrt(-a)). To get the correct quadrant, the determinant (+1 or -1) of the transition matrix is needed.

To sum up,

with(LinearAlgebra):

mm := <<A|B>,<B|C>>:
ee, vv := Eigenvectors(mm):
vv := <Normalize(Column(vv, 1), 2, conjugate = false)|
       Normalize(Column(vv, 2), 2, conjugate = false)>:
ss := Determinant(vv):

Int(exp(<x, y>^%T.mm.<x,y>), y = -infinity .. 0, x = 0 .. infinity) =
 1/(2*sqrt(Determinant(mm)))*(arctan(vv[2,2]*sqrt(-ee[2]), vv[1,2]*sqrt(-ee[1])) -
   arctan(ss*vv[2,1]*sqrt(-ee[2]), ss*vv[1,1]*sqrt(-ee[1])))

But there must be some way to "see" that it's simply 1/(2*sqrt(Determinant(mm)))*arctan(sqrt(Determinant(mm)), B).

It will give the correct answer even for Determinant(mm)<0, provided that the integral converges (can happen because we're not integrating over the whole plane).

 

@Carl Love

I see, I suppose that's why evalb doesn't complain about RealRange (just silently removes it when it's inside an infix "and"), but RealRange is not a type with special interpretation rules like Range is:

type(1, RealRange(0, 2));
                             false

type(1, Range(0, 2));
                              true

so it's like real or complex in the sense that it doesn't work as a type in assumptions.

 

First 6 7 8 9 Page 8 of 9