
(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 5 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}
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
:precision binary64
(let* ((t_0 (* s_m (* x_m c_m)))
(t_1 (cos (* x_m 2.0)))
(t_2 (* c_m (* x_m s_m))))
(if (<= x_m 3.5e+161) (/ (/ t_1 t_2) t_2) (/ t_1 (* t_0 t_0)))))x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double t_0 = s_m * (x_m * c_m);
double t_1 = cos((x_m * 2.0));
double t_2 = c_m * (x_m * s_m);
double tmp;
if (x_m <= 3.5e+161) {
tmp = (t_1 / t_2) / t_2;
} else {
tmp = t_1 / (t_0 * t_0);
}
return tmp;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = s_m * (x_m * c_m)
t_1 = cos((x_m * 2.0d0))
t_2 = c_m * (x_m * s_m)
if (x_m <= 3.5d+161) then
tmp = (t_1 / t_2) / t_2
else
tmp = t_1 / (t_0 * t_0)
end if
code = tmp
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double t_0 = s_m * (x_m * c_m);
double t_1 = Math.cos((x_m * 2.0));
double t_2 = c_m * (x_m * s_m);
double tmp;
if (x_m <= 3.5e+161) {
tmp = (t_1 / t_2) / t_2;
} else {
tmp = t_1 / (t_0 * t_0);
}
return tmp;
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): t_0 = s_m * (x_m * c_m) t_1 = math.cos((x_m * 2.0)) t_2 = c_m * (x_m * s_m) tmp = 0 if x_m <= 3.5e+161: tmp = (t_1 / t_2) / t_2 else: tmp = t_1 / (t_0 * t_0) return tmp
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(s_m * Float64(x_m * c_m)) t_1 = cos(Float64(x_m * 2.0)) t_2 = Float64(c_m * Float64(x_m * s_m)) tmp = 0.0 if (x_m <= 3.5e+161) tmp = Float64(Float64(t_1 / t_2) / t_2); else tmp = Float64(t_1 / Float64(t_0 * t_0)); end return tmp end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp_2 = code(x_m, c_m, s_m)
t_0 = s_m * (x_m * c_m);
t_1 = cos((x_m * 2.0));
t_2 = c_m * (x_m * s_m);
tmp = 0.0;
if (x_m <= 3.5e+161)
tmp = (t_1 / t_2) / t_2;
else
tmp = t_1 / (t_0 * t_0);
end
tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(s$95$m * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$95$m, 3.5e+161], N[(N[(t$95$1 / t$95$2), $MachinePrecision] / t$95$2), $MachinePrecision], N[(t$95$1 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := s\_m \cdot \left(x\_m \cdot c\_m\right)\\
t_1 := \cos \left(x\_m \cdot 2\right)\\
t_2 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\
\mathbf{if}\;x\_m \leq 3.5 \cdot 10^{+161}:\\
\;\;\;\;\frac{\frac{t\_1}{t\_2}}{t\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{t\_0 \cdot t\_0}\\
\end{array}
\end{array}
if x < 3.49999999999999988e161Initial program 67.2%
*-un-lft-identity67.2%
add-sqr-sqrt67.1%
times-frac67.1%
sqrt-prod67.1%
sqrt-pow143.5%
metadata-eval43.5%
pow143.5%
*-commutative43.5%
associate-*r*41.4%
unpow241.4%
pow-prod-down43.5%
sqrt-pow146.1%
metadata-eval46.1%
pow146.1%
*-commutative46.1%
Applied egg-rr98.6%
associate-*l/98.7%
*-un-lft-identity98.7%
*-commutative98.7%
Applied egg-rr98.7%
if 3.49999999999999988e161 < x Initial program 44.0%
*-un-lft-identity44.0%
add-sqr-sqrt44.0%
times-frac44.0%
sqrt-prod44.0%
sqrt-pow137.2%
metadata-eval37.2%
pow137.2%
*-commutative37.2%
associate-*r*33.4%
unpow233.4%
pow-prod-down37.2%
sqrt-pow140.4%
metadata-eval40.4%
pow140.4%
*-commutative40.4%
Applied egg-rr96.0%
associate-*l/96.0%
*-un-lft-identity96.0%
*-commutative96.0%
Applied egg-rr96.0%
frac-2neg96.0%
div-inv96.0%
distribute-neg-frac296.0%
associate-*r*89.8%
distribute-lft-neg-in89.8%
associate-*r*93.4%
distribute-lft-neg-in93.4%
Applied egg-rr93.4%
associate-*r/93.4%
*-rgt-identity93.4%
associate-/l/92.7%
distribute-lft-neg-out92.7%
distribute-lft-neg-out92.7%
sqr-neg92.7%
remove-double-neg92.7%
distribute-lft-neg-out92.7%
*-commutative92.7%
distribute-rgt-neg-in92.7%
remove-double-neg92.7%
remove-double-neg92.7%
distribute-lft-neg-out92.7%
*-commutative92.7%
distribute-rgt-neg-in92.7%
remove-double-neg92.7%
Simplified92.7%
Final simplification98.0%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (let* ((t_0 (* s_m (* x_m c_m))) (t_1 (/ (/ 1.0 c_m) (* x_m s_m)))) (if (<= x_m 3e-39) (* t_1 t_1) (/ (cos (* x_m 2.0)) (* t_0 t_0)))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double t_0 = s_m * (x_m * c_m);
double t_1 = (1.0 / c_m) / (x_m * s_m);
double tmp;
if (x_m <= 3e-39) {
tmp = t_1 * t_1;
} else {
tmp = cos((x_m * 2.0)) / (t_0 * t_0);
}
return tmp;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = s_m * (x_m * c_m)
t_1 = (1.0d0 / c_m) / (x_m * s_m)
if (x_m <= 3d-39) then
tmp = t_1 * t_1
else
tmp = cos((x_m * 2.0d0)) / (t_0 * t_0)
end if
code = tmp
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double t_0 = s_m * (x_m * c_m);
double t_1 = (1.0 / c_m) / (x_m * s_m);
double tmp;
if (x_m <= 3e-39) {
tmp = t_1 * t_1;
} else {
tmp = Math.cos((x_m * 2.0)) / (t_0 * t_0);
}
return tmp;
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): t_0 = s_m * (x_m * c_m) t_1 = (1.0 / c_m) / (x_m * s_m) tmp = 0 if x_m <= 3e-39: tmp = t_1 * t_1 else: tmp = math.cos((x_m * 2.0)) / (t_0 * t_0) return tmp
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(s_m * Float64(x_m * c_m)) t_1 = Float64(Float64(1.0 / c_m) / Float64(x_m * s_m)) tmp = 0.0 if (x_m <= 3e-39) tmp = Float64(t_1 * t_1); else tmp = Float64(cos(Float64(x_m * 2.0)) / Float64(t_0 * t_0)); end return tmp end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp_2 = code(x_m, c_m, s_m)
t_0 = s_m * (x_m * c_m);
t_1 = (1.0 / c_m) / (x_m * s_m);
tmp = 0.0;
if (x_m <= 3e-39)
tmp = t_1 * t_1;
else
tmp = cos((x_m * 2.0)) / (t_0 * t_0);
end
tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(s$95$m * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$95$m, 3e-39], N[(t$95$1 * t$95$1), $MachinePrecision], N[(N[Cos[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := s\_m \cdot \left(x\_m \cdot c\_m\right)\\
t_1 := \frac{\frac{1}{c\_m}}{x\_m \cdot s\_m}\\
\mathbf{if}\;x\_m \leq 3 \cdot 10^{-39}:\\
\;\;\;\;t\_1 \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x\_m \cdot 2\right)}{t\_0 \cdot t\_0}\\
\end{array}
\end{array}
if x < 3.00000000000000028e-39Initial program 67.2%
Taylor expanded in x around 0 55.3%
associate-/r*55.3%
*-commutative55.3%
unpow255.3%
unpow255.3%
swap-sqr63.9%
unpow263.9%
associate-/r*63.8%
unpow263.8%
unpow263.8%
swap-sqr80.8%
unpow280.8%
*-commutative80.8%
Simplified80.8%
metadata-eval80.8%
*-commutative80.8%
pow280.8%
frac-times81.1%
associate-/r*81.1%
associate-/r*81.1%
Applied egg-rr81.1%
if 3.00000000000000028e-39 < x Initial program 56.4%
*-un-lft-identity56.4%
add-sqr-sqrt56.4%
times-frac56.4%
sqrt-prod56.4%
sqrt-pow143.7%
metadata-eval43.7%
pow143.7%
*-commutative43.7%
associate-*r*40.5%
unpow240.5%
pow-prod-down43.7%
sqrt-pow147.0%
metadata-eval47.0%
pow147.0%
*-commutative47.0%
Applied egg-rr97.9%
associate-*l/97.9%
*-un-lft-identity97.9%
*-commutative97.9%
Applied egg-rr97.9%
frac-2neg97.9%
div-inv97.9%
distribute-neg-frac297.9%
associate-*r*95.0%
distribute-lft-neg-in95.0%
associate-*r*96.7%
distribute-lft-neg-in96.7%
Applied egg-rr96.7%
associate-*r/96.8%
*-rgt-identity96.8%
associate-/l/96.4%
distribute-lft-neg-out96.4%
distribute-lft-neg-out96.4%
sqr-neg96.4%
remove-double-neg96.4%
distribute-lft-neg-out96.4%
*-commutative96.4%
distribute-rgt-neg-in96.4%
remove-double-neg96.4%
remove-double-neg96.4%
distribute-lft-neg-out96.4%
*-commutative96.4%
distribute-rgt-neg-in96.4%
remove-double-neg96.4%
Simplified96.4%
Final simplification85.0%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (let* ((t_0 (/ (/ 1.0 c_m) (* x_m s_m)))) (* t_0 t_0)))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double t_0 = (1.0 / c_m) / (x_m * s_m);
return t_0 * t_0;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = (1.0d0 / c_m) / (x_m * s_m)
code = t_0 * t_0
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double t_0 = (1.0 / c_m) / (x_m * s_m);
return t_0 * t_0;
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): t_0 = (1.0 / c_m) / (x_m * s_m) return t_0 * t_0
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(Float64(1.0 / c_m) / Float64(x_m * s_m)) return Float64(t_0 * t_0) end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
t_0 = (1.0 / c_m) / (x_m * s_m);
tmp = t_0 * t_0;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * t$95$0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \frac{\frac{1}{c\_m}}{x\_m \cdot s\_m}\\
t\_0 \cdot t\_0
\end{array}
\end{array}
Initial program 64.5%
Taylor expanded in x around 0 51.3%
associate-/r*51.3%
*-commutative51.3%
unpow251.3%
unpow251.3%
swap-sqr60.7%
unpow260.7%
associate-/r*60.7%
unpow260.7%
unpow260.7%
swap-sqr75.5%
unpow275.5%
*-commutative75.5%
Simplified75.5%
metadata-eval75.5%
*-commutative75.5%
pow275.5%
frac-times75.7%
associate-/r*75.7%
associate-/r*75.7%
Applied egg-rr75.7%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (let* ((t_0 (/ 1.0 (* c_m (* x_m s_m))))) (* t_0 t_0)))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double t_0 = 1.0 / (c_m * (x_m * s_m));
return t_0 * t_0;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = 1.0d0 / (c_m * (x_m * s_m))
code = t_0 * t_0
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double t_0 = 1.0 / (c_m * (x_m * s_m));
return t_0 * t_0;
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): t_0 = 1.0 / (c_m * (x_m * s_m)) return t_0 * t_0
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(1.0 / Float64(c_m * Float64(x_m * s_m))) return Float64(t_0 * t_0) end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
t_0 = 1.0 / (c_m * (x_m * s_m));
tmp = t_0 * t_0;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(1.0 / N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * t$95$0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \frac{1}{c\_m \cdot \left(x\_m \cdot s\_m\right)}\\
t\_0 \cdot t\_0
\end{array}
\end{array}
Initial program 64.5%
*-un-lft-identity64.5%
add-sqr-sqrt64.4%
times-frac64.4%
sqrt-prod64.4%
sqrt-pow142.7%
metadata-eval42.7%
pow142.7%
*-commutative42.7%
associate-*r*40.5%
unpow240.5%
pow-prod-down42.8%
sqrt-pow145.4%
metadata-eval45.4%
pow145.4%
*-commutative45.4%
Applied egg-rr98.3%
Taylor expanded in x around 0 75.7%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (let* ((t_0 (* c_m (* x_m s_m)))) (/ 1.0 (* t_0 t_0))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double t_0 = c_m * (x_m * s_m);
return 1.0 / (t_0 * t_0);
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = c_m * (x_m * s_m)
code = 1.0d0 / (t_0 * t_0)
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double t_0 = c_m * (x_m * s_m);
return 1.0 / (t_0 * t_0);
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): t_0 = c_m * (x_m * s_m) return 1.0 / (t_0 * t_0)
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(c_m * Float64(x_m * s_m)) return Float64(1.0 / Float64(t_0 * t_0)) end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
t_0 = c_m * (x_m * s_m);
tmp = 1.0 / (t_0 * t_0);
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 64.5%
Taylor expanded in x around 0 51.3%
associate-/r*51.3%
*-commutative51.3%
unpow251.3%
unpow251.3%
swap-sqr60.7%
unpow260.7%
associate-/r*60.7%
unpow260.7%
unpow260.7%
swap-sqr75.5%
unpow275.5%
*-commutative75.5%
Simplified75.5%
*-commutative75.5%
pow275.5%
Applied egg-rr75.5%
herbie shell --seed 2024118
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))