Skip to content

Instantly share code, notes, and snippets.

View JeffreySarnoff's full-sized avatar

Jeffrey Sarnoff JeffreySarnoff

View GitHub Profile
@JeffreySarnoff
JeffreySarnoff / errorfree_introduction.md
Created July 7, 2020 04:23
introducing the notion of an error-free arithmetic operation

Introduction

An error-free transformation [EFT] is a transformation of a floating point realization of a mathematical operation that preserves the information inherent in the operation. Ordinary floating point addition of two Float64 values returns only that information about the sum which fits within a Float64 variable. For example, where flsum is short for ordinary_Float64_sum and flsum_errorfree is flsum with the remaining value that usually is lost in calculation.

flsum = 1.0 + 2.0^(-60)
flsum == 1.0

An error-free transformation of the floating point sum preserves the full value by returning two quantities.

flsum_errorfree = errorfree_sum(1.0, 2.0^(-60))
@JeffreySarnoff
JeffreySarnoff / errorfree_arithmetic.jl
Last active July 7, 2020 04:21
error-free & least-error transformations with mixed precision arithmetic ops
#=
errorfree_arithmetic.jl
Copyright 2020 by Jeffrey Sarnoff
Released under the MIT License
Questions and Comments are Welcome.
Ask on Discourse or raise an issue: https://github.com/JeffreySarnoff/ErrorfreeArithmetic.jl/issues
=#
@JeffreySarnoff
JeffreySarnoff / rationalrev_part1.jl
Last active May 1, 2020 09:53
revising rational.jl (first part of the file)`
"""
Rational{T<:Integer} <: Real
Rational number type, with numerator and denominator of type `T`.
Rationals are checked for overflow.
"""
struct Rational{T<:Integer} <: Real
num::T
den::T
@JeffreySarnoff
JeffreySarnoff / BenchmarkingRationals.jl
Last active April 26, 2020 13:11
benchmarks used to compare the PR for `rational.jl` with the current `rational.jl`
using LinearAlgebra
#=
you set this directory with the const or through the environment
ensure RelativeSpeeds.jl and Fractions.jl are kept there
=#
const DefaultBenchmarkingDir = pwd()
benchmarking_dir = haskey(ENV, "BenchmarkingDir") ? ENV["BenchmarkingDir"] : DefaultBenchmarkingDir
cd(benchmarking_dir)
@JeffreySarnoff
JeffreySarnoff / RelativeSpeeds.jl
Last active April 26, 2020 05:25
ascertain the performance of `fn(xs::T1)` relative to `fn(xs::T2)`
# enable benchmarking, force paramter presets
try
using BenchmarkTools
BTools=BenchmarkTools.DEFAULT_PARAMETERS;
BTools.overhead = BenchmarkTools.estimate_overhead();
BTools.evals=1; BTools.samples = 7000;
BTools.time_tolerance = 1e-8;
catch
error("BenchmarkTools.jl not found")
@JeffreySarnoff
JeffreySarnoff / Fractions.jl
Last active April 26, 2020 04:34
follows PR for improving `rationals.jl`, renames `Rational` to `Fraction`, renames `//` to `⨸`
# 2020-04-24 11:03 UTC, module follows PR for improving `rationals.jl`
# This file is a part of Julia. License is MIT: https://julialang.org/license
module Fractions
export Fraction, ⨸
import Base: show, read, write, fma,
BitSigned, Bool, AbstractFloat, big, BigInt, float,
==, !=, >, >=, <, <=, isequal, isless,
@JeffreySarnoff
JeffreySarnoff / rational_pr_summary_for_triage.md
Last active April 23, 2020 07:16
summary of rational.jl improvements and questions for #triage

In Breif

Over five years, members of the community have been discussing Julia's Rational Number implementation and experimenting with modifications intended to increase the performance of Rational arithmetic while protecting correctness and catching arithmetic exceptions (overflow, underflow, division by zero).

We have an approach that speeds up correct multiplication (division). The prod of 12 rationals is faster than v1.4.1 by at least 1.5x using Rational{Int64}, 1.25x using Rational{BigInt}. In this implementation, rational addition, subtraction do not speed up.

There are several ways to approach coding the core constructor. The specifics are discussed in this PR. We ask #triage to choose which it deem the most appropriate.

The Construction Approaches

@JeffreySarnoff
JeffreySarnoff / rational.jl
Last active April 23, 2020 07:25
a faster version of rational.jl (see https://github.com/JuliaLang/julia/pull/35492#)
# This file is a part of Julia. License is MIT: https://julialang.org/license
"""
Rational{T<:Integer} <: Real
Rational number type, with numerator and denominator of type `T`.
Rationals are checked for overflow.
"""
struct Rational{T<:Integer} <: Real
num::T
@JeffreySarnoff
JeffreySarnoff / Fractions.jl
Last active April 22, 2020 14:36
`Fractions.jl` exports Fraction \odiv
module Fractions
export Fraction, ⨸
# This file is an edited version of fraction.jl, a part of Julia. License is MIT: https://julialang.org/license
import Base: show, read, write, fma,
BitSigned, Bool, AbstractFloat, big, BigInt, float,
==, !=, >, >=, <, <=, isequal, isless,
zero, one, iszero, isone,
@JeffreySarnoff
JeffreySarnoff / BenchmarkToolsWrapping.jl
Last active February 25, 2020 04:42
BenchmarkTools: a macro to wrap `$x` as `$(Ref(x))[]`
#=
This material is the work of Mason Protter
https://github.com/JuliaCI/BenchmarkTools.jl/pull/140
id(x) = x
a, b = 1, 2
sym = :sym
@refd :($a)