Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef GINAC_NUMERIC_H
00024 #define GINAC_NUMERIC_H
00025
00026 #include "basic.h"
00027 #include "ex.h"
00028 #include "archive.h"
00029
00030 #include <cln/complex.h>
00031 #if defined(G__CINTVERSION) && !defined(__MAKECINT__)
00032
00033
00034
00035 #include <cln/complex_class.h>
00036 #endif
00037 #include <stdexcept>
00038 #include <vector>
00039
00040 namespace GiNaC {
00041
00046 typedef void (* digits_changed_callback)(long);
00047
00057 class _numeric_digits
00058 {
00059
00060 public:
00061 _numeric_digits();
00062 _numeric_digits& operator=(long prec);
00063 operator long();
00064 void print(std::ostream& os) const;
00065 void add_callback(digits_changed_callback callback);
00066
00067 private:
00068 long digits;
00069 static bool too_late;
00070
00071 std::vector<digits_changed_callback> callbacklist;
00072 };
00073
00074
00076 class pole_error : public std::domain_error {
00077 public:
00078 explicit pole_error(const std::string& what_arg, int degree);
00079 int degree() const;
00080 private:
00081 int deg;
00082 };
00083
00084
00087 class numeric : public basic
00088 {
00089 GINAC_DECLARE_REGISTERED_CLASS(numeric, basic)
00090
00091
00092
00093
00094 public:
00095 numeric(int i);
00096 numeric(unsigned int i);
00097 numeric(long i);
00098 numeric(unsigned long i);
00099 numeric(long numer, long denom);
00100 numeric(double d);
00101 numeric(const char *);
00102
00103
00104 public:
00105 unsigned precedence() const {return 30;}
00106 bool info(unsigned inf) const;
00107 bool is_polynomial(const ex & var) const;
00108 int degree(const ex & s) const;
00109 int ldegree(const ex & s) const;
00110 ex coeff(const ex & s, int n = 1) const;
00111 bool has(const ex &other, unsigned options = 0) const;
00112 ex eval(int level = 0) const;
00113 ex evalf(int level = 0) const;
00114 ex subs(const exmap & m, unsigned options = 0) const { return subs_one_level(m, options); }
00115 ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const;
00116 ex to_rational(exmap & repl) const;
00117 ex to_polynomial(exmap & repl) const;
00118 numeric integer_content() const;
00119 ex smod(const numeric &xi) const;
00120 numeric max_coefficient() const;
00121 ex conjugate() const;
00122 ex real_part() const;
00123 ex imag_part() const;
00125 void archive(archive_node& n) const;
00127 void read_archive(const archive_node& n, lst& syms);
00128 protected:
00131 ex derivative(const symbol &s) const { return 0; }
00132 bool is_equal_same_type(const basic &other) const;
00133 unsigned calchash() const;
00134
00135
00136
00137
00138
00139 public:
00140 const numeric add(const numeric &other) const;
00141 const numeric sub(const numeric &other) const;
00142 const numeric mul(const numeric &other) const;
00143 const numeric div(const numeric &other) const;
00144 const numeric power(const numeric &other) const;
00145 const numeric & add_dyn(const numeric &other) const;
00146 const numeric & sub_dyn(const numeric &other) const;
00147 const numeric & mul_dyn(const numeric &other) const;
00148 const numeric & div_dyn(const numeric &other) const;
00149 const numeric & power_dyn(const numeric &other) const;
00150 const numeric & operator=(int i);
00151 const numeric & operator=(unsigned int i);
00152 const numeric & operator=(long i);
00153 const numeric & operator=(unsigned long i);
00154 const numeric & operator=(double d);
00155 const numeric & operator=(const char *s);
00156 const numeric inverse() const;
00157 numeric step() const;
00158 int csgn() const;
00159 int compare(const numeric &other) const;
00160 bool is_equal(const numeric &other) const;
00161 bool is_zero() const;
00162 bool is_positive() const;
00163 bool is_negative() const;
00164 bool is_integer() const;
00165 bool is_pos_integer() const;
00166 bool is_nonneg_integer() const;
00167 bool is_even() const;
00168 bool is_odd() const;
00169 bool is_prime() const;
00170 bool is_rational() const;
00171 bool is_real() const;
00172 bool is_cinteger() const;
00173 bool is_crational() const;
00174 bool operator==(const numeric &other) const;
00175 bool operator!=(const numeric &other) const;
00176 bool operator<(const numeric &other) const;
00177 bool operator<=(const numeric &other) const;
00178 bool operator>(const numeric &other) const;
00179 bool operator>=(const numeric &other) const;
00180 int to_int() const;
00181 long to_long() const;
00182 double to_double() const;
00183 cln::cl_N to_cl_N() const;
00184 const numeric real() const;
00185 const numeric imag() const;
00186 const numeric numer() const;
00187 const numeric denom() const;
00188 int int_length() const;
00189
00190 explicit numeric(const cln::cl_N &z);
00191
00192 protected:
00193 void print_numeric(const print_context & c, const char *par_open, const char *par_close, const char *imag_sym, const char *mul_sym, unsigned level) const;
00194 void do_print(const print_context & c, unsigned level) const;
00195 void do_print_latex(const print_latex & c, unsigned level) const;
00196 void do_print_csrc(const print_csrc & c, unsigned level) const;
00197 void do_print_csrc_cl_N(const print_csrc_cl_N & c, unsigned level) const;
00198 void do_print_tree(const print_tree & c, unsigned level) const;
00199 void do_print_python_repr(const print_python_repr & c, unsigned level) const;
00200
00201
00202
00203 protected:
00204 cln::cl_N value;
00205 };
00206 GINAC_DECLARE_UNARCHIVER(numeric);
00207
00208
00209
00210
00211 extern const numeric I;
00212 extern _numeric_digits Digits;
00213
00214
00215
00216 const numeric exp(const numeric &x);
00217 const numeric log(const numeric &x);
00218 const numeric sin(const numeric &x);
00219 const numeric cos(const numeric &x);
00220 const numeric tan(const numeric &x);
00221 const numeric asin(const numeric &x);
00222 const numeric acos(const numeric &x);
00223 const numeric atan(const numeric &x);
00224 const numeric atan(const numeric &y, const numeric &x);
00225 const numeric sinh(const numeric &x);
00226 const numeric cosh(const numeric &x);
00227 const numeric tanh(const numeric &x);
00228 const numeric asinh(const numeric &x);
00229 const numeric acosh(const numeric &x);
00230 const numeric atanh(const numeric &x);
00231 const numeric Li2(const numeric &x);
00232 const numeric zeta(const numeric &x);
00233 const numeric lgamma(const numeric &x);
00234 const numeric tgamma(const numeric &x);
00235 const numeric psi(const numeric &x);
00236 const numeric psi(const numeric &n, const numeric &x);
00237 const numeric factorial(const numeric &n);
00238 const numeric doublefactorial(const numeric &n);
00239 const numeric binomial(const numeric &n, const numeric &k);
00240 const numeric bernoulli(const numeric &n);
00241 const numeric fibonacci(const numeric &n);
00242 const numeric isqrt(const numeric &x);
00243 const numeric sqrt(const numeric &x);
00244 const numeric abs(const numeric &x);
00245 const numeric mod(const numeric &a, const numeric &b);
00246 const numeric smod(const numeric &a, const numeric &b);
00247 const numeric irem(const numeric &a, const numeric &b);
00248 const numeric irem(const numeric &a, const numeric &b, numeric &q);
00249 const numeric iquo(const numeric &a, const numeric &b);
00250 const numeric iquo(const numeric &a, const numeric &b, numeric &r);
00251 const numeric gcd(const numeric &a, const numeric &b);
00252 const numeric lcm(const numeric &a, const numeric &b);
00253
00254
00255 inline const numeric pow(const numeric &x, const numeric &y)
00256 { return x.power(y); }
00257
00258 inline const numeric inverse(const numeric &x)
00259 { return x.inverse(); }
00260
00261 inline numeric step(const numeric &x)
00262 { return x.step(); }
00263
00264 inline int csgn(const numeric &x)
00265 { return x.csgn(); }
00266
00267 inline bool is_zero(const numeric &x)
00268 { return x.is_zero(); }
00269
00270 inline bool is_positive(const numeric &x)
00271 { return x.is_positive(); }
00272
00273 inline bool is_negative(const numeric &x)
00274 { return x.is_negative(); }
00275
00276 inline bool is_integer(const numeric &x)
00277 { return x.is_integer(); }
00278
00279 inline bool is_pos_integer(const numeric &x)
00280 { return x.is_pos_integer(); }
00281
00282 inline bool is_nonneg_integer(const numeric &x)
00283 { return x.is_nonneg_integer(); }
00284
00285 inline bool is_even(const numeric &x)
00286 { return x.is_even(); }
00287
00288 inline bool is_odd(const numeric &x)
00289 { return x.is_odd(); }
00290
00291 inline bool is_prime(const numeric &x)
00292 { return x.is_prime(); }
00293
00294 inline bool is_rational(const numeric &x)
00295 { return x.is_rational(); }
00296
00297 inline bool is_real(const numeric &x)
00298 { return x.is_real(); }
00299
00300 inline bool is_cinteger(const numeric &x)
00301 { return x.is_cinteger(); }
00302
00303 inline bool is_crational(const numeric &x)
00304 { return x.is_crational(); }
00305
00306 inline int to_int(const numeric &x)
00307 { return x.to_int(); }
00308
00309 inline long to_long(const numeric &x)
00310 { return x.to_long(); }
00311
00312 inline double to_double(const numeric &x)
00313 { return x.to_double(); }
00314
00315 inline const numeric real(const numeric &x)
00316 { return x.real(); }
00317
00318 inline const numeric imag(const numeric &x)
00319 { return x.imag(); }
00320
00321 inline const numeric numer(const numeric &x)
00322 { return x.numer(); }
00323
00324 inline const numeric denom(const numeric &x)
00325 { return x.denom(); }
00326
00327
00328
00329 ex PiEvalf();
00330 ex EulerEvalf();
00331 ex CatalanEvalf();
00332
00333
00334 }
00335
00336 #ifdef __MAKECINT__
00337 #pragma link off defined_in cln/number.h;
00338 #pragma link off defined_in cln/complex_class.h;
00339 #endif
00340
00341 #endif // ndef GINAC_NUMERIC_H