David Sycamore

45 Reputation

4 Badges

2 years, 37 days

MaplePrimes Activity


These are replies submitted by David Sycamore

@Carl Love Thank you. The Programming guide is of ongoing interest. I have not managed to find my way all around it yet but will keep at it. I did try to find answers to some of the questions I asked you, but did not succeed yet.

I did not appreciate the importance of the space after the comma, will watch out for that.

My code for k1, k2 (up to ordinal of a prime), adapted from Kitonum:

restart;
P := proc (k)

local n, k1, k2;

n := 1; k1 := 0; k2 := 0;

for n from 1 to 10^k do

if isprime(10*ithprime(n)+1) then k2 := k2+1 else k1 := k1+1 fi 

end do;

[k1, k2];

end proc;

seq(P(k), k = 1 .. 5);
   [6, 4], [76, 24], [822, 178], [8602, 1398], [88409, 11591]

It might not be all my own work, but i do understand it. (I like the output in this form, very clear to read). Can your code putput in this way ?

The k1 only case was also up to ordinal of a prime, which means the k2 is then obvious by difference. Though not of interest to you, it caused me more problems than the above, but I managed to find a solution. 

I looked up ?table, thanks. I ran your code and got the output, thanks. 

I did not mean to "quote" your code at the end of my last message. I imported it to my screen just for reference when writing to you, and did not include all of the last line. However I forgot to erase it at the end; thats all. I do understand  that the procedure ends with end proc, then comes the output. 

My dificulty understanding is not especially to do with spaces and commas, they are just symptoms. The reason is because computational science is new and very alien to me. I have had zero education in this so am a lone learner in an environment where every tiny mark on the screen is loaded with meaning, and the scope for error is vast (imagine you had to learn a foreign language: Mandarin, Russian... thats how this is for me). I do greatly appreciate your help; thank you. What I need is lots of practice and good exercises to do.

David.

ps: When i copied your code onto my reply last time, it came in a "box" with slightly different background. That did not happen when I copied my code here today, it arrived pretty much all in one line and with some punctuation missing, which I had to tidy it up. 

 

 

@Carl Love Thank you. I have looked at the Programming guide and found it helpful. I wrote a code to find just k1 (rather than k1 and k2) using ordinal of primes, and another to find k1, k2 (ie 1 or 2) for each prime up to a limit. Both used procs and both worked. I have also looked again at your code and seen that k1,k2 are not the same as K1 and K2. Whereas all are declared local within the proc, only k1,k2 are given initial values. I note the the 'name' of the proc is k1k2 and that this is never used (called) again. I dont know what K2[p] and K1[p] mean but they seem to be assigned (using :=) to the current values of k2 and k1 respectively after the execution of each iteration of "if" within the do loop. Between od and end proc the final values of k1,K2 are delivered but now there are no square brkts [ ] following them... I tried to adapt your code to tell me the values k1,k2 in sequence format (as per Kitonum) but did not succeed yet but will keep trying. I also wrote another simple code, using a proc, not related to this task, and it also worked. So some modest progress, but still some open questions.  
David.

 

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)

@Carl Love Thank you for all 3 answers: 

1. I ran the code you just sent (up to the end of the (k1k2(10^6)): line, so not including the graph bit).  It appeared to work but the only data I got was related to usage. How to get the k1,k2 data? When I ran the first version you sent I got the full graphics but not the numerical data as per Kitonum.

2. So both K1 and K2 have linear behaviour? I was expecting something logarithmic because this is about primes and pi(n) ~ n/log(n) and k1(n)+k2(n)=pi(n). I must have missed something...

3.I liked this answer; fair enough dont teach me bad stuff thats very respectable. I try to avoid procs because I cannot figure out how they work and when to use them.  If I could only get past that key hurdle you might never hear from me again (believe me I do try hard before asking here; every time). The answer always includes a proc, always works  but I rarely get to understand why, and dont like to ask again.  I do see the general structure (proc, do, if, fi,od,end proc ) but get thrown by the details. Examples: 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? What is the meaning of  "k2[p]:=k2", etc? After od you write k1,k2 and I dont see what is this command is doing. Then, after the end of the proc you write (K1,K2):= this looks to me that you are assigning values here, rather than calling for the latest versions of them. Kitonum used a seq command to call up the output, so I could see for up to 10^k, the data [k1,k2], and he used that square brkt format after the end of his proc, whereas you use round brkts. These differences are quite a challenge or a learner. Your  way is clearly different from his, perhaps because the aim was more to print out the graph rather than the numbers behind them?. 
I'm really sorry about all these extra questions.

Is there a decent book on Maple coding?

@Carl Love Thanks for your solution, I sent some questions to Kitonum, please comment also if you wish. 

David.

@Kitonum Thanks for your solution, I hope you wont mind some questions:

1. Instead of counting the number of "1" and "2" primes up to 10^k for some k= 1.2.... can your code be adapted to do the same count up to the 10^k-th prime ( or more generally up to ithprime(N))? Done this way the sum of a,b in [a,b] should be 10^k (or N).

2. I noted you got ~ straight lines with log scale on the vertical axis. However, unless I am mistaken, the graph produced by Carl  did not do this, and yet also got straight lines. What have I missed?

3. Is there any way to do a "counting up" code like this one, but without using a proc? (my attempt was an if statement within a do loop, no proc); it didnt work.

@Carl Love 

No calculation error, transcription mistake.  Thanks to everyone who responded; great response and so quick.
David.

@vv Sorry I dont understand your reply. What must I do to get the same results for P(n)  as you did, using your latest code ?

David

@vv Thanks very much for that. 
I copy pasted it, put P(50) and hit return.The output I got  was every prime <=50 (ie 2,3,...,47), whereas you  got the correct answer (2,3,5 7,11,13,19). Could this be because my version is 2017? Please advise any changes to make it work.

Thanks,

David.

 

 

 

@vv 

I got it running, have now ~50 terms which is great. I would now like to examine for each number n in the sequence the set P(n) of partition primes of n. Is it possible to adapt the code for this purpose?

Thanks in advance

David.

@vv 

Just checking how to do this: Copy paste code from the outline box above into a new worksheet, do changes for 2017, and then add :

for n from 2 to N do 

if........ fi

od;

Then run

Is that right?

 

@David Sycamore 

Will it work in 2017?

@vv 

Thanks very much for this; great job! I will try to run it later today (with Maple 2017).

David. 

@Carl Love Thanks for the clarification. I wrote {phi} because there was no way to write the usual Greek letter. What I meant was of course the empty set {}, not the set containing the empty set as sole element. 

@David Sycamore 

I wonder if it could be possible to argue (using the Goldbach conjecture) that for an even number 2n we will always be able to find a p in P(2n) such that 2n-p is a prime q>p such that p is not a member of P(q). Then p+q=2n and this is the only partition of 2n having p as least part.  Ergo in the set of partitions of 2n we will always find a (p,1), which if correct means that the numbers I am looking for are all odd composites (like 63,161...), no need to look for primes or even numbers. 
David.

@Kitonum Yes I mean that {phi} is empty set and I thought that notation was universal, just that I have no way to write it as it appears in text books.

 

Questions:

1. No restriction on the number of summands or the starting (least) prime which I call a "partition prime" of n (my own terminology, it might be called by another name elsewhere). 
 

2. Yes this is about partition of any whole number n into primes, so all the  summands are primes and they don't have to be distinct.

3. Let P(n) be the set of partition primes of n, so for n=12, P(12)={2,3,5}. Any prime partition of 12 must have one of these numbers as least part. Q(n) is a subset of P(n) and lists the "singular partition primes of n", meaning those which appear (as least part) in one and only one partition of n into primes. So Q(12)={3,5} because 3+3+3+3 = 5+7 = 12 are the only possible choices having least part 3 and 5 respectively.
 

I have a recursive method for computing the overall number of partitions of n into primes by adding up the number of partitions with least part p, for every p in P(n). This works but is laborious and I don't know how to tackle a code for it, which is why I sought assistance on here. 
 

4. The strange thing about 63 is that it has no singular partition prime. Compare the following: 46 is chosen at random:

P(46)= {2,3,5,7,11,17,23}, and the associated partition numbers are: (2,456), (3, 77), (5, 17), (7, 4), (11,1),  (17,1), (23,1), where (p,m) means there are m partitions (of 46) having least part p. Thus Q(46)={11,17,23}. However P(63)={2,3,5,7,11,13,17}, for which the corresponding partition numbers (for all p in P(63)) are: (2,2198), (3,323), (5,60), (7,15), (11,5), (13,2), (17,2). Since there is no (p,1) in this collection, Q(63)={phi}, the empty set. I thought that this was a one-off anomaly number because no ´n<63 has this property, but then found that 161 has the same property. P(161)={2,3...47} and the partition numbers are (2,1305679), (3,124055), (5,15646), (7,3006), (11,687), (13,236), (17,85), (19,38), (23,16) (29,9), (31,4), (37,2), (41,4), (43,2), and (47,2). There is no (p,1) in this set so Q(161)={phi}. My calculations have now reached 167 and these are the only two numbers having this property, which is why I am curious to know if there are any more. 
 

I hope this clarifies my question and that you can help with a code. 
 

Regards,

David

ps: Carl please say what was wrong with my use of {phi}?

1 2 3 4 Page 1 of 4