
(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
\frac{x - y}{x + 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(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
\frac{x - y}{x + y}
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (- x y) (+ x y)) -1.0) (fma (/ x y) 2.0 -1.0) (fma (/ y x) -2.0 1.0)))
double code(double x, double y) {
double tmp;
if (((x - y) / (x + y)) <= -1.0) {
tmp = fma((x / y), 2.0, -1.0);
} else {
tmp = fma((y / x), -2.0, 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(x - y) / Float64(x + y)) <= -1.0) tmp = fma(Float64(x / y), 2.0, -1.0); else tmp = fma(Float64(y / x), -2.0, 1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision], -1.0], N[(N[(x / y), $MachinePrecision] * 2.0 + -1.0), $MachinePrecision], N[(N[(y / x), $MachinePrecision] * -2.0 + 1.0), $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) / (x + y)) <= (-1)) THEN (((x / y) * (2)) + (-1)) ELSE (((y / x) * (-2)) + (1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{x + y} \leq -1:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, 2, -1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x}, -2, 1\right)\\
\end{array}
if (/.f64 (-.f64 x y) (+.f64 x y)) < -1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites51.3%
Applied rewrites51.3%
if -1 < (/.f64 (-.f64 x y) (+.f64 x y)) Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites50.8%
Applied rewrites50.8%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (- x y) (+ x y)) -1.0) (fma (/ x y) 2.0 -1.0) 1.0))
double code(double x, double y) {
double tmp;
if (((x - y) / (x + y)) <= -1.0) {
tmp = fma((x / y), 2.0, -1.0);
} else {
tmp = 1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(x - y) / Float64(x + y)) <= -1.0) tmp = fma(Float64(x / y), 2.0, -1.0); else tmp = 1.0; end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision], -1.0], N[(N[(x / y), $MachinePrecision] * 2.0 + -1.0), $MachinePrecision], 1.0]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF (((x - y) / (x + y)) <= (-1)) THEN (((x / y) * (2)) + (-1)) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{x + y} \leq -1:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, 2, -1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 (-.f64 x y) (+.f64 x y)) < -1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites51.3%
Applied rewrites51.3%
if -1 < (/.f64 (-.f64 x y) (+.f64 x y)) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites49.5%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (- x y) (+ x y)) -1.0) (/ (- x y) y) 1.0))
double code(double x, double y) {
double tmp;
if (((x - y) / (x + y)) <= -1.0) {
tmp = (x - y) / y;
} else {
tmp = 1.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) :: tmp
if (((x - y) / (x + y)) <= (-1.0d0)) then
tmp = (x - y) / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x - y) / (x + y)) <= -1.0) {
tmp = (x - y) / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x - y) / (x + y)) <= -1.0: tmp = (x - y) / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x - y) / Float64(x + y)) <= -1.0) tmp = Float64(Float64(x - y) / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x - y) / (x + y)) <= -1.0) tmp = (x - y) / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision], -1.0], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], 1.0]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF (((x - y) / (x + y)) <= (-1)) THEN ((x - y) / y) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{x + y} \leq -1:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 (-.f64 x y) (+.f64 x y)) < -1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.8%
if -1 < (/.f64 (-.f64 x y) (+.f64 x y)) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites49.5%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (- x y) (+ x y)) 6.758573732548052e-79) -1.0 1.0))
double code(double x, double y) {
double tmp;
if (((x - y) / (x + y)) <= 6.758573732548052e-79) {
tmp = -1.0;
} else {
tmp = 1.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) :: tmp
if (((x - y) / (x + y)) <= 6.758573732548052d-79) then
tmp = -1.0d0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x - y) / (x + y)) <= 6.758573732548052e-79) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x - y) / (x + y)) <= 6.758573732548052e-79: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x - y) / Float64(x + y)) <= 6.758573732548052e-79) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x - y) / (x + y)) <= 6.758573732548052e-79) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision], 6.758573732548052e-79], -1.0, 1.0]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp = IF (((x - y) / (x + y)) <= (67585737325480524122593017784783224281129036479529979170791439070932276332156772635614123730730560729694865766693754440503840626982182983204595483746874952097657820593720196064259884245482346877553769814994666376151144504547119140625e-311)) THEN (-1) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{x + y} \leq 6.758573732548052 \cdot 10^{-79}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 (-.f64 x y) (+.f64 x y)) < 6.7585737325480524e-79Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.1%
if 6.7585737325480524e-79 < (/.f64 (-.f64 x y) (+.f64 x y)) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites49.5%
(FPCore (x y) :precision binary64 :pre TRUE -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
public static double code(double x, double y) {
return -1.0;
}
def code(x, y): return -1.0
function code(x, y) return -1.0 end
function tmp = code(x, y) tmp = -1.0; end
code[x_, y_] := -1.0
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = -1 END code
-1
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.1%
herbie shell --seed 2026092
(FPCore (x y)
:name "Data.Colour.RGB:hslsv from colour-2.3.3, D"
:precision binary64
(/ (- x y) (+ x y)))