実行結果
Depth=0 Norm=1.0093 e0=1.0093 e1=0.0000
→ 干渉 Norm=1.0309 e0=1.0309 e1=0.0000
[通常の子]
Depth=1 Norm=1.0308 e0=1.0302 e1=0.0000
→ 干渉 Norm=1.0307 e0=1.0307 e1=0.0000
[通常の子]
Depth=2 Norm=1.0244 e0=1.0162 e1=0.1077
→ 干渉 Norm=0.9468 e0=0.9468 e1=0.0000
[通常の子]
Depth=3 Norm=0.9498 e0=0.8883 e1=0.3196
→ 干渉 Norm=0.6774 e0=0.6774 e1=0.0000
[通常の子]
Depth=4 Norm=0.8027 e0=0.5329 e1=0.5868
→ 干渉 Norm=0.1305 e0=0.1305 e1=0.0000
[通常の子]
Depth=5 Norm=1.1149 e0=0.1305 e1=1.0935
[共役の子]
Depth=5 Norm=1.1149 e0=0.1305 e1=-1.0935
[共役の子]
Depth=4 Norm=1.0178 e0=0.8219 e1=-0.5868
→ 干渉 Norm=1.0939 e0=1.0939 e1=0.0000
[通常の子]
Depth=5 Norm=1.1405 e0=1.0939 e1=-0.2969
[共役の子]
Depth=5 Norm=1.1405 e0=1.0939 e1=0.2969
[共役の子]
Depth=3 Norm=1.0601 e0=1.0054 e1=-0.3196
→ 干渉 Norm=1.0676 e0=1.0676 e1=0.0000
[通常の子]
Depth=4 Norm=1.0686 e0=1.0664 e1=0.0092
→ 干渉 Norm=0.9481 e0=0.9481 e1=0.0000
[通常の子]
Depth=5 Norm=1.1475 e0=0.9481 e1=0.6383
[共役の子]
Depth=5 Norm=1.1475 e0=0.9481 e1=-0.6383
[共役の子]
Depth=4 Norm=1.0710 e0=1.0688 e1=-0.0092
→ 干渉 Norm=0.9559 e0=0.9559 e1=0.0000
[通常の子]
Depth=5 Norm=1.1477 e0=0.9559 e1=0.6233
[共役の子]
Depth=5 Norm=1.1477 e0=0.9559 e1=-0.6233
[共役の子]
Depth=2 Norm=1.0531 e0=1.0452 e1=-0.1077
→ 干渉 Norm=1.0434 e0=1.0434 e1=0.0000
[通常の子]
Depth=3 Norm=1.0309 e0=1.0241 e1=0.1132
→ 干渉 Norm=0.8941 e0=0.8941 e1=0.0000
[通常の子]
Depth=4 Norm=0.9000 e0=0.7897 e1=0.4296
→ 干渉 Norm=0.4529 e0=0.4529 e1=0.0000
[通常の子]
Depth=5 Norm=1.1323 e0=0.4529 e1=1.0313
[共役の子]
Depth=5 Norm=1.1323 e0=0.4529 e1=-1.0313
[共役の子]
Depth=4 Norm=1.0878 e0=0.9985 e1=-0.4296
→ 干渉 Norm=1.1489 e0=1.1489 e1=0.0000
[通常の子]
Depth=5 Norm=1.1506 e0=1.1489 e1=0.0235
[共役の子]
Depth=5 Norm=1.1506 e0=1.1489 e1=-0.0235
[共役の子]
Depth=3 Norm=1.0695 e0=1.0628 e1=-0.1132
→ 干渉 Norm=1.0234 e0=1.0234 e1=0.0000
[通常の子]
Depth=4 Norm=0.9958 e0=0.9671 e1=0.2279
→ 干渉 Norm=0.7257 e0=0.7257 e1=0.0000
[通常の子]
Depth=5 Norm=1.1431 e0=0.7257 e1=0.8758
[共役の子]
Depth=5 Norm=1.1431 e0=0.7257 e1=-0.8758
[共役の子]
Depth=4 Norm=1.1055 e0=1.0797 e1=-0.2279
→ 干渉 Norm=1.1013 e0=1.1013 e1=0.0000
[通常の子]
Depth=5 Norm=1.1529 e0=1.1013 e1=0.3331
[共役の子]
Depth=5 Norm=1.1529 e0=1.1013 e1=-0.3331
[共役の子]
Depth=1 Norm=1.0323 e0=1.0317 e1=0.0000
→ 干渉 Norm=1.0356 e0=1.0356 e1=0.0000
[通常の子]
Depth=2 Norm=1.0282 e0=1.0225 e1=0.1077
→ 干渉 Norm=0.9561 e0=0.9561 e1=0.0000
[通常の子]
Depth=3 Norm=0.9549 e0=0.8988 e1=0.3201
→ 干渉 Norm=0.6896 e0=0.6896 e1=0.0000
[通常の子]
Depth=4 Norm=0.8061 e0=0.5456 e1=0.5887
→ 干渉 Norm=0.1427 e0=0.1427 e1=0.0000
[通常の子]
Depth=5 Norm=1.1160 e0=0.1427 e1=1.0991
[共役の子]
Depth=5 Norm=1.1160 e0=0.1427 e1=-1.0991
[共役の子]
Depth=4 Norm=1.0233 e0=0.8337 e1=-0.5887
→ 干渉 Norm=1.1030 e0=1.1030 e1=0.0000
[通常の子]
Depth=5 Norm=1.1415 e0=1.1030 e1=-0.2879
[共役の子]
Depth=5 Norm=1.1415 e0=1.1030 e1=0.2879
[共役の子]
Depth=3 Norm=1.0636 e0=1.0135 e1=-0.3201
→ 干渉 Norm=1.0720 e0=1.0720 e1=0.0000
[通常の子]
Depth=4 Norm=1.0690 e0=1.0689 e1=0.0132
→ 干渉 Norm=0.9455 e0=0.9455 e1=0.0000
[通常の子]
Depth=5 Norm=1.1480 e0=0.9455 e1=0.6495
[共役の子]
Depth=5 Norm=1.1480 e0=0.9455 e1=-0.6495
[共役の子]
Depth=4 Norm=1.0752 e0=1.0750 e1=-0.0132
→ 干渉 Norm=0.9661 e0=0.9661 e1=0.0000
[通常の子]
Depth=5 Norm=1.1485 e0=0.9661 e1=0.6172
[共役の子]
Depth=5 Norm=1.1485 e0=0.9661 e1=-0.6172
[共役の子]
Depth=2 Norm=1.0542 e0=1.0486 e1=-0.1077
→ 干渉 Norm=1.0433 e0=1.0433 e1=0.0000
[通常の子]
Depth=3 Norm=1.0294 e0=1.0223 e1=0.1147
→ 干渉 Norm=0.8888 e0=0.8888 e1=0.0000
[通常の子]
Depth=4 Norm=0.8967 e0=0.7827 e1=0.4325
→ 干渉 Norm=0.4428 e0=0.4428 e1=0.0000
[通常の子]
Depth=5 Norm=1.1320 e0=0.4428 e1=1.0355
[共役の子]
Depth=5 Norm=1.1320 e0=0.4428 e1=-1.0355
[共役の子]
Depth=4 Norm=1.0868 e0=0.9948 e1=-0.4325
→ 干渉 Norm=1.1497 e0=1.1497 e1=0.0000
[通常の子]
Depth=5 Norm=1.1506 e0=1.1497 e1=0.0130
[共役の子]
Depth=5 Norm=1.1506 e0=1.1497 e1=-0.0130
[共役の子]
Depth=3 Norm=1.0710 e0=1.0642 e1=-0.1147
→ 干渉 Norm=1.0284 e0=1.0284 e1=0.0000
[通常の子]
Depth=4 Norm=0.9996 e0=0.9738 e1=0.2249
→ 干渉 Norm=0.7357 e0=0.7357 e1=0.0000
[通常の子]
Depth=5 Norm=1.1437 e0=0.7357 e1=0.8713
[共役の子]
Depth=5 Norm=1.1437 e0=0.7357 e1=-0.8713
[共役の子]
Depth=4 Norm=1.1064 e0=1.0831 e1=-0.2249
→ 干渉 Norm=1.1002 e0=1.1002 e1=0.0000
[通常の子]
Depth=5 Norm=1.1532 e0=1.1002 e1=0.3436
[共役の子]
Depth=5 Norm=1.1532 e0=1.1002 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; // 共役の子(追加)
Octonion interference; // 干渉結果を保持するメンバーを追加
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), interference(Octonion()) {}
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);
// ===== 干渉計算 =====
interference = (child->value + childConj->value) * 0.5;
// ===== 親へのフィードバック(ここが追加) =====
// 干渉結果を親のvalueに少し混ぜる(フィードバック強度は調整可能)
double feedbackStrength = 0.3; // 0.1?0.5くらいで試すと良い
value = value * (1.0 – feedbackStrength) + interference * feedbackStrength;
}
void RecursiveOcto::Dump(TMemo* memo)
{
if (!memo) return;
Octonion conj = value.PhaseConjugate();
memo->Lines->Add(Format(“Depth=%d Norm=%.4f e0=%.4f e1=%.4f”,
ARRAYOFCONST((depth, value.Norm(), value.e[0], value.e[1]))));
// 干渉結果を表示(子がある場合)
if (child && childConj) {
memo->Lines->Add(Format(” → 干渉 Norm=%.4f e0=%.4f e1=%.4f”,
ARRAYOFCONST((interference.Norm(), interference.e[0], interference.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;
}
//—————————————————————————