
(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 6 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
(let* ((t_0 (* z (- x))))
(if (<= z -2.2e+198)
t_0
(if (<= z -9e+50)
(* y z)
(if (<= z -2060000.0)
t_0
(if (<= z -0.115)
(* y z)
(if (<= z 1.65e-68) x (if (<= z 9.5e+87) (* y z) t_0))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -2.2e+198) {
tmp = t_0;
} else if (z <= -9e+50) {
tmp = y * z;
} else if (z <= -2060000.0) {
tmp = t_0;
} else if (z <= -0.115) {
tmp = y * z;
} else if (z <= 1.65e-68) {
tmp = x;
} else if (z <= 9.5e+87) {
tmp = y * z;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = z * -x
if (z <= (-2.2d+198)) then
tmp = t_0
else if (z <= (-9d+50)) then
tmp = y * z
else if (z <= (-2060000.0d0)) then
tmp = t_0
else if (z <= (-0.115d0)) then
tmp = y * z
else if (z <= 1.65d-68) then
tmp = x
else if (z <= 9.5d+87) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -2.2e+198) {
tmp = t_0;
} else if (z <= -9e+50) {
tmp = y * z;
} else if (z <= -2060000.0) {
tmp = t_0;
} else if (z <= -0.115) {
tmp = y * z;
} else if (z <= 1.65e-68) {
tmp = x;
} else if (z <= 9.5e+87) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -2.2e+198: tmp = t_0 elif z <= -9e+50: tmp = y * z elif z <= -2060000.0: tmp = t_0 elif z <= -0.115: tmp = y * z elif z <= 1.65e-68: tmp = x elif z <= 9.5e+87: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -2.2e+198) tmp = t_0; elseif (z <= -9e+50) tmp = Float64(y * z); elseif (z <= -2060000.0) tmp = t_0; elseif (z <= -0.115) tmp = Float64(y * z); elseif (z <= 1.65e-68) tmp = x; elseif (z <= 9.5e+87) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -2.2e+198) tmp = t_0; elseif (z <= -9e+50) tmp = y * z; elseif (z <= -2060000.0) tmp = t_0; elseif (z <= -0.115) tmp = y * z; elseif (z <= 1.65e-68) tmp = x; elseif (z <= 9.5e+87) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -2.2e+198], t$95$0, If[LessEqual[z, -9e+50], N[(y * z), $MachinePrecision], If[LessEqual[z, -2060000.0], t$95$0, If[LessEqual[z, -0.115], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.65e-68], x, If[LessEqual[z, 9.5e+87], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -2.2 \cdot 10^{+198}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -9 \cdot 10^{+50}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -2060000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -0.115:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{-68}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{+87}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -2.2e198 or -9.00000000000000027e50 < z < -2.06e6 or 9.4999999999999992e87 < z Initial program 100.0%
Taylor expanded in y around 0 68.1%
mul-1-neg68.1%
distribute-lft-neg-out68.1%
*-commutative68.1%
Simplified68.1%
Taylor expanded in z around inf 67.0%
associate-*r*67.0%
mul-1-neg67.0%
Simplified67.0%
if -2.2e198 < z < -9.00000000000000027e50 or -2.06e6 < z < -0.115000000000000005 or 1.6499999999999999e-68 < z < 9.4999999999999992e87Initial program 100.0%
Taylor expanded in y around inf 76.5%
*-commutative76.5%
Simplified76.5%
Taylor expanded in x around 0 72.0%
if -0.115000000000000005 < z < 1.6499999999999999e-68Initial program 100.0%
Taylor expanded in y around inf 99.2%
*-commutative99.2%
Simplified99.2%
Taylor expanded in x around inf 78.3%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.9e+191) (not (<= z 2.4e+82))) (* z (- x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e+191) || !(z <= 2.4e+82)) {
tmp = z * -x;
} 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 ((z <= (-1.9d+191)) .or. (.not. (z <= 2.4d+82))) then
tmp = z * -x
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e+191) || !(z <= 2.4e+82)) {
tmp = z * -x;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.9e+191) or not (z <= 2.4e+82): tmp = z * -x else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.9e+191) || !(z <= 2.4e+82)) tmp = Float64(z * Float64(-x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.9e+191) || ~((z <= 2.4e+82))) tmp = z * -x; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.9e+191], N[Not[LessEqual[z, 2.4e+82]], $MachinePrecision]], N[(z * (-x)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{+191} \lor \neg \left(z \leq 2.4 \cdot 10^{+82}\right):\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1.8999999999999999e191 or 2.39999999999999998e82 < z Initial program 100.0%
Taylor expanded in y around 0 66.1%
mul-1-neg66.1%
distribute-lft-neg-out66.1%
*-commutative66.1%
Simplified66.1%
Taylor expanded in z around inf 66.1%
associate-*r*66.1%
mul-1-neg66.1%
Simplified66.1%
if -1.8999999999999999e191 < z < 2.39999999999999998e82Initial program 100.0%
Taylor expanded in y around inf 89.6%
*-commutative89.6%
Simplified89.6%
Final simplification83.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.4e+23) (not (<= y 1.08e-182))) (+ x (* y z)) (- x (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.4e+23) || !(y <= 1.08e-182)) {
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 <= (-5.4d+23)) .or. (.not. (y <= 1.08d-182))) 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 <= -5.4e+23) || !(y <= 1.08e-182)) {
tmp = x + (y * z);
} else {
tmp = x - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.4e+23) or not (y <= 1.08e-182): tmp = x + (y * z) else: tmp = x - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.4e+23) || !(y <= 1.08e-182)) 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 <= -5.4e+23) || ~((y <= 1.08e-182))) tmp = x + (y * z); else tmp = x - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.4e+23], N[Not[LessEqual[y, 1.08e-182]], $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 -5.4 \cdot 10^{+23} \lor \neg \left(y \leq 1.08 \cdot 10^{-182}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot z\\
\end{array}
\end{array}
if y < -5.3999999999999997e23 or 1.08000000000000003e-182 < y Initial program 100.0%
Taylor expanded in y around inf 87.9%
*-commutative87.9%
Simplified87.9%
if -5.3999999999999997e23 < y < 1.08000000000000003e-182Initial program 100.0%
Taylor expanded in y around 0 90.7%
mul-1-neg90.7%
distribute-lft-neg-out90.7%
*-commutative90.7%
Simplified90.7%
distribute-rgt-neg-out90.7%
unsub-neg90.7%
*-commutative90.7%
Applied egg-rr90.7%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (<= z -0.115) (* y z) (if (<= z 3.8e-69) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.115) {
tmp = y * z;
} else if (z <= 3.8e-69) {
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 <= (-0.115d0)) then
tmp = y * z
else if (z <= 3.8d-69) 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 <= -0.115) {
tmp = y * z;
} else if (z <= 3.8e-69) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.115: tmp = y * z elif z <= 3.8e-69: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.115) tmp = Float64(y * z); elseif (z <= 3.8e-69) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.115) tmp = y * z; elseif (z <= 3.8e-69) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.115], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.8e-69], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.115:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-69}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -0.115000000000000005 or 3.7999999999999998e-69 < z Initial program 100.0%
Taylor expanded in y around inf 54.6%
*-commutative54.6%
Simplified54.6%
Taylor expanded in x around 0 52.3%
if -0.115000000000000005 < z < 3.7999999999999998e-69Initial program 100.0%
Taylor expanded in y around inf 99.2%
*-commutative99.2%
Simplified99.2%
Taylor expanded in x around inf 78.3%
Final simplification65.1%
(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.6%
*-commutative76.6%
Simplified76.6%
Taylor expanded in x around inf 41.1%
Final simplification41.1%
herbie shell --seed 2023279
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))