Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

You have two problems. The first is trivial: In two places you typed StringTools*IsPrefix instead of StringTools:-IsPrefix.

The next problem is very subtle, and it shows why it is dangerous to use logical operators in prefix form. By prefix form, I mean `implies`(a,b). The safer form is the infix form a implies b. With the infix form, the McCarthy evaluation rules apply (look up "Short-circuit evaluation" in Wikipedia); with the prefix form, all arguments are evaluated. That leads to an error in your case: If P[x] is not assigned, then it is not legal to evaluate the second part of the implies.

Here's an example illustrating the McCarthy rules. The procedure F below just prints a message and returns 0. Thus we can see how many times it is called. The example below must be run in 1D input or CLI.

F:= proc() print("In F."); 0 end proc:

evalb(F(1)=1 implies F(2)=0);

                            "In F."
                              true

So F was only called once, because the truth of the proposition can be determined simply from the antecedent. Now do essentially the same thing with prefix form:

evalb(`implies`(F(1)=1, F(2)=0));
                            "In F."
                            "In F."
                              true

F gets called twice.

Here is your code which I corrected and indented and to which I added a few abbreviations.

macro(ST= StringTools):
Strings:= {
   "buffalo", "zebra", "aardvark", "aardwolf",
   "anteater", "antelope", "bumblebee"
};
CP:= {seq(seq(ST:-Take(x, ST:-CommonPrefix(x, y)), x in Strings), y in Strings)};
P:= table(Strings =~ "");
for x in CP do
     for y in CP minus {x} do
          if ST:-IsPrefix(y, x) and
               (assigned(P[x]) implies ST:-IsPrefix(P[x], y))
          then
               P[x]:= y
          end if
     end do
end do;
P = eval(P);

We can get Maple to do a proof by induction that x_n is rational for all n.

Base case (n=1):

x_1:= 1:
is(x_1, rational);

     true

Induction hypothesis: Assume the proposition is true for some n:

assume(p::integer, q::integer):
x_n:= p/q:
is(x_n, rational);

     true
Induction step: Prove it true for n+1:

R:= x-> 1/2*(x + 3/x):
is(R(x_n), rational);

     true

Thus x_n is rational for all n.

 

Some tips on your Maple syntax:

1. The name x_n is just a simple variable name. The n is not a distinct part of it. Thus you can't substitute for the n. If you want an indexed variable, use x[n] or x(n). Likewise, x_n-1 means 1 less than x_n.

2. Assignment statements are done with := not =    
     x_1:= 1;  (right)
     x_1= 1; (wrong)

3. There is no reason to use evalf in code like this; evalf is for decimal approximations.
   

Look for a command Student:-Calculus1:-RiemannSum. I don't know if it was available in Maple 13. It can handle arbitrary partitions, like this

Student:-Calculus1:-RiemannSum(
     x^3, x= 1..5, partition= [1, 1.3, 2.7, 3.6, 4.2, 5], method= midpoint
);

 

The following procedure will return two large well-separated randomly generated primes. Multiplying them is trivial. The parameter is the approximate number of bits in their product.

TwoPrimes:= proc(bits::posint)
local b:= max(2, iquo(bits,2));
     randomize();
     numtheory:-safeprime(rand(2^(b-2)..2^(b-1))()),
          numtheory:-safeprime(rand(2^b..2^(b+1))())
end proc:

p,q:= TwoPrimes(256);

n:= p*q;

 

m:= 2:  n:= 2:
combinat:-permute([1$n, 0$m]);

Since velocity = sqrt(2 * kinetic_energy / mass), I'd guess that T is kinetic energy and V0x is initial velocity in the x direction.

If you look at the code for the procedure Matrix, you'll see that it is very long because it deals with the vast number of different user input forms that can be used with command Matrix. Hence it is faster to use the builtin rtable and convert the result to a Matrix. However, that answer does not explain why the author did not simply include the option subtype= Matrix to the rtable command.

Here's how to ask that in Maple:

is(cos(theta/2) < 0) assuming Pi/2 < theta, theta < Pi;

     false

Hint for the explanation: What quadrant is theta in? So what quadrant is theta/2 in? Can you fill in the dots in this three-part inequality: ... < theta/2 < ...?

The Answer by Georgios shows a fine way to accomplish the same thing without using a for loop.  Instead, I'll correct your code directly. Your foremost problem is that you omitted the word do, which should be part of the for clause. Your next problem is that if you want to use 1-dimensional indexing on a multi-dimensional Matrix or Array, then you need to address the elements as A(k) rather than A[k]. Your next problem is that you switched the indexing variable from i to k. Your final problem is that assignment statements are done with := rather than simply =. Putting that all together, the code should be

for k from 1 to 9 do
     if A(k)=1 then
          A(k):= 0
     end if
end do;

That being said, there are much better ways to accomplish the same thing, as shown in Georgios's Answer.

The angles passed to the arc command should be in radians. You have converted the finishing angle to degrees. 

You can restrict input to any predicate by using satisfies:

f:= (x::satisfies(x-> x>0 and x<1))-> x^3 + (1-x)^3;


Note that it is not proper to code a procedure using

f(x):= ....

The correct syntax is

f:= x-> ...

or

f:= (x:: ... )-> ....

 

 

Yes, the command is PDEtools:-difforder.

You need to explicitly put a multiplication symbol between x and y, and between 3 and x:

implicitplot(x^3+y^3-3*x*y=0,x=-3..3,y=-3..3, scaling=constrained);

Change and to a semicolon (;). Put a colon (:) or semicolon after the end do.

Acer's answer explains why your A3 doesn't work. I will explain why your A2 doesn't work. A2 will match expressions that literally contain `or` and whose left argument is integer and whose right argument is rational. (Since `or` will reject as erroneous any explicitly non-Boolean input such as numbers, this type can never be matched.)

Here's an example of a valid use of lowercase or as a type:

TypeTools:-AddType(A2, symbol or indexed):
type(y or s[2], A2);

     true
type(s[2] or y, A2);
    
false

First 283 284 285 286 287 288 289 Last Page 285 of 395