
(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 (- 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 99.2%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
associate-+r+N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y z) x))) (if (<= x -2.1e-63) t_0 (if (<= x 4e-25) (* 1.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double tmp;
if (x <= -2.1e-63) {
tmp = t_0;
} else if (x <= 4e-25) {
tmp = 1.0 * 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 = (y - z) * x
if (x <= (-2.1d-63)) then
tmp = t_0
else if (x <= 4d-25) then
tmp = 1.0d0 * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double tmp;
if (x <= -2.1e-63) {
tmp = t_0;
} else if (x <= 4e-25) {
tmp = 1.0 * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - z) * x tmp = 0 if x <= -2.1e-63: tmp = t_0 elif x <= 4e-25: tmp = 1.0 * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - z) * x) tmp = 0.0 if (x <= -2.1e-63) tmp = t_0; elseif (x <= 4e-25) tmp = Float64(1.0 * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - z) * x; tmp = 0.0; if (x <= -2.1e-63) tmp = t_0; elseif (x <= 4e-25) tmp = 1.0 * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -2.1e-63], t$95$0, If[LessEqual[x, 4e-25], N[(1.0 * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - z\right) \cdot x\\
\mathbf{if}\;x \leq -2.1 \cdot 10^{-63}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4 \cdot 10^{-25}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.1e-63 or 4.00000000000000015e-25 < x Initial program 98.4%
Taylor expanded in x around inf
*-commutativeN/A
remove-double-negN/A
mul-1-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--.f6494.3
Applied rewrites94.3%
if -2.1e-63 < x < 4.00000000000000015e-25Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6484.1
Applied rewrites84.1%
Taylor expanded in x around 0
Applied rewrites84.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z) x))) (if (<= x -0.018) t_0 (if (<= x 6.5) (* 1.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -0.018) {
tmp = t_0;
} else if (x <= 6.5) {
tmp = 1.0 * 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 = -z * x
if (x <= (-0.018d0)) then
tmp = t_0
else if (x <= 6.5d0) then
tmp = 1.0d0 * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -0.018) {
tmp = t_0;
} else if (x <= 6.5) {
tmp = 1.0 * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if x <= -0.018: tmp = t_0 elif x <= 6.5: tmp = 1.0 * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (x <= -0.018) tmp = t_0; elseif (x <= 6.5) tmp = Float64(1.0 * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * x; tmp = 0.0; if (x <= -0.018) tmp = t_0; elseif (x <= 6.5) tmp = 1.0 * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[x, -0.018], t$95$0, If[LessEqual[x, 6.5], N[(1.0 * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;x \leq -0.018:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 6.5:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.0179999999999999986 or 6.5 < x Initial program 98.3%
Taylor expanded in x around inf
*-commutativeN/A
remove-double-negN/A
mul-1-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%
Taylor expanded in y around 0
Applied rewrites57.2%
if -0.0179999999999999986 < x < 6.5Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6478.9
Applied rewrites78.9%
Taylor expanded in x around 0
Applied rewrites78.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 99.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6469.4
Applied rewrites69.4%
(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 99.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6469.4
Applied rewrites69.4%
Taylor expanded in x around 0
Applied rewrites44.2%
herbie shell --seed 2024308
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))