
(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 6 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 -2.9e+58)
x
(if (<= z -5.5e-78)
(/ y z)
(if (<= z -3.4e-106)
t_0
(if (<= z -1.15e-210)
(/ y z)
(if (<= z 1.75e-283)
t_0
(if (or (<= z 1800000000000.0)
(and (not (<= z 3.5e+71)) (<= z 4.5e+104)))
(/ y z)
x))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -2.9e+58) {
tmp = x;
} else if (z <= -5.5e-78) {
tmp = y / z;
} else if (z <= -3.4e-106) {
tmp = t_0;
} else if (z <= -1.15e-210) {
tmp = y / z;
} else if (z <= 1.75e-283) {
tmp = t_0;
} else if ((z <= 1800000000000.0) || (!(z <= 3.5e+71) && (z <= 4.5e+104))) {
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 <= (-2.9d+58)) then
tmp = x
else if (z <= (-5.5d-78)) then
tmp = y / z
else if (z <= (-3.4d-106)) then
tmp = t_0
else if (z <= (-1.15d-210)) then
tmp = y / z
else if (z <= 1.75d-283) then
tmp = t_0
else if ((z <= 1800000000000.0d0) .or. (.not. (z <= 3.5d+71)) .and. (z <= 4.5d+104)) 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 <= -2.9e+58) {
tmp = x;
} else if (z <= -5.5e-78) {
tmp = y / z;
} else if (z <= -3.4e-106) {
tmp = t_0;
} else if (z <= -1.15e-210) {
tmp = y / z;
} else if (z <= 1.75e-283) {
tmp = t_0;
} else if ((z <= 1800000000000.0) || (!(z <= 3.5e+71) && (z <= 4.5e+104))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -2.9e+58: tmp = x elif z <= -5.5e-78: tmp = y / z elif z <= -3.4e-106: tmp = t_0 elif z <= -1.15e-210: tmp = y / z elif z <= 1.75e-283: tmp = t_0 elif (z <= 1800000000000.0) or (not (z <= 3.5e+71) and (z <= 4.5e+104)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -2.9e+58) tmp = x; elseif (z <= -5.5e-78) tmp = Float64(y / z); elseif (z <= -3.4e-106) tmp = t_0; elseif (z <= -1.15e-210) tmp = Float64(y / z); elseif (z <= 1.75e-283) tmp = t_0; elseif ((z <= 1800000000000.0) || (!(z <= 3.5e+71) && (z <= 4.5e+104))) 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 <= -2.9e+58) tmp = x; elseif (z <= -5.5e-78) tmp = y / z; elseif (z <= -3.4e-106) tmp = t_0; elseif (z <= -1.15e-210) tmp = y / z; elseif (z <= 1.75e-283) tmp = t_0; elseif ((z <= 1800000000000.0) || (~((z <= 3.5e+71)) && (z <= 4.5e+104))) 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, -2.9e+58], x, If[LessEqual[z, -5.5e-78], N[(y / z), $MachinePrecision], If[LessEqual[z, -3.4e-106], t$95$0, If[LessEqual[z, -1.15e-210], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.75e-283], t$95$0, If[Or[LessEqual[z, 1800000000000.0], And[N[Not[LessEqual[z, 3.5e+71]], $MachinePrecision], LessEqual[z, 4.5e+104]]], N[(y / z), $MachinePrecision], x]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -2.9 \cdot 10^{+58}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -5.5 \cdot 10^{-78}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -3.4 \cdot 10^{-106}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.15 \cdot 10^{-210}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.75 \cdot 10^{-283}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1800000000000 \lor \neg \left(z \leq 3.5 \cdot 10^{+71}\right) \land z \leq 4.5 \cdot 10^{+104}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.90000000000000002e58 or 1.8e12 < z < 3.4999999999999999e71 or 4.4999999999999998e104 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 78.6%
Taylor expanded in z around inf 78.6%
if -2.90000000000000002e58 < z < -5.50000000000000017e-78 or -3.39999999999999982e-106 < z < -1.15e-210 or 1.7499999999999999e-283 < z < 1.8e12 or 3.4999999999999999e71 < z < 4.4999999999999998e104Initial program 100.0%
div-sub96.8%
associate-+r-96.8%
remove-double-neg96.8%
distribute-frac-neg96.8%
unsub-neg96.8%
associate--r+96.8%
+-commutative96.8%
distribute-frac-neg96.8%
sub-neg96.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 71.9%
neg-mul-171.9%
distribute-neg-frac71.9%
Simplified71.9%
Taylor expanded in x around 0 67.1%
if -5.50000000000000017e-78 < z < -3.39999999999999982e-106 or -1.15e-210 < z < 1.7499999999999999e-283Initial program 100.0%
div-sub96.4%
associate-+r-96.4%
remove-double-neg96.4%
distribute-frac-neg96.4%
unsub-neg96.4%
associate--r+96.4%
+-commutative96.4%
distribute-frac-neg96.4%
sub-neg96.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 74.9%
Taylor expanded in z around 0 74.9%
mul-1-neg74.9%
distribute-frac-neg74.9%
Simplified74.9%
Final simplification72.4%
(FPCore (x y z)
:precision binary64
(if (<= z -1.8e+58)
x
(if (or (<= z 31000000000000.0) (and (not (<= z 3.4e+71)) (<= z 1.45e+105)))
(/ y z)
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.8e+58) {
tmp = x;
} else if ((z <= 31000000000000.0) || (!(z <= 3.4e+71) && (z <= 1.45e+105))) {
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 <= (-1.8d+58)) then
tmp = x
else if ((z <= 31000000000000.0d0) .or. (.not. (z <= 3.4d+71)) .and. (z <= 1.45d+105)) 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 <= -1.8e+58) {
tmp = x;
} else if ((z <= 31000000000000.0) || (!(z <= 3.4e+71) && (z <= 1.45e+105))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.8e+58: tmp = x elif (z <= 31000000000000.0) or (not (z <= 3.4e+71) and (z <= 1.45e+105)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.8e+58) tmp = x; elseif ((z <= 31000000000000.0) || (!(z <= 3.4e+71) && (z <= 1.45e+105))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.8e+58) tmp = x; elseif ((z <= 31000000000000.0) || (~((z <= 3.4e+71)) && (z <= 1.45e+105))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.8e+58], x, If[Or[LessEqual[z, 31000000000000.0], And[N[Not[LessEqual[z, 3.4e+71]], $MachinePrecision], LessEqual[z, 1.45e+105]]], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{+58}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 31000000000000 \lor \neg \left(z \leq 3.4 \cdot 10^{+71}\right) \land z \leq 1.45 \cdot 10^{+105}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.79999999999999998e58 or 3.1e13 < z < 3.3999999999999998e71 or 1.45000000000000005e105 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 78.6%
Taylor expanded in z around inf 78.6%
if -1.79999999999999998e58 < z < 3.1e13 or 3.3999999999999998e71 < z < 1.45000000000000005e105Initial program 100.0%
div-sub96.8%
associate-+r-96.8%
remove-double-neg96.8%
distribute-frac-neg96.8%
unsub-neg96.8%
associate--r+96.8%
+-commutative96.8%
distribute-frac-neg96.8%
sub-neg96.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 65.9%
neg-mul-165.9%
distribute-neg-frac65.9%
Simplified65.9%
Taylor expanded in x around 0 61.8%
Final simplification68.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.4e+107) (not (<= x 5.4e+25))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e+107) || !(x <= 5.4e+25)) {
tmp = x - (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 <= (-1.4d+107)) .or. (.not. (x <= 5.4d+25))) then
tmp = x - (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 <= -1.4e+107) || !(x <= 5.4e+25)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.4e+107) or not (x <= 5.4e+25): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.4e+107) || !(x <= 5.4e+25)) tmp = Float64(x - 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 <= -1.4e+107) || ~((x <= 5.4e+25))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.4e+107], N[Not[LessEqual[x, 5.4e+25]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+107} \lor \neg \left(x \leq 5.4 \cdot 10^{+25}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.39999999999999992e107 or 5.4e25 < x Initial program 100.0%
div-sub95.1%
associate-+r-95.1%
remove-double-neg95.1%
distribute-frac-neg95.1%
unsub-neg95.1%
associate--r+95.1%
+-commutative95.1%
distribute-frac-neg95.1%
sub-neg95.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 88.4%
if -1.39999999999999992e107 < x < 5.4e25Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 90.1%
neg-mul-190.1%
distribute-neg-frac90.1%
Simplified90.1%
Taylor expanded in x around 0 90.1%
+-commutative90.1%
Simplified90.1%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (+ x (/ y z)))
double code(double x, double y, double z) {
return x + (y / 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 / z)
end function
public static double code(double x, double y, double z) {
return x + (y / z);
}
def code(x, y, z): return x + (y / z)
function code(x, y, z) return Float64(x + Float64(y / z)) end
function tmp = code(x, y, z) tmp = x + (y / z); end
code[x_, y_, z_] := N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{z}
\end{array}
Initial program 100.0%
div-sub98.0%
associate-+r-98.0%
remove-double-neg98.0%
distribute-frac-neg98.0%
unsub-neg98.0%
associate--r+98.0%
+-commutative98.0%
distribute-frac-neg98.0%
sub-neg98.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 79.2%
neg-mul-179.2%
distribute-neg-frac79.2%
Simplified79.2%
Taylor expanded in x around 0 79.2%
+-commutative79.2%
Simplified79.2%
Final simplification79.2%
(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%
div-sub98.0%
associate-+r-98.0%
remove-double-neg98.0%
distribute-frac-neg98.0%
unsub-neg98.0%
associate--r+98.0%
+-commutative98.0%
distribute-frac-neg98.0%
sub-neg98.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 56.9%
Taylor expanded in z around inf 34.4%
Final simplification34.4%
herbie shell --seed 2024040
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))