
(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 -4.3e+163)
t_0
(if (<= z -1.4e-33)
(* y z)
(if (<= z 1.9e-15)
x
(if (or (<= z 5e+44) (and (not (<= z 1.75e+75)) (<= z 9.4e+113)))
(* y z)
t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -4.3e+163) {
tmp = t_0;
} else if (z <= -1.4e-33) {
tmp = y * z;
} else if (z <= 1.9e-15) {
tmp = x;
} else if ((z <= 5e+44) || (!(z <= 1.75e+75) && (z <= 9.4e+113))) {
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 <= (-4.3d+163)) then
tmp = t_0
else if (z <= (-1.4d-33)) then
tmp = y * z
else if (z <= 1.9d-15) then
tmp = x
else if ((z <= 5d+44) .or. (.not. (z <= 1.75d+75)) .and. (z <= 9.4d+113)) 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 <= -4.3e+163) {
tmp = t_0;
} else if (z <= -1.4e-33) {
tmp = y * z;
} else if (z <= 1.9e-15) {
tmp = x;
} else if ((z <= 5e+44) || (!(z <= 1.75e+75) && (z <= 9.4e+113))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -4.3e+163: tmp = t_0 elif z <= -1.4e-33: tmp = y * z elif z <= 1.9e-15: tmp = x elif (z <= 5e+44) or (not (z <= 1.75e+75) and (z <= 9.4e+113)): 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 <= -4.3e+163) tmp = t_0; elseif (z <= -1.4e-33) tmp = Float64(y * z); elseif (z <= 1.9e-15) tmp = x; elseif ((z <= 5e+44) || (!(z <= 1.75e+75) && (z <= 9.4e+113))) 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 <= -4.3e+163) tmp = t_0; elseif (z <= -1.4e-33) tmp = y * z; elseif (z <= 1.9e-15) tmp = x; elseif ((z <= 5e+44) || (~((z <= 1.75e+75)) && (z <= 9.4e+113))) 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, -4.3e+163], t$95$0, If[LessEqual[z, -1.4e-33], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.9e-15], x, If[Or[LessEqual[z, 5e+44], And[N[Not[LessEqual[z, 1.75e+75]], $MachinePrecision], LessEqual[z, 9.4e+113]]], N[(y * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -4.3 \cdot 10^{+163}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.4 \cdot 10^{-33}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-15}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+44} \lor \neg \left(z \leq 1.75 \cdot 10^{+75}\right) \land z \leq 9.4 \cdot 10^{+113}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -4.3000000000000002e163 or 4.9999999999999996e44 < z < 1.7499999999999999e75 or 9.3999999999999996e113 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around 0 67.6%
mul-1-neg67.6%
distribute-rgt-neg-out67.6%
Simplified67.6%
if -4.3000000000000002e163 < z < -1.4e-33 or 1.9000000000000001e-15 < z < 4.9999999999999996e44 or 1.7499999999999999e75 < z < 9.3999999999999996e113Initial program 100.0%
Taylor expanded in z around inf 94.4%
Taylor expanded in y around inf 69.8%
*-commutative69.8%
Simplified69.8%
if -1.4e-33 < z < 1.9000000000000001e-15Initial program 100.0%
Taylor expanded in z around 0 72.0%
Final simplification70.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.34e-33) (not (<= z 3.4e-18))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.34e-33) || !(z <= 3.4e-18)) {
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 <= (-1.34d-33)) .or. (.not. (z <= 3.4d-18))) 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 <= -1.34e-33) || !(z <= 3.4e-18)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.34e-33) or not (z <= 3.4e-18): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.34e-33) || !(z <= 3.4e-18)) 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 <= -1.34e-33) || ~((z <= 3.4e-18))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.34e-33], N[Not[LessEqual[z, 3.4e-18]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.34 \cdot 10^{-33} \lor \neg \left(z \leq 3.4 \cdot 10^{-18}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.3400000000000001e-33 or 3.40000000000000001e-18 < z Initial program 100.0%
Taylor expanded in z around inf 97.9%
if -1.3400000000000001e-33 < z < 3.40000000000000001e-18Initial program 100.0%
Taylor expanded in z around 0 72.0%
Final simplification85.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 2.9e-10))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 2.9e-10)) {
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 <= 2.9d-10))) 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 <= 2.9e-10)) {
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 <= 2.9e-10): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 2.9e-10)) 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 <= 2.9e-10))) 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, 2.9e-10]], $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 2.9 \cdot 10^{-10}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 2.89999999999999981e-10 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
if -1 < z < 2.89999999999999981e-10Initial program 100.0%
Taylor expanded in y around inf 99.2%
*-commutative30.0%
Simplified99.2%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.45e-32) (* y z) (if (<= z 1.9e-17) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.45e-32) {
tmp = y * z;
} else if (z <= 1.9e-17) {
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 <= (-1.45d-32)) then
tmp = y * z
else if (z <= 1.9d-17) 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 <= -1.45e-32) {
tmp = y * z;
} else if (z <= 1.9e-17) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.45e-32: tmp = y * z elif z <= 1.9e-17: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.45e-32) tmp = Float64(y * z); elseif (z <= 1.9e-17) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.45e-32) tmp = y * z; elseif (z <= 1.9e-17) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.45e-32], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.9e-17], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{-32}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-17}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.44999999999999998e-32 or 1.9000000000000001e-17 < z Initial program 100.0%
Taylor expanded in z around inf 97.9%
Taylor expanded in y around inf 49.4%
*-commutative49.4%
Simplified49.4%
if -1.44999999999999998e-32 < z < 1.9000000000000001e-17Initial program 100.0%
Taylor expanded in z around 0 72.0%
Final simplification60.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 37.7%
Final simplification37.7%
herbie shell --seed 2023214
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))