
(FPCore (x) :precision binary64 (sqrt (+ (* x x) (* x x))))
double code(double x) {
return sqrt(((x * x) + (x * x)));
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt(((x * x) + (x * x)))
end function
public static double code(double x) {
return Math.sqrt(((x * x) + (x * x)));
}
def code(x): return math.sqrt(((x * x) + (x * x)))
function code(x) return sqrt(Float64(Float64(x * x) + Float64(x * x))) end
function tmp = code(x) tmp = sqrt(((x * x) + (x * x))); end
code[x_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{x \cdot x + x \cdot x}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (sqrt (+ (* x x) (* x x))))
double code(double x) {
return sqrt(((x * x) + (x * x)));
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt(((x * x) + (x * x)))
end function
public static double code(double x) {
return Math.sqrt(((x * x) + (x * x)));
}
def code(x): return math.sqrt(((x * x) + (x * x)))
function code(x) return sqrt(Float64(Float64(x * x) + Float64(x * x))) end
function tmp = code(x) tmp = sqrt(((x * x) + (x * x))); end
code[x_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{x \cdot x + x \cdot x}
(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%
Applied rewrites99.4%
(FPCore (x) :precision binary64 (/ (* 2 (fabs x)) (sqrt 2)))
double code(double x) {
return (2.0 * fabs(x)) / sqrt(2.0);
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (2.0d0 * abs(x)) / sqrt(2.0d0)
end function
public static double code(double x) {
return (2.0 * Math.abs(x)) / Math.sqrt(2.0);
}
def code(x): return (2.0 * math.fabs(x)) / math.sqrt(2.0)
function code(x) return Float64(Float64(2.0 * abs(x)) / sqrt(2.0)) end
function tmp = code(x) tmp = (2.0 * abs(x)) / sqrt(2.0); end
code[x_] := N[(N[(2 * N[Abs[x], $MachinePrecision]), $MachinePrecision] / N[Sqrt[2], $MachinePrecision]), $MachinePrecision]
\frac{2 \cdot \left|x\right|}{\sqrt{2}}
Initial program 54.3%
lift-sqrt.f64N/A
lift-+.f64N/A
count-2N/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%
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
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
count-2N/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%
herbie shell --seed 2025326 -o generate:taylor -o generate:evaluate
(FPCore (x)
:name "sqrt A (should all be same)"
:precision binary64
(sqrt (+ (* x x) (* x x))))