最小多項式

 投稿者:しばっち  投稿日:2014年11月26日(水)18時09分28秒
  DECLARE EXTERNAL FUNCTION COMB
OPTION BASE 0
DIM X(8),T(8)
!'最小多項式
!'(x-(a+b+c))(x-(a+b-c))(x-(a-b+c))(x-(a-b-c))(x-(-a+b+c))(x-(-a+b-c))(x-(-a-b+c))(x-(-a-b-c))
!'(x-a)(x-b)=x^2-(a+b)x+ab
!'(x-a)(x-b)(x-c)=x^3-(a+b+c)x^2+(ab+bc+ca)x-abc
!'(x-a)(x-b)(x-c)(x-d)=x^4-(a+b+c+d)x^3+(ab+ac+ad+bc+bd+cd)x^2-(abc+abd+bcd+acd)x+abcd
LET A=SQR(2)
LET B=SQR(3)
LET C=SQR(5)
FOR I=1 TO -1 STEP -2
   FOR J=1 TO -1 STEP -2
      FOR K=1 TO -1 STEP -2
         LET N=N+1
         LET X(N)=I*A+J*B+K*C
         PRINT "(X";SIGN$(-X(N));")";
      NEXT  K
   NEXT J
NEXT I
PRINT
FOR I=N TO 0 STEP-1
   LET K=(-1)^(N-I)*COMB(X,N,N-I,T,1)
   IF ABS(K)<1E-6 THEN LET K=0
   IF ABS(FP(K))<1E-6 THEN LET K=SGN(K)*INT(ABS(K))
   IF I=1 THEN
      PRINT SIGN$(K);"*X";
   ELSEIF I=N THEN
      PRINT "X^";STR$(I);
   ELSEIF I>0 THEN
      IF K<>0 THEN PRINT SIGN$(K);"*X^";STR$(I);
   ELSE
      PRINT SIGN$(K)
   END IF
NEXT I
END

EXTERNAL FUNCTION SIGN$(X)
IF ABS(X)=1 THEN
   IF X<0 THEN LET SIGN$="-" ELSE LET SIGN$=""
ELSE
   IF X<0 THEN LET SIGN$="-"&STR$(ABS(X)) ELSE LET SIGN$="+"&STR$(X)
END IF
END FUNCTION

EXTERNAL FUNCTION COMB(X(),N,R,A(),K)
IF R=0 THEN
   LET S=1
   FOR I=1 TO N
      IF A(I)=1 THEN LET S=S*X(I)
   NEXT I
   LET COMB=S
ELSE
   FOR I=K TO N-R+1
      LET A(I)=1
      LET SS=SS+COMB(X,N,R-1,A,I+1)
      LET A(I)=0
   NEXT I
   LET COMB=SS
END IF
END FUNCTION
 

戻る