
(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 99.2%
sub-neg99.2%
+-commutative99.2%
distribute-lft1-in99.2%
associate-+r+99.2%
+-commutative99.2%
distribute-lft-neg-out99.2%
distribute-rgt-neg-out99.2%
distribute-lft-out100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 4.6e-5))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 4.6e-5)) {
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 <= (-1.0d0)) .or. (.not. (x <= 4.6d-5))) 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 <= -1.0) || !(x <= 4.6e-5)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 4.6e-5): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 4.6e-5)) 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 <= -1.0) || ~((x <= 4.6e-5))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 4.6e-5]], $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 -1 \lor \neg \left(x \leq 4.6 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1 or 4.6e-5 < x Initial program 98.4%
Taylor expanded in x around inf 98.8%
neg-mul-198.8%
sub-neg98.8%
Simplified98.8%
if -1 < x < 4.6e-5Initial program 100.0%
Taylor expanded in x around 0 99.0%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.35e-128) (not (<= x 2e-8))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.35e-128) || !(x <= 2e-8)) {
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 <= (-1.35d-128)) .or. (.not. (x <= 2d-8))) 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 <= -1.35e-128) || !(x <= 2e-8)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.35e-128) or not (x <= 2e-8): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.35e-128) || !(x <= 2e-8)) 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 <= -1.35e-128) || ~((x <= 2e-8))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.35e-128], N[Not[LessEqual[x, 2e-8]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{-128} \lor \neg \left(x \leq 2 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.35000000000000003e-128 or 2e-8 < x Initial program 98.7%
Taylor expanded in x around inf 90.7%
neg-mul-190.7%
sub-neg90.7%
Simplified90.7%
if -1.35000000000000003e-128 < x < 2e-8Initial program 100.0%
Taylor expanded in x around 0 98.8%
Taylor expanded in x around 0 71.4%
Final simplification83.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.00032) (not (<= x 82.0))) (* z (- x)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.00032) || !(x <= 82.0)) {
tmp = z * -x;
} 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 <= (-0.00032d0)) .or. (.not. (x <= 82.0d0))) then
tmp = z * -x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.00032) || !(x <= 82.0)) {
tmp = z * -x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.00032) or not (x <= 82.0): tmp = z * -x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.00032) || !(x <= 82.0)) tmp = Float64(z * Float64(-x)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.00032) || ~((x <= 82.0))) tmp = z * -x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.00032], N[Not[LessEqual[x, 82.0]], $MachinePrecision]], N[(z * (-x)), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00032 \lor \neg \left(x \leq 82\right):\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -3.20000000000000026e-4 or 82 < x Initial program 98.4%
Taylor expanded in x around inf 98.8%
neg-mul-198.8%
sub-neg98.8%
Simplified98.8%
Taylor expanded in y around 0 58.7%
associate-*r*58.7%
neg-mul-158.7%
*-commutative58.7%
Simplified58.7%
if -3.20000000000000026e-4 < x < 82Initial program 100.0%
Taylor expanded in x around 0 99.1%
Taylor expanded in x around 0 65.2%
Final simplification62.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -9e-10) (not (<= y 1.7e-19))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e-10) || !(y <= 1.7e-19)) {
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 ((y <= (-9d-10)) .or. (.not. (y <= 1.7d-19))) 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 ((y <= -9e-10) || !(y <= 1.7e-19)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e-10) or not (y <= 1.7e-19): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e-10) || !(y <= 1.7e-19)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9e-10) || ~((y <= 1.7e-19))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e-10], N[Not[LessEqual[y, 1.7e-19]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-10} \lor \neg \left(y \leq 1.7 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -8.9999999999999999e-10 or 1.7000000000000001e-19 < y Initial program 98.5%
Taylor expanded in y around inf 66.1%
if -8.9999999999999999e-10 < y < 1.7000000000000001e-19Initial program 100.0%
Taylor expanded in x around 0 59.9%
Taylor expanded in x around 0 48.8%
Final simplification57.8%
(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 99.2%
+-commutative99.2%
remove-double-neg99.2%
distribute-rgt-neg-out99.2%
neg-sub099.2%
neg-sub099.2%
*-commutative99.2%
distribute-lft-neg-in99.2%
remove-double-neg99.2%
distribute-rgt-out--99.2%
*-lft-identity99.2%
associate-+l-99.2%
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 99.2%
Taylor expanded in x around 0 72.8%
Taylor expanded in x around 0 34.6%
herbie shell --seed 2024150
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))