
(FPCore (x y) :precision binary64 :pre TRUE (+ x (/ (- x y) 2.0)))
double code(double x, double y) {
return x + ((x - y) / 2.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((x - y) / 2.0d0)
end function
public static double code(double x, double y) {
return x + ((x - y) / 2.0);
}
def code(x, y): return x + ((x - y) / 2.0)
function code(x, y) return Float64(x + Float64(Float64(x - y) / 2.0)) end
function tmp = code(x, y) tmp = x + ((x - y) / 2.0); end
code[x_, y_] := N[(x + N[(N[(x - y), $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 + ((x - y) / (2)) END code
x + \frac{x - y}{2}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (+ x (/ (- x y) 2.0)))
double code(double x, double y) {
return x + ((x - y) / 2.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((x - y) / 2.0d0)
end function
public static double code(double x, double y) {
return x + ((x - y) / 2.0);
}
def code(x, y): return x + ((x - y) / 2.0)
function code(x, y) return Float64(x + Float64(Float64(x - y) / 2.0)) end
function tmp = code(x, y) tmp = x + ((x - y) / 2.0); end
code[x_, y_] := N[(x + N[(N[(x - y), $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 + ((x - y) / (2)) END code
x + \frac{x - y}{2}
(FPCore (x y) :precision binary64 :pre TRUE (fma 1.5 x (* -0.5 y)))
double code(double x, double y) {
return fma(1.5, x, (-0.5 * y));
}
function code(x, y) return fma(1.5, x, Float64(-0.5 * y)) end
code[x_, y_] := N[(1.5 * x + N[(-0.5 * y), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = ((15e-1) * x) + ((-5e-1) * y) END code
\mathsf{fma}\left(1.5, x, -0.5 \cdot y\right)
Initial program 99.9%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (fma -0.5 (- y x) x))
double code(double x, double y) {
return fma(-0.5, (y - x), x);
}
function code(x, y) return fma(-0.5, Float64(y - x), x) end
code[x_, y_] := N[(-0.5 * N[(y - x), $MachinePrecision] + x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = ((-5e-1) * (y - x)) + x END code
\mathsf{fma}\left(-0.5, y - x, x\right)
Initial program 99.9%
Applied rewrites99.9%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= y -1.1623226477154053e-26) (fma -0.5 y x) (if (<= y 2.426229654520916e+48) (* 1.5 x) (fma -0.5 y x))))
double code(double x, double y) {
double tmp;
if (y <= -1.1623226477154053e-26) {
tmp = fma(-0.5, y, x);
} else if (y <= 2.426229654520916e+48) {
tmp = 1.5 * x;
} else {
tmp = fma(-0.5, y, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.1623226477154053e-26) tmp = fma(-0.5, y, x); elseif (y <= 2.426229654520916e+48) tmp = Float64(1.5 * x); else tmp = fma(-0.5, y, x); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.1623226477154053e-26], N[(-0.5 * y + x), $MachinePrecision], If[LessEqual[y, 2.426229654520916e+48], N[(1.5 * x), $MachinePrecision], N[(-0.5 * y + x), $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 ((15e-1) * x) ELSE (((-5e-1) * y) + x) ENDIF IN LET tmp = IF (y <= (-11623226477154053309672337016807098596194572553602347814800057447127815991871901957210866385139524936676025390625e-138)) THEN (((-5e-1) * y) + x) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq -1.1623226477154053 \cdot 10^{-26}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, y, x\right)\\
\mathbf{elif}\;y \leq 2.426229654520916 \cdot 10^{+48}:\\
\;\;\;\;1.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, y, x\right)\\
\end{array}
if y < -1.1623226477154053e-26 or 2.4262296545209159e48 < y Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites58.6%
if -1.1623226477154053e-26 < y < 2.4262296545209159e48Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites51.2%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= y -4.155509726251822e+46) (* -0.5 y) (if (<= y 2.426229654520916e+48) (* 1.5 x) (* -0.5 y))))
double code(double x, double y) {
double tmp;
if (y <= -4.155509726251822e+46) {
tmp = -0.5 * y;
} else if (y <= 2.426229654520916e+48) {
tmp = 1.5 * x;
} else {
tmp = -0.5 * y;
}
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 <= (-4.155509726251822d+46)) then
tmp = (-0.5d0) * y
else if (y <= 2.426229654520916d+48) then
tmp = 1.5d0 * x
else
tmp = (-0.5d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.155509726251822e+46) {
tmp = -0.5 * y;
} else if (y <= 2.426229654520916e+48) {
tmp = 1.5 * x;
} else {
tmp = -0.5 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.155509726251822e+46: tmp = -0.5 * y elif y <= 2.426229654520916e+48: tmp = 1.5 * x else: tmp = -0.5 * y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.155509726251822e+46) tmp = Float64(-0.5 * y); elseif (y <= 2.426229654520916e+48) tmp = Float64(1.5 * x); else tmp = Float64(-0.5 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.155509726251822e+46) tmp = -0.5 * y; elseif (y <= 2.426229654520916e+48) tmp = 1.5 * x; else tmp = -0.5 * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.155509726251822e+46], N[(-0.5 * y), $MachinePrecision], If[LessEqual[y, 2.426229654520916e+48], N[(1.5 * x), $MachinePrecision], N[(-0.5 * y), $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 ((15e-1) * x) ELSE ((-5e-1) * y) ENDIF IN LET tmp = IF (y <= (-41555097262518219140230899091581622926874509312)) THEN ((-5e-1) * y) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq -4.155509726251822 \cdot 10^{+46}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{elif}\;y \leq 2.426229654520916 \cdot 10^{+48}:\\
\;\;\;\;1.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot y\\
\end{array}
if y < -4.1555097262518219e46 or 2.4262296545209159e48 < y Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites58.6%
Taylor expanded in x around 0
Applied rewrites50.1%
if -4.1555097262518219e46 < y < 2.4262296545209159e48Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites51.2%
(FPCore (x y) :precision binary64 :pre TRUE (* 1.5 x))
double code(double x, double y) {
return 1.5 * x;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.5d0 * x
end function
public static double code(double x, double y) {
return 1.5 * x;
}
def code(x, y): return 1.5 * x
function code(x, y) return Float64(1.5 * x) end
function tmp = code(x, y) tmp = 1.5 * x; end
code[x_, y_] := N[(1.5 * x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (15e-1) * x END code
1.5 \cdot x
Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites51.2%
herbie shell --seed 2026092
(FPCore (x y)
:name "Graphics.Rendering.Chart.Axis.Types:hBufferRect from Chart-1.5.3"
:precision binary64
(+ x (/ (- x y) 2.0)))