
(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%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ x (- z))))
(if (<= z -4e+89)
x
(if (<= z -5.4e-41)
(/ y z)
(if (<= z -4.8e-83)
t_0
(if (<= z -1.85e-102)
(/ y z)
(if (<= z -4.6e-245)
t_0
(if (<= z 3.8e-198)
(/ y z)
(if (<= z 1.7e-19)
t_0
(if (<= z 470000000.0) (/ y z) x))))))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -4e+89) {
tmp = x;
} else if (z <= -5.4e-41) {
tmp = y / z;
} else if (z <= -4.8e-83) {
tmp = t_0;
} else if (z <= -1.85e-102) {
tmp = y / z;
} else if (z <= -4.6e-245) {
tmp = t_0;
} else if (z <= 3.8e-198) {
tmp = y / z;
} else if (z <= 1.7e-19) {
tmp = t_0;
} else if (z <= 470000000.0) {
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 <= (-4d+89)) then
tmp = x
else if (z <= (-5.4d-41)) then
tmp = y / z
else if (z <= (-4.8d-83)) then
tmp = t_0
else if (z <= (-1.85d-102)) then
tmp = y / z
else if (z <= (-4.6d-245)) then
tmp = t_0
else if (z <= 3.8d-198) then
tmp = y / z
else if (z <= 1.7d-19) then
tmp = t_0
else if (z <= 470000000.0d0) 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 <= -4e+89) {
tmp = x;
} else if (z <= -5.4e-41) {
tmp = y / z;
} else if (z <= -4.8e-83) {
tmp = t_0;
} else if (z <= -1.85e-102) {
tmp = y / z;
} else if (z <= -4.6e-245) {
tmp = t_0;
} else if (z <= 3.8e-198) {
tmp = y / z;
} else if (z <= 1.7e-19) {
tmp = t_0;
} else if (z <= 470000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -4e+89: tmp = x elif z <= -5.4e-41: tmp = y / z elif z <= -4.8e-83: tmp = t_0 elif z <= -1.85e-102: tmp = y / z elif z <= -4.6e-245: tmp = t_0 elif z <= 3.8e-198: tmp = y / z elif z <= 1.7e-19: tmp = t_0 elif z <= 470000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -4e+89) tmp = x; elseif (z <= -5.4e-41) tmp = Float64(y / z); elseif (z <= -4.8e-83) tmp = t_0; elseif (z <= -1.85e-102) tmp = Float64(y / z); elseif (z <= -4.6e-245) tmp = t_0; elseif (z <= 3.8e-198) tmp = Float64(y / z); elseif (z <= 1.7e-19) tmp = t_0; elseif (z <= 470000000.0) 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 <= -4e+89) tmp = x; elseif (z <= -5.4e-41) tmp = y / z; elseif (z <= -4.8e-83) tmp = t_0; elseif (z <= -1.85e-102) tmp = y / z; elseif (z <= -4.6e-245) tmp = t_0; elseif (z <= 3.8e-198) tmp = y / z; elseif (z <= 1.7e-19) tmp = t_0; elseif (z <= 470000000.0) 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, -4e+89], x, If[LessEqual[z, -5.4e-41], N[(y / z), $MachinePrecision], If[LessEqual[z, -4.8e-83], t$95$0, If[LessEqual[z, -1.85e-102], N[(y / z), $MachinePrecision], If[LessEqual[z, -4.6e-245], t$95$0, If[LessEqual[z, 3.8e-198], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.7e-19], t$95$0, If[LessEqual[z, 470000000.0], N[(y / z), $MachinePrecision], x]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -4 \cdot 10^{+89}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -5.4 \cdot 10^{-41}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -4.8 \cdot 10^{-83}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.85 \cdot 10^{-102}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -4.6 \cdot 10^{-245}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-198}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{-19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 470000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.99999999999999998e89 or 4.7e8 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 77.4%
if -3.99999999999999998e89 < z < -5.4e-41 or -4.8000000000000002e-83 < z < -1.8499999999999999e-102 or -4.6000000000000003e-245 < z < 3.8000000000000002e-198 or 1.7000000000000001e-19 < z < 4.7e8Initial program 100.0%
div-sub98.8%
sub-neg98.8%
distribute-frac-neg98.8%
+-commutative98.8%
associate-+r+98.8%
distribute-frac-neg98.8%
sub-neg98.8%
associate--r-98.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 71.1%
if -5.4e-41 < z < -4.8000000000000002e-83 or -1.8499999999999999e-102 < z < -4.6000000000000003e-245 or 3.8000000000000002e-198 < z < 1.7000000000000001e-19Initial program 99.9%
div-sub97.3%
sub-neg97.3%
distribute-frac-neg97.3%
+-commutative97.3%
associate-+r+97.3%
distribute-frac-neg97.3%
sub-neg97.3%
associate--r-97.3%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around inf 66.8%
Taylor expanded in z around 0 66.8%
associate-*r/66.8%
neg-mul-166.8%
Simplified66.8%
Final simplification72.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -42.0) (not (<= z 0.48))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -42.0) || !(z <= 0.48)) {
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 <= (-42.0d0)) .or. (.not. (z <= 0.48d0))) 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 <= -42.0) || !(z <= 0.48)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -42.0) or not (z <= 0.48): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -42.0) || !(z <= 0.48)) 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 <= -42.0) || ~((z <= 0.48))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -42.0], N[Not[LessEqual[z, 0.48]], $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 -42 \lor \neg \left(z \leq 0.48\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -42 or 0.47999999999999998 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
neg-mul-198.9%
distribute-neg-frac298.9%
Simplified98.9%
Taylor expanded in x around 0 98.9%
cancel-sign-sub-inv98.9%
metadata-eval98.9%
*-lft-identity98.9%
+-commutative98.9%
Simplified98.9%
if -42 < z < 0.47999999999999998Initial program 99.9%
div-sub97.7%
sub-neg97.7%
distribute-frac-neg97.7%
+-commutative97.7%
associate-+r+97.7%
distribute-frac-neg97.7%
sub-neg97.7%
associate--r-97.7%
div-sub99.9%
Simplified99.9%
Taylor expanded in z around 0 99.4%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.55e+50) (not (<= x 3.2e+34))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e+50) || !(x <= 3.2e+34)) {
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.55d+50)) .or. (.not. (x <= 3.2d+34))) 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.55e+50) || !(x <= 3.2e+34)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e+50) or not (x <= 3.2e+34): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.55e+50) || !(x <= 3.2e+34)) 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.55e+50) || ~((x <= 3.2e+34))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55e+50], N[Not[LessEqual[x, 3.2e+34]], $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.55 \cdot 10^{+50} \lor \neg \left(x \leq 3.2 \cdot 10^{+34}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.55000000000000001e50 or 3.1999999999999998e34 < x Initial program 100.0%
div-sub97.3%
sub-neg97.3%
distribute-frac-neg97.3%
+-commutative97.3%
associate-+r+97.3%
distribute-frac-neg97.3%
sub-neg97.3%
associate--r-97.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 92.6%
if -1.55000000000000001e50 < x < 3.1999999999999998e34Initial program 99.9%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 84.9%
neg-mul-184.9%
distribute-neg-frac284.9%
Simplified84.9%
Taylor expanded in x around 0 84.9%
cancel-sign-sub-inv84.9%
metadata-eval84.9%
*-lft-identity84.9%
+-commutative84.9%
Simplified84.9%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.65e-112) (not (<= y -2.5e-271))) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.65e-112) || !(y <= -2.5e-271)) {
tmp = x + (y / z);
} else {
tmp = 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 <= (-1.65d-112)) .or. (.not. (y <= (-2.5d-271)))) then
tmp = x + (y / z)
else
tmp = x / -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.65e-112) || !(y <= -2.5e-271)) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.65e-112) or not (y <= -2.5e-271): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.65e-112) || !(y <= -2.5e-271)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x / Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.65e-112) || ~((y <= -2.5e-271))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.65e-112], N[Not[LessEqual[y, -2.5e-271]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-112} \lor \neg \left(y \leq -2.5 \cdot 10^{-271}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if y < -1.65e-112 or -2.5000000000000001e-271 < y Initial program 100.0%
div-sub98.7%
sub-neg98.7%
distribute-frac-neg98.7%
+-commutative98.7%
associate-+r+98.7%
distribute-frac-neg98.7%
sub-neg98.7%
associate--r-98.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 80.0%
neg-mul-180.0%
distribute-neg-frac280.0%
Simplified80.0%
Taylor expanded in x around 0 80.0%
cancel-sign-sub-inv80.0%
metadata-eval80.0%
*-lft-identity80.0%
+-commutative80.0%
Simplified80.0%
if -1.65e-112 < y < -2.5000000000000001e-271Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 92.6%
Taylor expanded in z around 0 73.2%
associate-*r/73.2%
neg-mul-173.2%
Simplified73.2%
Final simplification79.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.85e+83) x (if (<= z 550000000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.85e+83) {
tmp = x;
} else if (z <= 550000000.0) {
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.85d+83)) then
tmp = x
else if (z <= 550000000.0d0) 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.85e+83) {
tmp = x;
} else if (z <= 550000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.85e+83: tmp = x elif z <= 550000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.85e+83) tmp = x; elseif (z <= 550000000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.85e+83) tmp = x; elseif (z <= 550000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.85e+83], x, If[LessEqual[z, 550000000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{+83}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 550000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.8500000000000001e83 or 5.5e8 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 77.4%
if -1.8500000000000001e83 < z < 5.5e8Initial program 99.9%
div-sub98.1%
sub-neg98.1%
distribute-frac-neg98.1%
+-commutative98.1%
associate-+r+98.1%
distribute-frac-neg98.1%
sub-neg98.1%
associate--r-98.1%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 55.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%
div-sub98.8%
sub-neg98.8%
distribute-frac-neg98.8%
+-commutative98.8%
associate-+r+98.8%
distribute-frac-neg98.8%
sub-neg98.8%
associate--r-98.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 33.9%
herbie shell --seed 2024085
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))