From d66ad4d3c9f73b32b01a82d4a433497c6ad77cdb Mon Sep 17 00:00:00 2001 From: irrevion Date: Sat, 25 Nov 2023 02:26:05 +0400 Subject: [PATCH] comply composer --- .gitignore | 2 + README.md | 2 + composer.json | 23 + .../irrevion/science => dev}/autoloader.php | 0 {lab => dev/use-cases}/test_complex.php | 254 ++-- {lab => dev/use-cases}/test_complexpolar.php | 706 ++++++------ {lab => dev/use-cases}/test_fraction.php | 318 ++--- {lab => dev/use-cases}/test_imaginary.php | 68 +- {lab => dev/use-cases}/test_math.php | 340 +++--- {lab => dev/use-cases}/test_matrix.php | 0 {lab => dev/use-cases}/test_physics.php | 0 .../use-cases}/test_physics_electron.php | 0 {lab => dev/use-cases}/test_scalar.php | 160 +-- {lab => dev/use-cases}/test_vector.php | 468 ++++---- .../science => src}/Geometry/Shapes/Shape.php | 32 +- .../Math/Branches/BaseMath.php | 546 ++++----- .../Math/Branches/LinearAlgebra.php | 0 .../Math/Branches/MathAnalysis.php | 0 .../Math/Branches/Statistics.php | 0 .../science => src}/Math/Entities/Complex.php | 410 +++---- .../Math/Entities/ComplexPolar.php | 448 ++++---- .../science => src}/Math/Entities/Entity.php | 0 .../Math/Entities/Fraction.php | 0 .../Math/Entities/Imaginary.php | 0 .../science => src}/Math/Entities/Scalar.php | 0 .../science => src}/Math/Entities/Vector.php | 1020 ++++++++--------- .../irrevion/science => src}/Math/Math.php | 176 +-- .../Math/Operations/Delegator.php | 152 +-- .../Math/Transformations/Matrix.php | 0 .../Math/Transformations/Transformation.php | 0 .../science => src}/Physics/Branches/Mech.php | 0 .../science => src}/Physics/Branches/QCD.php | 0 .../science => src}/Physics/Branches/QED.php | 0 .../science => src}/Physics/Branches/QFT.php | 0 .../Physics/Branches/Quantum.php | 0 .../Physics/Branches/Relativity.php | 30 +- .../Physics/Entities/Particles/Electron.php | 48 +- .../Physics/Entities/Quantity.php | 78 +- .../science => src}/Physics/Physics.php | 0 .../science => src}/Physics/Unit/CGS.php | 36 +- .../Physics/Unit/Categories.php | 0 .../Physics/Unit/Entities/AbAmpere.php | 0 .../Physics/Unit/Entities/Ampere.php | 0 .../Physics/Unit/Entities/Angle.php | 0 .../Unit/Entities/AstronomicalUnit.php | 0 .../Physics/Unit/Entities/Brightness.php | 0 .../Physics/Unit/Entities/CGS.php | 0 .../Physics/Unit/Entities/Candela.php | 0 .../Physics/Unit/Entities/Celsius.php | 0 .../Physics/Unit/Entities/Degree.php | 0 .../Physics/Unit/Entities/ElectricCurrent.php | 0 .../Physics/Unit/Entities/ElectricTension.php | 0 .../Physics/Unit/Entities/ElectronMass.php | 0 .../Physics/Unit/Entities/ElectronVolt.php | 2 +- .../Physics/Unit/Entities/Energy.php | 0 .../Physics/Unit/Entities/Fahrenheit.php | 0 .../Physics/Unit/Entities/IAU.php | 0 .../Physics/Unit/Entities/Imperial.php | 0 .../Physics/Unit/Entities/Joule.php | 0 .../Physics/Unit/Entities/Kelvin.php | 0 .../Physics/Unit/Entities/Kilogram.php | 0 .../Physics/Unit/Entities/Length.php | 0 .../Physics/Unit/Entities/LightYear.php | 0 .../Unit/Entities/LuminousIntensity.php | 0 .../Physics/Unit/Entities/Mass.php | 0 .../Physics/Unit/Entities/Metre.php | 0 .../Physics/Unit/Entities/Mole.php | 0 .../Physics/Unit/Entities/Nit.php | 0 .../Physics/Unit/Entities/NonStandard.php | 0 .../Physics/Unit/Entities/Parsec.php | 0 .../Physics/Unit/Entities/Planck.php | 0 .../Physics/Unit/Entities/PlanckLength.php | 0 .../Physics/Unit/Entities/PlanckTime.php | 0 .../Physics/Unit/Entities/Pound.php | 0 .../Physics/Unit/Entities/Radian.php | 0 .../Physics/Unit/Entities/Rankine.php | 0 .../Physics/Unit/Entities/SI.php | 0 .../Physics/Unit/Entities/Second.php | 0 .../Physics/Unit/Entities/SolarMass.php | 0 .../Physics/Unit/Entities/StatAmpere.php | 0 .../Physics/Unit/Entities/StatVolt.php | 0 .../Physics/Unit/Entities/Stilb.php | 0 .../Physics/Unit/Entities/SubstanceAmount.php | 0 .../Physics/Unit/Entities/Temperature.php | 0 .../Physics/Unit/Entities/Time.php | 0 .../Physics/Unit/Entities/USC.php | 0 .../Physics/Unit/Entities/UnitInterface.php | 0 .../Physics/Unit/Entities/Volt.php | 0 .../Physics/Unit/Entities/Year.php | 0 .../science => src}/Physics/Unit/IAU.php | 40 +- .../science => src}/Physics/Unit/Imperial.php | 30 +- .../science => src}/Physics/Unit/Natural.php | 0 .../Physics/Unit/NonStandard.php | 0 .../science => src}/Physics/Unit/Planck.php | 0 .../science => src}/Physics/Unit/SI.php | 0 .../Physics/Unit/SystemInterface.php | 12 +- .../science => src}/Physics/Unit/Systems.php | 0 .../science => src}/Physics/Unit/USC.php | 30 +- 98 files changed, 2727 insertions(+), 2704 deletions(-) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 composer.json rename {vendor/irrevion/science => dev}/autoloader.php (100%) rename {lab => dev/use-cases}/test_complex.php (95%) rename {lab => dev/use-cases}/test_complexpolar.php (95%) rename {lab => dev/use-cases}/test_fraction.php (95%) rename {lab => dev/use-cases}/test_imaginary.php (56%) rename {lab => dev/use-cases}/test_math.php (95%) rename {lab => dev/use-cases}/test_matrix.php (100%) rename {lab => dev/use-cases}/test_physics.php (100%) rename {lab => dev/use-cases}/test_physics_electron.php (100%) rename {lab => dev/use-cases}/test_scalar.php (94%) rename {lab => dev/use-cases}/test_vector.php (96%) rename {vendor/irrevion/science => src}/Geometry/Shapes/Shape.php (97%) rename {vendor/irrevion/science => src}/Math/Branches/BaseMath.php (95%) rename {vendor/irrevion/science => src}/Math/Branches/LinearAlgebra.php (100%) rename {vendor/irrevion/science => src}/Math/Branches/MathAnalysis.php (100%) rename {vendor/irrevion/science => src}/Math/Branches/Statistics.php (100%) rename {vendor/irrevion/science => src}/Math/Entities/Complex.php (96%) rename {vendor/irrevion/science => src}/Math/Entities/ComplexPolar.php (97%) rename {vendor/irrevion/science => src}/Math/Entities/Entity.php (100%) rename {vendor/irrevion/science => src}/Math/Entities/Fraction.php (100%) rename {vendor/irrevion/science => src}/Math/Entities/Imaginary.php (100%) rename {vendor/irrevion/science => src}/Math/Entities/Scalar.php (100%) rename {vendor/irrevion/science => src}/Math/Entities/Vector.php (96%) rename {vendor/irrevion/science => src}/Math/Math.php (96%) rename {vendor/irrevion/science => src}/Math/Operations/Delegator.php (97%) rename {vendor/irrevion/science => src}/Math/Transformations/Matrix.php (100%) rename {vendor/irrevion/science => src}/Math/Transformations/Transformation.php (100%) rename {vendor/irrevion/science => src}/Physics/Branches/Mech.php (100%) rename {vendor/irrevion/science => src}/Physics/Branches/QCD.php (100%) rename {vendor/irrevion/science => src}/Physics/Branches/QED.php (100%) rename {vendor/irrevion/science => src}/Physics/Branches/QFT.php (100%) rename {vendor/irrevion/science => src}/Physics/Branches/Quantum.php (100%) rename {vendor/irrevion/science => src}/Physics/Branches/Relativity.php (97%) rename {vendor/irrevion/science => src}/Physics/Entities/Particles/Electron.php (98%) rename {vendor/irrevion/science => src}/Physics/Entities/Quantity.php (95%) rename {vendor/irrevion/science => src}/Physics/Physics.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/CGS.php (96%) rename {vendor/irrevion/science => src}/Physics/Unit/Categories.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/AbAmpere.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Ampere.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Angle.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/AstronomicalUnit.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Brightness.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/CGS.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Candela.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Celsius.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Degree.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/ElectricCurrent.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/ElectricTension.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/ElectronMass.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/ElectronVolt.php (96%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Energy.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Fahrenheit.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/IAU.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Imperial.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Joule.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Kelvin.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Kilogram.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Length.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/LightYear.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/LuminousIntensity.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Mass.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Metre.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Mole.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Nit.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/NonStandard.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Parsec.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Planck.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/PlanckLength.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/PlanckTime.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Pound.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Radian.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Rankine.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/SI.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Second.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/SolarMass.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/StatAmpere.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/StatVolt.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Stilb.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/SubstanceAmount.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Temperature.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Time.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/USC.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/UnitInterface.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Volt.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Entities/Year.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/IAU.php (96%) rename {vendor/irrevion/science => src}/Physics/Unit/Imperial.php (95%) rename {vendor/irrevion/science => src}/Physics/Unit/Natural.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/NonStandard.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/Planck.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/SI.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/SystemInterface.php (94%) rename {vendor/irrevion/science => src}/Physics/Unit/Systems.php (100%) rename {vendor/irrevion/science => src}/Physics/Unit/USC.php (95%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a1419d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.trash/ +/vendor/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a427fb --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# science +PHP library for extended mathematical operations diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..94f6e06 --- /dev/null +++ b/composer.json @@ -0,0 +1,23 @@ +{ + "name": "irrevion/science", + "description": "PHP library for extended mathematical operations", + "type": "library", + "version": "0.0.1", + "license": "MIT", + "homepage": "https://github.com/irrevion/science/", + "autoload": { + "psr-4": { + "irrevion\\science\\": "src/" + } + }, + "authors": [ + { + "name": "Valentin Belousov", + "email": "irrevion@gmail.com" + } + ], + "minimum-stability": "dev", + "require": { + "php": ">=8", + }, +} diff --git a/vendor/irrevion/science/autoloader.php b/dev/autoloader.php similarity index 100% rename from vendor/irrevion/science/autoloader.php rename to dev/autoloader.php diff --git a/lab/test_complex.php b/dev/use-cases/test_complex.php similarity index 95% rename from lab/test_complex.php rename to dev/use-cases/test_complex.php index 66b782e..a500de5 100644 --- a/lab/test_complex.php +++ b/dev/use-cases/test_complex.php @@ -1,127 +1,127 @@ - - -
-real}, imaginary is {$x->imaginary}\n");
-print("Type of x is ".($x::class)."\n");
-unset($x);
-?>
-
-
-
-
-
-add($y);
-print("{$x} + {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-add($y);
-print("{$x} + {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-invert();
-$y = $x->negative();
-print("{$x} inverted is {$y} === {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-subtract($y);
-print("{$x} - {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-subtract($y);
-print("{$x} - {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-negative();
-$z1 = $x->abs();
-$z2 = $y->abs();
-print("{$x} and {$y} absolutes is {$z1} and {$z2}\n");
-print("Type of z1 is ".($z1::class)."\n");
-unset($x, $y, $z1, $z2);
-?>
-
-multiply($y);
-print("{$x} * {$y} is {$z}\n");
-print("Type of z is ".Delegator::getType($z)."\n");
-unset($x, $y, $z);
-?>
-
-divide($y);
-print("{$x} / {$y} is {$z}\n");
-print("Type of z is ".Delegator::getType($z)."\n");
-unset($x, $y, $z);
-?>
-
-divide($y);
-print("{$x} / {$y} is {$z}\n");
-print("Type of z is ".Delegator::getType($z)."\n");
-unset($x, $y, $z);
-?>
-
-divide($y);
-print("{$x} / {$y} is {$z}\n");
-print("Type of z is ".Delegator::getType($z)."\n");
-unset($x, $y, $z);
-?>
-
+ + +
+real}, imaginary is {$x->imaginary}\n");
+print("Type of x is ".($x::class)."\n");
+unset($x);
+?>
+
+
+
+
+
+add($y);
+print("{$x} + {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+add($y);
+print("{$x} + {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+invert();
+$y = $x->negative();
+print("{$x} inverted is {$y} === {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+subtract($y);
+print("{$x} - {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+subtract($y);
+print("{$x} - {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+negative();
+$z1 = $x->abs();
+$z2 = $y->abs();
+print("{$x} and {$y} absolutes is {$z1} and {$z2}\n");
+print("Type of z1 is ".($z1::class)."\n");
+unset($x, $y, $z1, $z2);
+?>
+
+multiply($y);
+print("{$x} * {$y} is {$z}\n");
+print("Type of z is ".Delegator::getType($z)."\n");
+unset($x, $y, $z);
+?>
+
+divide($y);
+print("{$x} / {$y} is {$z}\n");
+print("Type of z is ".Delegator::getType($z)."\n");
+unset($x, $y, $z);
+?>
+
+divide($y);
+print("{$x} / {$y} is {$z}\n");
+print("Type of z is ".Delegator::getType($z)."\n");
+unset($x, $y, $z);
+?>
+
+divide($y);
+print("{$x} / {$y} is {$z}\n");
+print("Type of z is ".Delegator::getType($z)."\n");
+unset($x, $y, $z);
+?>
+
diff --git a/lab/test_complexpolar.php b/dev/use-cases/test_complexpolar.php similarity index 95% rename from lab/test_complexpolar.php rename to dev/use-cases/test_complexpolar.php index 6d68ff6..220a6ed 100644 --- a/lab/test_complexpolar.php +++ b/dev/use-cases/test_complexpolar.php @@ -1,353 +1,353 @@ - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-toPolar();
-print("{$x} ".($x::class)." became {$y} ".($y::class)."\n");
-unset($x, $y);
-?>
-
-add($y);
-print "$x + $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->add($b);
-print "$a + $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i + $j = $k (".$c::class.")\n";
-?>
-
-add($y);
-print "$x + $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->add($b);
-print "$a + $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i + $j = $k (".$c::class.")\n";
-?>
-
-add($y);
-print "$x + $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->add($b);
-print "$a + $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i + $j = $k (".$c::class.")\n";
-?>
-
-add($y);
-print "$x + $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->add($b);
-print "$a + $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i + $j = $k (".$c::class.")\n";
-?>
-
-add($y);
-print "$x + $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->add($b);
-print "$a + $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i + $j = $k (".$c::class.")\n";
-?>
-
-add($y);
-print "$x + $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->add($b);
-print "$a + $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i + $j = $k (".$c::class.")\n";
-?>
-
-add($y);
-print "$x + $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->add($b);
-print "$a + $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i + $j = $k (".$c::class.")\n";
-?>
-
-subtract($y);
-print "$x - $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->subtract($b);
-print "$a - $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i - $j = $k (".$c::class.")\n";
-?>
-
-subtract($y);
-print "$x - $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->subtract($b);
-print "$a - $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i - $j = $k (".$c::class.")\n";
-?>
-
-subtract($y);
-print "$x - $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->subtract($b);
-print "$a - $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i - $j = $k (".$c::class.")\n";
-?>
-
-multiply($y);
-print "$x * $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->multiply($b);
-print "$a * $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i * $j = $k (".$c::class.")\n";
-?>
-
-multiply($y);
-print "$x * $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->multiply($b);
-print "$a * $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i * $j = $k (".$c::class.")\n";
-?>
-
-multiply($y);
-print "$x * $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->multiply($b);
-print "$a * $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i * $j = $k (".$c::class.")\n";
-?>
-
-divide($y);
-print "$x / $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->divide($b);
-print "$a / $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i / $j = $k (".$c::class.")\n";
-?>
-
-divide($y);
-print "$x / $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->divide($b);
-print "$a / $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i / $j = $k (".$c::class.")\n";
-?>
-
-divide($y);
-print "$x / $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->divide($b);
-print "$a / $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i / $j = $k (".$c::class.")\n";
-?>
-
-divide($y);
-print "$x / $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->divide($b);
-print "$a / $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i / $j = $k (".$c::class.")\n";
-?>
-
-divide($y);
-print "$x / $y = $z (".$z::class.")\n";
-$a = $x->toPolar();
-$b = $y->toPolar();
-$c = $a->divide($b);
-print "$a / $b = $c (".$c::class.")\n";
-$i = $a->toRectangular();
-$j = $b->toRectangular();
-$k = $c->toRectangular();
-print "Restored as: $i / $j = $k (".$c::class.")\n";
-?>
-
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+toPolar();
+print("{$x} ".($x::class)." became {$y} ".($y::class)."\n");
+unset($x, $y);
+?>
+
+add($y);
+print "$x + $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->add($b);
+print "$a + $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i + $j = $k (".$c::class.")\n";
+?>
+
+add($y);
+print "$x + $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->add($b);
+print "$a + $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i + $j = $k (".$c::class.")\n";
+?>
+
+add($y);
+print "$x + $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->add($b);
+print "$a + $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i + $j = $k (".$c::class.")\n";
+?>
+
+add($y);
+print "$x + $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->add($b);
+print "$a + $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i + $j = $k (".$c::class.")\n";
+?>
+
+add($y);
+print "$x + $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->add($b);
+print "$a + $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i + $j = $k (".$c::class.")\n";
+?>
+
+add($y);
+print "$x + $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->add($b);
+print "$a + $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i + $j = $k (".$c::class.")\n";
+?>
+
+add($y);
+print "$x + $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->add($b);
+print "$a + $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i + $j = $k (".$c::class.")\n";
+?>
+
+subtract($y);
+print "$x - $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->subtract($b);
+print "$a - $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i - $j = $k (".$c::class.")\n";
+?>
+
+subtract($y);
+print "$x - $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->subtract($b);
+print "$a - $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i - $j = $k (".$c::class.")\n";
+?>
+
+subtract($y);
+print "$x - $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->subtract($b);
+print "$a - $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i - $j = $k (".$c::class.")\n";
+?>
+
+multiply($y);
+print "$x * $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->multiply($b);
+print "$a * $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i * $j = $k (".$c::class.")\n";
+?>
+
+multiply($y);
+print "$x * $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->multiply($b);
+print "$a * $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i * $j = $k (".$c::class.")\n";
+?>
+
+multiply($y);
+print "$x * $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->multiply($b);
+print "$a * $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i * $j = $k (".$c::class.")\n";
+?>
+
+divide($y);
+print "$x / $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->divide($b);
+print "$a / $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i / $j = $k (".$c::class.")\n";
+?>
+
+divide($y);
+print "$x / $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->divide($b);
+print "$a / $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i / $j = $k (".$c::class.")\n";
+?>
+
+divide($y);
+print "$x / $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->divide($b);
+print "$a / $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i / $j = $k (".$c::class.")\n";
+?>
+
+divide($y);
+print "$x / $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->divide($b);
+print "$a / $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i / $j = $k (".$c::class.")\n";
+?>
+
+divide($y);
+print "$x / $y = $z (".$z::class.")\n";
+$a = $x->toPolar();
+$b = $y->toPolar();
+$c = $a->divide($b);
+print "$a / $b = $c (".$c::class.")\n";
+$i = $a->toRectangular();
+$j = $b->toRectangular();
+$k = $c->toRectangular();
+print "Restored as: $i / $j = $k (".$c::class.")\n";
+?>
+
diff --git a/lab/test_fraction.php b/dev/use-cases/test_fraction.php similarity index 95% rename from lab/test_fraction.php rename to dev/use-cases/test_fraction.php index e8d8411..4e08f1e 100644 --- a/lab/test_fraction.php +++ b/dev/use-cases/test_fraction.php @@ -1,160 +1,160 @@ - - -
-
-
-
-
-
-
-
-
-getMessage()."\n";
-}
-?>
-
-getMessage()."\n";
-}
-?>
-
-getMessage()."\n";
-}
-?>
-
-add($y);
-print("{$x} + {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-subtract($y);
-print("{$x} - {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-negative();
-print("-72/123 ( {$x} ) negative is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $z);
-?>
-
-negative();
-print("15/-35 ( {$x} ) negative is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $z);
-?>
-
-negative();
-print("-21/-77 ( {$x} ) negative is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $z);
-?>
-
-reciprocal();
-print("22/-33 ( {$x} ) reciprocal is {$z}\n");
-$y = new Fraction("22/-33");
-print("22/-33 ( {$y} )\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $z);
-?>
-
-multiply($y);
-print("{$x} * {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-multiply($y);
-print("{$x} * {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-divide($y);
-print("{$x} / {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-divide($y);
-print("{$x} / {$y} is {$z} = ".$z->toNumber()."\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
+
+
+
+
+
+
+
+
+
+
+
+getMessage()."\n";
+}
+?>
+
+getMessage()."\n";
+}
+?>
+
+getMessage()."\n";
+}
+?>
+
+add($y);
+print("{$x} + {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+subtract($y);
+print("{$x} - {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+negative();
+print("-72/123 ( {$x} ) negative is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $z);
+?>
+
+negative();
+print("15/-35 ( {$x} ) negative is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $z);
+?>
+
+negative();
+print("-21/-77 ( {$x} ) negative is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $z);
+?>
+
+reciprocal();
+print("22/-33 ( {$x} ) reciprocal is {$z}\n");
+$y = new Fraction("22/-33");
+print("22/-33 ( {$y} )\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $z);
+?>
+
+multiply($y);
+print("{$x} * {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+multiply($y);
+print("{$x} * {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+divide($y);
+print("{$x} / {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+divide($y);
+print("{$x} / {$y} is {$z} = ".$z->toNumber()."\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
 
\ No newline at end of file diff --git a/lab/test_imaginary.php b/dev/use-cases/test_imaginary.php similarity index 56% rename from lab/test_imaginary.php rename to dev/use-cases/test_imaginary.php index e2f726c..2aac5e7 100644 --- a/lab/test_imaginary.php +++ b/dev/use-cases/test_imaginary.php @@ -1,36 +1,32 @@ - - -
-
-
-add($y);
-print("{$x} + {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-
-
+ + +
+
+
+add($y);
+print("{$x} + {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+
+
diff --git a/lab/test_math.php b/dev/use-cases/test_math.php similarity index 95% rename from lab/test_math.php rename to dev/use-cases/test_math.php index 9e4929b..6459687 100644 --- a/lab/test_math.php +++ b/dev/use-cases/test_math.php @@ -1,170 +1,170 @@ - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-add($y);
-print "{$z}\n";
-print("Type of z is ".($z::class)."\n");
-unset($x, $z);
-?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+add($y);
+print "{$z}\n";
+print("Type of z is ".($z::class)."\n");
+unset($x, $z);
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lab/test_matrix.php b/dev/use-cases/test_matrix.php similarity index 100% rename from lab/test_matrix.php rename to dev/use-cases/test_matrix.php diff --git a/lab/test_physics.php b/dev/use-cases/test_physics.php similarity index 100% rename from lab/test_physics.php rename to dev/use-cases/test_physics.php diff --git a/lab/test_physics_electron.php b/dev/use-cases/test_physics_electron.php similarity index 100% rename from lab/test_physics_electron.php rename to dev/use-cases/test_physics_electron.php diff --git a/lab/test_scalar.php b/dev/use-cases/test_scalar.php similarity index 94% rename from lab/test_scalar.php rename to dev/use-cases/test_scalar.php index f906baa..614058e 100644 --- a/lab/test_scalar.php +++ b/dev/use-cases/test_scalar.php @@ -1,80 +1,80 @@ - - -
-
-
-invert();
-print("Inverted x is {$x}\n");
-print("Type of x is ".($x::class)."\n");
-unset($x);
-?>
-
-multiply($y);
-print("{$x} * {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-multiply($y);
-print("{$x} * {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-divide($y);
-print("{$x} / {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-add($y);
-print("{$x} + {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-subtract($y);
-print("{$x} - {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
-multiply($y);
-print("{$x} * {$y} is {$z}\n");
-print("Type of z is ".($z::class)."\n");
-unset($x, $y, $z);
-?>
-
+ + +
+
+
+invert();
+print("Inverted x is {$x}\n");
+print("Type of x is ".($x::class)."\n");
+unset($x);
+?>
+
+multiply($y);
+print("{$x} * {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+multiply($y);
+print("{$x} * {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+divide($y);
+print("{$x} / {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+add($y);
+print("{$x} + {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+subtract($y);
+print("{$x} - {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
+multiply($y);
+print("{$x} * {$y} is {$z}\n");
+print("Type of z is ".($z::class)."\n");
+unset($x, $y, $z);
+?>
+
diff --git a/lab/test_vector.php b/dev/use-cases/test_vector.php similarity index 96% rename from lab/test_vector.php rename to dev/use-cases/test_vector.php index 0a48ba2..366219f 100644 --- a/lab/test_vector.php +++ b/dev/use-cases/test_vector.php @@ -1,234 +1,234 @@ - - -
-inner_type}\n");
-unset($x);
-?>
-
-inner_type}\n");
-$y = new Vector([7, 6, 5, 4, 3]);
-$z = $x->multiply($y);
-print("Type of z $z is ".($z::class)." of {$z->inner_type}\n");
-$u = $z->multiply(new Imaginary(-1));
-print("Type of u $u is ".($u::class)." of {$u->inner_type}\n");
-unset($x);
-?>
-
-inner_type}\n");
-	unset($x);
-} catch (\Error $e) {
-	print "Error: new Vector('kapusta') -> ".$e->getMessage()."\n";
-} */
-?>
-
-inner_type}\n");
-	unset($x);
-} catch (\Error $e) {
-	print "Error: new Vector(['k', 'a', 'p', 'u', 's', 't', 'a']) -> ".$e->getMessage()."\n";
-} */
-?>
-
-inner_type}\n");
-	var_dump($x->value);
-	unset($x);
-} catch (\Error $e) {
-	print "Error: new Vector(['k', 'a', 'p', 'u', 's', 't', 'a'], 'string') -> ".$e->getMessage()."\n";
-} */
-?>
-
-inner_type}\n");
-	var_dump($x->value);
-	unset($x);
-} catch (\Error $e) {
-	print "Error: new Vector(['k', 'a', 'p', 'u', 's', 't', 'a'], 'float') -> ".$e->getMessage()."\n";
-} catch (\ReflectionException $e) {
-	print "Error: new Vector(['k', 'a', 'p', 'u', 's', 't', 'a'], 'float') -> ".$e->getMessage()."\n";
-} */
-?>
-
-inner_type}\n");
-	var_dump($x->value);
-	unset($x);
-} catch (\Error $e) {
-	print "Error: new Vector([73, 82, 995], 'irrevion\science\Math\Entities\Complex') -> ".$e->getMessage()."\n";
-} catch (\ReflectionException $e) {
-	print "Error: new Vector([73, 82, 995], 'irrevion\science\Math\Entities\Complex') -> ".$e->getMessage()."\n";
-} */
-?>
-
-dotProduct($y);
-print "$x ∙ $y = $z (".$z::class.")\n";
-?>
-
-dotProduct($y);
-print "$x ∙ $y = $z (".$z::class.")\n";
-?>
-
-dotProduct($y);
-print "$x ∙ $y = $z (".$z::class.")\n";
-?>
-
- 2, 'imaginary' => -4],
-	['real' => 7, 'imaginary' => 5],
-], 'irrevion\science\Math\Entities\Complex');
-$y = new Vector([
-	['real' => 1, 'imaginary' => 3],
-	['real' => -2, 'imaginary' => 346.33],
-], 'irrevion\science\Math\Entities\Complex');
-$z = $x->dotProduct($y);
-print "$x ∙ $y = $z (".$z::class.")\n";
-?>
-
-dot($y);
-print "$x ∙ $y = $z (".$z::class.")\n";
-?>
-
-multiply($y);
-print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
-$z = $z->divide($y);
-print "/ $y = $z (type ".$z::class." of {$x->inner_type})\n";
-?>
-
-multiply($y);
-print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
-?>
-
-k($y);
-print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
-?>
-
-multiply($y);
-print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
-?>
-
-multiply($y);
-print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
-?>
-
-x($y);
-print "$x ⨯ $y = $z (type ".$z::class." of {$x->inner_type})\n";
-?>
-
-vectorProduct($y);
-print "$x ⨯ $y = $z (type ".$z::class." of {$x->inner_type})\n";
-?>
-
-vectorProduct($y);
-print "$x ⨯ $y = $z (type ".$z::class." of {$x->inner_type})\n";
-?>
-
-vectorProduct($y);
-print "$x ⨯ $y = $z (type ".$z::class." of {$x->inner_type})\n";
-?>
-
-vectorProduct($y);
-print "$x ⨯ $y = $z (type ".$z::class." of {$z->inner_type})\n";
-$z = $x->dot($y);
-print "$x ∙ $y = $z (type ".$z::class.")\n";
-$z = $x->multiplyElementwise($y);
-print "$x * $y = $z (type ".$z::class." of {$z->inner_type})\n";
-?>
-
-vectorProduct($y);
-print "$x ⨯ $y = $z (type ".$z::class." of {$z->inner_type})\n";
-$z = $x->dot($y);
-print "$x ∙ $y = $z (type ".$z::class.")\n";
-$z = $x->multiplyElementwise($y);
-print "$x * $y = $z (type ".$z::class." of {$z->inner_type})\n";
-print $x->magnitude()." * ".$y->magnitude()." = ".$z->magnitude()." (type ".$z::class." of {$z->inner_type})\n";
-?>
-
-magnitude();
-$z = $x->normalize();
-print "$x / $y = $z (type ".$z::class." of {$x->inner_type})\n";
-$x = $z->multiply($y);
-print "$z * $y = $x (type ".$z::class." of {$x->inner_type})\n";
-$x = $x->invert();
-print "$x\n";
-?>
-
+ + +
+inner_type}\n");
+unset($x);
+?>
+
+inner_type}\n");
+$y = new Vector([7, 6, 5, 4, 3]);
+$z = $x->multiply($y);
+print("Type of z $z is ".($z::class)." of {$z->inner_type}\n");
+$u = $z->multiply(new Imaginary(-1));
+print("Type of u $u is ".($u::class)." of {$u->inner_type}\n");
+unset($x);
+?>
+
+inner_type}\n");
+	unset($x);
+} catch (\Error $e) {
+	print "Error: new Vector('kapusta') -> ".$e->getMessage()."\n";
+} */
+?>
+
+inner_type}\n");
+	unset($x);
+} catch (\Error $e) {
+	print "Error: new Vector(['k', 'a', 'p', 'u', 's', 't', 'a']) -> ".$e->getMessage()."\n";
+} */
+?>
+
+inner_type}\n");
+	var_dump($x->value);
+	unset($x);
+} catch (\Error $e) {
+	print "Error: new Vector(['k', 'a', 'p', 'u', 's', 't', 'a'], 'string') -> ".$e->getMessage()."\n";
+} */
+?>
+
+inner_type}\n");
+	var_dump($x->value);
+	unset($x);
+} catch (\Error $e) {
+	print "Error: new Vector(['k', 'a', 'p', 'u', 's', 't', 'a'], 'float') -> ".$e->getMessage()."\n";
+} catch (\ReflectionException $e) {
+	print "Error: new Vector(['k', 'a', 'p', 'u', 's', 't', 'a'], 'float') -> ".$e->getMessage()."\n";
+} */
+?>
+
+inner_type}\n");
+	var_dump($x->value);
+	unset($x);
+} catch (\Error $e) {
+	print "Error: new Vector([73, 82, 995], 'irrevion\science\Math\Entities\Complex') -> ".$e->getMessage()."\n";
+} catch (\ReflectionException $e) {
+	print "Error: new Vector([73, 82, 995], 'irrevion\science\Math\Entities\Complex') -> ".$e->getMessage()."\n";
+} */
+?>
+
+dotProduct($y);
+print "$x ∙ $y = $z (".$z::class.")\n";
+?>
+
+dotProduct($y);
+print "$x ∙ $y = $z (".$z::class.")\n";
+?>
+
+dotProduct($y);
+print "$x ∙ $y = $z (".$z::class.")\n";
+?>
+
+ 2, 'imaginary' => -4],
+	['real' => 7, 'imaginary' => 5],
+], 'irrevion\science\Math\Entities\Complex');
+$y = new Vector([
+	['real' => 1, 'imaginary' => 3],
+	['real' => -2, 'imaginary' => 346.33],
+], 'irrevion\science\Math\Entities\Complex');
+$z = $x->dotProduct($y);
+print "$x ∙ $y = $z (".$z::class.")\n";
+?>
+
+dot($y);
+print "$x ∙ $y = $z (".$z::class.")\n";
+?>
+
+multiply($y);
+print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
+$z = $z->divide($y);
+print "/ $y = $z (type ".$z::class." of {$x->inner_type})\n";
+?>
+
+multiply($y);
+print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
+?>
+
+k($y);
+print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
+?>
+
+multiply($y);
+print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
+?>
+
+multiply($y);
+print "$x * $y = $z (type ".$z::class." of {$x->inner_type})\n";
+?>
+
+x($y);
+print "$x ⨯ $y = $z (type ".$z::class." of {$x->inner_type})\n";
+?>
+
+vectorProduct($y);
+print "$x ⨯ $y = $z (type ".$z::class." of {$x->inner_type})\n";
+?>
+
+vectorProduct($y);
+print "$x ⨯ $y = $z (type ".$z::class." of {$x->inner_type})\n";
+?>
+
+vectorProduct($y);
+print "$x ⨯ $y = $z (type ".$z::class." of {$x->inner_type})\n";
+?>
+
+vectorProduct($y);
+print "$x ⨯ $y = $z (type ".$z::class." of {$z->inner_type})\n";
+$z = $x->dot($y);
+print "$x ∙ $y = $z (type ".$z::class.")\n";
+$z = $x->multiplyElementwise($y);
+print "$x * $y = $z (type ".$z::class." of {$z->inner_type})\n";
+?>
+
+vectorProduct($y);
+print "$x ⨯ $y = $z (type ".$z::class." of {$z->inner_type})\n";
+$z = $x->dot($y);
+print "$x ∙ $y = $z (type ".$z::class.")\n";
+$z = $x->multiplyElementwise($y);
+print "$x * $y = $z (type ".$z::class." of {$z->inner_type})\n";
+print $x->magnitude()." * ".$y->magnitude()." = ".$z->magnitude()." (type ".$z::class." of {$z->inner_type})\n";
+?>
+
+magnitude();
+$z = $x->normalize();
+print "$x / $y = $z (type ".$z::class." of {$x->inner_type})\n";
+$x = $z->multiply($y);
+print "$z * $y = $x (type ".$z::class." of {$x->inner_type})\n";
+$x = $x->invert();
+print "$x\n";
+?>
+
diff --git a/vendor/irrevion/science/Geometry/Shapes/Shape.php b/src/Geometry/Shapes/Shape.php similarity index 97% rename from vendor/irrevion/science/Geometry/Shapes/Shape.php rename to src/Geometry/Shapes/Shape.php index 63dc97d..91e2944 100644 --- a/vendor/irrevion/science/Geometry/Shapes/Shape.php +++ b/src/Geometry/Shapes/Shape.php @@ -1,17 +1,17 @@ - \ No newline at end of file diff --git a/vendor/irrevion/science/Math/Branches/BaseMath.php b/src/Math/Branches/BaseMath.php similarity index 95% rename from vendor/irrevion/science/Math/Branches/BaseMath.php rename to src/Math/Branches/BaseMath.php index 5bb7456..97ba710 100644 --- a/vendor/irrevion/science/Math/Branches/BaseMath.php +++ b/src/Math/Branches/BaseMath.php @@ -1,274 +1,274 @@ -$x) {$avg+=(($x-$avg)/($i+1));} - return $avg; - } - - public static function base_convert($num, $from_base=10, $to_base=16) { - return base_convert($num, $from_base, $to_base); - } - - public static function bindec($binary_string) { - return bindec($binary_string); - } - - public static function ceil($num) { - return ceil($num); - } - - public static function compare(float $x=0.0, string $rel='==', float $y=1e-12) { - $epsilon = ((self::EPSILON1e-2) { - // cannot be bigger than epsilon is .01 - $epsilon = 1e-2; - } - // print 'ε '.var_export($epsilon, 1)."\n"; - $rels = [ - '=' => 'equal', - '==' => 'equal', - '===' => 'equal', - '!=' => 'not equal', - '!==' => 'not equal', - '<>' => 'not equal', - '>' => 'greater than', - '>=' => 'greater than or equal', - '<' => 'less than', - '<=' => 'less than or equal', - '<=>' => 'spaceship', - ]; - if (!isset($rels[$rel])) { - throw new \Error('Unknown comparison operator "'.$rel.'"'); - } - $result = match($rels[$rel]) { - 'equal' => (abs($x-$y)<$epsilon), - // 'not equal' => !self::compare($x, '=', $y), - 'not equal' => (abs($x-$y)>=$epsilon), - 'greater than' => ($x>($y+$epsilon)), - 'greater than or equal' => ($x>=$y), // there are possible cases when "equal" returns true but "greater then or equal" return false - 'less than' => ($x<($y-$epsilon)), - 'less than or equal' => ($x<=$y), - 'spaceship' => (self::compare($x, '=', $y)? 0: (self::compare($x, '<', $y)? -1: 1)), - default => null, - }; - return $result; - } - - public static function cos($num) { - return cos($num); - } - - public static function cosh($num) { - return cosh($num); - } - - public static function decbin($num) { - return decbin($num); - } - - public static function dechex($num) { - return dechex($num); - } - - public static function decoct($num) { - return decoct($num); - } - - public static function deg2rad($num) { - return deg2rad($num); - } - - public static function diagonal($x, $y) { // same as hypot() - return sqrt(pow($x, 2) + pow($y, 2)); - } - - public static function exp($num) { - return exp($num); - } - - public static function expm1($num) { - return expm1($num); - } - - public static function fdiv($x, $y) { - return fdiv($x, $y); - } - - public static function floor($num) { - return floor($num); - } - - public static function fmod($x, $y) { - return fmod($x, $y); - } - - public static function gcd($x, $y) { // greatest common divisor - $a = abs((int)$x); - $b = abs((int)$y); - if ($b>$a) { - list($a, $b) = [$b, $a]; // swap - } - $remnant = $a%$b; - if ($remnant==0) {return $b;} - return self::gcd($b, $remnant); - } - - public static function gcd_simplify($x, $y) { // simplify fraction by gcd - $gcd = self::gcd($x, $y); - return [($x/$gcd), ($y/$gcd)]; - } - - public static function hexdec($s) { - return hexdec($s); - } - - public static function hypot($x, $y) { - return hypot($x, $y); - } - - public static function intdiv($x, $y) { - return intdiv($x, $y); - } - - public static function log10($x) { - return log10($x); - } - - public static function log1p($x) { - return log1p($x); - } - - public static function log($num, $base = M_E) { - return log($num, $base); - } - - public static function octdec($octal_string) { - return octdec($octal_string); - } - - public static function polar2rectangular($radius, $phase_angle=0) { - list($radius, $phase_angle) = self::polar_absolute($radius, $phase_angle); - $x = $radius * cos($phase_angle); - $y = $radius * sin($phase_angle); - return [$x, $y]; - } - - public static function polar_absolute($radius, $phase_angle=0) { - $radius = abs($radius); - $phi_sign = (($phase_angle>0)? 1: -1); - $phi_abs = abs($phase_angle); - $loops = floor($phi_abs / (2 * M_PI)); - if ($loops) { - $phase_angle = $phi_sign * ($phi_abs - ($loops * (2 * M_PI))); - } - if ($phase_angle<0) { - $phase_angle = (2 * M_PI) + $phase_angle; - } - return [$radius, $phase_angle]; - } - - public static function pow($x, $y) { - return pow($x, $y); - } - - public static function rad2deg($angle) { - return rad2deg($angle); - } - - public static function rectangular2polar($x, $y) { - $radius = hypot($x, $y); - $phase_angle = atan2($y, $x); - list($radius, $phase_angle) = self::polar_absolute($radius, $phase_angle); - return [$radius, $phase_angle]; - } - - public static function round($num, $precision=0, $mode=PHP_ROUND_HALF_UP) { - return round($num, $precision, $mode); - } - - public static function sin($x) { - return sin($x); - } - - public static function sinh($x) { - return sinh($x); - } - - public static function sqrt($x) { - return sqrt($x); - } - - public static function sum($array) { - return array_sum($array); - } - - public static function tan($x) { - return tan($x); - } - - public static function tanh($x) { - return tanh($x); - } -} +$x) {$avg+=(($x-$avg)/($i+1));} + return $avg; + } + + public static function base_convert($num, $from_base=10, $to_base=16) { + return base_convert($num, $from_base, $to_base); + } + + public static function bindec($binary_string) { + return bindec($binary_string); + } + + public static function ceil($num) { + return ceil($num); + } + + public static function compare(float $x=0.0, string $rel='==', float $y=1e-12) { + $epsilon = ((self::EPSILON1e-2) { + // cannot be bigger than epsilon is .01 + $epsilon = 1e-2; + } + // print 'ε '.var_export($epsilon, 1)."\n"; + $rels = [ + '=' => 'equal', + '==' => 'equal', + '===' => 'equal', + '!=' => 'not equal', + '!==' => 'not equal', + '<>' => 'not equal', + '>' => 'greater than', + '>=' => 'greater than or equal', + '<' => 'less than', + '<=' => 'less than or equal', + '<=>' => 'spaceship', + ]; + if (!isset($rels[$rel])) { + throw new \Error('Unknown comparison operator "'.$rel.'"'); + } + $result = match($rels[$rel]) { + 'equal' => (abs($x-$y)<$epsilon), + // 'not equal' => !self::compare($x, '=', $y), + 'not equal' => (abs($x-$y)>=$epsilon), + 'greater than' => ($x>($y+$epsilon)), + 'greater than or equal' => ($x>=$y), // there are possible cases when "equal" returns true but "greater then or equal" return false + 'less than' => ($x<($y-$epsilon)), + 'less than or equal' => ($x<=$y), + 'spaceship' => (self::compare($x, '=', $y)? 0: (self::compare($x, '<', $y)? -1: 1)), + default => null, + }; + return $result; + } + + public static function cos($num) { + return cos($num); + } + + public static function cosh($num) { + return cosh($num); + } + + public static function decbin($num) { + return decbin($num); + } + + public static function dechex($num) { + return dechex($num); + } + + public static function decoct($num) { + return decoct($num); + } + + public static function deg2rad($num) { + return deg2rad($num); + } + + public static function diagonal($x, $y) { // same as hypot() + return sqrt(pow($x, 2) + pow($y, 2)); + } + + public static function exp($num) { + return exp($num); + } + + public static function expm1($num) { + return expm1($num); + } + + public static function fdiv($x, $y) { + return fdiv($x, $y); + } + + public static function floor($num) { + return floor($num); + } + + public static function fmod($x, $y) { + return fmod($x, $y); + } + + public static function gcd($x, $y) { // greatest common divisor + $a = abs((int)$x); + $b = abs((int)$y); + if ($b>$a) { + list($a, $b) = [$b, $a]; // swap + } + $remnant = $a%$b; + if ($remnant==0) {return $b;} + return self::gcd($b, $remnant); + } + + public static function gcd_simplify($x, $y) { // simplify fraction by gcd + $gcd = self::gcd($x, $y); + return [($x/$gcd), ($y/$gcd)]; + } + + public static function hexdec($s) { + return hexdec($s); + } + + public static function hypot($x, $y) { + return hypot($x, $y); + } + + public static function intdiv($x, $y) { + return intdiv($x, $y); + } + + public static function log10($x) { + return log10($x); + } + + public static function log1p($x) { + return log1p($x); + } + + public static function log($num, $base = M_E) { + return log($num, $base); + } + + public static function octdec($octal_string) { + return octdec($octal_string); + } + + public static function polar2rectangular($radius, $phase_angle=0) { + list($radius, $phase_angle) = self::polar_absolute($radius, $phase_angle); + $x = $radius * cos($phase_angle); + $y = $radius * sin($phase_angle); + return [$x, $y]; + } + + public static function polar_absolute($radius, $phase_angle=0) { + $radius = abs($radius); + $phi_sign = (($phase_angle>0)? 1: -1); + $phi_abs = abs($phase_angle); + $loops = floor($phi_abs / (2 * M_PI)); + if ($loops) { + $phase_angle = $phi_sign * ($phi_abs - ($loops * (2 * M_PI))); + } + if ($phase_angle<0) { + $phase_angle = (2 * M_PI) + $phase_angle; + } + return [$radius, $phase_angle]; + } + + public static function pow($x, $y) { + return pow($x, $y); + } + + public static function rad2deg($angle) { + return rad2deg($angle); + } + + public static function rectangular2polar($x, $y) { + $radius = hypot($x, $y); + $phase_angle = atan2($y, $x); + list($radius, $phase_angle) = self::polar_absolute($radius, $phase_angle); + return [$radius, $phase_angle]; + } + + public static function round($num, $precision=0, $mode=PHP_ROUND_HALF_UP) { + return round($num, $precision, $mode); + } + + public static function sin($x) { + return sin($x); + } + + public static function sinh($x) { + return sinh($x); + } + + public static function sqrt($x) { + return sqrt($x); + } + + public static function sum($array) { + return array_sum($array); + } + + public static function tan($x) { + return tan($x); + } + + public static function tanh($x) { + return tanh($x); + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Math/Branches/LinearAlgebra.php b/src/Math/Branches/LinearAlgebra.php similarity index 100% rename from vendor/irrevion/science/Math/Branches/LinearAlgebra.php rename to src/Math/Branches/LinearAlgebra.php diff --git a/vendor/irrevion/science/Math/Branches/MathAnalysis.php b/src/Math/Branches/MathAnalysis.php similarity index 100% rename from vendor/irrevion/science/Math/Branches/MathAnalysis.php rename to src/Math/Branches/MathAnalysis.php diff --git a/vendor/irrevion/science/Math/Branches/Statistics.php b/src/Math/Branches/Statistics.php similarity index 100% rename from vendor/irrevion/science/Math/Branches/Statistics.php rename to src/Math/Branches/Statistics.php diff --git a/vendor/irrevion/science/Math/Entities/Complex.php b/src/Math/Entities/Complex.php similarity index 96% rename from vendor/irrevion/science/Math/Entities/Complex.php rename to src/Math/Entities/Complex.php index fb73802..9f3be26 100644 --- a/vendor/irrevion/science/Math/Entities/Complex.php +++ b/src/Math/Entities/Complex.php @@ -1,206 +1,206 @@ -value = $real->value; - return; - } else if (in_array($real::class, [self::T_SCALAR, self::T_FRACTION])) { - $this->value['real'] = Delegator::wrap($real->toNumber()); - } else if ($real::class==self::T_IMAGINARY) { - $this->value['real'] = new Scalar(0); - $this->value['imaginary'] = $real; - // can be constructed with only the imaginary part - return; - } else if ($real::class==self::T_POLAR) { - $real = $real->toRectangular(); - $this->value['real'] = $real->real; - $this->value['imaginary'] = $real->imaginary; - return; - } else { - throw new \TypeError("Real part of a Complex number should be Scalar"); - } - } else if (is_array($real)) { - $this->value['real'] = new Scalar($real['real']); - $this->value['imaginary'] = new Imaginary($real['imaginary']); - return; - } else { - $this->value['real'] = new Scalar($real); - } - if (is_object($imaginary)) { - if ($imaginary::class==self::T_IMAGINARY) { - $this->value['imaginary'] = $imaginary; - } else { - throw new \TypeError("Imaginary part of a Complex number should be Imaginary type or numeric"); - } - } else { - $this->value['imaginary'] = new Imaginary($imaginary); - } - } - - public function __get($property) { - if (isset($this->$property)) { - return $this->$property; - } else if (array_key_exists($property, $this->value)) { - return $this->value[$property]; - } - return null; - } - - public function __toString() { - return "[{$this->value['real']} + {$this->value['imaginary']}]"; - } - - public function toNumber() { - return $this->abs()->toNumber(); - } - - public function toPolar() { - //return Math::rectangular2polar($this->getReal(), $this->getImaginary()); - list($r, $phi) = Math::rectangular2polar($this->getReal(), $this->getImaginary()); - return Delegator::wrap([ - 'radius' => $r, - 'phase' => $phi - ], self::T_POLAR); - } - - public function toArray() { - return [ - 'real' => $this->getReal(), - 'imaginary' => $this->getImaginary() - ]; - } - - public function toVector() { - return Delegator::wrap([$this->getReal()->toNumber(), $this->getImaginary()->toNumber()], self::T_VECTOR); - } - - public function phase() { - return atan2($this->getImaginary(), $this->getReal()); - } - - public function getReal() { - return $this->value['real']->value; - } - - public function getImaginary() { - return $this->value['imaginary']->value; - } - - public function isComplex() { - return ($this::class==self::class); - } - - public function add($y) { - if (Delegator::getType($y)!=self::class) $y = new self($y); - $real = $this->value['real']->add($y->value['real']); - $imaginary = $this->value['imaginary']->add($y->value['imaginary']); - return new self($real, $imaginary); - } - - public function subtract($y) { - if (Delegator::getType($y)!=self::class) $y = new self($y); - $y = $y->negative($y); - return $this->add($y); - } - - public function multiply($y) { - if (Delegator::getType($y)!=self::class) $y = new self($y); - - // z * w = (a + bi) * (c + di) - // = ac + a*di + c*bi + bi*di - // = ac + a*di + c*bi - bd - // = (ac - bd) + (ad + cb)i - - // by formulae - /* - $real = $this->value['real']->multiply($y->value['real'])->subtract($this->value['imaginary']->value*$y->value['imaginary']->value); - $imaginary = $this->value['real']->multiply($y->value['imaginary']->value)->add($this->value['imaginary']->value*$y->value['real']->value); - $z = new self($real->value, $imaginary->value); - */ - - - // direct style - $z = $this->value['real']->multiply($y->value['real']) - //->add($this->value['real']->multiply($y->value['imaginary'])) - // this cause Memory Overflow Error due to Scalar doesnt know how to multiply to imaginary and delegates to Complex::multiply again and again - ->add($y->value['imaginary']->multiply($this->value['real'])) - ->add($this->value['imaginary']->multiply($y->value['real'])) - ->add($this->value['imaginary']->multiply($y->value['imaginary'])); - - // simplify return value - if ($z->value['imaginary']->empty()) { - return $z->value['real']; - } else if ($z->value['real']->empty()) { - return $z->value['imaginary']; - } - - return $z; - } - - public function divide($y) { - if (Delegator::getType($y)!=self::class) $y = new self($y); - if (($this->value['imaginary']->value==0) && ($y->value['real']->value==0)) { - // a / bi = ai / bi^2 = ai / -b = ( -a / b ) * i - $z = ($this->value['real']->value / $y->value['imaginary']->value) * -1; - $z = Delegator::wrap($z, self::T_IMAGINARY); - return $z; - } - - return $this->multiply($y->reciprocal()); - } - - public function reciprocal() { - // (1 / y) is reciprocal - // (1 / y) = 1 / (a + bi) = (a - bi) / (a + bi)(a - bi) = (a - bi) / ((a^2 + b^2) + (-ab + ab)i) = (a - bi) / (a^2 + b^2) - // (a - bi) / (a^2 + b^2) = (a / (a^2 + b^2)) + (-b / (a^2 + b^2)i) - // so, we can multiply: - // c * (a / (a^2 + b^2)) + (-b / (a^2 + b^2)i) - $a = $this->getReal(); - $b = $this->getImaginary(); - $denominator = (Math::pow($a, 2) + Math::pow($b, 2)); // (a / (a^2 + b^2)) - $reciprocal_real = ($a / $denominator); // (a / (a^2 + b^2)) - $reciprocal_imaginary = (($b*-1) / $denominator); // (-b / (a^2 + b^2)i) - $reciprocal = new self($reciprocal_real, $reciprocal_imaginary); - return $reciprocal; - } - - public function invert() { - return new self($this->value['real']->invert(), $this->value['imaginary']->invert()); - } - - public function abs() { - $abs = Math::diagonal($this->value['real']->value, $this->value['imaginary']->value); - return Delegator::wrap($abs, self::T_SCALAR); - } - - public function empty() { - return ($this->value['real']->empty() && $this->value['imaginary']->empty()); - } -} +value = $real->value; + return; + } else if (in_array($real::class, [self::T_SCALAR, self::T_FRACTION])) { + $this->value['real'] = Delegator::wrap($real->toNumber()); + } else if ($real::class==self::T_IMAGINARY) { + $this->value['real'] = new Scalar(0); + $this->value['imaginary'] = $real; + // can be constructed with only the imaginary part + return; + } else if ($real::class==self::T_POLAR) { + $real = $real->toRectangular(); + $this->value['real'] = $real->real; + $this->value['imaginary'] = $real->imaginary; + return; + } else { + throw new \TypeError("Real part of a Complex number should be Scalar"); + } + } else if (is_array($real)) { + $this->value['real'] = new Scalar($real['real']); + $this->value['imaginary'] = new Imaginary($real['imaginary']); + return; + } else { + $this->value['real'] = new Scalar($real); + } + if (is_object($imaginary)) { + if ($imaginary::class==self::T_IMAGINARY) { + $this->value['imaginary'] = $imaginary; + } else { + throw new \TypeError("Imaginary part of a Complex number should be Imaginary type or numeric"); + } + } else { + $this->value['imaginary'] = new Imaginary($imaginary); + } + } + + public function __get($property) { + if (isset($this->$property)) { + return $this->$property; + } else if (array_key_exists($property, $this->value)) { + return $this->value[$property]; + } + return null; + } + + public function __toString() { + return "[{$this->value['real']} + {$this->value['imaginary']}]"; + } + + public function toNumber() { + return $this->abs()->toNumber(); + } + + public function toPolar() { + //return Math::rectangular2polar($this->getReal(), $this->getImaginary()); + list($r, $phi) = Math::rectangular2polar($this->getReal(), $this->getImaginary()); + return Delegator::wrap([ + 'radius' => $r, + 'phase' => $phi + ], self::T_POLAR); + } + + public function toArray() { + return [ + 'real' => $this->getReal(), + 'imaginary' => $this->getImaginary() + ]; + } + + public function toVector() { + return Delegator::wrap([$this->getReal()->toNumber(), $this->getImaginary()->toNumber()], self::T_VECTOR); + } + + public function phase() { + return atan2($this->getImaginary(), $this->getReal()); + } + + public function getReal() { + return $this->value['real']->value; + } + + public function getImaginary() { + return $this->value['imaginary']->value; + } + + public function isComplex() { + return ($this::class==self::class); + } + + public function add($y) { + if (Delegator::getType($y)!=self::class) $y = new self($y); + $real = $this->value['real']->add($y->value['real']); + $imaginary = $this->value['imaginary']->add($y->value['imaginary']); + return new self($real, $imaginary); + } + + public function subtract($y) { + if (Delegator::getType($y)!=self::class) $y = new self($y); + $y = $y->negative($y); + return $this->add($y); + } + + public function multiply($y) { + if (Delegator::getType($y)!=self::class) $y = new self($y); + + // z * w = (a + bi) * (c + di) + // = ac + a*di + c*bi + bi*di + // = ac + a*di + c*bi - bd + // = (ac - bd) + (ad + cb)i + + // by formulae + /* + $real = $this->value['real']->multiply($y->value['real'])->subtract($this->value['imaginary']->value*$y->value['imaginary']->value); + $imaginary = $this->value['real']->multiply($y->value['imaginary']->value)->add($this->value['imaginary']->value*$y->value['real']->value); + $z = new self($real->value, $imaginary->value); + */ + + + // direct style + $z = $this->value['real']->multiply($y->value['real']) + //->add($this->value['real']->multiply($y->value['imaginary'])) + // this cause Memory Overflow Error due to Scalar doesnt know how to multiply to imaginary and delegates to Complex::multiply again and again + ->add($y->value['imaginary']->multiply($this->value['real'])) + ->add($this->value['imaginary']->multiply($y->value['real'])) + ->add($this->value['imaginary']->multiply($y->value['imaginary'])); + + // simplify return value + if ($z->value['imaginary']->empty()) { + return $z->value['real']; + } else if ($z->value['real']->empty()) { + return $z->value['imaginary']; + } + + return $z; + } + + public function divide($y) { + if (Delegator::getType($y)!=self::class) $y = new self($y); + if (($this->value['imaginary']->value==0) && ($y->value['real']->value==0)) { + // a / bi = ai / bi^2 = ai / -b = ( -a / b ) * i + $z = ($this->value['real']->value / $y->value['imaginary']->value) * -1; + $z = Delegator::wrap($z, self::T_IMAGINARY); + return $z; + } + + return $this->multiply($y->reciprocal()); + } + + public function reciprocal() { + // (1 / y) is reciprocal + // (1 / y) = 1 / (a + bi) = (a - bi) / (a + bi)(a - bi) = (a - bi) / ((a^2 + b^2) + (-ab + ab)i) = (a - bi) / (a^2 + b^2) + // (a - bi) / (a^2 + b^2) = (a / (a^2 + b^2)) + (-b / (a^2 + b^2)i) + // so, we can multiply: + // c * (a / (a^2 + b^2)) + (-b / (a^2 + b^2)i) + $a = $this->getReal(); + $b = $this->getImaginary(); + $denominator = (Math::pow($a, 2) + Math::pow($b, 2)); // (a / (a^2 + b^2)) + $reciprocal_real = ($a / $denominator); // (a / (a^2 + b^2)) + $reciprocal_imaginary = (($b*-1) / $denominator); // (-b / (a^2 + b^2)i) + $reciprocal = new self($reciprocal_real, $reciprocal_imaginary); + return $reciprocal; + } + + public function invert() { + return new self($this->value['real']->invert(), $this->value['imaginary']->invert()); + } + + public function abs() { + $abs = Math::diagonal($this->value['real']->value, $this->value['imaginary']->value); + return Delegator::wrap($abs, self::T_SCALAR); + } + + public function empty() { + return ($this->value['real']->empty() && $this->value['imaginary']->empty()); + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Math/Entities/ComplexPolar.php b/src/Math/Entities/ComplexPolar.php similarity index 97% rename from vendor/irrevion/science/Math/Entities/ComplexPolar.php rename to src/Math/Entities/ComplexPolar.php index cb86d10..34536ab 100644 --- a/vendor/irrevion/science/Math/Entities/ComplexPolar.php +++ b/src/Math/Entities/ComplexPolar.php @@ -1,225 +1,225 @@ -value = []; - $rt = Delegator::getType($r); - if (Delegator::isEntity($r)) { - if ($rt==self::class) { - $this->value['radius'] = clone $r->r; - $this->value['phase'] = clone $r->phi; - return; - } else if ($rt==self::T_COMPLEX) { - $c = $r->toArray(); - list($r, $phi) = Math::rectangular2polar($c['real'], $c['imaginary']); - $this->value['radius'] = Delegator::wrap($r); - $this->value['phase'] = Delegator::wrap($phi); - return; - } else if ($rt==self::T_SCALAR) { - $this->value['radius'] = clone $r; - } else { - //$this->value['radius'] = Delegator::wrap($r->toNumber()); - throw new \TypeError("Unrecognized type of radius argument ( {$r} :: {$rt} )"); - } - } else { - if (is_array($r)) { - list($r, $phi) = Math::polar_absolute($r['radius'], $r['phase']); - $this->value['radius'] = Delegator::wrap($r); - $this->value['phase'] = Delegator::wrap($phi); - return; - } else if (is_numeric($r)) { - $this->value['radius'] = Delegator::wrap($r); - } else { - throw new \TypeError("Unrecognized type of radius argument ( {$r} :: {$rt} )"); - } - } - $phi_type = Delegator::getType($phi); - if ($phi_type==self::T_SCALAR) { - $this->value['phase'] = clone $phi; - } else if (is_numeric($r)) { - $this->value['phase'] = Delegator::wrap($phi); - } else { - throw new \TypeError("Unrecognized type of phase argument ( {$phi} :: {$phi_type} )"); - } - - list($r, $phi) = Math::polar_absolute($this->value['radius']->toNumber(), $this->value['phase']->toNumber()); - $this->value['radius']->value = $r; - $this->value['phase']->value = $phi; - } - - public function __get($property) { - if (isset($this->$property)) { - return $this->$property; - } else if (array_key_exists($property, $this->value)) { - return $this->value[$property]; - } else if ($property=='r') { - return $this->value['radius']; - } else if ($property=='phi') { - return $this->value['phase']; - } - return null; - } - - public function __toString() { - return "[{$this->r}, φ ".($this->phi->toNumber()/Math::PI)."π RAD]"; - } - - public function toNumber() { - return $this->radius->toNumber(); - } - - public function toArray() { - return [ - 'radius' => $this->r->toNumber(), - 'phase' => $this->phi->toNumber() - ]; - } - - public function toRectangular() { - list($x, $y) = Math::polar2rectangular($this->r->toNumber(), $this->phi->toNumber()); - return Delegator::wrap([ - 'real' => $x, - 'imaginary' => $y - ], self::T_COMPLEX); - } - - public function isComplexPolar() { - return ($this::class==self::class); - } - - public function add($y) { - if (Delegator::getType($y)!=self::class) $y = new self($y); - $x = clone $this; - - $is_outer_parallelogram = false; - $phi_angle = $x->phi->toNumber(); // Rx angle (0, π, 2π is real axis; π/2, 3π/2, -π/2 is imaginary axis) - $theta_angle = $y->phi->toNumber(); // Ry angle - $rx = $x->r->toNumber(); - $ry = $y->r->toNumber(); - - $gamma_angle = Math::abs($theta_angle - $phi_angle); // angle between phi and theta ( Rx and Ry ) - if ($gamma_angle > Math::PI) { - $is_outer_parallelogram = true; - $gamma_angle = Math::TAU - $gamma_angle; - // we are counting outside angle, so - // get theta angle as the remained angle to do a loop - // then add phi to be relative to phi instead of x axis - } - $sigma_angle = Math::PI - $gamma_angle; // angle of another corner of parallelogram ( Ry and Ry->Rz ) - if (($sigma_angle==0) || ($gamma_angle==0)) { - return new self(0, 0); - } - $rz = Math::sqrt(Math::pow($rx, 2) + Math::pow($ry, 2) + ((2 * $rx * $ry) * Math::cos($gamma_angle))); // diagonal of parallelogram - // $rz = Math::sqrt(Math::pow($rx, 2) + Math::pow($ry, 2) - ((2 * $rx * $ry) * Math::cos($sigma_angle))); // diagonal of parallelogram by sigma - if ($phi_angle>$theta_angle) { - list($rx, $ry) = [$ry, $rx]; - list($phi_angle, $theta_angle) = [$theta_angle, $phi_angle]; - // calculate angle to the nearest side, so swap rx and ry, their angles too - } - $cos_alpha = ((Math::pow($ry, 2) + Math::pow($rz, 2) - Math::pow($rx, 2)) / (2 * $ry * $rz)); // angle between Ry and Rz - $alpha_angle = acos($cos_alpha); // angle between Ry and Rz - if ($is_outer_parallelogram) { - $beta_angle = Math::abs($theta_angle + $alpha_angle); // angle between 0 angle and Rz - } else { - $beta_angle = Math::abs($theta_angle - $alpha_angle); // angle between 0 angle and Rz - } - - return new self($rz, $beta_angle); - } - - public function subtract($y) { - if (Delegator::getType($y)!=self::class) $y = new self($y); - $y = $y->negative($y); - return $this->add($y); - } - - public function multiply($y) { - if (Delegator::getType($y)!=self::class) $y = new self($y); - $x = $this->toArray(); - $y = $y->toArray(); - $z = ['radius' => 0, 'phase' => 0]; - - // module of resulting vector is multiplied modules of given vectors - $z['radius'] = $x['radius'] * $y['radius']; - - // now we should calculate angle of Z - // knowing algebraic form XY = (a+bi)(c+di) = (ac - bd) + (ad + cb)i - // so Real part (coordinate on real axis) id (ac - bd) and Imaginary part is (ad + cb) - // knowing that sin = y/r and cos = x/r, so x=R*cos(α) and y=R*sin(α) - // knowing that Real = |Z|*cos(γ) and Imaginary = |Z|*sin(γ) - // lets replace Real or Imaginary with algebraic form - // thus for Imaginary: - // |Z|*sin(γ) = (ad + cb) => sin(γ) = (ad + cb)/|Z| - // replace |Z| with |X|*|Y| - // then lets change real "a" to |X|*cos(α), "b" to |X|*sin(α), "c" to |Y|*cos(β) and "d" to |Y|*sin(β) - // we will get - // sin(γ) = ( |X|*cos(α) * |Y|*sin(β) + |X|*sin(α) * |Y|*cos(β)) / |X|*|Y| - // => sin(γ) = cos(α)*sin(β) + sin(α)*cos(β) - // lets apply trigonometric rule sin(α ± β) = sin(α)*cos(β) ± cos(α)*sin(β) - // and get - // sin(γ) = sin(α + β) - // almost the same result we will got for Real part: - // cos(γ) = cos(α)*cos(β) - sin(α)*sin(β) - // apply cos(α ± β) = cos(α)*cos(β) ∓ sin(α)*sin(β) - // cos(γ) = cos(α + β) - // that means γ = α + β - $z['phase'] = $x['phase'] + $y['phase']; - - return new self($z); - } - - public function divide($y) { - if (Delegator::getType($y)!=self::class) $y = new self($y); - return $this->multiply($y->reciprocal()); - } - - public function reciprocal() { - // 1/z = ž/|z|^2 - // reciprocal is conjugate divided by squared module - // $reciprocal = $this->conjugate()->divide(Math::pow($this->r, 2)); - // to prevent infinit recursion in division method we directrly divide radius by scalar - $conjugate = $this->conjugate(); - $r = $conjugate->r->divide(Math::pow($this->r, 2)); - $reciprocal = new self($r->toNumber(), $conjugate->phi->toNumber()); - return $reciprocal; - } - - public function conjugate() { - return new self($this->r->toNumber(), ((2 * Math::PI) - $this->phi->toNumber())); - } - - public function invert() { - $x = $this->toArray(); - $x['phase'] = $x['phase'] + (Math::PI * (($x['phase']>Math::PI)? -1: 1)); - return new self($x); - } - - public function abs() { - return clone $this->r; - } - - public function empty() { - return $this->value['radius']->empty(); - } -} +value = []; + $rt = Delegator::getType($r); + if (Delegator::isEntity($r)) { + if ($rt==self::class) { + $this->value['radius'] = clone $r->r; + $this->value['phase'] = clone $r->phi; + return; + } else if ($rt==self::T_COMPLEX) { + $c = $r->toArray(); + list($r, $phi) = Math::rectangular2polar($c['real'], $c['imaginary']); + $this->value['radius'] = Delegator::wrap($r); + $this->value['phase'] = Delegator::wrap($phi); + return; + } else if ($rt==self::T_SCALAR) { + $this->value['radius'] = clone $r; + } else { + //$this->value['radius'] = Delegator::wrap($r->toNumber()); + throw new \TypeError("Unrecognized type of radius argument ( {$r} :: {$rt} )"); + } + } else { + if (is_array($r)) { + list($r, $phi) = Math::polar_absolute($r['radius'], $r['phase']); + $this->value['radius'] = Delegator::wrap($r); + $this->value['phase'] = Delegator::wrap($phi); + return; + } else if (is_numeric($r)) { + $this->value['radius'] = Delegator::wrap($r); + } else { + throw new \TypeError("Unrecognized type of radius argument ( {$r} :: {$rt} )"); + } + } + $phi_type = Delegator::getType($phi); + if ($phi_type==self::T_SCALAR) { + $this->value['phase'] = clone $phi; + } else if (is_numeric($r)) { + $this->value['phase'] = Delegator::wrap($phi); + } else { + throw new \TypeError("Unrecognized type of phase argument ( {$phi} :: {$phi_type} )"); + } + + list($r, $phi) = Math::polar_absolute($this->value['radius']->toNumber(), $this->value['phase']->toNumber()); + $this->value['radius']->value = $r; + $this->value['phase']->value = $phi; + } + + public function __get($property) { + if (isset($this->$property)) { + return $this->$property; + } else if (array_key_exists($property, $this->value)) { + return $this->value[$property]; + } else if ($property=='r') { + return $this->value['radius']; + } else if ($property=='phi') { + return $this->value['phase']; + } + return null; + } + + public function __toString() { + return "[{$this->r}, φ ".($this->phi->toNumber()/Math::PI)."π RAD]"; + } + + public function toNumber() { + return $this->radius->toNumber(); + } + + public function toArray() { + return [ + 'radius' => $this->r->toNumber(), + 'phase' => $this->phi->toNumber() + ]; + } + + public function toRectangular() { + list($x, $y) = Math::polar2rectangular($this->r->toNumber(), $this->phi->toNumber()); + return Delegator::wrap([ + 'real' => $x, + 'imaginary' => $y + ], self::T_COMPLEX); + } + + public function isComplexPolar() { + return ($this::class==self::class); + } + + public function add($y) { + if (Delegator::getType($y)!=self::class) $y = new self($y); + $x = clone $this; + + $is_outer_parallelogram = false; + $phi_angle = $x->phi->toNumber(); // Rx angle (0, π, 2π is real axis; π/2, 3π/2, -π/2 is imaginary axis) + $theta_angle = $y->phi->toNumber(); // Ry angle + $rx = $x->r->toNumber(); + $ry = $y->r->toNumber(); + + $gamma_angle = Math::abs($theta_angle - $phi_angle); // angle between phi and theta ( Rx and Ry ) + if ($gamma_angle > Math::PI) { + $is_outer_parallelogram = true; + $gamma_angle = Math::TAU - $gamma_angle; + // we are counting outside angle, so + // get theta angle as the remained angle to do a loop + // then add phi to be relative to phi instead of x axis + } + $sigma_angle = Math::PI - $gamma_angle; // angle of another corner of parallelogram ( Ry and Ry->Rz ) + if (($sigma_angle==0) || ($gamma_angle==0)) { + return new self(0, 0); + } + $rz = Math::sqrt(Math::pow($rx, 2) + Math::pow($ry, 2) + ((2 * $rx * $ry) * Math::cos($gamma_angle))); // diagonal of parallelogram + // $rz = Math::sqrt(Math::pow($rx, 2) + Math::pow($ry, 2) - ((2 * $rx * $ry) * Math::cos($sigma_angle))); // diagonal of parallelogram by sigma + if ($phi_angle>$theta_angle) { + list($rx, $ry) = [$ry, $rx]; + list($phi_angle, $theta_angle) = [$theta_angle, $phi_angle]; + // calculate angle to the nearest side, so swap rx and ry, their angles too + } + $cos_alpha = ((Math::pow($ry, 2) + Math::pow($rz, 2) - Math::pow($rx, 2)) / (2 * $ry * $rz)); // angle between Ry and Rz + $alpha_angle = acos($cos_alpha); // angle between Ry and Rz + if ($is_outer_parallelogram) { + $beta_angle = Math::abs($theta_angle + $alpha_angle); // angle between 0 angle and Rz + } else { + $beta_angle = Math::abs($theta_angle - $alpha_angle); // angle between 0 angle and Rz + } + + return new self($rz, $beta_angle); + } + + public function subtract($y) { + if (Delegator::getType($y)!=self::class) $y = new self($y); + $y = $y->negative($y); + return $this->add($y); + } + + public function multiply($y) { + if (Delegator::getType($y)!=self::class) $y = new self($y); + $x = $this->toArray(); + $y = $y->toArray(); + $z = ['radius' => 0, 'phase' => 0]; + + // module of resulting vector is multiplied modules of given vectors + $z['radius'] = $x['radius'] * $y['radius']; + + // now we should calculate angle of Z + // knowing algebraic form XY = (a+bi)(c+di) = (ac - bd) + (ad + cb)i + // so Real part (coordinate on real axis) id (ac - bd) and Imaginary part is (ad + cb) + // knowing that sin = y/r and cos = x/r, so x=R*cos(α) and y=R*sin(α) + // knowing that Real = |Z|*cos(γ) and Imaginary = |Z|*sin(γ) + // lets replace Real or Imaginary with algebraic form + // thus for Imaginary: + // |Z|*sin(γ) = (ad + cb) => sin(γ) = (ad + cb)/|Z| + // replace |Z| with |X|*|Y| + // then lets change real "a" to |X|*cos(α), "b" to |X|*sin(α), "c" to |Y|*cos(β) and "d" to |Y|*sin(β) + // we will get + // sin(γ) = ( |X|*cos(α) * |Y|*sin(β) + |X|*sin(α) * |Y|*cos(β)) / |X|*|Y| + // => sin(γ) = cos(α)*sin(β) + sin(α)*cos(β) + // lets apply trigonometric rule sin(α ± β) = sin(α)*cos(β) ± cos(α)*sin(β) + // and get + // sin(γ) = sin(α + β) + // almost the same result we will got for Real part: + // cos(γ) = cos(α)*cos(β) - sin(α)*sin(β) + // apply cos(α ± β) = cos(α)*cos(β) ∓ sin(α)*sin(β) + // cos(γ) = cos(α + β) + // that means γ = α + β + $z['phase'] = $x['phase'] + $y['phase']; + + return new self($z); + } + + public function divide($y) { + if (Delegator::getType($y)!=self::class) $y = new self($y); + return $this->multiply($y->reciprocal()); + } + + public function reciprocal() { + // 1/z = ž/|z|^2 + // reciprocal is conjugate divided by squared module + // $reciprocal = $this->conjugate()->divide(Math::pow($this->r, 2)); + // to prevent infinit recursion in division method we directrly divide radius by scalar + $conjugate = $this->conjugate(); + $r = $conjugate->r->divide(Math::pow($this->r, 2)); + $reciprocal = new self($r->toNumber(), $conjugate->phi->toNumber()); + return $reciprocal; + } + + public function conjugate() { + return new self($this->r->toNumber(), ((2 * Math::PI) - $this->phi->toNumber())); + } + + public function invert() { + $x = $this->toArray(); + $x['phase'] = $x['phase'] + (Math::PI * (($x['phase']>Math::PI)? -1: 1)); + return new self($x); + } + + public function abs() { + return clone $this->r; + } + + public function empty() { + return $this->value['radius']->empty(); + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Math/Entities/Entity.php b/src/Math/Entities/Entity.php similarity index 100% rename from vendor/irrevion/science/Math/Entities/Entity.php rename to src/Math/Entities/Entity.php diff --git a/vendor/irrevion/science/Math/Entities/Fraction.php b/src/Math/Entities/Fraction.php similarity index 100% rename from vendor/irrevion/science/Math/Entities/Fraction.php rename to src/Math/Entities/Fraction.php diff --git a/vendor/irrevion/science/Math/Entities/Imaginary.php b/src/Math/Entities/Imaginary.php similarity index 100% rename from vendor/irrevion/science/Math/Entities/Imaginary.php rename to src/Math/Entities/Imaginary.php diff --git a/vendor/irrevion/science/Math/Entities/Scalar.php b/src/Math/Entities/Scalar.php similarity index 100% rename from vendor/irrevion/science/Math/Entities/Scalar.php rename to src/Math/Entities/Scalar.php diff --git a/vendor/irrevion/science/Math/Entities/Vector.php b/src/Math/Entities/Vector.php similarity index 96% rename from vendor/irrevion/science/Math/Entities/Vector.php rename to src/Math/Entities/Vector.php index e6fc764..20ef15b 100644 --- a/vendor/irrevion/science/Math/Entities/Vector.php +++ b/src/Math/Entities/Vector.php @@ -1,511 +1,511 @@ -value = []; - $arr_type = Delegator::getType($array); - if (Delegator::isEntity($array)) { - $math_object = $array; - if ($arr_type==self::class) { - $this->value = $math_object->toArray(); - } else if (Delegator::hasMethod($math_object, 'toVector')) { - $this->value = $math_object->toVector()->toArray(); - } else { - $this->value = [$math_object]; - } - } else if (is_array($array)) { - $this->value = $array; - } else { - throw new \TypeError("Unrecognized type of argument"); - } - - if ($pad_to_length) { - $curr_length = count($this->value); - if ($pad_to_length>$curr_length) { - $n_elements_left = $pad_to_length-$curr_length; - while($n_elements_left) { - $this->value[] = ($type? Delegator::wrap(0, $type): 0); - $n_elements_left--; - } - } - } - $this->length = count($this->value); - - if ($type) { - $this->inner_type = $type; - // set specified type for all elements - foreach ($this->value as $i=>$el) { - $this->value[$i] = Delegator::wrap($el, $type); - } - } else { - if ($this->length) { - $this->inner_type = Delegator::getType($this->value[0]); - } - } - } - - public function __toString() { - return '['.implode(', ', $this->value).']'; - } - - public function toNumber() { - return $this->magnitude()->toNumber(); - } - - public function toArray() { - return $this->value; - } - - public function isVector() { - return ($this::class==self::class); - } - - public function pad(int $length): Vector { - /* $x_len = $this->count(); - $arr = $this->value; - while ($x_len<$length) { - $arr[] = Delegator::wrap(0, $this->inner_type); - } - return new self($arr, $this->inner_type); */ - return new self($this->value, $this->inner_type, $length); - } - - public function slice(int $length): Vector { - $z = new self(array_slice($this->value, 0, $length), $this->inner_type); - $z->count(); - return $z; - } - - public function cutZeroTail(): Vector { - $z = $this->value; - // print "cutZeroTail $this \n"; - while (count($z)) { - $v = end($z); - if ($v===false) {break;} - if (($v===0) || (Delegator::isEntity($v) && $v->empty())) { - array_pop($z); - } else { - break; - } - } - return new self($z, $this->inner_type); - } - - public function align($y) { - $x = clone $this; - // print "align $x and $y \n"; - $x = $x->cutZeroTail(); - $y = $y->cutZeroTail(); - $x_len = $x->count(); - $y_len = $y->count(); - // print "$y_len!=$x_len \n"; - if ($y_len<$x_len) { - $y = $y->pad($x_len); - } else if ($y_len>$x_len) { - $x = $x->pad($y_len); - } - return [$x, $y]; - } - - public function as($type) { - return new self($this->value, $type); - } - - public function add($y) { - // equivalent to finding diagonal end point coords of parallelogram formed by two vectors placed at 0 point at cartegian coordinate system - if (Delegator::getType($y)!=self::class) $y = new self($y, $this->inner_type, $this->length); - $x = clone $this; - $z = []; - - if ($y->length!=$x->length) { - // throw new \Error('Mismatch of the vectors length'); - // print "vector add mismatch $x + $y\n"; - list($x, $y) = $x->align($y); - } - // print "vector add $x + $y\n"; - - foreach ($x as $i=>$v) { - $z[] = $v->add($y[$i]); - } - $z = new self($z, $this->inner_type); - - return $z; - } - - public function subtract($y) { - // equivalent to finding vector as diagonal of parallelogram of vector and inverted vector - // equivalent to finding vector coords subtracting its initial coords - if (Delegator::getType($y)!=self::class) $y = new self($y, $this->inner_type, $this->length); - $x = clone $this; - $z = []; - - if ($y->length!=$x->length) { - throw new \Error('Mismatch of the vectors length'); - } - - foreach ($x as $i=>$v) { - $z[] = $v->subtract($y[$i]); - } - $z = new self($z, $this->inner_type); - - return $z; - } - - // scale vector using scalar scalarMultiply() (not scalar product!), k(), coefficient(), times(), scale() - // dot product ·→ aliases is dotProduct(), scalarProduct(), innerProduct(), dot() ***exclude scalarProduct() to avoid ambiquity - // Hadamard product ⊙→ aliases is multiplyElementwise(), hadamardProduct(), schurProduct() - // cross product ⨯→ aliases is crossProduct(), vectorProduct(), cross(), x() - // direct product ⊗→ (Kroneker product with transponed matrix) directProduct() - // Kronecker product ⊗→ aliases is kroneckerProduct(), tensorProduct(), matrixDirectProduct() - // exterior product is exteriorProduct(); - - public function dotProduct($y) { - // In mathematics, the dot product or scalar product is an algebraic operation that takes two equal-length sequences of numbers (usually coordinate vectors), and returns a single number. - // Algebraically, the dot product is the sum of the products of the corresponding entries of the two sequences of numbers. - // Geometrically, it is the product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them. - - // These definitions are equivalent when using Cartesian coordinates: - // →a · →b = ∑ (î₁î₂, ĵ₁ĵ₂, …, k₁k₂) ⇔ →a · →b = |a||b|cos(θ) - // θ is an angle between a & b - // cos(θ) is x/r = adjacent / hipotenuse - // assuming x is a (adjacent) and r is b (hipotenuse), projection of b to a will be hipotenuse * (adjacent / hipotenuse) = |b|*cos(θ) = b' - // projection of a to b is |a|*cos(θ) = a' - // so, basically, scalar product of two vectors is magnitude(a) times projection(b to a) => |a| * b' - // cos(θ) = b' / |b| = ( |b| * (a' / |a|) ) / |b| = a' / |a| - // |b|cos(θ) = |b| * ( a' / |a| ) - // →a · →b = |a| * |b| * ( a' / |a| ) = |a||b|a' / |a| = |b|*a' ⇔ |a|*b' - // a' = ( →a · →b ) / |b| = →a · →b₁ where →b₁ is Unit vector of b - - // any vector can be presented as a sum of unary vectors i, j, k, l, m, ... each multiplied by scalar koefficient - // →a = [X, Y, Z, W, U, ...] = X*→i + Y*→j + Z*→k + W*→l + U*→m + ... - // →b = Oi, Pj, Qk, Rl, Sm, ... = [O, P, Q, R, S, ...] - // since scalar product of two vectors is magnitude(a) times projection(b to a) - // →a · →b = |a||b|cos(θ) - // lets get →a vector components by multiplying →a · →i , considering |a||i|cos(φî) = |a|*1*cos(φî) = |a|cos(φî) = a'î = X - // (→a · →i + →a · →j + ...) = ∑ (X, Y, Z, W, U, ...) = →a · →basis - // lets get →b vector components by multiplying →b · →i , considering |b||i|cos(γî) = |b|*1*cos(γî) = |b|cos(γî) = b'î = O - // (→b · →i + →b · →j + ...) = ∑ (O, P, Q, R, S, ...) = →b · →basis - // →a · →b · →basis = (→a · →b · →i + →a · →b · →j + ...) = (a'î * b'î + a'î * b'î + ...) = (XO + YP + ZQ + ...) - - // https://en.wikipedia.org/wiki/Dot_product - // https://mathworld.wolfram.com/DotProduct.html - - $n = $this->count(); - if (empty($n)) {return 0;} - if (Delegator::getType($y)!=self::class) { - $y = new self($y, $this->inner_type, $n); - } - $y = $y->toArray(); - $x = $this->value; - $z = Delegator::wrap(0); - - foreach ($x as $i=>$v) { - $z = $z->add($v->multiply($y[$i])); - } - - return $z; - } - public function dot(...$args) {return $this->dotProduct(...$args);} - // public function innerProduct(...$args) {return $this->dotProduct(...$args);} // excluded not to mess with Hermitian inner product or inner product via conjugation a.b = Conjugate[a].b - // public function scalarProduct(...$args) {return $this->dotProduct(...$args);} // excluded not to mess with scalar multiplication - - public function multiply($y) { - $n = $this->count(); - if (empty($n)) { - return new self([]); - } - $yt = Delegator::getType($y); - if ($yt!=self::class) { - // if ($yt==self::T_SCALAR) { - if (Delegator::isEntity($y) && !Delegator::implements($y, 'Traversable')) { - return $this->k($y); - } else { - $y = new self($y, $this->inner_type, $n); - } - } - // return $this->vectorProduct($y); - return $this->multiplyElementwise($y); - } - - public function multiplyElementwise(Vector $y): Vector { - $x = clone $this; - $y_len = $y->count(); - $x_len = $this->count(); - // if ($y_len>$x_len) {$x = $x->pad($y_len);} - // if ($x_len>$y_len) {$y = $y->pad($x_len);} - if ($y_len>$x_len) {$y = $y->slice($x_len);} - if ($x_len>$y_len) {$x = $x->slice($y_len);} - $z = []; - if ($x->count()) { - foreach ($x->value as $i=>$v) { - $z[] = $v->multiply($y[$i]); - } - } - $z = new self($z, $this->inner_type); - $z = $z->cutZeroTail(); - return $z; - } - public function hadamardProduct(...$args) {return $this->multiplyElementwise(...$args);} - public function schurProduct(...$args) {return $this->multiplyElementwise(...$args);} - - public function vectorProduct(Vector $y): Vector { - $x = clone $this; - $y_len = $y->count(); - $x_len = $x->count(); - if ($y_len!=$x_len) { - // throw new \Error('Vector length mismatch: '.$x_len.' expected'); - if ($y_len<$x_len) { - $y = $y->pad($x_len); - $y_len = $y->count(); - } else { - $x = $x->pad($y_len); - $x_len = $x->count(); - } - } - if ($y_len==0) { - // null vector - return new self([]); - } else if ($y_len==1) { - // real number multiplication XXX WRONG!!! collinear vectors cross product gives zero! - // return new self([$x->value[0]->multiply($y-value[0])]); - return new self([0]); - } else if ($y_len==2) { - // 2d vector multiplication - return $x->crossProduct2D($y); - } else if ($y_len==3) { - return $x->crossProduct($y); - } else { - throw new \Error('Vector product not implemented for '.$x_len.' dimensions'); - } - } - - public function crossProduct2D(Vector $y): Vector { - $y_len = $y->count(); - $x_len = $this->count(); - if ($y_len!=2) throw new \Error('Vector expected to be 3D'); - if ($x_len!=$y_len) throw new \Error('Vector length mismatch: '.$x_len.' expected'); - - $determinant = [ - [$this->value[0], $this->value[1]], // [a, b] - [$y->value[0], $y->value[1]], // [c, d] - ]; - // calculates as ad-bc (why?) - // $determinant_calculated = $this->value[0]->multiply($y->value[1])->subtract($this->value[0]->multiply($y->value[1])); - $determinant_calculated = $determinant[0][0]->multiply($determinant[1][1])->subtract($determinant[0][1]->multiply($determinant[1][0])); - // resulting vector pointing in k direction (basis ijk) or z direction (basis xyz) - $z = [0, 0, $determinant_calculated]; - $z = new self($z, $this->inner_type); - - // using formula |c| = |a||b|sin(θ) we can obtain angle too (just for testing) - $x_magnitude = $this->magnitude(); - $y_magnitude = $y->magnitude(); - $z_magnitude = $z->magnitude(); - $sin_theta = $z_magnitude->divide($x_magnitude->multiply($y_magnitude)); - $theta = Math::asin($sin_theta); - print "|c| $z_magnitude = |a| $x_magnitude * |b| $y_magnitude * sin(θ) $sin_theta \n"; - print "angle θ is $theta RAD \n"; - - return $z; - } - - public function crossProduct(Vector $y): Vector { - // Cross product (AxB) - // https://en.wikipedia.org/wiki/Cross_product - - // | i j k | - // A x B = | a₀ a₁ a₂ | = |a₁ a₂| - |a₀ a₂| + |a₀ a₁| - // | b₀ b₁ b₂ | |b₁ b₂|i |b₀ b₂|j |b₀ b₁|k - - // = (a₁b₂ - b₁a₂) - (a₀b₂ - b₀a₂) + (a₀b₁ - b₀a₁) - - $y_len = $y->count(); - $x_len = $this->count(); - if ($y_len!=3) throw new \Error('Vector expected to be 3D'); - if ($x_len!=$y_len) throw new \Error('Vector length mismatch: '.$x_len.' expected'); - - $z = []; - $z[] = $this->value[1]->multiply($y[2])->subtract($this->value[2]->multiply($y[1])); - $z[] = $this->value[0]->multiply($y[2])->subtract($this->value[2]->multiply($y[0]))->invert(); - $z[] = $this->value[0]->multiply($y[1])->subtract($this->value[1]->multiply($y[0])); - - return new self($z, $this->inner_type); - } - public function crossProduct3D(...$args) {return $this->crossProduct(...$args);} - public function cross(...$args) {return $this->crossProduct(...$args);} - public function x(...$args) {return $this->crossProduct(...$args);} - - public function k($y) { - $z = []; - $n = $this->count(); - if ($n) { - foreach ($this->value as $i=>$v) { - $z[] = $v->multiply($y); - } - } - - // return new self($z, Delegator::getType($z[0])); - return new self($z, $this->inner_type); - } - public function coefficient(...$args) {return $this->k(...$args);} - public function times(...$args) {return $this->k(...$args);} - public function scale(...$args) {return $this->k(...$args);} - public function scalarMultiply(...$args) {return $this->k(...$args);} - - public function divide($y) { - $n = $this->count(); - if (empty($n)) { - return new self([]); - } - $yt = Delegator::getType($y); - if ($yt!=self::class) { - if ($yt==self::T_SCALAR) { - return $this->k($y->reciprocal()); - } else { - $y = new self($y, $this->inner_type, $n); - } - } - return $this->divideElementwise($y); - } - - public function divideElementwise(Vector $y): Vector { - $x = clone $this; - $y_len = $y->count(); - $x_len = $this->count(); - if ($y_len>$x_len) {$x = $x->pad($y_len);} - if ($x_len>$y_len) {$y = $y->pad($x_len);} - $z = []; - if ($x->count()) { - foreach ($x->value as $i=>$v) { - $z[] = $v->divide($y[$i]); - } - } - $z = new self($z, $this->inner_type); - $z = $z->cutZeroTail(); - return $z; - } - - public function reciprocal() { - throw new \Error('Not implemented yet'); - } - - public function conjugate() { - throw new \Error('Not implemented yet'); - } - - public function normalize() { - return $this->divide($this->magnitude()); - } - - public function transpose() { - $z = []; - $n = $this->count(); - if ($n) { - foreach ($this->value as $i=>$v) { - $z[$i][0] = $v; - } - } - return Delegator::wrap($z, self::T_MATRIX); - } - - public function invert() { - return $this->k(-1); - } - - public function magnitude() { - // equivalent to finding vector`s absolute length - $magnitude = 0; - if ($this->length) { - foreach ($this->value as $n) { - if (Delegator::isEntity($this->inner_type)) { - $magnitude+=Math::pow($n, 2)->toNumber(); - } else { - $magnitude+=Math::pow($n, 2); - } - } - $magnitude = Math::sqrt($magnitude); - } - return Delegator::wrap($magnitude); - } - - public function abs() { - $magnitude = $this->magnitude(); - return $magnitude; - } - - public function empty() { - return ($this->length==0); - } - - // methods to comply interface \Iterator - - public function current(): mixed { - return (isset($this->value[$this->pointer])? $this->value[$this->pointer]: null); - } - - public function key(): mixed { - return $this->pointer; - } - - public function next(): void { - $this->pointer++; - } - - public function rewind(): void { - $this->pointer = 0; - } - - public function valid(): bool { - return isset($this->value[$this->pointer]); - } - - // methods to comply interface \ArrayAccess - - public function offsetExists($offset): bool { - return isset($this->value[$offset]); - } - - public function offsetGet($offset): mixed { - return (isset($this->value[$offset])? $this->value[$offset]: null); - } - - public function offsetSet($offset, $value): void { - // throw new \Error('Immutable object'); - $type = Delegator::getType($value); - if ($type!=$this->inner_type) { - throw new \Error('Type mismatch: '.$this->inner_type.' expected'); - } - $this->value[$offset] = $value; - $this->length = count($this->value); - } - - public function offsetUnset($offset): void { - // throw new \Error('Immutable object'); - unset($this->value[$offset]); - $this->length = count($this->value); - } - - // methods to comply interface \Countable - - public function count(): int { - $n = count($this->value); - $this->length = $n; - return $this->length; - } -} +value = []; + $arr_type = Delegator::getType($array); + if (Delegator::isEntity($array)) { + $math_object = $array; + if ($arr_type==self::class) { + $this->value = $math_object->toArray(); + } else if (Delegator::hasMethod($math_object, 'toVector')) { + $this->value = $math_object->toVector()->toArray(); + } else { + $this->value = [$math_object]; + } + } else if (is_array($array)) { + $this->value = $array; + } else { + throw new \TypeError("Unrecognized type of argument"); + } + + if ($pad_to_length) { + $curr_length = count($this->value); + if ($pad_to_length>$curr_length) { + $n_elements_left = $pad_to_length-$curr_length; + while($n_elements_left) { + $this->value[] = ($type? Delegator::wrap(0, $type): 0); + $n_elements_left--; + } + } + } + $this->length = count($this->value); + + if ($type) { + $this->inner_type = $type; + // set specified type for all elements + foreach ($this->value as $i=>$el) { + $this->value[$i] = Delegator::wrap($el, $type); + } + } else { + if ($this->length) { + $this->inner_type = Delegator::getType($this->value[0]); + } + } + } + + public function __toString() { + return '['.implode(', ', $this->value).']'; + } + + public function toNumber() { + return $this->magnitude()->toNumber(); + } + + public function toArray() { + return $this->value; + } + + public function isVector() { + return ($this::class==self::class); + } + + public function pad(int $length): Vector { + /* $x_len = $this->count(); + $arr = $this->value; + while ($x_len<$length) { + $arr[] = Delegator::wrap(0, $this->inner_type); + } + return new self($arr, $this->inner_type); */ + return new self($this->value, $this->inner_type, $length); + } + + public function slice(int $length): Vector { + $z = new self(array_slice($this->value, 0, $length), $this->inner_type); + $z->count(); + return $z; + } + + public function cutZeroTail(): Vector { + $z = $this->value; + // print "cutZeroTail $this \n"; + while (count($z)) { + $v = end($z); + if ($v===false) {break;} + if (($v===0) || (Delegator::isEntity($v) && $v->empty())) { + array_pop($z); + } else { + break; + } + } + return new self($z, $this->inner_type); + } + + public function align($y) { + $x = clone $this; + // print "align $x and $y \n"; + $x = $x->cutZeroTail(); + $y = $y->cutZeroTail(); + $x_len = $x->count(); + $y_len = $y->count(); + // print "$y_len!=$x_len \n"; + if ($y_len<$x_len) { + $y = $y->pad($x_len); + } else if ($y_len>$x_len) { + $x = $x->pad($y_len); + } + return [$x, $y]; + } + + public function as($type) { + return new self($this->value, $type); + } + + public function add($y) { + // equivalent to finding diagonal end point coords of parallelogram formed by two vectors placed at 0 point at cartegian coordinate system + if (Delegator::getType($y)!=self::class) $y = new self($y, $this->inner_type, $this->length); + $x = clone $this; + $z = []; + + if ($y->length!=$x->length) { + // throw new \Error('Mismatch of the vectors length'); + // print "vector add mismatch $x + $y\n"; + list($x, $y) = $x->align($y); + } + // print "vector add $x + $y\n"; + + foreach ($x as $i=>$v) { + $z[] = $v->add($y[$i]); + } + $z = new self($z, $this->inner_type); + + return $z; + } + + public function subtract($y) { + // equivalent to finding vector as diagonal of parallelogram of vector and inverted vector + // equivalent to finding vector coords subtracting its initial coords + if (Delegator::getType($y)!=self::class) $y = new self($y, $this->inner_type, $this->length); + $x = clone $this; + $z = []; + + if ($y->length!=$x->length) { + throw new \Error('Mismatch of the vectors length'); + } + + foreach ($x as $i=>$v) { + $z[] = $v->subtract($y[$i]); + } + $z = new self($z, $this->inner_type); + + return $z; + } + + // scale vector using scalar scalarMultiply() (not scalar product!), k(), coefficient(), times(), scale() + // dot product ·→ aliases is dotProduct(), scalarProduct(), innerProduct(), dot() ***exclude scalarProduct() to avoid ambiquity + // Hadamard product ⊙→ aliases is multiplyElementwise(), hadamardProduct(), schurProduct() + // cross product ⨯→ aliases is crossProduct(), vectorProduct(), cross(), x() + // direct product ⊗→ (Kroneker product with transponed matrix) directProduct() + // Kronecker product ⊗→ aliases is kroneckerProduct(), tensorProduct(), matrixDirectProduct() + // exterior product is exteriorProduct(); + + public function dotProduct($y) { + // In mathematics, the dot product or scalar product is an algebraic operation that takes two equal-length sequences of numbers (usually coordinate vectors), and returns a single number. + // Algebraically, the dot product is the sum of the products of the corresponding entries of the two sequences of numbers. + // Geometrically, it is the product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them. + + // These definitions are equivalent when using Cartesian coordinates: + // →a · →b = ∑ (î₁î₂, ĵ₁ĵ₂, …, k₁k₂) ⇔ →a · →b = |a||b|cos(θ) + // θ is an angle between a & b + // cos(θ) is x/r = adjacent / hipotenuse + // assuming x is a (adjacent) and r is b (hipotenuse), projection of b to a will be hipotenuse * (adjacent / hipotenuse) = |b|*cos(θ) = b' + // projection of a to b is |a|*cos(θ) = a' + // so, basically, scalar product of two vectors is magnitude(a) times projection(b to a) => |a| * b' + // cos(θ) = b' / |b| = ( |b| * (a' / |a|) ) / |b| = a' / |a| + // |b|cos(θ) = |b| * ( a' / |a| ) + // →a · →b = |a| * |b| * ( a' / |a| ) = |a||b|a' / |a| = |b|*a' ⇔ |a|*b' + // a' = ( →a · →b ) / |b| = →a · →b₁ where →b₁ is Unit vector of b + + // any vector can be presented as a sum of unary vectors i, j, k, l, m, ... each multiplied by scalar koefficient + // →a = [X, Y, Z, W, U, ...] = X*→i + Y*→j + Z*→k + W*→l + U*→m + ... + // →b = Oi, Pj, Qk, Rl, Sm, ... = [O, P, Q, R, S, ...] + // since scalar product of two vectors is magnitude(a) times projection(b to a) + // →a · →b = |a||b|cos(θ) + // lets get →a vector components by multiplying →a · →i , considering |a||i|cos(φî) = |a|*1*cos(φî) = |a|cos(φî) = a'î = X + // (→a · →i + →a · →j + ...) = ∑ (X, Y, Z, W, U, ...) = →a · →basis + // lets get →b vector components by multiplying →b · →i , considering |b||i|cos(γî) = |b|*1*cos(γî) = |b|cos(γî) = b'î = O + // (→b · →i + →b · →j + ...) = ∑ (O, P, Q, R, S, ...) = →b · →basis + // →a · →b · →basis = (→a · →b · →i + →a · →b · →j + ...) = (a'î * b'î + a'î * b'î + ...) = (XO + YP + ZQ + ...) + + // https://en.wikipedia.org/wiki/Dot_product + // https://mathworld.wolfram.com/DotProduct.html + + $n = $this->count(); + if (empty($n)) {return 0;} + if (Delegator::getType($y)!=self::class) { + $y = new self($y, $this->inner_type, $n); + } + $y = $y->toArray(); + $x = $this->value; + $z = Delegator::wrap(0); + + foreach ($x as $i=>$v) { + $z = $z->add($v->multiply($y[$i])); + } + + return $z; + } + public function dot(...$args) {return $this->dotProduct(...$args);} + // public function innerProduct(...$args) {return $this->dotProduct(...$args);} // excluded not to mess with Hermitian inner product or inner product via conjugation a.b = Conjugate[a].b + // public function scalarProduct(...$args) {return $this->dotProduct(...$args);} // excluded not to mess with scalar multiplication + + public function multiply($y) { + $n = $this->count(); + if (empty($n)) { + return new self([]); + } + $yt = Delegator::getType($y); + if ($yt!=self::class) { + // if ($yt==self::T_SCALAR) { + if (Delegator::isEntity($y) && !Delegator::implements($y, 'Traversable')) { + return $this->k($y); + } else { + $y = new self($y, $this->inner_type, $n); + } + } + // return $this->vectorProduct($y); + return $this->multiplyElementwise($y); + } + + public function multiplyElementwise(Vector $y): Vector { + $x = clone $this; + $y_len = $y->count(); + $x_len = $this->count(); + // if ($y_len>$x_len) {$x = $x->pad($y_len);} + // if ($x_len>$y_len) {$y = $y->pad($x_len);} + if ($y_len>$x_len) {$y = $y->slice($x_len);} + if ($x_len>$y_len) {$x = $x->slice($y_len);} + $z = []; + if ($x->count()) { + foreach ($x->value as $i=>$v) { + $z[] = $v->multiply($y[$i]); + } + } + $z = new self($z, $this->inner_type); + $z = $z->cutZeroTail(); + return $z; + } + public function hadamardProduct(...$args) {return $this->multiplyElementwise(...$args);} + public function schurProduct(...$args) {return $this->multiplyElementwise(...$args);} + + public function vectorProduct(Vector $y): Vector { + $x = clone $this; + $y_len = $y->count(); + $x_len = $x->count(); + if ($y_len!=$x_len) { + // throw new \Error('Vector length mismatch: '.$x_len.' expected'); + if ($y_len<$x_len) { + $y = $y->pad($x_len); + $y_len = $y->count(); + } else { + $x = $x->pad($y_len); + $x_len = $x->count(); + } + } + if ($y_len==0) { + // null vector + return new self([]); + } else if ($y_len==1) { + // real number multiplication XXX WRONG!!! collinear vectors cross product gives zero! + // return new self([$x->value[0]->multiply($y-value[0])]); + return new self([0]); + } else if ($y_len==2) { + // 2d vector multiplication + return $x->crossProduct2D($y); + } else if ($y_len==3) { + return $x->crossProduct($y); + } else { + throw new \Error('Vector product not implemented for '.$x_len.' dimensions'); + } + } + + public function crossProduct2D(Vector $y): Vector { + $y_len = $y->count(); + $x_len = $this->count(); + if ($y_len!=2) throw new \Error('Vector expected to be 3D'); + if ($x_len!=$y_len) throw new \Error('Vector length mismatch: '.$x_len.' expected'); + + $determinant = [ + [$this->value[0], $this->value[1]], // [a, b] + [$y->value[0], $y->value[1]], // [c, d] + ]; + // calculates as ad-bc (why?) + // $determinant_calculated = $this->value[0]->multiply($y->value[1])->subtract($this->value[0]->multiply($y->value[1])); + $determinant_calculated = $determinant[0][0]->multiply($determinant[1][1])->subtract($determinant[0][1]->multiply($determinant[1][0])); + // resulting vector pointing in k direction (basis ijk) or z direction (basis xyz) + $z = [0, 0, $determinant_calculated]; + $z = new self($z, $this->inner_type); + + // using formula |c| = |a||b|sin(θ) we can obtain angle too (just for testing) + $x_magnitude = $this->magnitude(); + $y_magnitude = $y->magnitude(); + $z_magnitude = $z->magnitude(); + $sin_theta = $z_magnitude->divide($x_magnitude->multiply($y_magnitude)); + $theta = Math::asin($sin_theta); + print "|c| $z_magnitude = |a| $x_magnitude * |b| $y_magnitude * sin(θ) $sin_theta \n"; + print "angle θ is $theta RAD \n"; + + return $z; + } + + public function crossProduct(Vector $y): Vector { + // Cross product (AxB) + // https://en.wikipedia.org/wiki/Cross_product + + // | i j k | + // A x B = | a₀ a₁ a₂ | = |a₁ a₂| - |a₀ a₂| + |a₀ a₁| + // | b₀ b₁ b₂ | |b₁ b₂|i |b₀ b₂|j |b₀ b₁|k + + // = (a₁b₂ - b₁a₂) - (a₀b₂ - b₀a₂) + (a₀b₁ - b₀a₁) + + $y_len = $y->count(); + $x_len = $this->count(); + if ($y_len!=3) throw new \Error('Vector expected to be 3D'); + if ($x_len!=$y_len) throw new \Error('Vector length mismatch: '.$x_len.' expected'); + + $z = []; + $z[] = $this->value[1]->multiply($y[2])->subtract($this->value[2]->multiply($y[1])); + $z[] = $this->value[0]->multiply($y[2])->subtract($this->value[2]->multiply($y[0]))->invert(); + $z[] = $this->value[0]->multiply($y[1])->subtract($this->value[1]->multiply($y[0])); + + return new self($z, $this->inner_type); + } + public function crossProduct3D(...$args) {return $this->crossProduct(...$args);} + public function cross(...$args) {return $this->crossProduct(...$args);} + public function x(...$args) {return $this->crossProduct(...$args);} + + public function k($y) { + $z = []; + $n = $this->count(); + if ($n) { + foreach ($this->value as $i=>$v) { + $z[] = $v->multiply($y); + } + } + + // return new self($z, Delegator::getType($z[0])); + return new self($z, $this->inner_type); + } + public function coefficient(...$args) {return $this->k(...$args);} + public function times(...$args) {return $this->k(...$args);} + public function scale(...$args) {return $this->k(...$args);} + public function scalarMultiply(...$args) {return $this->k(...$args);} + + public function divide($y) { + $n = $this->count(); + if (empty($n)) { + return new self([]); + } + $yt = Delegator::getType($y); + if ($yt!=self::class) { + if ($yt==self::T_SCALAR) { + return $this->k($y->reciprocal()); + } else { + $y = new self($y, $this->inner_type, $n); + } + } + return $this->divideElementwise($y); + } + + public function divideElementwise(Vector $y): Vector { + $x = clone $this; + $y_len = $y->count(); + $x_len = $this->count(); + if ($y_len>$x_len) {$x = $x->pad($y_len);} + if ($x_len>$y_len) {$y = $y->pad($x_len);} + $z = []; + if ($x->count()) { + foreach ($x->value as $i=>$v) { + $z[] = $v->divide($y[$i]); + } + } + $z = new self($z, $this->inner_type); + $z = $z->cutZeroTail(); + return $z; + } + + public function reciprocal() { + throw new \Error('Not implemented yet'); + } + + public function conjugate() { + throw new \Error('Not implemented yet'); + } + + public function normalize() { + return $this->divide($this->magnitude()); + } + + public function transpose() { + $z = []; + $n = $this->count(); + if ($n) { + foreach ($this->value as $i=>$v) { + $z[$i][0] = $v; + } + } + return Delegator::wrap($z, self::T_MATRIX); + } + + public function invert() { + return $this->k(-1); + } + + public function magnitude() { + // equivalent to finding vector`s absolute length + $magnitude = 0; + if ($this->length) { + foreach ($this->value as $n) { + if (Delegator::isEntity($this->inner_type)) { + $magnitude+=Math::pow($n, 2)->toNumber(); + } else { + $magnitude+=Math::pow($n, 2); + } + } + $magnitude = Math::sqrt($magnitude); + } + return Delegator::wrap($magnitude); + } + + public function abs() { + $magnitude = $this->magnitude(); + return $magnitude; + } + + public function empty() { + return ($this->length==0); + } + + // methods to comply interface \Iterator + + public function current(): mixed { + return (isset($this->value[$this->pointer])? $this->value[$this->pointer]: null); + } + + public function key(): mixed { + return $this->pointer; + } + + public function next(): void { + $this->pointer++; + } + + public function rewind(): void { + $this->pointer = 0; + } + + public function valid(): bool { + return isset($this->value[$this->pointer]); + } + + // methods to comply interface \ArrayAccess + + public function offsetExists($offset): bool { + return isset($this->value[$offset]); + } + + public function offsetGet($offset): mixed { + return (isset($this->value[$offset])? $this->value[$offset]: null); + } + + public function offsetSet($offset, $value): void { + // throw new \Error('Immutable object'); + $type = Delegator::getType($value); + if ($type!=$this->inner_type) { + throw new \Error('Type mismatch: '.$this->inner_type.' expected'); + } + $this->value[$offset] = $value; + $this->length = count($this->value); + } + + public function offsetUnset($offset): void { + // throw new \Error('Immutable object'); + unset($this->value[$offset]); + $this->length = count($this->value); + } + + // methods to comply interface \Countable + + public function count(): int { + $n = count($this->value); + $this->length = $n; + return $this->length; + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Math/Math.php b/src/Math/Math.php similarity index 96% rename from vendor/irrevion/science/Math/Math.php rename to src/Math/Math.php index 7769ffe..a2fabd1 100644 --- a/vendor/irrevion/science/Math/Math.php +++ b/src/Math/Math.php @@ -1,89 +1,89 @@ -abs(); - } else { - throw new \Error("Method not implemented by Entity"); - } - } - } else if (is_numeric($x)) { - return parent::abs($x); - } else { - return null; - } - } - - public static function asin($x) { - if (Delegator::isEntity($x)) { - $x = $x->toNumber(); - } - return parent::asin($x); - } - - public static function compare(float $x=0.0, string $rel='==', float $y=1e-12) { - if (Delegator::isEntity($x)) {$x = $x->toNumber();} - if (Delegator::isEntity($y)) {$y = $y->toNumber();} - return parent::compare($x, $rel, $y); - } - - public static function pow($base, $exponent = 1) { - $exponent = $exponent * 1; - - if (is_object($base)) { - if (Delegator::isEntity($base)) { - if (method_exists($base, 'pow')) { - return $x->pow($exponent); - } else { - if ($exponent==0) { - // x^0 = 1 - return Delegator::wrap(1); - } else if ($exponent==1) { - // x^1 = x - return $base; - // } else if (($exponent>0) && !($exponent%1)) { - } else if (($exponent>0) && !self::fmod($exponent, 1)) { - // x^{2, 3, ... , Integer max} - return $base->multiply(self::pow($base, $exponent-1)); - } else if (($exponent<0) && !self::fmod($exponent, 1)) { - // x^{-1, -2, -3, ... , Integer min} - return Delegator::wrap(1)->divide(self::pow($base, self::abs($exponent))); - } else { - throw new \ArithmeticError("Method not implemented by Entity"); - } - } - } - } else if (is_numeric($base)) { - $result = parent::pow($base, $exponent); - return (is_nan($result)? null: $result); - } else { - return null; - } - } - - public static function sum($array, $wrap=null) { - $res = 0; - if (count($array)) { - if (Delegator::isEntity($array[0])) { - $res = Delegator::wrap($res, Delegator::getType($array[0])); - foreach ($array as $value) { - $res = $res->add($value); - } - } else { - $res = parent::sum($array); - } - } - if (!empty($wrap)) { - Delegator::wrap($res, $wrap); - } - return $res; - } -} +abs(); + } else { + throw new \Error("Method not implemented by Entity"); + } + } + } else if (is_numeric($x)) { + return parent::abs($x); + } else { + return null; + } + } + + public static function asin($x) { + if (Delegator::isEntity($x)) { + $x = $x->toNumber(); + } + return parent::asin($x); + } + + public static function compare(float $x=0.0, string $rel='==', float $y=1e-12) { + if (Delegator::isEntity($x)) {$x = $x->toNumber();} + if (Delegator::isEntity($y)) {$y = $y->toNumber();} + return parent::compare($x, $rel, $y); + } + + public static function pow($base, $exponent = 1) { + $exponent = $exponent * 1; + + if (is_object($base)) { + if (Delegator::isEntity($base)) { + if (method_exists($base, 'pow')) { + return $x->pow($exponent); + } else { + if ($exponent==0) { + // x^0 = 1 + return Delegator::wrap(1); + } else if ($exponent==1) { + // x^1 = x + return $base; + // } else if (($exponent>0) && !($exponent%1)) { + } else if (($exponent>0) && !self::fmod($exponent, 1)) { + // x^{2, 3, ... , Integer max} + return $base->multiply(self::pow($base, $exponent-1)); + } else if (($exponent<0) && !self::fmod($exponent, 1)) { + // x^{-1, -2, -3, ... , Integer min} + return Delegator::wrap(1)->divide(self::pow($base, self::abs($exponent))); + } else { + throw new \ArithmeticError("Method not implemented by Entity"); + } + } + } + } else if (is_numeric($base)) { + $result = parent::pow($base, $exponent); + return (is_nan($result)? null: $result); + } else { + return null; + } + } + + public static function sum($array, $wrap=null) { + $res = 0; + if (count($array)) { + if (Delegator::isEntity($array[0])) { + $res = Delegator::wrap($res, Delegator::getType($array[0])); + foreach ($array as $value) { + $res = $res->add($value); + } + } else { + $res = parent::sum($array); + } + } + if (!empty($wrap)) { + Delegator::wrap($res, $wrap); + } + return $res; + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Math/Operations/Delegator.php b/src/Math/Operations/Delegator.php similarity index 97% rename from vendor/irrevion/science/Math/Operations/Delegator.php rename to src/Math/Operations/Delegator.php index adbd19f..a006b3c 100644 --- a/vendor/irrevion/science/Math/Operations/Delegator.php +++ b/src/Math/Operations/Delegator.php @@ -1,77 +1,77 @@ -implementsInterface(self::ENTITY); - return $is_entity; - } else if (is_string($x)) { - if (!class_exists($x)) {return false;} - $class_reflection = new \ReflectionClass($x); - $is_entity = $class_reflection->implementsInterface(self::ENTITY); - return $is_entity; - } - return false; - } - - public static function implements($object, $any_of_interfaces=[]) { - if (!is_object($object)) {return false;} - if (!is_array($any_of_interfaces)) {$any_of_interfaces = [$any_of_interfaces];} - $instance_of = $object::class; - $class_reflection = new \ReflectionClass($instance_of); - foreach ($any_of_interfaces as $I) { - if ($class_reflection->implementsInterface($I)) {return true;} - } - return false; - } - - public static function hasMethod($x, $method_name) { - if (!self::isEntity($x)) return false; - if (method_exists($x, $method_name)) return true; - return false; - } - - public static function getType($x) { - $type = gettype($x); - if ($type=="object") { - $type = $x::class; - } - return $type; - } - - public static function getSuperset($x, $y) { - if (!self::isEntity($x)) return null; - if (!self::isEntity($y)) return null; - $superX = (empty($x->subset_of)? []: $x->subset_of); - $superY = (empty($y->subset_of)? []: $y->subset_of); - $supersets = array_intersect($superX, $superY); - if (count($supersets)) return $supersets[0]; - return null; - } - - public static function delegate($operation, $x, $y) { - $superset = self::getSuperset($x, $y); - if (empty($superset)) throw new \ArithmeticError("This entities are incompatible"); - if (!class_exists($superset)) throw new \ArithmeticError("Invalid superset name $superset"); - if (!self::hasMethod($superset, $operation)) throw new \ArithmeticError("Invalid operation to delegate in $superset"); - if (Delegator::getType($x)!=$superset) {$x = self::wrap($x, $superset);} - if (Delegator::getType($y)!=$superset) {$y = self::wrap($y, $superset);} - $z = $x->$operation($y); - return $z; - } - - public static function wrap($x, $to_superset=null) { - if (empty($to_superset)) {$to_superset = self::ENTITY_SCALAR;} - if (self::getType($x)==$to_superset) {return $x;} - // print "wrap ".var_export($x, 1)." to {$to_superset} \n"; - $class_reflection = new \ReflectionClass($to_superset); - return $class_reflection->newInstance($x); - } -} +implementsInterface(self::ENTITY); + return $is_entity; + } else if (is_string($x)) { + if (!class_exists($x)) {return false;} + $class_reflection = new \ReflectionClass($x); + $is_entity = $class_reflection->implementsInterface(self::ENTITY); + return $is_entity; + } + return false; + } + + public static function implements($object, $any_of_interfaces=[]) { + if (!is_object($object)) {return false;} + if (!is_array($any_of_interfaces)) {$any_of_interfaces = [$any_of_interfaces];} + $instance_of = $object::class; + $class_reflection = new \ReflectionClass($instance_of); + foreach ($any_of_interfaces as $I) { + if ($class_reflection->implementsInterface($I)) {return true;} + } + return false; + } + + public static function hasMethod($x, $method_name) { + if (!self::isEntity($x)) return false; + if (method_exists($x, $method_name)) return true; + return false; + } + + public static function getType($x) { + $type = gettype($x); + if ($type=="object") { + $type = $x::class; + } + return $type; + } + + public static function getSuperset($x, $y) { + if (!self::isEntity($x)) return null; + if (!self::isEntity($y)) return null; + $superX = (empty($x->subset_of)? []: $x->subset_of); + $superY = (empty($y->subset_of)? []: $y->subset_of); + $supersets = array_intersect($superX, $superY); + if (count($supersets)) return $supersets[0]; + return null; + } + + public static function delegate($operation, $x, $y) { + $superset = self::getSuperset($x, $y); + if (empty($superset)) throw new \ArithmeticError("This entities are incompatible"); + if (!class_exists($superset)) throw new \ArithmeticError("Invalid superset name $superset"); + if (!self::hasMethod($superset, $operation)) throw new \ArithmeticError("Invalid operation to delegate in $superset"); + if (Delegator::getType($x)!=$superset) {$x = self::wrap($x, $superset);} + if (Delegator::getType($y)!=$superset) {$y = self::wrap($y, $superset);} + $z = $x->$operation($y); + return $z; + } + + public static function wrap($x, $to_superset=null) { + if (empty($to_superset)) {$to_superset = self::ENTITY_SCALAR;} + if (self::getType($x)==$to_superset) {return $x;} + // print "wrap ".var_export($x, 1)." to {$to_superset} \n"; + $class_reflection = new \ReflectionClass($to_superset); + return $class_reflection->newInstance($x); + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Math/Transformations/Matrix.php b/src/Math/Transformations/Matrix.php similarity index 100% rename from vendor/irrevion/science/Math/Transformations/Matrix.php rename to src/Math/Transformations/Matrix.php diff --git a/vendor/irrevion/science/Math/Transformations/Transformation.php b/src/Math/Transformations/Transformation.php similarity index 100% rename from vendor/irrevion/science/Math/Transformations/Transformation.php rename to src/Math/Transformations/Transformation.php diff --git a/vendor/irrevion/science/Physics/Branches/Mech.php b/src/Physics/Branches/Mech.php similarity index 100% rename from vendor/irrevion/science/Physics/Branches/Mech.php rename to src/Physics/Branches/Mech.php diff --git a/vendor/irrevion/science/Physics/Branches/QCD.php b/src/Physics/Branches/QCD.php similarity index 100% rename from vendor/irrevion/science/Physics/Branches/QCD.php rename to src/Physics/Branches/QCD.php diff --git a/vendor/irrevion/science/Physics/Branches/QED.php b/src/Physics/Branches/QED.php similarity index 100% rename from vendor/irrevion/science/Physics/Branches/QED.php rename to src/Physics/Branches/QED.php diff --git a/vendor/irrevion/science/Physics/Branches/QFT.php b/src/Physics/Branches/QFT.php similarity index 100% rename from vendor/irrevion/science/Physics/Branches/QFT.php rename to src/Physics/Branches/QFT.php diff --git a/vendor/irrevion/science/Physics/Branches/Quantum.php b/src/Physics/Branches/Quantum.php similarity index 100% rename from vendor/irrevion/science/Physics/Branches/Quantum.php rename to src/Physics/Branches/Quantum.php diff --git a/vendor/irrevion/science/Physics/Branches/Relativity.php b/src/Physics/Branches/Relativity.php similarity index 97% rename from vendor/irrevion/science/Physics/Branches/Relativity.php rename to src/Physics/Branches/Relativity.php index 289897e..dc0e37d 100644 --- a/vendor/irrevion/science/Physics/Branches/Relativity.php +++ b/src/Physics/Branches/Relativity.php @@ -1,16 +1,16 @@ - \ No newline at end of file diff --git a/vendor/irrevion/science/Physics/Entities/Particles/Electron.php b/src/Physics/Entities/Particles/Electron.php similarity index 98% rename from vendor/irrevion/science/Physics/Entities/Particles/Electron.php rename to src/Physics/Entities/Particles/Electron.php index 337b0cc..6a4631e 100644 --- a/vendor/irrevion/science/Physics/Entities/Particles/Electron.php +++ b/src/Physics/Entities/Particles/Electron.php @@ -1,25 +1,25 @@ - \ No newline at end of file diff --git a/vendor/irrevion/science/Physics/Entities/Quantity.php b/src/Physics/Entities/Quantity.php similarity index 95% rename from vendor/irrevion/science/Physics/Entities/Quantity.php rename to src/Physics/Entities/Quantity.php index 1e2dcd5..bb6e2a3 100644 --- a/vendor/irrevion/science/Physics/Entities/Quantity.php +++ b/src/Physics/Entities/Quantity.php @@ -1,40 +1,40 @@ -value = $value; - $unit = Physics::unit($unit); - $this->unit = $unit; - } - - public function __toString() { - return "{$this->value} {$this->unit['measure']}"; - } - - public function toNumber() { - return $this->value; - } - - public function convert($to) { - return Physics::convert($this, $to); - } - - public function i($const='') { - // $reflection = new \ReflectionClass($this->unit); - // $reflection = $this->unit; - // if (empty($const)) { - // return $reflection; - // } - // return $reflection->getConstant($const); - - return (empty($const)? $this->unit: $this->unit[$const]); - } -} +value = $value; + $unit = Physics::unit($unit); + $this->unit = $unit; + } + + public function __toString() { + return "{$this->value} {$this->unit['measure']}"; + } + + public function toNumber() { + return $this->value; + } + + public function convert($to) { + return Physics::convert($this, $to); + } + + public function i($const='') { + // $reflection = new \ReflectionClass($this->unit); + // $reflection = $this->unit; + // if (empty($const)) { + // return $reflection; + // } + // return $reflection->getConstant($const); + + return (empty($const)? $this->unit: $this->unit[$const]); + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Physics/Physics.php b/src/Physics/Physics.php similarity index 100% rename from vendor/irrevion/science/Physics/Physics.php rename to src/Physics/Physics.php diff --git a/vendor/irrevion/science/Physics/Unit/CGS.php b/src/Physics/Unit/CGS.php similarity index 96% rename from vendor/irrevion/science/Physics/Unit/CGS.php rename to src/Physics/Unit/CGS.php index c3e94be..f44e69e 100644 --- a/vendor/irrevion/science/Physics/Unit/CGS.php +++ b/src/Physics/Unit/CGS.php @@ -1,19 +1,19 @@ -value); - if (empty($const)) { - return $reflection; - } - return $reflection->getConstant($const); - } -} +value); + if (empty($const)) { + return $reflection; + } + return $reflection->getConstant($const); + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Physics/Unit/Categories.php b/src/Physics/Unit/Categories.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Categories.php rename to src/Physics/Unit/Categories.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/AbAmpere.php b/src/Physics/Unit/Entities/AbAmpere.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/AbAmpere.php rename to src/Physics/Unit/Entities/AbAmpere.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Ampere.php b/src/Physics/Unit/Entities/Ampere.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Ampere.php rename to src/Physics/Unit/Entities/Ampere.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Angle.php b/src/Physics/Unit/Entities/Angle.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Angle.php rename to src/Physics/Unit/Entities/Angle.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/AstronomicalUnit.php b/src/Physics/Unit/Entities/AstronomicalUnit.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/AstronomicalUnit.php rename to src/Physics/Unit/Entities/AstronomicalUnit.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Brightness.php b/src/Physics/Unit/Entities/Brightness.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Brightness.php rename to src/Physics/Unit/Entities/Brightness.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/CGS.php b/src/Physics/Unit/Entities/CGS.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/CGS.php rename to src/Physics/Unit/Entities/CGS.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Candela.php b/src/Physics/Unit/Entities/Candela.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Candela.php rename to src/Physics/Unit/Entities/Candela.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Celsius.php b/src/Physics/Unit/Entities/Celsius.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Celsius.php rename to src/Physics/Unit/Entities/Celsius.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Degree.php b/src/Physics/Unit/Entities/Degree.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Degree.php rename to src/Physics/Unit/Entities/Degree.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/ElectricCurrent.php b/src/Physics/Unit/Entities/ElectricCurrent.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/ElectricCurrent.php rename to src/Physics/Unit/Entities/ElectricCurrent.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/ElectricTension.php b/src/Physics/Unit/Entities/ElectricTension.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/ElectricTension.php rename to src/Physics/Unit/Entities/ElectricTension.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/ElectronMass.php b/src/Physics/Unit/Entities/ElectronMass.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/ElectronMass.php rename to src/Physics/Unit/Entities/ElectronMass.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/ElectronVolt.php b/src/Physics/Unit/Entities/ElectronVolt.php similarity index 96% rename from vendor/irrevion/science/Physics/Unit/Entities/ElectronVolt.php rename to src/Physics/Unit/Entities/ElectronVolt.php index 3d87847..5525c7c 100644 --- a/vendor/irrevion/science/Physics/Unit/Entities/ElectronVolt.php +++ b/src/Physics/Unit/Entities/ElectronVolt.php @@ -7,7 +7,7 @@ class ElectronVolt implements Energy, NonStandard { // const category = 'energy'; // defined by interface // const unit_system = 'NonStandart'; // defined by interface const measure = 'eV'; - const reference = 1; + const reference = 1.602176634e-19; const reference_measure = 'J'; const alias = 'E'; const descr = 'In physics, an electronvolt (symbol eV, also written electron-volt and electron volt) is the measure of an amount of kinetic energy gained by a single electron accelerating from rest through an electric potential difference of one volt in vacuum. When used as a unit of energy, the numerical value of 1 eV in joules (symbol J) is equivalent to the numerical value of the charge of an electron in coulombs (symbol C). Under the 2019 redefinition of the SI base units, this sets 1 eV equal to the exact value 1.602176634×10−19 J.'; diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Energy.php b/src/Physics/Unit/Entities/Energy.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Energy.php rename to src/Physics/Unit/Entities/Energy.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Fahrenheit.php b/src/Physics/Unit/Entities/Fahrenheit.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Fahrenheit.php rename to src/Physics/Unit/Entities/Fahrenheit.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/IAU.php b/src/Physics/Unit/Entities/IAU.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/IAU.php rename to src/Physics/Unit/Entities/IAU.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Imperial.php b/src/Physics/Unit/Entities/Imperial.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Imperial.php rename to src/Physics/Unit/Entities/Imperial.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Joule.php b/src/Physics/Unit/Entities/Joule.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Joule.php rename to src/Physics/Unit/Entities/Joule.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Kelvin.php b/src/Physics/Unit/Entities/Kelvin.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Kelvin.php rename to src/Physics/Unit/Entities/Kelvin.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Kilogram.php b/src/Physics/Unit/Entities/Kilogram.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Kilogram.php rename to src/Physics/Unit/Entities/Kilogram.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Length.php b/src/Physics/Unit/Entities/Length.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Length.php rename to src/Physics/Unit/Entities/Length.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/LightYear.php b/src/Physics/Unit/Entities/LightYear.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/LightYear.php rename to src/Physics/Unit/Entities/LightYear.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/LuminousIntensity.php b/src/Physics/Unit/Entities/LuminousIntensity.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/LuminousIntensity.php rename to src/Physics/Unit/Entities/LuminousIntensity.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Mass.php b/src/Physics/Unit/Entities/Mass.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Mass.php rename to src/Physics/Unit/Entities/Mass.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Metre.php b/src/Physics/Unit/Entities/Metre.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Metre.php rename to src/Physics/Unit/Entities/Metre.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Mole.php b/src/Physics/Unit/Entities/Mole.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Mole.php rename to src/Physics/Unit/Entities/Mole.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Nit.php b/src/Physics/Unit/Entities/Nit.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Nit.php rename to src/Physics/Unit/Entities/Nit.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/NonStandard.php b/src/Physics/Unit/Entities/NonStandard.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/NonStandard.php rename to src/Physics/Unit/Entities/NonStandard.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Parsec.php b/src/Physics/Unit/Entities/Parsec.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Parsec.php rename to src/Physics/Unit/Entities/Parsec.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Planck.php b/src/Physics/Unit/Entities/Planck.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Planck.php rename to src/Physics/Unit/Entities/Planck.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/PlanckLength.php b/src/Physics/Unit/Entities/PlanckLength.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/PlanckLength.php rename to src/Physics/Unit/Entities/PlanckLength.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/PlanckTime.php b/src/Physics/Unit/Entities/PlanckTime.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/PlanckTime.php rename to src/Physics/Unit/Entities/PlanckTime.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Pound.php b/src/Physics/Unit/Entities/Pound.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Pound.php rename to src/Physics/Unit/Entities/Pound.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Radian.php b/src/Physics/Unit/Entities/Radian.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Radian.php rename to src/Physics/Unit/Entities/Radian.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Rankine.php b/src/Physics/Unit/Entities/Rankine.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Rankine.php rename to src/Physics/Unit/Entities/Rankine.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/SI.php b/src/Physics/Unit/Entities/SI.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/SI.php rename to src/Physics/Unit/Entities/SI.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Second.php b/src/Physics/Unit/Entities/Second.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Second.php rename to src/Physics/Unit/Entities/Second.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/SolarMass.php b/src/Physics/Unit/Entities/SolarMass.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/SolarMass.php rename to src/Physics/Unit/Entities/SolarMass.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/StatAmpere.php b/src/Physics/Unit/Entities/StatAmpere.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/StatAmpere.php rename to src/Physics/Unit/Entities/StatAmpere.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/StatVolt.php b/src/Physics/Unit/Entities/StatVolt.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/StatVolt.php rename to src/Physics/Unit/Entities/StatVolt.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Stilb.php b/src/Physics/Unit/Entities/Stilb.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Stilb.php rename to src/Physics/Unit/Entities/Stilb.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/SubstanceAmount.php b/src/Physics/Unit/Entities/SubstanceAmount.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/SubstanceAmount.php rename to src/Physics/Unit/Entities/SubstanceAmount.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Temperature.php b/src/Physics/Unit/Entities/Temperature.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Temperature.php rename to src/Physics/Unit/Entities/Temperature.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Time.php b/src/Physics/Unit/Entities/Time.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Time.php rename to src/Physics/Unit/Entities/Time.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/USC.php b/src/Physics/Unit/Entities/USC.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/USC.php rename to src/Physics/Unit/Entities/USC.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/UnitInterface.php b/src/Physics/Unit/Entities/UnitInterface.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/UnitInterface.php rename to src/Physics/Unit/Entities/UnitInterface.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Volt.php b/src/Physics/Unit/Entities/Volt.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Volt.php rename to src/Physics/Unit/Entities/Volt.php diff --git a/vendor/irrevion/science/Physics/Unit/Entities/Year.php b/src/Physics/Unit/Entities/Year.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Entities/Year.php rename to src/Physics/Unit/Entities/Year.php diff --git a/vendor/irrevion/science/Physics/Unit/IAU.php b/src/Physics/Unit/IAU.php similarity index 96% rename from vendor/irrevion/science/Physics/Unit/IAU.php rename to src/Physics/Unit/IAU.php index cd38a72..5a32623 100644 --- a/vendor/irrevion/science/Physics/Unit/IAU.php +++ b/src/Physics/Unit/IAU.php @@ -1,21 +1,21 @@ -value); - if (empty($const)) { - return $reflection; - } - return $reflection->getConstant($const); - } -} +value); + if (empty($const)) { + return $reflection; + } + return $reflection->getConstant($const); + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Physics/Unit/Imperial.php b/src/Physics/Unit/Imperial.php similarity index 95% rename from vendor/irrevion/science/Physics/Unit/Imperial.php rename to src/Physics/Unit/Imperial.php index add606b..ff2fbdc 100644 --- a/vendor/irrevion/science/Physics/Unit/Imperial.php +++ b/src/Physics/Unit/Imperial.php @@ -1,16 +1,16 @@ -value); - if (empty($const)) { - return $reflection; - } - return $reflection->getConstant($const); - } -} +value); + if (empty($const)) { + return $reflection; + } + return $reflection->getConstant($const); + } +} ?> \ No newline at end of file diff --git a/vendor/irrevion/science/Physics/Unit/Natural.php b/src/Physics/Unit/Natural.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Natural.php rename to src/Physics/Unit/Natural.php diff --git a/vendor/irrevion/science/Physics/Unit/NonStandard.php b/src/Physics/Unit/NonStandard.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/NonStandard.php rename to src/Physics/Unit/NonStandard.php diff --git a/vendor/irrevion/science/Physics/Unit/Planck.php b/src/Physics/Unit/Planck.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Planck.php rename to src/Physics/Unit/Planck.php diff --git a/vendor/irrevion/science/Physics/Unit/SI.php b/src/Physics/Unit/SI.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/SI.php rename to src/Physics/Unit/SI.php diff --git a/vendor/irrevion/science/Physics/Unit/SystemInterface.php b/src/Physics/Unit/SystemInterface.php similarity index 94% rename from vendor/irrevion/science/Physics/Unit/SystemInterface.php rename to src/Physics/Unit/SystemInterface.php index 8f9d82a..30d696c 100644 --- a/vendor/irrevion/science/Physics/Unit/SystemInterface.php +++ b/src/Physics/Unit/SystemInterface.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/vendor/irrevion/science/Physics/Unit/Systems.php b/src/Physics/Unit/Systems.php similarity index 100% rename from vendor/irrevion/science/Physics/Unit/Systems.php rename to src/Physics/Unit/Systems.php diff --git a/vendor/irrevion/science/Physics/Unit/USC.php b/src/Physics/Unit/USC.php similarity index 95% rename from vendor/irrevion/science/Physics/Unit/USC.php rename to src/Physics/Unit/USC.php index 32a8fab..3388b95 100644 --- a/vendor/irrevion/science/Physics/Unit/USC.php +++ b/src/Physics/Unit/USC.php @@ -1,16 +1,16 @@ -value); - if (empty($const)) { - return $reflection; - } - return $reflection->getConstant($const); - } -} +value); + if (empty($const)) { + return $reflection; + } + return $reflection->getConstant($const); + } +} ?> \ No newline at end of file