
(FPCore (x y) :precision binary64 :pre TRUE (+ x (/ (- y x) 2.0)))
double code(double x, double y) {
return x + ((y - x) / 2.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((y - x) / 2.0d0)
end function
public static double code(double x, double y) {
return x + ((y - x) / 2.0);
}
def code(x, y): return x + ((y - x) / 2.0)
function code(x, y) return Float64(x + Float64(Float64(y - x) / 2.0)) end
function tmp = code(x, y) tmp = x + ((y - x) / 2.0); end
code[x_, y_] := N[(x + N[(N[(y - x), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x + ((y - x) / (2)) END code
x + \frac{y - x}{2}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (+ x (/ (- y x) 2.0)))
double code(double x, double y) {
return x + ((y - x) / 2.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((y - x) / 2.0d0)
end function
public static double code(double x, double y) {
return x + ((y - x) / 2.0);
}
def code(x, y): return x + ((y - x) / 2.0)
function code(x, y) return Float64(x + Float64(Float64(y - x) / 2.0)) end
function tmp = code(x, y) tmp = x + ((y - x) / 2.0); end
code[x_, y_] := N[(x + N[(N[(y - x), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x + ((y - x) / (2)) END code
x + \frac{y - x}{2}
(FPCore (x y) :precision binary64 :pre TRUE (* (+ y x) 0.5))
double code(double x, double y) {
return (y + x) * 0.5;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + x) * 0.5d0
end function
public static double code(double x, double y) {
return (y + x) * 0.5;
}
def code(x, y): return (y + x) * 0.5
function code(x, y) return Float64(Float64(y + x) * 0.5) end
function tmp = code(x, y) tmp = (y + x) * 0.5; end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (y + x) * (5e-1) END code
\left(y + x\right) \cdot 0.5
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= y -3.7736488112764267e+33) (* y 0.5) (if (<= y 2.426229654520916e+48) (* 0.5 x) (* y 0.5))))
double code(double x, double y) {
double tmp;
if (y <= -3.7736488112764267e+33) {
tmp = y * 0.5;
} else if (y <= 2.426229654520916e+48) {
tmp = 0.5 * x;
} else {
tmp = y * 0.5;
}
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 (y <= (-3.7736488112764267d+33)) then
tmp = y * 0.5d0
else if (y <= 2.426229654520916d+48) then
tmp = 0.5d0 * x
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.7736488112764267e+33) {
tmp = y * 0.5;
} else if (y <= 2.426229654520916e+48) {
tmp = 0.5 * x;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.7736488112764267e+33: tmp = y * 0.5 elif y <= 2.426229654520916e+48: tmp = 0.5 * x else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.7736488112764267e+33) tmp = Float64(y * 0.5); elseif (y <= 2.426229654520916e+48) tmp = Float64(0.5 * x); else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.7736488112764267e+33) tmp = y * 0.5; elseif (y <= 2.426229654520916e+48) tmp = 0.5 * x; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.7736488112764267e+33], N[(y * 0.5), $MachinePrecision], If[LessEqual[y, 2.426229654520916e+48], N[(0.5 * x), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp_1 = IF (y <= (2426229654520915891643607200729785382101422440448)) THEN ((5e-1) * x) ELSE (y * (5e-1)) ENDIF IN LET tmp = IF (y <= (-3773648811276426676203284156383232)) THEN (y * (5e-1)) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq -3.7736488112764267 \cdot 10^{+33}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{elif}\;y \leq 2.426229654520916 \cdot 10^{+48}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
if y < -3.7736488112764267e33 or 2.4262296545209159e48 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites50.2%
if -3.7736488112764267e33 < y < 2.4262296545209159e48Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.3%
(FPCore (x y) :precision binary64 :pre TRUE (* 0.5 x))
double code(double x, double y) {
return 0.5 * x;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * x
end function
public static double code(double x, double y) {
return 0.5 * x;
}
def code(x, y): return 0.5 * x
function code(x, y) return Float64(0.5 * x) end
function tmp = code(x, y) tmp = 0.5 * x; end
code[x_, y_] := N[(0.5 * x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (5e-1) * x END code
0.5 \cdot x
Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.3%
herbie shell --seed 2026092
(FPCore (x y)
:name "Numeric.Interval.Internal:bisect from intervals-0.7.1, A"
:precision binary64
(+ x (/ (- y x) 2.0)))