
(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(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $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 \cdot y + x\right) + y
Herbie found 6 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(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $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 \cdot y + x\right) + y
(FPCore (x y) :precision binary64 :pre TRUE (+ (fma x y x) y))
double code(double x, double y) {
return fma(x, y, x) + y;
}
function code(x, y) return Float64(fma(x, y, x) + y) end
code[x_, y_] := N[(N[(x * y + x), $MachinePrecision] + y), $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
\mathsf{fma}\left(x, y, x\right) + y
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)
(fma (fmin x y) (fmax x y) (fmin x y))
(fma (fmax x y) (fmin x y) (fmax 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 = fma(fmin(x, y), fmax(x, y), fmin(x, y));
} else {
tmp = fma(fmax(x, y), fmin(x, y), fmax(x, y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(fmin(x, y) * fmax(x, y)) + fmin(x, y)) + fmax(x, y)) <= -5e-243) tmp = fma(fmin(x, y), fmax(x, y), fmin(x, y)); else tmp = fma(fmax(x, y), fmin(x, y), fmax(x, y)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision] + N[Min[x, y], $MachinePrecision]), $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision], -5e-243], N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision] + N[Min[x, y], $MachinePrecision]), $MachinePrecision], N[(N[Max[x, y], $MachinePrecision] * N[Min[x, y], $MachinePrecision] + 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_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_11 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_12 = IF (x < y) THEN x ELSE y ENDIF IN LET tmp_13 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_3 = IF ((((tmp_4 * tmp_5) + tmp_6) + tmp_7) <= (-499999999999999984683939913850061721489496590952589773390827798773737713095969188633192627621462316498790691672632378270778722894714282591665081646676534330402059887310135947479208884369292311377477501378209357934919133739094273166755544593266130898595976796117582471603708263244462299937705026182313773996576649739412955028089862877309315791663836061563811213000894375067941494972219497381288478141027142373996815747302928733577169901360013239235730522260790452621052053289221103216668717982290806856659157137617117372787702476621585898098080977451099317342653072129658731181933717380161397159099578857421875e-851)) THEN ((tmp_8 * tmp_9) + tmp_10) ELSE ((tmp_11 * tmp_12) + tmp_13) ENDIF IN tmp_3 END code
\begin{array}{l}
\mathbf{if}\;\left(\mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right) + \mathsf{min}\left(x, y\right)\right) + \mathsf{max}\left(x, y\right) \leq -5 \cdot 10^{-243}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{min}\left(x, y\right), \mathsf{max}\left(x, y\right), \mathsf{min}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{max}\left(x, y\right), \mathsf{min}\left(x, y\right), \mathsf{max}\left(x, y\right)\right)\\
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -4.9999999999999998e-243Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites62.5%
Taylor expanded in x around inf
Applied rewrites27.0%
Taylor expanded in x around inf
Applied rewrites63.5%
Applied rewrites63.6%
if -4.9999999999999998e-243 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites62.5%
Applied rewrites62.5%
(FPCore (x y)
:precision binary64
:pre TRUE
(let* ((t_0 (+ (+ (* (fmin x y) (fmax x y)) (fmin x y)) (fmax x y)))
(t_1 (fma (fmin x y) (fmax x y) (fmin x y))))
(if (<= t_0 -5e-243) t_1 (if (<= t_0 2e+275) (fmax x y) t_1))))double code(double x, double y) {
double t_0 = ((fmin(x, y) * fmax(x, y)) + fmin(x, y)) + fmax(x, y);
double t_1 = fma(fmin(x, y), fmax(x, y), fmin(x, y));
double tmp;
if (t_0 <= -5e-243) {
tmp = t_1;
} else if (t_0 <= 2e+275) {
tmp = fmax(x, y);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(Float64(fmin(x, y) * fmax(x, y)) + fmin(x, y)) + fmax(x, y)) t_1 = fma(fmin(x, y), fmax(x, y), fmin(x, y)) tmp = 0.0 if (t_0 <= -5e-243) tmp = t_1; elseif (t_0 <= 2e+275) tmp = fmax(x, y); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision] + N[Min[x, y], $MachinePrecision]), $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision] + N[Min[x, y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-243], t$95$1, If[LessEqual[t$95$0, 2e+275], N[Max[x, y], $MachinePrecision], t$95$1]]]]
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 LET tmp_1 = IF (x > y) THEN x ELSE y ENDIF IN 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 t_0 = (((tmp * tmp_1) + tmp_2) + tmp_3) 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 t_1 = ((tmp_4 * tmp_5) + tmp_6) IN LET tmp_10 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_9 = IF (t_0 <= (199999999999999991963354801579539865224719863466643166570237755888153096932896189915818952609920031781613357714761512012614125205154634640267751072327400569037934396194907236465391951327140093092900757315484959343965444154349978513521462377866702261531547814080948494523170816)) THEN tmp_10 ELSE t_1 ENDIF IN LET tmp_7 = IF (t_0 <= (-499999999999999984683939913850061721489496590952589773390827798773737713095969188633192627621462316498790691672632378270778722894714282591665081646676534330402059887310135947479208884369292311377477501378209357934919133739094273166755544593266130898595976796117582471603708263244462299937705026182313773996576649739412955028089862877309315791663836061563811213000894375067941494972219497381288478141027142373996815747302928733577169901360013239235730522260790452621052053289221103216668717982290806856659157137617117372787702476621585898098080977451099317342653072129658731181933717380161397159099578857421875e-851)) THEN t_1 ELSE tmp_9 ENDIF IN tmp_7 END code
\begin{array}{l}
t_0 := \left(\mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right) + \mathsf{min}\left(x, y\right)\right) + \mathsf{max}\left(x, y\right)\\
t_1 := \mathsf{fma}\left(\mathsf{min}\left(x, y\right), \mathsf{max}\left(x, y\right), \mathsf{min}\left(x, y\right)\right)\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{-243}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+275}:\\
\;\;\;\;\mathsf{max}\left(x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -4.9999999999999998e-243 or 1.9999999999999999e275 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites62.5%
Taylor expanded in x around inf
Applied rewrites27.0%
Taylor expanded in x around inf
Applied rewrites63.5%
Applied rewrites63.6%
if -4.9999999999999998e-243 < (+.f64 (+.f64 (*.f64 x y) x) y) < 1.9999999999999999e275Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites38.0%
(FPCore (x y)
:precision binary64
:pre TRUE
(let* ((t_0 (* (fmin x y) (fmax x y)))
(t_1 (+ (+ t_0 (fmin x y)) (fmax x y))))
(if (<= t_1 (- INFINITY))
t_0
(if (<= t_1 -5e-243)
(* (fmin x y) 1.0)
(if (<= t_1 2e+275) (fmax x y) t_0)))))double code(double x, double y) {
double t_0 = fmin(x, y) * fmax(x, y);
double t_1 = (t_0 + fmin(x, y)) + fmax(x, y);
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = t_0;
} else if (t_1 <= -5e-243) {
tmp = fmin(x, y) * 1.0;
} else if (t_1 <= 2e+275) {
tmp = fmax(x, y);
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = fmin(x, y) * fmax(x, y);
double t_1 = (t_0 + fmin(x, y)) + fmax(x, y);
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = t_0;
} else if (t_1 <= -5e-243) {
tmp = fmin(x, y) * 1.0;
} else if (t_1 <= 2e+275) {
tmp = fmax(x, y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = fmin(x, y) * fmax(x, y) t_1 = (t_0 + fmin(x, y)) + fmax(x, y) tmp = 0 if t_1 <= -math.inf: tmp = t_0 elif t_1 <= -5e-243: tmp = fmin(x, y) * 1.0 elif t_1 <= 2e+275: tmp = fmax(x, y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(fmin(x, y) * fmax(x, y)) t_1 = Float64(Float64(t_0 + fmin(x, y)) + fmax(x, y)) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = t_0; elseif (t_1 <= -5e-243) tmp = Float64(fmin(x, y) * 1.0); elseif (t_1 <= 2e+275) tmp = fmax(x, y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = min(x, y) * max(x, y); t_1 = (t_0 + min(x, y)) + max(x, y); tmp = 0.0; if (t_1 <= -Inf) tmp = t_0; elseif (t_1 <= -5e-243) tmp = min(x, y) * 1.0; elseif (t_1 <= 2e+275) tmp = max(x, y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 + N[Min[x, y], $MachinePrecision]), $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$0, If[LessEqual[t$95$1, -5e-243], N[(N[Min[x, y], $MachinePrecision] * 1.0), $MachinePrecision], If[LessEqual[t$95$1, 2e+275], N[Max[x, y], $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right)\\
t_1 := \left(t\_0 + \mathsf{min}\left(x, y\right)\right) + \mathsf{max}\left(x, y\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq -5 \cdot 10^{-243}:\\
\;\;\;\;\mathsf{min}\left(x, y\right) \cdot 1\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+275}:\\
\;\;\;\;\mathsf{max}\left(x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -inf.0 or 1.9999999999999999e275 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites62.5%
Taylor expanded in x around inf
Applied rewrites27.0%
if -inf.0 < (+.f64 (+.f64 (*.f64 x y) x) y) < -4.9999999999999998e-243Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites62.5%
Taylor expanded in x around inf
Applied rewrites27.0%
Taylor expanded in x around inf
Applied rewrites63.5%
Taylor expanded in y around 0
Applied rewrites39.0%
if -4.9999999999999998e-243 < (+.f64 (+.f64 (*.f64 x y) x) y) < 1.9999999999999999e275Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites38.0%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= x -0.3265401055606291) (* x y) (if (<= x 497724760173.6331) y (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -0.3265401055606291) {
tmp = x * y;
} else if (x <= 497724760173.6331) {
tmp = y;
} else {
tmp = 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 (x <= (-0.3265401055606291d0)) then
tmp = x * y
else if (x <= 497724760173.6331d0) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.3265401055606291) {
tmp = x * y;
} else if (x <= 497724760173.6331) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.3265401055606291: tmp = x * y elif x <= 497724760173.6331: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -0.3265401055606291) tmp = Float64(x * y); elseif (x <= 497724760173.6331) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.3265401055606291) tmp = x * y; elseif (x <= 497724760173.6331) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.3265401055606291], N[(x * y), $MachinePrecision], If[LessEqual[x, 497724760173.6331], y, N[(x * 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 (x <= (49772476017363311767578125e-14)) THEN y ELSE (x * y) ENDIF IN LET tmp = IF (x <= (-326540105560629123626625869292183779180049896240234375e-54)) THEN (x * y) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq -0.3265401055606291:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 497724760173.6331:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
if x < -0.32654010556062912 or 497724760173.63312 < x Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites62.5%
Taylor expanded in x around inf
Applied rewrites27.0%
if -0.32654010556062912 < x < 497724760173.63312Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites38.0%
(FPCore (x y) :precision binary64 :pre TRUE y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = y END code
y
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites38.0%
herbie shell --seed 2026092
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))