@uor-foundation/operators
Version:
Layer 3: Arithmetic operators - operations as chemical reactions between numbers
225 lines • 7.18 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createArithmeticOperators = exports.ArithmeticOperators = void 0;
// Import operators
const addition_1 = require("./addition");
const multiplication_1 = require("./multiplication");
const denormalization_1 = require("./denormalization");
// Export all types
__exportStar(require("./carry"), exports);
__exportStar(require("./denormalization"), exports);
__exportStar(require("./addition"), exports);
__exportStar(require("./multiplication"), exports);
/**
* Main arithmetic operators interface - operations as chemical reactions
* This implements Layer 3 of the Mathematical Universe
*/
class ArithmeticOperators {
constructor(substrate, resonance, topology) {
this.substrate = substrate;
this.resonance = resonance;
this.topology = topology;
this.addition = new addition_1.AdditionOperator(substrate, resonance, topology);
this.multiplication = new multiplication_1.MultiplicationOperator(substrate, resonance, topology);
this.denormalization = new denormalization_1.DenormalizationEngine(substrate, resonance);
}
/**
* Addition as field merger
*/
add(a, b) {
return this.addition.add(a, b);
}
/**
* Addition with modular reduction
*/
addModulo(a, b, modulus) {
return this.addition.addModulo(a, b, modulus);
}
/**
* Chain addition operations
*/
addChain(numbers) {
return this.addition.addChain(numbers);
}
/**
* Multiplication as field entanglement
*/
multiply(a, b) {
return this.multiplication.multiply(a, b);
}
/**
* Multiplication with modular reduction
*/
multiplyModulo(a, b, modulus) {
return this.multiplication.multiplyModulo(a, b, modulus);
}
/**
* Chain multiplication operations
*/
multiplyChain(numbers) {
return this.multiplication.multiplyChain(numbers);
}
/**
* Exponentiation through recursive compilation
*/
power(base, exponent) {
return this.multiplication.power(base, exponent);
}
/**
* Factorization as molecular decomposition
*/
factorize(n) {
return this.multiplication.factorize(n);
}
/**
* Subtraction (addition with negation)
*/
subtract(a, b) {
return this.addition.add(a, -b);
}
/**
* Division as inverse compilation
*/
divide(a, b) {
if (b === 0n) {
throw new Error('Division by zero');
}
const quotient = a / b;
const remainder = a % b;
// Analyze the decompilation process
const multiplicationCheck = this.multiplication.multiply(quotient, b);
const reconstructionWithRemainder = this.addition.add(multiplicationCheck.result, remainder);
return {
operation: 'division',
dividend: a,
divisor: b,
quotient,
remainder,
exact: remainder === 0n,
decompilationArtifacts: multiplicationCheck.artifacts,
fieldReconstruction: {
quotientPattern: this.substrate.getFieldPattern(quotient),
remainderPattern: this.substrate.getFieldPattern(remainder),
reconstructsOriginal: reconstructionWithRemainder.result === a,
},
};
}
/**
* Modulo operation
*/
modulo(a, b) {
if (b === 0n) {
throw new Error('Modulo by zero');
}
return ((a % b) + b) % b; // Ensure positive result
}
/**
* Greatest Common Divisor - finding common field sources
*/
gcd(a, b) {
const absA = a < 0n ? -a : a;
const absB = b < 0n ? -b : b;
let x = absA;
let y = absB;
const steps = [];
while (y !== 0n) {
const remainder = x % y;
steps.push({
x,
y,
quotient: x / y,
remainder,
xPattern: this.substrate.getFieldPattern(x),
yPattern: this.substrate.getFieldPattern(y),
});
x = y;
y = remainder;
}
return {
a: absA,
b: absB,
gcd: x,
steps,
commonFieldSources: this.findCommonFieldSources(absA, absB, x),
};
}
/**
* Least Common Multiple - finding first resonance harmony
*/
lcm(a, b) {
const absA = a < 0n ? -a : a;
const absB = b < 0n ? -b : b;
if (absA === 0n || absB === 0n) {
return {
a: absA,
b: absB,
lcm: 0n,
gcdUsed: 0n,
resonanceHarmony: 0,
};
}
const gcdResult = this.gcd(absA, absB);
const lcm = (absA * absB) / gcdResult.gcd;
return {
a: absA,
b: absB,
lcm,
gcdUsed: gcdResult.gcd,
resonanceHarmony: this.resonance.calculateResonance(lcm),
};
}
/**
* Track denormalization artifacts
*/
trackArtifacts(a, b) {
return this.denormalization.trackMultiplication(a, b);
}
/**
* Predict artifacts without computing
*/
predictArtifacts(a, b) {
return this.denormalization.predictArtifacts(a, b);
}
/**
* Find common field sources for GCD
*/
findCommonFieldSources(a, b, gcd) {
const patternA = this.substrate.getFieldPattern(a);
const patternB = this.substrate.getFieldPattern(b);
const patternGCD = this.substrate.getFieldPattern(gcd);
const commonSources = [];
for (let i = 0; i < patternGCD.length; i++) {
if (patternGCD[i] && patternA[i] && patternB[i]) {
commonSources.push(i);
}
}
return commonSources;
}
}
exports.ArithmeticOperators = ArithmeticOperators;
/**
* Create arithmetic operators instance
* @param substrate - Field substrate interface
* @param resonance - Resonance dynamics interface
* @param topology - Page topology interface
* @returns Arithmetic operators implementation
*/
function createArithmeticOperators(substrate, resonance, topology) {
return new ArithmeticOperators(substrate, resonance, topology);
}
exports.createArithmeticOperators = createArithmeticOperators;
//# sourceMappingURL=index.js.map