
(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 6 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}
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (* (* y (/ y x)) (/ 8.0 x))))
(t_1 (* y (* y 4.0)))
(t_2 (/ (- (* x x) t_1) (+ t_1 (* x x)))))
(if (<= t_1 2e-296)
t_0
(if (<= t_1 1e-134)
t_2
(if (<= t_1 1e-65)
t_0
(if (<= t_1 2e+223) t_2 (+ (* 0.5 (pow (/ x y) 2.0)) -1.0)))))))
double code(double x, double y) {
double t_0 = 1.0 - ((y * (y / x)) * (8.0 / x));
double t_1 = y * (y * 4.0);
double t_2 = ((x * x) - t_1) / (t_1 + (x * x));
double tmp;
if (t_1 <= 2e-296) {
tmp = t_0;
} else if (t_1 <= 1e-134) {
tmp = t_2;
} else if (t_1 <= 1e-65) {
tmp = t_0;
} else if (t_1 <= 2e+223) {
tmp = t_2;
} else {
tmp = (0.5 * pow((x / y), 2.0)) + -1.0;
}
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) :: tmp
t_0 = 1.0d0 - ((y * (y / x)) * (8.0d0 / x))
t_1 = y * (y * 4.0d0)
t_2 = ((x * x) - t_1) / (t_1 + (x * x))
if (t_1 <= 2d-296) then
tmp = t_0
else if (t_1 <= 1d-134) then
tmp = t_2
else if (t_1 <= 1d-65) then
tmp = t_0
else if (t_1 <= 2d+223) then
tmp = t_2
else
tmp = (0.5d0 * ((x / y) ** 2.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 - ((y * (y / x)) * (8.0 / x));
double t_1 = y * (y * 4.0);
double t_2 = ((x * x) - t_1) / (t_1 + (x * x));
double tmp;
if (t_1 <= 2e-296) {
tmp = t_0;
} else if (t_1 <= 1e-134) {
tmp = t_2;
} else if (t_1 <= 1e-65) {
tmp = t_0;
} else if (t_1 <= 2e+223) {
tmp = t_2;
} else {
tmp = (0.5 * Math.pow((x / y), 2.0)) + -1.0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - ((y * (y / x)) * (8.0 / x)) t_1 = y * (y * 4.0) t_2 = ((x * x) - t_1) / (t_1 + (x * x)) tmp = 0 if t_1 <= 2e-296: tmp = t_0 elif t_1 <= 1e-134: tmp = t_2 elif t_1 <= 1e-65: tmp = t_0 elif t_1 <= 2e+223: tmp = t_2 else: tmp = (0.5 * math.pow((x / y), 2.0)) + -1.0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(Float64(y * Float64(y / x)) * Float64(8.0 / x))) t_1 = Float64(y * Float64(y * 4.0)) t_2 = Float64(Float64(Float64(x * x) - t_1) / Float64(t_1 + Float64(x * x))) tmp = 0.0 if (t_1 <= 2e-296) tmp = t_0; elseif (t_1 <= 1e-134) tmp = t_2; elseif (t_1 <= 1e-65) tmp = t_0; elseif (t_1 <= 2e+223) tmp = t_2; else tmp = Float64(Float64(0.5 * (Float64(x / y) ^ 2.0)) + -1.0); end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - ((y * (y / x)) * (8.0 / x)); t_1 = y * (y * 4.0); t_2 = ((x * x) - t_1) / (t_1 + (x * x)); tmp = 0.0; if (t_1 <= 2e-296) tmp = t_0; elseif (t_1 <= 1e-134) tmp = t_2; elseif (t_1 <= 1e-65) tmp = t_0; elseif (t_1 <= 2e+223) tmp = t_2; else tmp = (0.5 * ((x / y) ^ 2.0)) + -1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision] * N[(8.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * x), $MachinePrecision] - t$95$1), $MachinePrecision] / N[(t$95$1 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 2e-296], t$95$0, If[LessEqual[t$95$1, 1e-134], t$95$2, If[LessEqual[t$95$1, 1e-65], t$95$0, If[LessEqual[t$95$1, 2e+223], t$95$2, N[(N[(0.5 * N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \left(y \cdot \frac{y}{x}\right) \cdot \frac{8}{x}\\
t_1 := y \cdot \left(y \cdot 4\right)\\
t_2 := \frac{x \cdot x - t_1}{t_1 + x \cdot x}\\
\mathbf{if}\;t_1 \leq 2 \cdot 10^{-296}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_1 \leq 10^{-134}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq 10^{-65}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+223}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {\left(\frac{x}{y}\right)}^{2} + -1\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 2e-296 or 1.00000000000000004e-134 < (*.f64 (*.f64 y 4) y) < 9.99999999999999923e-66Initial program 57.5%
frac-2neg57.5%
div-inv57.4%
sub-neg57.4%
+-commutative57.4%
*-commutative57.4%
distribute-rgt-neg-in57.4%
fma-def57.4%
distribute-rgt-neg-in57.4%
metadata-eval57.4%
+-commutative57.4%
distribute-neg-in57.4%
*-commutative57.4%
distribute-rgt-neg-in57.4%
fma-def57.4%
distribute-rgt-neg-in57.4%
metadata-eval57.4%
Applied egg-rr57.4%
distribute-rgt-neg-in57.4%
Simplified57.4%
fma-udef57.4%
Applied egg-rr57.4%
Taylor expanded in x around inf 82.5%
mul-1-neg82.5%
unsub-neg82.5%
unpow282.5%
unpow282.5%
distribute-rgt-out--82.5%
metadata-eval82.5%
unpow282.5%
times-frac90.2%
associate-*r/90.7%
Simplified90.7%
if 2e-296 < (*.f64 (*.f64 y 4) y) < 1.00000000000000004e-134 or 9.99999999999999923e-66 < (*.f64 (*.f64 y 4) y) < 2.00000000000000009e223Initial program 81.6%
if 2.00000000000000009e223 < (*.f64 (*.f64 y 4) y) Initial program 14.1%
frac-2neg14.1%
div-inv14.1%
sub-neg14.1%
+-commutative14.1%
*-commutative14.1%
distribute-rgt-neg-in14.1%
fma-def14.1%
distribute-rgt-neg-in14.1%
metadata-eval14.1%
+-commutative14.1%
distribute-neg-in14.1%
*-commutative14.1%
distribute-rgt-neg-in14.1%
fma-def14.1%
distribute-rgt-neg-in14.1%
metadata-eval14.1%
Applied egg-rr14.1%
distribute-rgt-neg-in14.1%
Simplified14.1%
Taylor expanded in x around 0 62.8%
associate--l+62.8%
fma-def62.8%
metadata-eval62.8%
pow-sqr62.8%
unpow262.8%
unpow262.8%
metadata-eval62.8%
pow-sqr62.8%
times-frac82.1%
unpow282.1%
times-frac82.1%
unpow282.1%
unpow282.1%
times-frac82.1%
unpow282.1%
pow-sqr82.1%
metadata-eval82.1%
fma-neg82.1%
Simplified87.3%
fma-udef87.3%
fma-udef87.3%
associate-+r+87.3%
*-commutative87.3%
Applied egg-rr87.3%
Taylor expanded in x around 0 82.3%
unpow282.3%
unpow282.3%
times-frac87.8%
unpow287.8%
Simplified87.8%
Final simplification86.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (* (* y (/ y x)) (/ 8.0 x))))
(t_1 (* y (* y 4.0)))
(t_2 (/ (- (* x x) t_1) (+ t_1 (* x x)))))
(if (<= t_1 2e-296)
t_0
(if (<= t_1 1e-134)
t_2
(if (<= t_1 1e-65)
t_0
(if (<= t_1 2e+223) t_2 (+ -1.0 (/ (/ (/ x y) (/ y x)) 4.0))))))))
double code(double x, double y) {
double t_0 = 1.0 - ((y * (y / x)) * (8.0 / x));
double t_1 = y * (y * 4.0);
double t_2 = ((x * x) - t_1) / (t_1 + (x * x));
double tmp;
if (t_1 <= 2e-296) {
tmp = t_0;
} else if (t_1 <= 1e-134) {
tmp = t_2;
} else if (t_1 <= 1e-65) {
tmp = t_0;
} else if (t_1 <= 2e+223) {
tmp = t_2;
} else {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
}
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) :: tmp
t_0 = 1.0d0 - ((y * (y / x)) * (8.0d0 / x))
t_1 = y * (y * 4.0d0)
t_2 = ((x * x) - t_1) / (t_1 + (x * x))
if (t_1 <= 2d-296) then
tmp = t_0
else if (t_1 <= 1d-134) then
tmp = t_2
else if (t_1 <= 1d-65) then
tmp = t_0
else if (t_1 <= 2d+223) then
tmp = t_2
else
tmp = (-1.0d0) + (((x / y) / (y / x)) / 4.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 - ((y * (y / x)) * (8.0 / x));
double t_1 = y * (y * 4.0);
double t_2 = ((x * x) - t_1) / (t_1 + (x * x));
double tmp;
if (t_1 <= 2e-296) {
tmp = t_0;
} else if (t_1 <= 1e-134) {
tmp = t_2;
} else if (t_1 <= 1e-65) {
tmp = t_0;
} else if (t_1 <= 2e+223) {
tmp = t_2;
} else {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
}
return tmp;
}
def code(x, y): t_0 = 1.0 - ((y * (y / x)) * (8.0 / x)) t_1 = y * (y * 4.0) t_2 = ((x * x) - t_1) / (t_1 + (x * x)) tmp = 0 if t_1 <= 2e-296: tmp = t_0 elif t_1 <= 1e-134: tmp = t_2 elif t_1 <= 1e-65: tmp = t_0 elif t_1 <= 2e+223: tmp = t_2 else: tmp = -1.0 + (((x / y) / (y / x)) / 4.0) return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(Float64(y * Float64(y / x)) * Float64(8.0 / x))) t_1 = Float64(y * Float64(y * 4.0)) t_2 = Float64(Float64(Float64(x * x) - t_1) / Float64(t_1 + Float64(x * x))) tmp = 0.0 if (t_1 <= 2e-296) tmp = t_0; elseif (t_1 <= 1e-134) tmp = t_2; elseif (t_1 <= 1e-65) tmp = t_0; elseif (t_1 <= 2e+223) tmp = t_2; else tmp = Float64(-1.0 + Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0)); end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - ((y * (y / x)) * (8.0 / x)); t_1 = y * (y * 4.0); t_2 = ((x * x) - t_1) / (t_1 + (x * x)); tmp = 0.0; if (t_1 <= 2e-296) tmp = t_0; elseif (t_1 <= 1e-134) tmp = t_2; elseif (t_1 <= 1e-65) tmp = t_0; elseif (t_1 <= 2e+223) tmp = t_2; else tmp = -1.0 + (((x / y) / (y / x)) / 4.0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision] * N[(8.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * x), $MachinePrecision] - t$95$1), $MachinePrecision] / N[(t$95$1 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 2e-296], t$95$0, If[LessEqual[t$95$1, 1e-134], t$95$2, If[LessEqual[t$95$1, 1e-65], t$95$0, If[LessEqual[t$95$1, 2e+223], t$95$2, N[(-1.0 + N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \left(y \cdot \frac{y}{x}\right) \cdot \frac{8}{x}\\
t_1 := y \cdot \left(y \cdot 4\right)\\
t_2 := \frac{x \cdot x - t_1}{t_1 + x \cdot x}\\
\mathbf{if}\;t_1 \leq 2 \cdot 10^{-296}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_1 \leq 10^{-134}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq 10^{-65}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+223}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4}\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 2e-296 or 1.00000000000000004e-134 < (*.f64 (*.f64 y 4) y) < 9.99999999999999923e-66Initial program 57.5%
frac-2neg57.5%
div-inv57.4%
sub-neg57.4%
+-commutative57.4%
*-commutative57.4%
distribute-rgt-neg-in57.4%
fma-def57.4%
distribute-rgt-neg-in57.4%
metadata-eval57.4%
+-commutative57.4%
distribute-neg-in57.4%
*-commutative57.4%
distribute-rgt-neg-in57.4%
fma-def57.4%
distribute-rgt-neg-in57.4%
metadata-eval57.4%
Applied egg-rr57.4%
distribute-rgt-neg-in57.4%
Simplified57.4%
fma-udef57.4%
Applied egg-rr57.4%
Taylor expanded in x around inf 82.5%
mul-1-neg82.5%
unsub-neg82.5%
unpow282.5%
unpow282.5%
distribute-rgt-out--82.5%
metadata-eval82.5%
unpow282.5%
times-frac90.2%
associate-*r/90.7%
Simplified90.7%
if 2e-296 < (*.f64 (*.f64 y 4) y) < 1.00000000000000004e-134 or 9.99999999999999923e-66 < (*.f64 (*.f64 y 4) y) < 2.00000000000000009e223Initial program 81.6%
if 2.00000000000000009e223 < (*.f64 (*.f64 y 4) y) Initial program 14.1%
Taylor expanded in x around 0 14.3%
*-commutative14.3%
unpow214.3%
associate-*r*14.3%
Simplified14.3%
div-sub14.3%
associate-*r*14.3%
associate-/r*14.3%
frac-times14.4%
pow214.4%
*-commutative14.4%
*-inverses87.8%
Applied egg-rr87.8%
unpow287.8%
clear-num87.8%
un-div-inv87.8%
Applied egg-rr87.8%
Final simplification86.3%
(FPCore (x y) :precision binary64 (if (<= (* y (* y 4.0)) 1e-65) (- 1.0 (* (* y (/ y x)) (/ 8.0 x))) (+ -1.0 (/ (/ (/ x y) (/ y x)) 4.0))))
double code(double x, double y) {
double tmp;
if ((y * (y * 4.0)) <= 1e-65) {
tmp = 1.0 - ((y * (y / x)) * (8.0 / x));
} else {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
}
return tmp;
}
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-65) then
tmp = 1.0d0 - ((y * (y / x)) * (8.0d0 / x))
else
tmp = (-1.0d0) + (((x / y) / (y / x)) / 4.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * (y * 4.0)) <= 1e-65) {
tmp = 1.0 - ((y * (y / x)) * (8.0 / x));
} else {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * (y * 4.0)) <= 1e-65: tmp = 1.0 - ((y * (y / x)) * (8.0 / x)) else: tmp = -1.0 + (((x / y) / (y / x)) / 4.0) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * Float64(y * 4.0)) <= 1e-65) tmp = Float64(1.0 - Float64(Float64(y * Float64(y / x)) * Float64(8.0 / x))); else tmp = Float64(-1.0 + Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * (y * 4.0)) <= 1e-65) tmp = 1.0 - ((y * (y / x)) * (8.0 / x)); else tmp = -1.0 + (((x / y) / (y / x)) / 4.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision], 1e-65], N[(1.0 - N[(N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision] * N[(8.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 10^{-65}:\\
\;\;\;\;1 - \left(y \cdot \frac{y}{x}\right) \cdot \frac{8}{x}\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4}\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 9.99999999999999923e-66Initial program 67.2%
frac-2neg67.2%
div-inv67.1%
sub-neg67.1%
+-commutative67.1%
*-commutative67.1%
distribute-rgt-neg-in67.1%
fma-def67.1%
distribute-rgt-neg-in67.1%
metadata-eval67.1%
+-commutative67.1%
distribute-neg-in67.1%
*-commutative67.1%
distribute-rgt-neg-in67.1%
fma-def67.1%
distribute-rgt-neg-in67.1%
metadata-eval67.1%
Applied egg-rr67.1%
distribute-rgt-neg-in67.1%
Simplified67.1%
fma-udef67.1%
Applied egg-rr67.1%
Taylor expanded in x around inf 78.1%
mul-1-neg78.1%
unsub-neg78.1%
unpow278.1%
unpow278.1%
distribute-rgt-out--78.1%
metadata-eval78.1%
unpow278.1%
times-frac83.4%
associate-*r/83.7%
Simplified83.7%
if 9.99999999999999923e-66 < (*.f64 (*.f64 y 4) y) Initial program 42.1%
Taylor expanded in x around 0 36.3%
*-commutative36.3%
unpow236.3%
associate-*r*36.3%
Simplified36.3%
div-sub36.3%
associate-*r*36.3%
associate-/r*36.3%
frac-times36.3%
pow236.3%
*-commutative36.3%
*-inverses77.2%
Applied egg-rr77.2%
unpow277.2%
clear-num77.2%
un-div-inv77.2%
Applied egg-rr77.2%
Final simplification80.2%
(FPCore (x y) :precision binary64 (if (<= y -1.05e-31) -1.0 (if (<= y 1.9e-6) (- 1.0 (* (* y (/ y x)) (/ 8.0 x))) -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.05e-31) {
tmp = -1.0;
} else if (y <= 1.9e-6) {
tmp = 1.0 - ((y * (y / x)) * (8.0 / x));
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.05d-31)) then
tmp = -1.0d0
else if (y <= 1.9d-6) then
tmp = 1.0d0 - ((y * (y / x)) * (8.0d0 / x))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.05e-31) {
tmp = -1.0;
} else if (y <= 1.9e-6) {
tmp = 1.0 - ((y * (y / x)) * (8.0 / x));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.05e-31: tmp = -1.0 elif y <= 1.9e-6: tmp = 1.0 - ((y * (y / x)) * (8.0 / x)) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.05e-31) tmp = -1.0; elseif (y <= 1.9e-6) tmp = Float64(1.0 - Float64(Float64(y * Float64(y / x)) * Float64(8.0 / x))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.05e-31) tmp = -1.0; elseif (y <= 1.9e-6) tmp = 1.0 - ((y * (y / x)) * (8.0 / x)); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.05e-31], -1.0, If[LessEqual[y, 1.9e-6], N[(1.0 - N[(N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision] * N[(8.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-31}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-6}:\\
\;\;\;\;1 - \left(y \cdot \frac{y}{x}\right) \cdot \frac{8}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -1.04999999999999996e-31 or 1.9e-6 < y Initial program 41.9%
Taylor expanded in x around 0 77.2%
if -1.04999999999999996e-31 < y < 1.9e-6Initial program 66.7%
frac-2neg66.7%
div-inv66.5%
sub-neg66.5%
+-commutative66.5%
*-commutative66.5%
distribute-rgt-neg-in66.5%
fma-def66.5%
distribute-rgt-neg-in66.5%
metadata-eval66.5%
+-commutative66.5%
distribute-neg-in66.5%
*-commutative66.5%
distribute-rgt-neg-in66.5%
fma-def66.5%
distribute-rgt-neg-in66.5%
metadata-eval66.5%
Applied egg-rr66.5%
distribute-rgt-neg-in66.5%
Simplified66.5%
fma-udef66.5%
Applied egg-rr66.5%
Taylor expanded in x around inf 77.2%
mul-1-neg77.2%
unsub-neg77.2%
unpow277.2%
unpow277.2%
distribute-rgt-out--77.2%
metadata-eval77.2%
unpow277.2%
times-frac82.4%
associate-*r/82.7%
Simplified82.7%
Final simplification79.8%
(FPCore (x y) :precision binary64 (if (<= y -1e-29) -1.0 (if (<= y 2e-32) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1e-29) {
tmp = -1.0;
} else if (y <= 2e-32) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1d-29)) then
tmp = -1.0d0
else if (y <= 2d-32) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1e-29) {
tmp = -1.0;
} else if (y <= 2e-32) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1e-29: tmp = -1.0 elif y <= 2e-32: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1e-29) tmp = -1.0; elseif (y <= 2e-32) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1e-29) tmp = -1.0; elseif (y <= 2e-32) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1e-29], -1.0, If[LessEqual[y, 2e-32], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-29}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-32}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -9.99999999999999943e-30 or 2.00000000000000011e-32 < y Initial program 42.1%
Taylor expanded in x around 0 76.5%
if -9.99999999999999943e-30 < y < 2.00000000000000011e-32Initial program 67.2%
Taylor expanded in x around inf 82.8%
Final simplification79.3%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
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
\begin{array}{l}
\\
-1
\end{array}
Initial program 53.5%
Taylor expanded in x around 0 50.0%
Final simplification50.0%
(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 2023185
(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))))