
(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 -7.8e+84)
(* y z)
(if (<= z -2.25e+38)
t_0
(if (<= z -1.35e-30)
(* y z)
(if (<= z 1.3e-17)
x
(if (or (<= z 1960000000000.0)
(and (not (<= z 2.8e+31)) (<= z 2.25e+202)))
(* y z)
t_0)))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -7.8e+84) {
tmp = y * z;
} else if (z <= -2.25e+38) {
tmp = t_0;
} else if (z <= -1.35e-30) {
tmp = y * z;
} else if (z <= 1.3e-17) {
tmp = x;
} else if ((z <= 1960000000000.0) || (!(z <= 2.8e+31) && (z <= 2.25e+202))) {
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 <= (-7.8d+84)) then
tmp = y * z
else if (z <= (-2.25d+38)) then
tmp = t_0
else if (z <= (-1.35d-30)) then
tmp = y * z
else if (z <= 1.3d-17) then
tmp = x
else if ((z <= 1960000000000.0d0) .or. (.not. (z <= 2.8d+31)) .and. (z <= 2.25d+202)) 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 <= -7.8e+84) {
tmp = y * z;
} else if (z <= -2.25e+38) {
tmp = t_0;
} else if (z <= -1.35e-30) {
tmp = y * z;
} else if (z <= 1.3e-17) {
tmp = x;
} else if ((z <= 1960000000000.0) || (!(z <= 2.8e+31) && (z <= 2.25e+202))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -7.8e+84: tmp = y * z elif z <= -2.25e+38: tmp = t_0 elif z <= -1.35e-30: tmp = y * z elif z <= 1.3e-17: tmp = x elif (z <= 1960000000000.0) or (not (z <= 2.8e+31) and (z <= 2.25e+202)): 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 <= -7.8e+84) tmp = Float64(y * z); elseif (z <= -2.25e+38) tmp = t_0; elseif (z <= -1.35e-30) tmp = Float64(y * z); elseif (z <= 1.3e-17) tmp = x; elseif ((z <= 1960000000000.0) || (!(z <= 2.8e+31) && (z <= 2.25e+202))) 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 <= -7.8e+84) tmp = y * z; elseif (z <= -2.25e+38) tmp = t_0; elseif (z <= -1.35e-30) tmp = y * z; elseif (z <= 1.3e-17) tmp = x; elseif ((z <= 1960000000000.0) || (~((z <= 2.8e+31)) && (z <= 2.25e+202))) 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, -7.8e+84], N[(y * z), $MachinePrecision], If[LessEqual[z, -2.25e+38], t$95$0, If[LessEqual[z, -1.35e-30], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.3e-17], x, If[Or[LessEqual[z, 1960000000000.0], And[N[Not[LessEqual[z, 2.8e+31]], $MachinePrecision], LessEqual[z, 2.25e+202]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -7.8 \cdot 10^{+84}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -2.25 \cdot 10^{+38}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.35 \cdot 10^{-30}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-17}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1960000000000 \lor \neg \left(z \leq 2.8 \cdot 10^{+31}\right) \land z \leq 2.25 \cdot 10^{+202}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -7.80000000000000032e84 or -2.2499999999999999e38 < z < -1.34999999999999994e-30 or 1.30000000000000002e-17 < z < 1.96e12 or 2.80000000000000017e31 < z < 2.24999999999999989e202Initial program 100.0%
Taylor expanded in z around inf 95.6%
Taylor expanded in y around inf 68.0%
*-commutative68.0%
Simplified68.0%
if -7.80000000000000032e84 < z < -2.2499999999999999e38 or 1.96e12 < z < 2.80000000000000017e31 or 2.24999999999999989e202 < z Initial program 99.9%
Taylor expanded in z around inf 99.4%
Taylor expanded in y around 0 71.9%
mul-1-neg71.9%
distribute-rgt-neg-out71.9%
Simplified71.9%
if -1.34999999999999994e-30 < z < 1.30000000000000002e-17Initial program 100.0%
Taylor expanded in z around 0 80.8%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.5e-28) (not (<= z 2.7e-19))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-28) || !(z <= 2.7e-19)) {
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 <= (-8.5d-28)) .or. (.not. (z <= 2.7d-19))) 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 <= -8.5e-28) || !(z <= 2.7e-19)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.5e-28) or not (z <= 2.7e-19): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.5e-28) || !(z <= 2.7e-19)) 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 <= -8.5e-28) || ~((z <= 2.7e-19))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e-28], N[Not[LessEqual[z, 2.7e-19]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-28} \lor \neg \left(z \leq 2.7 \cdot 10^{-19}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.49999999999999925e-28 or 2.7000000000000001e-19 < z Initial program 100.0%
Taylor expanded in z around inf 96.6%
if -8.49999999999999925e-28 < z < 2.7000000000000001e-19Initial program 100.0%
Taylor expanded in z around 0 80.8%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.42e-12))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.42e-12)) {
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 <= (-1.0d0)) .or. (.not. (z <= 1.42d-12))) 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 <= -1.0) || !(z <= 1.42e-12)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.42e-12): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.42e-12)) 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 <= -1.0) || ~((z <= 1.42e-12))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.42e-12]], $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 -1 \lor \neg \left(z \leq 1.42 \cdot 10^{-12}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1.42e-12 < z Initial program 100.0%
Taylor expanded in z around inf 98.7%
if -1 < z < 1.42e-12Initial program 100.0%
Taylor expanded in y around inf 98.8%
*-commutative25.0%
Simplified98.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= z -8.5e-29) (* y z) (if (<= z 5.3e-14) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.5e-29) {
tmp = y * z;
} else if (z <= 5.3e-14) {
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 <= (-8.5d-29)) then
tmp = y * z
else if (z <= 5.3d-14) 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 <= -8.5e-29) {
tmp = y * z;
} else if (z <= 5.3e-14) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.5e-29: tmp = y * z elif z <= 5.3e-14: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.5e-29) tmp = Float64(y * z); elseif (z <= 5.3e-14) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.5e-29) tmp = y * z; elseif (z <= 5.3e-14) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.5e-29], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.3e-14], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-29}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.3 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -8.5000000000000001e-29 or 5.3000000000000001e-14 < z Initial program 100.0%
Taylor expanded in z around inf 96.6%
Taylor expanded in y around inf 57.8%
*-commutative57.8%
Simplified57.8%
if -8.5000000000000001e-29 < z < 5.3000000000000001e-14Initial program 100.0%
Taylor expanded in z around 0 80.8%
Final simplification68.6%
(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 40.1%
Final simplification40.1%
herbie shell --seed 2023257
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))