Giter Club home page Giter Club logo

nan.numerics.prime-prolog's Introduction

A Simple Prime Number Library in Prolog

Nan.Numerics.Primes Nan.Numerics.Primes/Prolog 1.3.0-beta A Simple Prime Number Library in Prolog Copyright 2016-2017 Julio P. Di Egidio Licensed under GNU GPLv3. http://julio.diegidio.name/Projects/Nan.Numerics.Primes/ https://github.com/jp-diegidio/Nan.Numerics.Primes-Prolog/

=|library(nan_numerics_primes)|=

Module =prime= provides predicates to test (positive integer) numbers for primality, find divisors and factor numbers, generate prime numbers in some interval, find consecutive prime numbers, and save/load all prime numbers up to some value to/from a file or stream.

All predicates in module =prime= are safe, i.e. validate input arguments and ensure steadfastness. For maximum performance, user code can directly call the unsafe =public= (not exported) predicates in module =prime_lgc=.

Implements a variant of the Miller-Rabin primality test that is deterministic for numbers up to =3317044064679887385961980=, otherwise it is probabilistic with the number of iterations fixed at =20=.

For better performance, leverages a prime wheel of level =6=, i.e. generated by the first =6= prime numbers, and thread-local memoization of pairs of consecutive prime numbers.

NOTE: Since the primality test in use is probabilistic in general, this library is not suitable for cryptographic applications.

This library was developed and tested with: SWI-Prolog 7.3.25 - http://www.swi-prolog.org/

Usage example:

==
?- pack_install(nan_numerics_primes).
true.

?- use_module(library(nan_numerics_primes)).
true.

?- time(prime_right(1234567891012345678901234567890123456789011111, P)).
% 1,227 inferences, 0.000 CPU in 0.010 seconds (0% CPU, Infinite Lips)
P = 1234567891012345678901234567890123456789011139.
==

To be done: Implement parallel factoring functions. To be done: Implement probabilitic test error estimates? To be done: Implement option for num. of probabilistic iterations? To be done: Implement prime counting/n-th prime functions. To be done: Implement deterministic tests? To be done: Improve compatibility with other Prolog systems.

nan.numerics.prime-prolog's People

Contributors

jp-diegidio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

diegomt13309

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.