Carl Love

Carl Love

26488 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

As nm and acer have explained, the difference that you're seeing is not due to a difference between map and ~ but due to the difference between matrix/vector multiplication in the old linalg package vs the modern A.B. However, there are two differences between map and that average users should be aware of:

  1. can only map over lists, sets, rtables (which includes Vectors, Matrixes, and Arrays), and tables (I'll call these the neutral containers for the rest of this post); whereas map can map over almost any composite structure (functions, polynomials, etc.). Function arguments that aren't one of those types get treated as singletons. Example 1a: Let L be a list of pairs with each pair being a list; then op~(2, L) returns the same as map2(op, 2, L). Example 1b: The list of prime factors of any integer n is returned by op~(1, ifactors(n)[2]). In both these examples, the first argument of opor 2, is being ignored by (and still seen by op).
  2. map only maps over one object; whereas ~ maps simultaneously over all neutral containers that appear as arguments as long as their sizes (and sometimes shapes) conforms. Example 2: f~([1,2], 3, {a, b}).

 

Any plots of the same number of dimensions (either 2 or 3) can be combined into a single plot with the command plots:-display. The plots don't need to have anything in common other than the number of dimensions. So, you could do this:

p1:= plots:-arrow(...);
p2:= plots:-arrow(
...);
p3:= plots:-arrow(
...);
plots:-display(p1, p2, p3, 
...);

where the ... in the arrow commands represents exactly the arguments in your posted worksheet, and the ... in the display command represents possible other options that would apply to the plot as a whole (such as scaling= constrained). The above could also be done as

plots:-display(
    plots:-arrow(
...),
    plots:-arrow(
...),
    plots:-arrow(
...),
    ...
);

I didn't see any vector field defined in your worksheet; however, if there had been, you could use one the several commands for plotting vector fields (such as plots:-fieldplot3d) and include that in the display command.

All the information is in the paper, but the portion that you showed only gives this obviously periodic function:

x:= t-> exp((cos(t)-cos(T))/4);

They say T=Pi/2t>T, and gamma=0.4 (although your screenshot doesn't show where gamma is used). We can plot x like this:

T:= Pi/2:
plot(x(t), t= 1..24, view= [1..24, -0.2..1.8]);

All that you need is 

[entries](op~(1, ListTools:-Classify(O-> O:-sol, SOL)), nolist);

Even behind the scenes, Classify only does a single pass through the list.

Also, you can eliminate the problematic building of a list one element at a time yet still use a list like this:

restart;
ode_solution_type:= module()
    option object;
    export sol:= (), stuff;
end module:

SOL:= [
    for n to 5 do
        tmp:= Object(ode_solution_type);
        tmp:-sol:= y(x)=`if`(n=3, 1, 0);
        tmp:-stuff:= rand();
        tmp
    od
]:

As I told you a day or two ago:

Theorem: If the prime factorization of n is n = p1^e1*p2^e2*...*pb^eb, then its number of proper divisors is 
(e1+1)*(e2+1)*...*(eb+1) - 1.

Note that this number depends only on the exponents, not the prime factors.

This can be encoded in Maple 13 as a one-line procedure:

NPropDivs:= (n::posint)-> `*`((op~(2, ifactors(n)[2])+~1)[]) - 1:

Or you can use the command

numtheory[sigma][0](n) - 1;

Or Tom's method can be extended to arbitrary positive integers as

combinat:-numbcomb((`$`@op)~(ifactors(n)[2])) - 1;

Although it's kind of roundabout, it's still orders of magnitude faster than what you're doing. 

As we've discussed before, you are a Moderator. The editing privilege is reserved for Moderators, who are presumed to be responsible enough to use it with discretion and moderation. 

In addition to the situations mentioned by dharr, there are numerous others where editing should be done. All of these are commonly occurring, not things I'm making up:

  1. There are a huge number of blank lines in the post, often so that the entire first screen is blank.
  2. The entirety of the post is typed into the title box and the main body is blank or nearly blank.
  3. The product specifier is wrong or absent or all possible boxes have been rudely checked.
  4. The post has been misclassified as Post, Question, Answer, Reply.

Several high-profile crowd-sourced information sites, such as StackExchange and Wikipedia, use a system where contributors gradually gain trust and editorial abilities. 

The problem that you have displaying n:= 2^(2^26)+1 is only a limitation of the prettyprinted GUI display; it's not a computational limitation of Maple. If you suppress the display, Maple can compute the number in 16 milliseconds. Then it can be converted to a string of ~20 million base-10 digits in 4 seconds. Then you can easily display any substring of those digits. Or you can skip the string conversion steps and get any subsequence of the digits through pure arithmetic:

#The % signs below are only needed to get an accurate timing;
#they aren't needed to do the computation:
N:= CodeTools:-Usage(value(2%^(2%^26)%+1)):
memory used=16.06MiB, alloc change=16.01MiB, 
cpu time=16.00ms, real time=12.00ms, gc time=0ns

#Make base-10 string:
DN:= CodeTools:-Usage(cat("", N)):
memory used=0.99GiB, alloc change=0 bytes, 
cpu time=3.91s, real time=3.93s, gc time=0ns

L:= length(DN);
                         L := 20201782

#The millionth digit and the 100 following digits:
P:= 10^6..10^6+100:
DN[10^6..10^6+100];
"83772626128948024825321458257987526943544879027080675670992321924911766331675065174616704431088906993"

#Same thing done with pure arithmetic:
CodeTools:-Usage(irem(iquo(N, 10^(L-rhs(P))), 10^(rhs(P)-lhs(P)+1)));
memory used=141.49MiB, alloc change=15.26MiB, 
cpu time=469.00ms, real time=479.00ms, gc time=0ns

 83772626128948024825321458257987526943544879027080675670992321924911766331675065174616704431088906993

When working with large objects, it's crucial to suppress the display, because there's no way to interrupt the display phase once the computation phase has ended. This is true even if no output has been displayed yet because the GUI is still figuring out how to format it.

Let and n be positive integers greater than 1, and let be a nonnegative integer. (Without loss of generality, we can further restrict b < a.) Being someone interested in primes, you should prove the following (it's easy):

Proposition: If p = a*n+b is prime, then a and b are relatively prime (i.e., gcd(a,b) = 1).

The statement "All primes greater than 5 are of the form 6*n+1 or 6*n+5" is an easy consequence of this proposition. Another is that 3, 5, 7 is the only possible sequence of overlapping pairs of twin primes, i.e., 5 is the only prime that belongs to two distinct twin-prime pairs.

It's a fairly deep theorem, due to Dirichlet, that if gcd(a,b) = 1, then there are in fact an infinite number of primes of the form a*n+b, and the sum of their reciprocals diverges.

I think that most Maple commands work in Maple Flow. So, since I don't have Flow, I'll show you how to do it in Maple. Let me know if this works for you:

#Generate a random example:
Data:= LinearAlgebra:-RandomMatrix(9,2):

#Compute least-squares fit line:
F:= Statistics:-LinearFit(a+b*x, Data, x);
          F := -27.2507801140355 + 0.668921237072979 x

plot([F, Data], x= (min..max)(Data[..,1]), style= [line, point]);

 

In your PDF followup question, you propose the following solution:

sq:= anything^{-1/2, 1/2}:
subsindets(
    subsindets(expr, sq, e-> _O*e), 
    And(`*`, satisfies(e-> membertype(sq, {op}(e)) and has(e,exp))),
    e-> eval(simplify(sqrt(e^2)), _O= 1)
);

The problem with this is that it leaves some _Os in the result. That's because _O is added to every sqrt but it only gets removed from the sqrts that are paired with exp. The solution is to wrap the whole thing in eval(..., _O= 1)

sq:= anything^{-1/2, 1/2}:
eval(
    subsindets(
        subsindets(expr, sq, e-> _O*e), 
        And(
            `*`, 
            satisfies(
                e-> andmap(membertype, [sq, specop(exp)], {op}(e))
            )       
        ),
        e-> simplify(sqrt(e^2))
    ),
    _O= 1
);

I also corrected your use of has(e, exp), which is incorrect because it finds exps that are inside the sqrts also.

This trick with the _O is specifically to handle the situation that you discussed at length with Edgardo: `*` with only two operands; the _O becomes the implied coefficient 1. Thus, there's no need to treat two operands and more than two operands as separate cases.

And note that anything can only be matched by exactly one operand; it cannot be matched by the absence of an operand or by a sequence of operands. So, I think the above solution is much easier than using any type that begins with `&*`(...and/or is specific to a specific number of operands.

Like this:

restart:
expr:= 
    (-x + sqrt(9*x^2*exp(2*c) + 8)*exp(-c)+99)/(4*x)
    + (a*sqrt(z)-99+sin(c*sqrt(r+4)+20))/3 
    + 10
    + 1/(c+exp(-x)*sqrt(exp(x)))
    + sqrt(h)
:
sq:= anything^{-1/2, 1/2}:
subsindets(
    subsindets(expr, sq, e-> _O*e), 
    And(`*`, satisfies(e-> membertype(sq, {op}(e)))),
    e-> LargeExpressions:-Veil[Z](eval(e, _O= 1))
);

The product of two or more types is not a valid type. That was the cause of your error.

Also, the :: operator has higher precedence than *, so the expression that you used with applyrule needs some parentheses (although I don't know whether that alone is enough to make it work (and I don't really care)).

This display is quite unfortunate!

In a Maple worksheet (I mean not in a tutor), enter

Eval(Diff(ln(x), x), x= x/2);

Observe the output. Do you understand what that output means, especially the part with the vertical bar and the equation written small on the lower right of the bar? Let me know. That same vertical bar appears in the tutor output, but unfortunately it's much shorter than would ever be used in typeset mathematical notation.

Now consider the subexpression Diff(ln(x), x) of the above, which stands for "the (inert) derivative of ln(x) with respect to x." By inert, I mean that it expresses the intention to calculate a derivative without actually doing it. The inertness is just used to make the steps more clear; the derivative is of course computed in a later step. In this subexpression, the x (in both occurences) is what computer scientists and logicians call a bound variable and what mathematicians sometimes call a dummy variable (a term that makes me cringe). This means two things (in this case): 1) That x could be temporarily replaced by any other pure symbolic variable (a variable that has no assigned value); and 2) That x cannot be replaced by something other than a variable, such as a number. So, the tutor's author has decided that the exposition would be clearer if that x were temporarily replaced by _X0. I find this to be an unfortunate choice, but note that this is just another variable and the underscore has no computational meaning; it's just like any other letter in a variable name. When a Maple programmer makes up a variable that will appear in output, they usually begin its name with underscore (this is just a widely followed convention; Maple itself could care less), although these underscores can cause confusion to new users. For use in a calculus tutor, I think that u would've been a more understandable choice.

Have you learned yet the "chain rule" for derivatives? It's the rule for the derivative of compound functions such as f(g(x)). Specifically it says that the derivative with respect to x of f(g(x)) is f ' (g(x))*g ' (x) or in Maple notation
Diff(f(g(x)), x) = Eval(Diff(f(u), u), u= g(x))*Diff(g(x), x) 
In your tutor example, this rule is being applied to ln(x/2) with f(u) being ln(_X0) and g(x) being x/2.

Your usage of a*b is problematic because of this:

has(a*b*c, a*b);
                             false

Neither your solution nor Kitonum's nor nm's will work if your expression contains a*b*c. So, I'd do this:

select(t-> has(t,a) and not has(t,b), [op](_x+f));

The _x is needed in case f is a single term.

 

You can use cat to create a list of every possible one- or two-letter Excel column label in order like this:

my_alph:= [seq](cat(("A".."Z")$k, 1), k= 1..2):
27*26 = nops(%); #for verification only
                           
702 = 702

Like this:

expr := piecewise(x(t)<0, -1, x(t)<1, 0, 1) + f(t) + 
    piecewise(t<0, 0, t<1, 1, 0) + 
    x(t)*piecewise(t<0, 1, t<1, 0, 1) + 
    a*piecewise(t<0, 3, t<1, -1, 2)
:
OneVarPW:= proc(e::`+`, t::name)
local 
    v:= indets(e, And(name, Not(constant)))
        union 
    op~(0, indets(e, typefunc(anything, And(name, Not(mathfunc)))))
;
    select(hastype, [op](e), specfunc(freeof(v minus {t}), piecewise))
end proc
:
OneVarPW(expr, t);

In Maple 2021, typefunc(anything, ...) can be abbreviated to typefunc(...). I don't know whether this can be done in Maple 2015.

Type freeof is essentially the negation of type depends. My formulation above excludes all possible "variable" names other than t and mathfuncs whose arguments only depend on t. A "mathfunc" is one of Maple's standard defined functions (sinlnGAMMA, etc.). So, my formulation doesn't require your x to be specifically mentioned; since x is neither t nor a standard function name, both x(t) and "naked" x are excluded.

Note that if is anything other than anything or NULL, then
select(hastype, ..., specfunc(T, piecewise))
cannot be replaced by
select(has, ..., piecewise),
as was possible for Preben's Answer.

First 49 50 51 52 53 54 55 Last Page 51 of 382