
(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 8 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 (fma (- y x) z x))
double code(double x, double y, double z) {
return fma((y - x), z, x);
}
function code(x, y, z) return fma(Float64(y - x), z, x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= z -3.5e+181)
t_0
(if (<= z -2.6e+150)
(* y z)
(if (<= z -4.8e+98)
t_0
(if (<= z -5.4e-65)
(* y z)
(if (<= z 6.3e-49)
x
(if (or (<= z 4e+40) (not (<= z 1.4e+202))) (* y z) t_0))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -3.5e+181) {
tmp = t_0;
} else if (z <= -2.6e+150) {
tmp = y * z;
} else if (z <= -4.8e+98) {
tmp = t_0;
} else if (z <= -5.4e-65) {
tmp = y * z;
} else if (z <= 6.3e-49) {
tmp = x;
} else if ((z <= 4e+40) || !(z <= 1.4e+202)) {
tmp = 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 = z * -x
if (z <= (-3.5d+181)) then
tmp = t_0
else if (z <= (-2.6d+150)) then
tmp = y * z
else if (z <= (-4.8d+98)) then
tmp = t_0
else if (z <= (-5.4d-65)) then
tmp = y * z
else if (z <= 6.3d-49) then
tmp = x
else if ((z <= 4d+40) .or. (.not. (z <= 1.4d+202))) then
tmp = 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 = z * -x;
double tmp;
if (z <= -3.5e+181) {
tmp = t_0;
} else if (z <= -2.6e+150) {
tmp = y * z;
} else if (z <= -4.8e+98) {
tmp = t_0;
} else if (z <= -5.4e-65) {
tmp = y * z;
} else if (z <= 6.3e-49) {
tmp = x;
} else if ((z <= 4e+40) || !(z <= 1.4e+202)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -3.5e+181: tmp = t_0 elif z <= -2.6e+150: tmp = y * z elif z <= -4.8e+98: tmp = t_0 elif z <= -5.4e-65: tmp = y * z elif z <= 6.3e-49: tmp = x elif (z <= 4e+40) or not (z <= 1.4e+202): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -3.5e+181) tmp = t_0; elseif (z <= -2.6e+150) tmp = Float64(y * z); elseif (z <= -4.8e+98) tmp = t_0; elseif (z <= -5.4e-65) tmp = Float64(y * z); elseif (z <= 6.3e-49) tmp = x; elseif ((z <= 4e+40) || !(z <= 1.4e+202)) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -3.5e+181) tmp = t_0; elseif (z <= -2.6e+150) tmp = y * z; elseif (z <= -4.8e+98) tmp = t_0; elseif (z <= -5.4e-65) tmp = y * z; elseif (z <= 6.3e-49) tmp = x; elseif ((z <= 4e+40) || ~((z <= 1.4e+202))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -3.5e+181], t$95$0, If[LessEqual[z, -2.6e+150], N[(y * z), $MachinePrecision], If[LessEqual[z, -4.8e+98], t$95$0, If[LessEqual[z, -5.4e-65], N[(y * z), $MachinePrecision], If[LessEqual[z, 6.3e-49], x, If[Or[LessEqual[z, 4e+40], N[Not[LessEqual[z, 1.4e+202]], $MachinePrecision]], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -3.5 \cdot 10^{+181}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.6 \cdot 10^{+150}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -4.8 \cdot 10^{+98}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -5.4 \cdot 10^{-65}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6.3 \cdot 10^{-49}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+40} \lor \neg \left(z \leq 1.4 \cdot 10^{+202}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.50000000000000008e181 or -2.60000000000000006e150 < z < -4.7999999999999997e98 or 4.00000000000000012e40 < z < 1.40000000000000008e202Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around 0 62.9%
mul-1-neg62.9%
distribute-lft-neg-out62.9%
*-commutative62.9%
Simplified62.9%
if -3.50000000000000008e181 < z < -2.60000000000000006e150 or -4.7999999999999997e98 < z < -5.3999999999999997e-65 or 6.2999999999999997e-49 < z < 4.00000000000000012e40 or 1.40000000000000008e202 < z Initial program 100.0%
Taylor expanded in y around inf 73.0%
*-commutative73.0%
Simplified73.0%
Taylor expanded in z around inf 73.0%
Taylor expanded in y around inf 64.3%
if -5.3999999999999997e-65 < z < 6.2999999999999997e-49Initial program 100.0%
Taylor expanded in z around 0 79.2%
Final simplification70.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -5800.0) (not (<= z 0.0165))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5800.0) || !(z <= 0.0165)) {
tmp = (y - 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 ((z <= (-5800.0d0)) .or. (.not. (z <= 0.0165d0))) then
tmp = (y - 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 ((z <= -5800.0) || !(z <= 0.0165)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5800.0) or not (z <= 0.0165): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5800.0) || !(z <= 0.0165)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5800.0) || ~((z <= 0.0165))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5800.0], N[Not[LessEqual[z, 0.0165]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5800 \lor \neg \left(z \leq 0.0165\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -5800 or 0.016500000000000001 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 99.2%
if -5800 < z < 0.016500000000000001Initial program 100.0%
Taylor expanded in y around inf 99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.55e-65) (not (<= z 4e-50))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.55e-65) || !(z <= 4e-50)) {
tmp = (y - x) * 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.55d-65)) .or. (.not. (z <= 4d-50))) then
tmp = (y - x) * 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.55e-65) || !(z <= 4e-50)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.55e-65) or not (z <= 4e-50): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.55e-65) || !(z <= 4e-50)) tmp = Float64(Float64(y - x) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.55e-65) || ~((z <= 4e-50))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.55e-65], N[Not[LessEqual[z, 4e-50]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{-65} \lor \neg \left(z \leq 4 \cdot 10^{-50}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.55000000000000008e-65 or 4.00000000000000003e-50 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 94.2%
if -1.55000000000000008e-65 < z < 4.00000000000000003e-50Initial program 100.0%
Taylor expanded in z around 0 79.2%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e+124) (not (<= y 1.36e+94))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e+124) || !(y <= 1.36e+94)) {
tmp = y * z;
} else {
tmp = x * (1.0 - 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.5d+124)) .or. (.not. (y <= 1.36d+94))) then
tmp = y * z
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e+124) || !(y <= 1.36e+94)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e+124) or not (y <= 1.36e+94): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e+124) || !(y <= 1.36e+94)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.5e+124) || ~((y <= 1.36e+94))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e+124], N[Not[LessEqual[y, 1.36e+94]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+124} \lor \neg \left(y \leq 1.36 \cdot 10^{+94}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -2.4999999999999998e124 or 1.36e94 < y Initial program 100.0%
Taylor expanded in y around inf 93.7%
*-commutative93.7%
Simplified93.7%
Taylor expanded in z around inf 88.9%
Taylor expanded in y around inf 80.5%
if -2.4999999999999998e124 < y < 1.36e94Initial program 100.0%
Taylor expanded in x around inf 79.2%
mul-1-neg79.2%
unsub-neg79.2%
Simplified79.2%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.8e-64) (not (<= z 1.15e-48))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.8e-64) || !(z <= 1.15e-48)) {
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-64)) .or. (.not. (z <= 1.15d-48))) 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-64) || !(z <= 1.15e-48)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.8e-64) or not (z <= 1.15e-48): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.8e-64) || !(z <= 1.15e-48)) 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-64) || ~((z <= 1.15e-48))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.8e-64], N[Not[LessEqual[z, 1.15e-48]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{-64} \lor \neg \left(z \leq 1.15 \cdot 10^{-48}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.7999999999999999e-64 or 1.15e-48 < z Initial program 100.0%
Taylor expanded in y around inf 57.7%
*-commutative57.7%
Simplified57.7%
Taylor expanded in z around inf 57.6%
Taylor expanded in y around inf 52.6%
if -1.7999999999999999e-64 < z < 1.15e-48Initial program 100.0%
Taylor expanded in z around 0 79.2%
Final simplification63.9%
(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 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 37.9%
herbie shell --seed 2024110
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))