
(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 -0.000104) (not (<= z 1.08e-13))) (* z (- y x)) (fma (- x) z x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.000104) || !(z <= 1.08e-13)) {
tmp = z * (y - x);
} else {
tmp = fma(-x, z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -0.000104) || !(z <= 1.08e-13)) tmp = Float64(z * Float64(y - x)); else tmp = fma(Float64(-x), z, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.000104], N[Not[LessEqual[z, 1.08e-13]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[((-x) * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000104 \lor \neg \left(z \leq 1.08 \cdot 10^{-13}\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\end{array}
\end{array}
if z < -1.03999999999999994e-4 or 1.0799999999999999e-13 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.2
Applied rewrites53.2%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -1.03999999999999994e-4 < z < 1.0799999999999999e-13Initial 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.f6472.5
Applied rewrites72.5%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.000104) (not (<= z 1.08e-13))) (* z (- y x)) (* (- 1.0 z) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.000104) || !(z <= 1.08e-13)) {
tmp = z * (y - x);
} 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 <= (-0.000104d0)) .or. (.not. (z <= 1.08d-13))) then
tmp = z * (y - x)
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 <= -0.000104) || !(z <= 1.08e-13)) {
tmp = z * (y - x);
} else {
tmp = (1.0 - z) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.000104) or not (z <= 1.08e-13): tmp = z * (y - x) else: tmp = (1.0 - z) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.000104) || !(z <= 1.08e-13)) tmp = Float64(z * Float64(y - x)); else tmp = Float64(Float64(1.0 - z) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -0.000104) || ~((z <= 1.08e-13))) tmp = z * (y - x); else tmp = (1.0 - z) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.000104], N[Not[LessEqual[z, 1.08e-13]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000104 \lor \neg \left(z \leq 1.08 \cdot 10^{-13}\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\end{array}
\end{array}
if z < -1.03999999999999994e-4 or 1.0799999999999999e-13 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.2
Applied rewrites53.2%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -1.03999999999999994e-4 < z < 1.0799999999999999e-13Initial 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--.f6472.5
Applied rewrites72.5%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.5e-5) (not (<= z 9.5e-14))) (* z (- y x)) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.5e-5) || !(z <= 9.5e-14)) {
tmp = z * (y - x);
} 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 <= (-9.5d-5)) .or. (.not. (z <= 9.5d-14))) then
tmp = z * (y - x)
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 <= -9.5e-5) || !(z <= 9.5e-14)) {
tmp = z * (y - x);
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.5e-5) or not (z <= 9.5e-14): tmp = z * (y - x) else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.5e-5) || !(z <= 9.5e-14)) tmp = Float64(z * Float64(y - x)); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9.5e-5) || ~((z <= 9.5e-14))) tmp = z * (y - x); else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.5e-5], N[Not[LessEqual[z, 9.5e-14]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-5} \lor \neg \left(z \leq 9.5 \cdot 10^{-14}\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -9.5000000000000005e-5 or 9.4999999999999999e-14 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.2
Applied rewrites53.2%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -9.5000000000000005e-5 < z < 9.4999999999999999e-14Initial 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--.f6472.5
Applied rewrites72.5%
Taylor expanded in z around 0
Applied rewrites71.6%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.5e-5) (not (<= z 9.5e-14))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.5e-5) || !(z <= 9.5e-14)) {
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 <= (-9.5d-5)) .or. (.not. (z <= 9.5d-14))) 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 <= -9.5e-5) || !(z <= 9.5e-14)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.5e-5) or not (z <= 9.5e-14): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.5e-5) || !(z <= 9.5e-14)) 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 <= -9.5e-5) || ~((z <= 9.5e-14))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.5e-5], N[Not[LessEqual[z, 9.5e-14]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-5} \lor \neg \left(z \leq 9.5 \cdot 10^{-14}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -9.5000000000000005e-5 or 9.4999999999999999e-14 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.2
Applied rewrites53.2%
if -9.5000000000000005e-5 < z < 9.4999999999999999e-14Initial 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--.f6472.5
Applied rewrites72.5%
Taylor expanded in z around 0
Applied rewrites71.6%
Final simplification62.0%
(FPCore (x y z) :precision binary64 (if (<= z -0.000135) (* (- z) x) (if (<= z 9.5e-14) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.000135) {
tmp = -z * x;
} else if (z <= 9.5e-14) {
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 <= (-0.000135d0)) then
tmp = -z * x
else if (z <= 9.5d-14) 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 <= -0.000135) {
tmp = -z * x;
} else if (z <= 9.5e-14) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.000135: tmp = -z * x elif z <= 9.5e-14: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.000135) tmp = Float64(Float64(-z) * x); elseif (z <= 9.5e-14) 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 <= -0.000135) tmp = -z * x; elseif (z <= 9.5e-14) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.000135], N[((-z) * x), $MachinePrecision], If[LessEqual[z, 9.5e-14], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000135:\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{-14}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -1.35000000000000002e-4Initial 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--.f6462.1
Applied rewrites62.1%
Taylor expanded in z around inf
Applied rewrites61.4%
if -1.35000000000000002e-4 < z < 9.4999999999999999e-14Initial 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--.f6472.5
Applied rewrites72.5%
Taylor expanded in z around 0
Applied rewrites71.6%
if 9.4999999999999999e-14 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6461.5
Applied rewrites61.5%
(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-*.f6441.8
Applied rewrites41.8%
herbie shell --seed 2024340
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))