
(FPCore (x y) :precision binary64 :pre TRUE (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((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 + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $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 + ((abs((y - x))) / (2)) END code
x + \frac{\left|y - x\right|}{2}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((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 + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $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 + ((abs((y - x))) / (2)) END code
x + \frac{\left|y - x\right|}{2}
(FPCore (x y) :precision binary64 :pre TRUE (fma 0.5 (fabs (- y x)) x))
double code(double x, double y) {
return fma(0.5, fabs((y - x)), x);
}
function code(x, y) return fma(0.5, abs(Float64(y - x)), x) end
code[x_, y_] := N[(0.5 * N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] + x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = ((5e-1) * (abs((y - x)))) + x END code
\mathsf{fma}\left(0.5, \left|y - x\right|, x\right)
Initial program 99.9%
Applied rewrites99.9%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (+ x (/ (fabs (- y x)) 2.0)) 5e-194) (fma (fabs x) 0.5 x) (fma 0.5 (fabs y) x)))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= 5e-194) {
tmp = fma(fabs(x), 0.5, x);
} else {
tmp = fma(0.5, fabs(y), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(x + Float64(abs(Float64(y - x)) / 2.0)) <= 5e-194) tmp = fma(abs(x), 0.5, x); else tmp = fma(0.5, abs(y), x); end return tmp end
code[x_, y_] := If[LessEqual[N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], 5e-194], N[(N[Abs[x], $MachinePrecision] * 0.5 + x), $MachinePrecision], N[(0.5 * N[Abs[y], $MachinePrecision] + x), $MachinePrecision]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF ((x + ((abs((y - x))) / (2))) <= (500000000000000024025901121938478221147045809140089786880419736238950243745519939537454010864879495441296908907856491643658165580987505294446731832247650320925424270286857547130615491904230130177316749940482583783112397332246112980463360875015550554640174019551764103769427671211535168442701887771577450785234144342878468552851093186158299048532468929990642960399829866861547980369048689070909724364996636934641233277441370338964559834891463775097391839471214040890867380539930309168994426727294921875e-694)) THEN (((abs(x)) * (5e-1)) + x) ELSE (((5e-1) * (abs(y))) + x) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq 5 \cdot 10^{-194}:\\
\;\;\;\;\mathsf{fma}\left(\left|x\right|, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|y\right|, x\right)\\
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < 5.0000000000000002e-194Initial program 99.9%
Taylor expanded in x around -inf
Applied rewrites28.5%
Applied rewrites51.2%
if 5.0000000000000002e-194 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites58.3%
Applied rewrites58.3%
(FPCore (x y) :precision binary64 :pre TRUE (fma (fabs x) 0.5 x))
double code(double x, double y) {
return fma(fabs(x), 0.5, x);
}
function code(x, y) return fma(abs(x), 0.5, x) end
code[x_, y_] := N[(N[Abs[x], $MachinePrecision] * 0.5 + x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = ((abs(x)) * (5e-1)) + x END code
\mathsf{fma}\left(\left|x\right|, 0.5, x\right)
Initial program 99.9%
Taylor expanded in x around -inf
Applied rewrites28.5%
Applied rewrites51.2%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (+ x (/ (fabs (- y x)) 2.0)) -1e-169) (* -0.5 (fabs x)) (* 0.5 (fabs x))))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= -1e-169) {
tmp = -0.5 * fabs(x);
} else {
tmp = 0.5 * fabs(x);
}
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 ((x + (abs((y - x)) / 2.0d0)) <= (-1d-169)) then
tmp = (-0.5d0) * abs(x)
else
tmp = 0.5d0 * abs(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x + (Math.abs((y - x)) / 2.0)) <= -1e-169) {
tmp = -0.5 * Math.abs(x);
} else {
tmp = 0.5 * Math.abs(x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x + (math.fabs((y - x)) / 2.0)) <= -1e-169: tmp = -0.5 * math.fabs(x) else: tmp = 0.5 * math.fabs(x) return tmp
function code(x, y) tmp = 0.0 if (Float64(x + Float64(abs(Float64(y - x)) / 2.0)) <= -1e-169) tmp = Float64(-0.5 * abs(x)); else tmp = Float64(0.5 * abs(x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x + (abs((y - x)) / 2.0)) <= -1e-169) tmp = -0.5 * abs(x); else tmp = 0.5 * abs(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], -1e-169], N[(-0.5 * N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Abs[x], $MachinePrecision]), $MachinePrecision]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF ((x + ((abs((y - x))) / (2))) <= (-10000000000000000201179579279951889494332706650336297646126334616435798702446775408390300828267543734556479114876743872147869225462564480958602997490296631147190646714427999744304638141648645677568293476605921373886828801707213576973104942065303602800152996738639009092824083236212756882922294542672246320073171719768219062755043188870164156569825065005551127725431170669760491634397165652335013242654640323869852380767042632214725017547607421875e-614)) THEN ((-5e-1) * (abs(x))) ELSE ((5e-1) * (abs(x))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq -1 \cdot 10^{-169}:\\
\;\;\;\;-0.5 \cdot \left|x\right|\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left|x\right|\\
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < -1e-169Initial program 99.9%
Taylor expanded in x around -inf
Applied rewrites28.5%
Taylor expanded in x around 0
Applied rewrites26.4%
if -1e-169 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.9%
Taylor expanded in x around -inf
Applied rewrites28.5%
Applied rewrites51.2%
Taylor expanded in x around 0
Applied rewrites7.1%
(FPCore (x y) :precision binary64 :pre TRUE (* -0.5 (fabs x)))
double code(double x, double y) {
return -0.5 * fabs(x);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (-0.5d0) * abs(x)
end function
public static double code(double x, double y) {
return -0.5 * Math.abs(x);
}
def code(x, y): return -0.5 * math.fabs(x)
function code(x, y) return Float64(-0.5 * abs(x)) end
function tmp = code(x, y) tmp = -0.5 * abs(x); end
code[x_, y_] := N[(-0.5 * N[Abs[x], $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (-5e-1) * (abs(x)) END code
-0.5 \cdot \left|x\right|
Initial program 99.9%
Taylor expanded in x around -inf
Applied rewrites28.5%
Taylor expanded in x around 0
Applied rewrites26.4%
herbie shell --seed 2026092
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))