(FPCore (a b c d) :precision binary64 (+ (+ (+ (sqrt a) (sqrt b)) (sqrt c)) (sqrt d)))
double code(double a, double b, double c, double d) { return ((sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d); }
real(8) function code(a, b, c, d) real(8), intent (in) :: a real(8), intent (in) :: b real(8), intent (in) :: c real(8), intent (in) :: d code = ((sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d) end function
public static double code(double a, double b, double c, double d) { return ((Math.sqrt(a) + Math.sqrt(b)) + Math.sqrt(c)) + Math.sqrt(d); }
def code(a, b, c, d): return ((math.sqrt(a) + math.sqrt(b)) + math.sqrt(c)) + math.sqrt(d)
function code(a, b, c, d) return Float64(Float64(Float64(sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d)) end
function tmp = code(a, b, c, d) tmp = ((sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d); end
code[a_, b_, c_, d_] := N[(N[(N[(N[Sqrt[a], $MachinePrecision] + N[Sqrt[b], $MachinePrecision]), $MachinePrecision] + N[Sqrt[c], $MachinePrecision]), $MachinePrecision] + N[Sqrt[d], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\left(\sqrt{a} + \sqrt{b}\right) + \sqrt{c}\right) + \sqrt{d} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (a b c d) :precision binary64 (+ (+ (+ (sqrt a) (sqrt b)) (sqrt c)) (sqrt d)))
double code(double a, double b, double c, double d) { return ((sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d); }
real(8) function code(a, b, c, d) real(8), intent (in) :: a real(8), intent (in) :: b real(8), intent (in) :: c real(8), intent (in) :: d code = ((sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d) end function
public static double code(double a, double b, double c, double d) { return ((Math.sqrt(a) + Math.sqrt(b)) + Math.sqrt(c)) + Math.sqrt(d); }
def code(a, b, c, d): return ((math.sqrt(a) + math.sqrt(b)) + math.sqrt(c)) + math.sqrt(d)
function code(a, b, c, d) return Float64(Float64(Float64(sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d)) end
function tmp = code(a, b, c, d) tmp = ((sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d); end
code[a_, b_, c_, d_] := N[(N[(N[(N[Sqrt[a], $MachinePrecision] + N[Sqrt[b], $MachinePrecision]), $MachinePrecision] + N[Sqrt[c], $MachinePrecision]), $MachinePrecision] + N[Sqrt[d], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\left(\sqrt{a} + \sqrt{b}\right) + \sqrt{c}\right) + \sqrt{d} \end{array}
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. (FPCore (a b c d) :precision binary64 (+ (+ (+ (sqrt a) (sqrt b)) (sqrt c)) (sqrt d)))
assert(a < b && b < c && c < d); double code(double a, double b, double c, double d) { return ((sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d); }
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. real(8) function code(a, b, c, d) real(8), intent (in) :: a real(8), intent (in) :: b real(8), intent (in) :: c real(8), intent (in) :: d code = ((sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d) end function
assert a < b && b < c && c < d; public static double code(double a, double b, double c, double d) { return ((Math.sqrt(a) + Math.sqrt(b)) + Math.sqrt(c)) + Math.sqrt(d); }
[a, b, c, d] = sort([a, b, c, d]) def code(a, b, c, d): return ((math.sqrt(a) + math.sqrt(b)) + math.sqrt(c)) + math.sqrt(d)
a, b, c, d = sort([a, b, c, d]) function code(a, b, c, d) return Float64(Float64(Float64(sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d)) end
a, b, c, d = num2cell(sort([a, b, c, d])){:} function tmp = code(a, b, c, d) tmp = ((sqrt(a) + sqrt(b)) + sqrt(c)) + sqrt(d); end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. code[a_, b_, c_, d_] := N[(N[(N[(N[Sqrt[a], $MachinePrecision] + N[Sqrt[b], $MachinePrecision]), $MachinePrecision] + N[Sqrt[c], $MachinePrecision]), $MachinePrecision] + N[Sqrt[d], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} [a, b, c, d] = \mathsf{sort}([a, b, c, d])\\ \\ \left(\left(\sqrt{a} + \sqrt{b}\right) + \sqrt{c}\right) + \sqrt{d} \end{array}
Initial program 99.9%
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. (FPCore (a b c d) :precision binary64 (+ (+ (sqrt d) (sqrt b)) (sqrt a)))
assert(a < b && b < c && c < d); double code(double a, double b, double c, double d) { return (sqrt(d) + sqrt(b)) + sqrt(a); }
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. real(8) function code(a, b, c, d) real(8), intent (in) :: a real(8), intent (in) :: b real(8), intent (in) :: c real(8), intent (in) :: d code = (sqrt(d) + sqrt(b)) + sqrt(a) end function
assert a < b && b < c && c < d; public static double code(double a, double b, double c, double d) { return (Math.sqrt(d) + Math.sqrt(b)) + Math.sqrt(a); }
[a, b, c, d] = sort([a, b, c, d]) def code(a, b, c, d): return (math.sqrt(d) + math.sqrt(b)) + math.sqrt(a)
a, b, c, d = sort([a, b, c, d]) function code(a, b, c, d) return Float64(Float64(sqrt(d) + sqrt(b)) + sqrt(a)) end
a, b, c, d = num2cell(sort([a, b, c, d])){:} function tmp = code(a, b, c, d) tmp = (sqrt(d) + sqrt(b)) + sqrt(a); end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. code[a_, b_, c_, d_] := N[(N[(N[Sqrt[d], $MachinePrecision] + N[Sqrt[b], $MachinePrecision]), $MachinePrecision] + N[Sqrt[a], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} [a, b, c, d] = \mathsf{sort}([a, b, c, d])\\ \\ \left(\sqrt{d} + \sqrt{b}\right) + \sqrt{a} \end{array}
Initial program 99.9%
lift-+.f64
N/A
lift-+.f64
N/A
associate-+l+
N/A
+-commutative
N/A
flip-+
N/A
div-inv
N/A
lower-fma.f64
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
lower--.f64
N/A
metadata-eval
N/A
lower-/.f64
N/A
metadata-eval
N/A
lower--.f64
99.6
Applied rewrites99.6%
Taylor expanded in d around inf
cancel-sign-sub-inv
N/A
metadata-eval
N/A
*-lft-identity
N/A
associate-+r+
N/A
+-commutative
N/A
lower-+.f64
N/A
+-commutative
N/A
lower-+.f64
N/A
lower-sqrt.f64
N/A
lower-sqrt.f64
N/A
lower-sqrt.f64
74.4
Applied rewrites74.4%
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. (FPCore (a b c d) :precision binary64 (sqrt d))
assert(a < b && b < c && c < d); double code(double a, double b, double c, double d) { return sqrt(d); }
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. real(8) function code(a, b, c, d) real(8), intent (in) :: a real(8), intent (in) :: b real(8), intent (in) :: c real(8), intent (in) :: d code = sqrt(d) end function
assert a < b && b < c && c < d; public static double code(double a, double b, double c, double d) { return Math.sqrt(d); }
[a, b, c, d] = sort([a, b, c, d]) def code(a, b, c, d): return math.sqrt(d)
a, b, c, d = sort([a, b, c, d]) function code(a, b, c, d) return sqrt(d) end
a, b, c, d = num2cell(sort([a, b, c, d])){:} function tmp = code(a, b, c, d) tmp = sqrt(d); end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function. code[a_, b_, c_, d_] := N[Sqrt[d], $MachinePrecision]
\begin{array}{l} [a, b, c, d] = \mathsf{sort}([a, b, c, d])\\ \\ \sqrt{d} \end{array}
Initial program 99.9%
Taylor expanded in d around inf
lower-sqrt.f64
29.4
Applied rewrites29.4%
herbie shell --seed 1
(FPCore (a b c d)
:name "sqrt(a) + sqrt(b) + sqrt(c ) + sqrt(d)"
:precision binary64
:pre (and (and (and (and (<= -1.79e+308 a) (<= a 1.79e+308)) (and (<= -1.79e+308 b) (<= b 1.79e+308))) (and (<= -1.79e+308 c) (<= c 1.79e+308))) (and (<= -1.79e+308 d) (<= d 1.79e+308)))
(+ (+ (+ (sqrt a) (sqrt b)) (sqrt c)) (sqrt d)))