
(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 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 98.0%
sub-neg98.0%
+-commutative98.0%
distribute-lft1-in98.0%
associate-+r+98.0%
+-commutative98.0%
*-commutative98.0%
neg-mul-198.0%
associate-*r*98.0%
*-commutative98.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= x -3.1e+146)
(* x y)
(if (<= x -5.8e+87)
t_0
(if (<= x -27.0)
(* x y)
(if (<= x 3.7e-60)
z
(if (or (<= x 60000000000.0)
(and (not (<= x 5.8e+178)) (<= x 3.35e+271)))
(* x y)
t_0)))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -3.1e+146) {
tmp = x * y;
} else if (x <= -5.8e+87) {
tmp = t_0;
} else if (x <= -27.0) {
tmp = x * y;
} else if (x <= 3.7e-60) {
tmp = z;
} else if ((x <= 60000000000.0) || (!(x <= 5.8e+178) && (x <= 3.35e+271))) {
tmp = x * y;
} 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 <= (-3.1d+146)) then
tmp = x * y
else if (x <= (-5.8d+87)) then
tmp = t_0
else if (x <= (-27.0d0)) then
tmp = x * y
else if (x <= 3.7d-60) then
tmp = z
else if ((x <= 60000000000.0d0) .or. (.not. (x <= 5.8d+178)) .and. (x <= 3.35d+271)) then
tmp = x * y
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 <= -3.1e+146) {
tmp = x * y;
} else if (x <= -5.8e+87) {
tmp = t_0;
} else if (x <= -27.0) {
tmp = x * y;
} else if (x <= 3.7e-60) {
tmp = z;
} else if ((x <= 60000000000.0) || (!(x <= 5.8e+178) && (x <= 3.35e+271))) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if x <= -3.1e+146: tmp = x * y elif x <= -5.8e+87: tmp = t_0 elif x <= -27.0: tmp = x * y elif x <= 3.7e-60: tmp = z elif (x <= 60000000000.0) or (not (x <= 5.8e+178) and (x <= 3.35e+271)): tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (x <= -3.1e+146) tmp = Float64(x * y); elseif (x <= -5.8e+87) tmp = t_0; elseif (x <= -27.0) tmp = Float64(x * y); elseif (x <= 3.7e-60) tmp = z; elseif ((x <= 60000000000.0) || (!(x <= 5.8e+178) && (x <= 3.35e+271))) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (x <= -3.1e+146) tmp = x * y; elseif (x <= -5.8e+87) tmp = t_0; elseif (x <= -27.0) tmp = x * y; elseif (x <= 3.7e-60) tmp = z; elseif ((x <= 60000000000.0) || (~((x <= 5.8e+178)) && (x <= 3.35e+271))) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[x, -3.1e+146], N[(x * y), $MachinePrecision], If[LessEqual[x, -5.8e+87], t$95$0, If[LessEqual[x, -27.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.7e-60], z, If[Or[LessEqual[x, 60000000000.0], And[N[Not[LessEqual[x, 5.8e+178]], $MachinePrecision], LessEqual[x, 3.35e+271]]], N[(x * y), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -3.1 \cdot 10^{+146}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -5.8 \cdot 10^{+87}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -27:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-60}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 60000000000 \lor \neg \left(x \leq 5.8 \cdot 10^{+178}\right) \land x \leq 3.35 \cdot 10^{+271}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -3.1000000000000002e146 or -5.7999999999999996e87 < x < -27 or 3.70000000000000025e-60 < x < 6e10 or 5.8000000000000001e178 < x < 3.35e271Initial program 95.0%
Taylor expanded in y around inf 66.6%
if -3.1000000000000002e146 < x < -5.7999999999999996e87 or 6e10 < x < 5.8000000000000001e178 or 3.35e271 < x Initial program 98.0%
Taylor expanded in y around 0 67.9%
Taylor expanded in x around inf 67.3%
mul-1-neg67.3%
distribute-rgt-neg-out67.3%
Simplified67.3%
if -27 < x < 3.70000000000000025e-60Initial program 100.0%
Taylor expanded in x around 0 75.3%
Final simplification71.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1100000.0)
(* x y)
(if (or (<= y 3.2e+102) (and (not (<= y 1.25e+205)) (<= y 1.16e+227)))
(* z (- 1.0 x))
(* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1100000.0) {
tmp = x * y;
} else if ((y <= 3.2e+102) || (!(y <= 1.25e+205) && (y <= 1.16e+227))) {
tmp = z * (1.0 - x);
} 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 <= (-1100000.0d0)) then
tmp = x * y
else if ((y <= 3.2d+102) .or. (.not. (y <= 1.25d+205)) .and. (y <= 1.16d+227)) then
tmp = z * (1.0d0 - x)
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1100000.0) {
tmp = x * y;
} else if ((y <= 3.2e+102) || (!(y <= 1.25e+205) && (y <= 1.16e+227))) {
tmp = z * (1.0 - x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1100000.0: tmp = x * y elif (y <= 3.2e+102) or (not (y <= 1.25e+205) and (y <= 1.16e+227)): tmp = z * (1.0 - x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1100000.0) tmp = Float64(x * y); elseif ((y <= 3.2e+102) || (!(y <= 1.25e+205) && (y <= 1.16e+227))) tmp = Float64(z * Float64(1.0 - x)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1100000.0) tmp = x * y; elseif ((y <= 3.2e+102) || (~((y <= 1.25e+205)) && (y <= 1.16e+227))) tmp = z * (1.0 - x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1100000.0], N[(x * y), $MachinePrecision], If[Or[LessEqual[y, 3.2e+102], And[N[Not[LessEqual[y, 1.25e+205]], $MachinePrecision], LessEqual[y, 1.16e+227]]], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1100000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{+102} \lor \neg \left(y \leq 1.25 \cdot 10^{+205}\right) \land y \leq 1.16 \cdot 10^{+227}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.1e6 or 3.1999999999999999e102 < y < 1.25e205 or 1.1599999999999999e227 < y Initial program 95.2%
Taylor expanded in y around inf 71.8%
if -1.1e6 < y < 3.1999999999999999e102 or 1.25e205 < y < 1.1599999999999999e227Initial program 100.0%
Taylor expanded in y around 0 83.6%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -28.0) (not (<= x 6.2e-65))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -28.0) || !(x <= 6.2e-65)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - 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 <= (-28.0d0)) .or. (.not. (x <= 6.2d-65))) then
tmp = x * (y - z)
else
tmp = z * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -28.0) || !(x <= 6.2e-65)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -28.0) or not (x <= 6.2e-65): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -28.0) || !(x <= 6.2e-65)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -28.0) || ~((x <= 6.2e-65))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -28.0], N[Not[LessEqual[x, 6.2e-65]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -28 \lor \neg \left(x \leq 6.2 \cdot 10^{-65}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -28 or 6.20000000000000032e-65 < x Initial program 96.1%
Taylor expanded in x around inf 96.1%
neg-mul-196.1%
+-commutative96.1%
unsub-neg96.1%
Simplified96.1%
if -28 < x < 6.20000000000000032e-65Initial program 100.0%
Taylor expanded in y around 0 76.4%
Final simplification86.5%
(FPCore (x y z) :precision binary64 (if (<= x -27.0) (* x y) (if (<= x 2.5e-60) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -27.0) {
tmp = x * y;
} else if (x <= 2.5e-60) {
tmp = 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 (x <= (-27.0d0)) then
tmp = x * y
else if (x <= 2.5d-60) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -27.0) {
tmp = x * y;
} else if (x <= 2.5e-60) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -27.0: tmp = x * y elif x <= 2.5e-60: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -27.0) tmp = Float64(x * y); elseif (x <= 2.5e-60) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -27.0) tmp = x * y; elseif (x <= 2.5e-60) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -27.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.5e-60], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -27:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-60}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -27 or 2.5000000000000001e-60 < x Initial program 96.1%
Taylor expanded in y around inf 54.1%
if -27 < x < 2.5000000000000001e-60Initial program 100.0%
Taylor expanded in x around 0 75.3%
Final simplification64.5%
(FPCore (x y z) :precision binary64 (+ z (* x (- y z))))
double code(double x, double y, double z) {
return z + (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 = z + (x * (y - z))
end function
public static double code(double x, double y, double z) {
return z + (x * (y - z));
}
def code(x, y, z): return z + (x * (y - z))
function code(x, y, z) return Float64(z + Float64(x * Float64(y - z))) end
function tmp = code(x, y, z) tmp = z + (x * (y - z)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y - z\right)
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around 0 98.0%
*-commutative98.0%
neg-mul-198.0%
distribute-lft-in98.0%
*-rgt-identity98.0%
associate-+l+98.0%
distribute-rgt-neg-out98.0%
mul-1-neg98.0%
associate-*r*98.0%
distribute-rgt-in100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 38.9%
Final simplification38.9%
herbie shell --seed 2023229
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))