
(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 x (- y z) z))
double code(double x, double y, double z) {
return fma(x, (y - z), z);
}
function code(x, y, z) return fma(x, Float64(y - z), z) end
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y - z, z\right)
\end{array}
Initial program 99.2%
Taylor expanded in x around 0
+-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 (let* ((t_0 (* x (- y z)))) (if (<= y -1.9e+73) t_0 (if (<= y 7.4e-32) (fma (- z) x z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (y <= -1.9e+73) {
tmp = t_0;
} else if (y <= 7.4e-32) {
tmp = fma(-z, x, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (y <= -1.9e+73) tmp = t_0; elseif (y <= 7.4e-32) tmp = fma(Float64(-z), x, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.9e+73], t$95$0, If[LessEqual[y, 7.4e-32], N[((-z) * x + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;y \leq -1.9 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{-32}:\\
\;\;\;\;\mathsf{fma}\left(-z, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.90000000000000011e73 or 7.4e-32 < y Initial program 98.2%
Taylor expanded in x around inf
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--.f6485.0
Applied rewrites85.0%
if -1.90000000000000011e73 < y < 7.4e-32Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6486.2
Applied rewrites86.2%
Applied rewrites86.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= y -1.9e+73) t_0 (if (<= y 7.4e-32) (- z (* x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (y <= -1.9e+73) {
tmp = t_0;
} else if (y <= 7.4e-32) {
tmp = z - (x * z);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = x * (y - z)
if (y <= (-1.9d+73)) then
tmp = t_0
else if (y <= 7.4d-32) then
tmp = z - (x * z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (y <= -1.9e+73) {
tmp = t_0;
} else if (y <= 7.4e-32) {
tmp = z - (x * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if y <= -1.9e+73: tmp = t_0 elif y <= 7.4e-32: tmp = z - (x * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (y <= -1.9e+73) tmp = t_0; elseif (y <= 7.4e-32) tmp = Float64(z - Float64(x * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); tmp = 0.0; if (y <= -1.9e+73) tmp = t_0; elseif (y <= 7.4e-32) tmp = z - (x * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.9e+73], t$95$0, If[LessEqual[y, 7.4e-32], N[(z - N[(x * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;y \leq -1.9 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{-32}:\\
\;\;\;\;z - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.90000000000000011e73 or 7.4e-32 < y Initial program 98.2%
Taylor expanded in x around inf
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--.f6485.0
Applied rewrites85.0%
if -1.90000000000000011e73 < y < 7.4e-32Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6486.2
Applied rewrites86.2%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.26e-61) (* x y) (if (<= y 3.8e-7) (* x (- z)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.26e-61) {
tmp = x * y;
} else if (y <= 3.8e-7) {
tmp = x * -z;
} else {
tmp = x * 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 (y <= (-1.26d-61)) then
tmp = x * y
else if (y <= 3.8d-7) then
tmp = x * -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.26e-61) {
tmp = x * y;
} else if (y <= 3.8e-7) {
tmp = x * -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.26e-61: tmp = x * y elif y <= 3.8e-7: tmp = x * -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.26e-61) tmp = Float64(x * y); elseif (y <= 3.8e-7) tmp = Float64(x * Float64(-z)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.26e-61) tmp = x * y; elseif (y <= 3.8e-7) tmp = x * -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.26e-61], N[(x * y), $MachinePrecision], If[LessEqual[y, 3.8e-7], N[(x * (-z)), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.26 \cdot 10^{-61}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-7}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.2599999999999999e-61 or 3.80000000000000015e-7 < y Initial program 98.6%
Taylor expanded in y around inf
lower-*.f6468.7
Applied rewrites68.7%
if -1.2599999999999999e-61 < y < 3.80000000000000015e-7Initial program 100.0%
Taylor expanded in x around inf
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--.f6451.4
Applied rewrites51.4%
Taylor expanded in y around 0
Applied rewrites44.9%
(FPCore (x y z) :precision binary64 (* x (- y z)))
double code(double x, double y, double z) {
return x * (y - 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 - z)
end function
public static double code(double x, double y, double z) {
return x * (y - z);
}
def code(x, y, z): return x * (y - z)
function code(x, y, z) return Float64(x * Float64(y - z)) end
function tmp = code(x, y, z) tmp = x * (y - z); end
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y - z\right)
\end{array}
Initial program 99.2%
Taylor expanded in x around inf
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--.f6466.3
Applied rewrites66.3%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
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
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.2%
Taylor expanded in y around inf
lower-*.f6441.5
Applied rewrites41.5%
herbie shell --seed 2024223
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))