
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
double code(double x, double y, double z) {
return (x * (sin(y) / y)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (sin(y) / y)) / z
end function
public static double code(double x, double y, double z) {
return (x * (Math.sin(y) / y)) / z;
}
def code(x, y, z): return (x * (math.sin(y) / y)) / z
function code(x, y, z) return Float64(Float64(x * Float64(sin(y) / y)) / z) end
function tmp = code(x, y, z) tmp = (x * (sin(y) / y)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \frac{\sin y}{y}}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
double code(double x, double y, double z) {
return (x * (sin(y) / y)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (sin(y) / y)) / z
end function
public static double code(double x, double y, double z) {
return (x * (Math.sin(y) / y)) / z;
}
def code(x, y, z): return (x * (math.sin(y) / y)) / z
function code(x, y, z) return Float64(Float64(x * Float64(sin(y) / y)) / z) end
function tmp = code(x, y, z) tmp = (x * (sin(y) / y)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \frac{\sin y}{y}}{z}
\end{array}
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= x_m 8.5e-49)
(* (sin y) (/ (/ x_m z) y))
(/ (* x_m (/ (sin y) y)) z))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 8.5e-49) {
tmp = sin(y) * ((x_m / z) / y);
} else {
tmp = (x_m * (sin(y) / y)) / z;
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x_m <= 8.5d-49) then
tmp = sin(y) * ((x_m / z) / y)
else
tmp = (x_m * (sin(y) / y)) / z
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 8.5e-49) {
tmp = Math.sin(y) * ((x_m / z) / y);
} else {
tmp = (x_m * (Math.sin(y) / y)) / z;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if x_m <= 8.5e-49: tmp = math.sin(y) * ((x_m / z) / y) else: tmp = (x_m * (math.sin(y) / y)) / z return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (x_m <= 8.5e-49) tmp = Float64(sin(y) * Float64(Float64(x_m / z) / y)); else tmp = Float64(Float64(x_m * Float64(sin(y) / y)) / z); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (x_m <= 8.5e-49) tmp = sin(y) * ((x_m / z) / y); else tmp = (x_m * (sin(y) / y)) / z; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 8.5e-49], N[(N[Sin[y], $MachinePrecision] * N[(N[(x$95$m / z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 8.5 \cdot 10^{-49}:\\
\;\;\;\;\sin y \cdot \frac{\frac{x\_m}{z}}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m \cdot \frac{\sin y}{y}}{z}\\
\end{array}
\end{array}
if x < 8.50000000000000069e-49Initial program 90.6%
associate-*l/96.8%
associate-*r/85.7%
*-commutative85.7%
associate-/l*92.2%
Simplified92.2%
if 8.50000000000000069e-49 < x Initial program 99.8%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= y 3e-38)
(/ x_m z)
(if (<= y 4.3e+219)
(* x_m (/ (sin y) (* y z)))
(* (sin y) (/ (/ x_m z) y))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 3e-38) {
tmp = x_m / z;
} else if (y <= 4.3e+219) {
tmp = x_m * (sin(y) / (y * z));
} else {
tmp = sin(y) * ((x_m / z) / y);
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 3d-38) then
tmp = x_m / z
else if (y <= 4.3d+219) then
tmp = x_m * (sin(y) / (y * z))
else
tmp = sin(y) * ((x_m / z) / y)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 3e-38) {
tmp = x_m / z;
} else if (y <= 4.3e+219) {
tmp = x_m * (Math.sin(y) / (y * z));
} else {
tmp = Math.sin(y) * ((x_m / z) / y);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if y <= 3e-38: tmp = x_m / z elif y <= 4.3e+219: tmp = x_m * (math.sin(y) / (y * z)) else: tmp = math.sin(y) * ((x_m / z) / y) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (y <= 3e-38) tmp = Float64(x_m / z); elseif (y <= 4.3e+219) tmp = Float64(x_m * Float64(sin(y) / Float64(y * z))); else tmp = Float64(sin(y) * Float64(Float64(x_m / z) / y)); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (y <= 3e-38) tmp = x_m / z; elseif (y <= 4.3e+219) tmp = x_m * (sin(y) / (y * z)); else tmp = sin(y) * ((x_m / z) / y); end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[y, 3e-38], N[(x$95$m / z), $MachinePrecision], If[LessEqual[y, 4.3e+219], N[(x$95$m * N[(N[Sin[y], $MachinePrecision] / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(N[(x$95$m / z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-38}:\\
\;\;\;\;\frac{x\_m}{z}\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{+219}:\\
\;\;\;\;x\_m \cdot \frac{\sin y}{y \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \frac{\frac{x\_m}{z}}{y}\\
\end{array}
\end{array}
if y < 2.99999999999999989e-38Initial program 94.5%
associate-*l/98.3%
associate-*r/84.3%
*-commutative84.3%
associate-/l*90.5%
Simplified90.5%
Taylor expanded in y around 0 73.9%
if 2.99999999999999989e-38 < y < 4.2999999999999997e219Initial program 95.9%
associate-*l/90.9%
associate-*r/90.9%
*-commutative90.9%
associate-/l*91.0%
Simplified91.0%
associate-/l/94.3%
associate-*r/94.3%
*-commutative94.3%
*-commutative94.3%
associate-/l/95.9%
associate-*r/95.9%
associate-/l*94.1%
*-commutative94.1%
associate-/l/94.2%
Applied egg-rr94.2%
if 4.2999999999999997e219 < y Initial program 74.7%
associate-*l/86.0%
associate-*r/86.2%
*-commutative86.2%
associate-/l*86.2%
Simplified86.2%
Final simplification79.2%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= y 3.8e-48) (/ x_m z) (* (sin y) (/ (/ x_m z) y)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 3.8e-48) {
tmp = x_m / z;
} else {
tmp = sin(y) * ((x_m / z) / y);
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 3.8d-48) then
tmp = x_m / z
else
tmp = sin(y) * ((x_m / z) / y)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 3.8e-48) {
tmp = x_m / z;
} else {
tmp = Math.sin(y) * ((x_m / z) / y);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if y <= 3.8e-48: tmp = x_m / z else: tmp = math.sin(y) * ((x_m / z) / y) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (y <= 3.8e-48) tmp = Float64(x_m / z); else tmp = Float64(sin(y) * Float64(Float64(x_m / z) / y)); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (y <= 3.8e-48) tmp = x_m / z; else tmp = sin(y) * ((x_m / z) / y); end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[y, 3.8e-48], N[(x$95$m / z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(N[(x$95$m / z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq 3.8 \cdot 10^{-48}:\\
\;\;\;\;\frac{x\_m}{z}\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \frac{\frac{x\_m}{z}}{y}\\
\end{array}
\end{array}
if y < 3.80000000000000002e-48Initial program 94.4%
associate-*l/98.3%
associate-*r/84.1%
*-commutative84.1%
associate-/l*90.4%
Simplified90.4%
Taylor expanded in y around 0 73.6%
if 3.80000000000000002e-48 < y Initial program 90.2%
associate-*l/89.8%
associate-*r/89.8%
*-commutative89.8%
associate-/l*89.9%
Simplified89.9%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= y 2.8e-8) (/ x_m z) (* (sin y) (/ (/ x_m y) z)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 2.8e-8) {
tmp = x_m / z;
} else {
tmp = sin(y) * ((x_m / y) / z);
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 2.8d-8) then
tmp = x_m / z
else
tmp = sin(y) * ((x_m / y) / z)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 2.8e-8) {
tmp = x_m / z;
} else {
tmp = Math.sin(y) * ((x_m / y) / z);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if y <= 2.8e-8: tmp = x_m / z else: tmp = math.sin(y) * ((x_m / y) / z) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (y <= 2.8e-8) tmp = Float64(x_m / z); else tmp = Float64(sin(y) * Float64(Float64(x_m / y) / z)); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (y <= 2.8e-8) tmp = x_m / z; else tmp = sin(y) * ((x_m / y) / z); end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[y, 2.8e-8], N[(x$95$m / z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(N[(x$95$m / y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{-8}:\\
\;\;\;\;\frac{x\_m}{z}\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \frac{\frac{x\_m}{y}}{z}\\
\end{array}
\end{array}
if y < 2.7999999999999999e-8Initial program 94.6%
associate-*l/98.4%
associate-*r/84.6%
*-commutative84.6%
associate-/l*90.7%
Simplified90.7%
Taylor expanded in y around 0 74.3%
if 2.7999999999999999e-8 < y Initial program 89.5%
associate-*l/89.1%
associate-*r/89.1%
*-commutative89.1%
associate-/l*89.2%
Simplified89.2%
associate-/l/94.0%
associate-/r*89.6%
Applied egg-rr89.6%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= y 260000000.0) (/ x_m z) (* y (/ x_m (* y z))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 260000000.0) {
tmp = x_m / z;
} else {
tmp = y * (x_m / (y * z));
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 260000000.0d0) then
tmp = x_m / z
else
tmp = y * (x_m / (y * z))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 260000000.0) {
tmp = x_m / z;
} else {
tmp = y * (x_m / (y * z));
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if y <= 260000000.0: tmp = x_m / z else: tmp = y * (x_m / (y * z)) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (y <= 260000000.0) tmp = Float64(x_m / z); else tmp = Float64(y * Float64(x_m / Float64(y * z))); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (y <= 260000000.0) tmp = x_m / z; else tmp = y * (x_m / (y * z)); end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[y, 260000000.0], N[(x$95$m / z), $MachinePrecision], N[(y * N[(x$95$m / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq 260000000:\\
\;\;\;\;\frac{x\_m}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x\_m}{y \cdot z}\\
\end{array}
\end{array}
if y < 2.6e8Initial program 94.7%
associate-*l/98.4%
associate-*r/85.0%
*-commutative85.0%
associate-/l*90.9%
Simplified90.9%
Taylor expanded in y around 0 72.7%
if 2.6e8 < y Initial program 88.6%
associate-*l/88.2%
associate-*r/88.2%
*-commutative88.2%
associate-/l*88.3%
Simplified88.3%
associate-*r/88.2%
div-inv88.3%
associate-*r*88.2%
*-commutative88.2%
associate-*l/88.5%
associate-*r/88.6%
clear-num88.6%
un-div-inv88.6%
Applied egg-rr88.6%
*-commutative88.6%
frac-times93.5%
associate-/l*93.5%
associate-*l/93.4%
clear-num93.4%
associate-/r*94.0%
associate-*l/88.3%
Applied egg-rr88.3%
Taylor expanded in y around 0 8.4%
associate-/l*13.0%
frac-times16.7%
*-commutative16.7%
associate-/l*28.1%
*-commutative28.1%
Applied egg-rr28.1%
Final simplification61.2%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= y 3e-38) (/ x_m z) (* x_m (/ y (* y z))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 3e-38) {
tmp = x_m / z;
} else {
tmp = x_m * (y / (y * z));
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 3d-38) then
tmp = x_m / z
else
tmp = x_m * (y / (y * z))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (y <= 3e-38) {
tmp = x_m / z;
} else {
tmp = x_m * (y / (y * z));
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if y <= 3e-38: tmp = x_m / z else: tmp = x_m * (y / (y * z)) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (y <= 3e-38) tmp = Float64(x_m / z); else tmp = Float64(x_m * Float64(y / Float64(y * z))); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (y <= 3e-38) tmp = x_m / z; else tmp = x_m * (y / (y * z)); end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[y, 3e-38], N[(x$95$m / z), $MachinePrecision], N[(x$95$m * N[(y / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-38}:\\
\;\;\;\;\frac{x\_m}{z}\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot \frac{y}{y \cdot z}\\
\end{array}
\end{array}
if y < 2.99999999999999989e-38Initial program 94.5%
associate-*l/98.3%
associate-*r/84.3%
*-commutative84.3%
associate-/l*90.5%
Simplified90.5%
Taylor expanded in y around 0 73.9%
if 2.99999999999999989e-38 < y Initial program 89.9%
associate-*l/89.5%
associate-*r/89.6%
*-commutative89.6%
associate-/l*89.7%
Simplified89.7%
associate-*r/89.6%
div-inv89.6%
associate-*r*89.5%
*-commutative89.5%
associate-*l/89.9%
associate-*r/89.9%
clear-num89.8%
un-div-inv89.9%
Applied egg-rr89.9%
*-commutative89.9%
frac-times94.2%
associate-/l*94.2%
associate-*l/94.1%
clear-num94.1%
associate-/r*94.7%
associate-*l/89.6%
Applied egg-rr89.6%
Taylor expanded in y around 0 13.2%
*-commutative13.2%
associate-/l*13.3%
associate-/l/20.6%
associate-/l*21.9%
*-commutative21.9%
Applied egg-rr21.9%
Final simplification58.7%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (/ x_m z)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m / z);
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * (x_m / z)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m / z);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): return x_s * (x_m / z)
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) return Float64(x_s * Float64(x_m / z)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m, y, z) tmp = x_s * (x_m / z); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(x$95$m / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \frac{x\_m}{z}
\end{array}
Initial program 93.1%
associate-*l/95.8%
associate-*r/85.9%
*-commutative85.9%
associate-/l*90.3%
Simplified90.3%
Taylor expanded in y around 0 56.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ y (sin y))) (t_1 (/ (* x (/ 1.0 t_0)) z)))
(if (< z -4.2173720203427147e-29)
t_1
(if (< z 4.446702369113811e+64) (/ x (* z t_0)) t_1))))
double code(double x, double y, double z) {
double t_0 = y / sin(y);
double t_1 = (x * (1.0 / t_0)) / z;
double tmp;
if (z < -4.2173720203427147e-29) {
tmp = t_1;
} else if (z < 4.446702369113811e+64) {
tmp = x / (z * t_0);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = y / sin(y)
t_1 = (x * (1.0d0 / t_0)) / z
if (z < (-4.2173720203427147d-29)) then
tmp = t_1
else if (z < 4.446702369113811d+64) then
tmp = x / (z * t_0)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y / Math.sin(y);
double t_1 = (x * (1.0 / t_0)) / z;
double tmp;
if (z < -4.2173720203427147e-29) {
tmp = t_1;
} else if (z < 4.446702369113811e+64) {
tmp = x / (z * t_0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = y / math.sin(y) t_1 = (x * (1.0 / t_0)) / z tmp = 0 if z < -4.2173720203427147e-29: tmp = t_1 elif z < 4.446702369113811e+64: tmp = x / (z * t_0) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(y / sin(y)) t_1 = Float64(Float64(x * Float64(1.0 / t_0)) / z) tmp = 0.0 if (z < -4.2173720203427147e-29) tmp = t_1; elseif (z < 4.446702369113811e+64) tmp = Float64(x / Float64(z * t_0)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / sin(y); t_1 = (x * (1.0 / t_0)) / z; tmp = 0.0; if (z < -4.2173720203427147e-29) tmp = t_1; elseif (z < 4.446702369113811e+64) tmp = x / (z * t_0); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[Less[z, -4.2173720203427147e-29], t$95$1, If[Less[z, 4.446702369113811e+64], N[(x / N[(z * t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{\sin y}\\
t_1 := \frac{x \cdot \frac{1}{t\_0}}{z}\\
\mathbf{if}\;z < -4.2173720203427147 \cdot 10^{-29}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z < 4.446702369113811 \cdot 10^{+64}:\\
\;\;\;\;\frac{x}{z \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2024096
(FPCore (x y z)
:name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
:precision binary64
:alt
(if (< z -4.2173720203427147e-29) (/ (* x (/ 1.0 (/ y (sin y)))) z) (if (< z 4.446702369113811e+64) (/ x (* z (/ y (sin y)))) (/ (* x (/ 1.0 (/ y (sin y)))) z)))
(/ (* x (/ (sin y) y)) z))