
(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 9 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 (let* ((t_0 (/ (sin y) y))) (* x_s (if (<= x_m 5000000000.0) (* t_0 (/ x_m z)) (/ (* x_m t_0) z)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double t_0 = sin(y) / y;
double tmp;
if (x_m <= 5000000000.0) {
tmp = t_0 * (x_m / z);
} else {
tmp = (x_m * t_0) / 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) :: t_0
real(8) :: tmp
t_0 = sin(y) / y
if (x_m <= 5000000000.0d0) then
tmp = t_0 * (x_m / z)
else
tmp = (x_m * t_0) / 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 t_0 = Math.sin(y) / y;
double tmp;
if (x_m <= 5000000000.0) {
tmp = t_0 * (x_m / z);
} else {
tmp = (x_m * t_0) / 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): t_0 = math.sin(y) / y tmp = 0 if x_m <= 5000000000.0: tmp = t_0 * (x_m / z) else: tmp = (x_m * t_0) / z return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) t_0 = Float64(sin(y) / y) tmp = 0.0 if (x_m <= 5000000000.0) tmp = Float64(t_0 * Float64(x_m / z)); else tmp = Float64(Float64(x_m * t_0) / 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) t_0 = sin(y) / y; tmp = 0.0; if (x_m <= 5000000000.0) tmp = t_0 * (x_m / z); else tmp = (x_m * t_0) / 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_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, N[(x$95$s * If[LessEqual[x$95$m, 5000000000.0], N[(t$95$0 * N[(x$95$m / z), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m * t$95$0), $MachinePrecision] / z), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 5000000000:\\
\;\;\;\;t\_0 \cdot \frac{x\_m}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m \cdot t\_0}{z}\\
\end{array}
\end{array}
\end{array}
if x < 5e9Initial program 95.7%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6497.9
Applied rewrites97.9%
if 5e9 < 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
(let* ((t_0 (/ (sin y) y)))
(*
x_s
(if (<= (/ (* x_m t_0) z) -5e-10)
(/ (* x_m (sin y)) (* y z))
(* t_0 (/ 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) {
double t_0 = sin(y) / y;
double tmp;
if (((x_m * t_0) / z) <= -5e-10) {
tmp = (x_m * sin(y)) / (y * z);
} else {
tmp = t_0 * (x_m / 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) :: t_0
real(8) :: tmp
t_0 = sin(y) / y
if (((x_m * t_0) / z) <= (-5d-10)) then
tmp = (x_m * sin(y)) / (y * z)
else
tmp = t_0 * (x_m / 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 t_0 = Math.sin(y) / y;
double tmp;
if (((x_m * t_0) / z) <= -5e-10) {
tmp = (x_m * Math.sin(y)) / (y * z);
} else {
tmp = t_0 * (x_m / 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): t_0 = math.sin(y) / y tmp = 0 if ((x_m * t_0) / z) <= -5e-10: tmp = (x_m * math.sin(y)) / (y * z) else: tmp = t_0 * (x_m / z) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) t_0 = Float64(sin(y) / y) tmp = 0.0 if (Float64(Float64(x_m * t_0) / z) <= -5e-10) tmp = Float64(Float64(x_m * sin(y)) / Float64(y * z)); else tmp = Float64(t_0 * Float64(x_m / 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) t_0 = sin(y) / y; tmp = 0.0; if (((x_m * t_0) / z) <= -5e-10) tmp = (x_m * sin(y)) / (y * z); else tmp = t_0 * (x_m / 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_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, N[(x$95$s * If[LessEqual[N[(N[(x$95$m * t$95$0), $MachinePrecision] / z), $MachinePrecision], -5e-10], N[(N[(x$95$m * N[Sin[y], $MachinePrecision]), $MachinePrecision] / N[(y * z), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(x$95$m / z), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{x\_m \cdot t\_0}{z} \leq -5 \cdot 10^{-10}:\\
\;\;\;\;\frac{x\_m \cdot \sin y}{y \cdot z}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{x\_m}{z}\\
\end{array}
\end{array}
\end{array}
if (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < -5.00000000000000031e-10Initial program 99.8%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-/l/N/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6478.8
Applied rewrites78.8%
if -5.00000000000000031e-10 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6497.0
Applied rewrites97.0%
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 (<= (/ (sin y) y) 0.95)
(* (sin y) (/ x_m (* y z)))
(/
(*
x_m
(fma
(* y y)
(fma (* y y) 0.008333333333333333 -0.16666666666666666)
1.0))
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 ((sin(y) / y) <= 0.95) {
tmp = sin(y) * (x_m / (y * z));
} else {
tmp = (x_m * fma((y * y), fma((y * y), 0.008333333333333333, -0.16666666666666666), 1.0)) / 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 (Float64(sin(y) / y) <= 0.95) tmp = Float64(sin(y) * Float64(x_m / Float64(y * z))); else tmp = Float64(Float64(x_m * fma(Float64(y * y), fma(Float64(y * y), 0.008333333333333333, -0.16666666666666666), 1.0)) / z); end return Float64(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[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 0.95], N[(N[Sin[y], $MachinePrecision] * N[(x$95$m / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * 0.008333333333333333 + -0.16666666666666666), $MachinePrecision] + 1.0), $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}\;\frac{\sin y}{y} \leq 0.95:\\
\;\;\;\;\sin y \cdot \frac{x\_m}{y \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, 0.008333333333333333, -0.16666666666666666\right), 1\right)}{z}\\
\end{array}
\end{array}
if (/.f64 (sin.f64 y) y) < 0.94999999999999996Initial program 92.7%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*l/N/A
*-lft-identityN/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6490.1
Applied rewrites90.1%
if 0.94999999999999996 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification95.5%
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 (/ (sin y) y)) z) 0.0) (/ (* x_m y) (* y z)) (/ 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) {
double tmp;
if (((x_m * (sin(y) / y)) / z) <= 0.0) {
tmp = (x_m * y) / (y * z);
} else {
tmp = x_m / 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 * (sin(y) / y)) / z) <= 0.0d0) then
tmp = (x_m * y) / (y * z)
else
tmp = x_m / 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 * (Math.sin(y) / y)) / z) <= 0.0) {
tmp = (x_m * y) / (y * z);
} else {
tmp = x_m / 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 * (math.sin(y) / y)) / z) <= 0.0: tmp = (x_m * y) / (y * z) else: tmp = x_m / 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 (Float64(Float64(x_m * Float64(sin(y) / y)) / z) <= 0.0) tmp = Float64(Float64(x_m * y) / Float64(y * z)); else tmp = Float64(x_m / 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 * (sin(y) / y)) / z) <= 0.0) tmp = (x_m * y) / (y * z); else tmp = x_m / 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[N[(N[(x$95$m * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 0.0], N[(N[(x$95$m * y), $MachinePrecision] / N[(y * z), $MachinePrecision]), $MachinePrecision], 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 \begin{array}{l}
\mathbf{if}\;\frac{x\_m \cdot \frac{\sin y}{y}}{z} \leq 0:\\
\;\;\;\;\frac{x\_m \cdot y}{y \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{z}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < 0.0Initial program 95.6%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
div-invN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6485.1
Applied rewrites85.1%
Taylor expanded in y around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
Applied rewrites40.5%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
un-div-invN/A
lower-/.f6440.6
Applied rewrites40.6%
Taylor expanded in y around 0
lower-*.f6454.3
Applied rewrites54.3%
if 0.0 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) Initial program 98.1%
Taylor expanded in y around 0
lower-/.f6458.4
Applied rewrites58.4%
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 61000.0)
(/
(*
x_m
(fma
(* y y)
(fma
y
(* y (fma (* y y) -0.0001984126984126984 0.008333333333333333))
-0.16666666666666666)
1.0))
z)
(* x_m (pow (* z z) -0.5)))))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 <= 61000.0) {
tmp = (x_m * fma((y * y), fma(y, (y * fma((y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), 1.0)) / z;
} else {
tmp = x_m * pow((z * z), -0.5);
}
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 <= 61000.0) tmp = Float64(Float64(x_m * fma(Float64(y * y), fma(y, Float64(y * fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), 1.0)) / z); else tmp = Float64(x_m * (Float64(z * z) ^ -0.5)); end return Float64(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, 61000.0], N[(N[(x$95$m * N[(N[(y * y), $MachinePrecision] * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(x$95$m * N[Power[N[(z * z), $MachinePrecision], -0.5], $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 61000:\\
\;\;\;\;\frac{x\_m \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), 1\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot {\left(z \cdot z\right)}^{-0.5}\\
\end{array}
\end{array}
if y < 61000Initial program 98.1%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
unpow2N/A
associate-*l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6465.9
Applied rewrites65.9%
if 61000 < y Initial program 89.4%
Taylor expanded in y around 0
lower-/.f6410.7
Applied rewrites10.7%
Applied rewrites10.7%
Applied rewrites18.0%
Final simplification58.1%
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 61000.0)
(/
(*
x_m
(fma
(* y y)
(fma
y
(* y (fma (* y y) -0.0001984126984126984 0.008333333333333333))
-0.16666666666666666)
1.0))
z)
(* (/ 1.0 (* y z)) (* x_m 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 <= 61000.0) {
tmp = (x_m * fma((y * y), fma(y, (y * fma((y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), 1.0)) / z;
} else {
tmp = (1.0 / (y * z)) * (x_m * 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 <= 61000.0) tmp = Float64(Float64(x_m * fma(Float64(y * y), fma(y, Float64(y * fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), 1.0)) / z); else tmp = Float64(Float64(1.0 / Float64(y * z)) * Float64(x_m * y)); end return Float64(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, 61000.0], N[(N[(x$95$m * N[(N[(y * y), $MachinePrecision] * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(N[(1.0 / N[(y * z), $MachinePrecision]), $MachinePrecision] * N[(x$95$m * 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 61000:\\
\;\;\;\;\frac{x\_m \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), 1\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y \cdot z} \cdot \left(x\_m \cdot y\right)\\
\end{array}
\end{array}
if y < 61000Initial program 98.1%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
unpow2N/A
associate-*l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6465.9
Applied rewrites65.9%
if 61000 < y Initial program 89.4%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
div-invN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6488.2
Applied rewrites88.2%
Taylor expanded in y around 0
lower-*.f6412.9
Applied rewrites12.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 4.5)
(/
(*
x_m
(fma
(* y y)
(fma (* y y) 0.008333333333333333 -0.16666666666666666)
1.0))
z)
(* (/ 1.0 (* y z)) (* x_m 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 <= 4.5) {
tmp = (x_m * fma((y * y), fma((y * y), 0.008333333333333333, -0.16666666666666666), 1.0)) / z;
} else {
tmp = (1.0 / (y * z)) * (x_m * 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 <= 4.5) tmp = Float64(Float64(x_m * fma(Float64(y * y), fma(Float64(y * y), 0.008333333333333333, -0.16666666666666666), 1.0)) / z); else tmp = Float64(Float64(1.0 / Float64(y * z)) * Float64(x_m * y)); end return Float64(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, 4.5], N[(N[(x$95$m * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * 0.008333333333333333 + -0.16666666666666666), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(N[(1.0 / N[(y * z), $MachinePrecision]), $MachinePrecision] * N[(x$95$m * 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 4.5:\\
\;\;\;\;\frac{x\_m \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, 0.008333333333333333, -0.16666666666666666\right), 1\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y \cdot z} \cdot \left(x\_m \cdot y\right)\\
\end{array}
\end{array}
if y < 4.5Initial program 98.1%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6466.1
Applied rewrites66.1%
if 4.5 < y Initial program 89.6%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
div-invN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6488.4
Applied rewrites88.4%
Taylor expanded in y around 0
lower-*.f6412.7
Applied rewrites12.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
(if (<= y 6.5e+48)
(* (/ x_m z) (fma -0.16666666666666666 (* y y) 1.0))
(* (/ 1.0 (* y z)) (* x_m 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 <= 6.5e+48) {
tmp = (x_m / z) * fma(-0.16666666666666666, (y * y), 1.0);
} else {
tmp = (1.0 / (y * z)) * (x_m * 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 <= 6.5e+48) tmp = Float64(Float64(x_m / z) * fma(-0.16666666666666666, Float64(y * y), 1.0)); else tmp = Float64(Float64(1.0 / Float64(y * z)) * Float64(x_m * y)); end return Float64(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, 6.5e+48], N[(N[(x$95$m / z), $MachinePrecision] * N[(-0.16666666666666666 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(y * z), $MachinePrecision]), $MachinePrecision] * N[(x$95$m * 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 6.5 \cdot 10^{+48}:\\
\;\;\;\;\frac{x\_m}{z} \cdot \mathsf{fma}\left(-0.16666666666666666, y \cdot y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y \cdot z} \cdot \left(x\_m \cdot y\right)\\
\end{array}
\end{array}
if y < 6.49999999999999972e48Initial program 98.1%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6496.9
Applied rewrites96.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6465.2
Applied rewrites65.2%
if 6.49999999999999972e48 < y Initial program 88.1%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
div-invN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6489.3
Applied rewrites89.3%
Taylor expanded in y around 0
lower-*.f6413.9
Applied rewrites13.9%
Final simplification57.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 (/ 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 96.7%
Taylor expanded in y around 0
lower-/.f6460.0
Applied rewrites60.0%
(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 2024226
(FPCore (x y z)
:name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
:precision binary64
:alt
(! :herbie-platform default (if (< z -42173720203427147/1000000000000000000000000000000000000000000000) (/ (* x (/ 1 (/ y (sin y)))) z) (if (< z 44467023691138110000000000000000000000000000000000000000000000000) (/ x (* z (/ y (sin y)))) (/ (* x (/ 1 (/ y (sin y)))) z))))
(/ (* x (/ (sin y) y)) z))