File: theight.cc

package info (click to toggle)
eclib 20190909-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,196 kB
  • sloc: cpp: 47,090; makefile: 251; sh: 122
file content (175 lines) | stat: -rw-r--r-- 5,785 bytes parent folder | download
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// THEIGHT.CC -- test of height procedures
//////////////////////////////////////////////////////////////////////////
//
// Copyright 1990-2012 John Cremona
// 
// This file is part of the eclib package.
// 
// eclib is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// 
// eclib is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// 
// You should have received a copy of the GNU General Public License
// along with eclib; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
// 
//////////////////////////////////////////////////////////////////////////
//

#include <eclib/points.h>

int main(){
#ifdef MPFP
  set_precision(350);
#endif
  initprimes("PRIMES",1);
  Curve E;

  while (cout<<"Input a curve: ", cin>>E, !E.isnull())
  {
    Curvedata C(E, 0);
    cout<<"Curve "<< C <<endl;
    vector<bigint> badp = getbad_primes(C);

    Point P(C);

    while 
      (
       cout<<"Input a point on curve, [0] to finish:\n",
       cin >> P,
       !(!cin)&& P.isvalid()
       )
        {       
          cout << "Point " << P;
          int ord = order(P); 
          if(ord>0)cout<< " has order " << ord; 
          else     cout<< " has infinite order";
          cout << endl;

          cout << "Local heights:\n";
          bigfloat gh = to_bigfloat(0);
	  bigint d = gcd(P.getZ(),P.getX());
          vector<bigint> pdivsz=pdivs(d);
	  vector<bigint>::iterator qvar = pdivsz.begin();
	  while(qvar!=pdivsz.end())
            {
              bigint q = *qvar++;
	      cout << q << ":\t\t"  << flush;
	      bigfloat ph = pheight(P,q);
	      gh+=ph;
	      cout << ph << endl;
            }
	  cout << "Sum so far =\t" << gh << endl;
	  bigfloat lxd = 2*log(I2bigfloat(d));
	  cout << "log(den(x(P))) = " << lxd << endl;
	  vector<bigint>::iterator pvar = badp.begin();
	  while(pvar!=badp.end())
            {
              bigint pr = *pvar++;
	      if(div(pr,d)) continue;
              cout << pr << ":\t\t"  << flush;
              bigfloat  ph = pheight(P,pr);
              gh+=ph;
              cout << ph << endl;
            }
	  cout << "Sum so far =\t" << gh << endl;
          bigfloat rh = realheight(P);
          cout << "R:\t\t" << rh << endl;
	  gh += rh;
          cout << "\nSum of local heights: " << gh << endl;
//
// N.B. The call to height() calls realheight() and pheight() again,
//      since as height() was not called earlier, P's height field was 
//      not set.
//
          cout<<"global height of "<<P<<" is "<<height(P)<<endl;
//
        } // end point loop
  }       // end curve loop
  //  exit(0);
// Some tests borrowed from OM's test program:
  E = Curve(BIGINT(0), BIGINT(0), BIGINT(1), BIGINT(-7), BIGINT(6));  
  Curvedata C(E);
  cout << "\n\nTesting points on the curve " << E << endl;
  Point P0(C, BIGINT(0),BIGINT(2));
  Point P1(C, BIGINT(1),BIGINT(0));
  Point P2(C, BIGINT(2),BIGINT(0));
  cout << "The points are P0 = " << P0 << 
    ", P1 = " << P1 << ", and P2 = " << P2 << endl;
  if (!P0.isvalid()) cout << "P0 is not on the curve!\n";
  if (!P1.isvalid()) cout << "P1 is not on the curve!\n";
  if (!P2.isvalid()) cout << "P2 is not on the curve!\n";
  cout << "Their negatives are -P0 = " << -P0 << 
    ", -P1 = " << -P1 << ", and -P2 = " << -P2 << endl;
        
  cout << "Computing their heights:\n";
  bigfloat ht0 = height(P0);
  bigfloat ht1 = height(P1);
  bigfloat ht2 = height(P2);

  cout << "Heights are " << ht0 << ", " << ht1 << ", and " << ht2 << endl;
        
  Point origin(C);
  cout << "The origin is " << origin << endl;
  cout << "Now some additions etc,:\n";
  Point sum = P0 + P1;
  cout << "P0 + P1 = " << sum << endl;
  sum = P0 - P1;
  cout << "P0 - P1 = " << sum << endl;
  sum -= P2;
  cout << "P0 - P1 - P2 = " << sum << endl;
  sum = P0.twice();
  cout << "P0.twice() = " << sum << endl;
  sum = P0 + P0;
  cout << "P0 + P0 = " << sum << endl;
  sum = 3*P0;
  cout << "3*P0 = " << sum << endl;
  sum = P0 - P0;
  cout << "P0 - P0 = " << sum << endl;
  sum = P0 + 3 * P1 - P2;
  cout << "P0 +3 P1 - P2 = " << sum << endl;
  sum = 2*P0 + 2* P1 + P2;
  cout << "2P0 +2 P1 + P2 = " << sum << endl;
  /*
  cout << "Now we try a systematic exploration" << endl;
  Point Q; int i0,i1,i2;
  int k=3;
  for(i0 = -k; i0 <= k; i0++){
    for(i1 = -k; i1 <= k; i1++){
      for(i2 = -k; i2 <= k; i2++){
	Q = i0*P0+i1*P1+i2*P2;
        cout << i0 << ", " << i1 <<", " << i2<< ": " << Q << endl;
      }
    }
  }
  */
  sum = P0 -P1 -P2;
  bigfloat htsum = height(sum);
  cout << "P0 -P1 -P2 = " << sum << "\n\t with height " << htsum<<endl;

  Point doublesum = 2 * sum;
  bigfloat ht2sum = height(doublesum);
  cout << "2 (P0 -P1 -P2) = " << doublesum << "\n\t with height " << ht2sum << endl;
  cout << "The quotient is " << ht2sum/htsum << endl;

  Point triplesum = 3 * sum;
  bigfloat ht3sum = height(triplesum);
  cout << "3 (P0 -P1 -P2) = " << triplesum << "\n\t with height " << ht3sum << endl;
  cout << "The quotient is " << ht3sum/htsum << endl;
        
  vector<Point> pointlist(3);
  pointlist[0] = P0; pointlist[1] = P1; pointlist[2] = P2;
//cout << "Making a PointArray out of P0, P1, P2.  It is " << pointlist << endl;
//cout << "Calling regulator" << endl;
  bigfloat reg = regulator(pointlist);
//cout << "Back from calling regulator" << endl;
  cout << "The regulator of P0, P1, P2 is " << reg << endl;      
  return 0;
  }         // end main()