Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@ It's not a bug. The given result is mathematically equivalent to 0 under certain assumptions, which you did not provide. For example, if you specify a simple such as f:= (x,t)-> x-t and include the assumption k > 0, then the pdetest will quickly return [0, 0].

Permutation arithmetic in Maple is quite easy, and it's expressed naturally with ordinary arithmetic operators. Let's use the permutation from your previous Question:

Orb(1):= Perm([[1,4,6,9,10]]):
Orb(2):= Perm([[2,3,5,7]]):
P:= Orb(1) . Orb(2):

Your problem:

P^4567;
           
 (1, 6, 10, 4, 9)(2, 7, 5, 3)

Compare with (note: 4567 mod 20 = 7,  7 mod 5 = 2,  and 7 mod 4 = 3):

P^7;
Orb(1)^2 . Orb(2)^3;

@DanishMapleFan Great. Let me know if you have any trouble with it or questions about it.

It works quite efficiently for most numbers whose prime factors have at most (approximately) 28 decimal digits and whose overall length is at most (approximately) 56 decimal digits.

@DanishMapleFan The attached worksheet contains my module for the sum-of-four-squares problem along with several examples. Sum4Squares.mw

@David Sycamore 

1. My output data contains the information for every prime, all 1 million of them. If you tried to display this large amount of data in a GUI worksheet, it could cause problems. That's why I used a colon at the end of the command to suppress the display of the output. I was hoping that post-processing the data with Statistics:-TallyInto as I showed would provide the data to you in a more-useful format.

2. The plots that I showed are not linear; they are indeed O(n/ln(n)). But n/ln(n) is close enough to a line that it's difficult to visually distinguish it from a line. If you look very closely, you'll see that my curves are concave down.

3. Please pay attention to the distinction between lowercase and uppercase K.

You asked:

  • When you say "N::posint" does this tell the proc that you intend to use a number called N which is declared as a positive integer and that its value will be given later?

Almost. When the notation A::T appears in the parentheses following proc, that makes A a parameter of the procedure. Yes, the value will be given later, but the user does not need to call it (or call it anything at all). The name is only meaningful between the proc and end proc. If the value given later is not of type (positive integer in this case), then an error message will be given.

The line between od and end proc (the K1,K2 in this case) is the return value of the procedure.

You may re-ask your other questions if you pay respect to the difference between k and K.

4. The best book about Maple is available in the help system. See ?ProgrammingGuide.

 

@ Pi and pi mean different things to Maple, even though they both display as the lowercase Greek letter. The lowercase version is just a variable, like x.

The pdetest will take a long time to produce a not-very-useful result.

@DanishMapleFan If you're looking for solutions of the sum of four squares problem (there's at least one solution for every nonnegative integer), I've written a module that finds either all solutions or some desired number of them. I'll post it if you want.

@nm A problem with your first solution---

remove(`=`,op~(0,indets(x)),symbol)

---is that it'll find things that aren't functions for which op(0, ...is defined. An example would be an indexed name such as a[2], whose zeroeth operand is a. Also, since you are only removing a single element from a set, that part should be done as op~(0, indets(x)) minus {symbol}, which'd be faster for a large set.

In your second solution, why convert from set to list to set? And it seems that you do not trust that

indets(x, some type)

works.

Could you give some more details please? In general, a permutation may have several disjoint orbits.

@David Sycamore 

1. Adaption to counting up to a given ordinal of prime: Yes, this just requires a small modification to my procedure. Here is it is:

k1k2:= proc(N::posint, a::posint:= 10, b::posint:= 1)
local K1, K2, p:= 1, i, k1:= 0, k2:= 0;
    for i to N do
        p:= nextprime(p);
        if isprime(a*p+b) then 
            k2:= k2+1; K2[p]:= k2
        else 
            k1:= k1+1; K1[p]:= k1
        fi
    od;
    K1, K2
end proc
:
(K1,K2):= CodeTools:-Usage(k1k2(10^6)):
memory used=5.51GiB, alloc change=80.00MiB, 
cpu time=31.98s, real time=31.27s, gc time=2.34s

2. The straight-lines anomaly: Note that Kitonum's first plot is implicitly logarithmically scaled along its horizontal axis simply due to the way his procedure works. My plot is linearly scaled on both axes. To my mind, this completely explains the anomaly.

3. Doing it without a procedure: It can be done, but I think that pedagogically it's both the wrong thing to do and the wrong thing for me to show you how to do.

@janhardo I think that Acer's point is that you should in general "chance it" by accepting the default values for a first try. Then only start setting options if the first try produces an unacceptable plot. I'd apply this principle especially to the computational options, such as gridgridrefinenumpoints.

@nm For what it's worth, I can't figure out any way to have type assertion checking automatically done for assignments to globals, as can be done easily for locals.

That was the gist of your deleted Question. Personally, I don't see where you've also asked that in this thread. 

I very often see Questions deleted by Moderators on StackExchange sites. I think 4 Moderators need to flag it before it's deleted. I hate it when this happens after I've Answered the Question.

There is definitely a need on this site for Moderators to control duplicate Questions. I usually agree with Acer's deletion decisions, and I delete numerous duplicates myself. But I don't agree with him on this one. I don't recall any situation where you, nm, has posted what I'd consider to be a duplicate Question. Indeed, from what I've seen, you've always acted here with a high degree of respect and honor. 

@nm Again, why do you use has when `=` will do the job? `=` is much faster and more to the point.

One drawback to using a mutable structure such as a Record or table for a procedure's input is that the procedure will obtain no benefit from a remember table.

@Carl Love You can declare types for a Record's fields when you define the Record:

A:= Record('x'::integer= 1);

Then if you've correctly set assertlevel to 2, an attempt to assign the wrong type to x will give an error.

First 191 192 193 194 195 196 197 Last Page 193 of 709