
(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 96.8%
sub-neg96.8%
+-commutative96.8%
distribute-lft1-in96.8%
associate-+r+96.8%
+-commutative96.8%
distribute-lft-neg-out96.8%
distribute-rgt-neg-out96.8%
distribute-lft-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= x -2.6e+279)
(* x y)
(if (<= x -3.05e+65)
t_0
(if (<= x -1.05e-72)
(* x y)
(if (<= x 5.6e-27)
z
(if (or (<= x 8.2e+77) (not (<= x 1.18e+125))) (* x y) t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (x <= -2.6e+279) {
tmp = x * y;
} else if (x <= -3.05e+65) {
tmp = t_0;
} else if (x <= -1.05e-72) {
tmp = x * y;
} else if (x <= 5.6e-27) {
tmp = z;
} else if ((x <= 8.2e+77) || !(x <= 1.18e+125)) {
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 = x * -z
if (x <= (-2.6d+279)) then
tmp = x * y
else if (x <= (-3.05d+65)) then
tmp = t_0
else if (x <= (-1.05d-72)) then
tmp = x * y
else if (x <= 5.6d-27) then
tmp = z
else if ((x <= 8.2d+77) .or. (.not. (x <= 1.18d+125))) 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 = x * -z;
double tmp;
if (x <= -2.6e+279) {
tmp = x * y;
} else if (x <= -3.05e+65) {
tmp = t_0;
} else if (x <= -1.05e-72) {
tmp = x * y;
} else if (x <= 5.6e-27) {
tmp = z;
} else if ((x <= 8.2e+77) || !(x <= 1.18e+125)) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if x <= -2.6e+279: tmp = x * y elif x <= -3.05e+65: tmp = t_0 elif x <= -1.05e-72: tmp = x * y elif x <= 5.6e-27: tmp = z elif (x <= 8.2e+77) or not (x <= 1.18e+125): tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (x <= -2.6e+279) tmp = Float64(x * y); elseif (x <= -3.05e+65) tmp = t_0; elseif (x <= -1.05e-72) tmp = Float64(x * y); elseif (x <= 5.6e-27) tmp = z; elseif ((x <= 8.2e+77) || !(x <= 1.18e+125)) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (x <= -2.6e+279) tmp = x * y; elseif (x <= -3.05e+65) tmp = t_0; elseif (x <= -1.05e-72) tmp = x * y; elseif (x <= 5.6e-27) tmp = z; elseif ((x <= 8.2e+77) || ~((x <= 1.18e+125))) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[x, -2.6e+279], N[(x * y), $MachinePrecision], If[LessEqual[x, -3.05e+65], t$95$0, If[LessEqual[x, -1.05e-72], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.6e-27], z, If[Or[LessEqual[x, 8.2e+77], N[Not[LessEqual[x, 1.18e+125]], $MachinePrecision]], N[(x * y), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;x \leq -2.6 \cdot 10^{+279}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -3.05 \cdot 10^{+65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.05 \cdot 10^{-72}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-27}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 8.2 \cdot 10^{+77} \lor \neg \left(x \leq 1.18 \cdot 10^{+125}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.6000000000000001e279 or -3.04999999999999982e65 < x < -1.05e-72 or 5.5999999999999999e-27 < x < 8.2000000000000002e77 or 1.1799999999999999e125 < x Initial program 95.3%
Taylor expanded in y around inf 67.9%
if -2.6000000000000001e279 < x < -3.04999999999999982e65 or 8.2000000000000002e77 < x < 1.1799999999999999e125Initial program 93.8%
Taylor expanded in x around inf 100.0%
neg-mul-1100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 68.6%
associate-*r*68.6%
neg-mul-168.6%
*-commutative68.6%
Simplified68.6%
if -1.05e-72 < x < 5.5999999999999999e-27Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 70.2%
Final simplification69.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3700000.0) (not (<= x 5.2e-19))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3700000.0) || !(x <= 5.2e-19)) {
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 <= (-3700000.0d0)) .or. (.not. (x <= 5.2d-19))) 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 <= -3700000.0) || !(x <= 5.2e-19)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3700000.0) or not (x <= 5.2e-19): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3700000.0) || !(x <= 5.2e-19)) 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 <= -3700000.0) || ~((x <= 5.2e-19))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3700000.0], N[Not[LessEqual[x, 5.2e-19]], $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 -3700000 \lor \neg \left(x \leq 5.2 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -3.7e6 or 5.20000000000000026e-19 < x Initial program 94.1%
Taylor expanded in x around inf 99.9%
neg-mul-199.9%
sub-neg99.9%
Simplified99.9%
if -3.7e6 < x < 5.20000000000000026e-19Initial program 99.9%
Taylor expanded in x around 0 99.3%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.7e-73) (not (<= x 7.4e-21))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-73) || !(x <= 7.4e-21)) {
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-73)) .or. (.not. (x <= 7.4d-21))) 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-73) || !(x <= 7.4e-21)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.7e-73) or not (x <= 7.4e-21): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.7e-73) || !(x <= 7.4e-21)) 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-73) || ~((x <= 7.4e-21))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.7e-73], N[Not[LessEqual[x, 7.4e-21]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-73} \lor \neg \left(x \leq 7.4 \cdot 10^{-21}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.69999999999999994e-73 or 7.40000000000000041e-21 < x Initial program 94.7%
Taylor expanded in x around inf 96.3%
neg-mul-196.3%
sub-neg96.3%
Simplified96.3%
if -2.69999999999999994e-73 < x < 7.40000000000000041e-21Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 70.2%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.2e-74) (not (<= x 3.25e-25))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-74) || !(x <= 3.25e-25)) {
tmp = x * y;
} 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 <= (-4.2d-74)) .or. (.not. (x <= 3.25d-25))) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-74) || !(x <= 3.25e-25)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.2e-74) or not (x <= 3.25e-25): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.2e-74) || !(x <= 3.25e-25)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.2e-74) || ~((x <= 3.25e-25))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.2e-74], N[Not[LessEqual[x, 3.25e-25]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-74} \lor \neg \left(x \leq 3.25 \cdot 10^{-25}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -4.2e-74 or 3.25e-25 < x Initial program 94.7%
Taylor expanded in y around inf 55.7%
if -4.2e-74 < x < 3.25e-25Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 70.2%
Final simplification61.6%
(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 96.8%
+-commutative96.8%
remove-double-neg96.8%
distribute-rgt-neg-out96.8%
neg-sub096.8%
neg-sub096.8%
*-commutative96.8%
distribute-lft-neg-in96.8%
remove-double-neg96.8%
distribute-rgt-out--96.8%
*-lft-identity96.8%
associate-+l-96.8%
distribute-lft-out--100.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 96.8%
Taylor expanded in x around 0 75.7%
Taylor expanded in x around 0 32.0%
herbie shell --seed 2024181
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))