
(FPCore (x y) :precision binary64 :pre TRUE (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
return (x - y) / (2.0 - (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) / (2.0d0 - (x + y))
end function
public static double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
def code(x, y): return (x - y) / (2.0 - (x + y))
function code(x, y) return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) end
function tmp = code(x, y) tmp = (x - y) / (2.0 - (x + y)); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (x - y) / ((2) - (x + y)) END code
\frac{x - y}{2 - \left(x + y\right)}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
return (x - y) / (2.0 - (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) / (2.0d0 - (x + y))
end function
public static double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
def code(x, y): return (x - y) / (2.0 - (x + y))
function code(x, y) return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) end
function tmp = code(x, y) tmp = (x - y) / (2.0 - (x + y)); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (x - y) / ((2) - (x + y)) END code
\frac{x - y}{2 - \left(x + y\right)}
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (- x y) (- 2.0 (+ x y))) 0.005) (/ (- x y) (- 2.0 x)) (/ (- x y) (- 2.0 y))))
double code(double x, double y) {
double tmp;
if (((x - y) / (2.0 - (x + y))) <= 0.005) {
tmp = (x - y) / (2.0 - x);
} else {
tmp = (x - y) / (2.0 - 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 - y) / (2.0d0 - (x + y))) <= 0.005d0) then
tmp = (x - y) / (2.0d0 - x)
else
tmp = (x - y) / (2.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x - y) / (2.0 - (x + y))) <= 0.005) {
tmp = (x - y) / (2.0 - x);
} else {
tmp = (x - y) / (2.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if ((x - y) / (2.0 - (x + y))) <= 0.005: tmp = (x - y) / (2.0 - x) else: tmp = (x - y) / (2.0 - y) return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) <= 0.005) tmp = Float64(Float64(x - y) / Float64(2.0 - x)); else tmp = Float64(Float64(x - y) / Float64(2.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x - y) / (2.0 - (x + y))) <= 0.005) tmp = (x - y) / (2.0 - x); else tmp = (x - y) / (2.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.005], N[(N[(x - y), $MachinePrecision] / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / N[(2.0 - 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) / ((2) - (x + y))) <= (5000000000000000104083408558608425664715468883514404296875e-60)) THEN ((x - y) / ((2) - x)) ELSE ((x - y) / ((2) - y)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{2 - \left(x + y\right)} \leq 0.005:\\
\;\;\;\;\frac{x - y}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{2 - y}\\
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites63.5%
if 0.0050000000000000001 < (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites62.2%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (- x y) (- 2.0 (+ x y))) 0.005) (/ (- x y) (- 2.0 x)) 1.0))
double code(double x, double y) {
double tmp;
if (((x - y) / (2.0 - (x + y))) <= 0.005) {
tmp = (x - y) / (2.0 - x);
} 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) / (2.0d0 - (x + y))) <= 0.005d0) then
tmp = (x - y) / (2.0d0 - x)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x - y) / (2.0 - (x + y))) <= 0.005) {
tmp = (x - y) / (2.0 - x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x - y) / (2.0 - (x + y))) <= 0.005: tmp = (x - y) / (2.0 - x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) <= 0.005) tmp = Float64(Float64(x - y) / Float64(2.0 - x)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x - y) / (2.0 - (x + y))) <= 0.005) tmp = (x - y) / (2.0 - x); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.005], N[(N[(x - y), $MachinePrecision] / N[(2.0 - x), $MachinePrecision]), $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) / ((2) - (x + y))) <= (5000000000000000104083408558608425664715468883514404296875e-60)) THEN ((x - y) / ((2) - x)) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{2 - \left(x + y\right)} \leq 0.005:\\
\;\;\;\;\frac{x - y}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites63.5%
if 0.0050000000000000001 < (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites37.3%
(FPCore (x y)
:precision binary64
:pre TRUE
(let* ((t_0 (/ (- x y) (- 2.0 (+ x y)))))
(if (<= t_0 -2e-7)
(/ x (- 2.0 x))
(if (<= t_0 0.005) (/ (- x y) 2.0) 1.0))))double code(double x, double y) {
double t_0 = (x - y) / (2.0 - (x + y));
double tmp;
if (t_0 <= -2e-7) {
tmp = x / (2.0 - x);
} else if (t_0 <= 0.005) {
tmp = (x - y) / 2.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) :: t_0
real(8) :: tmp
t_0 = (x - y) / (2.0d0 - (x + y))
if (t_0 <= (-2d-7)) then
tmp = x / (2.0d0 - x)
else if (t_0 <= 0.005d0) then
tmp = (x - y) / 2.0d0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - y) / (2.0 - (x + y));
double tmp;
if (t_0 <= -2e-7) {
tmp = x / (2.0 - x);
} else if (t_0 <= 0.005) {
tmp = (x - y) / 2.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / (2.0 - (x + y)) tmp = 0 if t_0 <= -2e-7: tmp = x / (2.0 - x) elif t_0 <= 0.005: tmp = (x - y) / 2.0 else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) tmp = 0.0 if (t_0 <= -2e-7) tmp = Float64(x / Float64(2.0 - x)); elseif (t_0 <= 0.005) tmp = Float64(Float64(x - y) / 2.0); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / (2.0 - (x + y)); tmp = 0.0; if (t_0 <= -2e-7) tmp = x / (2.0 - x); elseif (t_0 <= 0.005) tmp = (x - y) / 2.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-7], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.005], N[(N[(x - y), $MachinePrecision] / 2.0), $MachinePrecision], 1.0]]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET t_0 = ((x - y) / ((2) - (x + y))) IN LET tmp_1 = IF (t_0 <= (5000000000000000104083408558608425664715468883514404296875e-60)) THEN ((x - y) / (2)) ELSE (1) ENDIF IN LET tmp = IF (t_0 <= (-199999999999999990949622365177251737122787744738161563873291015625e-72)) THEN (x / ((2) - x)) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \frac{x - y}{2 - \left(x + y\right)}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-7}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{elif}\;t\_0 \leq 0.005:\\
\;\;\;\;\frac{x - y}{2}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) < -1.9999999999999999e-7Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites51.7%
if -1.9999999999999999e-7 < (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites63.5%
Taylor expanded in x around 0
Applied rewrites26.4%
if 0.0050000000000000001 < (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites37.3%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (- x y) (- 2.0 (+ x y))) 0.005) (/ x (- 2.0 x)) 1.0))
double code(double x, double y) {
double tmp;
if (((x - y) / (2.0 - (x + y))) <= 0.005) {
tmp = x / (2.0 - x);
} 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) / (2.0d0 - (x + y))) <= 0.005d0) then
tmp = x / (2.0d0 - x)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x - y) / (2.0 - (x + y))) <= 0.005) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x - y) / (2.0 - (x + y))) <= 0.005: tmp = x / (2.0 - x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) <= 0.005) tmp = Float64(x / Float64(2.0 - x)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x - y) / (2.0 - (x + y))) <= 0.005) tmp = x / (2.0 - x); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.005], N[(x / N[(2.0 - x), $MachinePrecision]), $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) / ((2) - (x + y))) <= (5000000000000000104083408558608425664715468883514404296875e-60)) THEN (x / ((2) - x)) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{2 - \left(x + y\right)} \leq 0.005:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites51.7%
if 0.0050000000000000001 < (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites37.3%
(FPCore (x y) :precision binary64 :pre TRUE (let* ((t_0 (/ (- x y) (- 2.0 (+ x y))))) (if (<= t_0 -0.5) -1.0 (if (<= t_0 0.005) (* 0.5 x) 1.0))))
double code(double x, double y) {
double t_0 = (x - y) / (2.0 - (x + y));
double tmp;
if (t_0 <= -0.5) {
tmp = -1.0;
} else if (t_0 <= 0.005) {
tmp = 0.5 * x;
} 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) :: t_0
real(8) :: tmp
t_0 = (x - y) / (2.0d0 - (x + y))
if (t_0 <= (-0.5d0)) then
tmp = -1.0d0
else if (t_0 <= 0.005d0) then
tmp = 0.5d0 * x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - y) / (2.0 - (x + y));
double tmp;
if (t_0 <= -0.5) {
tmp = -1.0;
} else if (t_0 <= 0.005) {
tmp = 0.5 * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / (2.0 - (x + y)) tmp = 0 if t_0 <= -0.5: tmp = -1.0 elif t_0 <= 0.005: tmp = 0.5 * x else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) tmp = 0.0 if (t_0 <= -0.5) tmp = -1.0; elseif (t_0 <= 0.005) tmp = Float64(0.5 * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / (2.0 - (x + y)); tmp = 0.0; if (t_0 <= -0.5) tmp = -1.0; elseif (t_0 <= 0.005) tmp = 0.5 * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.5], -1.0, If[LessEqual[t$95$0, 0.005], N[(0.5 * x), $MachinePrecision], 1.0]]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET t_0 = ((x - y) / ((2) - (x + y))) IN LET tmp_1 = IF (t_0 <= (5000000000000000104083408558608425664715468883514404296875e-60)) THEN ((5e-1) * x) ELSE (1) ENDIF IN LET tmp = IF (t_0 <= (-5e-1)) THEN (-1) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \frac{x - y}{2 - \left(x + y\right)}\\
\mathbf{if}\;t\_0 \leq -0.5:\\
\;\;\;\;-1\\
\mathbf{elif}\;t\_0 \leq 0.005:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) < -0.5Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites38.6%
if -0.5 < (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites51.7%
Taylor expanded in x around 0
Applied rewrites15.1%
if 0.0050000000000000001 < (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites37.3%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ (- x y) (- 2.0 (+ x y))) 1.2423345892717348e-287) -1.0 1.0))
double code(double x, double y) {
double tmp;
if (((x - y) / (2.0 - (x + y))) <= 1.2423345892717348e-287) {
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) / (2.0d0 - (x + y))) <= 1.2423345892717348d-287) 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) / (2.0 - (x + y))) <= 1.2423345892717348e-287) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x - y) / (2.0 - (x + y))) <= 1.2423345892717348e-287: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) <= 1.2423345892717348e-287) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x - y) / (2.0 - (x + y))) <= 1.2423345892717348e-287) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.2423345892717348e-287], -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) / ((2) - (x + y))) <= (1242334589271734766694965026517907720287440807835919262790717453718264796586232870372742219313993639126732271887653312891673217485764275913935208689788400991999425081684233369133967092053600591711271565009616305561755793329555419578904695226767333125048876406319501324407047827118955270741031890851361457221001975359953622888113881968686396988159422708259137900394205831693205730602502096063680098810999724250314232074827573860718884208569997659215263730395847721814035768566635675449346359019778049325138083304927054078954017120551506776185727842591748845651099572271896389078801269178897586440719058896315829702125368319145544851777972247625557177649505143600781948884891059403656754511757753789424896240234375e-998)) THEN (-1) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{2 - \left(x + y\right)} \leq 1.2423345892717348 \cdot 10^{-287}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) < 1.2423345892717348e-287Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites38.6%
if 1.2423345892717348e-287 < (/.f64 (-.f64 x y) (-.f64 #s(literal 2 binary64) (+.f64 x y))) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites37.3%
(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 inf
Applied rewrites38.6%
herbie shell --seed 2026092
(FPCore (x y)
:name "Data.Colour.RGB:hslsv from colour-2.3.3, C"
:precision binary64
(/ (- x y) (- 2.0 (+ x y))))