
(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 (+ z (* (- y z) x)))
double code(double x, double y, double z) {
return z + ((y - z) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + ((y - z) * x)
end function
public static double code(double x, double y, double z) {
return z + ((y - z) * x);
}
def code(x, y, z): return z + ((y - z) * x)
function code(x, y, z) return Float64(z + Float64(Float64(y - z) * x)) end
function tmp = code(x, y, z) tmp = z + ((y - z) * x); end
code[x_, y_, z_] := N[(z + N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(y - z\right) \cdot x
\end{array}
Initial program 97.6%
sub-neg97.6%
+-commutative97.6%
distribute-lft1-in97.6%
associate-+r+97.6%
+-commutative97.6%
*-commutative97.6%
neg-mul-197.6%
associate-*r*97.6%
*-commutative97.6%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.85e+56)
(* y x)
(if (<= y -2.9e-44)
z
(if (<= y -4.7e-66)
(* y x)
(if (<= y 6e-139)
z
(if (<= y 9.6e-57) (* z (- x)) (if (<= y 1.2e-41) z (* y x))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e+56) {
tmp = y * x;
} else if (y <= -2.9e-44) {
tmp = z;
} else if (y <= -4.7e-66) {
tmp = y * x;
} else if (y <= 6e-139) {
tmp = z;
} else if (y <= 9.6e-57) {
tmp = z * -x;
} else if (y <= 1.2e-41) {
tmp = z;
} else {
tmp = y * 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 (y <= (-1.85d+56)) then
tmp = y * x
else if (y <= (-2.9d-44)) then
tmp = z
else if (y <= (-4.7d-66)) then
tmp = y * x
else if (y <= 6d-139) then
tmp = z
else if (y <= 9.6d-57) then
tmp = z * -x
else if (y <= 1.2d-41) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e+56) {
tmp = y * x;
} else if (y <= -2.9e-44) {
tmp = z;
} else if (y <= -4.7e-66) {
tmp = y * x;
} else if (y <= 6e-139) {
tmp = z;
} else if (y <= 9.6e-57) {
tmp = z * -x;
} else if (y <= 1.2e-41) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.85e+56: tmp = y * x elif y <= -2.9e-44: tmp = z elif y <= -4.7e-66: tmp = y * x elif y <= 6e-139: tmp = z elif y <= 9.6e-57: tmp = z * -x elif y <= 1.2e-41: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.85e+56) tmp = Float64(y * x); elseif (y <= -2.9e-44) tmp = z; elseif (y <= -4.7e-66) tmp = Float64(y * x); elseif (y <= 6e-139) tmp = z; elseif (y <= 9.6e-57) tmp = Float64(z * Float64(-x)); elseif (y <= 1.2e-41) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.85e+56) tmp = y * x; elseif (y <= -2.9e-44) tmp = z; elseif (y <= -4.7e-66) tmp = y * x; elseif (y <= 6e-139) tmp = z; elseif (y <= 9.6e-57) tmp = z * -x; elseif (y <= 1.2e-41) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.85e+56], N[(y * x), $MachinePrecision], If[LessEqual[y, -2.9e-44], z, If[LessEqual[y, -4.7e-66], N[(y * x), $MachinePrecision], If[LessEqual[y, 6e-139], z, If[LessEqual[y, 9.6e-57], N[(z * (-x)), $MachinePrecision], If[LessEqual[y, 1.2e-41], z, N[(y * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{+56}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.9 \cdot 10^{-44}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -4.7 \cdot 10^{-66}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-139}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 9.6 \cdot 10^{-57}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-41}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.84999999999999998e56 or -2.9000000000000001e-44 < y < -4.6999999999999999e-66 or 1.20000000000000011e-41 < y Initial program 95.6%
Taylor expanded in y around inf 76.4%
if -1.84999999999999998e56 < y < -2.9000000000000001e-44 or -4.6999999999999999e-66 < y < 5.9999999999999998e-139 or 9.60000000000000025e-57 < y < 1.20000000000000011e-41Initial program 100.0%
Taylor expanded in x around 0 54.4%
if 5.9999999999999998e-139 < y < 9.60000000000000025e-57Initial program 99.9%
sub-neg99.9%
+-commutative99.9%
distribute-lft1-in99.9%
associate-+r+99.9%
+-commutative99.9%
*-commutative99.9%
neg-mul-199.9%
associate-*r*99.9%
*-commutative99.9%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 87.4%
Taylor expanded in y around 0 49.6%
mul-1-neg49.6%
distribute-rgt-neg-in49.6%
Simplified49.6%
Final simplification65.7%
(FPCore (x y z)
:precision binary64
(if (<= y -3.3e+55)
(* y x)
(if (<= y -4.8e-46)
z
(if (or (<= y -1.25e-64) (not (<= y 6.5e-129))) (* y x) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.3e+55) {
tmp = y * x;
} else if (y <= -4.8e-46) {
tmp = z;
} else if ((y <= -1.25e-64) || !(y <= 6.5e-129)) {
tmp = y * 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 (y <= (-3.3d+55)) then
tmp = y * x
else if (y <= (-4.8d-46)) then
tmp = z
else if ((y <= (-1.25d-64)) .or. (.not. (y <= 6.5d-129))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.3e+55) {
tmp = y * x;
} else if (y <= -4.8e-46) {
tmp = z;
} else if ((y <= -1.25e-64) || !(y <= 6.5e-129)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.3e+55: tmp = y * x elif y <= -4.8e-46: tmp = z elif (y <= -1.25e-64) or not (y <= 6.5e-129): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.3e+55) tmp = Float64(y * x); elseif (y <= -4.8e-46) tmp = z; elseif ((y <= -1.25e-64) || !(y <= 6.5e-129)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.3e+55) tmp = y * x; elseif (y <= -4.8e-46) tmp = z; elseif ((y <= -1.25e-64) || ~((y <= 6.5e-129))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.3e+55], N[(y * x), $MachinePrecision], If[LessEqual[y, -4.8e-46], z, If[Or[LessEqual[y, -1.25e-64], N[Not[LessEqual[y, 6.5e-129]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+55}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -4.8 \cdot 10^{-46}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{-64} \lor \neg \left(y \leq 6.5 \cdot 10^{-129}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.3e55 or -4.80000000000000027e-46 < y < -1.25000000000000008e-64 or 6.49999999999999952e-129 < y Initial program 96.1%
Taylor expanded in y around inf 71.3%
if -3.3e55 < y < -4.80000000000000027e-46 or -1.25000000000000008e-64 < y < 6.49999999999999952e-129Initial program 100.0%
Taylor expanded in x around 0 52.6%
Final simplification63.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.3e+94) (not (<= y 1.55e-187))) (* (- y z) x) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.3e+94) || !(y <= 1.55e-187)) {
tmp = (y - z) * x;
} 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 ((y <= (-2.3d+94)) .or. (.not. (y <= 1.55d-187))) then
tmp = (y - z) * x
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 ((y <= -2.3e+94) || !(y <= 1.55e-187)) {
tmp = (y - z) * x;
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.3e+94) or not (y <= 1.55e-187): tmp = (y - z) * x else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.3e+94) || !(y <= 1.55e-187)) tmp = Float64(Float64(y - z) * x); else tmp = Float64(z * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.3e+94) || ~((y <= 1.55e-187))) tmp = (y - z) * x; else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.3e+94], N[Not[LessEqual[y, 1.55e-187]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+94} \lor \neg \left(y \leq 1.55 \cdot 10^{-187}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -2.3e94 or 1.5500000000000001e-187 < y Initial program 95.6%
sub-neg95.6%
+-commutative95.6%
distribute-lft1-in95.6%
associate-+r+95.6%
+-commutative95.6%
*-commutative95.6%
neg-mul-195.6%
associate-*r*95.6%
*-commutative95.6%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 87.5%
if -2.3e94 < y < 1.5500000000000001e-187Initial program 100.0%
Taylor expanded in y around 0 82.7%
Final simplification85.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.6e+18) (not (<= x 1.2e-10))) (* (- y z) x) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.6e+18) || !(x <= 1.2e-10)) {
tmp = (y - z) * x;
} else {
tmp = z + (y * 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 <= (-4.6d+18)) .or. (.not. (x <= 1.2d-10))) then
tmp = (y - z) * x
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.6e+18) || !(x <= 1.2e-10)) {
tmp = (y - z) * x;
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.6e+18) or not (x <= 1.2e-10): tmp = (y - z) * x else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.6e+18) || !(x <= 1.2e-10)) tmp = Float64(Float64(y - z) * x); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.6e+18) || ~((x <= 1.2e-10))) tmp = (y - z) * x; else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.6e+18], N[Not[LessEqual[x, 1.2e-10]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{+18} \lor \neg \left(x \leq 1.2 \cdot 10^{-10}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if x < -4.6e18 or 1.2e-10 < x Initial program 95.5%
sub-neg95.5%
+-commutative95.5%
distribute-lft1-in95.5%
associate-+r+95.5%
+-commutative95.5%
*-commutative95.5%
neg-mul-195.5%
associate-*r*95.5%
*-commutative95.5%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 99.7%
if -4.6e18 < x < 1.2e-10Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-lft1-in100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.6%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (<= y -7e+94) (* y x) (if (<= y 2e-41) (* z (- 1.0 x)) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7e+94) {
tmp = y * x;
} else if (y <= 2e-41) {
tmp = z * (1.0 - x);
} else {
tmp = y * 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 (y <= (-7d+94)) then
tmp = y * x
else if (y <= 2d-41) then
tmp = z * (1.0d0 - x)
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7e+94) {
tmp = y * x;
} else if (y <= 2e-41) {
tmp = z * (1.0 - x);
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7e+94: tmp = y * x elif y <= 2e-41: tmp = z * (1.0 - x) else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7e+94) tmp = Float64(y * x); elseif (y <= 2e-41) tmp = Float64(z * Float64(1.0 - x)); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7e+94) tmp = y * x; elseif (y <= 2e-41) tmp = z * (1.0 - x); else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7e+94], N[(y * x), $MachinePrecision], If[LessEqual[y, 2e-41], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+94}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-41}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -6.9999999999999994e94 or 2.00000000000000001e-41 < y Initial program 94.6%
Taylor expanded in y around inf 82.7%
if -6.9999999999999994e94 < y < 2.00000000000000001e-41Initial program 100.0%
Taylor expanded in y around 0 79.8%
Final simplification81.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 30.7%
Final simplification30.7%
herbie shell --seed 2023240
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))