
(FPCore (x y) :precision binary64 :pre TRUE (/ (+ x y) (* (* x 2.0) y)))
double code(double x, double y) {
return (x + y) / ((x * 2.0) * 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 * 2.0d0) * y)
end function
public static double code(double x, double y) {
return (x + y) / ((x * 2.0) * y);
}
def code(x, y): return (x + y) / ((x * 2.0) * y)
function code(x, y) return Float64(Float64(x + y) / Float64(Float64(x * 2.0) * y)) end
function tmp = code(x, y) tmp = (x + y) / ((x * 2.0) * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(N[(x * 2.0), $MachinePrecision] * 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 * (2)) * y) END code
\frac{x + y}{\left(x \cdot 2\right) \cdot y}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (/ (+ x y) (* (* x 2.0) y)))
double code(double x, double y) {
return (x + y) / ((x * 2.0) * 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 * 2.0d0) * y)
end function
public static double code(double x, double y) {
return (x + y) / ((x * 2.0) * y);
}
def code(x, y): return (x + y) / ((x * 2.0) * y)
function code(x, y) return Float64(Float64(x + y) / Float64(Float64(x * 2.0) * y)) end
function tmp = code(x, y) tmp = (x + y) / ((x * 2.0) * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(N[(x * 2.0), $MachinePrecision] * 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 * (2)) * y) END code
\frac{x + y}{\left(x \cdot 2\right) \cdot y}
(FPCore (x y) :precision binary64 :pre TRUE (+ (/ 0.5 x) (/ 0.5 y)))
double code(double x, double y) {
return (0.5 / x) + (0.5 / y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (0.5d0 / x) + (0.5d0 / y)
end function
public static double code(double x, double y) {
return (0.5 / x) + (0.5 / y);
}
def code(x, y): return (0.5 / x) + (0.5 / y)
function code(x, y) return Float64(Float64(0.5 / x) + Float64(0.5 / y)) end
function tmp = code(x, y) tmp = (0.5 / x) + (0.5 / y); end
code[x_, y_] := N[(N[(0.5 / x), $MachinePrecision] + N[(0.5 / y), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = ((5e-1) / x) + ((5e-1) / y) END code
\frac{0.5}{x} + \frac{0.5}{y}
Initial program 77.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (fmin x y) -6.880405119228122e-63) (/ 0.5 (fmax x y)) (/ 0.5 (fmin x y))))
double code(double x, double y) {
double tmp;
if (fmin(x, y) <= -6.880405119228122e-63) {
tmp = 0.5 / fmax(x, y);
} else {
tmp = 0.5 / fmin(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 (fmin(x, y) <= (-6.880405119228122d-63)) then
tmp = 0.5d0 / fmax(x, y)
else
tmp = 0.5d0 / fmin(x, y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (fmin(x, y) <= -6.880405119228122e-63) {
tmp = 0.5 / fmax(x, y);
} else {
tmp = 0.5 / fmin(x, y);
}
return tmp;
}
def code(x, y): tmp = 0 if fmin(x, y) <= -6.880405119228122e-63: tmp = 0.5 / fmax(x, y) else: tmp = 0.5 / fmin(x, y) return tmp
function code(x, y) tmp = 0.0 if (fmin(x, y) <= -6.880405119228122e-63) tmp = Float64(0.5 / fmax(x, y)); else tmp = Float64(0.5 / fmin(x, y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (min(x, y) <= -6.880405119228122e-63) tmp = 0.5 / max(x, y); else tmp = 0.5 / min(x, y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Min[x, y], $MachinePrecision], -6.880405119228122e-63], N[(0.5 / N[Max[x, y], $MachinePrecision]), $MachinePrecision], N[(0.5 / N[Min[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_2 = IF (x < y) THEN x ELSE y ENDIF IN LET tmp_3 = IF (x > y) THEN x ELSE y ENDIF IN LET tmp_4 = IF (x < y) THEN x ELSE y ENDIF IN LET tmp_1 = IF (tmp_2 <= (-68804051192281219585901139254960001215248046074855352696448477138479341380611927281996856719191995576752147176451878101687846773781836984194551142165398207976856337353410708601586520671844482421875e-259)) THEN ((5e-1) / tmp_3) ELSE ((5e-1) / tmp_4) ENDIF IN tmp_1 END code
\begin{array}{l}
\mathbf{if}\;\mathsf{min}\left(x, y\right) \leq -6.880405119228122 \cdot 10^{-63}:\\
\;\;\;\;\frac{0.5}{\mathsf{max}\left(x, y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\mathsf{min}\left(x, y\right)}\\
\end{array}
if x < -6.880405119228122e-63Initial program 77.0%
Taylor expanded in x around inf
Applied rewrites50.2%
if -6.880405119228122e-63 < x Initial program 77.0%
Taylor expanded in x around 0
Applied rewrites51.1%
(FPCore (x y) :precision binary64 :pre TRUE (/ 0.5 x))
double code(double x, double y) {
return 0.5 / x;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 / x
end function
public static double code(double x, double y) {
return 0.5 / x;
}
def code(x, y): return 0.5 / x
function code(x, y) return Float64(0.5 / x) end
function tmp = code(x, y) tmp = 0.5 / x; end
code[x_, y_] := N[(0.5 / x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (5e-1) / x END code
\frac{0.5}{x}
Initial program 77.0%
Taylor expanded in x around 0
Applied rewrites51.1%
herbie shell --seed 2026092
(FPCore (x y)
:name "Linear.Projection:inversePerspective from linear-1.19.1.3, C"
:precision binary64
(/ (+ x y) (* (* x 2.0) y)))