
(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 (<= x -6.1e-49) (not (<= x 9.5e+58))) (- x (* x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.1e-49) || !(x <= 9.5e+58)) {
tmp = x - (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 ((x <= (-6.1d-49)) .or. (.not. (x <= 9.5d+58))) then
tmp = x - (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 ((x <= -6.1e-49) || !(x <= 9.5e+58)) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.1e-49) or not (x <= 9.5e+58): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.1e-49) || !(x <= 9.5e+58)) tmp = Float64(x - Float64(x * z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.1e-49) || ~((x <= 9.5e+58))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.1e-49], N[Not[LessEqual[x, 9.5e+58]], $MachinePrecision]], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.1 \cdot 10^{-49} \lor \neg \left(x \leq 9.5 \cdot 10^{+58}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -6.09999999999999963e-49 or 9.5000000000000002e58 < x Initial program 100.0%
Taylor expanded in y around 0 88.3%
mul-1-neg88.3%
distribute-rgt-neg-out88.3%
Simplified88.3%
Taylor expanded in x around 0 88.3%
neg-mul-188.3%
distribute-rgt1-in88.3%
cancel-sign-sub-inv88.3%
Simplified88.3%
if -6.09999999999999963e-49 < x < 9.5000000000000002e58Initial program 100.0%
Taylor expanded in y around inf 89.7%
*-commutative89.7%
Simplified89.7%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.41) (not (<= z 1.0))) (* x (- z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.41) || !(z <= 1.0)) {
tmp = x * -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 <= (-0.41d0)) .or. (.not. (z <= 1.0d0))) then
tmp = x * -z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -0.41) || !(z <= 1.0)) {
tmp = x * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.41) or not (z <= 1.0): tmp = x * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.41) || !(z <= 1.0)) tmp = Float64(x * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -0.41) || ~((z <= 1.0))) tmp = x * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.41], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.41 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.409999999999999976 or 1 < z Initial program 100.0%
Taylor expanded in y around 0 53.9%
mul-1-neg53.9%
distribute-rgt-neg-out53.9%
Simplified53.9%
Taylor expanded in z around inf 53.7%
mul-1-neg53.7%
distribute-rgt-neg-in53.7%
Simplified53.7%
if -0.409999999999999976 < z < 1Initial program 100.0%
Taylor expanded in y around 0 68.8%
mul-1-neg68.8%
distribute-rgt-neg-out68.8%
Simplified68.8%
Taylor expanded in z around 0 67.7%
Final simplification61.4%
(FPCore (x y z) :precision binary64 (if (<= z 300000000000.0) (+ x (* y z)) (* x (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 300000000000.0) {
tmp = x + (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 <= 300000000000.0d0) then
tmp = x + (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 <= 300000000000.0) {
tmp = x + (y * z);
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 300000000000.0: tmp = x + (y * z) else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 300000000000.0) tmp = Float64(x + 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 <= 300000000000.0) tmp = x + (y * z); else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 300000000000.0], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 300000000000:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 3e11Initial program 100.0%
Taylor expanded in y around inf 86.9%
*-commutative86.9%
Simplified86.9%
if 3e11 < z Initial program 100.0%
Taylor expanded in y around 0 58.4%
mul-1-neg58.4%
distribute-rgt-neg-out58.4%
Simplified58.4%
Taylor expanded in z around inf 58.0%
mul-1-neg58.0%
distribute-rgt-neg-in58.0%
Simplified58.0%
Final simplification80.5%
(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 0 62.1%
mul-1-neg62.1%
distribute-rgt-neg-out62.1%
Simplified62.1%
Taylor expanded in z around 0 38.2%
Final simplification38.2%
herbie shell --seed 2023185
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))