
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- y z) x z))
double code(double x, double y, double z) {
return fma((y - z), x, z);
}
function code(x, y, z) return fma(Float64(y - z), x, z) end
code[x_, y_, z_] := N[(N[(y - z), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - z, x, z\right)
\end{array}
Initial program 97.2%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.2e-23) (not (<= x 1.28e-5))) (* (- y z) x) (fma (- z) x z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e-23) || !(x <= 1.28e-5)) {
tmp = (y - z) * x;
} else {
tmp = fma(-z, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -3.2e-23) || !(x <= 1.28e-5)) tmp = Float64(Float64(y - z) * x); else tmp = fma(Float64(-z), x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.2e-23], N[Not[LessEqual[x, 1.28e-5]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[((-z) * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 1.28 \cdot 10^{-5}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, x, z\right)\\
\end{array}
\end{array}
if x < -3.19999999999999976e-23 or 1.2799999999999999e-5 < x Initial program 94.8%
Taylor expanded in x around inf
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6498.9
Applied rewrites98.9%
if -3.19999999999999976e-23 < x < 1.2799999999999999e-5Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.6
Applied rewrites75.6%
Applied rewrites75.6%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.2e-23) (not (<= x 5e-10))) (* (- y z) x) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e-23) || !(x <= 5e-10)) {
tmp = (y - z) * x;
} else {
tmp = (1.0 - x) * 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 ((x <= (-3.2d-23)) .or. (.not. (x <= 5d-10))) then
tmp = (y - z) * x
else
tmp = (1.0d0 - x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e-23) || !(x <= 5e-10)) {
tmp = (y - z) * x;
} else {
tmp = (1.0 - x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.2e-23) or not (x <= 5e-10): tmp = (y - z) * x else: tmp = (1.0 - x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.2e-23) || !(x <= 5e-10)) tmp = Float64(Float64(y - z) * x); else tmp = Float64(Float64(1.0 - x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.2e-23) || ~((x <= 5e-10))) tmp = (y - z) * x; else tmp = (1.0 - x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.2e-23], N[Not[LessEqual[x, 5e-10]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 5 \cdot 10^{-10}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\end{array}
\end{array}
if x < -3.19999999999999976e-23 or 5.00000000000000031e-10 < x Initial program 94.8%
Taylor expanded in x around inf
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6498.2
Applied rewrites98.2%
if -3.19999999999999976e-23 < x < 5.00000000000000031e-10Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.0
Applied rewrites76.0%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -600000000.0) (not (<= x 0.92))) (* (- z) x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -600000000.0) || !(x <= 0.92)) {
tmp = -z * x;
} else {
tmp = 1.0 * 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 ((x <= (-600000000.0d0)) .or. (.not. (x <= 0.92d0))) then
tmp = -z * x
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -600000000.0) || !(x <= 0.92)) {
tmp = -z * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -600000000.0) or not (x <= 0.92): tmp = -z * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -600000000.0) || !(x <= 0.92)) tmp = Float64(Float64(-z) * x); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -600000000.0) || ~((x <= 0.92))) tmp = -z * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -600000000.0], N[Not[LessEqual[x, 0.92]], $MachinePrecision]], N[((-z) * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -600000000 \lor \neg \left(x \leq 0.92\right):\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -6e8 or 0.92000000000000004 < x Initial program 94.4%
Taylor expanded in x around inf
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6499.6
Applied rewrites99.6%
Taylor expanded in y around 0
Applied rewrites53.2%
if -6e8 < x < 0.92000000000000004Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6470.9
Applied rewrites70.9%
Taylor expanded in x around 0
Applied rewrites70.0%
Final simplification61.8%
(FPCore (x y z) :precision binary64 (* (- 1.0 x) z))
double code(double x, double y, double z) {
return (1.0 - 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 = (1.0d0 - x) * z
end function
public static double code(double x, double y, double z) {
return (1.0 - x) * z;
}
def code(x, y, z): return (1.0 - x) * z
function code(x, y, z) return Float64(Float64(1.0 - x) * z) end
function tmp = code(x, y, z) tmp = (1.0 - x) * z; end
code[x_, y_, z_] := N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot z
\end{array}
Initial program 97.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6462.5
Applied rewrites62.5%
(FPCore (x y z) :precision binary64 (* 1.0 z))
double code(double x, double y, double z) {
return 1.0 * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * z
end function
public static double code(double x, double y, double z) {
return 1.0 * z;
}
def code(x, y, z): return 1.0 * z
function code(x, y, z) return Float64(1.0 * z) end
function tmp = code(x, y, z) tmp = 1.0 * z; end
code[x_, y_, z_] := N[(1.0 * z), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot z
\end{array}
Initial program 97.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6462.5
Applied rewrites62.5%
Taylor expanded in x around 0
Applied rewrites37.6%
herbie shell --seed 2024324
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))