LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
TiTou

"Is prime?" primitive

Status: Completed

Check Prime VI is available in LabVIEW 2015 and later

Many languages have that, why not LabVIEW?

 

See here for implementation details.

 

This would help me out loads to solve Project Euler's problem faster, at this moment LabVIEW is ranked 53, it would be nice if we had tools that help us improve that.


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

9 Comments
altenbach
Knight of NI

Agreed. Mathscript already supports the "isprime" function (also e.g. "primes" and "factors"), so this probably already exists under the hood somewhere. 😉

 

In plain LabVIEW, we do have "prime factor" though, you could just look at the array size of the output ;))

 

(your links all point to the euler home page. Do we need to be signed in to get to the right place?) 

PaulG.
Active Participant

I logic yes/no output primitive would be ideal, but like altenbach said you can use prime factor and look for an array size output = 1. I made my own years ago while spending time in Project Euler. Smiley Happy

PaulG.

LabVIEW versions 5.0 - 2020

“All programmers are optimists”
― Frederick P. Brooks Jr.
JÞB
Knight of NI

Another one I've rolled my own on before.

1!.PNG

I had way too much time on my hands that day but the vi has been useful over many yearsSmiley Wink


"Should be" isn't "Is" -Jay
SteenSchmidt
Trusted Enthusiast

I'm about to release a new GPower toolset (it's basically a very efficient string expression parser/evaluator, working title is GPMath) in which I've opted to not include an ISPRIME function, simple due to the fact that such a function simply isn't that useful for small integers as available in LabVIEW.

 

I'm used to working with HP calculators and have earlier programmed a big_math library in C for the HP50G with an ARM9 CPU, and on that platform it makes sense. On that it's possible to calculate with integers with 200,000 digits for instance, while in LabVIEW we're dealing with max 20 digits. But maybe I should include it in GPMath as well, if there is a use for it?

 

The above isn't meant to stop an ISPRIME primitive from being included in native LV of course, my toolset would just be able to evaluate "ISPRIME(x) && ISPRIME(y)" for instance... And the mentioned built in Prime Factor VI is only available from LV 2011 onwards, and then only in LV Full and Professional, not in Base.

 

Cheers,

Steen

CLA, CTA, CLED & LabVIEW Champion
Charles_CLA
Active Participant

@altenbach, I'd never seen the "prime factor" vi before. However, it appears to have a flaw: if you input "1" into, then it returns "1". Should it not return an empty array as "1" is not a prime number?

Charles Chickering
Architecture is art with rules.

...and the rules are more like guidelines
SteenSchmidt
Trusted Enthusiast

Even though 1 is not a prime number, prime factorization of 1 is 1 by mathematical definition.

 

/Steen

CLA, CTA, CLED & LabVIEW Champion
WG-
Member
Member

Useless idea. It is fairly easy to validate up to a certain degree if a number is prime or not. Certainly up to the largest labview datatype 64 bit numerical value. This has only use if LabVIEW would have a bignum toolkit. Which provides arithmetic operations for arbitrarly large numbers.

SteenSchmidt
Trusted Enthusiast

Just as I wrote... 😉

CLA, CTA, CLED & LabVIEW Champion
Darren
Proven Zealot
Status changed to: Completed

Check Prime VI is available in LabVIEW 2015 and later