
(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
(if (<= x -7e-47)
(* x y)
(if (<= x 1.0)
z
(if (or (<= x 1.4e+85) (and (not (<= x 2.9e+147)) (<= x 3e+175)))
(* x (- z))
(* x y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7e-47) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = z;
} else if ((x <= 1.4e+85) || (!(x <= 2.9e+147) && (x <= 3e+175))) {
tmp = x * -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 <= (-7d-47)) then
tmp = x * y
else if (x <= 1.0d0) then
tmp = z
else if ((x <= 1.4d+85) .or. (.not. (x <= 2.9d+147)) .and. (x <= 3d+175)) then
tmp = x * -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 <= -7e-47) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = z;
} else if ((x <= 1.4e+85) || (!(x <= 2.9e+147) && (x <= 3e+175))) {
tmp = x * -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7e-47: tmp = x * y elif x <= 1.0: tmp = z elif (x <= 1.4e+85) or (not (x <= 2.9e+147) and (x <= 3e+175)): tmp = x * -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7e-47) tmp = Float64(x * y); elseif (x <= 1.0) tmp = z; elseif ((x <= 1.4e+85) || (!(x <= 2.9e+147) && (x <= 3e+175))) tmp = Float64(x * Float64(-z)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7e-47) tmp = x * y; elseif (x <= 1.0) tmp = z; elseif ((x <= 1.4e+85) || (~((x <= 2.9e+147)) && (x <= 3e+175))) tmp = x * -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7e-47], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], z, If[Or[LessEqual[x, 1.4e+85], And[N[Not[LessEqual[x, 2.9e+147]], $MachinePrecision], LessEqual[x, 3e+175]]], N[(x * (-z)), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-47}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{+85} \lor \neg \left(x \leq 2.9 \cdot 10^{+147}\right) \land x \leq 3 \cdot 10^{+175}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -6.9999999999999996e-47 or 1.4e85 < x < 2.8999999999999998e147 or 3.0000000000000002e175 < x Initial program 95.7%
Taylor expanded in y around inf 59.8%
if -6.9999999999999996e-47 < x < 1Initial program 100.0%
Taylor expanded in x around 0 73.7%
if 1 < x < 1.4e85 or 2.8999999999999998e147 < x < 3.0000000000000002e175Initial program 100.0%
Taylor expanded in y around 0 76.4%
Taylor expanded in x around inf 66.4%
associate-*r*66.4%
mul-1-neg66.4%
Simplified66.4%
Final simplification66.7%
(FPCore (x y z)
:precision binary64
(if (or (<= z -8e-90)
(not (or (<= z 3.2e-64) (and (not (<= z 6.6e+46)) (<= z 4.2e+80)))))
(* z (- 1.0 x))
(* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8e-90) || !((z <= 3.2e-64) || (!(z <= 6.6e+46) && (z <= 4.2e+80)))) {
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 ((z <= (-8d-90)) .or. (.not. (z <= 3.2d-64) .or. (.not. (z <= 6.6d+46)) .and. (z <= 4.2d+80))) 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 ((z <= -8e-90) || !((z <= 3.2e-64) || (!(z <= 6.6e+46) && (z <= 4.2e+80)))) {
tmp = z * (1.0 - x);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8e-90) or not ((z <= 3.2e-64) or (not (z <= 6.6e+46) and (z <= 4.2e+80))): tmp = z * (1.0 - x) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8e-90) || !((z <= 3.2e-64) || (!(z <= 6.6e+46) && (z <= 4.2e+80)))) 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 ((z <= -8e-90) || ~(((z <= 3.2e-64) || (~((z <= 6.6e+46)) && (z <= 4.2e+80))))) tmp = z * (1.0 - x); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8e-90], N[Not[Or[LessEqual[z, 3.2e-64], And[N[Not[LessEqual[z, 6.6e+46]], $MachinePrecision], LessEqual[z, 4.2e+80]]]], $MachinePrecision]], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{-90} \lor \neg \left(z \leq 3.2 \cdot 10^{-64} \lor \neg \left(z \leq 6.6 \cdot 10^{+46}\right) \land z \leq 4.2 \cdot 10^{+80}\right):\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -7.99999999999999996e-90 or 3.19999999999999975e-64 < z < 6.5999999999999996e46 or 4.20000000000000003e80 < z Initial program 98.5%
Taylor expanded in y around 0 88.4%
if -7.99999999999999996e-90 < z < 3.19999999999999975e-64 or 6.5999999999999996e46 < z < 4.20000000000000003e80Initial program 97.4%
Taylor expanded in y around inf 71.0%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-48) (not (<= x 48000000.0))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-48) || !(x <= 48000000.0)) {
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 <= (-9d-48)) .or. (.not. (x <= 48000000.0d0))) 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 <= -9e-48) || !(x <= 48000000.0)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-48) or not (x <= 48000000.0): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-48) || !(x <= 48000000.0)) 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 <= -9e-48) || ~((x <= 48000000.0))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-48], N[Not[LessEqual[x, 48000000.0]], $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 -9 \cdot 10^{-48} \lor \neg \left(x \leq 48000000\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -8.99999999999999977e-48 or 4.8e7 < x Initial program 96.3%
Taylor expanded in x around inf 97.2%
neg-mul-197.2%
+-commutative97.2%
unsub-neg97.2%
Simplified97.2%
if -8.99999999999999977e-48 < x < 4.8e7Initial program 100.0%
Taylor expanded in y around 0 75.6%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (<= x -4.4e-48) (* x y) (if (<= x 1.3e-30) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.4e-48) {
tmp = x * y;
} else if (x <= 1.3e-30) {
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 <= (-4.4d-48)) then
tmp = x * y
else if (x <= 1.3d-30) 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 <= -4.4e-48) {
tmp = x * y;
} else if (x <= 1.3e-30) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.4e-48: tmp = x * y elif x <= 1.3e-30: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.4e-48) tmp = Float64(x * y); elseif (x <= 1.3e-30) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.4e-48) tmp = x * y; elseif (x <= 1.3e-30) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.4e-48], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.3e-30], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{-48}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-30}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.40000000000000025e-48 or 1.29999999999999993e-30 < x Initial program 96.6%
Taylor expanded in y around inf 53.1%
if -4.40000000000000025e-48 < x < 1.29999999999999993e-30Initial program 100.0%
Taylor expanded in x around 0 76.4%
Final simplification62.9%
(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%
+-commutative98.0%
distribute-rgt-neg-out98.0%
unsub-neg98.0%
distribute-rgt-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 98.0%
Taylor expanded in x around 0 35.9%
Final simplification35.9%
herbie shell --seed 2023228
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))