
(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 + \left(y - x\right) \cdot 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 + \left(y - x\right) \cdot 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 + \left(y - x\right) \cdot z
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y x) z))) (if (<= z -110.0) t_0 (if (<= z 2.7e-5) (+ x (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -110.0) {
tmp = t_0;
} else if (z <= 2.7e-5) {
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 = (y - x) * z
if (z <= (-110.0d0)) then
tmp = t_0
else if (z <= 2.7d-5) 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 = (y - x) * z;
double tmp;
if (z <= -110.0) {
tmp = t_0;
} else if (z <= 2.7e-5) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) * z tmp = 0 if z <= -110.0: tmp = t_0 elif z <= 2.7e-5: tmp = x + (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - x) * z) tmp = 0.0 if (z <= -110.0) tmp = t_0; elseif (z <= 2.7e-5) tmp = Float64(x + Float64(y * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - x) * z; tmp = 0.0; if (z <= -110.0) tmp = t_0; elseif (z <= 2.7e-5) tmp = x + (y * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -110.0], t$95$0, If[LessEqual[z, 2.7e-5], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;z \leq -110:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-5}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -110 or 2.6999999999999999e-5 < z Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f64N/A
--lowering--.f6499.0%
Simplified99.0%
if -110 < z < 2.6999999999999999e-5Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6499.9%
Simplified99.9%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y x) z))) (if (<= z -3.1e-23) t_0 (if (<= z 7.2e-6) (* x (- 1.0 z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -3.1e-23) {
tmp = t_0;
} else if (z <= 7.2e-6) {
tmp = x * (1.0 - 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 = (y - x) * z
if (z <= (-3.1d-23)) then
tmp = t_0
else if (z <= 7.2d-6) then
tmp = x * (1.0d0 - z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -3.1e-23) {
tmp = t_0;
} else if (z <= 7.2e-6) {
tmp = x * (1.0 - z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) * z tmp = 0 if z <= -3.1e-23: tmp = t_0 elif z <= 7.2e-6: tmp = x * (1.0 - z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - x) * z) tmp = 0.0 if (z <= -3.1e-23) tmp = t_0; elseif (z <= 7.2e-6) tmp = Float64(x * Float64(1.0 - z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - x) * z; tmp = 0.0; if (z <= -3.1e-23) tmp = t_0; elseif (z <= 7.2e-6) tmp = x * (1.0 - z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -3.1e-23], t$95$0, If[LessEqual[z, 7.2e-6], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;z \leq -3.1 \cdot 10^{-23}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{-6}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.0999999999999999e-23 or 7.19999999999999967e-6 < z Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f64N/A
--lowering--.f6498.3%
Simplified98.3%
if -3.0999999999999999e-23 < z < 7.19999999999999967e-6Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6479.1%
Simplified79.1%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (<= y -6.6e+146) (* y z) (if (<= y 5.8e+160) (* x (- 1.0 z)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.6e+146) {
tmp = y * z;
} else if (y <= 5.8e+160) {
tmp = x * (1.0 - z);
} else {
tmp = 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 (y <= (-6.6d+146)) then
tmp = y * z
else if (y <= 5.8d+160) then
tmp = x * (1.0d0 - z)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.6e+146) {
tmp = y * z;
} else if (y <= 5.8e+160) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.6e+146: tmp = y * z elif y <= 5.8e+160: tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.6e+146) tmp = Float64(y * z); elseif (y <= 5.8e+160) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.6e+146) tmp = y * z; elseif (y <= 5.8e+160) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.6e+146], N[(y * z), $MachinePrecision], If[LessEqual[y, 5.8e+160], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.6 \cdot 10^{+146}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{+160}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -6.60000000000000032e146 or 5.7999999999999998e160 < y Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6479.6%
Simplified79.6%
if -6.60000000000000032e146 < y < 5.7999999999999998e160Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6477.2%
Simplified77.2%
(FPCore (x y z) :precision binary64 (if (<= z -9e-23) (* y z) (if (<= z 3.1e-12) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9e-23) {
tmp = y * z;
} else if (z <= 3.1e-12) {
tmp = x;
} else {
tmp = 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 (z <= (-9d-23)) then
tmp = y * z
else if (z <= 3.1d-12) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -9e-23) {
tmp = y * z;
} else if (z <= 3.1e-12) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9e-23: tmp = y * z elif z <= 3.1e-12: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9e-23) tmp = Float64(y * z); elseif (z <= 3.1e-12) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9e-23) tmp = y * z; elseif (z <= 3.1e-12) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9e-23], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.1e-12], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-23}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.1 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -8.9999999999999995e-23 or 3.1000000000000001e-12 < z Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6450.4%
Simplified50.4%
if -8.9999999999999995e-23 < z < 3.1000000000000001e-12Initial program 100.0%
Taylor expanded in z around 0
Simplified79.0%
(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 0
Simplified42.5%
herbie shell --seed 2024138
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))