
(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 6 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 (- z (* x (- z y))))
double code(double x, double y, double z) {
return z - (x * (z - y));
}
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 * (z - y))
end function
public static double code(double x, double y, double z) {
return z - (x * (z - y));
}
def code(x, y, z): return z - (x * (z - y))
function code(x, y, z) return Float64(z - Float64(x * Float64(z - y))) end
function tmp = code(x, y, z) tmp = z - (x * (z - y)); end
code[x_, y_, z_] := N[(z - N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - x \cdot \left(z - y\right)
\end{array}
Initial program 98.0%
+-commutative98.0%
remove-double-neg98.0%
distribute-rgt-neg-out98.0%
neg-sub098.0%
neg-sub098.0%
*-commutative98.0%
distribute-lft-neg-in98.0%
remove-double-neg98.0%
distribute-rgt-out--98.0%
*-lft-identity98.0%
associate-+l-98.0%
distribute-lft-out--100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -9e+266) (* z (- x)) (if (or (<= x -4.1e-60) (not (<= x 3e-65))) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -9e+266) {
tmp = z * -x;
} else if ((x <= -4.1e-60) || !(x <= 3e-65)) {
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 <= (-9d+266)) then
tmp = z * -x
else if ((x <= (-4.1d-60)) .or. (.not. (x <= 3d-65))) 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 <= -9e+266) {
tmp = z * -x;
} else if ((x <= -4.1e-60) || !(x <= 3e-65)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9e+266: tmp = z * -x elif (x <= -4.1e-60) or not (x <= 3e-65): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9e+266) tmp = Float64(z * Float64(-x)); elseif ((x <= -4.1e-60) || !(x <= 3e-65)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9e+266) tmp = z * -x; elseif ((x <= -4.1e-60) || ~((x <= 3e-65))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9e+266], N[(z * (-x)), $MachinePrecision], If[Or[LessEqual[x, -4.1e-60], N[Not[LessEqual[x, 3e-65]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+266}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;x \leq -4.1 \cdot 10^{-60} \lor \neg \left(x \leq 3 \cdot 10^{-65}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -8.99999999999999999e266Initial program 90.9%
Taylor expanded in x around inf 99.9%
neg-mul-199.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 75.3%
neg-mul-175.3%
*-commutative75.3%
distribute-rgt-neg-in75.3%
Simplified75.3%
if -8.99999999999999999e266 < x < -4.10000000000000013e-60 or 2.99999999999999998e-65 < x Initial program 97.2%
Taylor expanded in y around inf 59.1%
if -4.10000000000000013e-60 < x < 2.99999999999999998e-65Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 84.2%
Final simplification69.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1e-14))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1e-14)) {
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 <= 1d-14))) 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 <= 1e-14)) {
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 <= 1e-14): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1e-14)) 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 <= 1e-14))) 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, 1e-14]], $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 10^{-14}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1 or 9.99999999999999999e-15 < x Initial program 96.0%
Taylor expanded in x around inf 98.2%
neg-mul-198.2%
sub-neg98.2%
Simplified98.2%
if -1 < x < 9.99999999999999999e-15Initial program 100.0%
Taylor expanded in x around 0 98.7%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e-53) (not (<= x 3.6e-65))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-53) || !(x <= 3.6e-65)) {
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 <= (-4.5d-53)) .or. (.not. (x <= 3.6d-65))) 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 <= -4.5e-53) || !(x <= 3.6e-65)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e-53) or not (x <= 3.6e-65): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e-53) || !(x <= 3.6e-65)) 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 <= -4.5e-53) || ~((x <= 3.6e-65))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e-53], N[Not[LessEqual[x, 3.6e-65]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-53} \lor \neg \left(x \leq 3.6 \cdot 10^{-65}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -4.49999999999999985e-53 or 3.5999999999999998e-65 < x Initial program 96.7%
Taylor expanded in x around inf 92.4%
neg-mul-192.4%
sub-neg92.4%
Simplified92.4%
if -4.49999999999999985e-53 < x < 3.5999999999999998e-65Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 84.2%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-53) (not (<= x 5.4e-64))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-53) || !(x <= 5.4e-64)) {
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 <= (-5.8d-53)) .or. (.not. (x <= 5.4d-64))) 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 <= -5.8e-53) || !(x <= 5.4e-64)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-53) or not (x <= 5.4e-64): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-53) || !(x <= 5.4e-64)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e-53) || ~((x <= 5.4e-64))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-53], N[Not[LessEqual[x, 5.4e-64]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-53} \lor \neg \left(x \leq 5.4 \cdot 10^{-64}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.7999999999999996e-53 or 5.39999999999999971e-64 < x Initial program 96.7%
Taylor expanded in y around inf 57.0%
if -5.7999999999999996e-53 < x < 5.39999999999999971e-64Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 84.2%
Final simplification67.9%
(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 77.6%
Taylor expanded in x around 0 38.7%
herbie shell --seed 2024180
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))