Skip to content

Commit

Permalink
Make Equation Explorer faster (#705)
Browse files Browse the repository at this point in the history
Cuts ~2.5s off the load time for me locally.

I verified that the stats line-up by comparing CSVs before/after (this
change optimizes stats calculation)
  • Loading branch information
vlad902 authored Oct 21, 2024
1 parent c03f75d commit f57bba9
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions home_page/implications/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ function reshape(array, rows, cols) {
// Decode RLE
const decoded = decodeRLE(arr);

// Map through LUT
const mapped = mapThroughLUT(decoded);

// Reshape to 2694x2694
const implications = reshape(mapped, 4694, 4694);
// Reshape to 4694x4694
const implications = reshape(mapThroughLUT(decoded), 4694, 4694);

const GRAPHITI_BASE_URL = "https://teorth.github.io/equational_theories/graphiti/"
const FME_BASE_URL = "https://teorth.github.io/equational_theories/fme/"
Expand Down Expand Up @@ -186,29 +183,45 @@ function isUnknown(status, treatConjecturedAsUnknown = false) {
return status === 'unknown' || (treatConjecturedAsUnknown && status.includes('conjecture'));
}

function calculateStats(index, treatConjecturedAsUnknown = false) {
const stats = {implies: 0, impliedBy: 0, antiImplies: 0, antiImpliedBy: 0, unknown: 0, unknownBy: 0};
for (let i = 0; i < implications.length; i++) {
if (i === index) continue;
const forwardStatus = implications[index][i];
const backwardStatus = implications[i][index];
function calculateStats(treatConjecturedAsUnknown = false) {
let sccStats = []
for (let i = 0; i < equiv.length; i++) {
let stats = {implies: 0, impliedBy: 0, antiImplies: 0, antiImpliedBy: 0, unknown: 0, unknownBy: 0};
for (let j = 0; j < equiv.length; j++) {
let adjustment = 0;
if (i == j) {
adjustment = 1;
}

const forwardStatus = implications[equiv[i][0]][equiv[j][0]];
const backwardStatus = implications[equiv[j][0]][equiv[i][0]];

if (isImplies(forwardStatus, false, treatConjecturedAsUnknown)) stats.implies++;
else if (isAntiImplies(forwardStatus, false, treatConjecturedAsUnknown)) stats.antiImplies++;
else stats.unknown++;
if (isImplies(forwardStatus, false, treatConjecturedAsUnknown)) stats.implies += equiv[j].length - adjustment;
else if (isAntiImplies(forwardStatus, false, treatConjecturedAsUnknown)) stats.antiImplies += equiv[j].length - adjustment;
else stats.unknown += equiv[j].length - adjustment;

if (isImplies(backwardStatus, false, treatConjecturedAsUnknown)) stats.impliedBy++;
else if (isAntiImplies(backwardStatus, false, treatConjecturedAsUnknown)) stats.antiImpliedBy++;
else stats.unknownBy++;
if (isImplies(backwardStatus, false, treatConjecturedAsUnknown)) stats.impliedBy += equiv[j].length - adjustment;
else if (isAntiImplies(backwardStatus, false, treatConjecturedAsUnknown)) stats.antiImpliedBy += equiv[j].length - adjustment;
else stats.unknownBy += equiv[j].length - adjustment;
}
sccStats.push(stats)
}
return stats;
}

let overallStats = []
for (let i = 0; i < equiv.length; i++) {
for (const subidx of equiv[i]) {
overallStats[subidx] = sccStats[i]
}
}

return overallStats
}

function initializeEquationList() {
const treatConjecturedAsUnknown = treatConjectedAsUnknownList.checked;
const overallStats = calculateStats(treatConjecturedAsUnknown)
cachedItems = equations.map((eq, index) => {
const stats = calculateStats(index, treatConjecturedAsUnknown);
const stats = overallStats[index];
const element = document.createElement('div');
element.className = 'equation-item';
element.dataset.index = index;
Expand Down Expand Up @@ -244,8 +257,9 @@ function initializeEquationList() {

function updateEquationListStats() {
const treatConjecturedAsUnknown = treatConjectedAsUnknownList.checked;
const overallStats = calculateStats(treatConjecturedAsUnknown)
cachedItems.forEach((item) => {
const stats = calculateStats(item.index, treatConjecturedAsUnknown);
const stats = overallStats[item.index];
item.stats = stats;
item.statElements.implies.textContent = stats.implies;
item.statElements.impliedBy.textContent = stats.impliedBy;
Expand Down

0 comments on commit f57bba9

Please sign in to comment.