
(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 (<= z -4.3e+217) (* (- z) x) (if (or (<= z -1e-8) (not (<= z 2.4e-20))) (* z y) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.3e+217) {
tmp = -z * x;
} else if ((z <= -1e-8) || !(z <= 2.4e-20)) {
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 <= (-4.3d+217)) then
tmp = -z * x
else if ((z <= (-1d-8)) .or. (.not. (z <= 2.4d-20))) 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 <= -4.3e+217) {
tmp = -z * x;
} else if ((z <= -1e-8) || !(z <= 2.4e-20)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.3e+217: tmp = -z * x elif (z <= -1e-8) or not (z <= 2.4e-20): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.3e+217) tmp = Float64(Float64(-z) * x); elseif ((z <= -1e-8) || !(z <= 2.4e-20)) 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 <= -4.3e+217) tmp = -z * x; elseif ((z <= -1e-8) || ~((z <= 2.4e-20))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.3e+217], N[((-z) * x), $MachinePrecision], If[Or[LessEqual[z, -1e-8], N[Not[LessEqual[z, 2.4e-20]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.3 \cdot 10^{+217}:\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{elif}\;z \leq -1 \cdot 10^{-8} \lor \neg \left(z \leq 2.4 \cdot 10^{-20}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -4.3000000000000001e217Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6479.6
Applied rewrites79.6%
Taylor expanded in z around inf
Applied rewrites79.6%
if -4.3000000000000001e217 < z < -1e-8 or 2.39999999999999993e-20 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6458.3
Applied rewrites58.3%
if -1e-8 < z < 2.39999999999999993e-20Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6470.7
Applied rewrites70.7%
Taylor expanded in z around 0
Applied rewrites70.3%
Final simplification65.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.5e-6) (not (<= z 880.0))) (* z (- y x)) (fma (- x) z x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e-6) || !(z <= 880.0)) {
tmp = z * (y - x);
} else {
tmp = fma(-x, z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -3.5e-6) || !(z <= 880.0)) 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, -3.5e-6], N[Not[LessEqual[z, 880.0]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[((-x) * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{-6} \lor \neg \left(z \leq 880\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\end{array}
\end{array}
if z < -3.49999999999999995e-6 or 880 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6455.9
Applied rewrites55.9%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -3.49999999999999995e-6 < z < 880Initial 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.f6470.2
Applied rewrites70.2%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.5e-6) (not (<= z 880.0))) (* z (- y x)) (* (- 1.0 z) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e-6) || !(z <= 880.0)) {
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 <= (-3.5d-6)) .or. (.not. (z <= 880.0d0))) 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 <= -3.5e-6) || !(z <= 880.0)) {
tmp = z * (y - x);
} else {
tmp = (1.0 - z) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.5e-6) or not (z <= 880.0): tmp = z * (y - x) else: tmp = (1.0 - z) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.5e-6) || !(z <= 880.0)) 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 <= -3.5e-6) || ~((z <= 880.0))) tmp = z * (y - x); else tmp = (1.0 - z) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.5e-6], N[Not[LessEqual[z, 880.0]], $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 -3.5 \cdot 10^{-6} \lor \neg \left(z \leq 880\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\end{array}
\end{array}
if z < -3.49999999999999995e-6 or 880 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6455.9
Applied rewrites55.9%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -3.49999999999999995e-6 < z < 880Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6470.2
Applied rewrites70.2%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e-8) (not (<= z 3.7e-20))) (* z (- y x)) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e-8) || !(z <= 3.7e-20)) {
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 <= (-1d-8)) .or. (.not. (z <= 3.7d-20))) 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 <= -1e-8) || !(z <= 3.7e-20)) {
tmp = z * (y - x);
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e-8) or not (z <= 3.7e-20): tmp = z * (y - x) else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e-8) || !(z <= 3.7e-20)) 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 <= -1e-8) || ~((z <= 3.7e-20))) tmp = z * (y - x); else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e-8], N[Not[LessEqual[z, 3.7e-20]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-8} \lor \neg \left(z \leq 3.7 \cdot 10^{-20}\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -1e-8 or 3.7000000000000001e-20 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6455.3
Applied rewrites55.3%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6496.6
Applied rewrites96.6%
if -1e-8 < z < 3.7000000000000001e-20Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6470.7
Applied rewrites70.7%
Taylor expanded in z around 0
Applied rewrites70.3%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e-8) (not (<= z 2.4e-20))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e-8) || !(z <= 2.4e-20)) {
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 <= (-1d-8)) .or. (.not. (z <= 2.4d-20))) 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 <= -1e-8) || !(z <= 2.4e-20)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e-8) or not (z <= 2.4e-20): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e-8) || !(z <= 2.4e-20)) 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 <= -1e-8) || ~((z <= 2.4e-20))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e-8], N[Not[LessEqual[z, 2.4e-20]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-8} \lor \neg \left(z \leq 2.4 \cdot 10^{-20}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -1e-8 or 2.39999999999999993e-20 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6455.3
Applied rewrites55.3%
if -1e-8 < z < 2.39999999999999993e-20Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6470.7
Applied rewrites70.7%
Taylor expanded in z around 0
Applied rewrites70.3%
Final simplification62.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-*.f6443.2
Applied rewrites43.2%
herbie shell --seed 2024311
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))