
(FPCore (x y) :precision binary64 :pre TRUE (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)))
double code(double x, double y) {
return fmax(((pow(y, 2.0) + pow(x, 2.0)) - 0.5), fmax(x, y));
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = fmax((((y ** 2.0d0) + (x ** 2.0d0)) - 0.5d0), fmax(x, y))
end function
public static double code(double x, double y) {
return fmax(((Math.pow(y, 2.0) + Math.pow(x, 2.0)) - 0.5), fmax(x, y));
}
def code(x, y): return fmax(((math.pow(y, 2.0) + math.pow(x, 2.0)) - 0.5), fmax(x, y))
function code(x, y) return fmax(Float64(Float64((y ^ 2.0) + (x ^ 2.0)) - 0.5), fmax(x, y)) end
function tmp = code(x, y) tmp = max((((y ^ 2.0) + (x ^ 2.0)) - 0.5), max(x, y)); end
code[x_, y_] := N[Max[N[(N[(N[Power[y, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp_1 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_2 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp = IF ((((y ^ (2)) + (x ^ (2))) - (5e-1)) > tmp_1) THEN (((y ^ (2)) + (x ^ (2))) - (5e-1)) ELSE tmp_2 ENDIF IN tmp END code
\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right)
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)))
double code(double x, double y) {
return fmax(((pow(y, 2.0) + pow(x, 2.0)) - 0.5), fmax(x, y));
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = fmax((((y ** 2.0d0) + (x ** 2.0d0)) - 0.5d0), fmax(x, y))
end function
public static double code(double x, double y) {
return fmax(((Math.pow(y, 2.0) + Math.pow(x, 2.0)) - 0.5), fmax(x, y));
}
def code(x, y): return fmax(((math.pow(y, 2.0) + math.pow(x, 2.0)) - 0.5), fmax(x, y))
function code(x, y) return fmax(Float64(Float64((y ^ 2.0) + (x ^ 2.0)) - 0.5), fmax(x, y)) end
function tmp = code(x, y) tmp = max((((y ^ 2.0) + (x ^ 2.0)) - 0.5), max(x, y)); end
code[x_, y_] := N[Max[N[(N[(N[Power[y, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp_1 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_2 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp = IF ((((y ^ (2)) + (x ^ (2))) - (5e-1)) > tmp_1) THEN (((y ^ (2)) + (x ^ (2))) - (5e-1)) ELSE tmp_2 ENDIF IN tmp END code
\mathsf{max}\left(\left({y}^{2} + {x}^{2}\right) - 0.5, \mathsf{max}\left(x, y\right)\right)
(FPCore (x y) :precision binary64 :pre TRUE (fmax (* 1.0 (fma x x (fma y y -0.5))) (fmax x y)))
double code(double x, double y) {
return fmax((1.0 * fma(x, x, fma(y, y, -0.5))), fmax(x, y));
}
function code(x, y) return fmax(Float64(1.0 * fma(x, x, fma(y, y, -0.5))), fmax(x, y)) end
code[x_, y_] := N[Max[N[(1.0 * N[(x * x + N[(y * y + -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp_1 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_2 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp = IF (((1) * ((x * x) + ((y * y) + (-5e-1)))) > tmp_1) THEN ((1) * ((x * x) + ((y * y) + (-5e-1)))) ELSE tmp_2 ENDIF IN tmp END code
\mathsf{max}\left(1 \cdot \mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, -0.5\right)\right), \mathsf{max}\left(x, y\right)\right)
Initial program 100.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (fmax (* 1.0 (fma x x -0.5)) (fmax x y)))
double code(double x, double y) {
return fmax((1.0 * fma(x, x, -0.5)), fmax(x, y));
}
function code(x, y) return fmax(Float64(1.0 * fma(x, x, -0.5)), fmax(x, y)) end
code[x_, y_] := N[Max[N[(1.0 * N[(x * x + -0.5), $MachinePrecision]), $MachinePrecision], N[Max[x, y], $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp_1 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_2 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp = IF (((1) * ((x * x) + (-5e-1))) > tmp_1) THEN ((1) * ((x * x) + (-5e-1))) ELSE tmp_2 ENDIF IN tmp END code
\mathsf{max}\left(1 \cdot \mathsf{fma}\left(x, x, -0.5\right), \mathsf{max}\left(x, y\right)\right)
Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites67.7%
herbie shell --seed 2026070
(FPCore (x y)
:name "A quarter-circle in the lower-left quadrant"
:precision binary64
(fmax (- (+ (pow y 2.0) (pow x 2.0)) 0.5) (fmax x y)))