
(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 (if (<= z -5e-7) (* y z) (if (<= z 3e-71) x (if (<= z 3.35e+44) (* y z) (* z (- x))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5e-7) {
tmp = y * z;
} else if (z <= 3e-71) {
tmp = x;
} else if (z <= 3.35e+44) {
tmp = y * z;
} else {
tmp = z * -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 <= (-5d-7)) then
tmp = y * z
else if (z <= 3d-71) then
tmp = x
else if (z <= 3.35d+44) then
tmp = y * z
else
tmp = z * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5e-7) {
tmp = y * z;
} else if (z <= 3e-71) {
tmp = x;
} else if (z <= 3.35e+44) {
tmp = y * z;
} else {
tmp = z * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5e-7: tmp = y * z elif z <= 3e-71: tmp = x elif z <= 3.35e+44: tmp = y * z else: tmp = z * -x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5e-7) tmp = Float64(y * z); elseif (z <= 3e-71) tmp = x; elseif (z <= 3.35e+44) tmp = Float64(y * z); else tmp = Float64(z * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5e-7) tmp = y * z; elseif (z <= 3e-71) tmp = x; elseif (z <= 3.35e+44) tmp = y * z; else tmp = z * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5e-7], N[(y * z), $MachinePrecision], If[LessEqual[z, 3e-71], x, If[LessEqual[z, 3.35e+44], N[(y * z), $MachinePrecision], N[(z * (-x)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{-7}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3 \cdot 10^{-71}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.35 \cdot 10^{+44}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\end{array}
\end{array}
if z < -4.99999999999999977e-7 or 3.0000000000000001e-71 < z < 3.35000000000000018e44Initial program 100.0%
Taylor expanded in z around inf 93.5%
Taylor expanded in y around inf 56.4%
*-commutative56.4%
Simplified56.4%
if -4.99999999999999977e-7 < z < 3.0000000000000001e-71Initial program 100.0%
Taylor expanded in z around 0 76.9%
if 3.35000000000000018e44 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around 0 61.2%
mul-1-neg61.2%
distribute-rgt-neg-out61.2%
Simplified61.2%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8e-7) (not (<= z 2.2e-71))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e-7) || !(z <= 2.2e-71)) {
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.8d-7)) .or. (.not. (z <= 2.2d-71))) 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.8e-7) || !(z <= 2.2e-71)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8e-7) or not (z <= 2.2e-71): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8e-7) || !(z <= 2.2e-71)) 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.8e-7) || ~((z <= 2.2e-71))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e-7], N[Not[LessEqual[z, 2.2e-71]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{-7} \lor \neg \left(z \leq 2.2 \cdot 10^{-71}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.79999999999999957e-7 or 2.19999999999999997e-71 < z Initial program 100.0%
Taylor expanded in z around inf 96.4%
if -4.79999999999999957e-7 < z < 2.19999999999999997e-71Initial program 100.0%
Taylor expanded in z around 0 76.9%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1100000000000.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1100000000000.0) || !(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 <= (-1100000000000.0d0)) .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 <= -1100000000000.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1100000000000.0) 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 <= -1100000000000.0) || !(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 <= -1100000000000.0) || ~((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, -1100000000000.0], 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 -1100000000000 \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 < -1.1e12 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
if -1.1e12 < z < 1Initial program 100.0%
Taylor expanded in y around inf 97.8%
*-commutative29.1%
Simplified97.8%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (<= z -7.6e-7) (* y z) (if (<= z 2.6e-71) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.6e-7) {
tmp = y * z;
} else if (z <= 2.6e-71) {
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 <= (-7.6d-7)) then
tmp = y * z
else if (z <= 2.6d-71) 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 <= -7.6e-7) {
tmp = y * z;
} else if (z <= 2.6e-71) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.6e-7: tmp = y * z elif z <= 2.6e-71: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.6e-7) tmp = Float64(y * z); elseif (z <= 2.6e-71) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.6e-7) tmp = y * z; elseif (z <= 2.6e-71) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.6e-7], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.6e-71], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.6 \cdot 10^{-7}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.6 \cdot 10^{-71}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -7.60000000000000029e-7 or 2.5999999999999999e-71 < z Initial program 100.0%
Taylor expanded in z around inf 96.4%
Taylor expanded in y around inf 51.9%
*-commutative51.9%
Simplified51.9%
if -7.60000000000000029e-7 < z < 2.5999999999999999e-71Initial program 100.0%
Taylor expanded in z around 0 76.9%
Final simplification63.5%
(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 38.2%
Final simplification38.2%
herbie shell --seed 2023171
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))