
(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 (* x_m (* x_m 9.0)))))
x_m = fabs(x);
double code(double x_m) {
return x_m * sqrt((x_m * (x_m * 9.0)));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m * sqrt((x_m * (x_m * 9.0d0)))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m * Math.sqrt((x_m * (x_m * 9.0)));
}
x_m = math.fabs(x) def code(x_m): return x_m * math.sqrt((x_m * (x_m * 9.0)))
x_m = abs(x) function code(x_m) return Float64(x_m * sqrt(Float64(x_m * Float64(x_m * 9.0)))) end
x_m = abs(x); function tmp = code(x_m) tmp = x_m * sqrt((x_m * (x_m * 9.0))); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m * N[Sqrt[N[(x$95$m * N[(x$95$m * 9.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot \sqrt{x\_m \cdot \left(x\_m \cdot 9\right)}
\end{array}
Initial program 99.8%
*-commutative99.8%
associate-*r*99.7%
add-sqr-sqrt48.6%
associate-*r*48.6%
add-sqr-sqrt48.5%
associate-*l*48.5%
sqrt-unprod48.7%
sqrt-prod43.2%
pow343.2%
sqrt-pow148.7%
metadata-eval48.7%
pow1/248.7%
Applied egg-rr48.7%
add-sqr-sqrt48.6%
sqrt-unprod48.7%
swap-sqr48.7%
unpow1/248.7%
unpow1/248.7%
add-sqr-sqrt48.7%
metadata-eval48.7%
Applied egg-rr48.7%
add-sqr-sqrt48.5%
sqrt-unprod39.6%
swap-sqr39.6%
pow-prod-up39.6%
metadata-eval39.6%
pow339.6%
add-sqr-sqrt78.7%
associate-*l*78.5%
associate-*r*78.5%
associate-*l*78.6%
sqrt-prod99.7%
sqrt-prod48.6%
add-sqr-sqrt61.5%
associate-*l*61.5%
Applied egg-rr61.5%
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 2024097
(FPCore (x)
:name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, F"
:precision binary64
(* (* x 3.0) x))