Code Monkey home page Code Monkey logo

primes.jl's Introduction

Primes.jl

Primes Primes Build Status Windows Build Coverage Status

Julia functions for computing prime numbers.

Usage

This repository contains some functions relating to prime numbers which have been duplicated from Base Julia, as well as new functions and improvements.

factor(n) -> Dict

Compute the prime factorization of an integer n. Returns a dictionary. The keys of the dictionary correspond to the factors, and hence are of the same type as n. The value associated with each key indicates the number of times the factor appears in the factorization.

julia> factor(100) # == 225*5 Dict{Int64,Int64} with 2 entries: 2 => 2 5 => 2

factor(ContainerType, n) -> ContainerType

Return the factorization of n using ContainerType (a subtype of Associative or AbstractArray).

julia> factor(DataStructures.SortedDict, 100) DataStructures.SortedDict{Int64,Int64,Base.Order.ForwardOrdering} with 2 entries: 2 => 2 5 => 2

When ContainerType <: AbstractArray, this returns the list of all prime factors of n with multiplicities, in sorted order.

julia> factor(Vector, 100) 4-element Array{Int64,1}: 2 2 5 5

isprime(x::Integer) -> Bool

Returns true if x is prime, and false otherwise.

julia> isprime(3) true

isprime(x::BigInt, [reps = 25]) -> Bool

Probabilistic primality test. Returns true if x is prime with high probability (pseudoprime); and false if x is composite (not prime). The false positive rate is about 0.25^reps. reps = 25 is considered safe for cryptographic applications (Knuth, Seminumerical Algorithms).

julia> isprime(big(3)) true

primes([lo,] hi)

Returns a collection of the prime numbers (from lo, if specified) up to hi.

primesmask([lo,] hi)

Returns a prime sieve, as a BitArray, of the positive integers (from lo, if specified) up to hi. Useful when working with either primes or composite numbers.

To avoid naming conflicts with Base, these are not exported for Julia version 0.4. In this case you will need to explicitly import the symbols:

using Primes
import Primes: isprime, primes, primesmask, factor

primes.jl's People

Contributors

ararslan avatar simonbyrne avatar stefankarpinski avatar pabloferz avatar jeffbezanson avatar aiorla avatar rfourquet avatar jlapeyre avatar mbauman avatar timholy avatar tkelman avatar yuyichao avatar davidssmith avatar jakebolewski avatar mschauer avatar

Watchers

James Cloos avatar  avatar  avatar

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.