
(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 -5.5e-39)
(and (not (<= x 2.4e-211)) (or (<= x 2.5e-143) (not (<= x 2.9e-55)))))
(* x (- 1.0 z))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e-39) || (!(x <= 2.4e-211) && ((x <= 2.5e-143) || !(x <= 2.9e-55)))) {
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 <= (-5.5d-39)) .or. (.not. (x <= 2.4d-211)) .and. (x <= 2.5d-143) .or. (.not. (x <= 2.9d-55))) 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 <= -5.5e-39) || (!(x <= 2.4e-211) && ((x <= 2.5e-143) || !(x <= 2.9e-55)))) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e-39) or (not (x <= 2.4e-211) and ((x <= 2.5e-143) or not (x <= 2.9e-55))): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e-39) || (!(x <= 2.4e-211) && ((x <= 2.5e-143) || !(x <= 2.9e-55)))) 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 <= -5.5e-39) || (~((x <= 2.4e-211)) && ((x <= 2.5e-143) || ~((x <= 2.9e-55))))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e-39], And[N[Not[LessEqual[x, 2.4e-211]], $MachinePrecision], Or[LessEqual[x, 2.5e-143], N[Not[LessEqual[x, 2.9e-55]], $MachinePrecision]]]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-39} \lor \neg \left(x \leq 2.4 \cdot 10^{-211}\right) \land \left(x \leq 2.5 \cdot 10^{-143} \lor \neg \left(x \leq 2.9 \cdot 10^{-55}\right)\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -5.50000000000000018e-39 or 2.4000000000000002e-211 < x < 2.5000000000000001e-143 or 2.9e-55 < x Initial program 100.0%
Taylor expanded in x around inf 84.3%
mul-1-neg84.3%
unsub-neg84.3%
Simplified84.3%
if -5.50000000000000018e-39 < x < 2.4000000000000002e-211 or 2.5000000000000001e-143 < x < 2.9e-55Initial program 100.0%
Taylor expanded in y around inf 94.5%
*-commutative94.5%
Simplified94.5%
Taylor expanded in x around 0 79.5%
*-commutative79.5%
Simplified79.5%
Final simplification82.3%
(FPCore (x y z)
:precision binary64
(if (<= z -1.9e-95)
(* y z)
(if (<= z 5.4e-63)
x
(if (or (<= z 2.7e+156) (not (<= z 9e+258))) (* y z) (* x (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e-95) {
tmp = y * z;
} else if (z <= 5.4e-63) {
tmp = x;
} else if ((z <= 2.7e+156) || !(z <= 9e+258)) {
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.9d-95)) then
tmp = y * z
else if (z <= 5.4d-63) then
tmp = x
else if ((z <= 2.7d+156) .or. (.not. (z <= 9d+258))) 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.9e-95) {
tmp = y * z;
} else if (z <= 5.4e-63) {
tmp = x;
} else if ((z <= 2.7e+156) || !(z <= 9e+258)) {
tmp = y * z;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.9e-95: tmp = y * z elif z <= 5.4e-63: tmp = x elif (z <= 2.7e+156) or not (z <= 9e+258): tmp = y * z else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.9e-95) tmp = Float64(y * z); elseif (z <= 5.4e-63) tmp = x; elseif ((z <= 2.7e+156) || !(z <= 9e+258)) 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.9e-95) tmp = y * z; elseif (z <= 5.4e-63) tmp = x; elseif ((z <= 2.7e+156) || ~((z <= 9e+258))) tmp = y * z; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.9e-95], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.4e-63], x, If[Or[LessEqual[z, 2.7e+156], N[Not[LessEqual[z, 9e+258]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{-95}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.4 \cdot 10^{-63}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+156} \lor \neg \left(z \leq 9 \cdot 10^{+258}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -1.8999999999999999e-95 or 5.4000000000000004e-63 < z < 2.7e156 or 9.0000000000000007e258 < z Initial program 100.0%
Taylor expanded in y around inf 67.5%
*-commutative67.5%
Simplified67.5%
Taylor expanded in x around 0 58.9%
*-commutative58.9%
Simplified58.9%
if -1.8999999999999999e-95 < z < 5.4000000000000004e-63Initial program 100.0%
Taylor expanded in z around 0 77.4%
if 2.7e156 < z < 9.0000000000000007e258Initial program 100.0%
Taylor expanded in x around inf 61.5%
mul-1-neg61.5%
unsub-neg61.5%
Simplified61.5%
Taylor expanded in z around inf 61.5%
mul-1-neg61.5%
*-commutative61.5%
distribute-rgt-neg-in61.5%
Simplified61.5%
Final simplification66.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.55e-26) (not (<= y 1.02e-101))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.55e-26) || !(y <= 1.02e-101)) {
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 ((y <= (-1.55d-26)) .or. (.not. (y <= 1.02d-101))) 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 ((y <= -1.55e-26) || !(y <= 1.02e-101)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.55e-26) or not (y <= 1.02e-101): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.55e-26) || !(y <= 1.02e-101)) 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 ((y <= -1.55e-26) || ~((y <= 1.02e-101))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.55e-26], N[Not[LessEqual[y, 1.02e-101]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{-26} \lor \neg \left(y \leq 1.02 \cdot 10^{-101}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -1.54999999999999992e-26 or 1.02e-101 < y Initial program 100.0%
Taylor expanded in y around inf 90.4%
*-commutative90.4%
Simplified90.4%
if -1.54999999999999992e-26 < y < 1.02e-101Initial program 100.0%
Taylor expanded in x around inf 89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-95) (not (<= z 2.55e-63))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-95) || !(z <= 2.55e-63)) {
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 <= (-6.5d-95)) .or. (.not. (z <= 2.55d-63))) 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 <= -6.5e-95) || !(z <= 2.55e-63)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-95) or not (z <= 2.55e-63): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-95) || !(z <= 2.55e-63)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6.5e-95) || ~((z <= 2.55e-63))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-95], N[Not[LessEqual[z, 2.55e-63]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-95} \lor \neg \left(z \leq 2.55 \cdot 10^{-63}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.49999999999999985e-95 or 2.55000000000000012e-63 < z Initial program 100.0%
Taylor expanded in y around inf 63.9%
*-commutative63.9%
Simplified63.9%
Taylor expanded in x around 0 56.5%
*-commutative56.5%
Simplified56.5%
if -6.49999999999999985e-95 < z < 2.55000000000000012e-63Initial program 100.0%
Taylor expanded in z around 0 77.4%
Final simplification65.0%
(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 37.2%
Final simplification37.2%
herbie shell --seed 2023306
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))