Skip to content

Commit

Permalink
make slog more precise by making it binary search
Browse files Browse the repository at this point in the history
related issue: #108
  • Loading branch information
Patashu committed Jul 23, 2022
1 parent a2ce359 commit 4269c74
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 3 deletions.
33 changes: 33 additions & 0 deletions break_eternity.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2107,10 +2107,43 @@ var Decimal = /*#__PURE__*/function () {
return result;
} //Super-logarithm, one of tetration's inverses, tells you what size power tower you'd have to tetrate base to to get number. By definition, will never be higher than 1.8e308 in break_eternity.js, since a power tower 1.8e308 numbers tall is the largest representable number.
// https://en.wikipedia.org/wiki/Super-logarithm
// NEW: Accept a number of iterations, and use binary search to, after making an initial guess, hone in on the true value, assuming tetration as the ground truth.

}, {
key: "slog",
value: function slog() {
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
var iterations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 43;
var step_size = 0.001;
var has_changed_directions_once = false;
var previously_rose = false;
var result = this.slog_internal(base).toNumber();

for (var i = 1; i < iterations; ++i) {
var new_decimal = new Decimal(base).tetrate(result);
var currently_rose = new_decimal.gt(this);

if (iterations > 1) {
if (previously_rose != currently_rose) {
has_changed_directions_once = true;
}
}

previously_rose = currently_rose;

if (has_changed_directions_once) {
step_size /= 2;
}

step_size = Math.abs(step_size) * (currently_rose ? -1 : 1);
result += step_size;
}

return Decimal.fromNumber(result);
}
}, {
key: "slog_internal",
value: function slog_internal() {
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
base = D(base); //special cases:
//slog base 0 or lower is NaN
Expand Down
33 changes: 33 additions & 0 deletions break_eternity.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2105,10 +2105,43 @@ var Decimal = /*#__PURE__*/function () {
return result;
} //Super-logarithm, one of tetration's inverses, tells you what size power tower you'd have to tetrate base to to get number. By definition, will never be higher than 1.8e308 in break_eternity.js, since a power tower 1.8e308 numbers tall is the largest representable number.
// https://en.wikipedia.org/wiki/Super-logarithm
// NEW: Accept a number of iterations, and use binary search to, after making an initial guess, hone in on the true value, assuming tetration as the ground truth.

}, {
key: "slog",
value: function slog() {
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
var iterations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 43;
var step_size = 0.001;
var has_changed_directions_once = false;
var previously_rose = false;
var result = this.slog_internal(base).toNumber();

for (var i = 1; i < iterations; ++i) {
var new_decimal = new Decimal(base).tetrate(result);
var currently_rose = new_decimal.gt(this);

if (iterations > 1) {
if (previously_rose != currently_rose) {
has_changed_directions_once = true;
}
}

previously_rose = currently_rose;

if (has_changed_directions_once) {
step_size /= 2;
}

step_size = Math.abs(step_size) * (currently_rose ? -1 : 1);
result += step_size;
}

return Decimal.fromNumber(result);
}
}, {
key: "slog_internal",
value: function slog_internal() {
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
base = D(base); //special cases:
//slog base 0 or lower is NaN
Expand Down
33 changes: 33 additions & 0 deletions break_eternity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2111,10 +2111,43 @@
return result;
} //Super-logarithm, one of tetration's inverses, tells you what size power tower you'd have to tetrate base to to get number. By definition, will never be higher than 1.8e308 in break_eternity.js, since a power tower 1.8e308 numbers tall is the largest representable number.
// https://en.wikipedia.org/wiki/Super-logarithm
// NEW: Accept a number of iterations, and use binary search to, after making an initial guess, hone in on the true value, assuming tetration as the ground truth.

}, {
key: "slog",
value: function slog() {
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
var iterations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 43;
var step_size = 0.001;
var has_changed_directions_once = false;
var previously_rose = false;
var result = this.slog_internal(base).toNumber();

for (var i = 1; i < iterations; ++i) {
var new_decimal = new Decimal(base).tetrate(result);
var currently_rose = new_decimal.gt(this);

if (iterations > 1) {
if (previously_rose != currently_rose) {
has_changed_directions_once = true;
}
}

previously_rose = currently_rose;

if (has_changed_directions_once) {
step_size /= 2;
}

step_size = Math.abs(step_size) * (currently_rose ? -1 : 1);
result += step_size;
}

return Decimal.fromNumber(result);
}
}, {
key: "slog_internal",
value: function slog_internal() {
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
base = D(base); //special cases:
//slog base 0 or lower is NaN
Expand Down
2 changes: 1 addition & 1 deletion break_eternity.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ export default class Decimal {
tetrate(height?: number, payload?: DecimalSource): Decimal;
iteratedexp(height?: number, payload?: Decimal): Decimal;
iteratedlog(base?: DecimalSource, times?: number): Decimal;
slog(base?: DecimalSource): Decimal;
slog(base?: DecimalSource, iterations?: number): Decimal;
slog_internal(base?: DecimalSource): Decimal;
static slog_critical(base: number, height: number): number;
static tetrate_critical(base: number, height: number): number;
static critical_section(base: number, height: number, grid: number[][]): number;
Expand Down
30 changes: 29 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,35 @@ export default class Decimal {

//Super-logarithm, one of tetration's inverses, tells you what size power tower you'd have to tetrate base to to get number. By definition, will never be higher than 1.8e308 in break_eternity.js, since a power tower 1.8e308 numbers tall is the largest representable number.
// https://en.wikipedia.org/wiki/Super-logarithm
public slog(base: DecimalSource = 10): Decimal {
// NEW: Accept a number of iterations, and use binary search to, after making an initial guess, hone in on the true value, assuming tetration as the ground truth.
public slog(base: DecimalSource = 10, iterations = 43): Decimal {
let step_size = 0.001;
let has_changed_directions_once = false;
let previously_rose = false;
let result = this.slog_internal(base).toNumber();
for (var i = 1; i < iterations; ++i)
{
let new_decimal = new Decimal(base).tetrate(result);
let currently_rose = new_decimal.gt(this);
if (iterations > 1)
{
if (previously_rose != currently_rose)
{
has_changed_directions_once = true;
}
}
previously_rose = currently_rose;
if (has_changed_directions_once)
{
step_size /= 2;
}
step_size = Math.abs(step_size) * (currently_rose ? -1 : 1);
result += step_size;
}
return Decimal.fromNumber(result);
}

public slog_internal(base: DecimalSource = 10): Decimal {
base = D(base);

//special cases:
Expand Down

0 comments on commit 4269c74

Please sign in to comment.