
(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 5 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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= z -110000.0)
(not
(or (<= z -1.7e-185) (and (not (<= z -3.8e-214)) (<= z 3.8e-56)))))
(* y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -110000.0) || !((z <= -1.7e-185) || (!(z <= -3.8e-214) && (z <= 3.8e-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 ((z <= (-110000.0d0)) .or. (.not. (z <= (-1.7d-185)) .or. (.not. (z <= (-3.8d-214))) .and. (z <= 3.8d-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 ((z <= -110000.0) || !((z <= -1.7e-185) || (!(z <= -3.8e-214) && (z <= 3.8e-56)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -110000.0) or not ((z <= -1.7e-185) or (not (z <= -3.8e-214) and (z <= 3.8e-56))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -110000.0) || !((z <= -1.7e-185) || (!(z <= -3.8e-214) && (z <= 3.8e-56)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -110000.0) || ~(((z <= -1.7e-185) || (~((z <= -3.8e-214)) && (z <= 3.8e-56))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -110000.0], N[Not[Or[LessEqual[z, -1.7e-185], And[N[Not[LessEqual[z, -3.8e-214]], $MachinePrecision], LessEqual[z, 3.8e-56]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -110000 \lor \neg \left(z \leq -1.7 \cdot 10^{-185} \lor \neg \left(z \leq -3.8 \cdot 10^{-214}\right) \land z \leq 3.8 \cdot 10^{-56}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.1e5 or -1.6999999999999999e-185 < z < -3.8000000000000003e-214 or 3.8000000000000002e-56 < z Initial program 100.0%
Taylor expanded in y around inf 62.3%
*-commutative62.3%
Simplified62.3%
Taylor expanded in x around 0 58.7%
if -1.1e5 < z < -1.6999999999999999e-185 or -3.8000000000000003e-214 < z < 3.8000000000000002e-56Initial program 100.0%
Taylor expanded in y around inf 97.5%
*-commutative97.5%
Simplified97.5%
Taylor expanded in x around inf 73.8%
Final simplification64.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.7e+31) (not (<= y 6.5e-111))) (+ x (* y z)) (- x (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.7e+31) || !(y <= 6.5e-111)) {
tmp = x + (y * z);
} else {
tmp = x - (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 ((y <= (-1.7d+31)) .or. (.not. (y <= 6.5d-111))) then
tmp = x + (y * z)
else
tmp = x - (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.7e+31) || !(y <= 6.5e-111)) {
tmp = x + (y * z);
} else {
tmp = x - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.7e+31) or not (y <= 6.5e-111): tmp = x + (y * z) else: tmp = x - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.7e+31) || !(y <= 6.5e-111)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.7e+31) || ~((y <= 6.5e-111))) tmp = x + (y * z); else tmp = x - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.7e+31], N[Not[LessEqual[y, 6.5e-111]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{+31} \lor \neg \left(y \leq 6.5 \cdot 10^{-111}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot z\\
\end{array}
\end{array}
if y < -1.6999999999999999e31 or 6.49999999999999974e-111 < y Initial program 100.0%
Taylor expanded in y around inf 89.2%
*-commutative89.2%
Simplified89.2%
if -1.6999999999999999e31 < y < 6.49999999999999974e-111Initial program 100.0%
Taylor expanded in y around 0 88.9%
mul-1-neg88.9%
distribute-lft-neg-out88.9%
*-commutative88.9%
Simplified88.9%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (y * 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 * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 76.2%
*-commutative76.2%
Simplified76.2%
Final simplification76.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 y around inf 76.2%
*-commutative76.2%
Simplified76.2%
Taylor expanded in x around inf 32.8%
Final simplification32.8%
herbie shell --seed 2023305
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))