実行結果
Depth=0 Norm=1.0000 e0=1.0000 e1=0.0000 conj_e1=0.0000
[通常の子]
Depth=1 Norm=1.0312 e0=1.0300 e1=0.0000 conj_e1=0.0000
[通常の子]
Depth=2 Norm=1.0620 e0=1.0459 e1=0.1539 conj_e1=-0.1539
[通常の子]
Depth=3 Norm=1.0902 e0=0.9787 e1=0.4565 conj_e1=-0.4565
[通常の子]
Depth=4 Norm=1.1104 e0=0.7054 e1=0.8382 conj_e1=-0.8382
[通常の子]
Depth=5 Norm=1.1149 e0=0.1305 e1=1.0935 conj_e1=-1.0935
[共役の子]
Depth=5 Norm=1.1149 e0=0.1305 e1=-1.0935 conj_e1=1.0935
[共役の子]
Depth=4 Norm=1.1104 e0=0.7054 e1=-0.8382 conj_e1=0.8382
[通常の子]
Depth=5 Norm=1.1405 e0=1.0939 e1=-0.2969 conj_e1=0.2969
[共役の子]
Depth=5 Norm=1.1405 e0=1.0939 e1=0.2969 conj_e1=-0.2969
[共役の子]
Depth=3 Norm=1.0902 e0=0.9787 e1=-0.4565 conj_e1=0.4565
[通常の子]
Depth=4 Norm=1.1215 e0=1.1171 e1=0.0132 conj_e1=-0.0132
[通常の子]
Depth=5 Norm=1.1475 e0=0.9481 e1=0.6383 conj_e1=-0.6383
[共役の子]
Depth=5 Norm=1.1475 e0=0.9481 e1=-0.6383 conj_e1=0.6383
[共役の子]
Depth=4 Norm=1.1215 e0=1.1171 e1=-0.0132 conj_e1=0.0132
[通常の子]
Depth=5 Norm=1.1477 e0=0.9559 e1=0.6233 conj_e1=-0.6233
[共役の子]
Depth=5 Norm=1.1477 e0=0.9559 e1=-0.6233 conj_e1=0.6233
[共役の子]
Depth=2 Norm=1.0620 e0=1.0459 e1=-0.1539 conj_e1=0.1539
[通常の子]
Depth=3 Norm=1.0930 e0=1.0798 e1=0.1617 conj_e1=-0.1617
[通常の子]
Depth=4 Norm=1.1193 e0=0.9340 e1=0.6138 conj_e1=-0.6138
[通常の子]
Depth=5 Norm=1.1323 e0=0.4529 e1=1.0313 conj_e1=-1.0313
[共役の子]
Depth=5 Norm=1.1323 e0=0.4529 e1=-1.0313 conj_e1=1.0313
[共役の子]
Depth=4 Norm=1.1193 e0=0.9340 e1=-0.6138 conj_e1=0.6138
[通常の子]
Depth=5 Norm=1.1506 e0=1.1489 e1=0.0235 conj_e1=-0.0235
[共役の子]
Depth=5 Norm=1.1506 e0=1.1489 e1=-0.0235 conj_e1=0.0235
[共役の子]
Depth=3 Norm=1.0930 e0=1.0798 e1=-0.1617 conj_e1=0.1617
[通常の子]
Depth=4 Norm=1.1229 e0=1.0705 e1=0.3255 conj_e1=-0.3255
[通常の子]
Depth=5 Norm=1.1431 e0=0.7257 e1=0.8758 conj_e1=-0.8758
[共役の子]
Depth=5 Norm=1.1431 e0=0.7257 e1=-0.8758 conj_e1=0.8758
[共役の子]
Depth=4 Norm=1.1229 e0=1.0705 e1=-0.3255 conj_e1=0.3255
[通常の子]
Depth=5 Norm=1.1529 e0=1.1013 e1=0.3331 conj_e1=-0.3331
[共役の子]
Depth=5 Norm=1.1529 e0=1.1013 e1=-0.3331 conj_e1=0.3331
[共役の子]
Depth=1 Norm=1.0312 e0=1.0300 e1=0.0000 conj_e1=0.0000
[通常の子]
Depth=2 Norm=1.0622 e0=1.0509 e1=0.1539 conj_e1=-0.1539
[通常の子]
Depth=3 Norm=1.0906 e0=0.9884 e1=0.4572 conj_e1=-0.4572
[通常の子]
Depth=4 Norm=1.1111 e0=0.7183 e1=0.8409 conj_e1=-0.8409
[通常の子]
Depth=5 Norm=1.1160 e0=0.1427 e1=1.0991 conj_e1=-1.0991
[共役の子]
Depth=5 Norm=1.1160 e0=0.1427 e1=-1.0991 conj_e1=1.0991
[共役の子]
Depth=4 Norm=1.1111 e0=0.7183 e1=-0.8409 conj_e1=0.8409
[通常の子]
Depth=5 Norm=1.1415 e0=1.1030 e1=-0.2879 conj_e1=0.2879
[共役の子]
Depth=5 Norm=1.1415 e0=1.1030 e1=0.2879 conj_e1=-0.2879
[共役の子]
Depth=3 Norm=1.0906 e0=0.9884 e1=-0.4572 conj_e1=0.4572
[通常の子]
Depth=4 Norm=1.1220 e0=1.1217 e1=0.0189 conj_e1=-0.0189
[通常の子]
Depth=5 Norm=1.1480 e0=0.9455 e1=0.6495 conj_e1=-0.6495
[共役の子]
Depth=5 Norm=1.1480 e0=0.9455 e1=-0.6495 conj_e1=0.6495
[共役の子]
Depth=4 Norm=1.1220 e0=1.1217 e1=-0.0189 conj_e1=0.0189
[通常の子]
Depth=5 Norm=1.1485 e0=0.9661 e1=0.6172 conj_e1=-0.6172
[共役の子]
Depth=5 Norm=1.1485 e0=0.9661 e1=-0.6172 conj_e1=0.6172
[共役の子]
Depth=2 Norm=1.0622 e0=1.0509 e1=-0.1539 conj_e1=0.1539
[通常の子]
Depth=3 Norm=1.0931 e0=1.0796 e1=0.1639 conj_e1=-0.1639
[通常の子]
Depth=4 Norm=1.1192 e0=0.9284 e1=0.6179 conj_e1=-0.6179
[通常の子]
Depth=5 Norm=1.1320 e0=0.4428 e1=1.0355 conj_e1=-1.0355
[共役の子]
Depth=5 Norm=1.1320 e0=0.4428 e1=-1.0355 conj_e1=1.0355
[共役の子]
Depth=4 Norm=1.1192 e0=0.9284 e1=-0.6179 conj_e1=0.6179
[通常の子]
Depth=5 Norm=1.1506 e0=1.1497 e1=0.0130 conj_e1=-0.0130
[共役の子]
Depth=5 Norm=1.1506 e0=1.1497 e1=-0.0130 conj_e1=0.0130
[共役の子]
Depth=3 Norm=1.0931 e0=1.0796 e1=-0.1639 conj_e1=0.1639
[通常の子]
Depth=4 Norm=1.1232 e0=1.0758 e1=0.3213 conj_e1=-0.3213
[通常の子]
Depth=5 Norm=1.1437 e0=0.7357 e1=0.8713 conj_e1=-0.8713
[共役の子]
Depth=5 Norm=1.1437 e0=0.7357 e1=-0.8713 conj_e1=0.8713
[共役の子]
Depth=4 Norm=1.1232 e0=1.0758 e1=-0.3213 conj_e1=0.3213
[通常の子]
Depth=5 Norm=1.1532 e0=1.1002 e1=0.3436 conj_e1=-0.3436
[共役の子]
Depth=5 Norm=1.1532 e0=1.1002 e1=-0.3436 conj_e1=0.3436
C++Builder2007 ソースコード
//************************
//**** Unit1.h ***********
//************************
//—————————————————————————
#ifndef Unit1H
#define Unit1H
//—————————————————————————
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//—————————————————————————
struct Octonion {
double e[8];
Octonion(double a0=0.0, double a1=0.0, double a2=0.0, double a3=0.0,
double a4=0.0, double a5=0.0, double a6=0.0, double a7=0.0);
Octonion operator+(const Octonion& o) const;
Octonion operator*(const Octonion& o) const; // ← 変更:完全乗算
Octonion operator*(double scalar) const; // スカラー乗算は残す
double Norm() const;
Octonion Conjugate() const; // 標準的な共役
Octonion PhaseConjugate() const; // 位相共役用(必要に応じて拡張可能)
};
class RecursiveOcto {
public:
int depth;
Octonion value;
RecursiveOcto* child; // 通常の子
RecursiveOcto* childConj; // 共役の子(追加)
RecursiveOcto(int d, Octonion init);
~RecursiveOcto();
void Generate(int maxDepth);
void Dump(TMemo* memo);
};
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *ButtonExit;
TButton *Button1;
TMemo *Memo1;
void __fastcall ButtonExitClick(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//—————————————————————————
extern PACKAGE TForm1 *Form1;
//—————————————————————————
#endif
//************************
//**** Unit1.cpp *********
//************************
//—————————————————————————
#include <vcl.h>
#pragma hdrstop
#include <math.h>
#include “Unit1.h”
//—————————————————————————
#pragma package(smart_init)
#pragma resource “*.dfm”
TForm1 *Form1;
//—————————————————————————
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//—————————————————————————
void __fastcall TForm1::ButtonExitClick(TObject *Sender)
{
Close();
}
//—————————————————————————
//—————————————————————————
Octonion::Octonion(double a0, double a1, double a2, double a3,
double a4, double a5, double a6, double a7) {
e[0]=a0; e[1]=a1; e[2]=a2; e[3]=a3;
e[4]=a4; e[5]=a5; e[6]=a6; e[7]=a7;
}
Octonion Octonion::Conjugate() const {
return Octonion(
e[0],
-e[1], -e[2], -e[3], -e[4], -e[5], -e[6], -e[7]
);
}
Octonion Octonion::PhaseConjugate() const {
return Conjugate();
}
Octonion Octonion::operator+(const Octonion& o) const {
Octonion res;
for(int i=0; i<8; i++) res.e[i] = e[i] + o.e[i];
return res;
}
RecursiveOcto::RecursiveOcto(int d, Octonion init)
: depth(d), value(init), child(NULL), childConj(NULL) {}
RecursiveOcto::~RecursiveOcto() {
delete child;
delete childConj;
}
// スカラー乗算は残す
Octonion Octonion::operator*(double scalar) const {
Octonion res;
for(int i=0; i<8; i++) res.e[i] = e[i] * scalar;
return res;
}
// 完全な八元数乗算
Octonion Octonion::operator*(const Octonion& o) const {
Octonion res;
// e0(実部)
res.e[0] = e[0]*o.e[0] – e[1]*o.e[1] – e[2]*o.e[2] – e[3]*o.e[3]
– e[4]*o.e[4] – e[5]*o.e[5] – e[6]*o.e[6] – e[7]*o.e[7];
// e1
res.e[1] = e[0]*o.e[1] + e[1]*o.e[0] + e[2]*o.e[3] – e[3]*o.e[2]
+ e[4]*o.e[5] – e[5]*o.e[4] – e[6]*o.e[7] + e[7]*o.e[6];
// e2
res.e[2] = e[0]*o.e[2] – e[1]*o.e[3] + e[2]*o.e[0] + e[3]*o.e[1]
+ e[4]*o.e[6] + e[5]*o.e[7] – e[6]*o.e[4] – e[7]*o.e[5];
// e3
res.e[3] = e[0]*o.e[3] + e[1]*o.e[2] – e[2]*o.e[1] + e[3]*o.e[0]
+ e[4]*o.e[7] – e[5]*o.e[6] + e[6]*o.e[5] – e[7]*o.e[4];
// e4
res.e[4] = e[0]*o.e[4] – e[1]*o.e[5] – e[2]*o.e[6] – e[3]*o.e[7]
+ e[4]*o.e[0] + e[5]*o.e[1] + e[6]*o.e[2] + e[7]*o.e[3];
// e5
res.e[5] = e[0]*o.e[5] + e[1]*o.e[4] – e[2]*o.e[7] + e[3]*o.e[6]
– e[4]*o.e[1] + e[5]*o.e[0] – e[6]*o.e[3] + e[7]*o.e[2];
// e6
res.e[6] = e[0]*o.e[6] + e[1]*o.e[7] + e[2]*o.e[4] – e[3]*o.e[5]
– e[4]*o.e[2] + e[5]*o.e[3] + e[6]*o.e[0] – e[7]*o.e[1];
// e7
res.e[7] = e[0]*o.e[7] – e[1]*o.e[6] + e[2]*o.e[5] + e[3]*o.e[4]
– e[4]*o.e[3] – e[5]*o.e[2] + e[6]*o.e[1] + e[7]*o.e[0];
return res;
}
double Octonion::Norm() const {
double sum = 0.0;
for(int i=0; i<8; i++) sum += e[i]*e[i];
return sqrt(sum);
}
void RecursiveOcto::Generate(int maxDepth) {
if (depth >= maxDepth) return;
// 通常の次ステップ
Octonion rotator(cos(depth * 0.15), sin(depth * 0.15), 0.05, 0, 0, 0, 0, 0);
Octonion next = value * rotator;
next = next + Octonion(0.03, 0, 0, 0, 0, 0, 0, 0);
// 共役版
Octonion nextConj = next.PhaseConjugate();
// 通常の子を生成
child = new RecursiveOcto(depth + 1, next);
child->Generate(maxDepth);
// 共役の子を生成
childConj = new RecursiveOcto(depth + 1, nextConj);
childConj->Generate(maxDepth);
}
void RecursiveOcto::Dump(TMemo* memo)
{
if (!memo) return;
Octonion conj = value.PhaseConjugate();
memo->Lines->Add(Format(“Depth=%d Norm=%.4f e0=%.4f e1=%.4f conj_e1=%.4f”,
ARRAYOFCONST((depth, value.Norm(), value.e[0], value.e[1], conj.e[1]))));
// 子も表示(通常)
if (child) {
memo->Lines->Add(” [通常の子]”);
child->Dump(memo);
}
// 子も表示(共役)
if (childConj) {
memo->Lines->Add(” [共役の子]”);
childConj->Dump(memo);
}
}
//—————————————————————————
//—————————————————————————
void __fastcall TForm1::Button1Click(TObject *Sender)
{
RecursiveOcto* root = new RecursiveOcto(0, Octonion(1.0));
root->Generate(5); // ← 2分岐なので深さは浅めに(5?6推奨)
Memo1->Clear();
root->Dump(Memo1);
delete root;
}
//—————————————————————————