和の公式

 投稿者:しばっち  投稿日:2019年10月13日(日)19時22分2秒
  MathMLを使用してWebブラウザー上で数式を美麗に表示します。

https://it-engineer-lab.com/archives/825
https://it-engineer-lab.com/archives/1000


実行するとhtmlファイルを書き出しますので
Webブラウザー上にD&Dしてください。
(又はhtmlファイルをダブルクリック)

現在最新のOpera ver64,Chrome ver77,Fire fox ver69,Vivaldi ver 2.7にて動作確認しています。


和の公式をWebブラウザー上で表示させます。
https://decimalbasic.ninja-web.net/log/article/b/basic/104/shyvwm/shyvwm.html


OPTION BASE 0
OPTION ARITHMETIC RATIONAL
PUBLIC NUMERIC MAXLEVEL
LET MAXLEVEL=50
DIM X(MAXLEVEL+1)
OPEN #1:NAME "和の公式.html"
ERASE #1
PRINT #1:"<!DOCTYPE html>"
PRINT #1:"<html>"
PRINT #1:"<head>"
PRINT #1:"    <title>和の公式</title>"
PRINT #1:"    <script async src=";CHR$(34);"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML";CHR$(34);"></script>"
PRINT #1:"</head>"
PRINT #1:"<body>"
PRINT #1:"<h1>和の公式</h1>"
LET X(1)=1
FOR K=1 TO MAXLEVEL
   CALL SHORTMUL(X,K)
   CALL INTEGRAL(X)
   LET S=1
   FOR I=MAXLEVEL TO 2 STEP-1
      LET S=S-X(I)
   NEXT I
   LET X(1)=S
   PRINT #1:"<math>"
   PRINT #1:"    <munderover>"
   PRINT #1:"        <mi>∑</mi>"
   PRINT #1:"        <mrow>"
   PRINT #1:"        <mi>k</mi>"
   PRINT #1:"            <mo>=</mo>"
   PRINT #1:"            <mn>1</mn>"
   PRINT #1:"        </mrow>"
   PRINT #1:"        <mi>n</mi>"
   PRINT #1:"    </munderover>"
   PRINT #1:"    <msup>"
   PRINT #1:"        <mi>k</mi>"
   IF K>1 THEN PRINT #1:"        <mn>";STR$(K);"</mn>"
   PRINT #1:"    </msup>"
   PRINT #1:"<mo>=</mo>"
   CALL DISPLAY(X,#1)
   PRINT #1:"</math>"
   PRINT #1:CHR$(60);CHR$(98);CHR$(114);CHR$(62)
NEXT K
PRINT #1:"</body>"
PRINT #1:"</html>"
CLOSE #1
END

EXTERNAL SUB INTEGRAL(A())
OPTION ARITHMETIC RATIONAL
OPTION BASE 0
DIM B(MAXLEVEL)
FOR I=MAXLEVEL-1 TO 0 STEP-1
   LET B(I+1)=A(I)/(I+1)
NEXT I
CALL COPY(A,B)
END SUB

EXTERNAL FUNCTION DIMCHECK(X())
OPTION ARITHMETIC RATIONAL
FOR N=MAXLEVEL TO 0 STEP -1
   IF X(N)<>0 THEN EXIT FOR
NEXT N
LET DIMCHECK=N
END FUNCTION

EXTERNAL SUB DISPLAY(A(),#1)
OPTION ARITHMETIC RATIONAL
LET N=DIMCHECK(A)
IF N>1 THEN
   IF A(N)<0 THEN PRINT #1:"<mo>-</mo>"
   IF ABS(A(N))<>1 THEN
      IF ABS(DENOM(A(N)))=1 THEN
         PRINT #1:"    <mn>";STR$(ABS(A(N)));"</mn>"
      ELSE
         PRINT #1:"<mfrac>"
         PRINT #1:"    <mn>";STR$(ABS(NUMER(A(N))));"</mn>"
         PRINT #1:"    <mn>";STR$(ABS(DENOM(A(N))));"</mn>"
         PRINT #1:"</mfrac>"
      END IF
      PRINT #1:"<msup>"
      PRINT #1:"    <mi>n</mi>"
      PRINT #1:"    <mn>";STR$(N);"</mn>"
      PRINT #1:"</msup>"
   ELSE
      IF ABS(DENOM(A(N)))=1 THEN
         PRINT #1:"    <mn>";STR$(ABS(A(N)));"</mn>"
      ELSE
         PRINT #1:"<mfrac>"
         PRINT #1:"    <mn>";STR$(ABS(NUMER(A(N))));"</mn>"
         PRINT #1:"    <mn>";STR$(ABS(DENOM(A(N))));"</mn>"
         PRINT #1:"</mfrac>"
      END IF
      PRINT #1:"<msup>"
      PRINT #1:"    <mi>n</mi>"
      PRINT #1:"</msup>"
   END IF
END IF
FOR I=N-1 TO 2 STEP-1
   IF A(I)<>0 THEN
      IF A(I)<0 THEN PRINT #1:"<mo>-</mo>" ELSE PRINT #1:"<mo>+</mo>"
      IF ABS(A(I))<>1 THEN
         IF ABS(DENOM(A(I)))=1 THEN
            PRINT #1:"    <mn>";STR$(ABS(A(I)));"</mn>"
         ELSE
            PRINT #1:"<mfrac>"
            PRINT #1:"    <mn>";STR$(ABS(NUMER(A(I))));"</mn>"
            PRINT #1:"    <mn>";STR$(ABS(DENOM(A(I))));"</mn>"
            PRINT #1:"</mfrac>"
         END IF
         PRINT #1:"<msup>"
         PRINT #1:"    <mi>n</mi>"
         PRINT #1:"    <mn>";STR$(I);"</mn>"
         PRINT #1:"</msup>"
      ELSEIF ABS(A(I))=1 THEN
         PRINT #1:"<msup>"
         PRINT #1:"    <mi>n</mi>"
         PRINT #1:"    <mn>";STR$(I);"</mn>"
         PRINT #1:"</msup>"
      END IF
   END IF
NEXT I
IF A(1)<>0 THEN
   IF N>1 THEN
      IF A(1)<0 THEN PRINT #1:"<mo>-</mo>" ELSE PRINT #1:"<mo>+</mo>"
   END IF
   IF ABS(A(1))<>1 THEN
      IF ABS(DENOM(A(1)))=1 THEN
         PRINT #1:"    <mn>";STR$(ABS(A(1)));"</mn>"
      ELSE
         PRINT #1:"<mfrac>"
         PRINT #1:"    <mn>";STR$(ABS(NUMER(A(1))));"</mn>"
         PRINT #1:"    <mn>";STR$(ABS(DENOM(A(1))));"</mn>"
         PRINT #1:"</mfrac>"
      END IF
      PRINT #1:"<mi>n</mi>"
   ELSEIF ABS(A(1))=1 THEN
      PRINT #1:"<mi>n</mi>"
   END IF
END IF
IF A(0)<>0 THEN
   IF A(0)<0 THEN PRINT #1:"<mo>-</mo>" ELSE PRINT #1:"<mo>+</mo>"
   IF ABS(DENOM(A(0)))=1 THEN
      PRINT #1:"    <mn>";STR$(ABS(A(0)));"</mn>"
   ELSE
      PRINT #1:"<mfrac>"
      PRINT #1:"    <mn>";STR$(ABS(NUMER(A(0))));"</mn>"
      PRINT #1:"    <mn>";STR$(ABS(DENOM(A(0))));"</mn>"
      PRINT #1:"</mfrac>"
   END IF
END IF
END SUB

EXTERNAL SUB COPY(X(),Y())
OPTION ARITHMETIC RATIONAL
MAT X=Y
END SUB

EXTERNAL SUB SHORTMUL(X(),S)
OPTION ARITHMETIC RATIONAL
MAT X=(S)*X
END SUB
 

戻る