
(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
(if (<= z -3.7e+37)
x
(if (<= z 8.4e-88)
(/ y z)
(if (<= z 1.45e-28) (/ (- x) z) (if (<= z 3.6e+18) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.7e+37) {
tmp = x;
} else if (z <= 8.4e-88) {
tmp = y / z;
} else if (z <= 1.45e-28) {
tmp = -x / z;
} else if (z <= 3.6e+18) {
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 <= (-3.7d+37)) then
tmp = x
else if (z <= 8.4d-88) then
tmp = y / z
else if (z <= 1.45d-28) then
tmp = -x / z
else if (z <= 3.6d+18) 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 <= -3.7e+37) {
tmp = x;
} else if (z <= 8.4e-88) {
tmp = y / z;
} else if (z <= 1.45e-28) {
tmp = -x / z;
} else if (z <= 3.6e+18) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.7e+37: tmp = x elif z <= 8.4e-88: tmp = y / z elif z <= 1.45e-28: tmp = -x / z elif z <= 3.6e+18: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.7e+37) tmp = x; elseif (z <= 8.4e-88) tmp = Float64(y / z); elseif (z <= 1.45e-28) tmp = Float64(Float64(-x) / z); elseif (z <= 3.6e+18) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.7e+37) tmp = x; elseif (z <= 8.4e-88) tmp = y / z; elseif (z <= 1.45e-28) tmp = -x / z; elseif (z <= 3.6e+18) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.7e+37], x, If[LessEqual[z, 8.4e-88], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.45e-28], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 3.6e+18], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+37}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8.4 \cdot 10^{-88}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{-28}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+18}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.6999999999999999e37 or 3.6e18 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified70.0%
if -3.6999999999999999e37 < z < 8.3999999999999998e-88 or 1.45000000000000006e-28 < z < 3.6e18Initial program 100.0%
Taylor expanded in x around 0
/-lowering-/.f6459.1
Simplified59.1%
if 8.3999999999999998e-88 < z < 1.45000000000000006e-28Initial program 100.0%
Taylor expanded in z around 0
/-lowering-/.f64N/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6477.8
Simplified77.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (/ y z)))) (if (<= z -1.0) t_0 (if (<= z 1.0) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
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 + (y / z)
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 1.0d0) then
tmp = (y - x) / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 1.0: tmp = (y - x) / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 1.0) tmp = Float64(Float64(y - x) / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y / z); tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 1.0) tmp = (y - x) / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 1.0], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6498.2
Simplified98.2%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0
/-lowering-/.f64N/A
--lowering--.f6498.6
Simplified98.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= x -9e+124) t_0 (if (<= x 9200000000.0) (+ x (/ y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (x <= -9e+124) {
tmp = t_0;
} else if (x <= 9200000000.0) {
tmp = x + (y / z);
} else {
tmp = t_0;
}
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 - (x / z)
if (x <= (-9d+124)) then
tmp = t_0
else if (x <= 9200000000.0d0) then
tmp = x + (y / z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (x <= -9e+124) {
tmp = t_0;
} else if (x <= 9200000000.0) {
tmp = x + (y / z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if x <= -9e+124: tmp = t_0 elif x <= 9200000000.0: tmp = x + (y / z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(x / z)) tmp = 0.0 if (x <= -9e+124) tmp = t_0; elseif (x <= 9200000000.0) tmp = Float64(x + Float64(y / z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (x / z); tmp = 0.0; if (x <= -9e+124) tmp = t_0; elseif (x <= 9200000000.0) tmp = x + (y / z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9e+124], t$95$0, If[LessEqual[x, 9200000000.0], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;x \leq -9 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 9200000000:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.0000000000000008e124 or 9.2e9 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
--lowering--.f64N/A
/-lowering-/.f6491.0
Simplified91.0%
if -9.0000000000000008e124 < x < 9.2e9Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6487.9
Simplified87.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (/ y z)))) (if (<= y -1.65e-285) t_0 (if (<= y 1.85e-236) (/ (- x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (y <= -1.65e-285) {
tmp = t_0;
} else if (y <= 1.85e-236) {
tmp = -x / z;
} else {
tmp = t_0;
}
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 + (y / z)
if (y <= (-1.65d-285)) then
tmp = t_0
else if (y <= 1.85d-236) then
tmp = -x / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (y <= -1.65e-285) {
tmp = t_0;
} else if (y <= 1.85e-236) {
tmp = -x / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) tmp = 0 if y <= -1.65e-285: tmp = t_0 elif y <= 1.85e-236: tmp = -x / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) tmp = 0.0 if (y <= -1.65e-285) tmp = t_0; elseif (y <= 1.85e-236) tmp = Float64(Float64(-x) / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y / z); tmp = 0.0; if (y <= -1.65e-285) tmp = t_0; elseif (y <= 1.85e-236) tmp = -x / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.65e-285], t$95$0, If[LessEqual[y, 1.85e-236], N[((-x) / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;y \leq -1.65 \cdot 10^{-285}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{-236}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.64999999999999993e-285 or 1.85000000000000011e-236 < y Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6481.2
Simplified81.2%
if -1.64999999999999993e-285 < y < 1.85000000000000011e-236Initial program 99.9%
Taylor expanded in z around 0
/-lowering-/.f64N/A
--lowering--.f6494.2
Simplified94.2%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6489.1
Simplified89.1%
(FPCore (x y z) :precision binary64 (if (<= z -5.8e+37) x (if (<= z 5.4e+18) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.8e+37) {
tmp = x;
} else if (z <= 5.4e+18) {
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 <= (-5.8d+37)) then
tmp = x
else if (z <= 5.4d+18) 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 <= -5.8e+37) {
tmp = x;
} else if (z <= 5.4e+18) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.8e+37: tmp = x elif z <= 5.4e+18: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.8e+37) tmp = x; elseif (z <= 5.4e+18) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.8e+37) tmp = x; elseif (z <= 5.4e+18) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.8e+37], x, If[LessEqual[z, 5.4e+18], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{+37}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.4 \cdot 10^{+18}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.79999999999999957e37 or 5.4e18 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified70.0%
if -5.79999999999999957e37 < z < 5.4e18Initial program 100.0%
Taylor expanded in x around 0
/-lowering-/.f6454.4
Simplified54.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
Simplified34.3%
herbie shell --seed 2024204
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))