
(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
(let* ((t_0 (* z (- x))))
(if (<= z -5.9e+122)
t_0
(if (<= z -4.6e+42)
(* y z)
(if (<= z -2.2e+17)
t_0
(if (<= z -4.5e-57)
(* y z)
(if (<= z 3.2e-66)
x
(if (<= z 1.04e+214)
(* y z)
(if (<= z 1.6e+235) t_0 (* y z))))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -5.9e+122) {
tmp = t_0;
} else if (z <= -4.6e+42) {
tmp = y * z;
} else if (z <= -2.2e+17) {
tmp = t_0;
} else if (z <= -4.5e-57) {
tmp = y * z;
} else if (z <= 3.2e-66) {
tmp = x;
} else if (z <= 1.04e+214) {
tmp = y * z;
} else if (z <= 1.6e+235) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = z * -x
if (z <= (-5.9d+122)) then
tmp = t_0
else if (z <= (-4.6d+42)) then
tmp = y * z
else if (z <= (-2.2d+17)) then
tmp = t_0
else if (z <= (-4.5d-57)) then
tmp = y * z
else if (z <= 3.2d-66) then
tmp = x
else if (z <= 1.04d+214) then
tmp = y * z
else if (z <= 1.6d+235) then
tmp = t_0
else
tmp = y * z
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 <= -5.9e+122) {
tmp = t_0;
} else if (z <= -4.6e+42) {
tmp = y * z;
} else if (z <= -2.2e+17) {
tmp = t_0;
} else if (z <= -4.5e-57) {
tmp = y * z;
} else if (z <= 3.2e-66) {
tmp = x;
} else if (z <= 1.04e+214) {
tmp = y * z;
} else if (z <= 1.6e+235) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -5.9e+122: tmp = t_0 elif z <= -4.6e+42: tmp = y * z elif z <= -2.2e+17: tmp = t_0 elif z <= -4.5e-57: tmp = y * z elif z <= 3.2e-66: tmp = x elif z <= 1.04e+214: tmp = y * z elif z <= 1.6e+235: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -5.9e+122) tmp = t_0; elseif (z <= -4.6e+42) tmp = Float64(y * z); elseif (z <= -2.2e+17) tmp = t_0; elseif (z <= -4.5e-57) tmp = Float64(y * z); elseif (z <= 3.2e-66) tmp = x; elseif (z <= 1.04e+214) tmp = Float64(y * z); elseif (z <= 1.6e+235) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -5.9e+122) tmp = t_0; elseif (z <= -4.6e+42) tmp = y * z; elseif (z <= -2.2e+17) tmp = t_0; elseif (z <= -4.5e-57) tmp = y * z; elseif (z <= 3.2e-66) tmp = x; elseif (z <= 1.04e+214) tmp = y * z; elseif (z <= 1.6e+235) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -5.9e+122], t$95$0, If[LessEqual[z, -4.6e+42], N[(y * z), $MachinePrecision], If[LessEqual[z, -2.2e+17], t$95$0, If[LessEqual[z, -4.5e-57], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.2e-66], x, If[LessEqual[z, 1.04e+214], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.6e+235], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -5.9 \cdot 10^{+122}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.6 \cdot 10^{+42}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -2.2 \cdot 10^{+17}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.5 \cdot 10^{-57}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{-66}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.04 \cdot 10^{+214}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+235}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -5.90000000000000032e122 or -4.6e42 < z < -2.2e17 or 1.04e214 < z < 1.60000000000000003e235Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around 0 69.5%
mul-1-neg69.5%
distribute-rgt-neg-out69.5%
Simplified69.5%
if -5.90000000000000032e122 < z < -4.6e42 or -2.2e17 < z < -4.49999999999999973e-57 or 3.19999999999999982e-66 < z < 1.04e214 or 1.60000000000000003e235 < z Initial program 100.0%
Taylor expanded in z around inf 93.1%
Taylor expanded in y around inf 62.8%
*-commutative62.8%
Simplified62.8%
if -4.49999999999999973e-57 < z < 3.19999999999999982e-66Initial program 100.0%
Taylor expanded in z around 0 76.5%
Final simplification69.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.5e-57) (not (<= z 4e-66))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.5e-57) || !(z <= 4e-66)) {
tmp = (y - 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 <= (-4.5d-57)) .or. (.not. (z <= 4d-66))) then
tmp = (y - 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 <= -4.5e-57) || !(z <= 4e-66)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.5e-57) or not (z <= 4e-66): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.5e-57) || !(z <= 4e-66)) tmp = Float64(Float64(y - x) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.5e-57) || ~((z <= 4e-66))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.5e-57], N[Not[LessEqual[z, 4e-66]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-57} \lor \neg \left(z \leq 4 \cdot 10^{-66}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.49999999999999973e-57 or 3.9999999999999999e-66 < z Initial program 100.0%
Taylor expanded in z around inf 95.6%
if -4.49999999999999973e-57 < z < 3.9999999999999999e-66Initial program 100.0%
Taylor expanded in z around 0 76.5%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.5e+16) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e+16) || !(z <= 1.0)) {
tmp = (y - 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 ((z <= (-3.5d+16)) .or. (.not. (z <= 1.0d0))) then
tmp = (y - 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 ((z <= -3.5e+16) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.5e+16) or not (z <= 1.0): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.5e+16) || !(z <= 1.0)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.5e+16) || ~((z <= 1.0))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.5e+16], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{+16} \lor \neg \left(z \leq 1\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -3.5e16 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
if -3.5e16 < z < 1Initial program 100.0%
Taylor expanded in y around inf 98.9%
*-commutative32.4%
Simplified98.9%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= z -4.5e-57) (* y z) (if (<= z 2.05e-65) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e-57) {
tmp = y * z;
} else if (z <= 2.05e-65) {
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 <= (-4.5d-57)) then
tmp = y * z
else if (z <= 2.05d-65) 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 <= -4.5e-57) {
tmp = y * z;
} else if (z <= 2.05e-65) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.5e-57: tmp = y * z elif z <= 2.05e-65: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.5e-57) tmp = Float64(y * z); elseif (z <= 2.05e-65) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.5e-57) tmp = y * z; elseif (z <= 2.05e-65) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.5e-57], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.05e-65], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-57}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.05 \cdot 10^{-65}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.49999999999999973e-57 or 2.04999999999999994e-65 < z Initial program 100.0%
Taylor expanded in z around inf 95.6%
Taylor expanded in y around inf 54.7%
*-commutative54.7%
Simplified54.7%
if -4.49999999999999973e-57 < z < 2.04999999999999994e-65Initial program 100.0%
Taylor expanded in z around 0 76.5%
Final simplification63.2%
(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 33.9%
Final simplification33.9%
herbie shell --seed 2023199
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))