
(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 (- 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
(let* ((t_0 (* x (- z))))
(if (<= x -3.8e+134)
(* x y)
(if (<= x -1.55e+114)
t_0
(if (<= x -3.3e-47)
(* x y)
(if (<= x 9e-20)
z
(if (or (<= x 1.4e+22) (not (<= x 8.6e+182))) (* x y) t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (x <= -3.8e+134) {
tmp = x * y;
} else if (x <= -1.55e+114) {
tmp = t_0;
} else if (x <= -3.3e-47) {
tmp = x * y;
} else if (x <= 9e-20) {
tmp = z;
} else if ((x <= 1.4e+22) || !(x <= 8.6e+182)) {
tmp = x * y;
} 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 * -z
if (x <= (-3.8d+134)) then
tmp = x * y
else if (x <= (-1.55d+114)) then
tmp = t_0
else if (x <= (-3.3d-47)) then
tmp = x * y
else if (x <= 9d-20) then
tmp = z
else if ((x <= 1.4d+22) .or. (.not. (x <= 8.6d+182))) then
tmp = x * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (x <= -3.8e+134) {
tmp = x * y;
} else if (x <= -1.55e+114) {
tmp = t_0;
} else if (x <= -3.3e-47) {
tmp = x * y;
} else if (x <= 9e-20) {
tmp = z;
} else if ((x <= 1.4e+22) || !(x <= 8.6e+182)) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if x <= -3.8e+134: tmp = x * y elif x <= -1.55e+114: tmp = t_0 elif x <= -3.3e-47: tmp = x * y elif x <= 9e-20: tmp = z elif (x <= 1.4e+22) or not (x <= 8.6e+182): tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (x <= -3.8e+134) tmp = Float64(x * y); elseif (x <= -1.55e+114) tmp = t_0; elseif (x <= -3.3e-47) tmp = Float64(x * y); elseif (x <= 9e-20) tmp = z; elseif ((x <= 1.4e+22) || !(x <= 8.6e+182)) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (x <= -3.8e+134) tmp = x * y; elseif (x <= -1.55e+114) tmp = t_0; elseif (x <= -3.3e-47) tmp = x * y; elseif (x <= 9e-20) tmp = z; elseif ((x <= 1.4e+22) || ~((x <= 8.6e+182))) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[x, -3.8e+134], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.55e+114], t$95$0, If[LessEqual[x, -3.3e-47], N[(x * y), $MachinePrecision], If[LessEqual[x, 9e-20], z, If[Or[LessEqual[x, 1.4e+22], N[Not[LessEqual[x, 8.6e+182]], $MachinePrecision]], N[(x * y), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;x \leq -3.8 \cdot 10^{+134}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.55 \cdot 10^{+114}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -3.3 \cdot 10^{-47}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-20}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{+22} \lor \neg \left(x \leq 8.6 \cdot 10^{+182}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.79999999999999998e134 or -1.55e114 < x < -3.30000000000000004e-47 or 9.0000000000000003e-20 < x < 1.4e22 or 8.6000000000000003e182 < x Initial program 95.8%
+-commutative95.8%
remove-double-neg95.8%
distribute-rgt-neg-out95.8%
neg-sub095.8%
neg-sub095.8%
*-commutative95.8%
distribute-lft-neg-in95.8%
remove-double-neg95.8%
distribute-rgt-out--95.8%
*-lft-identity95.8%
associate-+l-95.8%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 70.2%
mul-1-neg70.2%
distribute-rgt-neg-out70.2%
Simplified70.2%
Taylor expanded in z around 0 66.0%
if -3.79999999999999998e134 < x < -1.55e114 or 1.4e22 < x < 8.6000000000000003e182Initial 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 73.3%
Taylor expanded in x around inf 73.3%
associate-*r*73.3%
neg-mul-173.3%
*-commutative73.3%
Simplified73.3%
if -3.30000000000000004e-47 < x < 9.0000000000000003e-20Initial 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.3%
Taylor expanded in x around 0 79.3%
Final simplification73.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ z (* x y))) (t_1 (* x (- z))))
(if (<= x -4.3e+132)
t_0
(if (<= x -2.15e+114)
t_1
(if (<= x 65000000000000.0) t_0 (if (<= x 9e+182) t_1 (* x y)))))))
double code(double x, double y, double z) {
double t_0 = z + (x * y);
double t_1 = x * -z;
double tmp;
if (x <= -4.3e+132) {
tmp = t_0;
} else if (x <= -2.15e+114) {
tmp = t_1;
} else if (x <= 65000000000000.0) {
tmp = t_0;
} else if (x <= 9e+182) {
tmp = t_1;
} else {
tmp = 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = z + (x * y)
t_1 = x * -z
if (x <= (-4.3d+132)) then
tmp = t_0
else if (x <= (-2.15d+114)) then
tmp = t_1
else if (x <= 65000000000000.0d0) then
tmp = t_0
else if (x <= 9d+182) then
tmp = t_1
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z + (x * y);
double t_1 = x * -z;
double tmp;
if (x <= -4.3e+132) {
tmp = t_0;
} else if (x <= -2.15e+114) {
tmp = t_1;
} else if (x <= 65000000000000.0) {
tmp = t_0;
} else if (x <= 9e+182) {
tmp = t_1;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): t_0 = z + (x * y) t_1 = x * -z tmp = 0 if x <= -4.3e+132: tmp = t_0 elif x <= -2.15e+114: tmp = t_1 elif x <= 65000000000000.0: tmp = t_0 elif x <= 9e+182: tmp = t_1 else: tmp = x * y return tmp
function code(x, y, z) t_0 = Float64(z + Float64(x * y)) t_1 = Float64(x * Float64(-z)) tmp = 0.0 if (x <= -4.3e+132) tmp = t_0; elseif (x <= -2.15e+114) tmp = t_1; elseif (x <= 65000000000000.0) tmp = t_0; elseif (x <= 9e+182) tmp = t_1; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z + (x * y); t_1 = x * -z; tmp = 0.0; if (x <= -4.3e+132) tmp = t_0; elseif (x <= -2.15e+114) tmp = t_1; elseif (x <= 65000000000000.0) tmp = t_0; elseif (x <= 9e+182) tmp = t_1; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[x, -4.3e+132], t$95$0, If[LessEqual[x, -2.15e+114], t$95$1, If[LessEqual[x, 65000000000000.0], t$95$0, If[LessEqual[x, 9e+182], t$95$1, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z + x \cdot y\\
t_1 := x \cdot \left(-z\right)\\
\mathbf{if}\;x \leq -4.3 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -2.15 \cdot 10^{+114}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 65000000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 9 \cdot 10^{+182}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.29999999999999982e132 or -2.15e114 < x < 6.5e13Initial program 99.5%
+-commutative99.5%
remove-double-neg99.5%
distribute-rgt-neg-out99.5%
neg-sub099.5%
neg-sub099.5%
*-commutative99.5%
distribute-lft-neg-in99.5%
remove-double-neg99.5%
distribute-rgt-out--99.5%
*-lft-identity99.5%
associate-+l-99.5%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 89.0%
mul-1-neg89.0%
distribute-rgt-neg-out89.0%
Simplified89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-out89.0%
remove-double-neg89.0%
Applied egg-rr89.0%
if -4.29999999999999982e132 < x < -2.15e114 or 6.5e13 < x < 9.00000000000000058e182Initial 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 73.3%
Taylor expanded in x around inf 73.3%
associate-*r*73.3%
neg-mul-173.3%
*-commutative73.3%
Simplified73.3%
if 9.00000000000000058e182 < x Initial program 86.4%
+-commutative86.4%
remove-double-neg86.4%
distribute-rgt-neg-out86.4%
neg-sub086.4%
neg-sub086.4%
*-commutative86.4%
distribute-lft-neg-in86.4%
remove-double-neg86.4%
distribute-rgt-out--86.4%
*-lft-identity86.4%
associate-+l-86.4%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 68.5%
mul-1-neg68.5%
distribute-rgt-neg-out68.5%
Simplified68.5%
Taylor expanded in z around 0 68.8%
Final simplification84.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -64.0) (not (<= z 3.7e+71))) (- z (* z x)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -64.0) || !(z <= 3.7e+71)) {
tmp = z - (z * x);
} 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 ((z <= (-64.0d0)) .or. (.not. (z <= 3.7d+71))) then
tmp = z - (z * x)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -64.0) || !(z <= 3.7e+71)) {
tmp = z - (z * x);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -64.0) or not (z <= 3.7e+71): tmp = z - (z * x) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -64.0) || !(z <= 3.7e+71)) tmp = Float64(z - Float64(z * x)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -64.0) || ~((z <= 3.7e+71))) tmp = z - (z * x); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -64.0], N[Not[LessEqual[z, 3.7e+71]], $MachinePrecision]], N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -64 \lor \neg \left(z \leq 3.7 \cdot 10^{+71}\right):\\
\;\;\;\;z - z \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if z < -64 or 3.7e71 < z Initial program 96.4%
+-commutative96.4%
remove-double-neg96.4%
distribute-rgt-neg-out96.4%
neg-sub096.4%
neg-sub096.4%
*-commutative96.4%
distribute-lft-neg-in96.4%
remove-double-neg96.4%
distribute-rgt-out--96.4%
*-lft-identity96.4%
associate-+l-96.4%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 91.1%
if -64 < z < 3.7e71Initial 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 90.0%
mul-1-neg90.0%
distribute-rgt-neg-out90.0%
Simplified90.0%
sub-neg90.0%
+-commutative90.0%
distribute-rgt-neg-out90.0%
remove-double-neg90.0%
Applied egg-rr90.0%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.75e-39) (not (<= x 1.8e-16))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.75e-39) || !(x <= 1.8e-16)) {
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 <= (-1.75d-39)) .or. (.not. (x <= 1.8d-16))) 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 <= -1.75e-39) || !(x <= 1.8e-16)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.75e-39) or not (x <= 1.8e-16): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.75e-39) || !(x <= 1.8e-16)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.75e-39) || ~((x <= 1.8e-16))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.75e-39], N[Not[LessEqual[x, 1.8e-16]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{-39} \lor \neg \left(x \leq 1.8 \cdot 10^{-16}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.75e-39 or 1.79999999999999991e-16 < x Initial program 97.0%
+-commutative97.0%
remove-double-neg97.0%
distribute-rgt-neg-out97.0%
neg-sub097.0%
neg-sub097.0%
*-commutative97.0%
distribute-lft-neg-in97.0%
remove-double-neg97.0%
distribute-rgt-out--97.0%
*-lft-identity97.0%
associate-+l-97.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 58.0%
mul-1-neg58.0%
distribute-rgt-neg-out58.0%
Simplified58.0%
Taylor expanded in z around 0 55.2%
if -1.75e-39 < x < 1.79999999999999991e-16Initial 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.3%
Taylor expanded in x around 0 79.3%
Final simplification66.6%
(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%
+-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%
Taylor expanded in z around inf 62.8%
Taylor expanded in x around 0 40.4%
Final simplification40.4%
herbie shell --seed 2024067
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))