In More efficient implementation for comparing coefficient lists in a Do-loop link, george2079 posts in his first answer a piece of code that takes 352 seconds to compute. When I run this same piece of code on my 2.3 GHz Intel Core i7 MacBook Pro laptop, it takes 853 seconds. What are the reasons for this, and how can I get the code running optimally on my machine? (Would it be appreciably faster if I used a desktop?) Perhaps this question is best posed to George2079, but the original thread is unfortunately dead and there doesn't seem to be a way to contact individual users.

  • $\begingroup$ Is the end goal you want to do this for various n and get the loop iterator values where the lhs coeff. list matches the right, or is it just this one-shot (n=2) you want to speed up? $\endgroup$
    – ciao
    Jun 19, 2014 at 2:23
  • $\begingroup$ If use for multiple n is the goal, just build a table of rhs3 coefficient lists (perhaps with indices added for each entry) once - since this doesn't change for differing lhs. This will take time (you're doing way more work than needed, there's a pattern to coeff.s you could take advantage of to short-circuit work, don't have time right now to analyze) - but once done, you need only get coeff. list to a given lhs n, then do a lookup (Cases, Select, whatever) into the table, will be quite quick. $\endgroup$
    – ciao
    Jun 19, 2014 at 2:45
  • $\begingroup$ @rasher Yes, I would like to do this for various n with maybe 10 more iterator variables. (This problem in question is somewhat of an intermediate step, which is why I'm looking for a better approach.) The rhs3 coefficient lists change for differing lhs. If you read the first comment and the ensuing comments I believe that you will see this is what was done, in fact for a particular q so the expansion would be numeric instead of symbolic. Not sure however if you're proposing something slightly different. $\endgroup$
    – Jonny
    Jun 19, 2014 at 3:33
  • 2
    $\begingroup$ Then you should update the original question to reflect this - one should not be required to read the comments on a question to determine the examples provided are for one specific case - anyone reading the code as it is would infer the RHS3 does not depend on N in any way... regardless, based on your reply, disregard earlier comment, you need to focus on smarter way to short-circuit the work, probably via number-theoretic characteristics of generated polys... $\endgroup$
    – ciao
    Jun 19, 2014 at 4:16
  • $\begingroup$ I'm sorry, I made a mistake in my reply to you. Indeed rhs3 does not depend on n in this example. If it is indeed the unfortunate situation that Mathematica can't provide an answer to the problem in the current state, can you answer the question I posed originally? Even the pmatch function in george2079's answer does not return for me what it claims to return, so the problem is not only that it takes more than twice as long for his code to run on my machine. $\endgroup$
    – Jonny
    Jun 19, 2014 at 4:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.