
(FPCore (x y) :precision binary64 (/ (- 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)
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]
\begin{array}{l}
\\
\frac{x - y}{\left(x \cdot 2\right) \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (- 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)
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]
\begin{array}{l}
\\
\frac{x - y}{\left(x \cdot 2\right) \cdot y}
\end{array}
(FPCore (x y) :precision binary64 (+ (/ 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)
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]
\begin{array}{l}
\\
\frac{0.5}{y} + \frac{-0.5}{x}
\end{array}
Initial program 78.3%
div-sub77.8%
sub-neg77.8%
associate-/r*85.3%
associate-/r*85.3%
*-inverses85.3%
metadata-eval85.3%
neg-mul-185.3%
metadata-eval85.3%
metadata-eval85.3%
times-frac85.3%
distribute-lft-neg-in85.3%
distribute-rgt-neg-in85.3%
neg-mul-185.3%
distribute-rgt-neg-out85.3%
times-frac100.0%
*-inverses100.0%
metadata-eval100.0%
associate-*l/100.0%
metadata-eval100.0%
metadata-eval100.0%
*-commutative100.0%
associate-/r*100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.4e+56) (/ 0.5 y) (if (<= x 1.75e-106) (/ -0.5 x) (/ 0.5 y))))
double code(double x, double y) {
double tmp;
if (x <= -1.4e+56) {
tmp = 0.5 / y;
} else if (x <= 1.75e-106) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.4d+56)) then
tmp = 0.5d0 / y
else if (x <= 1.75d-106) 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 <= -1.4e+56) {
tmp = 0.5 / y;
} else if (x <= 1.75e-106) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.4e+56: tmp = 0.5 / y elif x <= 1.75e-106: tmp = -0.5 / x else: tmp = 0.5 / y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.4e+56) tmp = Float64(0.5 / y); elseif (x <= 1.75e-106) 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 <= -1.4e+56) tmp = 0.5 / y; elseif (x <= 1.75e-106) tmp = -0.5 / x; else tmp = 0.5 / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.4e+56], N[(0.5 / y), $MachinePrecision], If[LessEqual[x, 1.75e-106], N[(-0.5 / x), $MachinePrecision], N[(0.5 / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+56}:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{-106}:\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{y}\\
\end{array}
\end{array}
if x < -1.40000000000000004e56 or 1.75e-106 < x Initial program 78.0%
div-sub77.8%
sub-neg77.8%
associate-/r*90.3%
associate-/r*90.3%
*-inverses90.3%
metadata-eval90.3%
neg-mul-190.3%
metadata-eval90.3%
metadata-eval90.3%
times-frac90.3%
distribute-lft-neg-in90.3%
distribute-rgt-neg-in90.3%
neg-mul-190.3%
distribute-rgt-neg-out90.3%
times-frac100.0%
*-inverses100.0%
metadata-eval100.0%
associate-*l/100.0%
metadata-eval100.0%
metadata-eval100.0%
*-commutative100.0%
associate-/r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 82.7%
if -1.40000000000000004e56 < x < 1.75e-106Initial program 78.6%
div-sub77.7%
sub-neg77.7%
associate-/r*78.4%
associate-/r*78.4%
*-inverses78.4%
metadata-eval78.4%
neg-mul-178.4%
metadata-eval78.4%
metadata-eval78.4%
times-frac78.4%
distribute-lft-neg-in78.4%
distribute-rgt-neg-in78.4%
neg-mul-178.4%
distribute-rgt-neg-out78.4%
times-frac100.0%
*-inverses100.0%
metadata-eval100.0%
associate-*l/100.0%
metadata-eval100.0%
metadata-eval100.0%
*-commutative100.0%
associate-/r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 80.8%
Final simplification81.9%
(FPCore (x y) :precision binary64 (/ -0.5 x))
double code(double x, double y) {
return -0.5 / x;
}
real(8) function code(x, y)
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]
\begin{array}{l}
\\
\frac{-0.5}{x}
\end{array}
Initial program 78.3%
div-sub77.8%
sub-neg77.8%
associate-/r*85.3%
associate-/r*85.3%
*-inverses85.3%
metadata-eval85.3%
neg-mul-185.3%
metadata-eval85.3%
metadata-eval85.3%
times-frac85.3%
distribute-lft-neg-in85.3%
distribute-rgt-neg-in85.3%
neg-mul-185.3%
distribute-rgt-neg-out85.3%
times-frac100.0%
*-inverses100.0%
metadata-eval100.0%
associate-*l/100.0%
metadata-eval100.0%
metadata-eval100.0%
*-commutative100.0%
associate-/r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 45.2%
Final simplification45.2%
(FPCore (x y) :precision binary64 (- (/ 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)
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]
\begin{array}{l}
\\
\frac{0.5}{y} - \frac{0.5}{x}
\end{array}
herbie shell --seed 2023279
(FPCore (x y)
:name "Linear.Projection:inversePerspective from linear-1.19.1.3, B"
:precision binary64
:herbie-target
(- (/ 0.5 y) (/ 0.5 x))
(/ (- x y) (* (* x 2.0) y)))