
(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 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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= x -6.5e+181)
(* y x)
(if (<= x -5.6e+15)
t_0
(if (<= x -5.2e-23)
(* y x)
(if (<= x 4.5e-63)
z
(if (<= x 1.9e-26)
(* y x)
(if (<= x 1.0)
z
(if (or (<= x 3.1e+115)
(and (not (<= x 5e+142)) (<= x 2.6e+220)))
t_0
(* y x))))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -6.5e+181) {
tmp = y * x;
} else if (x <= -5.6e+15) {
tmp = t_0;
} else if (x <= -5.2e-23) {
tmp = y * x;
} else if (x <= 4.5e-63) {
tmp = z;
} else if (x <= 1.9e-26) {
tmp = y * x;
} else if (x <= 1.0) {
tmp = z;
} else if ((x <= 3.1e+115) || (!(x <= 5e+142) && (x <= 2.6e+220))) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = z * -x
if (x <= (-6.5d+181)) then
tmp = y * x
else if (x <= (-5.6d+15)) then
tmp = t_0
else if (x <= (-5.2d-23)) then
tmp = y * x
else if (x <= 4.5d-63) then
tmp = z
else if (x <= 1.9d-26) then
tmp = y * x
else if (x <= 1.0d0) then
tmp = z
else if ((x <= 3.1d+115) .or. (.not. (x <= 5d+142)) .and. (x <= 2.6d+220)) then
tmp = t_0
else
tmp = y * x
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.5e+181) {
tmp = y * x;
} else if (x <= -5.6e+15) {
tmp = t_0;
} else if (x <= -5.2e-23) {
tmp = y * x;
} else if (x <= 4.5e-63) {
tmp = z;
} else if (x <= 1.9e-26) {
tmp = y * x;
} else if (x <= 1.0) {
tmp = z;
} else if ((x <= 3.1e+115) || (!(x <= 5e+142) && (x <= 2.6e+220))) {
tmp = t_0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if x <= -6.5e+181: tmp = y * x elif x <= -5.6e+15: tmp = t_0 elif x <= -5.2e-23: tmp = y * x elif x <= 4.5e-63: tmp = z elif x <= 1.9e-26: tmp = y * x elif x <= 1.0: tmp = z elif (x <= 3.1e+115) or (not (x <= 5e+142) and (x <= 2.6e+220)): tmp = t_0 else: tmp = y * x return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (x <= -6.5e+181) tmp = Float64(y * x); elseif (x <= -5.6e+15) tmp = t_0; elseif (x <= -5.2e-23) tmp = Float64(y * x); elseif (x <= 4.5e-63) tmp = z; elseif (x <= 1.9e-26) tmp = Float64(y * x); elseif (x <= 1.0) tmp = z; elseif ((x <= 3.1e+115) || (!(x <= 5e+142) && (x <= 2.6e+220))) tmp = t_0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (x <= -6.5e+181) tmp = y * x; elseif (x <= -5.6e+15) tmp = t_0; elseif (x <= -5.2e-23) tmp = y * x; elseif (x <= 4.5e-63) tmp = z; elseif (x <= 1.9e-26) tmp = y * x; elseif (x <= 1.0) tmp = z; elseif ((x <= 3.1e+115) || (~((x <= 5e+142)) && (x <= 2.6e+220))) tmp = t_0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[x, -6.5e+181], N[(y * x), $MachinePrecision], If[LessEqual[x, -5.6e+15], t$95$0, If[LessEqual[x, -5.2e-23], N[(y * x), $MachinePrecision], If[LessEqual[x, 4.5e-63], z, If[LessEqual[x, 1.9e-26], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.0], z, If[Or[LessEqual[x, 3.1e+115], And[N[Not[LessEqual[x, 5e+142]], $MachinePrecision], LessEqual[x, 2.6e+220]]], t$95$0, N[(y * x), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -6.5 \cdot 10^{+181}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -5.6 \cdot 10^{+15}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -5.2 \cdot 10^{-23}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-63}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-26}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{+115} \lor \neg \left(x \leq 5 \cdot 10^{+142}\right) \land x \leq 2.6 \cdot 10^{+220}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -6.5e181 or -5.6e15 < x < -5.2e-23 or 4.5e-63 < x < 1.90000000000000007e-26 or 3.10000000000000005e115 < x < 5.0000000000000001e142 or 2.59999999999999994e220 < x Initial program 100.0%
Taylor expanded in y around inf 78.8%
if -6.5e181 < x < -5.6e15 or 1 < x < 3.10000000000000005e115 or 5.0000000000000001e142 < x < 2.59999999999999994e220Initial 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 inf 96.5%
Taylor expanded in y around 0 66.5%
mul-1-neg66.5%
distribute-rgt-neg-out66.5%
Simplified66.5%
if -5.2e-23 < x < 4.5e-63 or 1.90000000000000007e-26 < x < 1Initial program 100.0%
Taylor expanded in x around 0 80.1%
Final simplification76.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- y z) x)))
(if (<= x -1.9e-24)
t_0
(if (<= x 5.6e-64)
z
(if (<= x 1.9e-26)
(* y x)
(if (<= x 10000000.0) (* z (- 1.0 x)) t_0))))))
double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double tmp;
if (x <= -1.9e-24) {
tmp = t_0;
} else if (x <= 5.6e-64) {
tmp = z;
} else if (x <= 1.9e-26) {
tmp = y * x;
} else if (x <= 10000000.0) {
tmp = z * (1.0 - 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 = (y - z) * x
if (x <= (-1.9d-24)) then
tmp = t_0
else if (x <= 5.6d-64) then
tmp = z
else if (x <= 1.9d-26) then
tmp = y * x
else if (x <= 10000000.0d0) then
tmp = z * (1.0d0 - x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double tmp;
if (x <= -1.9e-24) {
tmp = t_0;
} else if (x <= 5.6e-64) {
tmp = z;
} else if (x <= 1.9e-26) {
tmp = y * x;
} else if (x <= 10000000.0) {
tmp = z * (1.0 - x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - z) * x tmp = 0 if x <= -1.9e-24: tmp = t_0 elif x <= 5.6e-64: tmp = z elif x <= 1.9e-26: tmp = y * x elif x <= 10000000.0: tmp = z * (1.0 - x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - z) * x) tmp = 0.0 if (x <= -1.9e-24) tmp = t_0; elseif (x <= 5.6e-64) tmp = z; elseif (x <= 1.9e-26) tmp = Float64(y * x); elseif (x <= 10000000.0) tmp = Float64(z * Float64(1.0 - x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - z) * x; tmp = 0.0; if (x <= -1.9e-24) tmp = t_0; elseif (x <= 5.6e-64) tmp = z; elseif (x <= 1.9e-26) tmp = y * x; elseif (x <= 10000000.0) tmp = z * (1.0 - x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.9e-24], t$95$0, If[LessEqual[x, 5.6e-64], z, If[LessEqual[x, 1.9e-26], N[(y * x), $MachinePrecision], If[LessEqual[x, 10000000.0], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - z\right) \cdot x\\
\mathbf{if}\;x \leq -1.9 \cdot 10^{-24}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-64}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-26}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 10000000:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.90000000000000013e-24 or 1e7 < x Initial 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 inf 99.8%
if -1.90000000000000013e-24 < x < 5.60000000000000008e-64Initial program 100.0%
Taylor expanded in x around 0 80.9%
if 5.60000000000000008e-64 < x < 1.90000000000000007e-26Initial program 100.0%
Taylor expanded in y around inf 88.1%
if 1.90000000000000007e-26 < x < 1e7Initial program 99.8%
Taylor expanded in y around 0 78.7%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -24000000000.0) (not (<= x 1.0))) (* (- y z) x) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -24000000000.0) || !(x <= 1.0)) {
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 <= (-24000000000.0d0)) .or. (.not. (x <= 1.0d0))) 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 <= -24000000000.0) || !(x <= 1.0)) {
tmp = (y - z) * x;
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -24000000000.0) or not (x <= 1.0): tmp = (y - z) * x else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -24000000000.0) || !(x <= 1.0)) 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 <= -24000000000.0) || ~((x <= 1.0))) tmp = (y - z) * x; else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -24000000000.0], N[Not[LessEqual[x, 1.0]], $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 -24000000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if x < -2.4e10 or 1 < x Initial 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 inf 98.1%
if -2.4e10 < x < 1Initial 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 simplification98.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.7e+50) (* y x) (if (<= y 5.2e-75) (* z (- 1.0 x)) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.7e+50) {
tmp = y * x;
} else if (y <= 5.2e-75) {
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 <= (-1.7d+50)) then
tmp = y * x
else if (y <= 5.2d-75) 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 <= -1.7e+50) {
tmp = y * x;
} else if (y <= 5.2e-75) {
tmp = z * (1.0 - x);
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.7e+50: tmp = y * x elif y <= 5.2e-75: tmp = z * (1.0 - x) else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.7e+50) tmp = Float64(y * x); elseif (y <= 5.2e-75) 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 <= -1.7e+50) tmp = y * x; elseif (y <= 5.2e-75) tmp = z * (1.0 - x); else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.7e+50], N[(y * x), $MachinePrecision], If[LessEqual[y, 5.2e-75], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{+50}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-75}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.6999999999999999e50 or 5.2e-75 < y Initial program 100.0%
Taylor expanded in y around inf 71.6%
if -1.6999999999999999e50 < y < 5.2e-75Initial program 100.0%
Taylor expanded in y around 0 88.3%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (<= x -6e-27) (* y x) (if (<= x 3e-62) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6e-27) {
tmp = y * x;
} else if (x <= 3e-62) {
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 (x <= (-6d-27)) then
tmp = y * x
else if (x <= 3d-62) 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 (x <= -6e-27) {
tmp = y * x;
} else if (x <= 3e-62) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6e-27: tmp = y * x elif x <= 3e-62: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6e-27) tmp = Float64(y * x); elseif (x <= 3e-62) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6e-27) tmp = y * x; elseif (x <= 3e-62) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6e-27], N[(y * x), $MachinePrecision], If[LessEqual[x, 3e-62], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-27}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-62}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -6.0000000000000002e-27 or 3.0000000000000001e-62 < x Initial program 100.0%
Taylor expanded in y around inf 55.0%
if -6.0000000000000002e-27 < x < 3.0000000000000001e-62Initial program 100.0%
Taylor expanded in x around 0 80.9%
Final simplification67.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 100.0%
Taylor expanded in x around 0 40.9%
Final simplification40.9%
herbie shell --seed 2023174
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))