Carl Love

Carl Love

27343 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@nm 

For this Reply, let f be anything that can be a function[*1] name (formally, a function's 0th operand, which can be almost anything, not just a name), and let type1type2, etc., be any types. Then the following are also types:

  • f(type1) is a type that matches any function that has exactly 1 argument, that argument is type type1, and whose 0th operand is identically f.
  • f(type1, type2) is a type that matches any function that has exactly 2 arguments, the 1st of type type1 and the 2nd of type type2, and whose 0th operand is identically f.
  • f(type1, ..., type_n): The above pattern can be extended to any specific number of typed arguments.
  • f() is a type that matches only the identical expression f().
  • specfunc(type1, f) is a type that matches any function of any number (including 0) of arguments whose 0th operand is and all of whose arguments are type type1.
  • In modern Maple, specfunc(f) is equivalent to specfunc(anything, f).

Thus 'exp'(anything) is more precise than specfunc(exp) because the latter can have any number of arguments.

[*1] To learn the meaning of function in Maple, see the help page ?function. The help page ?type,function is nearly worthless and should be rewritten from scratch.

@Axel Vogt By "works for me", do you mean that the integral finishes, or that the timeout error was trapped (so, you got the output "waiting for timeout")? The point of this Question is to test the timelimit command, not to test int.

Changing 40 seconds to 5, I got it to hang. I do not have Physics Updates installed.

@Alfred_F The easiest way to get some information about what's going on is to set the infolevel. This gives a relatively small amount of info (compared to other ways in Maple), but it's high-quality info because it's formatted details put in the code by its author specifically for you to read. The following returns about 4 screenfuls of info for this problem.

 

restart:
infolevel[all]:= 5:
[y, s, x, a, b, c, d]=~ (simplify@eval)(
    [sqrt(a^2+b^2), d-b, sqrt(a^2+d^2), a, b, d, b],
    solve(
        {
            d-b = c-d, a/d = tan(45*Pi/180), a*(c-b)/2 = 60, a^2+c^2 = 19^2,
            (a,b,c,d ) >~ 0
        }, 
        {a,b,d,c},
        explicit
    )
);

The is the level of detail; it could be any positive integer. Usually 5 is the most detail, but that's up to the code's author. The all sets this for all Maple procedures. It could also be a specific command, such as solve.

If you run something, and then want to rerun it with infolevel turned on, make sure to do a restart first. This is to prevent Maple from simply remembering recently done computations and not actually redoing them.

As far as I can tell, the worksheet that you posted has no code, only components. I looked for hidden "startup code" and "component code" but didn't find any. However, I admit that I don't know much about finding component code.

@Thomas Richard 

plots:-spacecurve(
    [t*cos(t), t*sin(t), 2/3*sqrt(2)*t^(3/2)], t= 0..Pi,
    color= black, thickness= 5,
    axis[1]= [color= red, thickness= 3, tickmarks= [-2,2]],
    axis[2]= [color= green, thickness= 3, tickmarks= [-2,2,4]],
    axis[3]= [color= blue, thickness= 3, tickmarks= [2,4,6,8]],
    labels= ['x', 'y', 'z'], labelfont= [helvetica, bold, 14],
    axesfont= [helvetica, 12],
    view= [-3..3, -2..4, -1..8], scaling= constrained, axes= normal,
    projection= .7, orientation= [45, 85, 0]
);

If one is building an AI system capable of solving math word problems, then after the system has translated the problem from natural language to mathematical language (such as algebra), it still needs to know how to enter the problem into Maple (or other CAS). That step---translating from mathematical language to CAS input---is not trivial, even if the work that the CAS needs to do after receiving the input is trivial.

This is an excellent problem for testing or training such a system.

Furthermore, the Maple input needed to solve this isn't trivial, even if the computation that Maple does is. An "epsilon" such as vv used is needed.

@Andiguys To get a plot, you'll need some points where Maximize has actually done something, rather than saying "no improved point could be found."

@sursumCorda The true result returned by coulditbe in this case may simply be due to the incorrect result from solve, so I wouldn't judge it too harshly based on this example alone. Still, it would be preferable for it to return a witness.

@Christian Wolinski I don't understand the point that you're trying to make. Could you explain further?

My point is that solve(sys, {p}) returns an incorrect result--one that returns false when substituted back into sys. The fact that solve(sys, {q}) and solve(sys, {p,q}) return correct results is irrelevant (to my current point, but not irrelevant to the overall problem). I obtained the sys immediately above as a pared down case only for the purpose of submitting a bug report. The sys from the OP's actual problem (one of the 98) was actually

sys:= {
    p^2*q^2-4*q^3 = 0,  2*p^5-15*p^3*q+27*p*q^2 <= 0,
    p < 0, -q < 0, -q^2 < 0, -2*p^2+3*q < 0, -p^2+3*q < 0
}:

@segfault Many procedures in the Maple library (and there are many thousands) are short (say, 5 t0 20 lines) and written in fairly easy to understand Maple. As you read these, you will encounter a few unfamiliar commands, such as `tools/genglobal`. If you're reading a procedure that has many unfamiliar commands, you should probably move on to an easier procedure.

The command LibraryTools:-Browse gives you convenient access to all procedures in the library that are written in Maple, which is the vast majority.

The following is a learning exercise that I devised and practice very frequently. There is no better way to learn a computer language:

  1. Find a procedure or other code written by someone else that seems bloated, overwritten, or hard-to-read, etc. Your goal is to simplify this code (without changing its output). Numerous examples can of course be found here on MaplePrimes. The best examples are procedures that have repeated subexpressions. Your goal then is to remove as much repetition as possible. Also, remove unnecessary parentheses.
  2. It would be best if you only have a very vague idea of the purpose of the code. This forces you to only make small changes rather than doing a top-down rewrite. But, you may make a great many very small changes.
  3. If the code has comments or the author has said something about it, ignore it. Assume (for the time being) that they are likely mistaken. However, assume that the code does something useful (that you don't understand) for somebody and does it correctly. Obviously, this means that you can't practice this exercise on code that has syntax errors, doesn't compile, etc.
  4. For each small change that you consider making, ask yourself whether there's any possibility that the code change could change the output. If your answer is "No", make the change. If you can't answer it, run some small test cases of the same small change by itself in some other area than the main code (such as in a scratch worksheet). You don't need to prove mathematically that the code change won't change the output; empirical evidence is enough. Reading help pages is fine at this point.
  5. For every small change, check that the code is still syntactically correct. In Maple, you just need to press Return to do this. This makes Maple an excellent learning environemnt.
  6. Every few minutes, check that the code still produces the same output.

@segfault Just stop using the procedure and it will revert.

@nm Thanks, I understand now,

Please point  out which RootOf needed to be evaluated twice and repost the worksheet with that RootOf hightlighted.

@sursumCorda No, the bug is in solve, as my Answer clearly shows. RealDomain:-solve is just repeating what it got from solve. If you filed a report against RealDomain:-solve, you should amend it. And I hope you didn't include your whole problem in the report. The complete bug is shown by this simple example:

sys:= [p^2-4*q = 0, 2*p^5 - 15*p^3*q + 27*p*q^2 < 0]:
solve(sys, {p});
               /        (1/2)\    /       (1/2)\ 
              { p = -2 q      }, { p = 2 q      }
               \             /    \            / 

eval(sys, [q=1, p=2]);
                        [0 = 0, -2 < 0]

It could be that inequalities with high-degree polynomials are being ignored by solve.

There was no good reason to use RealDomain:-solve. If there are no complex solutions, then there are no real solutions either. It is IMO one of the most frequently misused commands in Maple.

When coulditbe returns true or is returns false, they don't provide witnesses. This alone makes them nearly impossible to trust. The much-more-sophicated command QuantifierElimination:-QuantifierEliminate provides witnesses.

Anytime that you have a combination of algebraic relations and logical operators, you should put it in DNF before procveeding.

@nm I'm glad that you know about `tools/genglobal`; vote up.

I don't intend to sound harsh or critical; I just want you to understand this difference between indets and evalindets or subsindets.

Although your Answer above works well, in light of the other "evalindets vs. indets" Reply that I just posted, I take this as further evidence that you've somehow switched the meanings of evalindets and indets in your mind. Specifically, the evidence in this case is that these 3 lines from your procedure above:

C_used:= indets(sol, And(symbol, suffixed(c__,  nonnegint))):
my_C := map(X-> X = `tools/genglobal`(c__), C_used):
eval(sol, my_C);

do exactly the same thing as 

evalindets[flat, 2](sol, suffixed(c__, nonnegint), c__, `tools/genglobal`);

The process requested in this Question is not simply to find the constants (for which indets works great), but to find and replace them, which is a task for evalindets or subsindets.

1 2 3 4 5 6 7 Last Page 3 of 701