
(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 97.6%
*-commutative97.6%
distribute-lft-out--97.6%
*-rgt-identity97.6%
cancel-sign-sub-inv97.6%
+-commutative97.6%
associate-+r+97.6%
*-commutative97.6%
distribute-rgt-out100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -3.7e-48)
(* x y)
(if (<= x 2.5e-28)
z
(if (or (<= x 2.8e+43) (and (not (<= x 1.8e+164)) (<= x 5.8e+241)))
(* x y)
(* x (- z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.7e-48) {
tmp = x * y;
} else if (x <= 2.5e-28) {
tmp = z;
} else if ((x <= 2.8e+43) || (!(x <= 1.8e+164) && (x <= 5.8e+241))) {
tmp = x * y;
} else {
tmp = x * -z;
}
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 <= (-3.7d-48)) then
tmp = x * y
else if (x <= 2.5d-28) then
tmp = z
else if ((x <= 2.8d+43) .or. (.not. (x <= 1.8d+164)) .and. (x <= 5.8d+241)) then
tmp = x * y
else
tmp = x * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.7e-48) {
tmp = x * y;
} else if (x <= 2.5e-28) {
tmp = z;
} else if ((x <= 2.8e+43) || (!(x <= 1.8e+164) && (x <= 5.8e+241))) {
tmp = x * y;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.7e-48: tmp = x * y elif x <= 2.5e-28: tmp = z elif (x <= 2.8e+43) or (not (x <= 1.8e+164) and (x <= 5.8e+241)): tmp = x * y else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.7e-48) tmp = Float64(x * y); elseif (x <= 2.5e-28) tmp = z; elseif ((x <= 2.8e+43) || (!(x <= 1.8e+164) && (x <= 5.8e+241))) tmp = Float64(x * y); else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.7e-48) tmp = x * y; elseif (x <= 2.5e-28) tmp = z; elseif ((x <= 2.8e+43) || (~((x <= 1.8e+164)) && (x <= 5.8e+241))) tmp = x * y; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.7e-48], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.5e-28], z, If[Or[LessEqual[x, 2.8e+43], And[N[Not[LessEqual[x, 1.8e+164]], $MachinePrecision], LessEqual[x, 5.8e+241]]], N[(x * y), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{-48}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-28}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{+43} \lor \neg \left(x \leq 1.8 \cdot 10^{+164}\right) \land x \leq 5.8 \cdot 10^{+241}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -3.6999999999999998e-48 or 2.5000000000000001e-28 < x < 2.80000000000000019e43 or 1.79999999999999995e164 < x < 5.8000000000000004e241Initial program 97.0%
Taylor expanded in y around inf 65.0%
if -3.6999999999999998e-48 < x < 2.5000000000000001e-28Initial program 100.0%
Taylor expanded in x around 0 80.9%
if 2.80000000000000019e43 < x < 1.79999999999999995e164 or 5.8000000000000004e241 < x Initial program 93.0%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 64.1%
mul-1-neg64.1%
distribute-rgt-neg-out64.1%
Simplified64.1%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.7e-48) (not (<= x 3.8e-28))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-48) || !(x <= 3.8e-28)) {
tmp = x * (y - z);
} else {
tmp = z;
}
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 <= (-2.7d-48)) .or. (.not. (x <= 3.8d-28))) then
tmp = x * (y - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-48) || !(x <= 3.8e-28)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.7e-48) or not (x <= 3.8e-28): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.7e-48) || !(x <= 3.8e-28)) tmp = Float64(x * Float64(y - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.7e-48) || ~((x <= 3.8e-28))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.7e-48], N[Not[LessEqual[x, 3.8e-28]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-48} \lor \neg \left(x \leq 3.8 \cdot 10^{-28}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.70000000000000011e-48 or 3.80000000000000009e-28 < x Initial program 95.7%
Taylor expanded in x around inf 97.8%
neg-mul-197.8%
sub-neg97.8%
Simplified97.8%
if -2.70000000000000011e-48 < x < 3.80000000000000009e-28Initial program 100.0%
Taylor expanded in x around 0 80.9%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -112.0) (not (<= x 0.000125))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -112.0) || !(x <= 0.000125)) {
tmp = x * (y - z);
} else {
tmp = z + (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 <= (-112.0d0)) .or. (.not. (x <= 0.000125d0))) then
tmp = x * (y - z)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -112.0) || !(x <= 0.000125)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -112.0) or not (x <= 0.000125): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -112.0) || !(x <= 0.000125)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -112.0) || ~((x <= 0.000125))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -112.0], N[Not[LessEqual[x, 0.000125]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -112 \lor \neg \left(x \leq 0.000125\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -112 or 1.25e-4 < x Initial program 95.4%
Taylor expanded in x around inf 99.5%
neg-mul-199.5%
sub-neg99.5%
Simplified99.5%
if -112 < x < 1.25e-4Initial program 100.0%
*-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
associate-+r+100.0%
*-commutative100.0%
distribute-rgt-out100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 98.9%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.1e-48) (* x y) (if (<= x 3.05e-28) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e-48) {
tmp = x * y;
} else if (x <= 3.05e-28) {
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 <= (-1.1d-48)) then
tmp = x * y
else if (x <= 3.05d-28) 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 <= -1.1e-48) {
tmp = x * y;
} else if (x <= 3.05e-28) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.1e-48: tmp = x * y elif x <= 3.05e-28: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.1e-48) tmp = Float64(x * y); elseif (x <= 3.05e-28) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.1e-48) tmp = x * y; elseif (x <= 3.05e-28) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.1e-48], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.05e-28], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-48}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.05 \cdot 10^{-28}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.10000000000000006e-48 or 3.05e-28 < x Initial program 95.7%
Taylor expanded in y around inf 56.4%
if -1.10000000000000006e-48 < x < 3.05e-28Initial program 100.0%
Taylor expanded in x around 0 80.9%
Final simplification67.3%
(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 97.6%
*-commutative97.6%
distribute-lft-out--97.6%
*-rgt-identity97.6%
cancel-sign-sub-inv97.6%
+-commutative97.6%
associate-+r+97.6%
*-commutative97.6%
distribute-rgt-out100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.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 97.6%
Taylor expanded in x around 0 37.9%
Final simplification37.9%
herbie shell --seed 2023276
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))