
(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 y) (/ 0.5 x)))
double code(double x, double y) {
return (0.5 / y) - (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 / y) - (0.5d0 / x)
end function
public static double code(double x, double y) {
return (0.5 / y) - (0.5 / x);
}
def code(x, y): return (0.5 / y) - (0.5 / x)
function code(x, y) return Float64(Float64(0.5 / y) - Float64(0.5 / x)) end
function tmp = code(x, y) tmp = (0.5 / y) - (0.5 / x); end
code[x_, y_] := N[(N[(0.5 / y), $MachinePrecision] - N[(0.5 / x), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = ((5e-1) / y) - ((5e-1) / x) END code
\frac{0.5}{y} - \frac{0.5}{x}
Initial program 77.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= x -3.1004388755873057e+78) (/ 0.5 y) (if (<= x 8.249630193851516e+85) (/ -0.5 x) (/ 0.5 y))))
double code(double x, double y) {
double tmp;
if (x <= -3.1004388755873057e+78) {
tmp = 0.5 / y;
} else if (x <= 8.249630193851516e+85) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / 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 <= (-3.1004388755873057d+78)) then
tmp = 0.5d0 / y
else if (x <= 8.249630193851516d+85) then
tmp = (-0.5d0) / x
else
tmp = 0.5d0 / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.1004388755873057e+78) {
tmp = 0.5 / y;
} else if (x <= 8.249630193851516e+85) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.1004388755873057e+78: tmp = 0.5 / y elif x <= 8.249630193851516e+85: tmp = -0.5 / x else: tmp = 0.5 / y return tmp
function code(x, y) tmp = 0.0 if (x <= -3.1004388755873057e+78) tmp = Float64(0.5 / y); elseif (x <= 8.249630193851516e+85) tmp = Float64(-0.5 / x); else tmp = Float64(0.5 / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.1004388755873057e+78) tmp = 0.5 / y; elseif (x <= 8.249630193851516e+85) tmp = -0.5 / x; else tmp = 0.5 / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.1004388755873057e+78], N[(0.5 / y), $MachinePrecision], If[LessEqual[x, 8.249630193851516e+85], N[(-0.5 / x), $MachinePrecision], N[(0.5 / y), $MachinePrecision]]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp_1 = IF (x <= (82496301938515155595674366554481906850508119056615024982644090771514546196319800655872)) THEN ((-5e-1) / x) ELSE ((5e-1) / y) ENDIF IN LET tmp = IF (x <= (-3100438875587305715332076491679402000941895339773951932515938630303066099810304)) THEN ((5e-1) / y) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq -3.1004388755873057 \cdot 10^{+78}:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{elif}\;x \leq 8.249630193851516 \cdot 10^{+85}:\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{y}\\
\end{array}
if x < -3.1004388755873057e78 or 8.2496301938515156e85 < x Initial program 77.0%
Taylor expanded in x around inf
Applied rewrites50.1%
if -3.1004388755873057e78 < x < 8.2496301938515156e85Initial 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, B"
:precision binary64
(/ (- x y) (* (* x 2.0) y)))