
(FPCore (x y) :precision binary64 :pre TRUE (sqrt (+ (* x x) y)))
double code(double x, double y) {
return sqrt(((x * x) + y));
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(((x * x) + y))
end function
public static double code(double x, double y) {
return Math.sqrt(((x * x) + y));
}
def code(x, y): return math.sqrt(((x * x) + y))
function code(x, y) return sqrt(Float64(Float64(x * x) + y)) end
function tmp = code(x, y) tmp = sqrt(((x * x) + y)); end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = sqrt(((x * x) + y)) END code
\sqrt{x \cdot x + y}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (sqrt (+ (* x x) y)))
double code(double x, double y) {
return sqrt(((x * x) + y));
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(((x * x) + y))
end function
public static double code(double x, double y) {
return Math.sqrt(((x * x) + y));
}
def code(x, y): return math.sqrt(((x * x) + y))
function code(x, y) return sqrt(Float64(Float64(x * x) + y)) end
function tmp = code(x, y) tmp = sqrt(((x * x) + y)); end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = sqrt(((x * x) + y)) END code
\sqrt{x \cdot x + y}
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (* (fabs x) (fabs x)) 1e+200) (sqrt (fma (fabs x) (fabs x) y)) (* (fabs x) 1.0)))
double code(double x, double y) {
double tmp;
if ((fabs(x) * fabs(x)) <= 1e+200) {
tmp = sqrt(fma(fabs(x), fabs(x), y));
} else {
tmp = fabs(x) * 1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(abs(x) * abs(x)) <= 1e+200) tmp = sqrt(fma(abs(x), abs(x), y)); else tmp = Float64(abs(x) * 1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision], 1e+200], N[Sqrt[N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision] + y), $MachinePrecision]], $MachinePrecision], N[(N[Abs[x], $MachinePrecision] * 1.0), $MachinePrecision]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF (((abs(x)) * (abs(x))) <= (99999999999999996973312221251036165947450327545502362648241750950346848435554075534196338404706251868027512415973882408182135734368278484639385041047239877871023591066789981811181813306167128854888448)) THEN (sqrt((((abs(x)) * (abs(x))) + y))) ELSE ((abs(x)) * (1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\left|x\right| \cdot \left|x\right| \leq 10^{+200}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\left|x\right|, \left|x\right|, y\right)}\\
\mathbf{else}:\\
\;\;\;\;\left|x\right| \cdot 1\\
\end{array}
if (*.f64 x x) < 9.9999999999999997e199Initial program 68.9%
Applied rewrites68.9%
if 9.9999999999999997e199 < (*.f64 x x) Initial program 68.9%
Taylor expanded in x around inf
Applied rewrites34.4%
Taylor expanded in x around inf
Applied rewrites34.4%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (* (fabs x) (fabs x)) 2e-99) (sqrt y) (* (fabs x) 1.0)))
double code(double x, double y) {
double tmp;
if ((fabs(x) * fabs(x)) <= 2e-99) {
tmp = sqrt(y);
} else {
tmp = fabs(x) * 1.0;
}
return tmp;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((abs(x) * abs(x)) <= 2d-99) then
tmp = sqrt(y)
else
tmp = abs(x) * 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((Math.abs(x) * Math.abs(x)) <= 2e-99) {
tmp = Math.sqrt(y);
} else {
tmp = Math.abs(x) * 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (math.fabs(x) * math.fabs(x)) <= 2e-99: tmp = math.sqrt(y) else: tmp = math.fabs(x) * 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(abs(x) * abs(x)) <= 2e-99) tmp = sqrt(y); else tmp = Float64(abs(x) * 1.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((abs(x) * abs(x)) <= 2e-99) tmp = sqrt(y); else tmp = abs(x) * 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision], 2e-99], N[Sqrt[y], $MachinePrecision], N[(N[Abs[x], $MachinePrecision] * 1.0), $MachinePrecision]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF (((abs(x)) * (abs(x))) <= (20000000000000000399837996052057672392955215770683188403652060118731913985110869352353525772265859791654921496218237015970565410794993080445368720839225272167125662825574358854498578849381613317832611860008691572046029005015889997371182867751115974641606953809969127178192138671875e-379)) THEN (sqrt(y)) ELSE ((abs(x)) * (1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\left|x\right| \cdot \left|x\right| \leq 2 \cdot 10^{-99}:\\
\;\;\;\;\sqrt{y}\\
\mathbf{else}:\\
\;\;\;\;\left|x\right| \cdot 1\\
\end{array}
if (*.f64 x x) < 2e-99Initial program 68.9%
Taylor expanded in x around 0
Applied rewrites34.6%
if 2e-99 < (*.f64 x x) Initial program 68.9%
Taylor expanded in x around inf
Applied rewrites34.4%
Taylor expanded in x around inf
Applied rewrites34.4%
(FPCore (x y) :precision binary64 :pre TRUE (sqrt y))
double code(double x, double y) {
return sqrt(y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(y)
end function
public static double code(double x, double y) {
return Math.sqrt(y);
}
def code(x, y): return math.sqrt(y)
function code(x, y) return sqrt(y) end
function tmp = code(x, y) tmp = sqrt(y); end
code[x_, y_] := N[Sqrt[y], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = sqrt(y) END code
\sqrt{y}
Initial program 68.9%
Taylor expanded in x around 0
Applied rewrites34.6%
(FPCore (x y) :precision binary64 :pre TRUE (- 0.0))
double code(double x, double y) {
return -0.0;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -0.0d0
end function
public static double code(double x, double y) {
return -0.0;
}
def code(x, y): return -0.0
function code(x, y) return Float64(-0.0) end
function tmp = code(x, y) tmp = -0.0; end
code[x_, y_] := (-0.0)
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = - (0) END code
-0
Initial program 68.9%
Taylor expanded in x around -inf
Applied rewrites34.7%
Applied rewrites34.7%
Taylor expanded in undef-var around zero
Applied rewrites2.6%
(FPCore (x y) :precision binary64 :pre TRUE (- x))
double code(double x, double y) {
return -x;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x
end function
public static double code(double x, double y) {
return -x;
}
def code(x, y): return -x
function code(x, y) return Float64(-x) end
function tmp = code(x, y) tmp = -x; end
code[x_, y_] := (-x)
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = - x END code
-x
Initial program 68.9%
Taylor expanded in x around -inf
Applied rewrites34.7%
Applied rewrites34.7%
herbie shell --seed 2026092
(FPCore (x y)
:name "Linear.Quaternion:$clog from linear-1.19.1.3"
:precision binary64
(sqrt (+ (* x x) y)))