
(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 7 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.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/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
+-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 (<= z -8.5e+52) (* (- 1.0 x) z) (if (<= z 7e-36) (* (- y z) x) (fma (- z) x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.5e+52) {
tmp = (1.0 - x) * z;
} else if (z <= 7e-36) {
tmp = (y - z) * x;
} else {
tmp = fma(-z, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -8.5e+52) tmp = Float64(Float64(1.0 - x) * z); elseif (z <= 7e-36) tmp = Float64(Float64(y - z) * x); else tmp = fma(Float64(-z), x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -8.5e+52], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 7e-36], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[((-z) * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{+52}:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-36}:\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, x, z\right)\\
\end{array}
\end{array}
if z < -8.49999999999999994e52Initial program 94.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6487.8
Applied rewrites87.8%
if -8.49999999999999994e52 < z < 6.9999999999999999e-36Initial program 99.1%
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--.f6483.2
Applied rewrites83.2%
if 6.9999999999999999e-36 < z Initial program 96.3%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6489.4
Applied rewrites89.4%
Applied rewrites89.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 x) z))) (if (<= z -8.5e+52) t_0 (if (<= z 7e-36) (* (- y z) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - x) * z;
double tmp;
if (z <= -8.5e+52) {
tmp = t_0;
} else if (z <= 7e-36) {
tmp = (y - z) * x;
} 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 = (1.0d0 - x) * z
if (z <= (-8.5d+52)) then
tmp = t_0
else if (z <= 7d-36) then
tmp = (y - z) * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 - x) * z;
double tmp;
if (z <= -8.5e+52) {
tmp = t_0;
} else if (z <= 7e-36) {
tmp = (y - z) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - x) * z tmp = 0 if z <= -8.5e+52: tmp = t_0 elif z <= 7e-36: tmp = (y - z) * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - x) * z) tmp = 0.0 if (z <= -8.5e+52) tmp = t_0; elseif (z <= 7e-36) tmp = Float64(Float64(y - z) * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - x) * z; tmp = 0.0; if (z <= -8.5e+52) tmp = t_0; elseif (z <= 7e-36) tmp = (y - z) * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -8.5e+52], t$95$0, If[LessEqual[z, 7e-36], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) \cdot z\\
\mathbf{if}\;z \leq -8.5 \cdot 10^{+52}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-36}:\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8.49999999999999994e52 or 6.9999999999999999e-36 < z Initial program 95.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6488.8
Applied rewrites88.8%
if -8.49999999999999994e52 < z < 6.9999999999999999e-36Initial program 99.1%
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--.f6483.2
Applied rewrites83.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 x) z))) (if (<= z -3.8e-51) t_0 (if (<= z 2.3e-36) (* y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - x) * z;
double tmp;
if (z <= -3.8e-51) {
tmp = t_0;
} else if (z <= 2.3e-36) {
tmp = y * x;
} 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 = (1.0d0 - x) * z
if (z <= (-3.8d-51)) then
tmp = t_0
else if (z <= 2.3d-36) then
tmp = y * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 - x) * z;
double tmp;
if (z <= -3.8e-51) {
tmp = t_0;
} else if (z <= 2.3e-36) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - x) * z tmp = 0 if z <= -3.8e-51: tmp = t_0 elif z <= 2.3e-36: tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - x) * z) tmp = 0.0 if (z <= -3.8e-51) tmp = t_0; elseif (z <= 2.3e-36) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - x) * z; tmp = 0.0; if (z <= -3.8e-51) tmp = t_0; elseif (z <= 2.3e-36) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -3.8e-51], t$95$0, If[LessEqual[z, 2.3e-36], N[(y * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) \cdot z\\
\mathbf{if}\;z \leq -3.8 \cdot 10^{-51}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-36}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.80000000000000003e-51 or 2.29999999999999996e-36 < z Initial program 95.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.4
Applied rewrites83.4%
if -3.80000000000000003e-51 < z < 2.29999999999999996e-36Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6475.6
Applied rewrites75.6%
(FPCore (x y z) :precision binary64 (if (<= x -7.2e-72) (* y x) (if (<= x 1.0) (* 1.0 z) (* (- z) x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e-72) {
tmp = y * x;
} else if (x <= 1.0) {
tmp = 1.0 * z;
} else {
tmp = -z * 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 (x <= (-7.2d-72)) then
tmp = y * x
else if (x <= 1.0d0) then
tmp = 1.0d0 * z
else
tmp = -z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e-72) {
tmp = y * x;
} else if (x <= 1.0) {
tmp = 1.0 * z;
} else {
tmp = -z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.2e-72: tmp = y * x elif x <= 1.0: tmp = 1.0 * z else: tmp = -z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.2e-72) tmp = Float64(y * x); elseif (x <= 1.0) tmp = Float64(1.0 * z); else tmp = Float64(Float64(-z) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.2e-72) tmp = y * x; elseif (x <= 1.0) tmp = 1.0 * z; else tmp = -z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.2e-72], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.0], N[(1.0 * z), $MachinePrecision], N[((-z) * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-72}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot x\\
\end{array}
\end{array}
if x < -7.2e-72Initial program 98.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6458.5
Applied rewrites58.5%
if -7.2e-72 < x < 1Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6472.4
Applied rewrites72.4%
Taylor expanded in x around 0
Applied rewrites71.8%
if 1 < x Initial program 90.3%
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.9
Applied rewrites99.9%
Taylor expanded in z around inf
Applied rewrites62.9%
(FPCore (x y z) :precision binary64 (if (<= x -7.2e-72) (* y x) (if (<= x 7.6e-61) (* 1.0 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e-72) {
tmp = y * x;
} else if (x <= 7.6e-61) {
tmp = 1.0 * z;
} else {
tmp = y * 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 (x <= (-7.2d-72)) then
tmp = y * x
else if (x <= 7.6d-61) then
tmp = 1.0d0 * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e-72) {
tmp = y * x;
} else if (x <= 7.6e-61) {
tmp = 1.0 * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.2e-72: tmp = y * x elif x <= 7.6e-61: tmp = 1.0 * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.2e-72) tmp = Float64(y * x); elseif (x <= 7.6e-61) tmp = Float64(1.0 * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.2e-72) tmp = y * x; elseif (x <= 7.6e-61) tmp = 1.0 * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.2e-72], N[(y * x), $MachinePrecision], If[LessEqual[x, 7.6e-61], N[(1.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-72}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-61}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -7.2e-72 or 7.59999999999999961e-61 < x Initial program 95.5%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6449.8
Applied rewrites49.8%
if -7.2e-72 < x < 7.59999999999999961e-61Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.3
Applied rewrites76.3%
Taylor expanded in x around 0
Applied rewrites76.3%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 97.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6440.3
Applied rewrites40.3%
herbie shell --seed 2024276
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))