
(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 (if (or (<= x -820.0) (not (<= x 62000.0))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -820.0) || !(x <= 62000.0)) {
tmp = x * (1.0 - 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 <= (-820.0d0)) .or. (.not. (x <= 62000.0d0))) then
tmp = x * (1.0d0 - 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 <= -820.0) || !(x <= 62000.0)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -820.0) or not (x <= 62000.0): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -820.0) || !(x <= 62000.0)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -820.0) || ~((x <= 62000.0))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -820.0], N[Not[LessEqual[x, 62000.0]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -820 \lor \neg \left(x \leq 62000\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -820 or 62000 < x Initial program 100.0%
Taylor expanded in x around inf 92.2%
mul-1-neg92.2%
unsub-neg92.2%
Simplified92.2%
if -820 < x < 62000Initial program 100.0%
Taylor expanded in y around inf 90.6%
*-commutative90.6%
Simplified90.6%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.1e-45) (not (<= x 1.7e-68))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e-45) || !(x <= 1.7e-68)) {
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 ((x <= (-4.1d-45)) .or. (.not. (x <= 1.7d-68))) 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 ((x <= -4.1e-45) || !(x <= 1.7e-68)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.1e-45) or not (x <= 1.7e-68): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.1e-45) || !(x <= 1.7e-68)) 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 ((x <= -4.1e-45) || ~((x <= 1.7e-68))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e-45], N[Not[LessEqual[x, 1.7e-68]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{-45} \lor \neg \left(x \leq 1.7 \cdot 10^{-68}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.0999999999999999e-45 or 1.70000000000000009e-68 < x Initial program 100.0%
Taylor expanded in x around inf 86.0%
mul-1-neg86.0%
unsub-neg86.0%
Simplified86.0%
if -4.0999999999999999e-45 < x < 1.70000000000000009e-68Initial program 100.0%
Taylor expanded in y around inf 93.0%
*-commutative93.0%
Simplified93.0%
Taylor expanded in y around inf 92.9%
Taylor expanded in y around inf 76.4%
*-commutative76.4%
Simplified76.4%
Final simplification81.6%
(FPCore (x y z) :precision binary64 (if (<= x -1560.0) (- x (* x z)) (if (<= x 128000.0) (+ x (* y z)) (* x (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1560.0) {
tmp = x - (x * z);
} else if (x <= 128000.0) {
tmp = x + (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 (x <= (-1560.0d0)) then
tmp = x - (x * z)
else if (x <= 128000.0d0) then
tmp = x + (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 (x <= -1560.0) {
tmp = x - (x * z);
} else if (x <= 128000.0) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1560.0: tmp = x - (x * z) elif x <= 128000.0: tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1560.0) tmp = Float64(x - Float64(x * z)); elseif (x <= 128000.0) tmp = Float64(x + 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 (x <= -1560.0) tmp = x - (x * z); elseif (x <= 128000.0) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1560.0], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 128000.0], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1560:\\
\;\;\;\;x - x \cdot z\\
\mathbf{elif}\;x \leq 128000:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if x < -1560Initial program 100.0%
Taylor expanded in x around inf 90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
sub-neg90.4%
distribute-rgt-in90.4%
*-un-lft-identity90.4%
distribute-lft-neg-in90.4%
unsub-neg90.4%
Applied egg-rr90.4%
if -1560 < x < 128000Initial program 100.0%
Taylor expanded in y around inf 90.6%
*-commutative90.6%
Simplified90.6%
if 128000 < x Initial program 100.0%
Taylor expanded in x around inf 93.7%
mul-1-neg93.7%
unsub-neg93.7%
Simplified93.7%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.4e-44) x (if (<= x 32000.0) (* y z) (* x (- z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.4e-44) {
tmp = x;
} else if (x <= 32000.0) {
tmp = 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 (x <= (-1.4d-44)) then
tmp = x
else if (x <= 32000.0d0) then
tmp = 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 (x <= -1.4e-44) {
tmp = x;
} else if (x <= 32000.0) {
tmp = y * z;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.4e-44: tmp = x elif x <= 32000.0: tmp = y * z else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.4e-44) tmp = x; elseif (x <= 32000.0) tmp = Float64(y * z); else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.4e-44) tmp = x; elseif (x <= 32000.0) tmp = y * z; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.4e-44], x, If[LessEqual[x, 32000.0], N[(y * z), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-44}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 32000:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -1.4e-44Initial program 100.0%
Taylor expanded in z around 0 52.2%
if -1.4e-44 < x < 32000Initial program 100.0%
Taylor expanded in y around inf 90.8%
*-commutative90.8%
Simplified90.8%
Taylor expanded in y around inf 90.8%
Taylor expanded in y around inf 72.3%
*-commutative72.3%
Simplified72.3%
if 32000 < x Initial program 100.0%
Taylor expanded in x around inf 93.7%
mul-1-neg93.7%
unsub-neg93.7%
Simplified93.7%
Taylor expanded in z around inf 53.1%
neg-mul-153.1%
Simplified53.1%
Final simplification63.2%
(FPCore (x y z) :precision binary64 (if (<= x -2.55e-45) x (if (<= x 2.3e+56) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.55e-45) {
tmp = x;
} else if (x <= 2.3e+56) {
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 (x <= (-2.55d-45)) then
tmp = x
else if (x <= 2.3d+56) 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 (x <= -2.55e-45) {
tmp = x;
} else if (x <= 2.3e+56) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.55e-45: tmp = x elif x <= 2.3e+56: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.55e-45) tmp = x; elseif (x <= 2.3e+56) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.55e-45) tmp = x; elseif (x <= 2.3e+56) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.55e-45], x, If[LessEqual[x, 2.3e+56], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.55 \cdot 10^{-45}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{+56}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.5499999999999999e-45 or 2.30000000000000015e56 < x Initial program 100.0%
Taylor expanded in z around 0 49.7%
if -2.5499999999999999e-45 < x < 2.30000000000000015e56Initial program 100.0%
Taylor expanded in y around inf 87.5%
*-commutative87.5%
Simplified87.5%
Taylor expanded in y around inf 86.9%
Taylor expanded in y around inf 69.1%
*-commutative69.1%
Simplified69.1%
Final simplification60.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 33.4%
herbie shell --seed 2024147
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))