
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) / z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) / z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) / z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (- x) z)))
(if (<= z -0.007)
x
(if (<= z -1.2e-69)
(/ y z)
(if (<= z -1.25e-154)
t_0
(if (<= z 3.4e-308)
(/ y z)
(if (<= z 3.8e-294)
t_0
(if (<= z 6.2e-217)
(/ y z)
(if (<= z 2.1e-23) t_0 (if (<= z 1.5e+150) (/ y z) x))))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -0.007) {
tmp = x;
} else if (z <= -1.2e-69) {
tmp = y / z;
} else if (z <= -1.25e-154) {
tmp = t_0;
} else if (z <= 3.4e-308) {
tmp = y / z;
} else if (z <= 3.8e-294) {
tmp = t_0;
} else if (z <= 6.2e-217) {
tmp = y / z;
} else if (z <= 2.1e-23) {
tmp = t_0;
} else if (z <= 1.5e+150) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = -x / z
if (z <= (-0.007d0)) then
tmp = x
else if (z <= (-1.2d-69)) then
tmp = y / z
else if (z <= (-1.25d-154)) then
tmp = t_0
else if (z <= 3.4d-308) then
tmp = y / z
else if (z <= 3.8d-294) then
tmp = t_0
else if (z <= 6.2d-217) then
tmp = y / z
else if (z <= 2.1d-23) then
tmp = t_0
else if (z <= 1.5d+150) then
tmp = y / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -0.007) {
tmp = x;
} else if (z <= -1.2e-69) {
tmp = y / z;
} else if (z <= -1.25e-154) {
tmp = t_0;
} else if (z <= 3.4e-308) {
tmp = y / z;
} else if (z <= 3.8e-294) {
tmp = t_0;
} else if (z <= 6.2e-217) {
tmp = y / z;
} else if (z <= 2.1e-23) {
tmp = t_0;
} else if (z <= 1.5e+150) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -0.007: tmp = x elif z <= -1.2e-69: tmp = y / z elif z <= -1.25e-154: tmp = t_0 elif z <= 3.4e-308: tmp = y / z elif z <= 3.8e-294: tmp = t_0 elif z <= 6.2e-217: tmp = y / z elif z <= 2.1e-23: tmp = t_0 elif z <= 1.5e+150: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -0.007) tmp = x; elseif (z <= -1.2e-69) tmp = Float64(y / z); elseif (z <= -1.25e-154) tmp = t_0; elseif (z <= 3.4e-308) tmp = Float64(y / z); elseif (z <= 3.8e-294) tmp = t_0; elseif (z <= 6.2e-217) tmp = Float64(y / z); elseif (z <= 2.1e-23) tmp = t_0; elseif (z <= 1.5e+150) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -0.007) tmp = x; elseif (z <= -1.2e-69) tmp = y / z; elseif (z <= -1.25e-154) tmp = t_0; elseif (z <= 3.4e-308) tmp = y / z; elseif (z <= 3.8e-294) tmp = t_0; elseif (z <= 6.2e-217) tmp = y / z; elseif (z <= 2.1e-23) tmp = t_0; elseif (z <= 1.5e+150) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -0.007], x, If[LessEqual[z, -1.2e-69], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.25e-154], t$95$0, If[LessEqual[z, 3.4e-308], N[(y / z), $MachinePrecision], If[LessEqual[z, 3.8e-294], t$95$0, If[LessEqual[z, 6.2e-217], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.1e-23], t$95$0, If[LessEqual[z, 1.5e+150], N[(y / z), $MachinePrecision], x]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -0.007:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.2 \cdot 10^{-69}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.25 \cdot 10^{-154}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{-308}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-294}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{-217}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-23}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+150}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.00700000000000000015 or 1.50000000000000006e150 < z Initial program 100.0%
Taylor expanded in z around inf 81.3%
if -0.00700000000000000015 < z < -1.2000000000000001e-69 or -1.25000000000000005e-154 < z < 3.39999999999999999e-308 or 3.8e-294 < z < 6.1999999999999997e-217 or 2.1000000000000001e-23 < z < 1.50000000000000006e150Initial program 99.9%
Taylor expanded in x around 0 65.4%
if -1.2000000000000001e-69 < z < -1.25000000000000005e-154 or 3.39999999999999999e-308 < z < 3.8e-294 or 6.1999999999999997e-217 < z < 2.1000000000000001e-23Initial program 100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in y around 0 70.8%
neg-mul-170.8%
distribute-neg-frac70.8%
Simplified70.8%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.1e+35) (not (<= y 8.5e-107))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e+35) || !(y <= 8.5e-107)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-2.1d+35)) .or. (.not. (y <= 8.5d-107))) then
tmp = x + (y / z)
else
tmp = x - (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e+35) || !(y <= 8.5e-107)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.1e+35) or not (y <= 8.5e-107): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.1e+35) || !(y <= 8.5e-107)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.1e+35) || ~((y <= 8.5e-107))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.1e+35], N[Not[LessEqual[y, 8.5e-107]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{+35} \lor \neg \left(y \leq 8.5 \cdot 10^{-107}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.0999999999999999e35 or 8.49999999999999956e-107 < y Initial program 99.9%
clear-num99.8%
inv-pow99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 90.8%
if -2.0999999999999999e35 < y < 8.49999999999999956e-107Initial program 100.0%
Taylor expanded in y around 0 88.8%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = x + (y / z)
else
tmp = (y - x) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(y - x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 1.0))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
clear-num99.6%
inv-pow99.6%
Applied egg-rr99.6%
Taylor expanded in y around inf 99.2%
if -1 < z < 1Initial program 99.9%
Taylor expanded in z around 0 97.9%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (<= z -0.007) x (if (<= z 1.5e+150) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.007) {
tmp = x;
} else if (z <= 1.5e+150) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-0.007d0)) then
tmp = x
else if (z <= 1.5d+150) then
tmp = y / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -0.007) {
tmp = x;
} else if (z <= 1.5e+150) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.007: tmp = x elif z <= 1.5e+150: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.007) tmp = x; elseif (z <= 1.5e+150) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.007) tmp = x; elseif (z <= 1.5e+150) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.007], x, If[LessEqual[z, 1.5e+150], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.007:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+150}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.00700000000000000015 or 1.50000000000000006e150 < z Initial program 100.0%
Taylor expanded in z around inf 81.3%
if -0.00700000000000000015 < z < 1.50000000000000006e150Initial program 99.9%
Taylor expanded in x around 0 53.4%
Final simplification64.2%
(FPCore (x y z) :precision binary64 (if (<= x -7.2e+124) (/ (- x) z) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e+124) {
tmp = -x / z;
} else {
tmp = x + (y / z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-7.2d+124)) then
tmp = -x / z
else
tmp = x + (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e+124) {
tmp = -x / z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.2e+124: tmp = -x / z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.2e+124) tmp = Float64(Float64(-x) / z); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.2e+124) tmp = -x / z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.2e+124], N[((-x) / z), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+124}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -7.19999999999999972e124Initial program 99.9%
Taylor expanded in z around 0 63.3%
Taylor expanded in y around 0 57.3%
neg-mul-157.3%
distribute-neg-frac57.3%
Simplified57.3%
if -7.19999999999999972e124 < x Initial program 100.0%
clear-num99.6%
inv-pow99.6%
Applied egg-rr99.6%
Taylor expanded in y around inf 80.5%
Final simplification77.4%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 37.5%
Final simplification37.5%
herbie shell --seed 2023242
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))