
(FPCore (x y) :precision binary64 :pre TRUE (/ (+ x y) 2.0))
double code(double x, double y) {
return (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 + y) / 2.0d0
end function
public static double code(double x, double y) {
return (x + y) / 2.0;
}
def code(x, y): return (x + y) / 2.0
function code(x, y) return Float64(Float64(x + y) / 2.0) end
function tmp = code(x, y) tmp = (x + y) / 2.0; end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / 2.0), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (x + y) / (2) END code
\frac{x + y}{2}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (/ (+ x y) 2.0))
double code(double x, double y) {
return (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 + y) / 2.0d0
end function
public static double code(double x, double y) {
return (x + y) / 2.0;
}
def code(x, y): return (x + y) / 2.0
function code(x, y) return Float64(Float64(x + y) / 2.0) end
function tmp = code(x, y) tmp = (x + y) / 2.0; end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / 2.0), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (x + y) / (2) END code
\frac{x + y}{2}
(FPCore (x y) :precision binary64 :pre TRUE (* 0.5 (+ x y)))
double code(double x, double y) {
return 0.5 * (x + y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * (x + y)
end function
public static double code(double x, double y) {
return 0.5 * (x + y);
}
def code(x, y): return 0.5 * (x + y)
function code(x, y) return Float64(0.5 * Float64(x + y)) end
function tmp = code(x, y) tmp = 0.5 * (x + y); end
code[x_, y_] := N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (5e-1) * (x + y) END code
0.5 \cdot \left(x + y\right)
Initial program 100.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (+ (fmin x y) (fmax x y)) -5e-243) (* 0.5 (fmin x y)) (* 0.5 (fmax x y))))
double code(double x, double y) {
double tmp;
if ((fmin(x, y) + fmax(x, y)) <= -5e-243) {
tmp = 0.5 * fmin(x, y);
} else {
tmp = 0.5 * fmax(x, 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 ((fmin(x, y) + fmax(x, y)) <= (-5d-243)) then
tmp = 0.5d0 * fmin(x, y)
else
tmp = 0.5d0 * fmax(x, y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((fmin(x, y) + fmax(x, y)) <= -5e-243) {
tmp = 0.5 * fmin(x, y);
} else {
tmp = 0.5 * fmax(x, y);
}
return tmp;
}
def code(x, y): tmp = 0 if (fmin(x, y) + fmax(x, y)) <= -5e-243: tmp = 0.5 * fmin(x, y) else: tmp = 0.5 * fmax(x, y) return tmp
function code(x, y) tmp = 0.0 if (Float64(fmin(x, y) + fmax(x, y)) <= -5e-243) tmp = Float64(0.5 * fmin(x, y)); else tmp = Float64(0.5 * fmax(x, y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((min(x, y) + max(x, y)) <= -5e-243) tmp = 0.5 * min(x, y); else tmp = 0.5 * max(x, y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Min[x, y], $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision], -5e-243], N[(0.5 * N[Min[x, y], $MachinePrecision]), $MachinePrecision], N[(0.5 * 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_2 = IF (x < y) THEN x ELSE y ENDIF IN LET tmp_3 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_4 = IF (x < y) THEN x ELSE y ENDIF IN LET tmp_5 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_1 = IF ((tmp_2 + tmp_3) <= (-499999999999999984683939913850061721489496590952589773390827798773737713095969188633192627621462316498790691672632378270778722894714282591665081646676534330402059887310135947479208884369292311377477501378209357934919133739094273166755544593266130898595976796117582471603708263244462299937705026182313773996576649739412955028089862877309315791663836061563811213000894375067941494972219497381288478141027142373996815747302928733577169901360013239235730522260790452621052053289221103216668717982290806856659157137617117372787702476621585898098080977451099317342653072129658731181933717380161397159099578857421875e-851)) THEN ((5e-1) * tmp_4) ELSE ((5e-1) * tmp_5) ENDIF IN tmp_1 END code
\begin{array}{l}
\mathbf{if}\;\mathsf{min}\left(x, y\right) + \mathsf{max}\left(x, y\right) \leq -5 \cdot 10^{-243}:\\
\;\;\;\;0.5 \cdot \mathsf{min}\left(x, y\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{max}\left(x, y\right)\\
\end{array}
if (+.f64 x y) < -4.9999999999999998e-243Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.3%
if -4.9999999999999998e-243 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.2%
(FPCore (x y) :precision binary64 :pre TRUE (* 0.5 (fmin x y)))
double code(double x, double y) {
return 0.5 * fmin(x, y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * fmin(x, y)
end function
public static double code(double x, double y) {
return 0.5 * fmin(x, y);
}
def code(x, y): return 0.5 * fmin(x, y)
function code(x, y) return Float64(0.5 * fmin(x, y)) end
function tmp = code(x, y) tmp = 0.5 * min(x, y); end
code[x_, y_] := N[(0.5 * N[Min[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 = IF (x < y) THEN x ELSE y ENDIF IN (5e-1) * tmp END code
0.5 \cdot \mathsf{min}\left(x, y\right)
Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.3%
herbie shell --seed 2026092
(FPCore (x y)
:name "Data.Colour.RGB:hslsv from colour-2.3.3, A"
:precision binary64
(/ (+ x y) 2.0))