
(FPCore (x c s) :precision binary64 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
double code(double x, double c, double s) {
return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
public static double code(double x, double c, double s) {
return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
def code(x, c, s): return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
function code(x, c, s) return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) end
function tmp = code(x, c, s) tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x)); end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x c s) :precision binary64 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
double code(double x, double c, double s) {
return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
public static double code(double x, double c, double s) {
return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
def code(x, c, s): return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
function code(x, c, s) return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) end
function tmp = code(x, c, s) tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x)); end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\end{array}
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (let* ((t_0 (* c (* s (sqrt x))))) (/ (cos (* 2.0 x)) (* t_0 (* x t_0)))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (s * sqrt(x));
return cos((2.0 * x)) / (t_0 * (x * t_0));
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
t_0 = c * (s * sqrt(x))
code = cos((2.0d0 * x)) / (t_0 * (x * t_0))
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = c * (s * Math.sqrt(x));
return Math.cos((2.0 * x)) / (t_0 * (x * t_0));
}
x = abs(x) c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (s * math.sqrt(x)) return math.cos((2.0 * x)) / (t_0 * (x * t_0))
x = abs(x) c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(c * Float64(s * sqrt(x))) return Float64(cos(Float64(2.0 * x)) / Float64(t_0 * Float64(x * t_0))) end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
t_0 = c * (s * sqrt(x));
tmp = cos((2.0 * x)) / (t_0 * (x * t_0));
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(s * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(s \cdot \sqrt{x}\right)\\
\frac{\cos \left(2 \cdot x\right)}{t_0 \cdot \left(x \cdot t_0\right)}
\end{array}
\end{array}
Initial program 71.1%
associate-/r*71.1%
remove-double-neg71.1%
distribute-lft-neg-out71.1%
distribute-lft-neg-out71.1%
distribute-rgt-neg-out71.1%
associate-/l/71.1%
distribute-rgt-neg-out71.1%
distribute-lft-neg-out71.1%
associate-*l*74.8%
distribute-lft-neg-in74.8%
distribute-lft-neg-out74.8%
remove-double-neg74.8%
associate-*r*74.9%
*-commutative74.9%
associate-*r*72.0%
Simplified76.8%
Taylor expanded in x around 0 66.3%
unpow266.3%
unpow266.3%
unpow266.3%
swap-sqr79.9%
swap-sqr97.0%
unpow297.0%
Simplified97.0%
associate-*r*97.8%
unpow-prod-down80.1%
pow-prod-down66.2%
pow266.2%
pow266.2%
associate-*r*70.3%
pow270.3%
*-commutative70.3%
associate-*r*76.8%
add-sqr-sqrt39.1%
associate-*r*39.1%
Applied egg-rr50.3%
Final simplification50.3%
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
:precision binary64
(let* ((t_0 (* c (* x s))))
(if (<= s 1.5e+173)
(/ (cos (* 2.0 x)) (* c (* x (* c (* s (* x s))))))
(/ 1.0 (* t_0 t_0)))))x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (x * s);
double tmp;
if (s <= 1.5e+173) {
tmp = cos((2.0 * x)) / (c * (x * (c * (s * (x * s)))));
} else {
tmp = 1.0 / (t_0 * t_0);
}
return tmp;
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
real(8) :: tmp
t_0 = c * (x * s)
if (s <= 1.5d+173) then
tmp = cos((2.0d0 * x)) / (c * (x * (c * (s * (x * s)))))
else
tmp = 1.0d0 / (t_0 * t_0)
end if
code = tmp
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = c * (x * s);
double tmp;
if (s <= 1.5e+173) {
tmp = Math.cos((2.0 * x)) / (c * (x * (c * (s * (x * s)))));
} else {
tmp = 1.0 / (t_0 * t_0);
}
return tmp;
}
x = abs(x) c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (x * s) tmp = 0 if s <= 1.5e+173: tmp = math.cos((2.0 * x)) / (c * (x * (c * (s * (x * s))))) else: tmp = 1.0 / (t_0 * t_0) return tmp
x = abs(x) c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(c * Float64(x * s)) tmp = 0.0 if (s <= 1.5e+173) tmp = Float64(cos(Float64(2.0 * x)) / Float64(c * Float64(x * Float64(c * Float64(s * Float64(x * s)))))); else tmp = Float64(1.0 / Float64(t_0 * t_0)); end return tmp end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
t_0 = c * (x * s);
tmp = 0.0;
if (s <= 1.5e+173)
tmp = cos((2.0 * x)) / (c * (x * (c * (s * (x * s)))));
else
tmp = 1.0 / (t_0 * t_0);
end
tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[s, 1.5e+173], N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(c * N[(x * N[(c * N[(s * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\mathbf{if}\;s \leq 1.5 \cdot 10^{+173}:\\
\;\;\;\;\frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0 \cdot t_0}\\
\end{array}
\end{array}
if s < 1.4999999999999999e173Initial program 71.3%
associate-/r*71.3%
remove-double-neg71.3%
distribute-lft-neg-out71.3%
distribute-lft-neg-out71.3%
distribute-rgt-neg-out71.3%
associate-/l/71.3%
distribute-rgt-neg-out71.3%
distribute-lft-neg-out71.3%
associate-*l*75.3%
distribute-lft-neg-in75.3%
distribute-lft-neg-out75.3%
remove-double-neg75.3%
associate-*r*75.4%
*-commutative75.4%
associate-*r*72.3%
Simplified77.5%
Taylor expanded in x around 0 66.8%
unpow266.8%
unpow266.8%
unpow266.8%
swap-sqr79.4%
swap-sqr97.1%
unpow297.1%
Simplified97.1%
unpow297.1%
swap-sqr79.4%
associate-*r*78.5%
*-commutative78.5%
associate-*l*71.3%
associate-*l*75.0%
associate-*l*78.8%
associate-*l*80.7%
associate-*l*87.5%
Applied egg-rr87.5%
if 1.4999999999999999e173 < s Initial program 70.1%
associate-/r*70.1%
remove-double-neg70.1%
distribute-lft-neg-out70.1%
distribute-lft-neg-out70.1%
distribute-rgt-neg-out70.1%
associate-/l/70.1%
distribute-rgt-neg-out70.1%
distribute-lft-neg-out70.1%
associate-*l*70.1%
distribute-lft-neg-in70.1%
distribute-lft-neg-out70.1%
remove-double-neg70.1%
associate-*r*70.1%
*-commutative70.1%
associate-*r*70.1%
Simplified70.4%
Taylor expanded in x around 0 61.9%
unpow261.9%
unpow261.9%
unpow261.9%
swap-sqr84.9%
swap-sqr96.0%
unpow296.0%
Simplified96.0%
unpow296.0%
Applied egg-rr96.0%
Taylor expanded in x around 0 92.5%
Final simplification88.0%
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
:precision binary64
(let* ((t_0 (cos (* 2.0 x))))
(if (<= s 5e-17)
(/ t_0 (* c (* x (* c (* s (* x s))))))
(/ t_0 (* (* c s) (* x (* c (* x s))))))))x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = cos((2.0 * x));
double tmp;
if (s <= 5e-17) {
tmp = t_0 / (c * (x * (c * (s * (x * s)))));
} else {
tmp = t_0 / ((c * s) * (x * (c * (x * s))));
}
return tmp;
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
real(8) :: tmp
t_0 = cos((2.0d0 * x))
if (s <= 5d-17) then
tmp = t_0 / (c * (x * (c * (s * (x * s)))))
else
tmp = t_0 / ((c * s) * (x * (c * (x * s))))
end if
code = tmp
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = Math.cos((2.0 * x));
double tmp;
if (s <= 5e-17) {
tmp = t_0 / (c * (x * (c * (s * (x * s)))));
} else {
tmp = t_0 / ((c * s) * (x * (c * (x * s))));
}
return tmp;
}
x = abs(x) c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = math.cos((2.0 * x)) tmp = 0 if s <= 5e-17: tmp = t_0 / (c * (x * (c * (s * (x * s))))) else: tmp = t_0 / ((c * s) * (x * (c * (x * s)))) return tmp
x = abs(x) c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = cos(Float64(2.0 * x)) tmp = 0.0 if (s <= 5e-17) tmp = Float64(t_0 / Float64(c * Float64(x * Float64(c * Float64(s * Float64(x * s)))))); else tmp = Float64(t_0 / Float64(Float64(c * s) * Float64(x * Float64(c * Float64(x * s))))); end return tmp end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
t_0 = cos((2.0 * x));
tmp = 0.0;
if (s <= 5e-17)
tmp = t_0 / (c * (x * (c * (s * (x * s)))));
else
tmp = t_0 / ((c * s) * (x * (c * (x * s))));
end
tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[s, 5e-17], N[(t$95$0 / N[(c * N[(x * N[(c * N[(s * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(N[(c * s), $MachinePrecision] * N[(x * N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \cos \left(2 \cdot x\right)\\
\mathbf{if}\;s \leq 5 \cdot 10^{-17}:\\
\;\;\;\;\frac{t_0}{c \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{\left(c \cdot s\right) \cdot \left(x \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}\\
\end{array}
\end{array}
if s < 4.9999999999999999e-17Initial program 71.1%
associate-/r*71.1%
remove-double-neg71.1%
distribute-lft-neg-out71.1%
distribute-lft-neg-out71.1%
distribute-rgt-neg-out71.1%
associate-/l/71.1%
distribute-rgt-neg-out71.1%
distribute-lft-neg-out71.1%
associate-*l*73.5%
distribute-lft-neg-in73.5%
distribute-lft-neg-out73.5%
remove-double-neg73.5%
associate-*r*73.0%
*-commutative73.0%
associate-*r*71.3%
Simplified76.5%
Taylor expanded in x around 0 65.8%
unpow265.8%
unpow265.8%
unpow265.8%
swap-sqr80.7%
swap-sqr97.2%
unpow297.2%
Simplified97.2%
unpow297.2%
swap-sqr80.7%
associate-*r*79.5%
*-commutative79.5%
associate-*l*71.1%
associate-*l*73.0%
associate-*l*77.5%
associate-*l*79.2%
associate-*l*87.2%
Applied egg-rr87.2%
if 4.9999999999999999e-17 < s Initial program 71.4%
associate-/r*71.4%
remove-double-neg71.4%
distribute-lft-neg-out71.4%
distribute-lft-neg-out71.4%
distribute-rgt-neg-out71.4%
associate-/l/71.4%
distribute-rgt-neg-out71.4%
distribute-lft-neg-out71.4%
associate-*l*79.1%
distribute-lft-neg-in79.1%
distribute-lft-neg-out79.1%
remove-double-neg79.1%
associate-*r*80.7%
*-commutative80.7%
associate-*r*74.5%
Simplified77.8%
Taylor expanded in x around 0 68.0%
unpow268.0%
unpow268.0%
unpow268.0%
swap-sqr77.7%
swap-sqr96.4%
unpow296.4%
Simplified96.4%
unpow296.4%
associate-*r*95.0%
associate-*l*91.9%
Applied egg-rr91.9%
Final simplification88.3%
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (let* ((t_0 (* c (* x s)))) (/ (cos (* 2.0 x)) (* t_0 t_0))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return cos((2.0 * x)) / (t_0 * t_0);
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
t_0 = c * (x * s)
code = cos((2.0d0 * x)) / (t_0 * t_0)
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = c * (x * s);
return Math.cos((2.0 * x)) / (t_0 * t_0);
}
x = abs(x) c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (x * s) return math.cos((2.0 * x)) / (t_0 * t_0)
x = abs(x) c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(c * Float64(x * s)) return Float64(cos(Float64(2.0 * x)) / Float64(t_0 * t_0)) end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
t_0 = c * (x * s);
tmp = cos((2.0 * x)) / (t_0 * t_0);
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\frac{\cos \left(2 \cdot x\right)}{t_0 \cdot t_0}
\end{array}
\end{array}
Initial program 71.1%
associate-/r*71.1%
remove-double-neg71.1%
distribute-lft-neg-out71.1%
distribute-lft-neg-out71.1%
distribute-rgt-neg-out71.1%
associate-/l/71.1%
distribute-rgt-neg-out71.1%
distribute-lft-neg-out71.1%
associate-*l*74.8%
distribute-lft-neg-in74.8%
distribute-lft-neg-out74.8%
remove-double-neg74.8%
associate-*r*74.9%
*-commutative74.9%
associate-*r*72.0%
Simplified76.8%
Taylor expanded in x around 0 66.3%
unpow266.3%
unpow266.3%
unpow266.3%
swap-sqr79.9%
swap-sqr97.0%
unpow297.0%
Simplified97.0%
unpow297.0%
Applied egg-rr97.0%
Final simplification97.0%
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (if (<= x 4.2e-55) (/ 1.0 (* x (* (* s (* x s)) (* c c)))) (/ 1.0 (* x (* x (* c (* c (* s s))))))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double tmp;
if (x <= 4.2e-55) {
tmp = 1.0 / (x * ((s * (x * s)) * (c * c)));
} else {
tmp = 1.0 / (x * (x * (c * (c * (s * s)))));
}
return tmp;
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: tmp
if (x <= 4.2d-55) then
tmp = 1.0d0 / (x * ((s * (x * s)) * (c * c)))
else
tmp = 1.0d0 / (x * (x * (c * (c * (s * s)))))
end if
code = tmp
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double tmp;
if (x <= 4.2e-55) {
tmp = 1.0 / (x * ((s * (x * s)) * (c * c)));
} else {
tmp = 1.0 / (x * (x * (c * (c * (s * s)))));
}
return tmp;
}
x = abs(x) c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): tmp = 0 if x <= 4.2e-55: tmp = 1.0 / (x * ((s * (x * s)) * (c * c))) else: tmp = 1.0 / (x * (x * (c * (c * (s * s))))) return tmp
x = abs(x) c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) tmp = 0.0 if (x <= 4.2e-55) tmp = Float64(1.0 / Float64(x * Float64(Float64(s * Float64(x * s)) * Float64(c * c)))); else tmp = Float64(1.0 / Float64(x * Float64(x * Float64(c * Float64(c * Float64(s * s)))))); end return tmp end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
tmp = 0.0;
if (x <= 4.2e-55)
tmp = 1.0 / (x * ((s * (x * s)) * (c * c)));
else
tmp = 1.0 / (x * (x * (c * (c * (s * s)))));
end
tmp_2 = tmp;
end
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := If[LessEqual[x, 4.2e-55], N[(1.0 / N[(x * N[(N[(s * N[(x * s), $MachinePrecision]), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(x * N[(x * N[(c * N[(c * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.2 \cdot 10^{-55}:\\
\;\;\;\;\frac{1}{x \cdot \left(\left(s \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot c\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \left(x \cdot \left(c \cdot \left(c \cdot \left(s \cdot s\right)\right)\right)\right)}\\
\end{array}
\end{array}
if x < 4.2000000000000003e-55Initial program 71.6%
associate-/r*71.6%
remove-double-neg71.6%
distribute-lft-neg-out71.6%
distribute-lft-neg-out71.6%
distribute-rgt-neg-out71.6%
associate-/l/71.6%
distribute-rgt-neg-out71.6%
distribute-lft-neg-out71.6%
associate-*l*75.2%
distribute-lft-neg-in75.2%
distribute-lft-neg-out75.2%
remove-double-neg75.2%
associate-*r*74.7%
*-commutative74.7%
associate-*r*71.7%
Simplified75.3%
Taylor expanded in x around 0 74.7%
unpow274.7%
unpow274.7%
Simplified74.7%
Taylor expanded in s around 0 74.7%
unpow274.7%
associate-*r*82.0%
Simplified82.0%
Taylor expanded in x around 0 75.0%
if 4.2000000000000003e-55 < x Initial program 70.1%
associate-/r*70.1%
remove-double-neg70.1%
distribute-lft-neg-out70.1%
distribute-lft-neg-out70.1%
distribute-rgt-neg-out70.1%
associate-/l/70.1%
distribute-rgt-neg-out70.1%
distribute-lft-neg-out70.1%
associate-*l*73.9%
distribute-lft-neg-in73.9%
distribute-lft-neg-out73.9%
remove-double-neg73.9%
associate-*r*75.3%
*-commutative75.3%
associate-*r*72.8%
Simplified80.6%
Taylor expanded in x around 0 60.1%
Final simplification70.7%
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ 1.0 (* x (* x (* c (* c (* s s)))))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
return 1.0 / (x * (x * (c * (c * (s * s)))));
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = 1.0d0 / (x * (x * (c * (c * (s * s)))))
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
return 1.0 / (x * (x * (c * (c * (s * s)))));
}
x = abs(x) c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): return 1.0 / (x * (x * (c * (c * (s * s)))))
x = abs(x) c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) return Float64(1.0 / Float64(x * Float64(x * Float64(c * Float64(c * Float64(s * s)))))) end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = 1.0 / (x * (x * (c * (c * (s * s)))));
end
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(1.0 / N[(x * N[(x * N[(c * N[(c * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{x \cdot \left(x \cdot \left(c \cdot \left(c \cdot \left(s \cdot s\right)\right)\right)\right)}
\end{array}
Initial program 71.1%
associate-/r*71.1%
remove-double-neg71.1%
distribute-lft-neg-out71.1%
distribute-lft-neg-out71.1%
distribute-rgt-neg-out71.1%
associate-/l/71.1%
distribute-rgt-neg-out71.1%
distribute-lft-neg-out71.1%
associate-*l*74.8%
distribute-lft-neg-in74.8%
distribute-lft-neg-out74.8%
remove-double-neg74.8%
associate-*r*74.9%
*-commutative74.9%
associate-*r*72.0%
Simplified76.8%
Taylor expanded in x around 0 67.5%
Final simplification67.5%
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ 1.0 (* (* c s) (* x (* c (* x s))))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
return 1.0 / ((c * s) * (x * (c * (x * s))));
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = 1.0d0 / ((c * s) * (x * (c * (x * s))))
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
return 1.0 / ((c * s) * (x * (c * (x * s))));
}
x = abs(x) c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): return 1.0 / ((c * s) * (x * (c * (x * s))))
x = abs(x) c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) return Float64(1.0 / Float64(Float64(c * s) * Float64(x * Float64(c * Float64(x * s))))) end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = 1.0 / ((c * s) * (x * (c * (x * s))));
end
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(1.0 / N[(N[(c * s), $MachinePrecision] * N[(x * N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{\left(c \cdot s\right) \cdot \left(x \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}
\end{array}
Initial program 71.1%
associate-/r*71.1%
remove-double-neg71.1%
distribute-lft-neg-out71.1%
distribute-lft-neg-out71.1%
distribute-rgt-neg-out71.1%
associate-/l/71.1%
distribute-rgt-neg-out71.1%
distribute-lft-neg-out71.1%
associate-*l*74.8%
distribute-lft-neg-in74.8%
distribute-lft-neg-out74.8%
remove-double-neg74.8%
associate-*r*74.9%
*-commutative74.9%
associate-*r*72.0%
Simplified76.8%
Taylor expanded in x around 0 66.3%
unpow266.3%
unpow266.3%
unpow266.3%
swap-sqr79.9%
swap-sqr97.0%
unpow297.0%
Simplified97.0%
unpow297.0%
associate-*r*95.6%
associate-*l*93.0%
Applied egg-rr93.0%
Taylor expanded in x around 0 78.5%
Final simplification78.5%
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (let* ((t_0 (* c (* x s)))) (/ 1.0 (* t_0 t_0))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return 1.0 / (t_0 * t_0);
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
t_0 = c * (x * s)
code = 1.0d0 / (t_0 * t_0)
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = c * (x * s);
return 1.0 / (t_0 * t_0);
}
x = abs(x) c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (x * s) return 1.0 / (t_0 * t_0)
x = abs(x) c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(c * Float64(x * s)) return Float64(1.0 / Float64(t_0 * t_0)) end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
t_0 = c * (x * s);
tmp = 1.0 / (t_0 * t_0);
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\frac{1}{t_0 \cdot t_0}
\end{array}
\end{array}
Initial program 71.1%
associate-/r*71.1%
remove-double-neg71.1%
distribute-lft-neg-out71.1%
distribute-lft-neg-out71.1%
distribute-rgt-neg-out71.1%
associate-/l/71.1%
distribute-rgt-neg-out71.1%
distribute-lft-neg-out71.1%
associate-*l*74.8%
distribute-lft-neg-in74.8%
distribute-lft-neg-out74.8%
remove-double-neg74.8%
associate-*r*74.9%
*-commutative74.9%
associate-*r*72.0%
Simplified76.8%
Taylor expanded in x around 0 66.3%
unpow266.3%
unpow266.3%
unpow266.3%
swap-sqr79.9%
swap-sqr97.0%
unpow297.0%
Simplified97.0%
unpow297.0%
Applied egg-rr97.0%
Taylor expanded in x around 0 79.5%
Final simplification79.5%
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ -2.0 (* (* c c) (* s s))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
return -2.0 / ((c * c) * (s * s));
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = (-2.0d0) / ((c * c) * (s * s))
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
return -2.0 / ((c * c) * (s * s));
}
x = abs(x) c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): return -2.0 / ((c * c) * (s * s))
x = abs(x) c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) return Float64(-2.0 / Float64(Float64(c * c) * Float64(s * s))) end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = -2.0 / ((c * c) * (s * s));
end
NOTE: x should be positive before calling this function NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(-2.0 / N[(N[(c * c), $MachinePrecision] * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{-2}{\left(c \cdot c\right) \cdot \left(s \cdot s\right)}
\end{array}
Initial program 71.1%
associate-/r*71.1%
remove-double-neg71.1%
distribute-lft-neg-out71.1%
distribute-lft-neg-out71.1%
distribute-rgt-neg-out71.1%
associate-/l/71.1%
distribute-rgt-neg-out71.1%
distribute-lft-neg-out71.1%
associate-*l*74.8%
distribute-lft-neg-in74.8%
distribute-lft-neg-out74.8%
remove-double-neg74.8%
associate-*r*74.9%
*-commutative74.9%
associate-*r*72.0%
Simplified76.8%
Taylor expanded in x around 0 51.1%
unpow251.1%
Simplified51.1%
Taylor expanded in x around inf 31.8%
unpow231.8%
unpow231.8%
associate-/r*31.7%
Simplified31.7%
Taylor expanded in c around 0 31.8%
unpow231.8%
unpow231.8%
*-commutative31.8%
Simplified31.8%
Final simplification31.8%
herbie shell --seed 2023293
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))