
(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 7 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 (<= (* x x) 1e-117)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(if (<= (* x x) 2e+271)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(fma (* (/ y x) (/ y x)) -8.0 1.0)))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 1e-117) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else if ((x * x) <= 2e+271) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = fma(((y / x) * (y / x)), -8.0, 1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (Float64(x * x) <= 1e-117) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); elseif (Float64(x * x) <= 2e+271) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = fma(Float64(Float64(y / x) * Float64(y / x)), -8.0, 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 1e-117], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e+271], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -8.0 + 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;x \cdot x \leq 10^{-117}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+271}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x} \cdot \frac{y}{x}, -8, 1\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 1.00000000000000003e-117Initial program 61.7%
Taylor expanded in x around 0 75.0%
fma-neg75.0%
unpow275.0%
unpow275.0%
times-frac84.8%
metadata-eval84.8%
Simplified84.8%
if 1.00000000000000003e-117 < (*.f64 x x) < 1.99999999999999991e271Initial program 78.1%
if 1.99999999999999991e271 < (*.f64 x x) Initial program 5.3%
Taylor expanded in x around inf 68.2%
associate--l+68.2%
distribute-rgt-out--68.2%
metadata-eval68.2%
*-commutative68.2%
+-commutative68.2%
*-commutative68.2%
fma-def68.2%
unpow268.2%
unpow268.2%
times-frac84.9%
Simplified84.9%
Final simplification82.6%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 1e-117)
(fma 0.5 (* (/ x y) (/ x y)) -1.0)
(if (<= (* x x) 2e+271)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 1e-117) {
tmp = fma(0.5, ((x / y) * (x / y)), -1.0);
} else if ((x * x) <= 2e+271) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (Float64(x * x) <= 1e-117) tmp = fma(0.5, Float64(Float64(x / y) * Float64(x / y)), -1.0); elseif (Float64(x * x) <= 2e+271) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 1e-117], N[(0.5 * N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e+271], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;x \cdot x \leq 10^{-117}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+271}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 1.00000000000000003e-117Initial program 61.7%
Taylor expanded in x around 0 75.0%
fma-neg75.0%
unpow275.0%
unpow275.0%
times-frac84.8%
metadata-eval84.8%
Simplified84.8%
if 1.00000000000000003e-117 < (*.f64 x x) < 1.99999999999999991e271Initial program 78.1%
if 1.99999999999999991e271 < (*.f64 x x) Initial program 5.3%
Taylor expanded in x around inf 5.5%
unpow25.5%
Simplified5.5%
Taylor expanded in x around inf 68.2%
unpow268.2%
unpow268.2%
times-frac84.7%
unpow284.7%
Simplified84.7%
unpow284.7%
clear-num84.7%
un-div-inv84.7%
Applied egg-rr84.7%
Final simplification82.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y 4.0))))
(if (<= (* x x) 1e-117)
(+ -1.0 (/ (/ (/ x y) (/ y x)) 4.0))
(if (<= (* x x) 2e+271)
(/ (- (* x x) t_0) (+ (* x x) t_0))
(+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))))
double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 1e-117) {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
} else if ((x * x) <= 2e+271) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
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 ((x * x) <= 1d-117) then
tmp = (-1.0d0) + (((x / y) / (y / x)) / 4.0d0)
else if ((x * x) <= 2d+271) then
tmp = ((x * x) - t_0) / ((x * x) + t_0)
else
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (y * 4.0);
double tmp;
if ((x * x) <= 1e-117) {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
} else if ((x * x) <= 2e+271) {
tmp = ((x * x) - t_0) / ((x * x) + t_0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
def code(x, y): t_0 = y * (y * 4.0) tmp = 0 if (x * x) <= 1e-117: tmp = -1.0 + (((x / y) / (y / x)) / 4.0) elif (x * x) <= 2e+271: tmp = ((x * x) - t_0) / ((x * x) + t_0) else: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) return tmp
function code(x, y) t_0 = Float64(y * Float64(y * 4.0)) tmp = 0.0 if (Float64(x * x) <= 1e-117) tmp = Float64(-1.0 + Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0)); elseif (Float64(x * x) <= 2e+271) tmp = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0)); else tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (y * 4.0); tmp = 0.0; if ((x * x) <= 1e-117) tmp = -1.0 + (((x / y) / (y / x)) / 4.0); elseif ((x * x) <= 2e+271) tmp = ((x * x) - t_0) / ((x * x) + t_0); else tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 1e-117], N[(-1.0 + N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 2e+271], N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;x \cdot x \leq 10^{-117}:\\
\;\;\;\;-1 + \frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4}\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+271}:\\
\;\;\;\;\frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 1.00000000000000003e-117Initial program 61.7%
Taylor expanded in x around 0 49.1%
*-commutative49.1%
unpow249.1%
associate-*r*49.1%
Simplified49.1%
div-sub48.9%
associate-*r*48.9%
associate-/r*48.9%
frac-times48.9%
pow248.9%
*-commutative48.9%
*-inverses84.0%
Applied egg-rr84.0%
unpow284.0%
clear-num84.0%
un-div-inv84.0%
Applied egg-rr84.0%
if 1.00000000000000003e-117 < (*.f64 x x) < 1.99999999999999991e271Initial program 78.1%
if 1.99999999999999991e271 < (*.f64 x x) Initial program 5.3%
Taylor expanded in x around inf 5.5%
unpow25.5%
Simplified5.5%
Taylor expanded in x around inf 68.2%
unpow268.2%
unpow268.2%
times-frac84.7%
unpow284.7%
Simplified84.7%
unpow284.7%
clear-num84.7%
un-div-inv84.7%
Applied egg-rr84.7%
Final simplification82.2%
(FPCore (x y) :precision binary64 (if (or (<= (* x x) 5e-66) (and (not (<= (* x x) 0.2)) (<= (* x x) 2e+51))) (+ -1.0 (/ (/ (/ x y) (/ y x)) 4.0)) (+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))))
double code(double x, double y) {
double tmp;
if (((x * x) <= 5e-66) || (!((x * x) <= 0.2) && ((x * x) <= 2e+51))) {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((x * x) <= 5d-66) .or. (.not. ((x * x) <= 0.2d0)) .and. ((x * x) <= 2d+51)) then
tmp = (-1.0d0) + (((x / y) / (y / x)) / 4.0d0)
else
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x * x) <= 5e-66) || (!((x * x) <= 0.2) && ((x * x) <= 2e+51))) {
tmp = -1.0 + (((x / y) / (y / x)) / 4.0);
} else {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * x) <= 5e-66) or (not ((x * x) <= 0.2) and ((x * x) <= 2e+51)): tmp = -1.0 + (((x / y) / (y / x)) / 4.0) else: tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) return tmp
function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 5e-66) || (!(Float64(x * x) <= 0.2) && (Float64(x * x) <= 2e+51))) tmp = Float64(-1.0 + Float64(Float64(Float64(x / y) / Float64(y / x)) / 4.0)); else tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x * x) <= 5e-66) || (~(((x * x) <= 0.2)) && ((x * x) <= 2e+51))) tmp = -1.0 + (((x / y) / (y / x)) / 4.0); else tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 5e-66], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 0.2]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 2e+51]]], N[(-1.0 + N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-66} \lor \neg \left(x \cdot x \leq 0.2\right) \land x \cdot x \leq 2 \cdot 10^{+51}:\\
\;\;\;\;-1 + \frac{\frac{\frac{x}{y}}{\frac{y}{x}}}{4}\\
\mathbf{else}:\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\end{array}
\end{array}
if (*.f64 x x) < 4.99999999999999962e-66 or 0.20000000000000001 < (*.f64 x x) < 2e51Initial program 64.9%
Taylor expanded in x around 0 48.0%
*-commutative48.0%
unpow248.0%
associate-*r*48.0%
Simplified48.0%
div-sub47.8%
associate-*r*47.8%
associate-/r*47.8%
frac-times47.8%
pow247.8%
*-commutative47.8%
*-inverses80.4%
Applied egg-rr80.4%
unpow280.4%
clear-num80.4%
un-div-inv80.4%
Applied egg-rr80.4%
if 4.99999999999999962e-66 < (*.f64 x x) < 0.20000000000000001 or 2e51 < (*.f64 x x) Initial program 38.8%
Taylor expanded in x around inf 33.8%
unpow233.8%
Simplified33.8%
Taylor expanded in x around inf 67.8%
unpow267.8%
unpow267.8%
times-frac76.7%
unpow276.7%
Simplified76.7%
unpow276.7%
clear-num76.7%
un-div-inv76.7%
Applied egg-rr76.7%
Final simplification78.4%
(FPCore (x y)
:precision binary64
(if (<= x 2.8e-33)
-1.0
(if (or (<= x 4000.0) (not (<= x 4.4e+26)))
(+ 1.0 (* -4.0 (/ (/ y x) (/ x y))))
-1.0)))
double code(double x, double y) {
double tmp;
if (x <= 2.8e-33) {
tmp = -1.0;
} else if ((x <= 4000.0) || !(x <= 4.4e+26)) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} 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 (x <= 2.8d-33) then
tmp = -1.0d0
else if ((x <= 4000.0d0) .or. (.not. (x <= 4.4d+26))) then
tmp = 1.0d0 + ((-4.0d0) * ((y / x) / (x / y)))
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 2.8e-33) {
tmp = -1.0;
} else if ((x <= 4000.0) || !(x <= 4.4e+26)) {
tmp = 1.0 + (-4.0 * ((y / x) / (x / y)));
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2.8e-33: tmp = -1.0 elif (x <= 4000.0) or not (x <= 4.4e+26): tmp = 1.0 + (-4.0 * ((y / x) / (x / y))) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= 2.8e-33) tmp = -1.0; elseif ((x <= 4000.0) || !(x <= 4.4e+26)) tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y / x) / Float64(x / y)))); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2.8e-33) tmp = -1.0; elseif ((x <= 4000.0) || ~((x <= 4.4e+26))) tmp = 1.0 + (-4.0 * ((y / x) / (x / y))); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2.8e-33], -1.0, If[Or[LessEqual[x, 4000.0], N[Not[LessEqual[x, 4.4e+26]], $MachinePrecision]], N[(1.0 + N[(-4.0 * N[(N[(y / x), $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.8 \cdot 10^{-33}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 4000 \lor \neg \left(x \leq 4.4 \cdot 10^{+26}\right):\\
\;\;\;\;1 + -4 \cdot \frac{\frac{y}{x}}{\frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < 2.8e-33 or 4e3 < x < 4.40000000000000014e26Initial program 55.1%
Taylor expanded in x around 0 59.8%
if 2.8e-33 < x < 4e3 or 4.40000000000000014e26 < x Initial program 39.1%
Taylor expanded in x around inf 35.2%
unpow235.2%
Simplified35.2%
Taylor expanded in x around inf 74.5%
unpow274.5%
unpow274.5%
times-frac79.3%
unpow279.3%
Simplified79.3%
unpow279.3%
clear-num79.3%
un-div-inv79.3%
Applied egg-rr79.3%
Final simplification65.0%
(FPCore (x y) :precision binary64 (if (<= x 2.9e-32) -1.0 (if (<= x 2.5e-16) 1.0 (if (<= x 6.6e+30) -1.0 1.0))))
double code(double x, double y) {
double tmp;
if (x <= 2.9e-32) {
tmp = -1.0;
} else if (x <= 2.5e-16) {
tmp = 1.0;
} else if (x <= 6.6e+30) {
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 (x <= 2.9d-32) then
tmp = -1.0d0
else if (x <= 2.5d-16) then
tmp = 1.0d0
else if (x <= 6.6d+30) 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 (x <= 2.9e-32) {
tmp = -1.0;
} else if (x <= 2.5e-16) {
tmp = 1.0;
} else if (x <= 6.6e+30) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2.9e-32: tmp = -1.0 elif x <= 2.5e-16: tmp = 1.0 elif x <= 6.6e+30: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= 2.9e-32) tmp = -1.0; elseif (x <= 2.5e-16) tmp = 1.0; elseif (x <= 6.6e+30) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2.9e-32) tmp = -1.0; elseif (x <= 2.5e-16) tmp = 1.0; elseif (x <= 6.6e+30) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2.9e-32], -1.0, If[LessEqual[x, 2.5e-16], 1.0, If[LessEqual[x, 6.6e+30], -1.0, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.9 \cdot 10^{-32}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-16}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 6.6 \cdot 10^{+30}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 2.89999999999999996e-32 or 2.5000000000000002e-16 < x < 6.60000000000000053e30Initial program 55.7%
Taylor expanded in x around 0 59.3%
if 2.89999999999999996e-32 < x < 2.5000000000000002e-16 or 6.60000000000000053e30 < x Initial program 35.9%
Taylor expanded in x around inf 80.0%
Final simplification64.5%
(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.8%
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 2023275
(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))))