
(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 (* (+ d2 (+ 37.0 d3)) d1))
double code(double d1, double d2, double d3) {
return (d2 + (37.0 + d3)) * d1;
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
code = (d2 + (37.0d0 + d3)) * d1
end function
public static double code(double d1, double d2, double d3) {
return (d2 + (37.0 + d3)) * d1;
}
def code(d1, d2, d3): return (d2 + (37.0 + d3)) * d1
function code(d1, d2, d3) return Float64(Float64(d2 + Float64(37.0 + d3)) * d1) end
function tmp = code(d1, d2, d3) tmp = (d2 + (37.0 + d3)) * d1; end
code[d1_, d2_, d3_] := N[(N[(d2 + N[(37.0 + d3), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]
\begin{array}{l}
\\
\left(d2 + \left(37 + d3\right)\right) \cdot d1
\end{array}
Initial program 96.4%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
distribute-lft-outN/A
lift-*.f64N/A
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lower-+.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (d1 d2 d3)
:precision binary64
(let* ((t_0 (* (+ d2 37.0) d1))
(t_1 (+ (* 32.0 d1) (+ (* (+ 5.0 d3) d1) (* d2 d1)))))
(if (<= t_1 -2e-235) t_0 (if (<= t_1 INFINITY) (* (- d3 -37.0) d1) t_0))))
double code(double d1, double d2, double d3) {
double t_0 = (d2 + 37.0) * d1;
double t_1 = (32.0 * d1) + (((5.0 + d3) * d1) + (d2 * d1));
double tmp;
if (t_1 <= -2e-235) {
tmp = t_0;
} else if (t_1 <= ((double) INFINITY)) {
tmp = (d3 - -37.0) * d1;
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double d1, double d2, double d3) {
double t_0 = (d2 + 37.0) * d1;
double t_1 = (32.0 * d1) + (((5.0 + d3) * d1) + (d2 * d1));
double tmp;
if (t_1 <= -2e-235) {
tmp = t_0;
} else if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = (d3 - -37.0) * d1;
} else {
tmp = t_0;
}
return tmp;
}
def code(d1, d2, d3): t_0 = (d2 + 37.0) * d1 t_1 = (32.0 * d1) + (((5.0 + d3) * d1) + (d2 * d1)) tmp = 0 if t_1 <= -2e-235: tmp = t_0 elif t_1 <= math.inf: tmp = (d3 - -37.0) * d1 else: tmp = t_0 return tmp
function code(d1, d2, d3) t_0 = Float64(Float64(d2 + 37.0) * d1) t_1 = Float64(Float64(32.0 * d1) + Float64(Float64(Float64(5.0 + d3) * d1) + Float64(d2 * d1))) tmp = 0.0 if (t_1 <= -2e-235) tmp = t_0; elseif (t_1 <= Inf) tmp = Float64(Float64(d3 - -37.0) * d1); else tmp = t_0; end return tmp end
function tmp_2 = code(d1, d2, d3) t_0 = (d2 + 37.0) * d1; t_1 = (32.0 * d1) + (((5.0 + d3) * d1) + (d2 * d1)); tmp = 0.0; if (t_1 <= -2e-235) tmp = t_0; elseif (t_1 <= Inf) tmp = (d3 - -37.0) * d1; else tmp = t_0; end tmp_2 = tmp; end
code[d1_, d2_, d3_] := Block[{t$95$0 = N[(N[(d2 + 37.0), $MachinePrecision] * d1), $MachinePrecision]}, Block[{t$95$1 = N[(N[(32.0 * d1), $MachinePrecision] + N[(N[(N[(5.0 + d3), $MachinePrecision] * d1), $MachinePrecision] + N[(d2 * d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-235], t$95$0, If[LessEqual[t$95$1, Infinity], N[(N[(d3 - -37.0), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(d2 + 37\right) \cdot d1\\
t_1 := 32 \cdot d1 + \left(\left(5 + d3\right) \cdot d1 + d2 \cdot d1\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{-235}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\left(d3 - -37\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 d1 d2) (*.f64 (+.f64 d3 #s(literal 5 binary64)) d1)) (*.f64 d1 #s(literal 32 binary64))) < -1.9999999999999999e-235 or +inf.0 < (+.f64 (+.f64 (*.f64 d1 d2) (*.f64 (+.f64 d3 #s(literal 5 binary64)) d1)) (*.f64 d1 #s(literal 32 binary64))) Initial program 92.3%
Taylor expanded in d3 around 0
associate-+r+N/A
distribute-rgt-outN/A
metadata-evalN/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6464.8
Applied rewrites64.8%
if -1.9999999999999999e-235 < (+.f64 (+.f64 (*.f64 d1 d2) (*.f64 (+.f64 d3 #s(literal 5 binary64)) d1)) (*.f64 d1 #s(literal 32 binary64))) < +inf.0Initial program 99.9%
Taylor expanded in d2 around 0
+-commutativeN/A
*-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-+l+N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sub-negN/A
lower--.f64N/A
metadata-evalN/A
metadata-eval67.4
Applied rewrites67.4%
Final simplification66.2%
(FPCore (d1 d2 d3) :precision binary64 (let* ((t_0 (+ (* 32.0 d1) (+ (* (+ 5.0 d3) d1) (* d2 d1))))) (if (<= t_0 2e-281) (* d2 d1) (if (<= t_0 INFINITY) (* d3 d1) (* d2 d1)))))
double code(double d1, double d2, double d3) {
double t_0 = (32.0 * d1) + (((5.0 + d3) * d1) + (d2 * d1));
double tmp;
if (t_0 <= 2e-281) {
tmp = d2 * d1;
} else if (t_0 <= ((double) INFINITY)) {
tmp = d3 * d1;
} else {
tmp = d2 * d1;
}
return tmp;
}
public static double code(double d1, double d2, double d3) {
double t_0 = (32.0 * d1) + (((5.0 + d3) * d1) + (d2 * d1));
double tmp;
if (t_0 <= 2e-281) {
tmp = d2 * d1;
} else if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = d3 * d1;
} else {
tmp = d2 * d1;
}
return tmp;
}
def code(d1, d2, d3): t_0 = (32.0 * d1) + (((5.0 + d3) * d1) + (d2 * d1)) tmp = 0 if t_0 <= 2e-281: tmp = d2 * d1 elif t_0 <= math.inf: tmp = d3 * d1 else: tmp = d2 * d1 return tmp
function code(d1, d2, d3) t_0 = Float64(Float64(32.0 * d1) + Float64(Float64(Float64(5.0 + d3) * d1) + Float64(d2 * d1))) tmp = 0.0 if (t_0 <= 2e-281) tmp = Float64(d2 * d1); elseif (t_0 <= Inf) tmp = Float64(d3 * d1); else tmp = Float64(d2 * d1); end return tmp end
function tmp_2 = code(d1, d2, d3) t_0 = (32.0 * d1) + (((5.0 + d3) * d1) + (d2 * d1)); tmp = 0.0; if (t_0 <= 2e-281) tmp = d2 * d1; elseif (t_0 <= Inf) tmp = d3 * d1; else tmp = d2 * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_] := Block[{t$95$0 = N[(N[(32.0 * d1), $MachinePrecision] + N[(N[(N[(5.0 + d3), $MachinePrecision] * d1), $MachinePrecision] + N[(d2 * d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-281], N[(d2 * d1), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(d3 * d1), $MachinePrecision], N[(d2 * d1), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 32 \cdot d1 + \left(\left(5 + d3\right) \cdot d1 + d2 \cdot d1\right)\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{-281}:\\
\;\;\;\;d2 \cdot d1\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;d3 \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d2 \cdot d1\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 d1 d2) (*.f64 (+.f64 d3 #s(literal 5 binary64)) d1)) (*.f64 d1 #s(literal 32 binary64))) < 2e-281 or +inf.0 < (+.f64 (+.f64 (*.f64 d1 d2) (*.f64 (+.f64 d3 #s(literal 5 binary64)) d1)) (*.f64 d1 #s(literal 32 binary64))) Initial program 92.7%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6438.2
Applied rewrites38.2%
if 2e-281 < (+.f64 (+.f64 (*.f64 d1 d2) (*.f64 (+.f64 d3 #s(literal 5 binary64)) d1)) (*.f64 d1 #s(literal 32 binary64))) < +inf.0Initial program 99.9%
Taylor expanded in d3 around inf
*-commutativeN/A
lower-*.f6445.2
Applied rewrites45.2%
Final simplification41.8%
(FPCore (d1 d2 d3) :precision binary64 (if (<= d2 -75000.0) (* d2 d1) (if (<= d2 3.2e-193) (* 37.0 d1) (* d3 d1))))
double code(double d1, double d2, double d3) {
double tmp;
if (d2 <= -75000.0) {
tmp = d2 * d1;
} else if (d2 <= 3.2e-193) {
tmp = 37.0 * d1;
} else {
tmp = d3 * d1;
}
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 <= (-75000.0d0)) then
tmp = d2 * d1
else if (d2 <= 3.2d-193) then
tmp = 37.0d0 * d1
else
tmp = d3 * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3) {
double tmp;
if (d2 <= -75000.0) {
tmp = d2 * d1;
} else if (d2 <= 3.2e-193) {
tmp = 37.0 * d1;
} else {
tmp = d3 * d1;
}
return tmp;
}
def code(d1, d2, d3): tmp = 0 if d2 <= -75000.0: tmp = d2 * d1 elif d2 <= 3.2e-193: tmp = 37.0 * d1 else: tmp = d3 * d1 return tmp
function code(d1, d2, d3) tmp = 0.0 if (d2 <= -75000.0) tmp = Float64(d2 * d1); elseif (d2 <= 3.2e-193) tmp = Float64(37.0 * d1); else tmp = Float64(d3 * d1); end return tmp end
function tmp_2 = code(d1, d2, d3) tmp = 0.0; if (d2 <= -75000.0) tmp = d2 * d1; elseif (d2 <= 3.2e-193) tmp = 37.0 * d1; else tmp = d3 * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_] := If[LessEqual[d2, -75000.0], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, 3.2e-193], N[(37.0 * d1), $MachinePrecision], N[(d3 * d1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -75000:\\
\;\;\;\;d2 \cdot d1\\
\mathbf{elif}\;d2 \leq 3.2 \cdot 10^{-193}:\\
\;\;\;\;37 \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d3 \cdot d1\\
\end{array}
\end{array}
if d2 < -75000Initial program 90.2%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6479.3
Applied rewrites79.3%
if -75000 < d2 < 3.20000000000000006e-193Initial program 99.9%
Taylor expanded in d3 around 0
associate-+r+N/A
distribute-rgt-outN/A
metadata-evalN/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6450.3
Applied rewrites50.3%
Taylor expanded in d2 around 0
Applied rewrites50.3%
if 3.20000000000000006e-193 < d2 Initial program 97.1%
Taylor expanded in d3 around inf
*-commutativeN/A
lower-*.f6442.1
Applied rewrites42.1%
(FPCore (d1 d2 d3) :precision binary64 (if (<= (+ 5.0 d3) 100000.0) (* (+ d2 37.0) d1) (* d3 d1)))
double code(double d1, double d2, double d3) {
double tmp;
if ((5.0 + d3) <= 100000.0) {
tmp = (d2 + 37.0) * d1;
} else {
tmp = d3 * d1;
}
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 ((5.0d0 + d3) <= 100000.0d0) then
tmp = (d2 + 37.0d0) * d1
else
tmp = d3 * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3) {
double tmp;
if ((5.0 + d3) <= 100000.0) {
tmp = (d2 + 37.0) * d1;
} else {
tmp = d3 * d1;
}
return tmp;
}
def code(d1, d2, d3): tmp = 0 if (5.0 + d3) <= 100000.0: tmp = (d2 + 37.0) * d1 else: tmp = d3 * d1 return tmp
function code(d1, d2, d3) tmp = 0.0 if (Float64(5.0 + d3) <= 100000.0) tmp = Float64(Float64(d2 + 37.0) * d1); else tmp = Float64(d3 * d1); end return tmp end
function tmp_2 = code(d1, d2, d3) tmp = 0.0; if ((5.0 + d3) <= 100000.0) tmp = (d2 + 37.0) * d1; else tmp = d3 * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_] := If[LessEqual[N[(5.0 + d3), $MachinePrecision], 100000.0], N[(N[(d2 + 37.0), $MachinePrecision] * d1), $MachinePrecision], N[(d3 * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;5 + d3 \leq 100000:\\
\;\;\;\;\left(d2 + 37\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d3 \cdot d1\\
\end{array}
\end{array}
if (+.f64 d3 #s(literal 5 binary64)) < 1e5Initial program 97.8%
Taylor expanded in d3 around 0
associate-+r+N/A
distribute-rgt-outN/A
metadata-evalN/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6472.8
Applied rewrites72.8%
if 1e5 < (+.f64 d3 #s(literal 5 binary64)) Initial program 92.6%
Taylor expanded in d3 around inf
*-commutativeN/A
lower-*.f6474.5
Applied rewrites74.5%
Final simplification73.2%
(FPCore (d1 d2 d3) :precision binary64 (* d2 d1))
double code(double d1, double d2, double d3) {
return d2 * d1;
}
real(8) function code(d1, d2, d3)
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
code = d2 * d1
end function
public static double code(double d1, double d2, double d3) {
return d2 * d1;
}
def code(d1, d2, d3): return d2 * d1
function code(d1, d2, d3) return Float64(d2 * d1) end
function tmp = code(d1, d2, d3) tmp = d2 * d1; end
code[d1_, d2_, d3_] := N[(d2 * d1), $MachinePrecision]
\begin{array}{l}
\\
d2 \cdot d1
\end{array}
Initial program 96.4%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6437.0
Applied rewrites37.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 2024272
(FPCore (d1 d2 d3)
:name "FastMath dist3"
:precision binary64
:alt
(! :herbie-platform default (* d1 (+ 37 d3 d2)))
(+ (+ (* d1 d2) (* (+ d3 5.0) d1)) (* d1 32.0)))