
(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 2 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-pow172.5%
metadata-eval72.5%
pow272.5%
*-commutative72.5%
*-commutative72.5%
associate-*r*72.5%
associate-*r*72.4%
swap-sqr72.4%
pow272.4%
metadata-eval72.4%
pow-prod-down72.4%
pow-prod-up72.5%
metadata-eval72.5%
metadata-eval72.5%
metadata-eval72.5%
metadata-eval72.5%
Applied egg-rr72.5%
pow1/272.5%
metadata-eval72.5%
pow-sqr72.4%
associate-*l*72.4%
unpow-prod-down99.8%
pow-pow67.1%
metadata-eval67.1%
pow167.1%
Applied egg-rr67.1%
unpow1/267.1%
Simplified67.1%
Final simplification67.1%
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 2024019
(FPCore (x)
:name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, F"
:precision binary64
(* (* x 3.0) x))