
(FPCore (x y) :precision binary64 (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = (y * 4.0d0) * y
code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y): t_0 = (y * 4.0) * y return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y) t_0 = Float64(Float64(y * 4.0) * y) return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) end
function tmp = code(x, y) t_0 = (y * 4.0) * y; tmp = ((x * x) - t_0) / ((x * x) + t_0); end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t_0}{x \cdot x + t_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (let* ((t_0 (* (* y 4.0) y))) (/ (- (* x x) t_0) (+ (* x x) t_0))))
double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = (y * 4.0d0) * y
code = ((x * x) - t_0) / ((x * x) + t_0)
end function
public static double code(double x, double y) {
double t_0 = (y * 4.0) * y;
return ((x * x) - t_0) / ((x * x) + t_0);
}
def code(x, y): t_0 = (y * 4.0) * y return ((x * x) - t_0) / ((x * x) + t_0)
function code(x, y) t_0 = Float64(Float64(y * 4.0) * y) return Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)) end
function tmp = code(x, y) t_0 = (y * 4.0) * y; tmp = ((x * x) - t_0) / ((x * x) + t_0); end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot 4\right) \cdot y\\
\frac{x \cdot x - t_0}{x \cdot x + t_0}
\end{array}
\end{array}
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= y 1.4e-97)
(fma (* 2.0 (log1p (/ 0.5 (pow (/ x y) 2.0)))) -8.0 1.0)
(if (<= y 1.75e+112)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(fma 0.5 (* (/ x y) (/ x y)) -1.0)))))y = abs(y);
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (y <= 1.4e-97) {
tmp = fma((2.0 * log1p((0.5 / pow((x / y), 2.0)))), -8.0, 1.0);
} else if (y <= 1.75e+112) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
}
return tmp;
}
y = abs(y) function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (y <= 1.4e-97) tmp = fma(Float64(2.0 * log1p(Float64(0.5 / (Float64(x / y) ^ 2.0)))), -8.0, 1.0); elseif (y <= 1.75e+112) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); end return tmp end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 1.4e-97], N[(N[(2.0 * N[Log[1 + N[(0.5 / N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision], If[LessEqual[y, 1.75e+112], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;y \leq 1.4 \cdot 10^{-97}:\\
\;\;\;\;\mathsf{fma}\left(2 \cdot \mathsf{log1p}\left(\frac{0.5}{{\left(\frac{x}{y}\right)}^{2}}\right), -8, 1\right)\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{+112}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\end{array}
\end{array}
if y < 1.4000000000000001e-97Initial program 53.5%
Taylor expanded in x around inf 54.1%
associate--l+54.1%
distribute-rgt-out--54.1%
metadata-eval54.1%
*-commutative54.1%
+-commutative54.1%
*-commutative54.1%
fma-def54.1%
unpow254.1%
unpow254.1%
times-frac58.4%
Simplified58.4%
add-log-exp57.9%
add-sqr-sqrt57.9%
log-prod57.9%
pow257.9%
pow257.9%
Applied egg-rr57.9%
count-257.9%
Simplified57.9%
Taylor expanded in y around 0 54.5%
unpow254.5%
unpow254.5%
times-frac60.0%
unpow260.0%
Simplified60.0%
*-un-lft-identity60.0%
log-prod60.0%
metadata-eval60.0%
log1p-def60.1%
unpow260.1%
clear-num60.1%
associate-/r/60.1%
un-div-inv60.1%
div-inv60.1%
clear-num60.1%
pow260.1%
Applied egg-rr60.1%
+-lft-identity60.1%
Simplified60.1%
if 1.4000000000000001e-97 < y < 1.74999999999999998e112Initial program 76.3%
if 1.74999999999999998e112 < y Initial program 15.2%
Taylor expanded in x around 0 65.5%
fma-neg65.5%
unpow265.5%
unpow265.5%
times-frac73.5%
metadata-eval73.5%
Simplified73.5%
Final simplification64.9%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= y 1e-97)
(fma (* 2.0 (log (+ 1.0 (/ (* 0.5 (/ y x)) (/ x y))))) -8.0 1.0)
(if (<= y 1.6e+112)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(fma 0.5 (* (/ x y) (/ x y)) -1.0)))))y = abs(y);
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (y <= 1e-97) {
tmp = fma((2.0 * log((1.0 + ((0.5 * (y / x)) / (x / y))))), -8.0, 1.0);
} else if (y <= 1.6e+112) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
}
return tmp;
}
y = abs(y) function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (y <= 1e-97) tmp = fma(Float64(2.0 * log(Float64(1.0 + Float64(Float64(0.5 * Float64(y / x)) / Float64(x / y))))), -8.0, 1.0); elseif (y <= 1.6e+112) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); end return tmp end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 1e-97], N[(N[(2.0 * N[Log[N[(1.0 + N[(N[(0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision], If[LessEqual[y, 1.6e+112], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;y \leq 10^{-97}:\\
\;\;\;\;\mathsf{fma}\left(2 \cdot \log \left(1 + \frac{0.5 \cdot \frac{y}{x}}{\frac{x}{y}}\right), -8, 1\right)\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{+112}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\end{array}
\end{array}
if y < 1.00000000000000004e-97Initial program 53.5%
Taylor expanded in x around inf 54.1%
associate--l+54.1%
distribute-rgt-out--54.1%
metadata-eval54.1%
*-commutative54.1%
+-commutative54.1%
*-commutative54.1%
fma-def54.1%
unpow254.1%
unpow254.1%
times-frac58.4%
Simplified58.4%
add-log-exp57.9%
add-sqr-sqrt57.9%
log-prod57.9%
pow257.9%
pow257.9%
Applied egg-rr57.9%
count-257.9%
Simplified57.9%
Taylor expanded in y around 0 54.5%
unpow254.5%
unpow254.5%
times-frac60.0%
unpow260.0%
Simplified60.0%
*-commutative60.0%
unpow260.0%
clear-num60.0%
div-inv60.0%
associate-*l/60.0%
Applied egg-rr60.0%
if 1.00000000000000004e-97 < y < 1.59999999999999993e112Initial program 76.3%
if 1.59999999999999993e112 < y Initial program 15.2%
Taylor expanded in x around 0 65.5%
fma-neg65.5%
unpow265.5%
unpow265.5%
times-frac73.5%
metadata-eval73.5%
Simplified73.5%
Final simplification64.9%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= t_0 5e-194)
(fma (* (/ y x) (/ y x)) -8.0 1.0)
(if (<= t_0 5e+216)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(fma 0.5 (* (/ x y) (/ x y)) -1.0)))))y = abs(y);
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 5e-194) {
tmp = fma(((y / x) * (y / x)), -8.0, 1.0);
} else if (t_0 <= 5e+216) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
}
return tmp;
}
y = abs(y) function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 5e-194) tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 1.0); elseif (t_0 <= 5e+216) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); end return tmp end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e-194], N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision], If[LessEqual[t$95$0, 5e+216], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{-194}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+216}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 5.0000000000000002e-194Initial program 59.2%
Taylor expanded in x around inf 80.7%
associate--l+80.7%
distribute-rgt-out--80.7%
metadata-eval80.7%
*-commutative80.7%
+-commutative80.7%
*-commutative80.7%
fma-def80.7%
unpow280.7%
unpow280.7%
times-frac86.9%
Simplified86.9%
if 5.0000000000000002e-194 < (*.f64 (*.f64 y 4) y) < 4.9999999999999998e216Initial program 79.2%
if 4.9999999999999998e216 < (*.f64 (*.f64 y 4) y) Initial program 15.1%
Taylor expanded in x around 0 75.7%
fma-neg75.7%
unpow275.7%
unpow275.7%
times-frac84.7%
metadata-eval84.7%
Simplified84.7%
Final simplification84.0%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= y 1.6e-94)
(+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))
(if (<= y 5.2e+112)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(fma 0.5 (* (/ x y) (/ x y)) -1.0)))))y = abs(y);
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (y <= 1.6e-94) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} else if (y <= 5.2e+112) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
}
return tmp;
}
y = abs(y) function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (y <= 1.6e-94) tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); elseif (y <= 5.2e+112) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); end return tmp end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 1.6e-94], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.2e+112], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;y \leq 1.6 \cdot 10^{-94}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+112}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\end{array}
\end{array}
if y < 1.59999999999999998e-94Initial program 53.5%
Taylor expanded in x around inf 36.4%
unpow236.4%
Simplified36.4%
Taylor expanded in x around inf 53.9%
unpow253.9%
unpow253.9%
times-frac58.2%
unpow258.2%
Simplified58.2%
unpow258.2%
clear-num58.2%
un-div-inv58.2%
Applied egg-rr58.2%
if 1.59999999999999998e-94 < y < 5.2000000000000001e112Initial program 76.3%
if 5.2000000000000001e112 < y Initial program 15.2%
Taylor expanded in x around 0 65.5%
fma-neg65.5%
unpow265.5%
unpow265.5%
times-frac73.5%
metadata-eval73.5%
Simplified73.5%
Final simplification63.7%
NOTE: y should be positive before calling this function
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= y 9.5e-98)
(+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))
(if (<= y 1.15e+111) (/ (- (* x x) t_0) (+ (* x x) t_0)) -1.0))))y = abs(y);
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (y <= 9.5e-98) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} else if (y <= 1.15e+111) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = -1.0;
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = y * (y * 4.0d0)
if (y <= 9.5d-98) then
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
else if (y <= 1.15d+111) then
tmp = ((x * x) - t_0) / ((x * x) + t_0)
else
tmp = -1.0d0
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (y <= 9.5e-98) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} else if (y <= 1.15e+111) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): t_0 = y * (y * 4.0) tmp = 0 if y <= 9.5e-98: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) elif y <= 1.15e+111: tmp = ((x * x) - t_0) / ((x * x) + t_0) else: tmp = -1.0 return tmp
y = abs(y) function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (y <= 9.5e-98) tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); elseif (y <= 1.15e+111) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = -1.0; end return tmp end
y = abs(y) function tmp_2 = code(x, y) t_0 = y * (y * 4.0); tmp = 0.0; if (y <= 9.5e-98) tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); elseif (y <= 1.15e+111) tmp = ((x * x) - t_0) / ((x * x) + t_0); else tmp = -1.0; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 9.5e-98], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.15e+111], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], -1.0]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;y \leq 9.5 \cdot 10^{-98}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+111}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 9.5000000000000001e-98Initial program 53.5%
Taylor expanded in x around inf 36.4%
unpow236.4%
Simplified36.4%
Taylor expanded in x around inf 53.9%
unpow253.9%
unpow253.9%
times-frac58.2%
unpow258.2%
Simplified58.2%
unpow258.2%
clear-num58.2%
un-div-inv58.2%
Applied egg-rr58.2%
if 9.5000000000000001e-98 < y < 1.15000000000000001e111Initial program 76.3%
if 1.15000000000000001e111 < y Initial program 15.2%
Taylor expanded in x around 0 72.1%
Final simplification63.4%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= (* y (* y 4.0)) 1e-21) (+ 1.0 (* -4.0 (/ (/ y x) (/ x y)))) -1.0))
y = abs(y);
double code(double x, double y) {
double tmp;
if ((y * (y * 4.0)) <= 1e-21) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} else {
tmp = -1.0;
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * (y * 4.0d0)) <= 1d-21) then
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
else
tmp = -1.0d0
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if ((y * (y * 4.0)) <= 1e-21) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} else {
tmp = -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if (y * (y * 4.0)) <= 1e-21: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) else: tmp = -1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (Float64(y * Float64(y * 4.0)) <= 1e-21) tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); else tmp = -1.0; end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if ((y * (y * 4.0)) <= 1e-21) tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); else tmp = -1.0; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision], 1e-21], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 10^{-21}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 9.99999999999999908e-22Initial program 64.3%
Taylor expanded in x around inf 52.9%
unpow252.9%
Simplified52.9%
Taylor expanded in x around inf 76.2%
unpow276.2%
unpow276.2%
times-frac80.9%
unpow280.9%
Simplified80.9%
unpow280.9%
clear-num80.9%
un-div-inv80.9%
Applied egg-rr80.9%
if 9.99999999999999908e-22 < (*.f64 (*.f64 y 4) y) Initial program 35.4%
Taylor expanded in x around 0 79.5%
Final simplification80.2%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 2e-11) 1.0 -1.0))
y = abs(y);
double code(double x, double y) {
double tmp;
if (y <= 2e-11) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2d-11) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
double tmp;
if (y <= 2e-11) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
y = abs(y) def code(x, y): tmp = 0 if y <= 2e-11: tmp = 1.0 else: tmp = -1.0 return tmp
y = abs(y) function code(x, y) tmp = 0.0 if (y <= 2e-11) tmp = 1.0; else tmp = -1.0; end return tmp end
y = abs(y) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2e-11) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_] := If[LessEqual[y, 2e-11], 1.0, -1.0]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-11}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.99999999999999988e-11Initial program 56.3%
Taylor expanded in x around inf 57.5%
if 1.99999999999999988e-11 < y Initial program 31.8%
Taylor expanded in x around 0 68.6%
Final simplification60.4%
NOTE: y should be positive before calling this function (FPCore (x y) :precision binary64 -1.0)
y = abs(y);
double code(double x, double y) {
return -1.0;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
y = Math.abs(y);
public static double code(double x, double y) {
return -1.0;
}
y = abs(y) def code(x, y): return -1.0
y = abs(y) function code(x, y) return -1.0 end
y = abs(y) function tmp = code(x, y) tmp = -1.0; end
NOTE: y should be positive before calling this function code[x_, y_] := -1.0
\begin{array}{l}
y = |y|\\
\\
-1
\end{array}
Initial program 50.0%
Taylor expanded in x around 0 49.8%
Final simplification49.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (* y y) 4.0))
(t_1 (+ (* x x) t_0))
(t_2 (/ t_0 t_1))
(t_3 (* (* y 4.0) y)))
(if (< (/ (- (* x x) t_3) (+ (* x x) t_3)) 0.9743233849626781)
(- (/ (* x x) t_1) t_2)
(- (pow (/ x (sqrt t_1)) 2.0) t_2))))
double code(double x, double y) {
double t_0 = (y * y) * 4.0;
double t_1 = (x * x) + t_0;
double t_2 = t_0 / t_1;
double t_3 = (y * 4.0) * y;
double tmp;
if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) {
tmp = ((x * x) / t_1) - t_2;
} else {
tmp = pow((x / sqrt(t_1)), 2.0) - t_2;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = (y * y) * 4.0d0
t_1 = (x * x) + t_0
t_2 = t_0 / t_1
t_3 = (y * 4.0d0) * y
if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781d0) then
tmp = ((x * x) / t_1) - t_2
else
tmp = ((x / sqrt(t_1)) ** 2.0d0) - t_2
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y * y) * 4.0;
double t_1 = (x * x) + t_0;
double t_2 = t_0 / t_1;
double t_3 = (y * 4.0) * y;
double tmp;
if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) {
tmp = ((x * x) / t_1) - t_2;
} else {
tmp = Math.pow((x / Math.sqrt(t_1)), 2.0) - t_2;
}
return tmp;
}
def code(x, y): t_0 = (y * y) * 4.0 t_1 = (x * x) + t_0 t_2 = t_0 / t_1 t_3 = (y * 4.0) * y tmp = 0 if (((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781: tmp = ((x * x) / t_1) - t_2 else: tmp = math.pow((x / math.sqrt(t_1)), 2.0) - t_2 return tmp
function code(x, y) t_0 = Float64(Float64(y * y) * 4.0) t_1 = Float64(Float64(x * x) + t_0) t_2 = Float64(t_0 / t_1) t_3 = Float64(Float64(y * 4.0) * y) tmp = 0.0 if (Float64(Float64(Float64(x * x) - t_3) / Float64(Float64(x * x) + t_3)) < 0.9743233849626781) tmp = Float64(Float64(Float64(x * x) / t_1) - t_2); else tmp = Float64((Float64(x / sqrt(t_1)) ^ 2.0) - t_2); end return tmp end
function tmp_2 = code(x, y) t_0 = (y * y) * 4.0; t_1 = (x * x) + t_0; t_2 = t_0 / t_1; t_3 = (y * 4.0) * y; tmp = 0.0; if ((((x * x) - t_3) / ((x * x) + t_3)) < 0.9743233849626781) tmp = ((x * x) / t_1) - t_2; else tmp = ((x / sqrt(t_1)) ^ 2.0) - t_2; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * y), $MachinePrecision] * 4.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, If[Less[N[(N[(N[(x * x), $MachinePrecision] - t$95$3), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$3), $MachinePrecision]), $MachinePrecision], 0.9743233849626781], N[(N[(N[(x * x), $MachinePrecision] / t$95$1), $MachinePrecision] - t$95$2), $MachinePrecision], N[(N[Power[N[(x / N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - t$95$2), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot y\right) \cdot 4\\
t_1 := x \cdot x + t_0\\
t_2 := \frac{t_0}{t_1}\\
t_3 := \left(y \cdot 4\right) \cdot y\\
\mathbf{if}\;\frac{x \cdot x - t_3}{x \cdot x + t_3} < 0.9743233849626781:\\
\;\;\;\;\frac{x \cdot x}{t_1} - t_2\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{x}{\sqrt{t_1}}\right)}^{2} - t_2\\
\end{array}
\end{array}
herbie shell --seed 2023229
(FPCore (x y)
:name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))
(/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))