
(FPCore (d1 d2 d3) :precision binary64 (+ (+ (* d1 d2) (* (+ d3 5.0) d1)) (* d1 32.0)))
double code(double d1, double d2, double d3) {
return ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0);
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
code = ((d1 * d2) + ((d3 + 5.0d0) * d1)) + (d1 * 32.0d0)
end function
public static double code(double d1, double d2, double d3) {
return ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0);
}
def code(d1, d2, d3): return ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0)
function code(d1, d2, d3) return Float64(Float64(Float64(d1 * d2) + Float64(Float64(d3 + 5.0) * d1)) + Float64(d1 * 32.0)) end
function tmp = code(d1, d2, d3) tmp = ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0); end
code[d1_, d2_, d3_] := N[(N[(N[(d1 * d2), $MachinePrecision] + N[(N[(d3 + 5.0), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] + N[(d1 * 32.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(d1 \cdot d2 + \left(d3 + 5\right) \cdot d1\right) + d1 \cdot 32
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (d1 d2 d3) :precision binary64 (+ (+ (* d1 d2) (* (+ d3 5.0) d1)) (* d1 32.0)))
double code(double d1, double d2, double d3) {
return ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0);
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
code = ((d1 * d2) + ((d3 + 5.0d0) * d1)) + (d1 * 32.0d0)
end function
public static double code(double d1, double d2, double d3) {
return ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0);
}
def code(d1, d2, d3): return ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0)
function code(d1, d2, d3) return Float64(Float64(Float64(d1 * d2) + Float64(Float64(d3 + 5.0) * d1)) + Float64(d1 * 32.0)) end
function tmp = code(d1, d2, d3) tmp = ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0); end
code[d1_, d2_, d3_] := N[(N[(N[(d1 * d2), $MachinePrecision] + N[(N[(d3 + 5.0), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] + N[(d1 * 32.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(d1 \cdot d2 + \left(d3 + 5\right) \cdot d1\right) + d1 \cdot 32
\end{array}
(FPCore (d1 d2 d3) :precision binary64 (* d1 (+ 37.0 (+ d2 d3))))
double code(double d1, double d2, double d3) {
return d1 * (37.0 + (d2 + d3));
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
code = d1 * (37.0d0 + (d2 + d3))
end function
public static double code(double d1, double d2, double d3) {
return d1 * (37.0 + (d2 + d3));
}
def code(d1, d2, d3): return d1 * (37.0 + (d2 + d3))
function code(d1, d2, d3) return Float64(d1 * Float64(37.0 + Float64(d2 + d3))) end
function tmp = code(d1, d2, d3) tmp = d1 * (37.0 + (d2 + d3)); end
code[d1_, d2_, d3_] := N[(d1 * N[(37.0 + N[(d2 + d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(37 + \left(d2 + d3\right)\right)
\end{array}
Initial program 98.4%
cancel-sign-sub98.4%
+-commutative98.4%
*-commutative98.4%
distribute-lft-out100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
associate-+r+100.0%
+-commutative100.0%
associate--l+100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-+l+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in d1 around 0 100.0%
Final simplification100.0%
(FPCore (d1 d2 d3) :precision binary64 (if (or (<= d3 3.35e+24) (and (not (<= d3 5e+68)) (<= d3 9.8e+104))) (* d1 (+ 37.0 d2)) (* d1 d3)))
double code(double d1, double d2, double d3) {
double tmp;
if ((d3 <= 3.35e+24) || (!(d3 <= 5e+68) && (d3 <= 9.8e+104))) {
tmp = d1 * (37.0 + d2);
} else {
tmp = d1 * d3;
}
return tmp;
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8) :: tmp
if ((d3 <= 3.35d+24) .or. (.not. (d3 <= 5d+68)) .and. (d3 <= 9.8d+104)) then
tmp = d1 * (37.0d0 + d2)
else
tmp = d1 * d3
end if
code = tmp
end function
public static double code(double d1, double d2, double d3) {
double tmp;
if ((d3 <= 3.35e+24) || (!(d3 <= 5e+68) && (d3 <= 9.8e+104))) {
tmp = d1 * (37.0 + d2);
} else {
tmp = d1 * d3;
}
return tmp;
}
def code(d1, d2, d3): tmp = 0 if (d3 <= 3.35e+24) or (not (d3 <= 5e+68) and (d3 <= 9.8e+104)): tmp = d1 * (37.0 + d2) else: tmp = d1 * d3 return tmp
function code(d1, d2, d3) tmp = 0.0 if ((d3 <= 3.35e+24) || (!(d3 <= 5e+68) && (d3 <= 9.8e+104))) tmp = Float64(d1 * Float64(37.0 + d2)); else tmp = Float64(d1 * d3); end return tmp end
function tmp_2 = code(d1, d2, d3) tmp = 0.0; if ((d3 <= 3.35e+24) || (~((d3 <= 5e+68)) && (d3 <= 9.8e+104))) tmp = d1 * (37.0 + d2); else tmp = d1 * d3; end tmp_2 = tmp; end
code[d1_, d2_, d3_] := If[Or[LessEqual[d3, 3.35e+24], And[N[Not[LessEqual[d3, 5e+68]], $MachinePrecision], LessEqual[d3, 9.8e+104]]], N[(d1 * N[(37.0 + d2), $MachinePrecision]), $MachinePrecision], N[(d1 * d3), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq 3.35 \cdot 10^{+24} \lor \neg \left(d3 \leq 5 \cdot 10^{+68}\right) \land d3 \leq 9.8 \cdot 10^{+104}:\\
\;\;\;\;d1 \cdot \left(37 + d2\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d3\\
\end{array}
\end{array}
if d3 < 3.35e24 or 5.0000000000000004e68 < d3 < 9.7999999999999997e104Initial program 98.1%
cancel-sign-sub98.1%
+-commutative98.1%
*-commutative98.1%
distribute-lft-out100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
associate-+r+100.0%
+-commutative100.0%
associate--l+99.9%
sub-neg99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-+l+99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in d3 around 0 71.5%
if 3.35e24 < d3 < 5.0000000000000004e68 or 9.7999999999999997e104 < d3 Initial program 100.0%
cancel-sign-sub100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft-out100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
associate-+r+100.0%
+-commutative100.0%
associate--l+100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-+l+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in d3 around inf 89.6%
Final simplification74.7%
(FPCore (d1 d2 d3) :precision binary64 (if (or (<= d2 -1750.0) (not (<= d2 37.0))) (* d1 d2) (* d1 37.0)))
double code(double d1, double d2, double d3) {
double tmp;
if ((d2 <= -1750.0) || !(d2 <= 37.0)) {
tmp = d1 * d2;
} else {
tmp = d1 * 37.0;
}
return tmp;
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8) :: tmp
if ((d2 <= (-1750.0d0)) .or. (.not. (d2 <= 37.0d0))) then
tmp = d1 * d2
else
tmp = d1 * 37.0d0
end if
code = tmp
end function
public static double code(double d1, double d2, double d3) {
double tmp;
if ((d2 <= -1750.0) || !(d2 <= 37.0)) {
tmp = d1 * d2;
} else {
tmp = d1 * 37.0;
}
return tmp;
}
def code(d1, d2, d3): tmp = 0 if (d2 <= -1750.0) or not (d2 <= 37.0): tmp = d1 * d2 else: tmp = d1 * 37.0 return tmp
function code(d1, d2, d3) tmp = 0.0 if ((d2 <= -1750.0) || !(d2 <= 37.0)) tmp = Float64(d1 * d2); else tmp = Float64(d1 * 37.0); end return tmp end
function tmp_2 = code(d1, d2, d3) tmp = 0.0; if ((d2 <= -1750.0) || ~((d2 <= 37.0))) tmp = d1 * d2; else tmp = d1 * 37.0; end tmp_2 = tmp; end
code[d1_, d2_, d3_] := If[Or[LessEqual[d2, -1750.0], N[Not[LessEqual[d2, 37.0]], $MachinePrecision]], N[(d1 * d2), $MachinePrecision], N[(d1 * 37.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1750 \lor \neg \left(d2 \leq 37\right):\\
\;\;\;\;d1 \cdot d2\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot 37\\
\end{array}
\end{array}
if d2 < -1750 or 37 < d2 Initial program 97.1%
cancel-sign-sub97.1%
+-commutative97.1%
*-commutative97.1%
distribute-lft-out100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
associate-+r+100.0%
+-commutative100.0%
associate--l+100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-+l+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in d2 around inf 76.3%
if -1750 < d2 < 37Initial program 99.9%
cancel-sign-sub99.9%
+-commutative99.9%
*-commutative99.9%
distribute-lft-out99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
distribute-lft-out--99.9%
associate-+r+99.9%
+-commutative99.9%
associate--l+99.9%
sub-neg99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-+l+99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in d3 around 0 48.3%
Taylor expanded in d2 around 0 47.0%
*-commutative47.0%
Simplified47.0%
Final simplification62.6%
(FPCore (d1 d2 d3) :precision binary64 (if (<= d2 -1750.0) (* d1 d2) (if (<= d2 -5.5e-232) (* d1 37.0) (* d1 d3))))
double code(double d1, double d2, double d3) {
double tmp;
if (d2 <= -1750.0) {
tmp = d1 * d2;
} else if (d2 <= -5.5e-232) {
tmp = d1 * 37.0;
} else {
tmp = d1 * d3;
}
return tmp;
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8) :: tmp
if (d2 <= (-1750.0d0)) then
tmp = d1 * d2
else if (d2 <= (-5.5d-232)) then
tmp = d1 * 37.0d0
else
tmp = d1 * d3
end if
code = tmp
end function
public static double code(double d1, double d2, double d3) {
double tmp;
if (d2 <= -1750.0) {
tmp = d1 * d2;
} else if (d2 <= -5.5e-232) {
tmp = d1 * 37.0;
} else {
tmp = d1 * d3;
}
return tmp;
}
def code(d1, d2, d3): tmp = 0 if d2 <= -1750.0: tmp = d1 * d2 elif d2 <= -5.5e-232: tmp = d1 * 37.0 else: tmp = d1 * d3 return tmp
function code(d1, d2, d3) tmp = 0.0 if (d2 <= -1750.0) tmp = Float64(d1 * d2); elseif (d2 <= -5.5e-232) tmp = Float64(d1 * 37.0); else tmp = Float64(d1 * d3); end return tmp end
function tmp_2 = code(d1, d2, d3) tmp = 0.0; if (d2 <= -1750.0) tmp = d1 * d2; elseif (d2 <= -5.5e-232) tmp = d1 * 37.0; else tmp = d1 * d3; end tmp_2 = tmp; end
code[d1_, d2_, d3_] := If[LessEqual[d2, -1750.0], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -5.5e-232], N[(d1 * 37.0), $MachinePrecision], N[(d1 * d3), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1750:\\
\;\;\;\;d1 \cdot d2\\
\mathbf{elif}\;d2 \leq -5.5 \cdot 10^{-232}:\\
\;\;\;\;d1 \cdot 37\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d3\\
\end{array}
\end{array}
if d2 < -1750Initial program 100.0%
cancel-sign-sub100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft-out100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
associate-+r+100.0%
+-commutative100.0%
associate--l+100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-+l+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in d2 around inf 76.8%
if -1750 < d2 < -5.50000000000000023e-232Initial program 99.9%
cancel-sign-sub99.9%
+-commutative99.9%
*-commutative99.9%
distribute-lft-out99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
distribute-lft-out--99.9%
associate-+r+99.9%
+-commutative99.9%
associate--l+99.9%
sub-neg99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-+l+99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in d3 around 0 46.4%
Taylor expanded in d2 around 0 46.1%
*-commutative46.1%
Simplified46.1%
if -5.50000000000000023e-232 < d2 Initial program 97.2%
cancel-sign-sub97.2%
+-commutative97.2%
*-commutative97.2%
distribute-lft-out100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
associate-+r+100.0%
+-commutative100.0%
associate--l+99.9%
sub-neg99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-+l+99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in d3 around inf 42.6%
Final simplification52.1%
(FPCore (d1 d2 d3) :precision binary64 (if (<= d2 -18500.0) (* d1 (+ 37.0 d2)) (* d1 (+ 37.0 d3))))
double code(double d1, double d2, double d3) {
double tmp;
if (d2 <= -18500.0) {
tmp = d1 * (37.0 + d2);
} else {
tmp = d1 * (37.0 + d3);
}
return tmp;
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8) :: tmp
if (d2 <= (-18500.0d0)) then
tmp = d1 * (37.0d0 + d2)
else
tmp = d1 * (37.0d0 + d3)
end if
code = tmp
end function
public static double code(double d1, double d2, double d3) {
double tmp;
if (d2 <= -18500.0) {
tmp = d1 * (37.0 + d2);
} else {
tmp = d1 * (37.0 + d3);
}
return tmp;
}
def code(d1, d2, d3): tmp = 0 if d2 <= -18500.0: tmp = d1 * (37.0 + d2) else: tmp = d1 * (37.0 + d3) return tmp
function code(d1, d2, d3) tmp = 0.0 if (d2 <= -18500.0) tmp = Float64(d1 * Float64(37.0 + d2)); else tmp = Float64(d1 * Float64(37.0 + d3)); end return tmp end
function tmp_2 = code(d1, d2, d3) tmp = 0.0; if (d2 <= -18500.0) tmp = d1 * (37.0 + d2); else tmp = d1 * (37.0 + d3); end tmp_2 = tmp; end
code[d1_, d2_, d3_] := If[LessEqual[d2, -18500.0], N[(d1 * N[(37.0 + d2), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(37.0 + d3), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -18500:\\
\;\;\;\;d1 \cdot \left(37 + d2\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(37 + d3\right)\\
\end{array}
\end{array}
if d2 < -18500Initial program 100.0%
cancel-sign-sub100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft-out100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
associate-+r+100.0%
+-commutative100.0%
associate--l+100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-+l+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in d3 around 0 76.8%
if -18500 < d2 Initial program 97.8%
cancel-sign-sub97.8%
+-commutative97.8%
*-commutative97.8%
distribute-lft-out100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
associate-+r+100.0%
+-commutative100.0%
associate--l+99.9%
sub-neg99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-+l+99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in d2 around 0 74.8%
Final simplification75.3%
(FPCore (d1 d2 d3) :precision binary64 (* d1 37.0))
double code(double d1, double d2, double d3) {
return d1 * 37.0;
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
code = d1 * 37.0d0
end function
public static double code(double d1, double d2, double d3) {
return d1 * 37.0;
}
def code(d1, d2, d3): return d1 * 37.0
function code(d1, d2, d3) return Float64(d1 * 37.0) end
function tmp = code(d1, d2, d3) tmp = d1 * 37.0; end
code[d1_, d2_, d3_] := N[(d1 * 37.0), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot 37
\end{array}
Initial program 98.4%
cancel-sign-sub98.4%
+-commutative98.4%
*-commutative98.4%
distribute-lft-out100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
associate-+r+100.0%
+-commutative100.0%
associate--l+100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-+l+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in d3 around 0 63.3%
Taylor expanded in d2 around 0 24.0%
*-commutative24.0%
Simplified24.0%
Final simplification24.0%
(FPCore (d1 d2 d3) :precision binary64 (* d1 (+ (+ 37.0 d3) d2)))
double code(double d1, double d2, double d3) {
return d1 * ((37.0 + d3) + d2);
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
code = d1 * ((37.0d0 + d3) + d2)
end function
public static double code(double d1, double d2, double d3) {
return d1 * ((37.0 + d3) + d2);
}
def code(d1, d2, d3): return d1 * ((37.0 + d3) + d2)
function code(d1, d2, d3) return Float64(d1 * Float64(Float64(37.0 + d3) + d2)) end
function tmp = code(d1, d2, d3) tmp = d1 * ((37.0 + d3) + d2); end
code[d1_, d2_, d3_] := N[(d1 * N[(N[(37.0 + d3), $MachinePrecision] + d2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(\left(37 + d3\right) + d2\right)
\end{array}
herbie shell --seed 2024029
(FPCore (d1 d2 d3)
:name "FastMath dist3"
:precision binary64
:herbie-target
(* d1 (+ (+ 37.0 d3) d2))
(+ (+ (* d1 d2) (* (+ d3 5.0) d1)) (* d1 32.0)))