
(FPCore (d1 d2 d3 d4) :precision binary64 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4): return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4) return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) end
function tmp = code(d1, d2, d3, d4) tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1); end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (d1 d2 d3 d4) :precision binary64 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4): return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4) return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) end
function tmp = code(d1, d2, d3, d4) tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1); end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\end{array}
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (+ (- (- d4 d3) d1) d2)))
double code(double d1, double d2, double d3, double d4) {
return d1 * (((d4 - d3) - d1) + d2);
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = d1 * (((d4 - d3) - d1) + d2)
end function
public static double code(double d1, double d2, double d3, double d4) {
return d1 * (((d4 - d3) - d1) + d2);
}
def code(d1, d2, d3, d4): return d1 * (((d4 - d3) - d1) + d2)
function code(d1, d2, d3, d4) return Float64(d1 * Float64(Float64(Float64(d4 - d3) - d1) + d2)) end
function tmp = code(d1, d2, d3, d4) tmp = d1 * (((d4 - d3) - d1) + d2); end
code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(N[(d4 - d3), $MachinePrecision] - d1), $MachinePrecision] + d2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) + d2\right)
\end{array}
Initial program 88.3%
associate--l+88.3%
sub-neg88.3%
associate-+l+88.3%
+-commutative88.3%
--rgt-identity88.3%
associate--r-88.3%
associate-+r-88.3%
+-commutative88.3%
*-commutative88.3%
sub-neg88.3%
distribute-lft-out--89.0%
distribute-lft-out--95.3%
neg-sub095.3%
distribute-rgt-neg-out95.3%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* d1 (- d3))) (t_1 (* d1 (+ d4 d2))))
(if (<= d3 -7e+122)
t_0
(if (<= d3 9.5e-105)
t_1
(if (<= d3 3.4) (* d1 (- d1)) (if (<= d3 5.4e+106) t_1 t_0))))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * -d3;
double t_1 = d1 * (d4 + d2);
double tmp;
if (d3 <= -7e+122) {
tmp = t_0;
} else if (d3 <= 9.5e-105) {
tmp = t_1;
} else if (d3 <= 3.4) {
tmp = d1 * -d1;
} else if (d3 <= 5.4e+106) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = d1 * -d3
t_1 = d1 * (d4 + d2)
if (d3 <= (-7d+122)) then
tmp = t_0
else if (d3 <= 9.5d-105) then
tmp = t_1
else if (d3 <= 3.4d0) then
tmp = d1 * -d1
else if (d3 <= 5.4d+106) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * -d3;
double t_1 = d1 * (d4 + d2);
double tmp;
if (d3 <= -7e+122) {
tmp = t_0;
} else if (d3 <= 9.5e-105) {
tmp = t_1;
} else if (d3 <= 3.4) {
tmp = d1 * -d1;
} else if (d3 <= 5.4e+106) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = d1 * -d3 t_1 = d1 * (d4 + d2) tmp = 0 if d3 <= -7e+122: tmp = t_0 elif d3 <= 9.5e-105: tmp = t_1 elif d3 <= 3.4: tmp = d1 * -d1 elif d3 <= 5.4e+106: tmp = t_1 else: tmp = t_0 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(d1 * Float64(-d3)) t_1 = Float64(d1 * Float64(d4 + d2)) tmp = 0.0 if (d3 <= -7e+122) tmp = t_0; elseif (d3 <= 9.5e-105) tmp = t_1; elseif (d3 <= 3.4) tmp = Float64(d1 * Float64(-d1)); elseif (d3 <= 5.4e+106) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = d1 * -d3; t_1 = d1 * (d4 + d2); tmp = 0.0; if (d3 <= -7e+122) tmp = t_0; elseif (d3 <= 9.5e-105) tmp = t_1; elseif (d3 <= 3.4) tmp = d1 * -d1; elseif (d3 <= 5.4e+106) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * (-d3)), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -7e+122], t$95$0, If[LessEqual[d3, 9.5e-105], t$95$1, If[LessEqual[d3, 3.4], N[(d1 * (-d1)), $MachinePrecision], If[LessEqual[d3, 5.4e+106], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := d1 \cdot \left(-d3\right)\\
t_1 := d1 \cdot \left(d4 + d2\right)\\
\mathbf{if}\;d3 \leq -7 \cdot 10^{+122}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d3 \leq 9.5 \cdot 10^{-105}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d3 \leq 3.4:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\
\mathbf{elif}\;d3 \leq 5.4 \cdot 10^{+106}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d3 < -7.00000000000000028e122 or 5.40000000000000012e106 < d3 Initial program 84.1%
associate--l+84.1%
sub-neg84.1%
associate-+l+84.1%
+-commutative84.1%
--rgt-identity84.1%
associate--r-84.1%
associate-+r-84.1%
+-commutative84.1%
*-commutative84.1%
sub-neg84.1%
distribute-lft-out--86.5%
distribute-lft-out--93.9%
neg-sub093.9%
distribute-rgt-neg-out93.9%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d3 around inf 71.3%
associate-*r*71.3%
neg-mul-171.3%
Simplified71.3%
if -7.00000000000000028e122 < d3 < 9.5000000000000002e-105 or 3.39999999999999991 < d3 < 5.40000000000000012e106Initial program 91.3%
associate--l+91.3%
sub-neg91.3%
associate-+l+91.3%
+-commutative91.3%
--rgt-identity91.3%
associate--r-91.3%
associate-+r-91.3%
+-commutative91.3%
*-commutative91.3%
sub-neg91.3%
distribute-lft-out--91.3%
distribute-lft-out--96.0%
neg-sub096.0%
distribute-rgt-neg-out96.0%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d4 around inf 74.9%
if 9.5000000000000002e-105 < d3 < 3.39999999999999991Initial program 84.0%
associate--l+84.0%
sub-neg84.0%
associate-+l+84.0%
+-commutative84.0%
--rgt-identity84.0%
associate--r-84.0%
associate-+r-84.0%
+-commutative84.0%
*-commutative84.0%
sub-neg84.0%
distribute-lft-out--84.0%
distribute-lft-out--96.0%
neg-sub096.0%
distribute-rgt-neg-out96.0%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d1 around inf 66.0%
mul-1-neg66.0%
unpow266.0%
distribute-rgt-neg-out66.0%
Simplified66.0%
Final simplification72.9%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* d1 (- d2 d3))) (t_1 (* d1 (+ d4 d2))))
(if (<= d3 -3.3e-7)
t_0
(if (<= d3 9.5e-105)
t_1
(if (<= d3 3.4) (* d1 (- d1)) (if (<= d3 8e+104) t_1 t_0))))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * (d2 - d3);
double t_1 = d1 * (d4 + d2);
double tmp;
if (d3 <= -3.3e-7) {
tmp = t_0;
} else if (d3 <= 9.5e-105) {
tmp = t_1;
} else if (d3 <= 3.4) {
tmp = d1 * -d1;
} else if (d3 <= 8e+104) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = d1 * (d2 - d3)
t_1 = d1 * (d4 + d2)
if (d3 <= (-3.3d-7)) then
tmp = t_0
else if (d3 <= 9.5d-105) then
tmp = t_1
else if (d3 <= 3.4d0) then
tmp = d1 * -d1
else if (d3 <= 8d+104) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * (d2 - d3);
double t_1 = d1 * (d4 + d2);
double tmp;
if (d3 <= -3.3e-7) {
tmp = t_0;
} else if (d3 <= 9.5e-105) {
tmp = t_1;
} else if (d3 <= 3.4) {
tmp = d1 * -d1;
} else if (d3 <= 8e+104) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = d1 * (d2 - d3) t_1 = d1 * (d4 + d2) tmp = 0 if d3 <= -3.3e-7: tmp = t_0 elif d3 <= 9.5e-105: tmp = t_1 elif d3 <= 3.4: tmp = d1 * -d1 elif d3 <= 8e+104: tmp = t_1 else: tmp = t_0 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(d1 * Float64(d2 - d3)) t_1 = Float64(d1 * Float64(d4 + d2)) tmp = 0.0 if (d3 <= -3.3e-7) tmp = t_0; elseif (d3 <= 9.5e-105) tmp = t_1; elseif (d3 <= 3.4) tmp = Float64(d1 * Float64(-d1)); elseif (d3 <= 8e+104) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = d1 * (d2 - d3); t_1 = d1 * (d4 + d2); tmp = 0.0; if (d3 <= -3.3e-7) tmp = t_0; elseif (d3 <= 9.5e-105) tmp = t_1; elseif (d3 <= 3.4) tmp = d1 * -d1; elseif (d3 <= 8e+104) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -3.3e-7], t$95$0, If[LessEqual[d3, 9.5e-105], t$95$1, If[LessEqual[d3, 3.4], N[(d1 * (-d1)), $MachinePrecision], If[LessEqual[d3, 8e+104], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 - d3\right)\\
t_1 := d1 \cdot \left(d4 + d2\right)\\
\mathbf{if}\;d3 \leq -3.3 \cdot 10^{-7}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d3 \leq 9.5 \cdot 10^{-105}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d3 \leq 3.4:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\
\mathbf{elif}\;d3 \leq 8 \cdot 10^{+104}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d3 < -3.3000000000000002e-7 or 8e104 < d3 Initial program 85.3%
associate--l+85.3%
sub-neg85.3%
associate-+l+85.3%
+-commutative85.3%
--rgt-identity85.3%
associate--r-85.3%
associate-+r-85.3%
+-commutative85.3%
*-commutative85.3%
sub-neg85.3%
distribute-lft-out--87.1%
distribute-lft-out--93.6%
neg-sub093.6%
distribute-rgt-neg-out93.6%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d3 around inf 78.8%
neg-mul-178.8%
Simplified78.8%
Taylor expanded in d1 around 0 78.8%
if -3.3000000000000002e-7 < d3 < 9.5000000000000002e-105 or 3.39999999999999991 < d3 < 8e104Initial program 91.8%
associate--l+91.8%
sub-neg91.8%
associate-+l+91.8%
+-commutative91.8%
--rgt-identity91.8%
associate--r-91.8%
associate-+r-91.8%
+-commutative91.8%
*-commutative91.8%
sub-neg91.8%
distribute-lft-out--91.8%
distribute-lft-out--96.7%
neg-sub096.7%
distribute-rgt-neg-out96.7%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d4 around inf 78.8%
if 9.5000000000000002e-105 < d3 < 3.39999999999999991Initial program 84.0%
associate--l+84.0%
sub-neg84.0%
associate-+l+84.0%
+-commutative84.0%
--rgt-identity84.0%
associate--r-84.0%
associate-+r-84.0%
+-commutative84.0%
*-commutative84.0%
sub-neg84.0%
distribute-lft-out--84.0%
distribute-lft-out--96.0%
neg-sub096.0%
distribute-rgt-neg-out96.0%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d1 around inf 66.0%
mul-1-neg66.0%
unpow266.0%
distribute-rgt-neg-out66.0%
Simplified66.0%
Final simplification77.6%
(FPCore (d1 d2 d3 d4)
:precision binary64
(if (<= d2 -9e+106)
(* d1 d2)
(if (or (<= d2 -2.9e-70) (and (not (<= d2 -8.4e-156)) (<= d2 8.6e-198)))
(* d1 (- d1))
(* d1 d4))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -9e+106) {
tmp = d1 * d2;
} else if ((d2 <= -2.9e-70) || (!(d2 <= -8.4e-156) && (d2 <= 8.6e-198))) {
tmp = d1 * -d1;
} else {
tmp = d1 * d4;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-9d+106)) then
tmp = d1 * d2
else if ((d2 <= (-2.9d-70)) .or. (.not. (d2 <= (-8.4d-156))) .and. (d2 <= 8.6d-198)) then
tmp = d1 * -d1
else
tmp = d1 * d4
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -9e+106) {
tmp = d1 * d2;
} else if ((d2 <= -2.9e-70) || (!(d2 <= -8.4e-156) && (d2 <= 8.6e-198))) {
tmp = d1 * -d1;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -9e+106: tmp = d1 * d2 elif (d2 <= -2.9e-70) or (not (d2 <= -8.4e-156) and (d2 <= 8.6e-198)): tmp = d1 * -d1 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -9e+106) tmp = Float64(d1 * d2); elseif ((d2 <= -2.9e-70) || (!(d2 <= -8.4e-156) && (d2 <= 8.6e-198))) tmp = Float64(d1 * Float64(-d1)); else tmp = Float64(d1 * d4); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -9e+106) tmp = d1 * d2; elseif ((d2 <= -2.9e-70) || (~((d2 <= -8.4e-156)) && (d2 <= 8.6e-198))) tmp = d1 * -d1; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -9e+106], N[(d1 * d2), $MachinePrecision], If[Or[LessEqual[d2, -2.9e-70], And[N[Not[LessEqual[d2, -8.4e-156]], $MachinePrecision], LessEqual[d2, 8.6e-198]]], N[(d1 * (-d1)), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -9 \cdot 10^{+106}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq -2.9 \cdot 10^{-70} \lor \neg \left(d2 \leq -8.4 \cdot 10^{-156}\right) \land d2 \leq 8.6 \cdot 10^{-198}:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d2 < -8.9999999999999994e106Initial program 97.5%
associate--l+97.5%
sub-neg97.5%
associate-+l+97.5%
+-commutative97.5%
--rgt-identity97.5%
associate--r-97.5%
associate-+r-97.5%
+-commutative97.5%
*-commutative97.5%
sub-neg97.5%
distribute-lft-out--97.5%
distribute-lft-out--97.5%
neg-sub097.5%
distribute-rgt-neg-out97.5%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d2 around inf 73.6%
if -8.9999999999999994e106 < d2 < -2.89999999999999971e-70 or -8.40000000000000049e-156 < d2 < 8.6000000000000007e-198Initial program 90.9%
associate--l+90.9%
sub-neg90.9%
associate-+l+90.9%
+-commutative90.9%
--rgt-identity90.9%
associate--r-90.9%
associate-+r-90.9%
+-commutative90.9%
*-commutative90.9%
sub-neg90.9%
distribute-lft-out--90.9%
distribute-lft-out--98.7%
neg-sub098.7%
distribute-rgt-neg-out98.7%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d1 around inf 47.6%
mul-1-neg47.6%
unpow247.6%
distribute-rgt-neg-out47.6%
Simplified47.6%
if -2.89999999999999971e-70 < d2 < -8.40000000000000049e-156 or 8.6000000000000007e-198 < d2 Initial program 84.0%
associate--l+84.0%
sub-neg84.0%
associate-+l+84.0%
+-commutative84.0%
--rgt-identity84.0%
associate--r-84.0%
associate-+r-84.0%
+-commutative84.0%
*-commutative84.0%
sub-neg84.0%
distribute-lft-out--85.5%
distribute-lft-out--92.7%
neg-sub092.7%
distribute-rgt-neg-out92.7%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d4 around inf 31.2%
Final simplification42.9%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* d1 (- d1))))
(if (<= d2 -1.25e+110)
(* d1 d2)
(if (<= d2 -3e-83)
t_0
(if (<= d2 -2.75e-151)
(* d1 (- d3))
(if (<= d2 5.6e-195) t_0 (* d1 d4)))))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * -d1;
double tmp;
if (d2 <= -1.25e+110) {
tmp = d1 * d2;
} else if (d2 <= -3e-83) {
tmp = t_0;
} else if (d2 <= -2.75e-151) {
tmp = d1 * -d3;
} else if (d2 <= 5.6e-195) {
tmp = t_0;
} else {
tmp = d1 * d4;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: t_0
real(8) :: tmp
t_0 = d1 * -d1
if (d2 <= (-1.25d+110)) then
tmp = d1 * d2
else if (d2 <= (-3d-83)) then
tmp = t_0
else if (d2 <= (-2.75d-151)) then
tmp = d1 * -d3
else if (d2 <= 5.6d-195) then
tmp = t_0
else
tmp = d1 * d4
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * -d1;
double tmp;
if (d2 <= -1.25e+110) {
tmp = d1 * d2;
} else if (d2 <= -3e-83) {
tmp = t_0;
} else if (d2 <= -2.75e-151) {
tmp = d1 * -d3;
} else if (d2 <= 5.6e-195) {
tmp = t_0;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = d1 * -d1 tmp = 0 if d2 <= -1.25e+110: tmp = d1 * d2 elif d2 <= -3e-83: tmp = t_0 elif d2 <= -2.75e-151: tmp = d1 * -d3 elif d2 <= 5.6e-195: tmp = t_0 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(d1 * Float64(-d1)) tmp = 0.0 if (d2 <= -1.25e+110) tmp = Float64(d1 * d2); elseif (d2 <= -3e-83) tmp = t_0; elseif (d2 <= -2.75e-151) tmp = Float64(d1 * Float64(-d3)); elseif (d2 <= 5.6e-195) tmp = t_0; else tmp = Float64(d1 * d4); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = d1 * -d1; tmp = 0.0; if (d2 <= -1.25e+110) tmp = d1 * d2; elseif (d2 <= -3e-83) tmp = t_0; elseif (d2 <= -2.75e-151) tmp = d1 * -d3; elseif (d2 <= 5.6e-195) tmp = t_0; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * (-d1)), $MachinePrecision]}, If[LessEqual[d2, -1.25e+110], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -3e-83], t$95$0, If[LessEqual[d2, -2.75e-151], N[(d1 * (-d3)), $MachinePrecision], If[LessEqual[d2, 5.6e-195], t$95$0, N[(d1 * d4), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := d1 \cdot \left(-d1\right)\\
\mathbf{if}\;d2 \leq -1.25 \cdot 10^{+110}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq -3 \cdot 10^{-83}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d2 \leq -2.75 \cdot 10^{-151}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\
\mathbf{elif}\;d2 \leq 5.6 \cdot 10^{-195}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d2 < -1.24999999999999995e110Initial program 97.5%
associate--l+97.5%
sub-neg97.5%
associate-+l+97.5%
+-commutative97.5%
--rgt-identity97.5%
associate--r-97.5%
associate-+r-97.5%
+-commutative97.5%
*-commutative97.5%
sub-neg97.5%
distribute-lft-out--97.5%
distribute-lft-out--97.5%
neg-sub097.5%
distribute-rgt-neg-out97.5%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d2 around inf 73.0%
if -1.24999999999999995e110 < d2 < -3.0000000000000001e-83 or -2.7499999999999999e-151 < d2 < 5.60000000000000007e-195Initial program 89.0%
associate--l+89.0%
sub-neg89.0%
associate-+l+89.0%
+-commutative89.0%
--rgt-identity89.0%
associate--r-89.0%
associate-+r-89.0%
+-commutative89.0%
*-commutative89.0%
sub-neg89.0%
distribute-lft-out--89.0%
distribute-lft-out--98.8%
neg-sub098.8%
distribute-rgt-neg-out98.8%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d1 around inf 48.4%
mul-1-neg48.4%
unpow248.4%
distribute-rgt-neg-out48.4%
Simplified48.4%
if -3.0000000000000001e-83 < d2 < -2.7499999999999999e-151Initial program 100.0%
associate--l+100.0%
sub-neg100.0%
associate-+l+100.0%
+-commutative100.0%
--rgt-identity100.0%
associate--r-100.0%
associate-+r-100.0%
+-commutative100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-out--100.0%
distribute-lft-out--100.0%
neg-sub0100.0%
distribute-rgt-neg-out100.0%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d3 around inf 50.6%
associate-*r*50.6%
neg-mul-150.6%
Simplified50.6%
if 5.60000000000000007e-195 < d2 Initial program 83.7%
associate--l+83.7%
sub-neg83.7%
associate-+l+83.7%
+-commutative83.7%
--rgt-identity83.7%
associate--r-83.7%
associate-+r-83.7%
+-commutative83.7%
*-commutative83.7%
sub-neg83.7%
distribute-lft-out--85.3%
distribute-lft-out--91.9%
neg-sub091.9%
distribute-rgt-neg-out91.9%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d4 around inf 29.9%
Final simplification43.5%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* d1 (- d2 d3))))
(if (<= d3 -5e-7)
t_0
(if (<= d3 1.85e-110)
(* d1 (+ d4 d2))
(if (<= d3 1.5e+88) (* d1 (- d4 d1)) t_0)))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * (d2 - d3);
double tmp;
if (d3 <= -5e-7) {
tmp = t_0;
} else if (d3 <= 1.85e-110) {
tmp = d1 * (d4 + d2);
} else if (d3 <= 1.5e+88) {
tmp = d1 * (d4 - d1);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: t_0
real(8) :: tmp
t_0 = d1 * (d2 - d3)
if (d3 <= (-5d-7)) then
tmp = t_0
else if (d3 <= 1.85d-110) then
tmp = d1 * (d4 + d2)
else if (d3 <= 1.5d+88) then
tmp = d1 * (d4 - d1)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * (d2 - d3);
double tmp;
if (d3 <= -5e-7) {
tmp = t_0;
} else if (d3 <= 1.85e-110) {
tmp = d1 * (d4 + d2);
} else if (d3 <= 1.5e+88) {
tmp = d1 * (d4 - d1);
} else {
tmp = t_0;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = d1 * (d2 - d3) tmp = 0 if d3 <= -5e-7: tmp = t_0 elif d3 <= 1.85e-110: tmp = d1 * (d4 + d2) elif d3 <= 1.5e+88: tmp = d1 * (d4 - d1) else: tmp = t_0 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(d1 * Float64(d2 - d3)) tmp = 0.0 if (d3 <= -5e-7) tmp = t_0; elseif (d3 <= 1.85e-110) tmp = Float64(d1 * Float64(d4 + d2)); elseif (d3 <= 1.5e+88) tmp = Float64(d1 * Float64(d4 - d1)); else tmp = t_0; end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = d1 * (d2 - d3); tmp = 0.0; if (d3 <= -5e-7) tmp = t_0; elseif (d3 <= 1.85e-110) tmp = d1 * (d4 + d2); elseif (d3 <= 1.5e+88) tmp = d1 * (d4 - d1); else tmp = t_0; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -5e-7], t$95$0, If[LessEqual[d3, 1.85e-110], N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 1.5e+88], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 - d3\right)\\
\mathbf{if}\;d3 \leq -5 \cdot 10^{-7}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d3 \leq 1.85 \cdot 10^{-110}:\\
\;\;\;\;d1 \cdot \left(d4 + d2\right)\\
\mathbf{elif}\;d3 \leq 1.5 \cdot 10^{+88}:\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d3 < -4.99999999999999977e-7 or 1.50000000000000003e88 < d3 Initial program 84.9%
associate--l+84.9%
sub-neg84.9%
associate-+l+84.9%
+-commutative84.9%
--rgt-identity84.9%
associate--r-84.9%
associate-+r-84.9%
+-commutative84.9%
*-commutative84.9%
sub-neg84.9%
distribute-lft-out--86.7%
distribute-lft-out--93.8%
neg-sub093.8%
distribute-rgt-neg-out93.8%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d3 around inf 77.1%
neg-mul-177.1%
Simplified77.1%
Taylor expanded in d1 around 0 77.1%
if -4.99999999999999977e-7 < d3 < 1.85000000000000008e-110Initial program 92.2%
associate--l+92.2%
sub-neg92.2%
associate-+l+92.2%
+-commutative92.2%
--rgt-identity92.2%
associate--r-92.2%
associate-+r-92.2%
+-commutative92.2%
*-commutative92.2%
sub-neg92.2%
distribute-lft-out--92.2%
distribute-lft-out--96.1%
neg-sub096.1%
distribute-rgt-neg-out96.1%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d4 around inf 79.4%
if 1.85000000000000008e-110 < d3 < 1.50000000000000003e88Initial program 87.5%
associate--l+87.5%
sub-neg87.5%
associate-+l+87.5%
+-commutative87.5%
--rgt-identity87.5%
associate--r-87.5%
associate-+r-87.5%
+-commutative87.5%
*-commutative87.5%
sub-neg87.5%
distribute-lft-out--87.5%
distribute-lft-out--97.5%
neg-sub097.5%
distribute-rgt-neg-out97.5%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d2 around 0 72.5%
Taylor expanded in d3 around 0 70.2%
Final simplification77.0%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -5.6e+108) (* d1 (- d2 d3)) (* d1 (- d4 (+ d1 d3)))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.6e+108) {
tmp = d1 * (d2 - d3);
} else {
tmp = d1 * (d4 - (d1 + d3));
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-5.6d+108)) then
tmp = d1 * (d2 - d3)
else
tmp = d1 * (d4 - (d1 + d3))
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.6e+108) {
tmp = d1 * (d2 - d3);
} else {
tmp = d1 * (d4 - (d1 + d3));
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -5.6e+108: tmp = d1 * (d2 - d3) else: tmp = d1 * (d4 - (d1 + d3)) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -5.6e+108) tmp = Float64(d1 * Float64(d2 - d3)); else tmp = Float64(d1 * Float64(d4 - Float64(d1 + d3))); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -5.6e+108) tmp = d1 * (d2 - d3); else tmp = d1 * (d4 - (d1 + d3)); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.6e+108], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - N[(d1 + d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.6 \cdot 10^{+108}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\\
\end{array}
\end{array}
if d2 < -5.5999999999999996e108Initial program 97.5%
associate--l+97.5%
sub-neg97.5%
associate-+l+97.5%
+-commutative97.5%
--rgt-identity97.5%
associate--r-97.5%
associate-+r-97.5%
+-commutative97.5%
*-commutative97.5%
sub-neg97.5%
distribute-lft-out--97.5%
distribute-lft-out--97.5%
neg-sub097.5%
distribute-rgt-neg-out97.5%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d3 around inf 82.7%
neg-mul-182.7%
Simplified82.7%
Taylor expanded in d1 around 0 82.7%
if -5.5999999999999996e108 < d2 Initial program 86.6%
associate--l+86.6%
sub-neg86.6%
associate-+l+86.6%
+-commutative86.6%
--rgt-identity86.6%
associate--r-86.6%
associate-+r-86.6%
+-commutative86.6%
*-commutative86.6%
sub-neg86.6%
distribute-lft-out--87.5%
distribute-lft-out--94.9%
neg-sub094.9%
distribute-rgt-neg-out94.9%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d2 around 0 82.7%
Final simplification82.7%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -2.4e+59) (* d1 d2) (* d1 d4)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -2.4e+59) {
tmp = d1 * d2;
} else {
tmp = d1 * d4;
}
return tmp;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-2.4d+59)) then
tmp = d1 * d2
else
tmp = d1 * d4
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -2.4e+59) {
tmp = d1 * d2;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -2.4e+59: tmp = d1 * d2 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -2.4e+59) tmp = Float64(d1 * d2); else tmp = Float64(d1 * d4); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -2.4e+59) tmp = d1 * d2; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -2.4e+59], N[(d1 * d2), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -2.4 \cdot 10^{+59}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d2 < -2.4000000000000002e59Initial program 94.3%
associate--l+94.3%
sub-neg94.3%
associate-+l+94.3%
+-commutative94.3%
--rgt-identity94.3%
associate--r-94.3%
associate-+r-94.3%
+-commutative94.3%
*-commutative94.3%
sub-neg94.3%
distribute-lft-out--94.3%
distribute-lft-out--98.1%
neg-sub098.1%
distribute-rgt-neg-out98.1%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d2 around inf 68.8%
if -2.4000000000000002e59 < d2 Initial program 86.7%
associate--l+86.7%
sub-neg86.7%
associate-+l+86.7%
+-commutative86.7%
--rgt-identity86.7%
associate--r-86.7%
associate-+r-86.7%
+-commutative86.7%
*-commutative86.7%
sub-neg86.7%
distribute-lft-out--87.7%
distribute-lft-out--94.6%
neg-sub094.6%
distribute-rgt-neg-out94.6%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d4 around inf 32.4%
Final simplification40.0%
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 d2))
double code(double d1, double d2, double d3, double d4) {
return d1 * d2;
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = d1 * d2
end function
public static double code(double d1, double d2, double d3, double d4) {
return d1 * d2;
}
def code(d1, d2, d3, d4): return d1 * d2
function code(d1, d2, d3, d4) return Float64(d1 * d2) end
function tmp = code(d1, d2, d3, d4) tmp = d1 * d2; end
code[d1_, d2_, d3_, d4_] := N[(d1 * d2), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot d2
\end{array}
Initial program 88.3%
associate--l+88.3%
sub-neg88.3%
associate-+l+88.3%
+-commutative88.3%
--rgt-identity88.3%
associate--r-88.3%
associate-+r-88.3%
+-commutative88.3%
*-commutative88.3%
sub-neg88.3%
distribute-lft-out--89.0%
distribute-lft-out--95.3%
neg-sub095.3%
distribute-rgt-neg-out95.3%
distribute-lft-out--100.0%
sub-neg100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in d2 around inf 36.0%
Final simplification36.0%
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (- (+ (- d2 d3) d4) d1)))
double code(double d1, double d2, double d3, double d4) {
return d1 * (((d2 - d3) + d4) - d1);
}
real(8) function code(d1, d2, d3, d4)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = d1 * (((d2 - d3) + d4) - d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
return d1 * (((d2 - d3) + d4) - d1);
}
def code(d1, d2, d3, d4): return d1 * (((d2 - d3) + d4) - d1)
function code(d1, d2, d3, d4) return Float64(d1 * Float64(Float64(Float64(d2 - d3) + d4) - d1)) end
function tmp = code(d1, d2, d3, d4) tmp = d1 * (((d2 - d3) + d4) - d1); end
code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(N[(d2 - d3), $MachinePrecision] + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right)
\end{array}
herbie shell --seed 2023293
(FPCore (d1 d2 d3 d4)
:name "FastMath dist4"
:precision binary64
:herbie-target
(* d1 (- (+ (- d2 d3) d4) d1))
(- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))