Skip to content

Instantly share code, notes, and snippets.

@ityonemo
ityonemo / elliptic.jl
Last active May 29, 2017 02:18
(unsecure) elliptic numbers is julia
#elliptic.jl
#we'll make an "elliptic curve type" that is empty with no parameters. The advantage to this is that the parameter values
#take no memory in the point representation and are JITted in as assembler immediates.
type EllipticCurve{A, B}; end
#properties of the elliptic curves
discriminant{A,B}(E::Type{EllipticCurve{A,B}}) = -16 * (4*A^3 + 27*B^2)
issmooth(E) = discriminant(E) != 0
haspoint{A,B}(E::Type{EllipticCurve{A,B}}, x, y) = y^2 == x^3 + A*x + B
@ityonemo
ityonemo / tree_printer.jl
Created May 19, 2017 01:42
prints trees, yay
## binary_tree_print.jl
#binary tree defined as the following:
type Tree{T}
node::T
left::Union{Tree{T}, Void}
right::Union{Tree{T}, Void}
end
function magicsum(arg){
var sumsofar = 0;
var f;
f = function(inner_arg){
if (inner_arg){
sumsofar += inner_arg;
return f;
} else {
return sumsofar;
#supson.jl
type ツ; end
_(::Type{ツ}) =
*(::Type{ツ}, ::Function) =
type ⎺; end
Base.:\(::Type{⎺},::Type{ツ}) =
Base.:/(::Type{ツ},::Type{⎺}) = true
\_(ツ)_/#==> true
@ityonemo
ityonemo / bloom.jl
Created November 3, 2016 23:00
bloom filter in 65 minutes in julia.
#bloom.jl - takes a file, reads binary data from the file and does whatever a
#bloom filter would do.
doc"""
`BloomFilter{V}`
defines a bloom filter over a value type V
"""
type BloomFilter{V}
filter::BitVector
hashes::Array{Function, 1}
@ityonemo
ityonemo / column_sort_inplace.jl
Created November 2, 2016 01:58
sorts a matrix by columns in place
function column_sort_inplace!(matrix::AbstractMatrix, fn::Function)
p = sort_columns_return_permutation(matrix, fn)
#first, find the permutation of the matrix, reduced by rows.
#create an array that signals the completion status of the process.
completion = falses(length(p))
#store important indices
current_root = 1 #root of the current cycle we're operating on.
current_index = 1 #array index we're operating on.
#next, allocate a short array that looks like the vector.
@ityonemo
ityonemo / driving.jl
Created October 16, 2016 20:53
queries google maps to tabulate driving distances.
#drivingtaxes.jl
using JSON
#make sure we have what we're looking for.
(length(ARGS) == 0) && throw(ErrorException("needs a file name"))
###################################
#rows iterator
type rows; tgt::Matrix; end
Base.start(r::rows) = 1
@ityonemo
ityonemo / uppertriangular.jl
Created September 28, 2016 04:36
Iterates over upper triangular indices.
#upper triangular indices - iterates over upper triangular indices in a list of
#indices.
type uppertriangular; iterable; end
Base.start(x::uppertriangular) = (1, 1)
function Base.next(x::uppertriangular, state)
(idx1, idx2) = state
next1 = idx1
next2 = idx2 + 1
if next2 > length(x.iterable)
@ityonemo
ityonemo / lookup_table_lemma.md
Last active August 18, 2016 01:16
Proof that lattice lookups only need exact values.

Definitions:

ℝᵖ - projective reals. ℝᵖ/L - projective reals represented by a Type2 Unum Lattice L. The elements are intervals, which will be denoted as x̅. An element of may also be an exact value or an ulp value, which will be denoted as ẋ.

O:(ℝᵖ/L)ⁿ → ℝᵖ/L is an implementation of an operation o:(ℝᵖ)ⁿ → ℝᵖ. The implementation must have the property o(x) ∈ O(ẋ), where ẋ is the unique ulp

@ityonemo
ityonemo / 64to16.jl
Last active June 5, 2016 01:18
converting to unsigned 16 bit integers in julia
# converting from Int64 to UInt16 in Julia can result in a minefield of inexacterrors,
# which could be performance-debilitating (if you care about that).
code_native(Int16, (Int64,))
# ==>(edited)
# pushq %rbp
# movq %rsp, %rbp
# movswq %si, %rax
# cmpq %rsi, %rax