Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 361 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

I've added some features to LinearCombo based on user requests. The first is that parameters are now allowed:

LinearCombo([a*x+b*y, x^2+a*y], x^2+x+y, params= {a,b});

The params argument is optional, and, if present, it must be a set of names. A true result indicates that the returned coefficients form a linear combination for all values of the parameters. A false result indicates that there are no such coefficients. This is very different from finding the values of the parameters for which there is linear dependence or independence.

The second change is that the returned value is now always a pair. The first member of the pair is a trivalent Boolean value (i.e.truefalse, or FAIL), and the second is the list of coefficients. Note that in the vast, vast majority of cases a false result is correct and thus the returned coefficients are meaningless. In case the returned value is false, [], the result is guaranteed.

LinearCombo:= proc(B::list(algebraic), T::algebraic, {params::set(name):= {}})
local
     V:= indets([B,T], And(name, Not(constant))) minus params,
     nV:= nops(V),
     c, #linear coeffiecients
     k, #index
     nB:= nops(B),
     C:= [c[k] $ k= 1..nB],
     Eq:= `+`((C*~B)[]) - T,
     Eqs, S, Z
;
     for k to 2 do
          Eqs:= {'eval(Eq, V=~ {'rand()' $ nV})' $ nB};
          if nops(Eqs) = nB then break end if;
     end do;
     if k = 3 then
          error "Almost certainly, all expressions are constant"
     end if;
     S:= solve(Eqs, {C[]});
     if S=[][] then return false,[] end if;
     Z:= indets(rhs~(S), And(name, Not(constant))) minus params=~ 0;
     S:= eval(S,Z) union Z;
     is(eval(Eq,S) = 0), simplify(eval(C,S))
end proc:

@erik10 

The following seems too trivial to post, but maybe it was what you had in mind:


restart:

TwoDice:= {combinat:-permute([$1..6, $1..6], 2)[]};

{[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6]}

H:= select(x-> `+`(x[]) = 5, TwoDice);

{[1, 4], [2, 3], [3, 2], [4, 1]}

G:= select(x-> x[2] < 3, TwoDice);

{[1, 1], [1, 2], [2, 1], [2, 2], [3, 1], [3, 2], [4, 1], [4, 2], [5, 1], [5, 2], [6, 1], [6, 2]}

#Complement function:

C:= A-> TwoDice minus A;

proc (A) options operator, arrow; `minus`(TwoDice, A) end proc

#Probability function:
#Use two arguments for conditional probability.

p:= proc(A::set, B::set:= TwoDice)
     nops(A intersect B)/nops(B)
end proc;

proc (A::set, B::set := TwoDice) nops(`intersect`(A, B))/nops(B) end proc

p(H);

1/9

p(G);

1/3

p(H union G);

7/18

p(H intersect G);

1/18

p(H,G);

1/6

p(G,H);

1/2

#Law of total probability illustration

p(H) = p(H,G)*p(G) + p(H,C(G))*p(C(G));

1/9 = 1/9

 


Download prob.mw

@Axel Vogt I decided to avoid the issue of cases and dependencies by using assuming real.

Did you know that you can do a parameter-case analysis of a definite integral by including the option AllSolutions? For the problem at hand, this gives very lengthy and wide output for the first integral, with many invocations of piecewise. I didn't do it for the second integral.

@Axel Vogt 

Absolutely. Despite numerous attempts, Markiyan has come up with only one example of a transcendental identity for which the program returns FAIL, which, as I've said, is unfortunate but not incorrect. (And my computer with Maple 18 returns successfully for that identity. I don't know why his is returning FAIL.) (And since when do we expect Maple programs to return a definite answer for all transcendental expression input?) For the four other example that he posted where he thought that my program was wrong, it turns out that the program was correct.

I've tested the program extensively on polynomials (up to 36 polynomials in three variables), and less extensively on transcendental identities involving sincos, and exp, including ones with complex coefficients (e.g.LinearCombo([sin(x), cos(x)], exp(I*x))). It could use more testing on algebraic and rational functions.

It seems like Markiyan is compelled to poison the well.

@Kitonum C'mon, now: That's a vast overstatement of the power of the power of identify. It really only knows a few transcendentals: Piln(2), ln(3), exp(1)Zeta(3), and Zeta(5). You can teach it others (see ?identify), but that means that you need to have a guess of the basis transcendentals in your expression.

@MDD As my program is currently written, it treats all nonconstant names as variables. I'll have to make some modifications for it to be able to treat some as parameters. I'll work on it this evening.

@Markiyan Hirnyk 

You already presented that example in your Reply "Still". The answer FAIL is unfortunate, but not incorrect. (It's also the fault of is so not really about my program.) So this is not a "counterexample". Like I said (three times now), I never claimed that this program works for all transcendental expressions. Even so, you have yet to come up with a single instance where my program returned incorrect results. If you think my program is so bad, can you name any other program or algorithm that finds the linear coefficients for transcendental identities?

So how about a polynomial example? 

@MDD I am sorry that you got an error. Your error is caused by Maple's acursed 2D input. Your error would go away if you use 1D input. I am by no means an expert on 2D input, so I can't tell you how to correct this if you want to continuing using 2D input. Maybe an expert on 2D input will chime in here.

One option other than 1D input would be to cut and paste my code into a plaintext file and then use the read command with that file's name.

@Markiyan Hirnyk What? How is that a counterexample?? What are the coefficients that make it a linear combination?? You might as well say that 2*x+y+1 can be expressed as a linear combination of x+1 and y. You can't express an arbitrary three-term polynomial as a linear combination of only two basis elements!

@Markiyan Hirnyk 

You need to set the environment variable _EnvTry:= hard. (This is documented briefly at ?is.) If do this and retry your example, then you'll get coefficients which will simplify to 1.

Nonetheless, you'll always be able to come up with more and more convoluted examples of transcendental identities for which FAIL or even false are returned, even with _EnvTry set to hard. This is a result of a long-standing deficiency of is, which affects many areas of Maple. This deficiency has been the subject of extensive debate here on MaplePrimes in recent months, as I'm sure you're aware.

Remember that this program is primarily intended for polynomials. (I never claimed that it would work for all transcendental expressions, just that the class of expressions for which it works is much larger than simply polynomials.) I'll be really impressed if you can come up with a polynomial example where my program returns FAIL or incorrectly returns false. Such polynomials would need to have very convoluted transcendental coefficients with some unresolved (and unresolvable by is) identity lurking in the coefficients.

@MDD 

Well show me the error! What's the point of saying "there is an error" if you don't show the error?! If you have a Maple version earlier than 13, then I know what the error is. If so, let me know, and I'll give you another version.

@Markiyan Hirnyk 

Thank you for testing my program. You have come up with some great examples that illustrate its power, and you've also verified that it works well in conjunction with assuming. Indeed, in all three of your test cases, my program returns the correct and expected results. In the your first two test cases, the desired identity is indeed false unless you make some assumptions. In your third test, the returned coefficients are identically equal to 1, although in a complicated form. You just need to use simplify to verify that.

I did make a change to the program (in anticipation of your next test, which would've produced an incorrect result), so please download a fresh copy from the Answer.

 

@Markiyan Hirnyk 

Thanks. It's fixed now. Somehow two cut-and-pastes got merged.

@Preben Alsholm 

Thanks, Preben. It's a lot to absorb. To further my understanding of these steps, would you mind completing these steps just for the epsilon = 0 case, for which we know there's a nice solution? That is, take the ODESOLStruc (with epsilon=0), solve the first-order ODE with dsolve, do the integration, and invert the function to obtain something akin to the nice solution? I can do the dsolve and the int, but not the inversion.

@Carl Love 

I don't know the small parameter method, but I guess that you start with a solution for epsilon = 0For what it's worth, Maple has a nice compact symbolic solution for that:

dsolve(eval(eq, epsilon= 0));

     x(t) = _C2*sqrt(2)*sqrt(1/(_C2^2+1))*JacobiSN(((1/2*I)*sqrt(2)*t+_C1)*sqrt(2)*sqrt(1/(_C2^2+1)), _C2)

And Maple even has a sort of symbolic solution for the fully parameterized equation:

dsolve(eq);

     x(t) = _a &where
           [{(diff(_b(_a), _a))*_b(_a)-_b(_a)*_a^4*alpha*epsilon
                +_b(_a)*beta*epsilon+_a^3-_a = 0},
            {_a = x(t), _b(_a) = diff(x(t), t)},
            {t = Int(1/_b(_a), _a)+_C1, x(t) = _a}]

I don't know what this means, and I was hoping that someone here could explain it to me. In particular, What does it mean that _a appears as both the dependent variable and as an independent variable? Why is there no _C2? How can this solution be used? Why is it better than just giving no solution?

First 481 482 483 484 485 486 487 Last Page 483 of 709