File: app_sturmsequence.cpp

package info (click to toggle)
gfan 0.5%2Bdfsg-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,296 kB
  • ctags: 5,612
  • sloc: cpp: 39,675; makefile: 453; sh: 1
file content (72 lines) | stat: -rw-r--r-- 1,819 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "dimension.h"
#include "printer.h"
#include "parser.h"
#include "gfanapplication.h"
#include "division.h"
#include "field_rationals.h"

class SturmSequenceApplication : public GFanApplication
{
  SimpleOption evaluateOption;
public:
  bool includeInDefaultInstallation()
  {
    return false;
  }
  const char *helpText()
  {
    return "Given a polynomial this program computes the Sturm sequence of polynomials as defined in Sturm's Theorem.\n";
  }
  SturmSequenceApplication():
    evaluateOption("-e","Evaluate the sequence in a set of points given in a vector. (Only integer vectors are supported at the moment).")
  {
    registerOptions();
  }
  const char *name()
  {
    return "_sturmsequence";
  }
  int main()
  {
    FileParser P(Stdin);
    Polynomial f1=P.parsePolynomialWithRing();

    Polynomial f2=f1.derivative();

    PolynomialRing theRing=f1.getRing();
    PolynomialSet result(theRing);
    result.push_back(f1);
    while(!f2.isZero())
      {
	result.push_back(f2);
	PolynomialSet g(theRing);
	Polynomial temp=f2;
	g.push_back(f2);
	g.markAndScale(LexicographicTermOrder());
	f2=(f1-f1)-division(f1,g,LexicographicTermOrder());
	f1=temp;
      }
    AsciiPrinter(Stdout).printPolynomialSet(result);

    if(evaluateOption.getValue())
      {
	IntegerVector v=P.parseIntegerVector();
	for(int i=0;i<v.size();i++)
	  {
	    FieldElement x=Q.zHomomorphism(v[i]);
	    AsciiPrinter(Stdout).printString("Evaluating in ");
	    AsciiPrinter(Stdout).printFieldElement(x);
	    AsciiPrinter(Stdout).printNewLine();
	    for(PolynomialSet::const_iterator j=result.begin();j!=result.end();j++)
	      {
		AsciiPrinter(Stdout).printFieldElement(j->evaluate(x));
		AsciiPrinter(Stdout).printNewLine();
	      }
	  }
      }

    return 0;
  }
};

static SturmSequenceApplication theApplication;