Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've noticed there's a command line call "factor", which prints the prime factors of a number.
Does anybody have an idea why this is included as a standard Unix/Linux routine? Is it really that important to do prime factorizations on the command line? Most programming languages don't have a factor command, so why does a very popular OS have one?
There must be some interesting history to this I'm missing. The only use I've gotten out of factor is getting a rough comparion of processor speeds on my various boxes by doing
factor 18446744073709551557
...which takes from 52 seconds to over 2 minutes, depending on the machine
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Well, I think it exists because it has always been there.
The venerable Unix Version 7 manual (Jan 1979) has it and states:
Maximum time to factor is proportional to √n and occurs when n is prime or the square of a prime. It takes 1 minute to factor a prime near 10 14 on a PDP11.
It improves since that time (x240), but not as much as I was expecting:
Code:
time factor 99999999999971
99999999999971
99999999999971
real 0m0.25s
user 0m0.17s
sys 0m0.00s
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
The benchmark theory may be correct, I have never seen this command actually used in a script.
Note that OpenSolaris is providing a source code which is certainly very close to the original one. There are no comments about the intended use of it though.
I would guess that it's there because at the time Unix was originally developed around 1970, the only real market for computers was large, well-funded organizations, and at that time, number crunching was one of a computer's primary uses. Factoring is a useful function for certain areas of study (eg, in scientific labs, universities, etc) and by including a simple-to-use utility to compute factors in Unix, it may have been a minor but useful selling point. Sort of like cup holders in a car - they aren't really necessary, but to a potential customer, having them is better than not having them. Same with a factor command. Just speculation, of course
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.