
(FPCore (x y z) :precision binary64 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)) end
function tmp = code(x, y, z) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)) end
function tmp = code(x, y, z) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
:precision binary64
(let* ((t_0 (/ (- (+ (* x x) (* y_m y_m)) (* z_m z_m)) (* y_m 2.0))))
(*
y_s
(if (<= t_0 0.0)
(* 0.5 (* (+ y_m z_m) (/ (- y_m z_m) y_m)))
(if (<= t_0 INFINITY)
(* 0.5 (+ y_m (* x (/ x y_m))))
(* 0.5 (* (+ y_m z_m) (- 1.0 (/ z_m y_m)))))))))z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
double tmp;
if (t_0 <= 0.0) {
tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
} else if (t_0 <= ((double) INFINITY)) {
tmp = 0.5 * (y_m + (x * (x / y_m)));
} else {
tmp = 0.5 * ((y_m + z_m) * (1.0 - (z_m / y_m)));
}
return y_s * tmp;
}
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
double tmp;
if (t_0 <= 0.0) {
tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
} else if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = 0.5 * (y_m + (x * (x / y_m)));
} else {
tmp = 0.5 * ((y_m + z_m) * (1.0 - (z_m / y_m)));
}
return y_s * tmp;
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0) tmp = 0 if t_0 <= 0.0: tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m)) elif t_0 <= math.inf: tmp = 0.5 * (y_m + (x * (x / y_m))) else: tmp = 0.5 * ((y_m + z_m) * (1.0 - (z_m / y_m))) return y_s * tmp
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) t_0 = Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z_m * z_m)) / Float64(y_m * 2.0)) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(0.5 * Float64(Float64(y_m + z_m) * Float64(Float64(y_m - z_m) / y_m))); elseif (t_0 <= Inf) tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m)))); else tmp = Float64(0.5 * Float64(Float64(y_m + z_m) * Float64(1.0 - Float64(z_m / y_m)))); end return Float64(y_s * tmp) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z_m) t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0); tmp = 0.0; if (t_0 <= 0.0) tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m)); elseif (t_0 <= Inf) tmp = 0.5 * (y_m + (x * (x / y_m))); else tmp = 0.5 * ((y_m + z_m) * (1.0 - (z_m / y_m))); end tmp_2 = y_s * tmp; end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := Block[{t$95$0 = N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(y$95$s * If[LessEqual[t$95$0, 0.0], N[(0.5 * N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(1.0 - N[(z$95$m / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
\begin{array}{l}
t_0 := \frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z\_m \cdot z\_m}{y\_m \cdot 2}\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \left(1 - \frac{z\_m}{y\_m}\right)\right)\\
\end{array}
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < 0.0Initial program 77.8%
remove-double-neg77.8%
distribute-lft-neg-out77.8%
distribute-frac-neg277.8%
distribute-frac-neg77.8%
neg-mul-177.8%
distribute-lft-neg-out77.8%
*-commutative77.8%
distribute-lft-neg-in77.8%
times-frac77.8%
metadata-eval77.8%
metadata-eval77.8%
associate--l+77.8%
fma-define77.8%
Simplified77.8%
difference-of-squares77.8%
*-commutative77.8%
Applied egg-rr77.8%
Taylor expanded in x around 0 45.9%
associate-/l*64.5%
+-commutative64.5%
Simplified64.5%
if 0.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < +inf.0Initial program 81.5%
remove-double-neg81.5%
distribute-lft-neg-out81.5%
distribute-frac-neg281.5%
distribute-frac-neg81.5%
neg-mul-181.5%
distribute-lft-neg-out81.5%
*-commutative81.5%
distribute-lft-neg-in81.5%
times-frac81.5%
metadata-eval81.5%
metadata-eval81.5%
associate--l+81.5%
fma-define81.5%
Simplified81.5%
Taylor expanded in z around inf 57.1%
associate--l+57.1%
unpow257.1%
times-frac57.1%
fma-neg57.1%
distribute-neg-frac57.1%
metadata-eval57.1%
Simplified57.1%
Taylor expanded in z around 0 56.9%
unpow256.9%
associate-/l*62.2%
Applied egg-rr62.2%
if +inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) Initial program 0.0%
remove-double-neg0.0%
distribute-lft-neg-out0.0%
distribute-frac-neg20.0%
distribute-frac-neg0.0%
neg-mul-10.0%
distribute-lft-neg-out0.0%
*-commutative0.0%
distribute-lft-neg-in0.0%
times-frac0.0%
metadata-eval0.0%
metadata-eval0.0%
associate--l+0.0%
fma-define35.7%
Simplified35.7%
difference-of-squares46.2%
*-commutative46.2%
Applied egg-rr46.2%
Taylor expanded in x around 0 46.2%
+-commutative46.2%
Simplified46.2%
*-commutative46.2%
associate-*l/78.8%
div-sub78.9%
*-inverses78.9%
Applied egg-rr78.9%
Final simplification65.1%
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
:precision binary64
(*
y_s
(if (or (<= z_m 2.6e+27)
(and (not (<= z_m 3.9e+54))
(or (<= z_m 4.5e+88)
(and (not (<= z_m 1.15e+113)) (<= z_m 2.55e+132)))))
(* 0.5 (+ y_m (* x (/ x y_m))))
(* 0.5 (* z_m (- -1.0 (/ z_m y_m)))))))z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double tmp;
if ((z_m <= 2.6e+27) || (!(z_m <= 3.9e+54) && ((z_m <= 4.5e+88) || (!(z_m <= 1.15e+113) && (z_m <= 2.55e+132))))) {
tmp = 0.5 * (y_m + (x * (x / y_m)));
} else {
tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m)));
}
return y_s * tmp;
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if ((z_m <= 2.6d+27) .or. (.not. (z_m <= 3.9d+54)) .and. (z_m <= 4.5d+88) .or. (.not. (z_m <= 1.15d+113)) .and. (z_m <= 2.55d+132)) then
tmp = 0.5d0 * (y_m + (x * (x / y_m)))
else
tmp = 0.5d0 * (z_m * ((-1.0d0) - (z_m / y_m)))
end if
code = y_s * tmp
end function
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
double tmp;
if ((z_m <= 2.6e+27) || (!(z_m <= 3.9e+54) && ((z_m <= 4.5e+88) || (!(z_m <= 1.15e+113) && (z_m <= 2.55e+132))))) {
tmp = 0.5 * (y_m + (x * (x / y_m)));
} else {
tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m)));
}
return y_s * tmp;
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): tmp = 0 if (z_m <= 2.6e+27) or (not (z_m <= 3.9e+54) and ((z_m <= 4.5e+88) or (not (z_m <= 1.15e+113) and (z_m <= 2.55e+132)))): tmp = 0.5 * (y_m + (x * (x / y_m))) else: tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m))) return y_s * tmp
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) tmp = 0.0 if ((z_m <= 2.6e+27) || (!(z_m <= 3.9e+54) && ((z_m <= 4.5e+88) || (!(z_m <= 1.15e+113) && (z_m <= 2.55e+132))))) tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m)))); else tmp = Float64(0.5 * Float64(z_m * Float64(-1.0 - Float64(z_m / y_m)))); end return Float64(y_s * tmp) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z_m) tmp = 0.0; if ((z_m <= 2.6e+27) || (~((z_m <= 3.9e+54)) && ((z_m <= 4.5e+88) || (~((z_m <= 1.15e+113)) && (z_m <= 2.55e+132))))) tmp = 0.5 * (y_m + (x * (x / y_m))); else tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m))); end tmp_2 = y_s * tmp; end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := N[(y$95$s * If[Or[LessEqual[z$95$m, 2.6e+27], And[N[Not[LessEqual[z$95$m, 3.9e+54]], $MachinePrecision], Or[LessEqual[z$95$m, 4.5e+88], And[N[Not[LessEqual[z$95$m, 1.15e+113]], $MachinePrecision], LessEqual[z$95$m, 2.55e+132]]]]], N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(z$95$m * N[(-1.0 - N[(z$95$m / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 2.6 \cdot 10^{+27} \lor \neg \left(z\_m \leq 3.9 \cdot 10^{+54}\right) \land \left(z\_m \leq 4.5 \cdot 10^{+88} \lor \neg \left(z\_m \leq 1.15 \cdot 10^{+113}\right) \land z\_m \leq 2.55 \cdot 10^{+132}\right):\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(z\_m \cdot \left(-1 - \frac{z\_m}{y\_m}\right)\right)\\
\end{array}
\end{array}
if z < 2.60000000000000009e27 or 3.9000000000000003e54 < z < 4.5e88 or 1.14999999999999998e113 < z < 2.55e132Initial program 70.2%
remove-double-neg70.2%
distribute-lft-neg-out70.2%
distribute-frac-neg270.2%
distribute-frac-neg70.2%
neg-mul-170.2%
distribute-lft-neg-out70.2%
*-commutative70.2%
distribute-lft-neg-in70.2%
times-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
associate--l+70.2%
fma-define72.1%
Simplified72.1%
Taylor expanded in z around inf 50.3%
associate--l+50.3%
unpow250.3%
times-frac53.3%
fma-neg53.3%
distribute-neg-frac53.3%
metadata-eval53.3%
Simplified53.3%
Taylor expanded in z around 0 70.0%
unpow270.0%
associate-/l*74.9%
Applied egg-rr74.9%
if 2.60000000000000009e27 < z < 3.9000000000000003e54 or 4.5e88 < z < 1.14999999999999998e113 or 2.55e132 < z Initial program 73.3%
remove-double-neg73.3%
distribute-lft-neg-out73.3%
distribute-frac-neg273.3%
distribute-frac-neg73.3%
neg-mul-173.3%
distribute-lft-neg-out73.3%
*-commutative73.3%
distribute-lft-neg-in73.3%
times-frac73.3%
metadata-eval73.3%
metadata-eval73.3%
associate--l+73.3%
fma-define84.8%
Simplified84.8%
difference-of-squares85.3%
*-commutative85.3%
Applied egg-rr85.3%
Taylor expanded in x around 0 83.2%
associate-/l*88.6%
+-commutative88.6%
Simplified88.6%
Taylor expanded in y around 0 79.5%
neg-mul-179.5%
distribute-neg-frac279.5%
Simplified79.5%
Taylor expanded in z around 0 79.5%
sub-neg79.5%
mul-1-neg79.5%
distribute-neg-in79.5%
+-commutative79.5%
distribute-neg-in79.5%
metadata-eval79.5%
unsub-neg79.5%
Simplified79.5%
Final simplification75.8%
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
:precision binary64
(let* ((t_0 (* 0.5 (/ (* z_m (- (- z_m) y_m)) y_m)))
(t_1 (* 0.5 (+ y_m (* x (/ x y_m))))))
(*
y_s
(if (<= z_m 2.7e+27)
t_1
(if (<= z_m 1.12e+55)
t_0
(if (<= z_m 5e+87)
t_1
(if (<= z_m 2.1e+113)
t_0
(if (<= z_m 4.55e+132)
t_1
(* 0.5 (* z_m (- -1.0 (/ z_m y_m))))))))))))z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double t_0 = 0.5 * ((z_m * (-z_m - y_m)) / y_m);
double t_1 = 0.5 * (y_m + (x * (x / y_m)));
double tmp;
if (z_m <= 2.7e+27) {
tmp = t_1;
} else if (z_m <= 1.12e+55) {
tmp = t_0;
} else if (z_m <= 5e+87) {
tmp = t_1;
} else if (z_m <= 2.1e+113) {
tmp = t_0;
} else if (z_m <= 4.55e+132) {
tmp = t_1;
} else {
tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m)));
}
return y_s * tmp;
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * ((z_m * (-z_m - y_m)) / y_m)
t_1 = 0.5d0 * (y_m + (x * (x / y_m)))
if (z_m <= 2.7d+27) then
tmp = t_1
else if (z_m <= 1.12d+55) then
tmp = t_0
else if (z_m <= 5d+87) then
tmp = t_1
else if (z_m <= 2.1d+113) then
tmp = t_0
else if (z_m <= 4.55d+132) then
tmp = t_1
else
tmp = 0.5d0 * (z_m * ((-1.0d0) - (z_m / y_m)))
end if
code = y_s * tmp
end function
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
double t_0 = 0.5 * ((z_m * (-z_m - y_m)) / y_m);
double t_1 = 0.5 * (y_m + (x * (x / y_m)));
double tmp;
if (z_m <= 2.7e+27) {
tmp = t_1;
} else if (z_m <= 1.12e+55) {
tmp = t_0;
} else if (z_m <= 5e+87) {
tmp = t_1;
} else if (z_m <= 2.1e+113) {
tmp = t_0;
} else if (z_m <= 4.55e+132) {
tmp = t_1;
} else {
tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m)));
}
return y_s * tmp;
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): t_0 = 0.5 * ((z_m * (-z_m - y_m)) / y_m) t_1 = 0.5 * (y_m + (x * (x / y_m))) tmp = 0 if z_m <= 2.7e+27: tmp = t_1 elif z_m <= 1.12e+55: tmp = t_0 elif z_m <= 5e+87: tmp = t_1 elif z_m <= 2.1e+113: tmp = t_0 elif z_m <= 4.55e+132: tmp = t_1 else: tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m))) return y_s * tmp
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) t_0 = Float64(0.5 * Float64(Float64(z_m * Float64(Float64(-z_m) - y_m)) / y_m)) t_1 = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m)))) tmp = 0.0 if (z_m <= 2.7e+27) tmp = t_1; elseif (z_m <= 1.12e+55) tmp = t_0; elseif (z_m <= 5e+87) tmp = t_1; elseif (z_m <= 2.1e+113) tmp = t_0; elseif (z_m <= 4.55e+132) tmp = t_1; else tmp = Float64(0.5 * Float64(z_m * Float64(-1.0 - Float64(z_m / y_m)))); end return Float64(y_s * tmp) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z_m) t_0 = 0.5 * ((z_m * (-z_m - y_m)) / y_m); t_1 = 0.5 * (y_m + (x * (x / y_m))); tmp = 0.0; if (z_m <= 2.7e+27) tmp = t_1; elseif (z_m <= 1.12e+55) tmp = t_0; elseif (z_m <= 5e+87) tmp = t_1; elseif (z_m <= 2.1e+113) tmp = t_0; elseif (z_m <= 4.55e+132) tmp = t_1; else tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m))); end tmp_2 = y_s * tmp; end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := Block[{t$95$0 = N[(0.5 * N[(N[(z$95$m * N[((-z$95$m) - y$95$m), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(y$95$s * If[LessEqual[z$95$m, 2.7e+27], t$95$1, If[LessEqual[z$95$m, 1.12e+55], t$95$0, If[LessEqual[z$95$m, 5e+87], t$95$1, If[LessEqual[z$95$m, 2.1e+113], t$95$0, If[LessEqual[z$95$m, 4.55e+132], t$95$1, N[(0.5 * N[(z$95$m * N[(-1.0 - N[(z$95$m / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]), $MachinePrecision]]]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{z\_m \cdot \left(\left(-z\_m\right) - y\_m\right)}{y\_m}\\
t_1 := 0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 2.7 \cdot 10^{+27}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z\_m \leq 1.12 \cdot 10^{+55}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z\_m \leq 5 \cdot 10^{+87}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z\_m \leq 2.1 \cdot 10^{+113}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z\_m \leq 4.55 \cdot 10^{+132}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(z\_m \cdot \left(-1 - \frac{z\_m}{y\_m}\right)\right)\\
\end{array}
\end{array}
\end{array}
if z < 2.6999999999999997e27 or 1.12000000000000006e55 < z < 4.9999999999999998e87 or 2.0999999999999999e113 < z < 4.5499999999999997e132Initial program 70.2%
remove-double-neg70.2%
distribute-lft-neg-out70.2%
distribute-frac-neg270.2%
distribute-frac-neg70.2%
neg-mul-170.2%
distribute-lft-neg-out70.2%
*-commutative70.2%
distribute-lft-neg-in70.2%
times-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
associate--l+70.2%
fma-define72.1%
Simplified72.1%
Taylor expanded in z around inf 50.3%
associate--l+50.3%
unpow250.3%
times-frac53.3%
fma-neg53.3%
distribute-neg-frac53.3%
metadata-eval53.3%
Simplified53.3%
Taylor expanded in z around 0 70.0%
unpow270.0%
associate-/l*74.9%
Applied egg-rr74.9%
if 2.6999999999999997e27 < z < 1.12000000000000006e55 or 4.9999999999999998e87 < z < 2.0999999999999999e113Initial program 92.1%
remove-double-neg92.1%
distribute-lft-neg-out92.1%
distribute-frac-neg292.1%
distribute-frac-neg92.1%
neg-mul-192.1%
distribute-lft-neg-out92.1%
*-commutative92.1%
distribute-lft-neg-in92.1%
times-frac92.1%
metadata-eval92.1%
metadata-eval92.1%
associate--l+92.1%
fma-define92.1%
Simplified92.1%
difference-of-squares92.1%
*-commutative92.1%
Applied egg-rr92.1%
Taylor expanded in x around 0 92.1%
associate-/l*99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in y around 0 84.2%
neg-mul-184.2%
distribute-neg-frac284.2%
Simplified84.2%
distribute-frac-neg284.2%
distribute-frac-neg84.2%
associate-*r/84.5%
Applied egg-rr84.5%
if 4.5499999999999997e132 < z Initial program 67.6%
remove-double-neg67.6%
distribute-lft-neg-out67.6%
distribute-frac-neg267.6%
distribute-frac-neg67.6%
neg-mul-167.6%
distribute-lft-neg-out67.6%
*-commutative67.6%
distribute-lft-neg-in67.6%
times-frac67.6%
metadata-eval67.6%
metadata-eval67.6%
associate--l+67.6%
fma-define82.6%
Simplified82.6%
difference-of-squares83.2%
*-commutative83.2%
Applied egg-rr83.2%
Taylor expanded in x around 0 80.6%
associate-/l*85.2%
+-commutative85.2%
Simplified85.2%
Taylor expanded in y around 0 78.1%
neg-mul-178.1%
distribute-neg-frac278.1%
Simplified78.1%
Taylor expanded in z around 0 78.1%
sub-neg78.1%
mul-1-neg78.1%
distribute-neg-in78.1%
+-commutative78.1%
distribute-neg-in78.1%
metadata-eval78.1%
unsub-neg78.1%
Simplified78.1%
Final simplification75.9%
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
:precision binary64
(*
y_s
(if (<= z_m 3.3e+26)
(* 0.5 (+ y_m (* x (/ x y_m))))
(* 0.5 (* (+ y_m z_m) (/ (- y_m z_m) y_m))))))z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double tmp;
if (z_m <= 3.3e+26) {
tmp = 0.5 * (y_m + (x * (x / y_m)));
} else {
tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
}
return y_s * tmp;
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if (z_m <= 3.3d+26) then
tmp = 0.5d0 * (y_m + (x * (x / y_m)))
else
tmp = 0.5d0 * ((y_m + z_m) * ((y_m - z_m) / y_m))
end if
code = y_s * tmp
end function
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
double tmp;
if (z_m <= 3.3e+26) {
tmp = 0.5 * (y_m + (x * (x / y_m)));
} else {
tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
}
return y_s * tmp;
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): tmp = 0 if z_m <= 3.3e+26: tmp = 0.5 * (y_m + (x * (x / y_m))) else: tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m)) return y_s * tmp
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) tmp = 0.0 if (z_m <= 3.3e+26) tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m)))); else tmp = Float64(0.5 * Float64(Float64(y_m + z_m) * Float64(Float64(y_m - z_m) / y_m))); end return Float64(y_s * tmp) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z_m) tmp = 0.0; if (z_m <= 3.3e+26) tmp = 0.5 * (y_m + (x * (x / y_m))); else tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m)); end tmp_2 = y_s * tmp; end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := N[(y$95$s * If[LessEqual[z$95$m, 3.3e+26], N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 3.3 \cdot 10^{+26}:\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\
\end{array}
\end{array}
if z < 3.29999999999999993e26Initial program 69.1%
remove-double-neg69.1%
distribute-lft-neg-out69.1%
distribute-frac-neg269.1%
distribute-frac-neg69.1%
neg-mul-169.1%
distribute-lft-neg-out69.1%
*-commutative69.1%
distribute-lft-neg-in69.1%
times-frac69.1%
metadata-eval69.1%
metadata-eval69.1%
associate--l+69.1%
fma-define71.1%
Simplified71.1%
Taylor expanded in z around inf 48.6%
associate--l+48.6%
unpow248.6%
times-frac51.6%
fma-neg51.6%
distribute-neg-frac51.6%
metadata-eval51.6%
Simplified51.6%
Taylor expanded in z around 0 69.9%
unpow269.9%
associate-/l*75.0%
Applied egg-rr75.0%
if 3.29999999999999993e26 < z Initial program 76.4%
remove-double-neg76.4%
distribute-lft-neg-out76.4%
distribute-frac-neg276.4%
distribute-frac-neg76.4%
neg-mul-176.4%
distribute-lft-neg-out76.4%
*-commutative76.4%
distribute-lft-neg-in76.4%
times-frac76.4%
metadata-eval76.4%
metadata-eval76.4%
associate--l+76.4%
fma-define86.6%
Simplified86.6%
difference-of-squares87.0%
*-commutative87.0%
Applied egg-rr87.0%
Taylor expanded in x around 0 80.1%
associate-/l*84.8%
+-commutative84.8%
Simplified84.8%
Final simplification77.3%
z_m = (fabs.f64 z) y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) (FPCore (y_s x y_m z_m) :precision binary64 (* y_s (if (<= z_m 2.5e+15) (* y_m 0.5) (* 0.5 (* z_m (- -1.0 (/ z_m y_m)))))))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double tmp;
if (z_m <= 2.5e+15) {
tmp = y_m * 0.5;
} else {
tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m)));
}
return y_s * tmp;
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if (z_m <= 2.5d+15) then
tmp = y_m * 0.5d0
else
tmp = 0.5d0 * (z_m * ((-1.0d0) - (z_m / y_m)))
end if
code = y_s * tmp
end function
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
double tmp;
if (z_m <= 2.5e+15) {
tmp = y_m * 0.5;
} else {
tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m)));
}
return y_s * tmp;
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): tmp = 0 if z_m <= 2.5e+15: tmp = y_m * 0.5 else: tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m))) return y_s * tmp
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) tmp = 0.0 if (z_m <= 2.5e+15) tmp = Float64(y_m * 0.5); else tmp = Float64(0.5 * Float64(z_m * Float64(-1.0 - Float64(z_m / y_m)))); end return Float64(y_s * tmp) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z_m) tmp = 0.0; if (z_m <= 2.5e+15) tmp = y_m * 0.5; else tmp = 0.5 * (z_m * (-1.0 - (z_m / y_m))); end tmp_2 = y_s * tmp; end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := N[(y$95$s * If[LessEqual[z$95$m, 2.5e+15], N[(y$95$m * 0.5), $MachinePrecision], N[(0.5 * N[(z$95$m * N[(-1.0 - N[(z$95$m / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 2.5 \cdot 10^{+15}:\\
\;\;\;\;y\_m \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(z\_m \cdot \left(-1 - \frac{z\_m}{y\_m}\right)\right)\\
\end{array}
\end{array}
if z < 2.5e15Initial program 69.0%
Taylor expanded in y around inf 41.2%
*-commutative41.2%
Simplified41.2%
if 2.5e15 < z Initial program 76.8%
remove-double-neg76.8%
distribute-lft-neg-out76.8%
distribute-frac-neg276.8%
distribute-frac-neg76.8%
neg-mul-176.8%
distribute-lft-neg-out76.8%
*-commutative76.8%
distribute-lft-neg-in76.8%
times-frac76.8%
metadata-eval76.8%
metadata-eval76.8%
associate--l+76.8%
fma-define86.8%
Simplified86.8%
difference-of-squares87.2%
*-commutative87.2%
Applied egg-rr87.2%
Taylor expanded in x around 0 78.8%
associate-/l*83.4%
+-commutative83.4%
Simplified83.4%
Taylor expanded in y around 0 72.5%
neg-mul-172.5%
distribute-neg-frac272.5%
Simplified72.5%
Taylor expanded in z around 0 72.5%
sub-neg72.5%
mul-1-neg72.5%
distribute-neg-in72.5%
+-commutative72.5%
distribute-neg-in72.5%
metadata-eval72.5%
unsub-neg72.5%
Simplified72.5%
Final simplification48.5%
z_m = (fabs.f64 z) y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) (FPCore (y_s x y_m z_m) :precision binary64 (* y_s (* y_m 0.5)))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
return y_s * (y_m * 0.5);
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
code = y_s * (y_m * 0.5d0)
end function
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
return y_s * (y_m * 0.5);
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): return y_s * (y_m * 0.5)
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) return Float64(y_s * Float64(y_m * 0.5)) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp = code(y_s, x, y_m, z_m) tmp = y_s * (y_m * 0.5); end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := N[(y$95$s * N[(y$95$m * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \left(y\_m \cdot 0.5\right)
\end{array}
Initial program 70.8%
Taylor expanded in y around inf 34.2%
*-commutative34.2%
Simplified34.2%
Final simplification34.2%
(FPCore (x y z) :precision binary64 (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x))))
double code(double x, double y, double z) {
return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y * 0.5d0) - (((0.5d0 / y) * (z + x)) * (z - x))
end function
public static double code(double x, double y, double z) {
return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
def code(x, y, z): return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x))
function code(x, y, z) return Float64(Float64(y * 0.5) - Float64(Float64(Float64(0.5 / y) * Float64(z + x)) * Float64(z - x))) end
function tmp = code(x, y, z) tmp = (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x)); end
code[x_, y_, z_] := N[(N[(y * 0.5), $MachinePrecision] - N[(N[(N[(0.5 / y), $MachinePrecision] * N[(z + x), $MachinePrecision]), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right)
\end{array}
herbie shell --seed 2024081
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
:precision binary64
:alt
(- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))