
(FPCore (x) :precision binary64 (sqrt (* (* 2.0 x) x)))
double code(double x) {
return sqrt(((2.0 * x) * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((2.0d0 * x) * x))
end function
public static double code(double x) {
return Math.sqrt(((2.0 * x) * x));
}
def code(x): return math.sqrt(((2.0 * x) * x))
function code(x) return sqrt(Float64(Float64(2.0 * x) * x)) end
function tmp = code(x) tmp = sqrt(((2.0 * x) * x)); end
code[x_] := N[Sqrt[N[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(2 \cdot x\right) \cdot x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (sqrt (* (* 2.0 x) x)))
double code(double x) {
return sqrt(((2.0 * x) * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((2.0d0 * x) * x))
end function
public static double code(double x) {
return Math.sqrt(((2.0 * x) * x));
}
def code(x): return math.sqrt(((2.0 * x) * x))
function code(x) return sqrt(Float64(Float64(2.0 * x) * x)) end
function tmp = code(x) tmp = sqrt(((2.0 * x) * x)); end
code[x_] := N[Sqrt[N[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(2 \cdot x\right) \cdot x}
\end{array}
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (* (sqrt (* x 2.0)) (sqrt x)))
x = abs(x);
double code(double x) {
return sqrt((x * 2.0)) * sqrt(x);
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x * 2.0d0)) * sqrt(x)
end function
x = Math.abs(x);
public static double code(double x) {
return Math.sqrt((x * 2.0)) * Math.sqrt(x);
}
x = abs(x) def code(x): return math.sqrt((x * 2.0)) * math.sqrt(x)
x = abs(x) function code(x) return Float64(sqrt(Float64(x * 2.0)) * sqrt(x)) end
x = abs(x) function tmp = code(x) tmp = sqrt((x * 2.0)) * sqrt(x); end
NOTE: x should be positive before calling this function code[x_] := N[(N[Sqrt[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\sqrt{x \cdot 2} \cdot \sqrt{x}
\end{array}
Initial program 55.6%
sqrt-prod49.0%
Applied egg-rr49.0%
*-commutative49.0%
Simplified49.0%
Final simplification49.0%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (* x (sqrt 2.0)))
x = abs(x);
double code(double x) {
return x * sqrt(2.0);
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = x * sqrt(2.0d0)
end function
x = Math.abs(x);
public static double code(double x) {
return x * Math.sqrt(2.0);
}
x = abs(x) def code(x): return x * math.sqrt(2.0)
x = abs(x) function code(x) return Float64(x * sqrt(2.0)) end
x = abs(x) function tmp = code(x) tmp = x * sqrt(2.0); end
NOTE: x should be positive before calling this function code[x_] := N[(x * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
x \cdot \sqrt{2}
\end{array}
Initial program 55.6%
associate-*l*55.6%
sqrt-prod55.3%
sqrt-unprod48.7%
add-sqr-sqrt50.1%
Applied egg-rr50.1%
Final simplification50.1%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 1.0)
x = abs(x);
double code(double x) {
return 1.0;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
x = Math.abs(x);
public static double code(double x) {
return 1.0;
}
x = abs(x) def code(x): return 1.0
x = abs(x) function code(x) return 1.0 end
x = abs(x) function tmp = code(x) tmp = 1.0; end
NOTE: x should be positive before calling this function code[x_] := 1.0
\begin{array}{l}
x = |x|\\
\\
1
\end{array}
Initial program 55.6%
rem-cube-cbrt54.7%
associate-*l*54.7%
sqrt-prod54.6%
sqrt-unprod48.2%
add-sqr-sqrt49.5%
*-commutative49.5%
Applied egg-rr49.5%
rem-cube-cbrt50.1%
*-commutative50.1%
add-sqr-sqrt50.0%
associate-*l*50.1%
pow1/250.1%
sqrt-pow150.1%
metadata-eval50.1%
pow1/250.1%
sqrt-pow150.1%
metadata-eval50.1%
Applied egg-rr50.1%
associate-*r*50.0%
*-commutative50.0%
pow-sqr50.1%
metadata-eval50.1%
pow1/250.1%
+-rgt-identity50.1%
metadata-eval50.1%
associate--l+29.1%
flip--18.8%
clear-num18.8%
*-un-lft-identity18.8%
associate-/l*18.8%
flip--29.0%
associate--l+50.1%
metadata-eval50.1%
+-rgt-identity50.1%
Applied egg-rr50.1%
/-rgt-identity50.1%
add-sqr-sqrt48.6%
associate-/l*48.7%
metadata-eval48.7%
sqrt-div48.8%
add-sqr-sqrt48.8%
sqrt-unprod28.9%
sqr-neg28.9%
sqrt-unprod0.0%
add-sqr-sqrt0.0%
add-exp-log0.0%
add-sqr-sqrt0.0%
sqrt-unprod27.3%
Applied egg-rr2.7%
*-inverses5.4%
Simplified5.4%
Final simplification5.4%
herbie shell --seed 2023301
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))