
(FPCore (x y) :precision binary64 :pre TRUE (- x (/ y (+ 1.0 (/ (* x y) 2.0)))))
double code(double x, double y) {
return x - (y / (1.0 + ((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 / (1.0d0 + ((x * y) / 2.0d0)))
end function
public static double code(double x, double y) {
return x - (y / (1.0 + ((x * y) / 2.0)));
}
def code(x, y): return x - (y / (1.0 + ((x * y) / 2.0)))
function code(x, y) return Float64(x - Float64(y / Float64(1.0 + Float64(Float64(x * y) / 2.0)))) end
function tmp = code(x, y) tmp = x - (y / (1.0 + ((x * y) / 2.0))); end
code[x_, y_] := N[(x - N[(y / N[(1.0 + N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x - (y / ((1) + ((x * y) / (2)))) END code
x - \frac{y}{1 + \frac{x \cdot y}{2}}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (- x (/ y (+ 1.0 (/ (* x y) 2.0)))))
double code(double x, double y) {
return x - (y / (1.0 + ((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 / (1.0d0 + ((x * y) / 2.0d0)))
end function
public static double code(double x, double y) {
return x - (y / (1.0 + ((x * y) / 2.0)));
}
def code(x, y): return x - (y / (1.0 + ((x * y) / 2.0)))
function code(x, y) return Float64(x - Float64(y / Float64(1.0 + Float64(Float64(x * y) / 2.0)))) end
function tmp = code(x, y) tmp = x - (y / (1.0 + ((x * y) / 2.0))); end
code[x_, y_] := N[(x - N[(y / N[(1.0 + N[(N[(x * y), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x - (y / ((1) + ((x * y) / (2)))) END code
x - \frac{y}{1 + \frac{x \cdot y}{2}}
(FPCore (x y) :precision binary64 :pre TRUE (fma (/ y (fma y x 2.0)) -2.0 x))
double code(double x, double y) {
return fma((y / fma(y, x, 2.0)), -2.0, x);
}
function code(x, y) return fma(Float64(y / fma(y, x, 2.0)), -2.0, x) end
code[x_, y_] := N[(N[(y / N[(y * x + 2.0), $MachinePrecision]), $MachinePrecision] * -2.0 + x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = ((y / ((y * x) + (2))) * (-2)) + x END code
\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(y, x, 2\right)}, -2, x\right)
Initial program 99.9%
Applied rewrites99.9%
(FPCore (x y) :precision binary64 :pre TRUE (fma y (/ -2.0 (fma y x 2.0)) x))
double code(double x, double y) {
return fma(y, (-2.0 / fma(y, x, 2.0)), x);
}
function code(x, y) return fma(y, Float64(-2.0 / fma(y, x, 2.0)), x) end
code[x_, y_] := N[(y * N[(-2.0 / N[(y * x + 2.0), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (y * ((-2) / ((y * x) + (2)))) + x END code
\mathsf{fma}\left(y, \frac{-2}{\mathsf{fma}\left(y, x, 2\right)}, x\right)
Initial program 99.9%
Applied rewrites99.9%
(FPCore (x y)
:precision binary64
:pre TRUE
(let* ((t_0 (- x (/ 2.0 x))))
(if (<= y -3.0122611981243973e+89)
t_0
(if (<= y 2.0645343699431568e+124) (- x y) t_0))))double code(double x, double y) {
double t_0 = x - (2.0 / x);
double tmp;
if (y <= -3.0122611981243973e+89) {
tmp = t_0;
} else if (y <= 2.0645343699431568e+124) {
tmp = x - y;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x - (2.0d0 / x)
if (y <= (-3.0122611981243973d+89)) then
tmp = t_0
else if (y <= 2.0645343699431568d+124) then
tmp = x - y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x - (2.0 / x);
double tmp;
if (y <= -3.0122611981243973e+89) {
tmp = t_0;
} else if (y <= 2.0645343699431568e+124) {
tmp = x - y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x - (2.0 / x) tmp = 0 if y <= -3.0122611981243973e+89: tmp = t_0 elif y <= 2.0645343699431568e+124: tmp = x - y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x - Float64(2.0 / x)) tmp = 0.0 if (y <= -3.0122611981243973e+89) tmp = t_0; elseif (y <= 2.0645343699431568e+124) tmp = Float64(x - y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x - (2.0 / x); tmp = 0.0; if (y <= -3.0122611981243973e+89) tmp = t_0; elseif (y <= 2.0645343699431568e+124) tmp = x - y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.0122611981243973e+89], t$95$0, If[LessEqual[y, 2.0645343699431568e+124], N[(x - y), $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 - ((2) / x)) IN LET tmp_1 = IF (y <= (20645343699431567580510374441683576030400255320276555212756315034617729988378208293496342842769843479236700533775763549192192)) THEN (x - y) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-301226119812439733339043170925700121541684620358723203201631769572565545659143467980292096)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := x - \frac{2}{x}\\
\mathbf{if}\;y \leq -3.0122611981243973 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.0645343699431568 \cdot 10^{+124}:\\
\;\;\;\;x - y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -3.0122611981243973e89 or 2.0645343699431568e124 < y Initial program 99.9%
Taylor expanded in x around inf
Applied rewrites61.5%
if -3.0122611981243973e89 < y < 2.0645343699431568e124Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites75.4%
(FPCore (x y) :precision binary64 :pre TRUE (- x y))
double code(double x, double y) {
return 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
end function
public static double code(double x, double y) {
return x - y;
}
def code(x, y): return x - y
function code(x, y) return Float64(x - y) end
function tmp = code(x, y) tmp = x - y; end
code[x_, y_] := N[(x - y), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x - y END code
x - y
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites75.4%
herbie shell --seed 2026092
(FPCore (x y)
:name "Data.Number.Erf:$cinvnormcdf from erf-2.0.0.0, B"
:precision binary64
(- x (/ y (+ 1.0 (/ (* x y) 2.0)))))