
(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%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.8e-6) (not (<= z 1.32e-145))) (* (- y x) z) (fma (- x) z x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-6) || !(z <= 1.32e-145)) {
tmp = (y - x) * z;
} else {
tmp = fma(-x, z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e-6) || !(z <= 1.32e-145)) tmp = Float64(Float64(y - x) * z); else tmp = fma(Float64(-x), z, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e-6], N[Not[LessEqual[z, 1.32e-145]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[((-x) * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-6} \lor \neg \left(z \leq 1.32 \cdot 10^{-145}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\end{array}
\end{array}
if z < -2.79999999999999987e-6 or 1.32e-145 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6452.4
Applied rewrites52.4%
Taylor expanded in z around inf
*-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6494.2
Applied rewrites94.2%
if -2.79999999999999987e-6 < z < 1.32e-145Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6478.8
Applied rewrites78.8%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.8e-6) (not (<= z 1.32e-145))) (* (- y x) z) (* (- 1.0 z) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-6) || !(z <= 1.32e-145)) {
tmp = (y - x) * z;
} else {
tmp = (1.0 - 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 <= (-2.8d-6)) .or. (.not. (z <= 1.32d-145))) then
tmp = (y - x) * z
else
tmp = (1.0d0 - z) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-6) || !(z <= 1.32e-145)) {
tmp = (y - x) * z;
} else {
tmp = (1.0 - z) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.8e-6) or not (z <= 1.32e-145): tmp = (y - x) * z else: tmp = (1.0 - z) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e-6) || !(z <= 1.32e-145)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(Float64(1.0 - z) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.8e-6) || ~((z <= 1.32e-145))) tmp = (y - x) * z; else tmp = (1.0 - z) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e-6], N[Not[LessEqual[z, 1.32e-145]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-6} \lor \neg \left(z \leq 1.32 \cdot 10^{-145}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\end{array}
\end{array}
if z < -2.79999999999999987e-6 or 1.32e-145 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6452.4
Applied rewrites52.4%
Taylor expanded in z around inf
*-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6494.2
Applied rewrites94.2%
if -2.79999999999999987e-6 < z < 1.32e-145Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6478.8
Applied rewrites78.8%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.6e-83) (not (<= x 3.9e-40))) (* (- 1.0 z) x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6e-83) || !(x <= 3.9e-40)) {
tmp = (1.0 - z) * x;
} else {
tmp = z * y;
}
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 ((x <= (-8.6d-83)) .or. (.not. (x <= 3.9d-40))) then
tmp = (1.0d0 - z) * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6e-83) || !(x <= 3.9e-40)) {
tmp = (1.0 - z) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.6e-83) or not (x <= 3.9e-40): tmp = (1.0 - z) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.6e-83) || !(x <= 3.9e-40)) tmp = Float64(Float64(1.0 - z) * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.6e-83) || ~((x <= 3.9e-40))) tmp = (1.0 - z) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.6e-83], N[Not[LessEqual[x, 3.9e-40]], $MachinePrecision]], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \cdot 10^{-83} \lor \neg \left(x \leq 3.9 \cdot 10^{-40}\right):\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -8.60000000000000066e-83 or 3.89999999999999981e-40 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6484.6
Applied rewrites84.6%
if -8.60000000000000066e-83 < x < 3.89999999999999981e-40Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6472.3
Applied rewrites72.3%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.8e-7) (not (<= z 1.32e-145))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e-7) || !(z <= 1.32e-145)) {
tmp = z * y;
} else {
tmp = 1.0 * 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 <= (-3.8d-7)) .or. (.not. (z <= 1.32d-145))) then
tmp = z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e-7) || !(z <= 1.32e-145)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.8e-7) or not (z <= 1.32e-145): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e-7) || !(z <= 1.32e-145)) tmp = Float64(z * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.8e-7) || ~((z <= 1.32e-145))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e-7], N[Not[LessEqual[z, 1.32e-145]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-7} \lor \neg \left(z \leq 1.32 \cdot 10^{-145}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -3.80000000000000015e-7 or 1.32e-145 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6452.4
Applied rewrites52.4%
if -3.80000000000000015e-7 < z < 1.32e-145Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6478.8
Applied rewrites78.8%
Taylor expanded in z around 0
Applied rewrites78.0%
Final simplification62.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* (- z) x) (if (<= z 1.32e-145) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = -z * x;
} else if (z <= 1.32e-145) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
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)) then
tmp = -z * x
else if (z <= 1.32d-145) then
tmp = 1.0d0 * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = -z * x;
} else if (z <= 1.32e-145) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = -z * x elif z <= 1.32e-145: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(Float64(-z) * x); elseif (z <= 1.32e-145) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = -z * x; elseif (z <= 1.32e-145) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[((-z) * x), $MachinePrecision], If[LessEqual[z, 1.32e-145], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{elif}\;z \leq 1.32 \cdot 10^{-145}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -1Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6458.4
Applied rewrites58.4%
Taylor expanded in z around inf
Applied rewrites56.9%
if -1 < z < 1.32e-145Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6478.3
Applied rewrites78.3%
Taylor expanded in z around 0
Applied rewrites76.8%
if 1.32e-145 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6454.8
Applied rewrites54.8%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6440.9
Applied rewrites40.9%
herbie shell --seed 2024339
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))