
(FPCore (x) :precision binary64 (sqrt (* 2 (pow x 2))))
double code(double x) {
return sqrt((2.0 * pow(x, 2.0)));
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt((2.0d0 * (x ** 2.0d0)))
end function
public static double code(double x) {
return Math.sqrt((2.0 * Math.pow(x, 2.0)));
}
def code(x): return math.sqrt((2.0 * math.pow(x, 2.0)))
function code(x) return sqrt(Float64(2.0 * (x ^ 2.0))) end
function tmp = code(x) tmp = sqrt((2.0 * (x ^ 2.0))); end
code[x_] := N[Sqrt[N[(2 * N[Power[x, 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{2 \cdot {x}^{2}}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (sqrt (* 2 (pow x 2))))
double code(double x) {
return sqrt((2.0 * pow(x, 2.0)));
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt((2.0d0 * (x ** 2.0d0)))
end function
public static double code(double x) {
return Math.sqrt((2.0 * Math.pow(x, 2.0)));
}
def code(x): return math.sqrt((2.0 * math.pow(x, 2.0)))
function code(x) return sqrt(Float64(2.0 * (x ^ 2.0))) end
function tmp = code(x) tmp = sqrt((2.0 * (x ^ 2.0))); end
code[x_] := N[Sqrt[N[(2 * N[Power[x, 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{2 \cdot {x}^{2}}
(FPCore (x) :precision binary64 (* (sqrt (fabs (+ x x))) (sqrt (fabs x))))
double code(double x) {
return sqrt(fabs((x + x))) * sqrt(fabs(x));
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt(abs((x + x))) * sqrt(abs(x))
end function
public static double code(double x) {
return Math.sqrt(Math.abs((x + x))) * Math.sqrt(Math.abs(x));
}
def code(x): return math.sqrt(math.fabs((x + x))) * math.sqrt(math.fabs(x))
function code(x) return Float64(sqrt(abs(Float64(x + x))) * sqrt(abs(x))) end
function tmp = code(x) tmp = sqrt(abs((x + x))) * sqrt(abs(x)); end
code[x_] := N[(N[Sqrt[N[Abs[N[(x + x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\sqrt{\left|x + x\right|} \cdot \sqrt{\left|x\right|}
Initial program 54.3%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*l*N/A
count-2-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-fabs.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-fabs.f6499.4%
Applied rewrites99.4%
(FPCore (x) :precision binary64 (/ (* (fabs x) 2) (sqrt 2)))
double code(double x) {
return (fabs(x) * 2.0) / sqrt(2.0);
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (abs(x) * 2.0d0) / sqrt(2.0d0)
end function
public static double code(double x) {
return (Math.abs(x) * 2.0) / Math.sqrt(2.0);
}
def code(x): return (math.fabs(x) * 2.0) / math.sqrt(2.0)
function code(x) return Float64(Float64(abs(x) * 2.0) / sqrt(2.0)) end
function tmp = code(x) tmp = (abs(x) * 2.0) / sqrt(2.0); end
code[x_] := N[(N[(N[Abs[x], $MachinePrecision] * 2), $MachinePrecision] / N[Sqrt[2], $MachinePrecision]), $MachinePrecision]
\frac{\left|x\right| \cdot 2}{\sqrt{2}}
Initial program 54.3%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-pow.f64N/A
unpow2N/A
fabs-sqrN/A
rem-sqrt-square-revN/A
lower-*.f64N/A
metadata-evalN/A
lower-sqrt.f64N/A
lower-fabs.f6499.3%
Applied rewrites99.3%
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lower-*.f6499.1%
Applied rewrites99.1%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrt99.3%
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-divN/A
metadata-evalN/A
pow1/2N/A
lift-sqrt.f64N/A
add-sound-/N/A
lower-/.f6499.1%
Applied rewrites99.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
add-sound-/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6499.3%
Applied rewrites99.3%
(FPCore (x) :precision binary64 (* (sqrt 2) (fabs x)))
double code(double x) {
return sqrt(2.0) * fabs(x);
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt(2.0d0) * abs(x)
end function
public static double code(double x) {
return Math.sqrt(2.0) * Math.abs(x);
}
def code(x): return math.sqrt(2.0) * math.fabs(x)
function code(x) return Float64(sqrt(2.0) * abs(x)) end
function tmp = code(x) tmp = sqrt(2.0) * abs(x); end
code[x_] := N[(N[Sqrt[2], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]
\sqrt{2} \cdot \left|x\right|
Initial program 54.3%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-pow.f64N/A
unpow2N/A
fabs-sqrN/A
rem-sqrt-square-revN/A
lower-*.f64N/A
metadata-evalN/A
lower-sqrt.f64N/A
lower-fabs.f6499.3%
Applied rewrites99.3%
herbie shell --seed 2025326 -o generate:taylor -o generate:evaluate
(FPCore (x)
:name "sqrt D (should all be same)"
:precision binary64
(sqrt (* 2 (pow x 2))))