mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Software

Reply
 
Thread Tools
Old 2013-02-15, 00:39   #1
ixfd64
Bemusing Prompter
 
ixfd64's Avatar
 
"Danny"
Dec 2002
California

95616 Posts
Default an expression parser for manual tests?

For the "P-1..." and "ECM..." options, users can input an expression of the form k * bn ± c. However, it requires the user to input values into four separate fields. It seems a bit clumsy in today's standards. Therefore, I'm proposing a feature that will automatically parse expressions of certain forms.

As a proof of concept, I've written a simple Python program that processes expressions of the form k * bn ± c and bn ± c (in which case k = 1). I don't imagine it being to hard to add a similar feature to Prime95.

Code:
import re

def main():
    
    # it's probably possible to use just one regular expression
    pattern_full = "^(\d+)\s*\*\s*\d+\s*\^\s*\d+\s*[\+-]\s*\d+"
    pattern_no_prefix = "(\d+)\s*\^\s*(\d+)\s*([\+-])\s*(\d+)"
    
    v1 = 1
    
    def print_vars(k = 1, b = 1, p = 1, c = 0):
        out = "k = " + str(k) + ", b = " + str(b) + ", n = " + str(p) + ", c = " + str(c)
        print out
    
    while True:
        raw_expr = raw_input("Enter expression (\"q\" to quit): ")
        expr = raw_expr.strip()
        if expr == "q":
            break
        f = re.findall(pattern_full, expr)
        np = re.findall(pattern_no_prefix, expr)
        if not f == []:
            v1 = int(f[0])
        if np == []:
            print "Invalid expression"
        else:
            v2 = int(np[0][0])
            v3 = int(np[0][1])
            v4 = int(np[0][3])
            if np[0][2] == "-":
                v4 = -v4
            print_vars(v1, v2, v3, v4)

if __name__ == "__main__":
    main()
Sample output:

Code:
Enter expression ("q" to quit): 2^57885161-1
k = 1, b = 2, n = 57885161, c = -1
Enter expression ("q" to quit): 2^1024+1
k = 1, b = 2, n = 1024, c = 1
Enter expression ("q" to quit): 19249 *2^ 13018586 + 1
k = 19249, b = 2, n = 13018586, c = 1
Enter expression ("q" to quit): q

Last fiddled with by ixfd64 on 2013-02-15 at 00:44
ixfd64 is offline   Reply With Quote
Old 2013-02-15, 01:27   #2
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

11100001101012 Posts
Default

Good luck using regular expressions in C.
Dubslow is offline   Reply With Quote
Old 2013-02-15, 02:05   #3
rogue
 
rogue's Avatar
 
"Mark"
Apr 2003
Between here and the

11·577 Posts
Default

If you want to PRP, then use pfgw. For P+1/P-1/ecm, use GMP-ECM with gwnum. In fact, isn't there a GPU version of GMP-ECM?

Last fiddled with by rogue on 2013-02-15 at 02:06
rogue is offline   Reply With Quote
Old 2013-02-15, 09:22   #4
ET_
Banned
 
ET_'s Avatar
 
"Luigi"
Aug 2002
Team Italia

481510 Posts
Default

Quote:
Originally Posted by rogue View Post
If you want to PRP, then use pfgw. For P+1/P-1/ecm, use GMP-ECM with gwnum. In fact, isn't there a GPU version of GMP-ECM?
There is, with some limitations.

- The number to test should have less than 1017 bits.
- The number of curves to do is locked to reach the best GPU performance (512 curves on my GTX580, 224 on lower cards).

Luigi)
ET_ is offline   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
A Fib expression with multiplication MattcAnderson Homework Help 5 2016-11-01 08:16
Testing an expression for primality 1260 Software 17 2015-08-28 01:35
regular expression help ixfd64 Programming 2 2009-03-01 06:19
Does Anyone Know how to Simplify the Following Expression? jinydu Puzzles 9 2004-04-02 01:03
Can I do manual tests? clowns789 NFSNET Discussion 3 2003-07-11 17:07

All times are UTC. The time now is 23:55.


Fri Jul 16 23:55:40 UTC 2021 up 49 days, 21:42, 1 user, load averages: 1.89, 1.68, 1.49

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.