
(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 (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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.28e-82) (not (<= x 2.05e-54))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.28e-82) || !(x <= 2.05e-54)) {
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 <= (-1.28d-82)) .or. (.not. (x <= 2.05d-54))) 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 <= -1.28e-82) || !(x <= 2.05e-54)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.28e-82) or not (x <= 2.05e-54): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.28e-82) || !(x <= 2.05e-54)) 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 <= -1.28e-82) || ~((x <= 2.05e-54))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.28e-82], N[Not[LessEqual[x, 2.05e-54]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.28 \cdot 10^{-82} \lor \neg \left(x \leq 2.05 \cdot 10^{-54}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.28e-82 or 2.05e-54 < x Initial program 100.0%
Taylor expanded in x around inf 83.6%
mul-1-neg83.6%
unsub-neg83.6%
Simplified83.6%
if -1.28e-82 < x < 2.05e-54Initial program 100.0%
Taylor expanded in y around inf 92.5%
*-commutative92.5%
Simplified92.5%
Taylor expanded in x around 0 72.8%
*-commutative72.8%
Simplified72.8%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.1e+113) (not (<= x 1.8e+50))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.1e+113) || !(x <= 1.8e+50)) {
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 <= (-5.1d+113)) .or. (.not. (x <= 1.8d+50))) 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 <= -5.1e+113) || !(x <= 1.8e+50)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.1e+113) or not (x <= 1.8e+50): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.1e+113) || !(x <= 1.8e+50)) 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 <= -5.1e+113) || ~((x <= 1.8e+50))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.1e+113], N[Not[LessEqual[x, 1.8e+50]], $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 -5.1 \cdot 10^{+113} \lor \neg \left(x \leq 1.8 \cdot 10^{+50}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -5.09999999999999994e113 or 1.79999999999999993e50 < x Initial program 100.0%
Taylor expanded in x around inf 90.1%
mul-1-neg90.1%
unsub-neg90.1%
Simplified90.1%
if -5.09999999999999994e113 < x < 1.79999999999999993e50Initial program 100.0%
Taylor expanded in y around inf 89.2%
*-commutative89.2%
Simplified89.2%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -9e-6) (not (<= z 2.15e-9))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9e-6) || !(z <= 2.15e-9)) {
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 <= (-9d-6)) .or. (.not. (z <= 2.15d-9))) 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 <= -9e-6) || !(z <= 2.15e-9)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9e-6) or not (z <= 2.15e-9): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9e-6) || !(z <= 2.15e-9)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9e-6) || ~((z <= 2.15e-9))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9e-6], N[Not[LessEqual[z, 2.15e-9]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-6} \lor \neg \left(z \leq 2.15 \cdot 10^{-9}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.00000000000000023e-6 or 2.14999999999999981e-9 < z Initial program 100.0%
Taylor expanded in y around inf 54.0%
*-commutative54.0%
Simplified54.0%
Taylor expanded in x around 0 53.7%
*-commutative53.7%
Simplified53.7%
if -9.00000000000000023e-6 < z < 2.14999999999999981e-9Initial program 100.0%
Taylor expanded in z around 0 75.5%
Final simplification65.1%
(FPCore (x y z) :precision binary64 (if (<= z -1850.0) (* x (- z)) (if (<= z 5.5e-16) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1850.0) {
tmp = x * -z;
} else if (z <= 5.5e-16) {
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 <= (-1850.0d0)) then
tmp = x * -z
else if (z <= 5.5d-16) 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 <= -1850.0) {
tmp = x * -z;
} else if (z <= 5.5e-16) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1850.0: tmp = x * -z elif z <= 5.5e-16: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1850.0) tmp = Float64(x * Float64(-z)); elseif (z <= 5.5e-16) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1850.0) tmp = x * -z; elseif (z <= 5.5e-16) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1850.0], N[(x * (-z)), $MachinePrecision], If[LessEqual[z, 5.5e-16], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1850:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-16}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1850Initial program 100.0%
Taylor expanded in x around inf 57.7%
mul-1-neg57.7%
unsub-neg57.7%
Simplified57.7%
Taylor expanded in z around inf 57.7%
associate-*r*57.7%
neg-mul-157.7%
*-commutative57.7%
Simplified57.7%
if -1850 < z < 5.49999999999999964e-16Initial program 100.0%
Taylor expanded in z around 0 75.0%
if 5.49999999999999964e-16 < z Initial program 100.0%
Taylor expanded in y around inf 61.7%
*-commutative61.7%
Simplified61.7%
Taylor expanded in x around 0 62.4%
*-commutative62.4%
Simplified62.4%
Final simplification67.8%
(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%
Final simplification100.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 41.1%
Final simplification41.1%
herbie shell --seed 2023318
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))