
(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 d1) (- d4 d3))))
double code(double d1, double d2, double d3, double d4) {
return d1 * ((d2 - d1) + (d4 - d3));
}
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) + (d4 - d3))
end function
public static double code(double d1, double d2, double d3, double d4) {
return d1 * ((d2 - d1) + (d4 - d3));
}
def code(d1, d2, d3, d4): return d1 * ((d2 - d1) + (d4 - d3))
function code(d1, d2, d3, d4) return Float64(d1 * Float64(Float64(d2 - d1) + Float64(d4 - d3))) end
function tmp = code(d1, d2, d3, d4) tmp = d1 * ((d2 - d1) + (d4 - d3)); end
code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(d2 - d1), $MachinePrecision] + N[(d4 - d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)
\end{array}
Initial program 83.2%
sub-neg83.2%
associate-+l+83.2%
*-commutative83.2%
+-commutative83.2%
*-commutative83.2%
sub-neg83.2%
+-commutative83.2%
associate--l+83.2%
distribute-lft-out--85.1%
distribute-rgt-out--89.4%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (d1 d2 d3 d4)
:precision binary64
(if (<= d2 -3.9e+42)
(* d1 (- d2 d1))
(if (or (<= d2 -2.05e-139) (and (not (<= d2 -8.4e-294)) (<= d2 1.85e-216)))
(* d1 (- d4 d3))
(* d1 (- d4 d1)))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -3.9e+42) {
tmp = d1 * (d2 - d1);
} else if ((d2 <= -2.05e-139) || (!(d2 <= -8.4e-294) && (d2 <= 1.85e-216))) {
tmp = d1 * (d4 - 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 (d2 <= (-3.9d+42)) then
tmp = d1 * (d2 - d1)
else if ((d2 <= (-2.05d-139)) .or. (.not. (d2 <= (-8.4d-294))) .and. (d2 <= 1.85d-216)) then
tmp = d1 * (d4 - 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 (d2 <= -3.9e+42) {
tmp = d1 * (d2 - d1);
} else if ((d2 <= -2.05e-139) || (!(d2 <= -8.4e-294) && (d2 <= 1.85e-216))) {
tmp = d1 * (d4 - d3);
} else {
tmp = d1 * (d4 - d1);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -3.9e+42: tmp = d1 * (d2 - d1) elif (d2 <= -2.05e-139) or (not (d2 <= -8.4e-294) and (d2 <= 1.85e-216)): tmp = d1 * (d4 - d3) else: tmp = d1 * (d4 - d1) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -3.9e+42) tmp = Float64(d1 * Float64(d2 - d1)); elseif ((d2 <= -2.05e-139) || (!(d2 <= -8.4e-294) && (d2 <= 1.85e-216))) tmp = Float64(d1 * Float64(d4 - d3)); else tmp = Float64(d1 * Float64(d4 - d1)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -3.9e+42) tmp = d1 * (d2 - d1); elseif ((d2 <= -2.05e-139) || (~((d2 <= -8.4e-294)) && (d2 <= 1.85e-216))) tmp = d1 * (d4 - d3); else tmp = d1 * (d4 - d1); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -3.9e+42], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[d2, -2.05e-139], And[N[Not[LessEqual[d2, -8.4e-294]], $MachinePrecision], LessEqual[d2, 1.85e-216]]], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -3.9 \cdot 10^{+42}:\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\
\mathbf{elif}\;d2 \leq -2.05 \cdot 10^{-139} \lor \neg \left(d2 \leq -8.4 \cdot 10^{-294}\right) \land d2 \leq 1.85 \cdot 10^{-216}:\\
\;\;\;\;d1 \cdot \left(d4 - d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\
\end{array}
\end{array}
if d2 < -3.8999999999999997e42Initial program 84.3%
sub-neg84.3%
associate-+l+84.3%
*-commutative84.3%
+-commutative84.3%
*-commutative84.3%
sub-neg84.3%
+-commutative84.3%
associate--l+84.3%
distribute-lft-out--86.3%
distribute-rgt-out--98.0%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around 0 92.5%
Taylor expanded in d4 around 0 82.0%
if -3.8999999999999997e42 < d2 < -2.05000000000000007e-139 or -8.39999999999999937e-294 < d2 < 1.84999999999999998e-216Initial program 82.7%
sub-neg82.7%
associate-+l+82.7%
*-commutative82.7%
+-commutative82.7%
*-commutative82.7%
sub-neg82.7%
+-commutative82.7%
associate--l+82.7%
distribute-lft-out--86.5%
distribute-rgt-out--86.5%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d2 around 0 97.1%
+-commutative97.1%
associate--r+97.1%
Simplified97.1%
Taylor expanded in d1 around 0 73.0%
if -2.05000000000000007e-139 < d2 < -8.39999999999999937e-294 or 1.84999999999999998e-216 < d2 Initial program 83.0%
sub-neg83.0%
associate-+l+83.0%
*-commutative83.0%
+-commutative83.0%
*-commutative83.0%
sub-neg83.0%
+-commutative83.0%
associate--l+83.0%
distribute-lft-out--84.3%
distribute-rgt-out--87.5%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around 0 76.9%
Taylor expanded in d2 around 0 59.7%
Final simplification66.9%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* d1 (- d2 d1))) (t_1 (* d1 (+ d2 d4))))
(if (<= d1 -1.25e+53)
t_0
(if (<= d1 -2.85e-154)
t_1
(if (<= d1 -6e-195) (* d1 (- d3)) (if (<= d1 7.2e+121) t_1 t_0))))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * (d2 - d1);
double t_1 = d1 * (d2 + d4);
double tmp;
if (d1 <= -1.25e+53) {
tmp = t_0;
} else if (d1 <= -2.85e-154) {
tmp = t_1;
} else if (d1 <= -6e-195) {
tmp = d1 * -d3;
} else if (d1 <= 7.2e+121) {
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 - d1)
t_1 = d1 * (d2 + d4)
if (d1 <= (-1.25d+53)) then
tmp = t_0
else if (d1 <= (-2.85d-154)) then
tmp = t_1
else if (d1 <= (-6d-195)) then
tmp = d1 * -d3
else if (d1 <= 7.2d+121) 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 - d1);
double t_1 = d1 * (d2 + d4);
double tmp;
if (d1 <= -1.25e+53) {
tmp = t_0;
} else if (d1 <= -2.85e-154) {
tmp = t_1;
} else if (d1 <= -6e-195) {
tmp = d1 * -d3;
} else if (d1 <= 7.2e+121) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = d1 * (d2 - d1) t_1 = d1 * (d2 + d4) tmp = 0 if d1 <= -1.25e+53: tmp = t_0 elif d1 <= -2.85e-154: tmp = t_1 elif d1 <= -6e-195: tmp = d1 * -d3 elif d1 <= 7.2e+121: tmp = t_1 else: tmp = t_0 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(d1 * Float64(d2 - d1)) t_1 = Float64(d1 * Float64(d2 + d4)) tmp = 0.0 if (d1 <= -1.25e+53) tmp = t_0; elseif (d1 <= -2.85e-154) tmp = t_1; elseif (d1 <= -6e-195) tmp = Float64(d1 * Float64(-d3)); elseif (d1 <= 7.2e+121) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = d1 * (d2 - d1); t_1 = d1 * (d2 + d4); tmp = 0.0; if (d1 <= -1.25e+53) tmp = t_0; elseif (d1 <= -2.85e-154) tmp = t_1; elseif (d1 <= -6e-195) tmp = d1 * -d3; elseif (d1 <= 7.2e+121) 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 - d1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d1, -1.25e+53], t$95$0, If[LessEqual[d1, -2.85e-154], t$95$1, If[LessEqual[d1, -6e-195], N[(d1 * (-d3)), $MachinePrecision], If[LessEqual[d1, 7.2e+121], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 - d1\right)\\
t_1 := d1 \cdot \left(d2 + d4\right)\\
\mathbf{if}\;d1 \leq -1.25 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d1 \leq -2.85 \cdot 10^{-154}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d1 \leq -6 \cdot 10^{-195}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\
\mathbf{elif}\;d1 \leq 7.2 \cdot 10^{+121}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d1 < -1.2500000000000001e53 or 7.19999999999999963e121 < d1 Initial program 60.7%
sub-neg60.7%
associate-+l+60.7%
*-commutative60.7%
+-commutative60.7%
*-commutative60.7%
sub-neg60.7%
+-commutative60.7%
associate--l+60.7%
distribute-lft-out--64.5%
distribute-rgt-out--74.8%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around 0 86.4%
Taylor expanded in d4 around 0 77.3%
if -1.2500000000000001e53 < d1 < -2.8499999999999999e-154 or -6e-195 < d1 < 7.19999999999999963e121Initial program 99.3%
sub-neg99.3%
associate-+l+99.3%
*-commutative99.3%
+-commutative99.3%
*-commutative99.3%
sub-neg99.3%
+-commutative99.3%
associate--l+99.3%
distribute-lft-out--100.0%
distribute-rgt-out--100.0%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around 0 75.1%
Taylor expanded in d1 around 0 72.0%
if -2.8499999999999999e-154 < d1 < -6e-195Initial program 100.0%
sub-neg100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
sub-neg100.0%
+-commutative100.0%
associate--l+100.0%
distribute-lft-out--100.0%
distribute-rgt-out--100.0%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around inf 86.6%
mul-1-neg86.6%
distribute-rgt-neg-out86.6%
Simplified86.6%
Final simplification74.6%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (or (<= d3 -1e+180) (not (<= d3 3.2e+167))) (* d1 (- d4 d3)) (* d1 (- (+ d2 d4) d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d3 <= -1e+180) || !(d3 <= 3.2e+167)) {
tmp = d1 * (d4 - d3);
} else {
tmp = d1 * ((d2 + 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 ((d3 <= (-1d+180)) .or. (.not. (d3 <= 3.2d+167))) then
tmp = d1 * (d4 - d3)
else
tmp = d1 * ((d2 + d4) - d1)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d3 <= -1e+180) || !(d3 <= 3.2e+167)) {
tmp = d1 * (d4 - d3);
} else {
tmp = d1 * ((d2 + d4) - d1);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if (d3 <= -1e+180) or not (d3 <= 3.2e+167): tmp = d1 * (d4 - d3) else: tmp = d1 * ((d2 + d4) - d1) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if ((d3 <= -1e+180) || !(d3 <= 3.2e+167)) tmp = Float64(d1 * Float64(d4 - d3)); else tmp = Float64(d1 * Float64(Float64(d2 + d4) - d1)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if ((d3 <= -1e+180) || ~((d3 <= 3.2e+167))) tmp = d1 * (d4 - d3); else tmp = d1 * ((d2 + d4) - d1); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -1e+180], N[Not[LessEqual[d3, 3.2e+167]], $MachinePrecision]], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(d2 + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -1 \cdot 10^{+180} \lor \neg \left(d3 \leq 3.2 \cdot 10^{+167}\right):\\
\;\;\;\;d1 \cdot \left(d4 - d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\
\end{array}
\end{array}
if d3 < -1e180 or 3.19999999999999981e167 < d3 Initial program 81.0%
sub-neg81.0%
associate-+l+81.0%
*-commutative81.0%
+-commutative81.0%
*-commutative81.0%
sub-neg81.0%
+-commutative81.0%
associate--l+81.0%
distribute-lft-out--85.7%
distribute-rgt-out--87.3%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d2 around 0 92.4%
+-commutative92.4%
associate--r+92.4%
Simplified92.4%
Taylor expanded in d1 around 0 89.2%
if -1e180 < d3 < 3.19999999999999981e167Initial program 83.9%
sub-neg83.9%
associate-+l+83.9%
*-commutative83.9%
+-commutative83.9%
*-commutative83.9%
sub-neg83.9%
+-commutative83.9%
associate--l+83.9%
distribute-lft-out--84.9%
distribute-rgt-out--90.1%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around 0 92.3%
Final simplification91.5%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (or (<= d3 -7e+179) (not (<= d3 1.02e+90))) (* d1 (- d3)) (* d1 (+ d2 d4))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d3 <= -7e+179) || !(d3 <= 1.02e+90)) {
tmp = d1 * -d3;
} else {
tmp = d1 * (d2 + 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 ((d3 <= (-7d+179)) .or. (.not. (d3 <= 1.02d+90))) then
tmp = d1 * -d3
else
tmp = d1 * (d2 + d4)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d3 <= -7e+179) || !(d3 <= 1.02e+90)) {
tmp = d1 * -d3;
} else {
tmp = d1 * (d2 + d4);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if (d3 <= -7e+179) or not (d3 <= 1.02e+90): tmp = d1 * -d3 else: tmp = d1 * (d2 + d4) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if ((d3 <= -7e+179) || !(d3 <= 1.02e+90)) tmp = Float64(d1 * Float64(-d3)); else tmp = Float64(d1 * Float64(d2 + d4)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if ((d3 <= -7e+179) || ~((d3 <= 1.02e+90))) tmp = d1 * -d3; else tmp = d1 * (d2 + d4); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -7e+179], N[Not[LessEqual[d3, 1.02e+90]], $MachinePrecision]], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -7 \cdot 10^{+179} \lor \neg \left(d3 \leq 1.02 \cdot 10^{+90}\right):\\
\;\;\;\;d1 \cdot \left(-d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d2 + d4\right)\\
\end{array}
\end{array}
if d3 < -7.0000000000000003e179 or 1.02000000000000005e90 < d3 Initial program 80.7%
sub-neg80.7%
associate-+l+80.7%
*-commutative80.7%
+-commutative80.7%
*-commutative80.7%
sub-neg80.7%
+-commutative80.7%
associate--l+80.7%
distribute-lft-out--85.9%
distribute-rgt-out--87.2%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around inf 79.2%
mul-1-neg79.2%
distribute-rgt-neg-out79.2%
Simplified79.2%
if -7.0000000000000003e179 < d3 < 1.02000000000000005e90Initial program 84.3%
sub-neg84.3%
associate-+l+84.3%
*-commutative84.3%
+-commutative84.3%
*-commutative84.3%
sub-neg84.3%
+-commutative84.3%
associate--l+84.3%
distribute-lft-out--84.8%
distribute-rgt-out--90.4%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around 0 94.4%
Taylor expanded in d1 around 0 66.7%
Final simplification70.5%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -5.5) (* d1 (- d2 d1)) (if (<= d2 -1.9e-136) (* d1 (- d3)) (* d1 (- d4 d1)))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.5) {
tmp = d1 * (d2 - d1);
} else if (d2 <= -1.9e-136) {
tmp = d1 * -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 (d2 <= (-5.5d0)) then
tmp = d1 * (d2 - d1)
else if (d2 <= (-1.9d-136)) then
tmp = d1 * -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 (d2 <= -5.5) {
tmp = d1 * (d2 - d1);
} else if (d2 <= -1.9e-136) {
tmp = d1 * -d3;
} else {
tmp = d1 * (d4 - d1);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -5.5: tmp = d1 * (d2 - d1) elif d2 <= -1.9e-136: tmp = d1 * -d3 else: tmp = d1 * (d4 - d1) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -5.5) tmp = Float64(d1 * Float64(d2 - d1)); elseif (d2 <= -1.9e-136) tmp = Float64(d1 * Float64(-d3)); else tmp = Float64(d1 * Float64(d4 - d1)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -5.5) tmp = d1 * (d2 - d1); elseif (d2 <= -1.9e-136) tmp = d1 * -d3; else tmp = d1 * (d4 - d1); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.5], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d2, -1.9e-136], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.5:\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\
\mathbf{elif}\;d2 \leq -1.9 \cdot 10^{-136}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 - d1\right)\\
\end{array}
\end{array}
if d2 < -5.5Initial program 82.5%
sub-neg82.5%
associate-+l+82.5%
*-commutative82.5%
+-commutative82.5%
*-commutative82.5%
sub-neg82.5%
+-commutative82.5%
associate--l+82.5%
distribute-lft-out--84.2%
distribute-rgt-out--94.7%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around 0 91.5%
Taylor expanded in d4 around 0 78.8%
if -5.5 < d2 < -1.9000000000000001e-136Initial program 83.3%
sub-neg83.3%
associate-+l+83.3%
*-commutative83.3%
+-commutative83.3%
*-commutative83.3%
sub-neg83.3%
+-commutative83.3%
associate--l+83.3%
distribute-lft-out--87.5%
distribute-rgt-out--87.5%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around inf 61.5%
mul-1-neg61.5%
distribute-rgt-neg-out61.5%
Simplified61.5%
if -1.9000000000000001e-136 < d2 Initial program 83.4%
sub-neg83.4%
associate-+l+83.4%
*-commutative83.4%
+-commutative83.4%
*-commutative83.4%
sub-neg83.4%
+-commutative83.4%
associate--l+83.4%
distribute-lft-out--85.1%
distribute-rgt-out--88.0%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around 0 77.1%
Taylor expanded in d2 around 0 62.0%
Final simplification65.7%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -5.8e+46) (* d1 d2) (if (<= d2 2.05e-278) (* d1 (- d3)) (* d1 d4))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -5.8e+46) {
tmp = d1 * d2;
} else if (d2 <= 2.05e-278) {
tmp = d1 * -d3;
} 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 <= (-5.8d+46)) then
tmp = d1 * d2
else if (d2 <= 2.05d-278) then
tmp = d1 * -d3
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 <= -5.8e+46) {
tmp = d1 * d2;
} else if (d2 <= 2.05e-278) {
tmp = d1 * -d3;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -5.8e+46: tmp = d1 * d2 elif d2 <= 2.05e-278: tmp = d1 * -d3 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -5.8e+46) tmp = Float64(d1 * d2); elseif (d2 <= 2.05e-278) tmp = Float64(d1 * Float64(-d3)); else tmp = Float64(d1 * d4); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -5.8e+46) tmp = d1 * d2; elseif (d2 <= 2.05e-278) tmp = d1 * -d3; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.8e+46], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, 2.05e-278], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.8 \cdot 10^{+46}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq 2.05 \cdot 10^{-278}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d2 < -5.8000000000000004e46Initial program 83.7%
sub-neg83.7%
associate-+l+83.7%
*-commutative83.7%
+-commutative83.7%
*-commutative83.7%
sub-neg83.7%
+-commutative83.7%
associate--l+83.7%
distribute-lft-out--85.7%
distribute-rgt-out--98.0%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d2 around inf 65.2%
if -5.8000000000000004e46 < d2 < 2.05000000000000001e-278Initial program 82.5%
sub-neg82.5%
associate-+l+82.5%
*-commutative82.5%
+-commutative82.5%
*-commutative82.5%
sub-neg82.5%
+-commutative82.5%
associate--l+82.5%
distribute-lft-out--85.0%
distribute-rgt-out--85.0%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around inf 44.4%
mul-1-neg44.4%
distribute-rgt-neg-out44.4%
Simplified44.4%
if 2.05000000000000001e-278 < d2 Initial program 83.4%
sub-neg83.4%
associate-+l+83.4%
*-commutative83.4%
+-commutative83.4%
*-commutative83.4%
sub-neg83.4%
+-commutative83.4%
associate--l+83.4%
distribute-lft-out--85.0%
distribute-rgt-out--88.9%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d4 around inf 33.5%
Final simplification42.9%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1e+47) (* d1 (- (+ d2 d4) d1)) (* d1 (- (- d4 d3) d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1e+47) {
tmp = d1 * ((d2 + d4) - d1);
} else {
tmp = d1 * ((d4 - d3) - 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 <= (-1d+47)) then
tmp = d1 * ((d2 + d4) - d1)
else
tmp = d1 * ((d4 - d3) - d1)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1e+47) {
tmp = d1 * ((d2 + d4) - d1);
} else {
tmp = d1 * ((d4 - d3) - d1);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1e+47: tmp = d1 * ((d2 + d4) - d1) else: tmp = d1 * ((d4 - d3) - d1) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1e+47) tmp = Float64(d1 * Float64(Float64(d2 + d4) - d1)); else tmp = Float64(d1 * Float64(Float64(d4 - d3) - d1)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -1e+47) tmp = d1 * ((d2 + d4) - d1); else tmp = d1 * ((d4 - d3) - d1); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1e+47], N[(d1 * N[(N[(d2 + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(d4 - d3), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1 \cdot 10^{+47}:\\
\;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(\left(d4 - d3\right) - d1\right)\\
\end{array}
\end{array}
if d2 < -1e47Initial program 83.7%
sub-neg83.7%
associate-+l+83.7%
*-commutative83.7%
+-commutative83.7%
*-commutative83.7%
sub-neg83.7%
+-commutative83.7%
associate--l+83.7%
distribute-lft-out--85.7%
distribute-rgt-out--98.0%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d3 around 0 94.2%
if -1e47 < d2 Initial program 83.1%
sub-neg83.1%
associate-+l+83.1%
*-commutative83.1%
+-commutative83.1%
*-commutative83.1%
sub-neg83.1%
+-commutative83.1%
associate--l+83.1%
distribute-lft-out--85.0%
distribute-rgt-out--87.4%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d2 around 0 86.4%
+-commutative86.4%
associate--r+86.4%
Simplified86.4%
Final simplification87.9%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.45e+35) (* d1 d2) (* d1 d4)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.45e+35) {
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 <= (-1.45d+35)) 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 <= -1.45e+35) {
tmp = d1 * d2;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.45e+35: tmp = d1 * d2 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.45e+35) 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 <= -1.45e+35) tmp = d1 * d2; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.45e+35], N[(d1 * d2), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.45 \cdot 10^{+35}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d2 < -1.44999999999999997e35Initial program 83.0%
sub-neg83.0%
associate-+l+83.0%
*-commutative83.0%
+-commutative83.0%
*-commutative83.0%
sub-neg83.0%
+-commutative83.0%
associate--l+83.0%
distribute-lft-out--84.9%
distribute-rgt-out--96.2%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d2 around inf 60.6%
if -1.44999999999999997e35 < d2 Initial program 83.2%
sub-neg83.2%
associate-+l+83.2%
*-commutative83.2%
+-commutative83.2%
*-commutative83.2%
sub-neg83.2%
+-commutative83.2%
associate--l+83.2%
distribute-lft-out--85.2%
distribute-rgt-out--87.7%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d4 around inf 35.1%
Final simplification40.4%
(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 83.2%
sub-neg83.2%
associate-+l+83.2%
*-commutative83.2%
+-commutative83.2%
*-commutative83.2%
sub-neg83.2%
+-commutative83.2%
associate--l+83.2%
distribute-lft-out--85.1%
distribute-rgt-out--89.4%
distribute-lft-out100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
sub-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in d2 around inf 30.0%
Final simplification30.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 2024031
(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)))