
(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 (* x (- z))))
(if (<= z -9.5e+207)
t_0
(if (<= z -8.6e-13) (* y z) (if (<= z 6.2e-6) x t_0)))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -9.5e+207) {
tmp = t_0;
} else if (z <= -8.6e-13) {
tmp = y * z;
} else if (z <= 6.2e-6) {
tmp = x;
} 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 * -z
if (z <= (-9.5d+207)) then
tmp = t_0
else if (z <= (-8.6d-13)) then
tmp = y * z
else if (z <= 6.2d-6) then
tmp = x
else
tmp = t_0
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 <= -9.5e+207) {
tmp = t_0;
} else if (z <= -8.6e-13) {
tmp = y * z;
} else if (z <= 6.2e-6) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -9.5e+207: tmp = t_0 elif z <= -8.6e-13: tmp = y * z elif z <= 6.2e-6: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -9.5e+207) tmp = t_0; elseif (z <= -8.6e-13) tmp = Float64(y * z); elseif (z <= 6.2e-6) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -9.5e+207) tmp = t_0; elseif (z <= -8.6e-13) tmp = y * z; elseif (z <= 6.2e-6) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -9.5e+207], t$95$0, If[LessEqual[z, -8.6e-13], N[(y * z), $MachinePrecision], If[LessEqual[z, 6.2e-6], x, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -9.5 \cdot 10^{+207}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -8.6 \cdot 10^{-13}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -9.5000000000000005e207 or 6.1999999999999999e-6 < z Initial program 100.0%
Taylor expanded in x around inf 60.3%
mul-1-neg60.3%
unsub-neg60.3%
Simplified60.3%
Taylor expanded in z around inf 59.8%
neg-mul-159.8%
Simplified59.8%
if -9.5000000000000005e207 < z < -8.5999999999999997e-13Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in y around inf 98.3%
Taylor expanded in y around inf 59.4%
if -8.5999999999999997e-13 < z < 6.1999999999999999e-6Initial program 100.0%
Taylor expanded in z around 0 72.8%
Final simplification66.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 6.2e-6))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 6.2e-6)) {
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 <= (-1.0d0)) .or. (.not. (z <= 6.2d-6))) 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 <= -1.0) || !(z <= 6.2e-6)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 6.2e-6): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 6.2e-6)) 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 <= -1.0) || ~((z <= 6.2e-6))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 6.2e-6]], $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 -1 \lor \neg \left(z \leq 6.2 \cdot 10^{-6}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 6.1999999999999999e-6 < z Initial program 99.9%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 99.1%
if -1 < z < 6.1999999999999999e-6Initial program 100.0%
Taylor expanded in y around inf 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e-13) (not (<= z 6e-6))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e-13) || !(z <= 6e-6)) {
tmp = (y - x) * 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 ((z <= (-3d-13)) .or. (.not. (z <= 6d-6))) then
tmp = (y - x) * 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 ((z <= -3e-13) || !(z <= 6e-6)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e-13) or not (z <= 6e-6): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3e-13) || !(z <= 6e-6)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3e-13) || ~((z <= 6e-6))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e-13], N[Not[LessEqual[z, 6e-6]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-13} \lor \neg \left(z \leq 6 \cdot 10^{-6}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -2.99999999999999984e-13 or 6.0000000000000002e-6 < z Initial program 99.9%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 99.1%
if -2.99999999999999984e-13 < z < 6.0000000000000002e-6Initial program 100.0%
Taylor expanded in x around inf 73.8%
mul-1-neg73.8%
unsub-neg73.8%
Simplified73.8%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.65e+69) (not (<= y 1.2e+178))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.65e+69) || !(y <= 1.2e+178)) {
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 <= (-1.65d+69)) .or. (.not. (y <= 1.2d+178))) 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 <= -1.65e+69) || !(y <= 1.2e+178)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.65e+69) or not (y <= 1.2e+178): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.65e+69) || !(y <= 1.2e+178)) 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 <= -1.65e+69) || ~((y <= 1.2e+178))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.65e+69], N[Not[LessEqual[y, 1.2e+178]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+69} \lor \neg \left(y \leq 1.2 \cdot 10^{+178}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -1.6499999999999999e69 or 1.2e178 < y Initial program 99.9%
Taylor expanded in z around inf 88.9%
Taylor expanded in y around inf 84.5%
Taylor expanded in y around inf 77.2%
if -1.6499999999999999e69 < y < 1.2e178Initial program 100.0%
Taylor expanded in x around inf 78.2%
mul-1-neg78.2%
unsub-neg78.2%
Simplified78.2%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.3e-12) (not (<= z 5e-14))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.3e-12) || !(z <= 5e-14)) {
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.3d-12)) .or. (.not. (z <= 5d-14))) 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.3e-12) || !(z <= 5e-14)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.3e-12) or not (z <= 5e-14): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.3e-12) || !(z <= 5e-14)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.3e-12) || ~((z <= 5e-14))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.3e-12], N[Not[LessEqual[z, 5e-14]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{-12} \lor \neg \left(z \leq 5 \cdot 10^{-14}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.29999999999999991e-12 or 5.0000000000000002e-14 < z Initial program 99.9%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 97.6%
Taylor expanded in y around inf 50.3%
if -1.29999999999999991e-12 < z < 5.0000000000000002e-14Initial program 100.0%
Taylor expanded in z around 0 73.8%
Final simplification61.4%
(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 36.9%
herbie shell --seed 2024167
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))