
(FPCore (x) :precision binary64 (* (* x 3.0) x))
double code(double x) {
return (x * 3.0) * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 3.0d0) * x
end function
public static double code(double x) {
return (x * 3.0) * x;
}
def code(x): return (x * 3.0) * x
function code(x) return Float64(Float64(x * 3.0) * x) end
function tmp = code(x) tmp = (x * 3.0) * x; end
code[x_] := N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (* x 3.0) x))
double code(double x) {
return (x * 3.0) * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 3.0d0) * x
end function
public static double code(double x) {
return (x * 3.0) * x;
}
def code(x): return (x * 3.0) * x
function code(x) return Float64(Float64(x * 3.0) * x) end
function tmp = code(x) tmp = (x * 3.0) * x; end
code[x_] := N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot x
\end{array}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* x_m (sqrt (* (pow x_m 2.0) 9.0))))
x_m = fabs(x);
double code(double x_m) {
return x_m * sqrt((pow(x_m, 2.0) * 9.0));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m * sqrt(((x_m ** 2.0d0) * 9.0d0))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m * Math.sqrt((Math.pow(x_m, 2.0) * 9.0));
}
x_m = math.fabs(x) def code(x_m): return x_m * math.sqrt((math.pow(x_m, 2.0) * 9.0))
x_m = abs(x) function code(x_m) return Float64(x_m * sqrt(Float64((x_m ^ 2.0) * 9.0))) end
x_m = abs(x); function tmp = code(x_m) tmp = x_m * sqrt(((x_m ^ 2.0) * 9.0)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m * N[Sqrt[N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 9.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot \sqrt{{x\_m}^{2} \cdot 9}
\end{array}
Initial program 99.8%
pow199.8%
metadata-eval99.8%
metadata-eval99.8%
sqrt-pow177.9%
metadata-eval77.9%
pow277.9%
*-commutative77.9%
*-commutative77.9%
associate-*r*77.9%
associate-*r*77.9%
swap-sqr77.7%
pow277.7%
metadata-eval77.7%
pow-prod-down77.7%
pow-prod-up77.8%
metadata-eval77.8%
metadata-eval77.8%
metadata-eval77.8%
metadata-eval77.8%
Applied egg-rr77.8%
pow1/277.8%
metadata-eval77.8%
pow-sqr77.7%
associate-*l*77.9%
unpow-prod-down99.8%
pow-pow62.1%
metadata-eval62.1%
pow162.1%
Applied egg-rr62.1%
unpow1/262.1%
Simplified62.1%
Final simplification62.1%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (pow x_m 2.0) 3.0))
x_m = fabs(x);
double code(double x_m) {
return pow(x_m, 2.0) * 3.0;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (x_m ** 2.0d0) * 3.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(x_m, 2.0) * 3.0;
}
x_m = math.fabs(x) def code(x_m): return math.pow(x_m, 2.0) * 3.0
x_m = abs(x) function code(x_m) return Float64((x_m ^ 2.0) * 3.0) end
x_m = abs(x); function tmp = code(x_m) tmp = (x_m ^ 2.0) * 3.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 3.0), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{x\_m}^{2} \cdot 3
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* x_m (* x_m 3.0)))
x_m = fabs(x);
double code(double x_m) {
return x_m * (x_m * 3.0);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m * (x_m * 3.0d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m * (x_m * 3.0);
}
x_m = math.fabs(x) def code(x_m): return x_m * (x_m * 3.0)
x_m = abs(x) function code(x_m) return Float64(x_m * Float64(x_m * 3.0)) end
x_m = abs(x); function tmp = code(x_m) tmp = x_m * (x_m * 3.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m * N[(x$95$m * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot \left(x\_m \cdot 3\right)
\end{array}
Initial program 99.8%
Final simplification99.8%
herbie shell --seed 2024027
(FPCore (x)
:name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, F"
:precision binary64
(* (* x 3.0) x))