
(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 5 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 97.3%
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
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -8e-14) (* x y) (if (<= x 4.2e-19) (fma z x z) (if (<= x 3e+21) (* x y) (* x (- z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8e-14) {
tmp = x * y;
} else if (x <= 4.2e-19) {
tmp = fma(z, x, z);
} else if (x <= 3e+21) {
tmp = x * y;
} else {
tmp = x * -z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -8e-14) tmp = Float64(x * y); elseif (x <= 4.2e-19) tmp = fma(z, x, z); elseif (x <= 3e+21) tmp = Float64(x * y); else tmp = Float64(x * Float64(-z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -8e-14], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.2e-19], N[(z * x + z), $MachinePrecision], If[LessEqual[x, 3e+21], N[(x * y), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-14}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{fma}\left(z, x, z\right)\\
\mathbf{elif}\;x \leq 3 \cdot 10^{+21}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -7.99999999999999999e-14 or 4.1999999999999998e-19 < x < 3e21Initial program 93.5%
Taylor expanded in y around inf
lower-*.f6456.2
Simplified56.2%
if -7.99999999999999999e-14 < x < 4.1999999999999998e-19Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6479.0
Simplified79.0%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6479.0
Applied egg-rr79.0%
lift-neg.f64N/A
lift-fma.f6479.0
Applied egg-rr79.0%
if 3e21 < x Initial program 95.1%
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--.f64100.0
Simplified100.0%
Taylor expanded in y around 0
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6475.2
Simplified75.2%
Final simplification72.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -3e-19) t_0 (if (<= x 1.1e-12) (fma z x z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -3e-19) {
tmp = t_0;
} else if (x <= 1.1e-12) {
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 (x <= -3e-19) tmp = t_0; elseif (x <= 1.1e-12) tmp = fma(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[x, -3e-19], t$95$0, If[LessEqual[x, 1.1e-12], N[(z * x + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -3 \cdot 10^{-19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(z, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.99999999999999993e-19 or 1.09999999999999996e-12 < x Initial program 94.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--.f6499.6
Simplified99.6%
if -2.99999999999999993e-19 < x < 1.09999999999999996e-12Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6478.6
Simplified78.6%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6478.6
Applied egg-rr78.6%
lift-neg.f64N/A
lift-fma.f6478.6
Applied egg-rr78.6%
(FPCore (x y z) :precision binary64 (if (<= x -5.4e-13) (* x y) (if (<= x 3.65e-19) (fma z x z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e-13) {
tmp = x * y;
} else if (x <= 3.65e-19) {
tmp = fma(z, x, z);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -5.4e-13) tmp = Float64(x * y); elseif (x <= 3.65e-19) tmp = fma(z, x, z); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -5.4e-13], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.65e-19], N[(z * x + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{-13}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.65 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{fma}\left(z, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.40000000000000021e-13 or 3.6499999999999998e-19 < x Initial program 94.3%
Taylor expanded in y around inf
lower-*.f6443.4
Simplified43.4%
if -5.40000000000000021e-13 < x < 3.6499999999999998e-19Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6479.0
Simplified79.0%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6479.0
Applied egg-rr79.0%
lift-neg.f64N/A
lift-fma.f6479.0
Applied egg-rr79.0%
(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 97.3%
Taylor expanded in y around inf
lower-*.f6432.9
Simplified32.9%
herbie shell --seed 2024207
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))