
(FPCore (x y) :precision binary64 :pre TRUE (/ x (+ y x)))
double code(double x, double y) {
return x / (y + x);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (y + x)
end function
public static double code(double x, double y) {
return x / (y + x);
}
def code(x, y): return x / (y + x)
function code(x, y) return Float64(x / Float64(y + x)) end
function tmp = code(x, y) tmp = x / (y + x); end
code[x_, y_] := N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x / (y + x) END code
\frac{x}{y + x}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (/ x (+ y x)))
double code(double x, double y) {
return x / (y + x);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (y + x)
end function
public static double code(double x, double y) {
return x / (y + x);
}
def code(x, y): return x / (y + x)
function code(x, y) return Float64(x / Float64(y + x)) end
function tmp = code(x, y) tmp = x / (y + x); end
code[x_, y_] := N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x / (y + x) END code
\frac{x}{y + x}
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (/ x (+ y x)) 1e-17) (/ x y) 1.0))
double code(double x, double y) {
double tmp;
if ((x / (y + x)) <= 1e-17) {
tmp = x / 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)) <= 1d-17) then
tmp = x / 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)) <= 1e-17) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x / (y + x)) <= 1e-17: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(x / Float64(y + x)) <= 1e-17) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x / (y + x)) <= 1e-17) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision], 1e-17], N[(x / 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)) <= (100000000000000007154242405462192450852805618492324772617063644020163337700068950653076171875e-109)) THEN (x / y) ELSE (1) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{y + x} \leq 10^{-17}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
if (/.f64 x (+.f64 y x)) < 1.0000000000000001e-17Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.8%
if 1.0000000000000001e-17 < (/.f64 x (+.f64 y x)) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites50.7%
(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 rewrites50.7%
herbie shell --seed 2026092
(FPCore (x y)
:name "AI.Clustering.Hierarchical.Internal:average from clustering-0.2.1, B"
:precision binary64
(/ x (+ y x)))