
(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 (<= y -1.8e+91)
(not
(or (<= y -185000000.0)
(and (not (<= y -2.1e-99)) (<= y 1.55e-89)))))
(+ x (* y z))
(- x (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e+91) || !((y <= -185000000.0) || (!(y <= -2.1e-99) && (y <= 1.55e-89)))) {
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.8d+91)) .or. (.not. (y <= (-185000000.0d0)) .or. (.not. (y <= (-2.1d-99))) .and. (y <= 1.55d-89))) 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.8e+91) || !((y <= -185000000.0) || (!(y <= -2.1e-99) && (y <= 1.55e-89)))) {
tmp = x + (y * z);
} else {
tmp = x - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8e+91) or not ((y <= -185000000.0) or (not (y <= -2.1e-99) and (y <= 1.55e-89))): tmp = x + (y * z) else: tmp = x - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8e+91) || !((y <= -185000000.0) || (!(y <= -2.1e-99) && (y <= 1.55e-89)))) 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.8e+91) || ~(((y <= -185000000.0) || (~((y <= -2.1e-99)) && (y <= 1.55e-89))))) tmp = x + (y * z); else tmp = x - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e+91], N[Not[Or[LessEqual[y, -185000000.0], And[N[Not[LessEqual[y, -2.1e-99]], $MachinePrecision], LessEqual[y, 1.55e-89]]]], $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.8 \cdot 10^{+91} \lor \neg \left(y \leq -185000000 \lor \neg \left(y \leq -2.1 \cdot 10^{-99}\right) \land y \leq 1.55 \cdot 10^{-89}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot z\\
\end{array}
\end{array}
if y < -1.8e91 or -1.85e8 < y < -2.09999999999999984e-99 or 1.54999999999999998e-89 < y Initial program 100.0%
Taylor expanded in y around inf 90.4%
*-commutative90.4%
Simplified90.4%
if -1.8e91 < y < -1.85e8 or -2.09999999999999984e-99 < y < 1.54999999999999998e-89Initial program 100.0%
Taylor expanded in y around 0 89.3%
mul-1-neg89.3%
distribute-lft-neg-out89.3%
*-commutative89.3%
Simplified89.3%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.2e-25) (not (<= z 1.7e-5))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.2e-25) || !(z <= 1.7e-5)) {
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 <= (-7.2d-25)) .or. (.not. (z <= 1.7d-5))) 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 <= -7.2e-25) || !(z <= 1.7e-5)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.2e-25) or not (z <= 1.7e-5): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.2e-25) || !(z <= 1.7e-5)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.2e-25) || ~((z <= 1.7e-5))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.2e-25], N[Not[LessEqual[z, 1.7e-5]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{-25} \lor \neg \left(z \leq 1.7 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.1999999999999998e-25 or 1.7e-5 < z Initial program 100.0%
Taylor expanded in y around inf 56.4%
*-commutative56.4%
Simplified56.4%
Taylor expanded in x around 0 55.6%
if -7.1999999999999998e-25 < z < 1.7e-5Initial program 100.0%
Taylor expanded in y around inf 99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in x around inf 73.9%
Final simplification64.9%
(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 78.3%
*-commutative78.3%
Simplified78.3%
Final simplification78.3%
(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 78.3%
*-commutative78.3%
Simplified78.3%
Taylor expanded in x around inf 39.2%
Final simplification39.2%
herbie shell --seed 2024024
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))