
(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 (* 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.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
(if (<= x -1.8e-125)
(* x y)
(if (<= x 3.5e-152)
z
(if (<= x 1.95e-115)
(* x y)
(if (<= x 7.8e-7)
z
(if (or (<= x 1e+73) (not (<= x 1.6e+196))) (* x y) (* z (- x))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e-125) {
tmp = x * y;
} else if (x <= 3.5e-152) {
tmp = z;
} else if (x <= 1.95e-115) {
tmp = x * y;
} else if (x <= 7.8e-7) {
tmp = z;
} else if ((x <= 1e+73) || !(x <= 1.6e+196)) {
tmp = x * y;
} else {
tmp = z * -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 <= (-1.8d-125)) then
tmp = x * y
else if (x <= 3.5d-152) then
tmp = z
else if (x <= 1.95d-115) then
tmp = x * y
else if (x <= 7.8d-7) then
tmp = z
else if ((x <= 1d+73) .or. (.not. (x <= 1.6d+196))) then
tmp = x * y
else
tmp = z * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e-125) {
tmp = x * y;
} else if (x <= 3.5e-152) {
tmp = z;
} else if (x <= 1.95e-115) {
tmp = x * y;
} else if (x <= 7.8e-7) {
tmp = z;
} else if ((x <= 1e+73) || !(x <= 1.6e+196)) {
tmp = x * y;
} else {
tmp = z * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.8e-125: tmp = x * y elif x <= 3.5e-152: tmp = z elif x <= 1.95e-115: tmp = x * y elif x <= 7.8e-7: tmp = z elif (x <= 1e+73) or not (x <= 1.6e+196): tmp = x * y else: tmp = z * -x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.8e-125) tmp = Float64(x * y); elseif (x <= 3.5e-152) tmp = z; elseif (x <= 1.95e-115) tmp = Float64(x * y); elseif (x <= 7.8e-7) tmp = z; elseif ((x <= 1e+73) || !(x <= 1.6e+196)) tmp = Float64(x * y); else tmp = Float64(z * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.8e-125) tmp = x * y; elseif (x <= 3.5e-152) tmp = z; elseif (x <= 1.95e-115) tmp = x * y; elseif (x <= 7.8e-7) tmp = z; elseif ((x <= 1e+73) || ~((x <= 1.6e+196))) tmp = x * y; else tmp = z * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.8e-125], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.5e-152], z, If[LessEqual[x, 1.95e-115], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.8e-7], z, If[Or[LessEqual[x, 1e+73], N[Not[LessEqual[x, 1.6e+196]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * (-x)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-125}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-152}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.95 \cdot 10^{-115}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{-7}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 10^{+73} \lor \neg \left(x \leq 1.6 \cdot 10^{+196}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -1.8000000000000001e-125 or 3.5000000000000001e-152 < x < 1.9499999999999999e-115 or 7.80000000000000049e-7 < x < 9.99999999999999983e72 or 1.59999999999999996e196 < x Initial program 97.1%
Taylor expanded in y around inf 66.6%
if -1.8000000000000001e-125 < x < 3.5000000000000001e-152 or 1.9499999999999999e-115 < x < 7.80000000000000049e-7Initial program 100.0%
Taylor expanded in x around 0 80.0%
if 9.99999999999999983e72 < x < 1.59999999999999996e196Initial program 100.0%
Taylor expanded in x around inf 99.9%
neg-mul-199.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 66.7%
mul-1-neg66.7%
*-commutative66.7%
distribute-rgt-neg-in66.7%
Simplified66.7%
Final simplification71.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y z))))
(if (<= x -2.05e-125)
t_0
(if (<= x 1.18e-150)
z
(if (<= x 2.25e-114) (* x y) (if (<= x 9.5e-8) z t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -2.05e-125) {
tmp = t_0;
} else if (x <= 1.18e-150) {
tmp = z;
} else if (x <= 2.25e-114) {
tmp = x * y;
} else if (x <= 9.5e-8) {
tmp = z;
} 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 = x * (y - z)
if (x <= (-2.05d-125)) then
tmp = t_0
else if (x <= 1.18d-150) then
tmp = z
else if (x <= 2.25d-114) then
tmp = x * y
else if (x <= 9.5d-8) then
tmp = z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -2.05e-125) {
tmp = t_0;
} else if (x <= 1.18e-150) {
tmp = z;
} else if (x <= 2.25e-114) {
tmp = x * y;
} else if (x <= 9.5e-8) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -2.05e-125: tmp = t_0 elif x <= 1.18e-150: tmp = z elif x <= 2.25e-114: tmp = x * y elif x <= 9.5e-8: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -2.05e-125) tmp = t_0; elseif (x <= 1.18e-150) tmp = z; elseif (x <= 2.25e-114) tmp = Float64(x * y); elseif (x <= 9.5e-8) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); tmp = 0.0; if (x <= -2.05e-125) tmp = t_0; elseif (x <= 1.18e-150) tmp = z; elseif (x <= 2.25e-114) tmp = x * y; elseif (x <= 9.5e-8) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.05e-125], t$95$0, If[LessEqual[x, 1.18e-150], z, If[LessEqual[x, 2.25e-114], N[(x * y), $MachinePrecision], If[LessEqual[x, 9.5e-8], z, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -2.05 \cdot 10^{-125}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.18 \cdot 10^{-150}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 2.25 \cdot 10^{-114}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-8}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.0499999999999999e-125 or 9.50000000000000036e-8 < x Initial program 97.4%
Taylor expanded in x around inf 94.1%
neg-mul-194.1%
unsub-neg94.1%
Simplified94.1%
if -2.0499999999999999e-125 < x < 1.18e-150 or 2.24999999999999984e-114 < x < 9.50000000000000036e-8Initial program 100.0%
Taylor expanded in x around 0 80.0%
if 1.18e-150 < x < 2.24999999999999984e-114Initial program 100.0%
Taylor expanded in y around inf 100.0%
Final simplification89.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y z))) (t_1 (- z (* z x))))
(if (<= x -1.06e-129)
t_0
(if (<= x 1.18e-150)
t_1
(if (<= x 2.2e-115) (* x y) (if (<= x 0.00022) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double t_1 = z - (z * x);
double tmp;
if (x <= -1.06e-129) {
tmp = t_0;
} else if (x <= 1.18e-150) {
tmp = t_1;
} else if (x <= 2.2e-115) {
tmp = x * y;
} else if (x <= 0.00022) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = x * (y - z)
t_1 = z - (z * x)
if (x <= (-1.06d-129)) then
tmp = t_0
else if (x <= 1.18d-150) then
tmp = t_1
else if (x <= 2.2d-115) then
tmp = x * y
else if (x <= 0.00022d0) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y - z);
double t_1 = z - (z * x);
double tmp;
if (x <= -1.06e-129) {
tmp = t_0;
} else if (x <= 1.18e-150) {
tmp = t_1;
} else if (x <= 2.2e-115) {
tmp = x * y;
} else if (x <= 0.00022) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) t_1 = z - (z * x) tmp = 0 if x <= -1.06e-129: tmp = t_0 elif x <= 1.18e-150: tmp = t_1 elif x <= 2.2e-115: tmp = x * y elif x <= 0.00022: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) t_1 = Float64(z - Float64(z * x)) tmp = 0.0 if (x <= -1.06e-129) tmp = t_0; elseif (x <= 1.18e-150) tmp = t_1; elseif (x <= 2.2e-115) tmp = Float64(x * y); elseif (x <= 0.00022) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); t_1 = z - (z * x); tmp = 0.0; if (x <= -1.06e-129) tmp = t_0; elseif (x <= 1.18e-150) tmp = t_1; elseif (x <= 2.2e-115) tmp = x * y; elseif (x <= 0.00022) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.06e-129], t$95$0, If[LessEqual[x, 1.18e-150], t$95$1, If[LessEqual[x, 2.2e-115], N[(x * y), $MachinePrecision], If[LessEqual[x, 0.00022], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
t_1 := z - z \cdot x\\
\mathbf{if}\;x \leq -1.06 \cdot 10^{-129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.18 \cdot 10^{-150}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-115}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 0.00022:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.0600000000000001e-129 or 2.20000000000000008e-4 < x Initial program 97.4%
Taylor expanded in x around inf 94.7%
neg-mul-194.7%
unsub-neg94.7%
Simplified94.7%
if -1.0600000000000001e-129 < x < 1.18e-150 or 2.1999999999999999e-115 < x < 2.20000000000000008e-4Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 79.9%
*-commutative79.9%
Simplified79.9%
if 1.18e-150 < x < 2.1999999999999999e-115Initial program 100.0%
Taylor expanded in y around inf 100.0%
Final simplification89.3%
(FPCore (x y z)
:precision binary64
(if (or (<= x -2.05e-125)
(not (or (<= x 2.1e-151) (and (not (<= x 1.9e-115)) (<= x 9.2e-8)))))
(* x y)
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.05e-125) || !((x <= 2.1e-151) || (!(x <= 1.9e-115) && (x <= 9.2e-8)))) {
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 <= (-2.05d-125)) .or. (.not. (x <= 2.1d-151) .or. (.not. (x <= 1.9d-115)) .and. (x <= 9.2d-8))) 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 <= -2.05e-125) || !((x <= 2.1e-151) || (!(x <= 1.9e-115) && (x <= 9.2e-8)))) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.05e-125) or not ((x <= 2.1e-151) or (not (x <= 1.9e-115) and (x <= 9.2e-8))): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.05e-125) || !((x <= 2.1e-151) || (!(x <= 1.9e-115) && (x <= 9.2e-8)))) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.05e-125) || ~(((x <= 2.1e-151) || (~((x <= 1.9e-115)) && (x <= 9.2e-8))))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.05e-125], N[Not[Or[LessEqual[x, 2.1e-151], And[N[Not[LessEqual[x, 1.9e-115]], $MachinePrecision], LessEqual[x, 9.2e-8]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{-125} \lor \neg \left(x \leq 2.1 \cdot 10^{-151} \lor \neg \left(x \leq 1.9 \cdot 10^{-115}\right) \land x \leq 9.2 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.0499999999999999e-125 or 2.0999999999999999e-151 < x < 1.89999999999999996e-115 or 9.2000000000000003e-8 < x Initial program 97.5%
Taylor expanded in y around inf 62.9%
if -2.0499999999999999e-125 < x < 2.0999999999999999e-151 or 1.89999999999999996e-115 < x < 9.2000000000000003e-8Initial program 100.0%
Taylor expanded in x around 0 80.0%
Final simplification69.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
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 <= 1.0): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 97.0%
Taylor expanded in x around inf 99.3%
neg-mul-199.3%
unsub-neg99.3%
Simplified99.3%
if -1 < x < 1Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 99.2%
associate-*r*99.2%
neg-mul-199.2%
*-commutative99.2%
Simplified99.2%
Final simplification99.2%
(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 34.0%
Final simplification34.0%
herbie shell --seed 2024041
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))