
(FPCore (x) :precision binary64 (sqrt (* 2 (* x x))))
double code(double x) {
return sqrt((2.0 * (x * x)));
}
real(8) function code(x)
use fmin_fmax_functions
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(2.0 * Float64(x * x))) end
function tmp = code(x) tmp = sqrt((2.0 * (x * x))); end
code[x_] := N[Sqrt[N[(2 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{2 \cdot \left(x \cdot x\right)}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (sqrt (* 2 (* x x))))
double code(double x) {
return sqrt((2.0 * (x * x)));
}
real(8) function code(x)
use fmin_fmax_functions
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(2.0 * Float64(x * x))) end
function tmp = code(x) tmp = sqrt((2.0 * (x * x))); end
code[x_] := N[Sqrt[N[(2 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{2 \cdot \left(x \cdot x\right)}
(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 55.0%
lift-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
metadata-evalN/A
pow-plus-revN/A
associate-*l*N/A
*-commutativeN/A
count-2-revN/A
count-2-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-fabs.f64N/A
lower-pow.f64N/A
lower-sqrt.f64N/A
lower-fabs.f64N/A
count-2-revN/A
lower-+.f6499.4%
Applied rewrites99.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.4%
lift-fabs.f64N/A
lift-pow.f64N/A
unpow1N/A
lift-fabs.f6499.4%
Applied rewrites99.4%
(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 55.0%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-*.f64N/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%
(FPCore (x) :precision binary64 (sqrt (fabs (+ x x))))
double code(double x) {
return sqrt(fabs((x + x)));
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt(abs((x + x)))
end function
public static double code(double x) {
return Math.sqrt(Math.abs((x + x)));
}
def code(x): return math.sqrt(math.fabs((x + x)))
function code(x) return sqrt(abs(Float64(x + x))) end
function tmp = code(x) tmp = sqrt(abs((x + x))); end
code[x_] := N[Sqrt[N[Abs[N[(x + x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\sqrt{\left|x + x\right|}
Initial program 55.0%
lift-*.f64N/A
count-2-revN/A
rem-square-sqrtN/A
sqrt-unprodN/A
rem-square-sqrtN/A
sqrt-unprodN/A
flip-+N/A
+-inversesN/A
rem-sqrt-square-revN/A
lift-*.f64N/A
mul-fabsN/A
sqr-abs-revN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lift-*.f64N/A
mul-fabsN/A
sqr-abs-revN/A
lift-*.f64N/A
+-inversesN/A
lower-/.f320.0%
lower-/.f32N/A
+-inversesN/A
+-inversesN/A
Applied rewrites7.0%
herbie shell --seed 2025326 -o generate:taylor -o generate:evaluate
(FPCore (x)
:name "sqrt C (should all be same)"
:precision binary64
(sqrt (* 2 (* x x))))