
(FPCore (lo hi x) :precision binary64 (/ (- x lo) (- hi lo)))
double code(double lo, double hi, double x) {
return (x - lo) / (hi - lo);
}
real(8) function code(lo, hi, x)
real(8), intent (in) :: lo
real(8), intent (in) :: hi
real(8), intent (in) :: x
code = (x - lo) / (hi - lo)
end function
public static double code(double lo, double hi, double x) {
return (x - lo) / (hi - lo);
}
def code(lo, hi, x): return (x - lo) / (hi - lo)
function code(lo, hi, x) return Float64(Float64(x - lo) / Float64(hi - lo)) end
function tmp = code(lo, hi, x) tmp = (x - lo) / (hi - lo); end
code[lo_, hi_, x_] := N[(N[(x - lo), $MachinePrecision] / N[(hi - lo), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - lo}{hi - lo}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (lo hi x) :precision binary64 (/ (- x lo) (- hi lo)))
double code(double lo, double hi, double x) {
return (x - lo) / (hi - lo);
}
real(8) function code(lo, hi, x)
real(8), intent (in) :: lo
real(8), intent (in) :: hi
real(8), intent (in) :: x
code = (x - lo) / (hi - lo)
end function
public static double code(double lo, double hi, double x) {
return (x - lo) / (hi - lo);
}
def code(lo, hi, x): return (x - lo) / (hi - lo)
function code(lo, hi, x) return Float64(Float64(x - lo) / Float64(hi - lo)) end
function tmp = code(lo, hi, x) tmp = (x - lo) / (hi - lo); end
code[lo_, hi_, x_] := N[(N[(x - lo), $MachinePrecision] / N[(hi - lo), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - lo}{hi - lo}
\end{array}
(FPCore (lo hi x) :precision binary64 (let* ((t_0 (/ (- x lo) hi))) (expm1 (+ t_0 (* -0.5 (pow t_0 2.0))))))
double code(double lo, double hi, double x) {
double t_0 = (x - lo) / hi;
return expm1((t_0 + (-0.5 * pow(t_0, 2.0))));
}
public static double code(double lo, double hi, double x) {
double t_0 = (x - lo) / hi;
return Math.expm1((t_0 + (-0.5 * Math.pow(t_0, 2.0))));
}
def code(lo, hi, x): t_0 = (x - lo) / hi return math.expm1((t_0 + (-0.5 * math.pow(t_0, 2.0))))
function code(lo, hi, x) t_0 = Float64(Float64(x - lo) / hi) return expm1(Float64(t_0 + Float64(-0.5 * (t_0 ^ 2.0)))) end
code[lo_, hi_, x_] := Block[{t$95$0 = N[(N[(x - lo), $MachinePrecision] / hi), $MachinePrecision]}, N[(Exp[N[(t$95$0 + N[(-0.5 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - lo}{hi}\\
\mathsf{expm1}\left(t\_0 + -0.5 \cdot {t\_0}^{2}\right)
\end{array}
\end{array}
Initial program 3.1%
Taylor expanded in hi around inf 18.8%
expm1-log1p-u18.8%
expm1-undefine18.8%
Applied egg-rr18.8%
expm1-define18.8%
Simplified18.8%
Taylor expanded in hi around inf 0.0%
associate--l+0.0%
div-sub0.0%
fma-define0.0%
unpow20.0%
unpow20.0%
times-frac21.8%
unpow221.8%
Simplified21.8%
fma-undefine21.8%
+-commutative21.8%
Applied egg-rr21.8%
Final simplification21.8%
(FPCore (lo hi x) :precision binary64 (expm1 (fma -0.5 (pow (* (- x lo) (/ (pow hi -0.5) (sqrt hi))) 2.0) (/ (- x lo) hi))))
double code(double lo, double hi, double x) {
return expm1(fma(-0.5, pow(((x - lo) * (pow(hi, -0.5) / sqrt(hi))), 2.0), ((x - lo) / hi)));
}
function code(lo, hi, x) return expm1(fma(-0.5, (Float64(Float64(x - lo) * Float64((hi ^ -0.5) / sqrt(hi))) ^ 2.0), Float64(Float64(x - lo) / hi))) end
code[lo_, hi_, x_] := N[(Exp[N[(-0.5 * N[Power[N[(N[(x - lo), $MachinePrecision] * N[(N[Power[hi, -0.5], $MachinePrecision] / N[Sqrt[hi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(x - lo), $MachinePrecision] / hi), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(\mathsf{fma}\left(-0.5, {\left(\left(x - lo\right) \cdot \frac{{hi}^{-0.5}}{\sqrt{hi}}\right)}^{2}, \frac{x - lo}{hi}\right)\right)
\end{array}
Initial program 3.1%
Taylor expanded in hi around inf 18.8%
expm1-log1p-u18.8%
expm1-undefine18.8%
Applied egg-rr18.8%
expm1-define18.8%
Simplified18.8%
Taylor expanded in hi around inf 0.0%
associate--l+0.0%
div-sub0.0%
fma-define0.0%
unpow20.0%
unpow20.0%
times-frac21.8%
unpow221.8%
Simplified21.8%
*-un-lft-identity21.8%
add-sqr-sqrt21.8%
times-frac21.8%
metadata-eval21.8%
sqrt-div21.8%
inv-pow21.8%
sqrt-pow121.8%
metadata-eval21.8%
Applied egg-rr21.8%
associate-*r/21.8%
*-commutative21.8%
associate-/l*21.8%
Simplified21.8%
Final simplification21.8%
(FPCore (lo hi x) :precision binary64 (let* ((t_0 (/ (- x lo) hi))) (/ (* t_0 (+ 2.0 (/ x hi))) (+ 2.0 t_0))))
double code(double lo, double hi, double x) {
double t_0 = (x - lo) / hi;
return (t_0 * (2.0 + (x / hi))) / (2.0 + t_0);
}
real(8) function code(lo, hi, x)
real(8), intent (in) :: lo
real(8), intent (in) :: hi
real(8), intent (in) :: x
real(8) :: t_0
t_0 = (x - lo) / hi
code = (t_0 * (2.0d0 + (x / hi))) / (2.0d0 + t_0)
end function
public static double code(double lo, double hi, double x) {
double t_0 = (x - lo) / hi;
return (t_0 * (2.0 + (x / hi))) / (2.0 + t_0);
}
def code(lo, hi, x): t_0 = (x - lo) / hi return (t_0 * (2.0 + (x / hi))) / (2.0 + t_0)
function code(lo, hi, x) t_0 = Float64(Float64(x - lo) / hi) return Float64(Float64(t_0 * Float64(2.0 + Float64(x / hi))) / Float64(2.0 + t_0)) end
function tmp = code(lo, hi, x) t_0 = (x - lo) / hi; tmp = (t_0 * (2.0 + (x / hi))) / (2.0 + t_0); end
code[lo_, hi_, x_] := Block[{t$95$0 = N[(N[(x - lo), $MachinePrecision] / hi), $MachinePrecision]}, N[(N[(t$95$0 * N[(2.0 + N[(x / hi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - lo}{hi}\\
\frac{t\_0 \cdot \left(2 + \frac{x}{hi}\right)}{2 + t\_0}
\end{array}
\end{array}
Initial program 3.1%
Taylor expanded in hi around inf 18.8%
add-cbrt-cube18.8%
pow318.8%
Applied egg-rr18.8%
rem-cbrt-cube18.8%
expm1-log1p-u18.8%
expm1-undefine18.8%
flip--18.8%
log1p-undefine18.8%
rem-exp-log18.8%
+-commutative18.8%
log1p-undefine18.8%
rem-exp-log18.8%
+-commutative18.8%
metadata-eval18.8%
log1p-undefine18.8%
rem-exp-log18.8%
+-commutative18.8%
Applied egg-rr18.8%
difference-of-sqr-118.8%
+-commutative18.8%
+-commutative18.8%
associate-+r+18.8%
metadata-eval18.8%
associate--l+18.8%
metadata-eval18.8%
+-rgt-identity18.8%
+-commutative18.8%
+-commutative18.8%
associate-+r+18.8%
metadata-eval18.8%
Simplified18.8%
Taylor expanded in lo around 0 20.9%
Final simplification20.9%
(FPCore (lo hi x) :precision binary64 (let* ((t_0 (/ (- x lo) hi))) (/ (* 2.0 t_0) (+ 2.0 t_0))))
double code(double lo, double hi, double x) {
double t_0 = (x - lo) / hi;
return (2.0 * t_0) / (2.0 + t_0);
}
real(8) function code(lo, hi, x)
real(8), intent (in) :: lo
real(8), intent (in) :: hi
real(8), intent (in) :: x
real(8) :: t_0
t_0 = (x - lo) / hi
code = (2.0d0 * t_0) / (2.0d0 + t_0)
end function
public static double code(double lo, double hi, double x) {
double t_0 = (x - lo) / hi;
return (2.0 * t_0) / (2.0 + t_0);
}
def code(lo, hi, x): t_0 = (x - lo) / hi return (2.0 * t_0) / (2.0 + t_0)
function code(lo, hi, x) t_0 = Float64(Float64(x - lo) / hi) return Float64(Float64(2.0 * t_0) / Float64(2.0 + t_0)) end
function tmp = code(lo, hi, x) t_0 = (x - lo) / hi; tmp = (2.0 * t_0) / (2.0 + t_0); end
code[lo_, hi_, x_] := Block[{t$95$0 = N[(N[(x - lo), $MachinePrecision] / hi), $MachinePrecision]}, N[(N[(2.0 * t$95$0), $MachinePrecision] / N[(2.0 + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - lo}{hi}\\
\frac{2 \cdot t\_0}{2 + t\_0}
\end{array}
\end{array}
Initial program 3.1%
Taylor expanded in hi around inf 18.8%
add-cbrt-cube18.8%
pow318.8%
Applied egg-rr18.8%
rem-cbrt-cube18.8%
expm1-log1p-u18.8%
expm1-undefine18.8%
flip--18.8%
log1p-undefine18.8%
rem-exp-log18.8%
+-commutative18.8%
log1p-undefine18.8%
rem-exp-log18.8%
+-commutative18.8%
metadata-eval18.8%
log1p-undefine18.8%
rem-exp-log18.8%
+-commutative18.8%
Applied egg-rr18.8%
difference-of-sqr-118.8%
+-commutative18.8%
+-commutative18.8%
associate-+r+18.8%
metadata-eval18.8%
associate--l+18.8%
metadata-eval18.8%
+-rgt-identity18.8%
+-commutative18.8%
+-commutative18.8%
associate-+r+18.8%
metadata-eval18.8%
Simplified18.8%
Taylor expanded in hi around inf 20.9%
Final simplification20.9%
(FPCore (lo hi x) :precision binary64 (/ (- x lo) hi))
double code(double lo, double hi, double x) {
return (x - lo) / hi;
}
real(8) function code(lo, hi, x)
real(8), intent (in) :: lo
real(8), intent (in) :: hi
real(8), intent (in) :: x
code = (x - lo) / hi
end function
public static double code(double lo, double hi, double x) {
return (x - lo) / hi;
}
def code(lo, hi, x): return (x - lo) / hi
function code(lo, hi, x) return Float64(Float64(x - lo) / hi) end
function tmp = code(lo, hi, x) tmp = (x - lo) / hi; end
code[lo_, hi_, x_] := N[(N[(x - lo), $MachinePrecision] / hi), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - lo}{hi}
\end{array}
Initial program 3.1%
Taylor expanded in hi around inf 18.8%
Final simplification18.8%
(FPCore (lo hi x) :precision binary64 (/ lo (- hi)))
double code(double lo, double hi, double x) {
return lo / -hi;
}
real(8) function code(lo, hi, x)
real(8), intent (in) :: lo
real(8), intent (in) :: hi
real(8), intent (in) :: x
code = lo / -hi
end function
public static double code(double lo, double hi, double x) {
return lo / -hi;
}
def code(lo, hi, x): return lo / -hi
function code(lo, hi, x) return Float64(lo / Float64(-hi)) end
function tmp = code(lo, hi, x) tmp = lo / -hi; end
code[lo_, hi_, x_] := N[(lo / (-hi)), $MachinePrecision]
\begin{array}{l}
\\
\frac{lo}{-hi}
\end{array}
Initial program 3.1%
Taylor expanded in lo around 0 18.8%
+-commutative18.8%
mul-1-neg18.8%
unsub-neg18.8%
+-commutative18.8%
mul-1-neg18.8%
unsub-neg18.8%
Simplified18.8%
Taylor expanded in x around 0 18.8%
neg-mul-118.8%
distribute-neg-frac18.8%
Simplified18.8%
Final simplification18.8%
(FPCore (lo hi x) :precision binary64 1.0)
double code(double lo, double hi, double x) {
return 1.0;
}
real(8) function code(lo, hi, x)
real(8), intent (in) :: lo
real(8), intent (in) :: hi
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double lo, double hi, double x) {
return 1.0;
}
def code(lo, hi, x): return 1.0
function code(lo, hi, x) return 1.0 end
function tmp = code(lo, hi, x) tmp = 1.0; end
code[lo_, hi_, x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 3.1%
Taylor expanded in lo around inf 18.6%
Final simplification18.6%
herbie shell --seed 2024059
(FPCore (lo hi x)
:name "xlohi (overflows)"
:precision binary64
:pre (and (< lo -1e+308) (> hi 1e+308))
(/ (- x lo) (- hi lo)))