
(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 (* y (* y 4.0))))
(if (<= t_0 2e-241)
(+ 1.0 (* -8.0 (* (/ y x) (/ y x))))
(if (<= t_0 5e+143)
(/ (- (* x x) t_0) (+ t_0 (* x x)))
(+ (* 0.5 (pow (/ x y) 2.0)) -1.0)))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 2e-241) {
tmp = 1.0 + (-8.0 * ((y / x) * (y / x)));
} else if (t_0 <= 5e+143) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} 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) :: tmp
t_0 = y * (y * 4.0d0)
if (t_0 <= 2d-241) then
tmp = 1.0d0 + ((-8.0d0) * ((y / x) * (y / x)))
else if (t_0 <= 5d+143) then
tmp = ((x * x) - t_0) / (t_0 + (x * x))
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 = y * (y * 4.0);
double tmp;
if (t_0 <= 2e-241) {
tmp = 1.0 + (-8.0 * ((y / x) * (y / x)));
} else if (t_0 <= 5e+143) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} else {
tmp = (0.5 * Math.pow((x / y), 2.0)) + -1.0;
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) tmp = 0 if t_0 <= 2e-241: tmp = 1.0 + (-8.0 * ((y / x) * (y / x))) elif t_0 <= 5e+143: tmp = ((x * x) - t_0) / (t_0 + (x * x)) else: tmp = (0.5 * math.pow((x / y), 2.0)) + -1.0 return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 2e-241) tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) * Float64(y / x)))); elseif (t_0 <= 5e+143) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(t_0 + Float64(x * x))); 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 = y * (y * 4.0); tmp = 0.0; if (t_0 <= 2e-241) tmp = 1.0 + (-8.0 * ((y / x) * (y / x))); elseif (t_0 <= 5e+143) tmp = ((x * x) - t_0) / (t_0 + (x * x)); else tmp = (0.5 * ((x / y) ^ 2.0)) + -1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-241], N[(1.0 + N[(-8.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+143], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-241}:\\
\;\;\;\;1 + -8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+143}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {\left(\frac{x}{y}\right)}^{2} + -1\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 1.9999999999999999e-241Initial program 58.8%
div-inv57.3%
sub-neg57.3%
+-commutative57.3%
*-commutative57.3%
distribute-rgt-neg-in57.3%
fma-def57.3%
distribute-rgt-neg-in57.3%
metadata-eval57.3%
fma-def57.3%
*-commutative57.3%
Applied egg-rr57.3%
Taylor expanded in y around 0 79.0%
unpow279.0%
unpow279.0%
times-frac84.8%
Simplified84.8%
if 1.9999999999999999e-241 < (*.f64 (*.f64 y 4) y) < 5.00000000000000012e143Initial program 80.0%
if 5.00000000000000012e143 < (*.f64 (*.f64 y 4) y) Initial program 23.6%
div-inv23.5%
sub-neg23.5%
+-commutative23.5%
*-commutative23.5%
distribute-rgt-neg-in23.5%
fma-def23.5%
distribute-rgt-neg-in23.5%
metadata-eval23.5%
fma-def23.5%
*-commutative23.5%
Applied egg-rr23.5%
Taylor expanded in x around 0 64.2%
associate--l+64.2%
fma-def64.2%
metadata-eval64.2%
pow-sqr64.2%
unpow264.2%
unpow264.2%
metadata-eval64.2%
pow-sqr64.2%
unpow264.2%
unpow264.2%
times-frac75.5%
times-frac75.5%
unpow275.5%
times-frac75.5%
unpow275.5%
pow-sqr75.5%
metadata-eval75.5%
fma-neg75.5%
unpow275.5%
unpow275.5%
times-frac82.2%
unpow282.2%
metadata-eval82.2%
Simplified82.2%
fma-udef82.2%
fma-udef82.2%
associate-+r+82.2%
Applied egg-rr82.2%
Taylor expanded in x around 0 75.8%
unpow275.8%
unpow275.8%
times-frac82.9%
unpow282.9%
Simplified82.9%
Final simplification82.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= t_0 2e-241)
(+ 1.0 (* -8.0 (* (/ y x) (/ y x))))
(if (<= t_0 2e+232) (/ (- (* x x) t_0) (+ t_0 (* x x))) -1.0))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 2e-241) {
tmp = 1.0 + (-8.0 * ((y / x) * (y / x)));
} else if (t_0 <= 2e+232) {
tmp = ((x * x) - t_0) / (t_0 + (x * 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) :: t_0
real(8) :: tmp
t_0 = y * (y * 4.0d0)
if (t_0 <= 2d-241) then
tmp = 1.0d0 + ((-8.0d0) * ((y / x) * (y / x)))
else if (t_0 <= 2d+232) then
tmp = ((x * x) - t_0) / (t_0 + (x * x))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if (t_0 <= 2e-241) {
tmp = 1.0 + (-8.0 * ((y / x) * (y / x)));
} else if (t_0 <= 2e+232) {
tmp = ((x * x) - t_0) / (t_0 + (x * x));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) tmp = 0 if t_0 <= 2e-241: tmp = 1.0 + (-8.0 * ((y / x) * (y / x))) elif t_0 <= 2e+232: tmp = ((x * x) - t_0) / (t_0 + (x * x)) else: tmp = -1.0 return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (t_0 <= 2e-241) tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) * Float64(y / x)))); elseif (t_0 <= 2e+232) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(t_0 + Float64(x * x))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); tmp = 0.0; if (t_0 <= 2e-241) tmp = 1.0 + (-8.0 * ((y / x) * (y / x))); elseif (t_0 <= 2e+232) tmp = ((x * x) - t_0) / (t_0 + (x * x)); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-241], N[(1.0 + N[(-8.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+232], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-241}:\\
\;\;\;\;1 + -8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+232}:\\
\;\;\;\;\frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 1.9999999999999999e-241Initial program 58.8%
div-inv57.3%
sub-neg57.3%
+-commutative57.3%
*-commutative57.3%
distribute-rgt-neg-in57.3%
fma-def57.3%
distribute-rgt-neg-in57.3%
metadata-eval57.3%
fma-def57.3%
*-commutative57.3%
Applied egg-rr57.3%
Taylor expanded in y around 0 79.0%
unpow279.0%
unpow279.0%
times-frac84.8%
Simplified84.8%
if 1.9999999999999999e-241 < (*.f64 (*.f64 y 4) y) < 2.00000000000000011e232Initial program 75.5%
if 2.00000000000000011e232 < (*.f64 (*.f64 y 4) y) Initial program 15.1%
Taylor expanded in x around 0 87.4%
Final simplification82.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))) (t_1 (+ 1.0 (* -8.0 (* (/ y x) (/ y x))))))
(if (<= t_0 2e-82)
t_1
(if (<= t_0 4e+25)
(+ -1.0 (* 0.5 (/ (* x x) (* y y))))
(if (<= t_0 5e+98) t_1 -1.0)))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = 1.0 + (-8.0 * ((y / x) * (y / x)));
double tmp;
if (t_0 <= 2e-82) {
tmp = t_1;
} else if (t_0 <= 4e+25) {
tmp = -1.0 + (0.5 * ((x * x) / (y * y)));
} else if (t_0 <= 5e+98) {
tmp = t_1;
} else {
tmp = -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) :: tmp
t_0 = y * (y * 4.0d0)
t_1 = 1.0d0 + ((-8.0d0) * ((y / x) * (y / x)))
if (t_0 <= 2d-82) then
tmp = t_1
else if (t_0 <= 4d+25) then
tmp = (-1.0d0) + (0.5d0 * ((x * x) / (y * y)))
else if (t_0 <= 5d+98) then
tmp = t_1
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (y * 4.0);
double t_1 = 1.0 + (-8.0 * ((y / x) * (y / x)));
double tmp;
if (t_0 <= 2e-82) {
tmp = t_1;
} else if (t_0 <= 4e+25) {
tmp = -1.0 + (0.5 * ((x * x) / (y * y)));
} else if (t_0 <= 5e+98) {
tmp = t_1;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) t_1 = 1.0 + (-8.0 * ((y / x) * (y / x))) tmp = 0 if t_0 <= 2e-82: tmp = t_1 elif t_0 <= 4e+25: tmp = -1.0 + (0.5 * ((x * x) / (y * y))) elif t_0 <= 5e+98: tmp = t_1 else: tmp = -1.0 return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) t_1 = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) * Float64(y / x)))) tmp = 0.0 if (t_0 <= 2e-82) tmp = t_1; elseif (t_0 <= 4e+25) tmp = Float64(-1.0 + Float64(0.5 * Float64(Float64(x * x) / Float64(y * y)))); elseif (t_0 <= 5e+98) tmp = t_1; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); t_1 = 1.0 + (-8.0 * ((y / x) * (y / x))); tmp = 0.0; if (t_0 <= 2e-82) tmp = t_1; elseif (t_0 <= 4e+25) tmp = -1.0 + (0.5 * ((x * x) / (y * y))); elseif (t_0 <= 5e+98) tmp = t_1; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-8.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-82], t$95$1, If[LessEqual[t$95$0, 4e+25], N[(-1.0 + N[(0.5 * N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+98], t$95$1, -1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := 1 + -8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-82}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{+25}:\\
\;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+98}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if (*.f64 (*.f64 y 4) y) < 2e-82 or 4.00000000000000036e25 < (*.f64 (*.f64 y 4) y) < 4.9999999999999998e98Initial program 64.8%
div-inv63.8%
sub-neg63.8%
+-commutative63.8%
*-commutative63.8%
distribute-rgt-neg-in63.8%
fma-def63.8%
distribute-rgt-neg-in63.8%
metadata-eval63.8%
fma-def63.8%
*-commutative63.8%
Applied egg-rr63.8%
Taylor expanded in y around 0 77.8%
unpow277.8%
unpow277.8%
times-frac81.5%
Simplified81.5%
if 2e-82 < (*.f64 (*.f64 y 4) y) < 4.00000000000000036e25Initial program 83.3%
div-inv83.0%
sub-neg83.0%
+-commutative83.0%
*-commutative83.0%
distribute-rgt-neg-in83.0%
fma-def83.0%
distribute-rgt-neg-in83.0%
metadata-eval83.0%
fma-def83.0%
*-commutative83.0%
Applied egg-rr83.0%
Taylor expanded in x around 0 66.7%
associate--l+66.7%
fma-def66.7%
metadata-eval66.7%
pow-sqr66.7%
unpow266.7%
unpow266.7%
metadata-eval66.7%
pow-sqr66.7%
unpow266.7%
unpow266.7%
times-frac66.7%
times-frac66.7%
unpow266.7%
times-frac66.7%
unpow266.7%
pow-sqr66.7%
metadata-eval66.7%
fma-neg66.7%
unpow266.7%
unpow266.7%
times-frac66.7%
unpow266.7%
metadata-eval66.7%
Simplified66.7%
fma-udef66.7%
fma-udef66.7%
associate-+r+66.7%
Applied egg-rr66.7%
Taylor expanded in x around 0 68.0%
*-commutative68.0%
unpow268.0%
unpow268.0%
Simplified68.0%
if 4.9999999999999998e98 < (*.f64 (*.f64 y 4) y) Initial program 28.3%
Taylor expanded in x around 0 81.4%
Final simplification80.5%
(FPCore (x y) :precision binary64 (if (or (<= y 8.6e-38) (and (not (<= y 5600000000000.0)) (<= y 1.05e+49))) (+ 1.0 (* -8.0 (* (/ y x) (/ y x)))) -1.0))
double code(double x, double y) {
double tmp;
if ((y <= 8.6e-38) || (!(y <= 5600000000000.0) && (y <= 1.05e+49))) {
tmp = 1.0 + (-8.0 * ((y / x) * (y / 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 <= 8.6d-38) .or. (.not. (y <= 5600000000000.0d0)) .and. (y <= 1.05d+49)) then
tmp = 1.0d0 + ((-8.0d0) * ((y / x) * (y / x)))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 8.6e-38) || (!(y <= 5600000000000.0) && (y <= 1.05e+49))) {
tmp = 1.0 + (-8.0 * ((y / x) * (y / x)));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 8.6e-38) or (not (y <= 5600000000000.0) and (y <= 1.05e+49)): tmp = 1.0 + (-8.0 * ((y / x) * (y / x))) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= 8.6e-38) || (!(y <= 5600000000000.0) && (y <= 1.05e+49))) tmp = Float64(1.0 + Float64(-8.0 * Float64(Float64(y / x) * Float64(y / x)))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 8.6e-38) || (~((y <= 5600000000000.0)) && (y <= 1.05e+49))) tmp = 1.0 + (-8.0 * ((y / x) * (y / x))); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 8.6e-38], And[N[Not[LessEqual[y, 5600000000000.0]], $MachinePrecision], LessEqual[y, 1.05e+49]]], N[(1.0 + N[(-8.0 * N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.6 \cdot 10^{-38} \lor \neg \left(y \leq 5600000000000\right) \land y \leq 1.05 \cdot 10^{+49}:\\
\;\;\;\;1 + -8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 8.6000000000000004e-38 or 5.6e12 < y < 1.05000000000000005e49Initial program 54.0%
div-inv53.4%
sub-neg53.4%
+-commutative53.4%
*-commutative53.4%
distribute-rgt-neg-in53.4%
fma-def53.4%
distribute-rgt-neg-in53.4%
metadata-eval53.4%
fma-def53.4%
*-commutative53.4%
Applied egg-rr53.4%
Taylor expanded in y around 0 56.1%
unpow256.1%
unpow256.1%
times-frac60.9%
Simplified60.9%
if 8.6000000000000004e-38 < y < 5.6e12 or 1.05000000000000005e49 < y Initial program 39.4%
Taylor expanded in x around 0 74.5%
Final simplification64.7%
(FPCore (x y) :precision binary64 (if (<= y 1e-41) 1.0 (if (<= y 5000000000000.0) -1.0 (if (<= y 1.06e+49) 1.0 -1.0))))
double code(double x, double y) {
double tmp;
if (y <= 1e-41) {
tmp = 1.0;
} else if (y <= 5000000000000.0) {
tmp = -1.0;
} else if (y <= 1.06e+49) {
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-41) then
tmp = 1.0d0
else if (y <= 5000000000000.0d0) then
tmp = -1.0d0
else if (y <= 1.06d+49) 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-41) {
tmp = 1.0;
} else if (y <= 5000000000000.0) {
tmp = -1.0;
} else if (y <= 1.06e+49) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1e-41: tmp = 1.0 elif y <= 5000000000000.0: tmp = -1.0 elif y <= 1.06e+49: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 1e-41) tmp = 1.0; elseif (y <= 5000000000000.0) tmp = -1.0; elseif (y <= 1.06e+49) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1e-41) tmp = 1.0; elseif (y <= 5000000000000.0) tmp = -1.0; elseif (y <= 1.06e+49) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1e-41], 1.0, If[LessEqual[y, 5000000000000.0], -1.0, If[LessEqual[y, 1.06e+49], 1.0, -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 10^{-41}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5000000000000:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{+49}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < 1.00000000000000001e-41 or 5e12 < y < 1.06e49Initial program 54.0%
Taylor expanded in x around inf 59.7%
if 1.00000000000000001e-41 < y < 5e12 or 1.06e49 < y Initial program 39.4%
Taylor expanded in x around 0 74.5%
Final simplification63.8%
(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 50.0%
Taylor expanded in x around 0 50.2%
Final simplification50.2%
(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 2023285
(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))))