
(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 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 + \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 (if (<= z -1.5e-10) (* y z) (if (<= z 2.6e-84) x (if (<= z 2.1e+128) (* y z) (* x (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.5e-10) {
tmp = y * z;
} else if (z <= 2.6e-84) {
tmp = x;
} else if (z <= 2.1e+128) {
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 (z <= (-1.5d-10)) then
tmp = y * z
else if (z <= 2.6d-84) then
tmp = x
else if (z <= 2.1d+128) 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 (z <= -1.5e-10) {
tmp = y * z;
} else if (z <= 2.6e-84) {
tmp = x;
} else if (z <= 2.1e+128) {
tmp = y * z;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.5e-10: tmp = y * z elif z <= 2.6e-84: tmp = x elif z <= 2.1e+128: tmp = y * z else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.5e-10) tmp = Float64(y * z); elseif (z <= 2.6e-84) tmp = x; elseif (z <= 2.1e+128) 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 (z <= -1.5e-10) tmp = y * z; elseif (z <= 2.6e-84) tmp = x; elseif (z <= 2.1e+128) tmp = y * z; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.5e-10], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.6e-84], x, If[LessEqual[z, 2.1e+128], N[(y * z), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{-10}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.6 \cdot 10^{-84}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{+128}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -1.5e-10 or 2.6e-84 < z < 2.1e128Initial program 100.0%
Taylor expanded in x around 0 59.5%
if -1.5e-10 < z < 2.6e-84Initial program 100.0%
Taylor expanded in z around 0 78.6%
if 2.1e128 < z Initial program 100.0%
Taylor expanded in x around inf 59.0%
mul-1-neg59.0%
unsub-neg59.0%
Simplified59.0%
Taylor expanded in z around inf 59.0%
mul-1-neg59.0%
distribute-lft-neg-out59.0%
*-commutative59.0%
Simplified59.0%
Final simplification68.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
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 <= 1.0): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 99.1%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf 98.7%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.4e-8) (not (<= z 10.0))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.4e-8) || !(z <= 10.0)) {
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 <= (-6.4d-8)) .or. (.not. (z <= 10.0d0))) 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 <= -6.4e-8) || !(z <= 10.0)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.4e-8) or not (z <= 10.0): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.4e-8) || !(z <= 10.0)) 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 <= -6.4e-8) || ~((z <= 10.0))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.4e-8], N[Not[LessEqual[z, 10.0]], $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 -6.4 \cdot 10^{-8} \lor \neg \left(z \leq 10\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -6.4000000000000004e-8 or 10 < z Initial program 100.0%
Taylor expanded in z around inf 99.7%
if -6.4000000000000004e-8 < z < 10Initial program 100.0%
Taylor expanded in x around inf 76.2%
mul-1-neg76.2%
unsub-neg76.2%
Simplified76.2%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.2e+117) (not (<= y 1.1e+17))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.2e+117) || !(y <= 1.1e+17)) {
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 <= (-8.2d+117)) .or. (.not. (y <= 1.1d+17))) 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 <= -8.2e+117) || !(y <= 1.1e+17)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.2e+117) or not (y <= 1.1e+17): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.2e+117) || !(y <= 1.1e+17)) 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 <= -8.2e+117) || ~((y <= 1.1e+17))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.2e+117], N[Not[LessEqual[y, 1.1e+17]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{+117} \lor \neg \left(y \leq 1.1 \cdot 10^{+17}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -8.1999999999999999e117 or 1.1e17 < y Initial program 100.0%
Taylor expanded in x around 0 70.6%
if -8.1999999999999999e117 < y < 1.1e17Initial program 100.0%
Taylor expanded in x around inf 83.2%
mul-1-neg83.2%
unsub-neg83.2%
Simplified83.2%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.04e-10) (not (<= z 1.45e-86))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.04e-10) || !(z <= 1.45e-86)) {
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.04d-10)) .or. (.not. (z <= 1.45d-86))) 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.04e-10) || !(z <= 1.45e-86)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.04e-10) or not (z <= 1.45e-86): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.04e-10) || !(z <= 1.45e-86)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.04e-10) || ~((z <= 1.45e-86))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.04e-10], N[Not[LessEqual[z, 1.45e-86]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.04 \cdot 10^{-10} \lor \neg \left(z \leq 1.45 \cdot 10^{-86}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.04e-10 or 1.45e-86 < z Initial program 100.0%
Taylor expanded in x around 0 56.0%
if -1.04e-10 < z < 1.45e-86Initial program 100.0%
Taylor expanded in z around 0 78.6%
Final simplification66.2%
(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 39.1%
herbie shell --seed 2024135
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))