
(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 5 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 -1.65e+192)
(* z y)
(if (<= z -1.22e+56)
(* (- z) x)
(if (or (<= z -7.5e-42) (not (<= z 5e-56))) (* z y) (* 1.0 x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.65e+192) {
tmp = z * y;
} else if (z <= -1.22e+56) {
tmp = -z * x;
} else if ((z <= -7.5e-42) || !(z <= 5e-56)) {
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 <= (-1.65d+192)) then
tmp = z * y
else if (z <= (-1.22d+56)) then
tmp = -z * x
else if ((z <= (-7.5d-42)) .or. (.not. (z <= 5d-56))) 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 <= -1.65e+192) {
tmp = z * y;
} else if (z <= -1.22e+56) {
tmp = -z * x;
} else if ((z <= -7.5e-42) || !(z <= 5e-56)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.65e+192: tmp = z * y elif z <= -1.22e+56: tmp = -z * x elif (z <= -7.5e-42) or not (z <= 5e-56): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.65e+192) tmp = Float64(z * y); elseif (z <= -1.22e+56) tmp = Float64(Float64(-z) * x); elseif ((z <= -7.5e-42) || !(z <= 5e-56)) 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 <= -1.65e+192) tmp = z * y; elseif (z <= -1.22e+56) tmp = -z * x; elseif ((z <= -7.5e-42) || ~((z <= 5e-56))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.65e+192], N[(z * y), $MachinePrecision], If[LessEqual[z, -1.22e+56], N[((-z) * x), $MachinePrecision], If[Or[LessEqual[z, -7.5e-42], N[Not[LessEqual[z, 5e-56]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{+192}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq -1.22 \cdot 10^{+56}:\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{elif}\;z \leq -7.5 \cdot 10^{-42} \lor \neg \left(z \leq 5 \cdot 10^{-56}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -1.65000000000000005e192 or -1.22e56 < z < -7.49999999999999972e-42 or 4.99999999999999997e-56 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6465.9
Applied rewrites65.9%
if -1.65000000000000005e192 < z < -1.22e56Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6482.4
Applied rewrites82.4%
Taylor expanded in z around inf
Applied rewrites82.4%
if -7.49999999999999972e-42 < z < 4.99999999999999997e-56Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6473.4
Applied rewrites73.4%
Taylor expanded in z around 0
Applied rewrites73.4%
Final simplification71.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-42) (not (<= z 5e-56))) (* z (- y x)) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-42) || !(z <= 5e-56)) {
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 <= (-6.5d-42)) .or. (.not. (z <= 5d-56))) 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 <= -6.5e-42) || !(z <= 5e-56)) {
tmp = z * (y - x);
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-42) or not (z <= 5e-56): tmp = z * (y - x) else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-42) || !(z <= 5e-56)) 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 <= -6.5e-42) || ~((z <= 5e-56))) tmp = z * (y - x); else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-42], N[Not[LessEqual[z, 5e-56]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-42} \lor \neg \left(z \leq 5 \cdot 10^{-56}\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -6.4999999999999998e-42 or 4.99999999999999997e-56 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6458.5
Applied rewrites58.5%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6496.8
Applied rewrites96.8%
if -6.4999999999999998e-42 < z < 4.99999999999999997e-56Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6473.4
Applied rewrites73.4%
Taylor expanded in z around 0
Applied rewrites73.4%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.5e-42) (not (<= z 5e-56))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.5e-42) || !(z <= 5e-56)) {
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 <= (-7.5d-42)) .or. (.not. (z <= 5d-56))) 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 <= -7.5e-42) || !(z <= 5e-56)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.5e-42) or not (z <= 5e-56): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.5e-42) || !(z <= 5e-56)) 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 <= -7.5e-42) || ~((z <= 5e-56))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.5e-42], N[Not[LessEqual[z, 5e-56]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{-42} \lor \neg \left(z \leq 5 \cdot 10^{-56}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -7.49999999999999972e-42 or 4.99999999999999997e-56 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6458.5
Applied rewrites58.5%
if -7.49999999999999972e-42 < z < 4.99999999999999997e-56Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6473.4
Applied rewrites73.4%
Taylor expanded in z around 0
Applied rewrites73.4%
Final simplification64.7%
(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-*.f6445.5
Applied rewrites45.5%
herbie shell --seed 2024322
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))