Skip to content

Add a function for computing multiplicative order#60

Closed
davidamarquis wants to merge 11 commits intomasterfrom
mult_order
Closed

Add a function for computing multiplicative order#60
davidamarquis wants to merge 11 commits intomasterfrom
mult_order

Conversation

@davidamarquis
Copy link
Copy Markdown
Collaborator

Benchmark

@btime bench_mult_order_es1(1009)
210.208 μs (8056 allocations: 188.81 KiB)

@btime bench_mult_order(1009)
727.166 μs (28 allocations: 1.05 KiB

function mult_order_eric1(n::Int, q::Int)
    (q <= 0 || n <= 0) && 
        throw(DomainError("q and n both need to be positive. Passed: q = $q, n = $n"))

    # finite stop instead of while
    for i in 1:200
        if mod(BigInt(q)^i, n) == 1
            return i
        end
    end
    error("Unable to compute ord($n, $q).")
end

function bench_mult_order_eric1(n::Int)
    for x in 2:(n-1) 
        mult_order_eric1(x,n) 
    end 
end

function bench_mult_order(n::Int)
    data = prepare_mult_order(n)
    for x in 2:(n-1)
        mult_order(x, data) 
    end 
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants