synaps/usolve/Sturm.h

00001 #ifndef _synaps_solve_Sturm_h_
00002 #define _synaps_solve_Sturm_h_
00003 
00004 #include <synaps/init.h>
00005 #include <synaps/arithm/Interval.h>
00006 #include <synaps/arithm/traits.h>
00007 #include <synaps/upol/UPolDse.h>
00008 #include <synaps/usolve/Small_degree.h>
00009 #include <synaps/usolve/sturm/common.h>
00010 #include <synaps/usolve/sturm/solve_sturm.h>
00011 
00012 __BEGIN_NAMESPACE_SYNAPS
00013 
00014 
00015 template < class NT >
00016 struct Sturm : public Small_degree<NT>
00017 {
00018     typedef Sturm          self_t;
00019 };
00020 
00021 
00024 template < class NT > inline
00025 Seq< typename Sturm<NT>::RO_t > 
00026 solve( const typename Sturm<NT>::Poly& f,
00027        Sturm<NT>)
00028 {
00029     typedef Sturm<NT>          K;
00030     typedef typename K::RO_t          RO_t;
00031     
00032     Seq<RO_t> sol;
00033    
00034     ALGEBRAIC::solve_sturm(f, std::back_inserter(sol.rep()), K());
00035 
00036     std::stable_sort( sol.begin(), sol.end(), ALGEBRAIC::Refine_compare());
00037     return sol;
00038 }
00039 
00040 
00041 template < class NT,
00042            class OutputIterator> inline
00043 OutputIterator
00044 solve( const typename Sturm<NT>::Poly& f,
00045        OutputIterator it,
00046        Sturm<NT>)
00047 {
00048     typedef Sturm<NT>          K;
00049 
00050     return ALGEBRAIC::solve_sturm(f, it, K());
00051 }
00052 
00053 
00054 
00055 template < class NT >  inline
00056 typename Sturm<NT>::RO_t 
00057 RootOf( const typename Sturm<NT>::Poly& f, unsigned i, Sturm<NT>)
00058 {
00059    typedef Sturm<NT>          K;
00060    return solve( f, K())[i];
00061 }
00062 
00063 
00064 
00065 template < class NT > inline
00066 int
00067 Count_real_roots( const typename Sturm<NT>::Poly& f, Sturm<NT>)
00068 {
00069     typedef Sturm<NT>          K;
00070     typedef typename K::RT            RT;
00071     typedef typename K::FT            FT;
00072     typedef typename K::FIT           FIT;
00073 
00074     SturmSeq<RT> sth( f, UPOLDAR::diff(f), SUBRES());
00075     FT b = Bound( f, Cauchy());
00076     FT a = -b;
00077 
00078     return ( Var( sth, a) - Var( sth, b) );
00079 }
00080 
00081 
00082 __END_NAMESPACE_SYNAPS
00083 
00084 #endif // _SYNAPS_SOLVE_STURM_H_
00085 

SYNAPS DOCUMENTATION
logo