【问题标题】:Prime factorization in julia 0.6Julia 0.6 中的素数分解
【发布时间】:2017-02-26 10:05:59
【问题描述】:

正如 Julia 的文档中所述(0.6 之前),可以使用 factor(n) 来完成素数分解。

它在 Julia 0.6 中不起作用。新版本的 Julia 中是否有任何软件包可以输出任何给定数字 n 的素数及其元数,因为 factor(n) 如下所示(来自文档)?

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) # == 2*2*5*5
Dict{Int64,Int64} with 2 entries:
2 => 2
5 => 2

【问题讨论】:

    标签: julia factorization


    【解决方案1】:

    这已移至包Primes.jl

    Julia v0.5 中提供了弃用警告,该功能在 v0.6 中被完全删除。

    julia> VERSION
    v"0.5.0"
    
    julia> factor(100)
    ERROR: factor(100,) has been moved to the package Primes.jl.
    Run Pkg.add("Primes") to install Primes on Julia v0.5-
     in factor(::Int64, ::Vararg{Int64,N}) at ./deprecated.jl:210
    

    【讨论】:

    • 没有对应的弃用警告吗?
    • 它在 0.5 中被移动,并且有一个弃用警告。该警告在 0.6 中消失了,因为它已被弃用发布。跳过发布是危险的:)
    【解决方案2】:

    运行:Pkg.add(Primes) pkg.update() 全部更新

    运行:使用(Primes) 编译包

    因子(100)

    【讨论】:

      【解决方案3】:
      • 运行import Pkg; Pkg.add("Primes") 安装primes 包。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-05
        • 1970-01-01
        • 2014-07-11
        • 2014-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多