
(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 (- y z) x z))
double code(double x, double y, double z) {
return fma((y - z), x, z);
}
function code(x, y, z) return fma(Float64(y - z), x, z) end
code[x_, y_, z_] := N[(N[(y - z), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - z, x, z\right)
\end{array}
Initial program 98.4%
+-commutative98.4%
remove-double-neg98.4%
distribute-rgt-neg-out98.4%
neg-sub098.4%
neg-sub098.4%
*-commutative98.4%
distribute-lft-neg-in98.4%
remove-double-neg98.4%
distribute-rgt-out--98.4%
*-lft-identity98.4%
associate-+l-98.4%
distribute-lft-out--100.0%
Simplified100.0%
sub-neg100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
fma-define100.0%
Applied egg-rr100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= x -6.6e+113)
(* y x)
(if (<= x -1.25e+29)
t_0
(if (<= x -1.45e-49)
(* y x)
(if (<= x 2.65e-40)
z
(if (or (<= x 7e+105) (not (<= x 1.3e+171))) (* y x) t_0)))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -6.6e+113) {
tmp = y * x;
} else if (x <= -1.25e+29) {
tmp = t_0;
} else if (x <= -1.45e-49) {
tmp = y * x;
} else if (x <= 2.65e-40) {
tmp = z;
} else if ((x <= 7e+105) || !(x <= 1.3e+171)) {
tmp = y * x;
} 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 = z * -x
if (x <= (-6.6d+113)) then
tmp = y * x
else if (x <= (-1.25d+29)) then
tmp = t_0
else if (x <= (-1.45d-49)) then
tmp = y * x
else if (x <= 2.65d-40) then
tmp = z
else if ((x <= 7d+105) .or. (.not. (x <= 1.3d+171))) then
tmp = y * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -6.6e+113) {
tmp = y * x;
} else if (x <= -1.25e+29) {
tmp = t_0;
} else if (x <= -1.45e-49) {
tmp = y * x;
} else if (x <= 2.65e-40) {
tmp = z;
} else if ((x <= 7e+105) || !(x <= 1.3e+171)) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if x <= -6.6e+113: tmp = y * x elif x <= -1.25e+29: tmp = t_0 elif x <= -1.45e-49: tmp = y * x elif x <= 2.65e-40: tmp = z elif (x <= 7e+105) or not (x <= 1.3e+171): tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (x <= -6.6e+113) tmp = Float64(y * x); elseif (x <= -1.25e+29) tmp = t_0; elseif (x <= -1.45e-49) tmp = Float64(y * x); elseif (x <= 2.65e-40) tmp = z; elseif ((x <= 7e+105) || !(x <= 1.3e+171)) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (x <= -6.6e+113) tmp = y * x; elseif (x <= -1.25e+29) tmp = t_0; elseif (x <= -1.45e-49) tmp = y * x; elseif (x <= 2.65e-40) tmp = z; elseif ((x <= 7e+105) || ~((x <= 1.3e+171))) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[x, -6.6e+113], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.25e+29], t$95$0, If[LessEqual[x, -1.45e-49], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.65e-40], z, If[Or[LessEqual[x, 7e+105], N[Not[LessEqual[x, 1.3e+171]], $MachinePrecision]], N[(y * x), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -6.6 \cdot 10^{+113}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{+29}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.45 \cdot 10^{-49}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.65 \cdot 10^{-40}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 7 \cdot 10^{+105} \lor \neg \left(x \leq 1.3 \cdot 10^{+171}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -6.6000000000000006e113 or -1.25e29 < x < -1.45e-49 or 2.6500000000000001e-40 < x < 6.99999999999999982e105 or 1.3e171 < x Initial program 97.4%
Taylor expanded in y around inf 62.6%
if -6.6000000000000006e113 < x < -1.25e29 or 6.99999999999999982e105 < x < 1.3e171Initial program 96.6%
Taylor expanded in y around 0 69.8%
Taylor expanded in x around inf 69.8%
mul-1-neg69.8%
distribute-rgt-neg-in69.8%
Simplified69.8%
if -1.45e-49 < x < 2.6500000000000001e-40Initial program 100.0%
Taylor expanded in x around 0 77.1%
Final simplification69.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.5e-50) (not (<= x 3.6e-40))) (* (- y z) x) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e-50) || !(x <= 3.6e-40)) {
tmp = (y - 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 <= (-7.5d-50)) .or. (.not. (x <= 3.6d-40))) then
tmp = (y - 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 <= -7.5e-50) || !(x <= 3.6e-40)) {
tmp = (y - z) * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.5e-50) or not (x <= 3.6e-40): tmp = (y - z) * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.5e-50) || !(x <= 3.6e-40)) tmp = Float64(Float64(y - z) * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.5e-50) || ~((x <= 3.6e-40))) tmp = (y - z) * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e-50], N[Not[LessEqual[x, 3.6e-40]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-50} \lor \neg \left(x \leq 3.6 \cdot 10^{-40}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -7.5e-50 or 3.6e-40 < x Initial program 97.2%
Taylor expanded in x around inf 93.9%
neg-mul-193.9%
sub-neg93.9%
Simplified93.9%
if -7.5e-50 < x < 3.6e-40Initial program 100.0%
Taylor expanded in x around 0 77.1%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -5e-49) (not (<= x 1.7e-15))) (* (- y z) x) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5e-49) || !(x <= 1.7e-15)) {
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 ((x <= (-5d-49)) .or. (.not. (x <= 1.7d-15))) 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 ((x <= -5e-49) || !(x <= 1.7e-15)) {
tmp = (y - z) * x;
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5e-49) or not (x <= 1.7e-15): tmp = (y - z) * x else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5e-49) || !(x <= 1.7e-15)) 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 ((x <= -5e-49) || ~((x <= 1.7e-15))) tmp = (y - z) * x; else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5e-49], N[Not[LessEqual[x, 1.7e-15]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-49} \lor \neg \left(x \leq 1.7 \cdot 10^{-15}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -4.9999999999999999e-49 or 1.7e-15 < x Initial program 97.2%
Taylor expanded in x around inf 95.2%
neg-mul-195.2%
sub-neg95.2%
Simplified95.2%
if -4.9999999999999999e-49 < x < 1.7e-15Initial program 100.0%
Taylor expanded in y around 0 76.2%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-49) (not (<= x 8.2e-41))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-49) || !(x <= 8.2e-41)) {
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 ((x <= (-5.8d-49)) .or. (.not. (x <= 8.2d-41))) 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 ((x <= -5.8e-49) || !(x <= 8.2e-41)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-49) or not (x <= 8.2e-41): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-49) || !(x <= 8.2e-41)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e-49) || ~((x <= 8.2e-41))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-49], N[Not[LessEqual[x, 8.2e-41]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-49} \lor \neg \left(x \leq 8.2 \cdot 10^{-41}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.8e-49 or 8.20000000000000028e-41 < x Initial program 97.2%
Taylor expanded in y around inf 57.6%
if -5.8e-49 < x < 8.20000000000000028e-41Initial program 100.0%
Taylor expanded in x around 0 77.1%
Final simplification66.0%
(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 98.4%
+-commutative98.4%
remove-double-neg98.4%
distribute-rgt-neg-out98.4%
neg-sub098.4%
neg-sub098.4%
*-commutative98.4%
distribute-lft-neg-in98.4%
remove-double-neg98.4%
distribute-rgt-out--98.4%
*-lft-identity98.4%
associate-+l-98.4%
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 98.4%
Taylor expanded in x around 0 37.1%
Final simplification37.1%
herbie shell --seed 2024048
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))