Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from JakubDrozd/beta
Browse files Browse the repository at this point in the history
Version 0.2.0
  • Loading branch information
b3s23love authored Nov 4, 2021
2 parents 2a0318b + 3180e12 commit 1c864df
Show file tree
Hide file tree
Showing 26 changed files with 2,680 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
git-commit.sh
/source.zip
/node_modules
/node_modules
/.nyc_output
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\main.js",
"args": [""]
"program": "${workspaceFolder}\\main.js"
}
]
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to JSprimecount will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.2.0] - 2021-11-04
### Added
- Small phi partial sieve function calculator
- Time argument for measuring time

## [0.1.0] - 2021-11-02
### Added
- Eratosthenes sieve
Expand Down
13 changes: 11 additions & 2 deletions JSprimesieve/utilities.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
const ersieve = n => {
// Eratosthenes algorithm to find all primes under n
var array = [], upperLimit = Math.sqrt(n), output = [];
Expand Down Expand Up @@ -105,10 +105,19 @@ const phismall = (x, b, primlist) => {
return phi1 - phi2;
}
};

const nthprimeapprox = n => {
if (n >= 6) {
return n * Math.log(n * Math.log(n));
} else {
return 15;
}
};
// Module exports
module.exports.ersieve = ersieve;
module.exports.pismall = pismall;
module.exports.pitabulator = pitabulator;
module.exports.mobius = mobius;
module.exports.mobiustabulator = mobiustabulator;
module.exports.phismall = phismall;
module.exports.phismall = phismall;
module.exports.nthprimeapprox = nthprimeapprox;
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ $ node main.js 1e7
Usage: main.js x [options]
Positionals:
x The number for computing the prime-counting function. [number]
x [number]
Options:
-v, --version Show version number [boolean]
--phi phi(x, a) counts the numbers <= x that are not divisible by any
of the first a primes Call it by --phi x a.
--time Display time in seconds. [boolean]
-h, --help Show help [boolean]
```

Expand Down
12 changes: 10 additions & 2 deletions cmdvalidators.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { exit } = require('yargs');

const xValidator = (x) => {
const xValidator = x => {
if (isNaN(x)) {
console.log('Exited with code 2: Input is not a number');
exit(2, 'Input is not a number');
Expand All @@ -13,4 +13,12 @@ const xValidator = (x) => {
}
};

module.exports.xValidator = xValidator;
const phiArgValidator = (x, a) => {
if (x < 0 || a < 0) {
console.log('Exited with code 5: One of phi inputs is negative');
exit(5, 'One of phi inputs is negative.');
}
};

module.exports.xValidator = xValidator;
module.exports.phiArgValidator = phiArgValidator;
2 changes: 1 addition & 1 deletion deleglise-rivat/P2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// P2 function implementation
const P2 = x => {
}
Expand Down
2 changes: 1 addition & 1 deletion deleglise-rivat/S.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Module imports
const S1 = require('./S1.js');
const S2 = require('./S2.js');
Expand Down
2 changes: 1 addition & 1 deletion deleglise-rivat/S0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Module import
const { mobiustabulator } = require('../JSprimesieve/utilities.js');
// Function
Expand Down
2 changes: 1 addition & 1 deletion deleglise-rivat/S1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Function
const S1 = (piofy, piofcbrtx) => {
console.log('Calculating S1...');
Expand Down
2 changes: 1 addition & 1 deletion deleglise-rivat/S2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Module imports
const U = require('./S2/U.js');
const V = require('./S2/V.js');
Expand Down
2 changes: 1 addition & 1 deletion deleglise-rivat/S3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Have to do...
// Module export
module.exports = S3;
2 changes: 1 addition & 1 deletion deleglise-rivat/U.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Module import
const { pitabulator, ersieve } = require('../JSprimesieve/utilities.js');
// Function
Expand Down
2 changes: 1 addition & 1 deletion deleglise-rivat/V.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Module imports
const V1 = require('./V1.js');
const V2 = require('./V2.js');
Expand Down
2 changes: 1 addition & 1 deletion deleglise-rivat/V1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Have to do...
// Module export
module.exports = V1;
2 changes: 1 addition & 1 deletion deleglise-rivat/V2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Module imports
const W1 = require('./W1.js');
const W2 = require('./W2.js');
Expand Down
2 changes: 1 addition & 1 deletion deleglise-rivat/W1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Have to do...
// Module export
module.exports = W1;
2 changes: 1 addition & 1 deletion deleglise-rivat/W2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Have to do...
// Module export
module.exports = W2;
2 changes: 1 addition & 1 deletion deleglise-rivat/W3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Have to do...
// Module export
module.exports = W3;
2 changes: 1 addition & 1 deletion deleglise-rivat/W4.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Have to do...
// Module export
module.exports = W4;
2 changes: 1 addition & 1 deletion deleglise-rivat/W5.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
// Have to do...
// Module export
module.exports = W5;
2 changes: 1 addition & 1 deletion deleglise-rivat/phi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* JSprimecount is a fast implementation of algorithms calculating the prime-counting function.
Copyright © 2021 Jakub Drozd
For full notice see pi.js */
For full notice see main.js at the top level directory. */
64 changes: 43 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,55 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see https://www.gnu.org/licenses/.
E-mail: [email protected] */
// Import of modules
const { pismall } = require('./JSprimesieve/utilities.js');
const utilities = require('./JSprimesieve/utilities.js');
const { hideBin } = require('yargs/helpers');
const yargs = require('yargs');
const validators = require('./cmdvalidators.js');
// License
const licensePrinter = () => {
console.log('JSprimecount Copyright © 2021 Jakub Drozd');
console.log('This program comes with ABSOLUTELY NO WARRANTY; for details see https://github.com/JakubDrozd/JSprimecount/blob/main/LICENSE.txt.');
console.log('This is free software, and you are welcome to redistribute it under certain conditions; see the above link for details.');
};
const startTime = new Date();
// Yargs logic
const options = yargs(hideBin(process.argv))
.usage('Usage: $0 x [options]')
.command('$0 <x>', false, yargs => {
.usage('Usage: $0 x [options]')
.command('$0 [x]', false, yargs => {
return yargs.positional('x', {
describe: 'The number for computing the prime-counting function.',
conflicts: 'phi',
type: 'number'
});
}, argv => {
validators.xValidator(argv.x);
})
.option('n', {
alias: 'nth-prime',
description: 'Compute the n-th prime'
})
.help()
.alias('help', 'h')
.alias('version', 'v')
.locale('en')
.strict()
.argv;
// License
console.log('JSprimecount Copyright © 2021 Jakub Drozd');
console.log('This program comes with ABSOLUTELY NO WARRANTY; for details see https://github.com/JakubDrozd/JSprimecount/blob/main/LICENSE.txt.');
console.log('This is free software, and you are welcome to redistribute it under certain conditions; see the above link for details.');
if (argv.x !== undefined) {
licensePrinter();
validators.xValidator(argv.x);
console.log(utilities.pismall(argv.x));
}
})
.option('phi', {
describe: 'phi(x, a) counts the numbers <= x that are not divisible by any of the first a primes. Syntax: --phi <x> <a>.',
nargs: 2
})
.option('time', {
describe: 'Display time in seconds.',
type: 'boolean'
})
.help()
.alias('help', 'h')
.alias('version', 'v')
.locale('en')
.strict()
.argv;

if (options.phi) {
validators.phiArgValidator(options.phi[0], options.phi[1]);
const primes = utilities.ersieve(utilities.nthprimeapprox(options.phi[1]));
// console.log(utilities.phismall(options.phi[0], options.phi[1], primes));
console.log(utilities.phismall(options.phi[0], options.phi[1], primes));
}

console.log(pismall(options.x));
if (options.time) {
const endTime = new Date();
console.log(`${(endTime - startTime) / 1000} seconds`);
}
Loading

0 comments on commit 1c864df

Please sign in to comment.