Vectorized Prime Number Testing

So I realized last night, that you can probably find Hamiltonian circuits quickly, using vectorization / parallel computing, and tonight, I realized you can also test for whether a number is prime using vectorization, and the results are pretty impressive, and below is some command line code, together with the runtimes, which are in the fractions of a second until you hit the double digit millions, which took just over one second:

ostensible_prime = 7;

tic; [is_prime divisor_vector] = prime_test(ostensible_prime); toc

0.000156164 seconds.

ostensible_prime = 16127;

tic; [is_prime divisor_vector] = prime_test(ostensible_prime); toc

0.000491858 seconds.

ostensible_prime = 27644437;

tic; [is_prime divisor_vector] = prime_test(ostensible_prime); toc

1.00698 seconds.

The code is attached below.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s