
(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 12 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 d1) (- d2 d3))))
double code(double d1, double d2, double d3, double d4) {
return d1 * ((d4 - d1) + (d2 - 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 * ((d4 - d1) + (d2 - d3))
end function
public static double code(double d1, double d2, double d3, double d4) {
return d1 * ((d4 - d1) + (d2 - d3));
}
def code(d1, d2, d3, d4): return d1 * ((d4 - d1) + (d2 - d3))
function code(d1, d2, d3, d4) return Float64(d1 * Float64(Float64(d4 - d1) + Float64(d2 - d3))) end
function tmp = code(d1, d2, d3, d4) tmp = d1 * ((d4 - d1) + (d2 - d3)); end
code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(d4 - d1), $MachinePrecision] + N[(d2 - d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(\left(d4 - d1\right) + \left(d2 - d3\right)\right)
\end{array}
Initial program 89.0%
associate--l+89.0%
+-commutative89.0%
distribute-rgt-out--90.2%
distribute-lft-out--91.8%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (d1 d2 d3 d4)
:precision binary64
(if (<= d2 -4.25e+18)
(* d1 d2)
(if (or (<= d2 -5.6e-171) (and (not (<= d2 -1.14e-240)) (<= d2 1.02e-251)))
(* d1 (- d3))
(* d1 d4))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -4.25e+18) {
tmp = d1 * d2;
} else if ((d2 <= -5.6e-171) || (!(d2 <= -1.14e-240) && (d2 <= 1.02e-251))) {
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 <= (-4.25d+18)) then
tmp = d1 * d2
else if ((d2 <= (-5.6d-171)) .or. (.not. (d2 <= (-1.14d-240))) .and. (d2 <= 1.02d-251)) 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 <= -4.25e+18) {
tmp = d1 * d2;
} else if ((d2 <= -5.6e-171) || (!(d2 <= -1.14e-240) && (d2 <= 1.02e-251))) {
tmp = d1 * -d3;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -4.25e+18: tmp = d1 * d2 elif (d2 <= -5.6e-171) or (not (d2 <= -1.14e-240) and (d2 <= 1.02e-251)): tmp = d1 * -d3 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -4.25e+18) tmp = Float64(d1 * d2); elseif ((d2 <= -5.6e-171) || (!(d2 <= -1.14e-240) && (d2 <= 1.02e-251))) 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 <= -4.25e+18) tmp = d1 * d2; elseif ((d2 <= -5.6e-171) || (~((d2 <= -1.14e-240)) && (d2 <= 1.02e-251))) tmp = d1 * -d3; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.25e+18], N[(d1 * d2), $MachinePrecision], If[Or[LessEqual[d2, -5.6e-171], And[N[Not[LessEqual[d2, -1.14e-240]], $MachinePrecision], LessEqual[d2, 1.02e-251]]], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4.25 \cdot 10^{+18}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq -5.6 \cdot 10^{-171} \lor \neg \left(d2 \leq -1.14 \cdot 10^{-240}\right) \land d2 \leq 1.02 \cdot 10^{-251}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d2 < -4.25e18Initial program 78.7%
associate--l+78.7%
+-commutative78.7%
distribute-rgt-out--78.7%
distribute-lft-out--81.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around inf 66.0%
if -4.25e18 < d2 < -5.60000000000000046e-171 or -1.14e-240 < d2 < 1.0200000000000001e-251Initial program 95.0%
associate--l+95.0%
+-commutative95.0%
distribute-rgt-out--96.6%
distribute-lft-out--96.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around inf 56.2%
associate-*r*56.2%
neg-mul-156.2%
Simplified56.2%
if -5.60000000000000046e-171 < d2 < -1.14e-240 or 1.0200000000000001e-251 < d2 Initial program 91.1%
associate--l+91.1%
+-commutative91.1%
distribute-rgt-out--92.6%
distribute-lft-out--94.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d4 around inf 35.7%
Final simplification47.7%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* d1 (- d2 d1))))
(if (<= d4 1.25e-232)
t_0
(if (<= d4 2.4e-182)
(* d1 (- d3))
(if (<= d4 4e+80) t_0 (* d1 (+ d4 d2)))))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * (d2 - d1);
double tmp;
if (d4 <= 1.25e-232) {
tmp = t_0;
} else if (d4 <= 2.4e-182) {
tmp = d1 * -d3;
} else if (d4 <= 4e+80) {
tmp = t_0;
} else {
tmp = d1 * (d4 + d2);
}
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 - d1)
if (d4 <= 1.25d-232) then
tmp = t_0
else if (d4 <= 2.4d-182) then
tmp = d1 * -d3
else if (d4 <= 4d+80) then
tmp = t_0
else
tmp = d1 * (d4 + d2)
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 tmp;
if (d4 <= 1.25e-232) {
tmp = t_0;
} else if (d4 <= 2.4e-182) {
tmp = d1 * -d3;
} else if (d4 <= 4e+80) {
tmp = t_0;
} else {
tmp = d1 * (d4 + d2);
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = d1 * (d2 - d1) tmp = 0 if d4 <= 1.25e-232: tmp = t_0 elif d4 <= 2.4e-182: tmp = d1 * -d3 elif d4 <= 4e+80: tmp = t_0 else: tmp = d1 * (d4 + d2) return tmp
function code(d1, d2, d3, d4) t_0 = Float64(d1 * Float64(d2 - d1)) tmp = 0.0 if (d4 <= 1.25e-232) tmp = t_0; elseif (d4 <= 2.4e-182) tmp = Float64(d1 * Float64(-d3)); elseif (d4 <= 4e+80) tmp = t_0; else tmp = Float64(d1 * Float64(d4 + d2)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = d1 * (d2 - d1); tmp = 0.0; if (d4 <= 1.25e-232) tmp = t_0; elseif (d4 <= 2.4e-182) tmp = d1 * -d3; elseif (d4 <= 4e+80) tmp = t_0; else tmp = d1 * (d4 + d2); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, 1.25e-232], t$95$0, If[LessEqual[d4, 2.4e-182], N[(d1 * (-d3)), $MachinePrecision], If[LessEqual[d4, 4e+80], t$95$0, N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 - d1\right)\\
\mathbf{if}\;d4 \leq 1.25 \cdot 10^{-232}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d4 \leq 2.4 \cdot 10^{-182}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\
\mathbf{elif}\;d4 \leq 4 \cdot 10^{+80}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 + d2\right)\\
\end{array}
\end{array}
if d4 < 1.25e-232 or 2.3999999999999998e-182 < d4 < 4e80Initial program 90.6%
associate--l+90.6%
+-commutative90.6%
distribute-rgt-out--91.7%
distribute-lft-out--93.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around 0 76.2%
Taylor expanded in d4 around 0 58.1%
if 1.25e-232 < d4 < 2.3999999999999998e-182Initial program 75.0%
associate--l+75.0%
+-commutative75.0%
distribute-rgt-out--75.0%
distribute-lft-out--75.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around inf 39.9%
associate-*r*39.9%
neg-mul-139.9%
Simplified39.9%
if 4e80 < d4 Initial program 85.7%
associate--l+85.7%
+-commutative85.7%
distribute-rgt-out--87.5%
distribute-lft-out--87.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 93.0%
Taylor expanded in d3 around 0 78.9%
+-commutative78.9%
Simplified78.9%
Final simplification62.1%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* d1 (- d2 d3))))
(if (<= d4 5.5e-70)
t_0
(if (<= d4 2.1e+17)
(* d1 (- d2 d1))
(if (<= d4 3.75e+81) t_0 (* d1 (+ d4 d2)))))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = d1 * (d2 - d3);
double tmp;
if (d4 <= 5.5e-70) {
tmp = t_0;
} else if (d4 <= 2.1e+17) {
tmp = d1 * (d2 - d1);
} else if (d4 <= 3.75e+81) {
tmp = t_0;
} else {
tmp = d1 * (d4 + d2);
}
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 (d4 <= 5.5d-70) then
tmp = t_0
else if (d4 <= 2.1d+17) then
tmp = d1 * (d2 - d1)
else if (d4 <= 3.75d+81) then
tmp = t_0
else
tmp = d1 * (d4 + d2)
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 (d4 <= 5.5e-70) {
tmp = t_0;
} else if (d4 <= 2.1e+17) {
tmp = d1 * (d2 - d1);
} else if (d4 <= 3.75e+81) {
tmp = t_0;
} else {
tmp = d1 * (d4 + d2);
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = d1 * (d2 - d3) tmp = 0 if d4 <= 5.5e-70: tmp = t_0 elif d4 <= 2.1e+17: tmp = d1 * (d2 - d1) elif d4 <= 3.75e+81: tmp = t_0 else: tmp = d1 * (d4 + d2) return tmp
function code(d1, d2, d3, d4) t_0 = Float64(d1 * Float64(d2 - d3)) tmp = 0.0 if (d4 <= 5.5e-70) tmp = t_0; elseif (d4 <= 2.1e+17) tmp = Float64(d1 * Float64(d2 - d1)); elseif (d4 <= 3.75e+81) tmp = t_0; else tmp = Float64(d1 * Float64(d4 + d2)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = d1 * (d2 - d3); tmp = 0.0; if (d4 <= 5.5e-70) tmp = t_0; elseif (d4 <= 2.1e+17) tmp = d1 * (d2 - d1); elseif (d4 <= 3.75e+81) tmp = t_0; else tmp = d1 * (d4 + d2); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, 5.5e-70], t$95$0, If[LessEqual[d4, 2.1e+17], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d4, 3.75e+81], t$95$0, N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 - d3\right)\\
\mathbf{if}\;d4 \leq 5.5 \cdot 10^{-70}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d4 \leq 2.1 \cdot 10^{+17}:\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\
\mathbf{elif}\;d4 \leq 3.75 \cdot 10^{+81}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 + d2\right)\\
\end{array}
\end{array}
if d4 < 5.5000000000000001e-70 or 2.1e17 < d4 < 3.74999999999999986e81Initial program 92.0%
associate--l+92.0%
+-commutative92.0%
distribute-rgt-out--93.0%
distribute-lft-out--94.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 83.9%
Taylor expanded in d4 around 0 64.0%
if 5.5000000000000001e-70 < d4 < 2.1e17Initial program 61.5%
associate--l+61.5%
+-commutative61.5%
distribute-rgt-out--61.5%
distribute-lft-out--69.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around 0 78.6%
Taylor expanded in d4 around 0 71.5%
if 3.74999999999999986e81 < d4 Initial program 85.7%
associate--l+85.7%
+-commutative85.7%
distribute-rgt-out--87.5%
distribute-lft-out--87.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 93.0%
Taylor expanded in d3 around 0 78.9%
+-commutative78.9%
Simplified78.9%
Final simplification67.7%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (or (<= d1 -1.25e+48) (not (<= d1 5e-18))) (* d1 (- (+ d4 d2) d1)) (* d1 (- (+ d4 d2) d3))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d1 <= -1.25e+48) || !(d1 <= 5e-18)) {
tmp = d1 * ((d4 + d2) - d1);
} else {
tmp = d1 * ((d4 + d2) - 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 ((d1 <= (-1.25d+48)) .or. (.not. (d1 <= 5d-18))) then
tmp = d1 * ((d4 + d2) - d1)
else
tmp = d1 * ((d4 + d2) - d3)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d1 <= -1.25e+48) || !(d1 <= 5e-18)) {
tmp = d1 * ((d4 + d2) - d1);
} else {
tmp = d1 * ((d4 + d2) - d3);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if (d1 <= -1.25e+48) or not (d1 <= 5e-18): tmp = d1 * ((d4 + d2) - d1) else: tmp = d1 * ((d4 + d2) - d3) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if ((d1 <= -1.25e+48) || !(d1 <= 5e-18)) tmp = Float64(d1 * Float64(Float64(d4 + d2) - d1)); else tmp = Float64(d1 * Float64(Float64(d4 + d2) - d3)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if ((d1 <= -1.25e+48) || ~((d1 <= 5e-18))) tmp = d1 * ((d4 + d2) - d1); else tmp = d1 * ((d4 + d2) - d3); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d1, -1.25e+48], N[Not[LessEqual[d1, 5e-18]], $MachinePrecision]], N[(d1 * N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -1.25 \cdot 10^{+48} \lor \neg \left(d1 \leq 5 \cdot 10^{-18}\right):\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\
\end{array}
\end{array}
if d1 < -1.24999999999999993e48 or 5.00000000000000036e-18 < d1 Initial program 70.8%
associate--l+70.8%
+-commutative70.8%
distribute-rgt-out--74.0%
distribute-lft-out--78.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around 0 91.3%
if -1.24999999999999993e48 < d1 < 5.00000000000000036e-18Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 99.3%
Final simplification96.3%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d3 -1.9e+102) (* d1 (- d2 d3)) (if (<= d3 1.85e+176) (* d1 (- (+ d4 d2) d1)) (* d1 (- (- d3) d1)))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d3 <= -1.9e+102) {
tmp = d1 * (d2 - d3);
} else if (d3 <= 1.85e+176) {
tmp = d1 * ((d4 + d2) - d1);
} else {
tmp = d1 * (-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 (d3 <= (-1.9d+102)) then
tmp = d1 * (d2 - d3)
else if (d3 <= 1.85d+176) then
tmp = d1 * ((d4 + d2) - d1)
else
tmp = d1 * (-d3 - d1)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d3 <= -1.9e+102) {
tmp = d1 * (d2 - d3);
} else if (d3 <= 1.85e+176) {
tmp = d1 * ((d4 + d2) - d1);
} else {
tmp = d1 * (-d3 - d1);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d3 <= -1.9e+102: tmp = d1 * (d2 - d3) elif d3 <= 1.85e+176: tmp = d1 * ((d4 + d2) - d1) else: tmp = d1 * (-d3 - d1) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d3 <= -1.9e+102) tmp = Float64(d1 * Float64(d2 - d3)); elseif (d3 <= 1.85e+176) tmp = Float64(d1 * Float64(Float64(d4 + d2) - d1)); else tmp = Float64(d1 * Float64(Float64(-d3) - d1)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d3 <= -1.9e+102) tmp = d1 * (d2 - d3); elseif (d3 <= 1.85e+176) tmp = d1 * ((d4 + d2) - d1); else tmp = d1 * (-d3 - d1); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d3, -1.9e+102], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 1.85e+176], N[(d1 * N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[((-d3) - d1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -1.9 \cdot 10^{+102}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\
\mathbf{elif}\;d3 \leq 1.85 \cdot 10^{+176}:\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(\left(-d3\right) - d1\right)\\
\end{array}
\end{array}
if d3 < -1.89999999999999989e102Initial program 89.5%
associate--l+89.5%
+-commutative89.5%
distribute-rgt-out--89.5%
distribute-lft-out--94.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 97.8%
Taylor expanded in d4 around 0 90.2%
if -1.89999999999999989e102 < d3 < 1.8499999999999999e176Initial program 91.1%
associate--l+91.1%
+-commutative91.1%
distribute-rgt-out--92.6%
distribute-lft-out--93.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around 0 91.6%
if 1.8499999999999999e176 < d3 Initial program 74.1%
Taylor expanded in d2 around 0 70.8%
distribute-lft-out--74.4%
Simplified74.4%
Taylor expanded in d4 around 0 63.3%
mul-1-neg63.3%
distribute-rgt-neg-out63.3%
unpow263.3%
distribute-lft-out--89.2%
Simplified89.2%
Final simplification91.1%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -3.6e+18) (* d1 (+ d4 d2)) (if (<= d2 -1.86e-180) (* d1 (- (- d3) d1)) (* d1 (- d4 d3)))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -3.6e+18) {
tmp = d1 * (d4 + d2);
} else if (d2 <= -1.86e-180) {
tmp = d1 * (-d3 - d1);
} else {
tmp = d1 * (d4 - 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 <= (-3.6d+18)) then
tmp = d1 * (d4 + d2)
else if (d2 <= (-1.86d-180)) then
tmp = d1 * (-d3 - d1)
else
tmp = d1 * (d4 - d3)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -3.6e+18) {
tmp = d1 * (d4 + d2);
} else if (d2 <= -1.86e-180) {
tmp = d1 * (-d3 - d1);
} else {
tmp = d1 * (d4 - d3);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -3.6e+18: tmp = d1 * (d4 + d2) elif d2 <= -1.86e-180: tmp = d1 * (-d3 - d1) else: tmp = d1 * (d4 - d3) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -3.6e+18) tmp = Float64(d1 * Float64(d4 + d2)); elseif (d2 <= -1.86e-180) tmp = Float64(d1 * Float64(Float64(-d3) - d1)); else tmp = Float64(d1 * Float64(d4 - d3)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -3.6e+18) tmp = d1 * (d4 + d2); elseif (d2 <= -1.86e-180) tmp = d1 * (-d3 - d1); else tmp = d1 * (d4 - d3); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -3.6e+18], N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision], If[LessEqual[d2, -1.86e-180], N[(d1 * N[((-d3) - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -3.6 \cdot 10^{+18}:\\
\;\;\;\;d1 \cdot \left(d4 + d2\right)\\
\mathbf{elif}\;d2 \leq -1.86 \cdot 10^{-180}:\\
\;\;\;\;d1 \cdot \left(\left(-d3\right) - d1\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 - d3\right)\\
\end{array}
\end{array}
if d2 < -3.6e18Initial program 78.7%
associate--l+78.7%
+-commutative78.7%
distribute-rgt-out--78.7%
distribute-lft-out--81.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 88.7%
Taylor expanded in d3 around 0 86.6%
+-commutative86.6%
Simplified86.6%
if -3.6e18 < d2 < -1.86e-180Initial program 97.5%
Taylor expanded in d2 around 0 95.2%
distribute-lft-out--95.2%
Simplified95.2%
Taylor expanded in d4 around 0 71.1%
mul-1-neg71.1%
distribute-rgt-neg-out71.1%
unpow271.1%
distribute-lft-out--71.1%
Simplified71.1%
if -1.86e-180 < d2 Initial program 90.9%
associate--l+90.9%
+-commutative90.9%
distribute-rgt-out--92.2%
distribute-lft-out--93.5%
distribute-lft-out99.9%
Simplified99.9%
Taylor expanded in d1 around 0 83.2%
Taylor expanded in d2 around 0 60.9%
Final simplification68.6%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (or (<= d3 -6.2e+151) (not (<= d3 2.3e+121))) (* d1 (- d3)) (* d1 (+ d4 d2))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d3 <= -6.2e+151) || !(d3 <= 2.3e+121)) {
tmp = d1 * -d3;
} else {
tmp = d1 * (d4 + d2);
}
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 <= (-6.2d+151)) .or. (.not. (d3 <= 2.3d+121))) then
tmp = d1 * -d3
else
tmp = d1 * (d4 + d2)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d3 <= -6.2e+151) || !(d3 <= 2.3e+121)) {
tmp = d1 * -d3;
} else {
tmp = d1 * (d4 + d2);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if (d3 <= -6.2e+151) or not (d3 <= 2.3e+121): tmp = d1 * -d3 else: tmp = d1 * (d4 + d2) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if ((d3 <= -6.2e+151) || !(d3 <= 2.3e+121)) tmp = Float64(d1 * Float64(-d3)); else tmp = Float64(d1 * Float64(d4 + d2)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if ((d3 <= -6.2e+151) || ~((d3 <= 2.3e+121))) tmp = d1 * -d3; else tmp = d1 * (d4 + d2); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -6.2e+151], N[Not[LessEqual[d3, 2.3e+121]], $MachinePrecision]], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -6.2 \cdot 10^{+151} \lor \neg \left(d3 \leq 2.3 \cdot 10^{+121}\right):\\
\;\;\;\;d1 \cdot \left(-d3\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 + d2\right)\\
\end{array}
\end{array}
if d3 < -6.2000000000000004e151 or 2.2999999999999999e121 < d3 Initial program 79.7%
associate--l+79.7%
+-commutative79.7%
distribute-rgt-out--79.7%
distribute-lft-out--85.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around inf 71.9%
associate-*r*71.9%
neg-mul-171.9%
Simplified71.9%
if -6.2000000000000004e151 < d3 < 2.2999999999999999e121Initial program 92.5%
associate--l+92.5%
+-commutative92.5%
distribute-rgt-out--94.1%
distribute-lft-out--94.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 81.4%
Taylor expanded in d3 around 0 73.7%
+-commutative73.7%
Simplified73.7%
Final simplification73.2%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -4.7e+18) (* d1 (- (+ d4 d2) d1)) (* d1 (- (- d4 d3) d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -4.7e+18) {
tmp = d1 * ((d4 + d2) - 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 <= (-4.7d+18)) then
tmp = d1 * ((d4 + d2) - 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 <= -4.7e+18) {
tmp = d1 * ((d4 + d2) - d1);
} else {
tmp = d1 * ((d4 - d3) - d1);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -4.7e+18: tmp = d1 * ((d4 + d2) - d1) else: tmp = d1 * ((d4 - d3) - d1) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -4.7e+18) tmp = Float64(d1 * Float64(Float64(d4 + d2) - 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 <= -4.7e+18) tmp = d1 * ((d4 + d2) - d1); else tmp = d1 * ((d4 - d3) - d1); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.7e+18], N[(d1 * N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(d4 - d3), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4.7 \cdot 10^{+18}:\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(\left(d4 - d3\right) - d1\right)\\
\end{array}
\end{array}
if d2 < -4.7e18Initial program 78.7%
associate--l+78.7%
+-commutative78.7%
distribute-rgt-out--78.7%
distribute-lft-out--81.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d3 around 0 97.9%
if -4.7e18 < d2 Initial program 92.3%
associate--l+92.3%
+-commutative92.3%
distribute-rgt-out--93.8%
distribute-lft-out--94.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around 0 82.2%
+-commutative82.2%
associate--r+82.2%
Simplified82.2%
Final simplification85.9%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -4e+18) (* d1 (+ d4 d2)) (* d1 (- d4 d3))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -4e+18) {
tmp = d1 * (d4 + d2);
} else {
tmp = d1 * (d4 - 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 <= (-4d+18)) then
tmp = d1 * (d4 + d2)
else
tmp = d1 * (d4 - d3)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -4e+18) {
tmp = d1 * (d4 + d2);
} else {
tmp = d1 * (d4 - d3);
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -4e+18: tmp = d1 * (d4 + d2) else: tmp = d1 * (d4 - d3) return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -4e+18) tmp = Float64(d1 * Float64(d4 + d2)); else tmp = Float64(d1 * Float64(d4 - d3)); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -4e+18) tmp = d1 * (d4 + d2); else tmp = d1 * (d4 - d3); end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4e+18], N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4 \cdot 10^{+18}:\\
\;\;\;\;d1 \cdot \left(d4 + d2\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d4 - d3\right)\\
\end{array}
\end{array}
if d2 < -4e18Initial program 78.7%
associate--l+78.7%
+-commutative78.7%
distribute-rgt-out--78.7%
distribute-lft-out--81.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 88.7%
Taylor expanded in d3 around 0 86.6%
+-commutative86.6%
Simplified86.6%
if -4e18 < d2 Initial program 92.3%
associate--l+92.3%
+-commutative92.3%
distribute-rgt-out--93.8%
distribute-lft-out--94.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d1 around 0 83.2%
Taylor expanded in d2 around 0 65.0%
Final simplification70.2%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d4 3.05e+66) (* d1 d2) (* d1 d4)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d4 <= 3.05e+66) {
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 (d4 <= 3.05d+66) 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 (d4 <= 3.05e+66) {
tmp = d1 * d2;
} else {
tmp = d1 * d4;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d4 <= 3.05e+66: tmp = d1 * d2 else: tmp = d1 * d4 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d4 <= 3.05e+66) 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 (d4 <= 3.05e+66) tmp = d1 * d2; else tmp = d1 * d4; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 3.05e+66], N[(d1 * d2), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 3.05 \cdot 10^{+66}:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d4\\
\end{array}
\end{array}
if d4 < 3.0500000000000001e66Initial program 89.7%
associate--l+89.7%
+-commutative89.7%
distribute-rgt-out--90.8%
distribute-lft-out--92.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around inf 38.1%
if 3.0500000000000001e66 < d4 Initial program 86.8%
associate--l+86.8%
+-commutative86.8%
distribute-rgt-out--88.5%
distribute-lft-out--88.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d4 around inf 59.1%
Final simplification43.1%
(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 89.0%
associate--l+89.0%
+-commutative89.0%
distribute-rgt-out--90.2%
distribute-lft-out--91.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in d2 around inf 34.4%
Final simplification34.4%
(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 2023321
(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)))