
(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 10 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 (+ (- 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(d2 - d3) + Float64(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[(d2 - d3), $MachinePrecision] + N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\right)
\end{array}
Initial program 85.1%
associate--l+85.1%
distribute-lft-out--85.9%
distribute-rgt-out--91.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (- (* d1 d3))) (t_1 (* d1 (- d1))))
(if (<= d2 -5.5e+67)
(* d1 d2)
(if (<= d2 -6.5e-193)
t_1
(if (<= d2 -2.3e-274)
t_0
(if (<= d2 -5.2e-305)
t_1
(if (<= d2 1.7e-249)
(* d1 d4)
(if (<= d2 1.18e-191) t_0 (* d1 d4)))))))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = -(d1 * d3);
double t_1 = d1 * -d1;
double tmp;
if (d2 <= -5.5e+67) {
tmp = d1 * d2;
} else if (d2 <= -6.5e-193) {
tmp = t_1;
} else if (d2 <= -2.3e-274) {
tmp = t_0;
} else if (d2 <= -5.2e-305) {
tmp = t_1;
} else if (d2 <= 1.7e-249) {
tmp = d1 * d4;
} else if (d2 <= 1.18e-191) {
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) :: t_1
real(8) :: tmp
t_0 = -(d1 * d3)
t_1 = d1 * -d1
if (d2 <= (-5.5d+67)) then
tmp = d1 * d2
else if (d2 <= (-6.5d-193)) then
tmp = t_1
else if (d2 <= (-2.3d-274)) then
tmp = t_0
else if (d2 <= (-5.2d-305)) then
tmp = t_1
else if (d2 <= 1.7d-249) then
tmp = d1 * d4
else if (d2 <= 1.18d-191) 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 * d3);
double t_1 = d1 * -d1;
double tmp;
if (d2 <= -5.5e+67) {
tmp = d1 * d2;
} else if (d2 <= -6.5e-193) {
tmp = t_1;
} else if (d2 <= -2.3e-274) {
tmp = t_0;
} else if (d2 <= -5.2e-305) {
tmp = t_1;
} else if (d2 <= 1.7e-249) {
tmp = d1 * d4;
} else if (d2 <= 1.18e-191) {
tmp = t_0;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = -(d1 * d3) t_1 = d1 * -d1 tmp = 0 if d2 <= -5.5e+67: tmp = d1 * d2 elif d2 <= -6.5e-193: tmp = t_1 elif d2 <= -2.3e-274: tmp = t_0 elif d2 <= -5.2e-305: tmp = t_1 elif d2 <= 1.7e-249: tmp = d1 * d4 elif d2 <= 1.18e-191: tmp = t_0 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(-Float64(d1 * d3)) t_1 = Float64(d1 * Float64(-d1)) tmp = 0.0 if (d2 <= -5.5e+67) tmp = Float64(d1 * d2); elseif (d2 <= -6.5e-193) tmp = t_1; elseif (d2 <= -2.3e-274) tmp = t_0; elseif (d2 <= -5.2e-305) tmp = t_1; elseif (d2 <= 1.7e-249) tmp = Float64(d1 * d4); elseif (d2 <= 1.18e-191) tmp = t_0; else tmp = Float64(d1 * d4); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = -(d1 * d3); t_1 = d1 * -d1; tmp = 0.0; if (d2 <= -5.5e+67) tmp = d1 * d2; elseif (d2 <= -6.5e-193) tmp = t_1; elseif (d2 <= -2.3e-274) tmp = t_0; elseif (d2 <= -5.2e-305) tmp = t_1; elseif (d2 <= 1.7e-249) tmp = d1 * d4; elseif (d2 <= 1.18e-191) tmp = t_0; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = (-N[(d1 * d3), $MachinePrecision])}, Block[{t$95$1 = N[(d1 * (-d1)), $MachinePrecision]}, If[LessEqual[d2, -5.5e+67], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -6.5e-193], t$95$1, If[LessEqual[d2, -2.3e-274], t$95$0, If[LessEqual[d2, -5.2e-305], t$95$1, If[LessEqual[d2, 1.7e-249], N[(d1 * d4), $MachinePrecision], If[LessEqual[d2, 1.18e-191], t$95$0, N[(d1 * d4), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -d1 \cdot d3\\
t_1 := d1 \cdot \left(-d1\right)\\
\mathbf{if}\;d2 \leq -5.5 \cdot 10^{+67}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq -6.5 \cdot 10^{-193}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d2 \leq -2.3 \cdot 10^{-274}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d2 \leq -5.2 \cdot 10^{-305}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d2 \leq 1.7 \cdot 10^{-249}:\\
\;\;\;\;d1 \cdot d4\\
\mathbf{elif}\;d2 \leq 1.18 \cdot 10^{-191}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d2 < -5.49999999999999968e67Initial program 73.3%
associate--l+73.3%
distribute-lft-out--75.6%
distribute-rgt-out--75.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around inf 64.4%
if -5.49999999999999968e67 < d2 < -6.5000000000000004e-193 or -2.29999999999999996e-274 < d2 < -5.2000000000000003e-305Initial program 85.2%
associate--l+85.2%
distribute-lft-out--85.2%
distribute-rgt-out--95.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around inf 48.4%
unpow248.4%
mul-1-neg48.4%
distribute-rgt-neg-out48.4%
Simplified48.4%
if -6.5000000000000004e-193 < d2 < -2.29999999999999996e-274 or 1.6999999999999999e-249 < d2 < 1.1799999999999999e-191Initial program 90.9%
associate--l+90.9%
distribute-lft-out--90.9%
distribute-rgt-out--95.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around inf 57.8%
associate-*r*57.8%
neg-mul-157.8%
*-commutative57.8%
Simplified57.8%
if -5.2000000000000003e-305 < d2 < 1.6999999999999999e-249 or 1.1799999999999999e-191 < d2 Initial program 88.3%
associate--l+88.3%
distribute-lft-out--89.0%
distribute-rgt-out--93.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d4 around inf 32.8%
Final simplification44.2%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* d1 (- d1))) (t_1 (* d1 (+ d2 d4))))
(if (<= d1 -4.5e+168)
t_0
(if (<= d1 -3e-32)
t_1
(if (<= d1 -2.8e-85) (- (* d1 d3)) (if (<= d1 3.5e+143) t_1 t_0))))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * -d1;
double t_1 = d1 * (d2 + d4);
double tmp;
if (d1 <= -4.5e+168) {
tmp = t_0;
} else if (d1 <= -3e-32) {
tmp = t_1;
} else if (d1 <= -2.8e-85) {
tmp = -(d1 * d3);
} else if (d1 <= 3.5e+143) {
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 * -d1
t_1 = d1 * (d2 + d4)
if (d1 <= (-4.5d+168)) then
tmp = t_0
else if (d1 <= (-3d-32)) then
tmp = t_1
else if (d1 <= (-2.8d-85)) then
tmp = -(d1 * d3)
else if (d1 <= 3.5d+143) 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 * -d1;
double t_1 = d1 * (d2 + d4);
double tmp;
if (d1 <= -4.5e+168) {
tmp = t_0;
} else if (d1 <= -3e-32) {
tmp = t_1;
} else if (d1 <= -2.8e-85) {
tmp = -(d1 * d3);
} else if (d1 <= 3.5e+143) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = d1 * -d1 t_1 = d1 * (d2 + d4) tmp = 0 if d1 <= -4.5e+168: tmp = t_0 elif d1 <= -3e-32: tmp = t_1 elif d1 <= -2.8e-85: tmp = -(d1 * d3) elif d1 <= 3.5e+143: tmp = t_1 else: tmp = t_0 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(d1 * Float64(-d1)) t_1 = Float64(d1 * Float64(d2 + d4)) tmp = 0.0 if (d1 <= -4.5e+168) tmp = t_0; elseif (d1 <= -3e-32) tmp = t_1; elseif (d1 <= -2.8e-85) tmp = Float64(-Float64(d1 * d3)); elseif (d1 <= 3.5e+143) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = d1 * -d1; t_1 = d1 * (d2 + d4); tmp = 0.0; if (d1 <= -4.5e+168) tmp = t_0; elseif (d1 <= -3e-32) tmp = t_1; elseif (d1 <= -2.8e-85) tmp = -(d1 * d3); elseif (d1 <= 3.5e+143) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * (-d1)), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d1, -4.5e+168], t$95$0, If[LessEqual[d1, -3e-32], t$95$1, If[LessEqual[d1, -2.8e-85], (-N[(d1 * d3), $MachinePrecision]), If[LessEqual[d1, 3.5e+143], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := d1 \cdot \left(-d1\right)\\
t_1 := d1 \cdot \left(d2 + d4\right)\\
\mathbf{if}\;d1 \leq -4.5 \cdot 10^{+168}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d1 \leq -3 \cdot 10^{-32}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d1 \leq -2.8 \cdot 10^{-85}:\\
\;\;\;\;-d1 \cdot d3\\
\mathbf{elif}\;d1 \leq 3.5 \cdot 10^{+143}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if d1 < -4.50000000000000012e168 or 3.50000000000000008e143 < d1 Initial program 51.4%
associate--l+51.4%
distribute-lft-out--52.9%
distribute-rgt-out--71.4%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around inf 91.4%
unpow291.4%
mul-1-neg91.4%
distribute-rgt-neg-out91.4%
Simplified91.4%
if -4.50000000000000012e168 < d1 < -3e-32 or -2.80000000000000017e-85 < d1 < 3.50000000000000008e143Initial program 97.7%
associate--l+97.7%
distribute-lft-out--98.2%
distribute-rgt-out--98.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d4 around 0 99.4%
Taylor expanded in d3 around 0 74.6%
fma-def74.6%
*-commutative74.6%
Simplified74.6%
Taylor expanded in d1 around 0 66.1%
if -3e-32 < d1 < -2.80000000000000017e-85Initial program 100.0%
associate--l+100.0%
distribute-lft-out--100.0%
distribute-rgt-out--100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around inf 77.7%
associate-*r*77.7%
neg-mul-177.7%
*-commutative77.7%
Simplified77.7%
Final simplification73.6%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (or (<= d4 1.25e-108) (and (not (<= d4 1.7e-79)) (<= d4 22000000000.0))) (* d1 (- d2 d3)) (* d1 (- d4 d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d4 <= 1.25e-108) || (!(d4 <= 1.7e-79) && (d4 <= 22000000000.0))) {
tmp = d1 * (d2 - d3);
} else {
tmp = d1 * (d4 - d1);
}
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 ((d4 <= 1.25d-108) .or. (.not. (d4 <= 1.7d-79)) .and. (d4 <= 22000000000.0d0)) then
tmp = d1 * (d2 - d3)
else
tmp = d1 * (d4 - d1)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d4 <= 1.25e-108) || (!(d4 <= 1.7e-79) && (d4 <= 22000000000.0))) {
tmp = d1 * (d2 - d3);
} else {
tmp = d1 * (d4 - d1);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if (d4 <= 1.25e-108) or (not (d4 <= 1.7e-79) and (d4 <= 22000000000.0)): tmp = d1 * (d2 - d3) else: tmp = d1 * (d4 - d1) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if ((d4 <= 1.25e-108) || (!(d4 <= 1.7e-79) && (d4 <= 22000000000.0))) tmp = Float64(d1 * Float64(d2 - d3)); else tmp = Float64(d1 * Float64(d4 - d1)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if ((d4 <= 1.25e-108) || (~((d4 <= 1.7e-79)) && (d4 <= 22000000000.0))) tmp = d1 * (d2 - d3); else tmp = d1 * (d4 - d1); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d4, 1.25e-108], And[N[Not[LessEqual[d4, 1.7e-79]], $MachinePrecision], LessEqual[d4, 22000000000.0]]], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 1.25 \cdot 10^{-108} \lor \neg \left(d4 \leq 1.7 \cdot 10^{-79}\right) \land d4 \leq 22000000000:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\
\end{array}
\end{array}
if d4 < 1.25e-108 or 1.69999999999999988e-79 < d4 < 2.2e10Initial program 90.6%
associate--l+90.6%
distribute-lft-out--91.7%
distribute-rgt-out--93.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 80.3%
Taylor expanded in d4 around 0 61.3%
if 1.25e-108 < d4 < 1.69999999999999988e-79 or 2.2e10 < d4 Initial program 72.0%
associate--l+72.0%
distribute-lft-out--72.0%
distribute-rgt-out--84.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around 0 85.9%
Taylor expanded in d3 around 0 74.2%
Final simplification65.1%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.3e+35) (* d1 (- d2 d3)) (* d1 (- d4 (+ d1 d3)))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.3e+35) {
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 <= (-1.3d+35)) 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 <= -1.3e+35) {
tmp = d1 * (d2 - d3);
} else {
tmp = d1 * (d4 - (d1 + d3));
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.3e+35: tmp = d1 * (d2 - d3) else: tmp = d1 * (d4 - (d1 + d3)) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.3e+35) 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 <= -1.3e+35) tmp = d1 * (d2 - d3); else tmp = d1 * (d4 - (d1 + d3)); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.3e+35], 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 -1.3 \cdot 10^{+35}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\\
\end{array}
\end{array}
if d2 < -1.30000000000000003e35Initial program 74.5%
associate--l+74.5%
distribute-lft-out--76.5%
distribute-rgt-out--78.4%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 84.4%
Taylor expanded in d4 around 0 75.4%
if -1.30000000000000003e35 < d2 Initial program 87.8%
associate--l+87.8%
distribute-lft-out--88.3%
distribute-rgt-out--94.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around 0 84.3%
Final simplification82.5%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -8.2e-22) (* d1 (- (+ d2 d4) d3)) (* d1 (- d4 (+ d1 d3)))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -8.2e-22) {
tmp = d1 * ((d2 + d4) - 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 <= (-8.2d-22)) then
tmp = d1 * ((d2 + d4) - 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 <= -8.2e-22) {
tmp = d1 * ((d2 + d4) - d3);
} else {
tmp = d1 * (d4 - (d1 + d3));
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -8.2e-22: tmp = d1 * ((d2 + d4) - d3) else: tmp = d1 * (d4 - (d1 + d3)) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -8.2e-22) tmp = Float64(d1 * Float64(Float64(d2 + d4) - 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 <= -8.2e-22) tmp = d1 * ((d2 + d4) - d3); else tmp = d1 * (d4 - (d1 + d3)); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -8.2e-22], N[(d1 * N[(N[(d2 + d4), $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - N[(d1 + d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -8.2 \cdot 10^{-22}:\\
\;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\\
\end{array}
\end{array}
if d2 < -8.1999999999999999e-22Initial program 78.3%
associate--l+78.3%
distribute-lft-out--80.0%
distribute-rgt-out--81.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 83.6%
if -8.1999999999999999e-22 < d2 Initial program 87.2%
associate--l+87.2%
distribute-lft-out--87.7%
distribute-rgt-out--93.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around 0 84.8%
Final simplification84.5%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -7.5e+67) (* d1 d2) (if (<= d2 -2.3e-305) (* d1 (- d1)) (* d1 d4))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -7.5e+67) {
tmp = d1 * d2;
} else if (d2 <= -2.3e-305) {
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 <= (-7.5d+67)) then
tmp = d1 * d2
else if (d2 <= (-2.3d-305)) 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 <= -7.5e+67) {
tmp = d1 * d2;
} else if (d2 <= -2.3e-305) {
tmp = d1 * -d1;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -7.5e+67: tmp = d1 * d2 elif d2 <= -2.3e-305: tmp = d1 * -d1 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -7.5e+67) tmp = Float64(d1 * d2); elseif (d2 <= -2.3e-305) 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 <= -7.5e+67) tmp = d1 * d2; elseif (d2 <= -2.3e-305) tmp = d1 * -d1; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -7.5e+67], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -2.3e-305], N[(d1 * (-d1)), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -7.5 \cdot 10^{+67}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq -2.3 \cdot 10^{-305}:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d2 < -7.5000000000000005e67Initial program 73.3%
associate--l+73.3%
distribute-lft-out--75.6%
distribute-rgt-out--75.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around inf 64.4%
if -7.5000000000000005e67 < d2 < -2.3e-305Initial program 85.5%
associate--l+85.5%
distribute-lft-out--85.5%
distribute-rgt-out--94.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around inf 46.6%
unpow246.6%
mul-1-neg46.6%
distribute-rgt-neg-out46.6%
Simplified46.6%
if -2.3e-305 < d2 Initial program 88.9%
associate--l+88.9%
distribute-lft-out--89.6%
distribute-rgt-out--94.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d4 around inf 31.9%
Final simplification42.0%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.12e-21) (* d1 (+ d2 d4)) (* d1 (- d4 d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.12e-21) {
tmp = d1 * (d2 + d4);
} else {
tmp = d1 * (d4 - d1);
}
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 <= (-1.12d-21)) then
tmp = d1 * (d2 + d4)
else
tmp = d1 * (d4 - d1)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.12e-21) {
tmp = d1 * (d2 + d4);
} else {
tmp = d1 * (d4 - d1);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.12e-21: tmp = d1 * (d2 + d4) else: tmp = d1 * (d4 - d1) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.12e-21) tmp = Float64(d1 * Float64(d2 + d4)); else tmp = Float64(d1 * Float64(d4 - d1)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -1.12e-21) tmp = d1 * (d2 + d4); else tmp = d1 * (d4 - d1); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.12e-21], N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.12 \cdot 10^{-21}:\\
\;\;\;\;d1 \cdot \left(d2 + d4\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\
\end{array}
\end{array}
if d2 < -1.11999999999999998e-21Initial program 78.3%
associate--l+78.3%
distribute-lft-out--80.0%
distribute-rgt-out--81.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d4 around 0 93.3%
Taylor expanded in d3 around 0 73.0%
fma-def79.7%
*-commutative79.7%
Simplified79.7%
Taylor expanded in d1 around 0 65.1%
if -1.11999999999999998e-21 < d2 Initial program 87.2%
associate--l+87.2%
distribute-lft-out--87.7%
distribute-rgt-out--93.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around 0 84.8%
Taylor expanded in d3 around 0 63.9%
Final simplification64.2%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -2.4e-18) (* d1 d2) (* d1 d4)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -2.4e-18) {
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-18)) 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-18) {
tmp = d1 * d2;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -2.4e-18: tmp = d1 * d2 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -2.4e-18) 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-18) tmp = d1 * d2; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -2.4e-18], N[(d1 * d2), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -2.4 \cdot 10^{-18}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d2 < -2.39999999999999994e-18Initial program 78.3%
associate--l+78.3%
distribute-lft-out--80.0%
distribute-rgt-out--81.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around inf 54.2%
if -2.39999999999999994e-18 < d2 Initial program 87.2%
associate--l+87.2%
distribute-lft-out--87.7%
distribute-rgt-out--93.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d4 around inf 35.8%
Final simplification40.1%
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 d4))
double code(double d1, double d2, double d3, double d4) {
return d1 * d4;
}
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
end function
public static double code(double d1, double d2, double d3, double d4) {
return d1 * d4;
}
def code(d1, d2, d3, d4): return d1 * d4
function code(d1, d2, d3, d4) return Float64(d1 * d4) end
function tmp = code(d1, d2, d3, d4) tmp = d1 * d4; end
code[d1_, d2_, d3_, d4_] := N[(d1 * d4), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot d4
\end{array}
Initial program 85.1%
associate--l+85.1%
distribute-lft-out--85.9%
distribute-rgt-out--91.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d4 around inf 31.7%
Final simplification31.7%
(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 2023178
(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)))