
(FPCore (x y) :precision binary64 :pre TRUE (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (x * y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (x + y) - (x * y) END code
\left(x + y\right) - x \cdot y
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (x * y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (x + y) - (x * y) END code
\left(x + y\right) - x \cdot y
(FPCore (x y) :precision binary64 :pre TRUE (fma y (- 1.0 x) x))
double code(double x, double y) {
return fma(y, (1.0 - x), x);
}
function code(x, y) return fma(y, Float64(1.0 - x), x) end
code[x_, y_] := N[(y * N[(1.0 - x), $MachinePrecision] + x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (y * ((1) - x)) + x END code
\mathsf{fma}\left(y, 1 - x, x\right)
Initial program 100.0%
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
:pre TRUE
(if (<=
(- (+ (fmin x y) (fmax x y)) (* (fmin x y) (fmax x y)))
-5e-243)
(* (fmin x y) (- 1.0 (fmax x y)))
(* (fmax x y) (- 1.0 (fmin x y)))))double code(double x, double y) {
double tmp;
if (((fmin(x, y) + fmax(x, y)) - (fmin(x, y) * fmax(x, y))) <= -5e-243) {
tmp = fmin(x, y) * (1.0 - fmax(x, y));
} else {
tmp = fmax(x, y) * (1.0 - fmin(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)) - (fmin(x, y) * fmax(x, y))) <= (-5d-243)) then
tmp = fmin(x, y) * (1.0d0 - fmax(x, y))
else
tmp = fmax(x, y) * (1.0d0 - fmin(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)) - (fmin(x, y) * fmax(x, y))) <= -5e-243) {
tmp = fmin(x, y) * (1.0 - fmax(x, y));
} else {
tmp = fmax(x, y) * (1.0 - fmin(x, y));
}
return tmp;
}
def code(x, y): tmp = 0 if ((fmin(x, y) + fmax(x, y)) - (fmin(x, y) * fmax(x, y))) <= -5e-243: tmp = fmin(x, y) * (1.0 - fmax(x, y)) else: tmp = fmax(x, y) * (1.0 - fmin(x, y)) return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(fmin(x, y) + fmax(x, y)) - Float64(fmin(x, y) * fmax(x, y))) <= -5e-243) tmp = Float64(fmin(x, y) * Float64(1.0 - fmax(x, y))); else tmp = Float64(fmax(x, y) * Float64(1.0 - fmin(x, y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((min(x, y) + max(x, y)) - (min(x, y) * max(x, y))) <= -5e-243) tmp = min(x, y) * (1.0 - max(x, y)); else tmp = max(x, y) * (1.0 - min(x, y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(N[Min[x, y], $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision] - N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -5e-243], N[(N[Min[x, y], $MachinePrecision] * N[(1.0 - N[Max[x, y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Max[x, y], $MachinePrecision] * N[(1.0 - N[Min[x, y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = 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_6 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_7 = IF (x < y) THEN x ELSE y ENDIF IN LET tmp_8 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_9 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_10 = IF (x < y) THEN x ELSE y ENDIF IN LET tmp_2 = IF (((tmp_3 + tmp_4) - (tmp_5 * tmp_6)) <= (-499999999999999984683939913850061721489496590952589773390827798773737713095969188633192627621462316498790691672632378270778722894714282591665081646676534330402059887310135947479208884369292311377477501378209357934919133739094273166755544593266130898595976796117582471603708263244462299937705026182313773996576649739412955028089862877309315791663836061563811213000894375067941494972219497381288478141027142373996815747302928733577169901360013239235730522260790452621052053289221103216668717982290806856659157137617117372787702476621585898098080977451099317342653072129658731181933717380161397159099578857421875e-851)) THEN (tmp_7 * ((1) - tmp_8)) ELSE (tmp_9 * ((1) - tmp_10)) ENDIF IN tmp_2 END code
\begin{array}{l}
\mathbf{if}\;\left(\mathsf{min}\left(x, y\right) + \mathsf{max}\left(x, y\right)\right) - \mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right) \leq -5 \cdot 10^{-243}:\\
\;\;\;\;\mathsf{min}\left(x, y\right) \cdot \left(1 - \mathsf{max}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(x, y\right) \cdot \left(1 - \mathsf{min}\left(x, y\right)\right)\\
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -4.9999999999999998e-243Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites63.6%
if -4.9999999999999998e-243 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites62.5%
(FPCore (x y)
:precision binary64
:pre TRUE
(let* ((t_0 (* x (- 1.0 y))))
(if (<= x -764.2516277385)
t_0
(if (<= x 497724760173.6331) (fma y 1.0 x) t_0))))double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -764.2516277385) {
tmp = t_0;
} else if (x <= 497724760173.6331) {
tmp = fma(y, 1.0, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(x * Float64(1.0 - y)) tmp = 0.0 if (x <= -764.2516277385) tmp = t_0; elseif (x <= 497724760173.6331) tmp = fma(y, 1.0, x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -764.2516277385], t$95$0, If[LessEqual[x, 497724760173.6331], N[(y * 1.0 + x), $MachinePrecision], t$95$0]]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET t_0 = (x * ((1) - y)) IN LET tmp_1 = IF (x <= (49772476017363311767578125e-14)) THEN ((y * (1)) + x) ELSE t_0 ENDIF IN LET tmp = IF (x <= (-764251627738500019404455088078975677490234375e-42)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := x \cdot \left(1 - y\right)\\
\mathbf{if}\;x \leq -764.2516277385:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 497724760173.6331:\\
\;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if x < -764.25162773850002 or 497724760173.63312 < x Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites63.6%
if -764.25162773850002 < x < 497724760173.63312Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites74.7%
(FPCore (x y) :precision binary64 :pre TRUE (fma y 1.0 x))
double code(double x, double y) {
return fma(y, 1.0, x);
}
function code(x, y) return fma(y, 1.0, x) end
code[x_, y_] := N[(y * 1.0 + x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (y * (1)) + x END code
\mathsf{fma}\left(y, 1, x\right)
Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites74.7%
(FPCore (x y) :precision binary64 :pre TRUE (fmax x y))
double code(double x, double y) {
return 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(x, y)
end function
public static double code(double x, double y) {
return fmax(x, y);
}
def code(x, y): return fmax(x, y)
function code(x, y) return fmax(x, y) end
function tmp = code(x, y) tmp = max(x, y); end
code[x_, y_] := N[Max[x, y], $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 tmp END code
\mathsf{max}\left(x, y\right)
Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites63.6%
Taylor expanded in x around 0
Applied rewrites37.9%
herbie shell --seed 2026092
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))