Public
Edited
May 14, 2023
1 fork
Insert cell
Insert cell
viewof text = {
const defaultLiveMarkdownText = ` while( result.p.getpol(result.p.getn()-1).getg()<=s1.q.getpol(0).getg() )
{ monome.init(s2.r.getg()*i,s2.r.getd()*i);
result.p=oplus(result.p,temp=otimes(s2.q,monome));
i++;
}
monome.init(s1.q.getpol(0).getg(),infinit); //normalemnt pas necessaire
result.p=oplus(temp=oplus(s1.p,s2.p,result.p),monome);`;

// Instantiating the editor
const { editor, view } = ace(defaultLiveMarkdownText, undefined, {
mode: "ace/mode/javascript"
});

// initial value for viewof
view.value = editor.getValue();

// Setting up the callback that reacts to the changes
editor.on("change", () => {
view.value = editor.getValue();
});

return view;
}
Insert cell
p = {
let a = text;
//try |execute "%s/.getg()/.g/g" | catch |try| execute "%s/.getpol((.+?))/.data[$1]/g" | catch |try|execute "%s/.getd()/.d/g" | catch |try|execute "%s/_infinit/NegInfinity/g" | catch |execute "%s/infinit/Infinity/g"|endtry|endtry|endtry|endtry

/*Given a string str and an index index (of a parenthesis), it returns the index of the matching parenthesis in the string.*/
function findMatchingParenthesis(str, index) {
let openParens = 0;

for (let i = index; i < str.length; i++) {
if (str[i] === "(") {
openParens++;
} else if (str[i] === ")") {
openParens--;
if (openParens === 0) {
return i;
}
}
}

return -1;
}
function replaceNestedBracePattern(str) {
let result = "";
let i = 0;

while (i < str.length) {
if (str.slice(i, i + 9) === "_brace.b_") {
const openingParenthesisIndex = str.lastIndexOf("(", i);
const closingParenthesisIndex = findMatchingParenthesis(
str,
openingParenthesisIndex
);

if (closingParenthesisIndex !== -1) {
const anythingX = str.slice(
openingParenthesisIndex + 1,
closingParenthesisIndex
);
i = closingParenthesisIndex + 1;

const openingParenthesisIndexY = str.indexOf("(", i + 8);
const closingParenthesisIndexY = findMatchingParenthesis(
str,
openingParenthesisIndexY
);

if (closingParenthesisIndexY !== -1) {
const anythingY = str.slice(
openingParenthesisIndexY + 1,
closingParenthesisIndexY
);
result =
result.slice(0, openingParenthesisIndex) +
`underbrace(${anythingX},${anythingY})`;
i = closingParenthesisIndexY + 1;
} else {
result += str.slice(i, i + 9);
i += 9;
}
} else {
result += str.slice(i, i + 9);
i += 9;
}
} else {
result += str[i];
i++;
}
}

return result;
}

a = replaceNestedBracePattern(a);

return md`\`\`\`
${a}
\`\`\``;
}
Insert cell
import { ace } from "@jobleonard/ace"
Insert cell
{
function findMatchingParenthesis(str, index) {
let openParens = 0;

for (let i = index; i < str.length; i++) {
if (str[i] === "(") {
openParens++;
} else if (str[i] === ")") {
openParens--;
if (openParens === 0) {
return i;
}
}
}

return -1;
}
function replaceNestedBracePattern(str) {
let result = "";
let i = 0;

while (i < str.length) {
if (str.slice(i, i + 9) === "_brace.b_") {
const openingParenthesisIndex = str.lastIndexOf("(", i);
const closingParenthesisIndex = findMatchingParenthesis(
str,
openingParenthesisIndex
);

if (closingParenthesisIndex !== -1) {
const anythingX = str.slice(
openingParenthesisIndex + 1,
closingParenthesisIndex
);
i = closingParenthesisIndex + 1;

const openingParenthesisIndexY = str.indexOf("(", i + 8);
const closingParenthesisIndexY = findMatchingParenthesis(
str,
openingParenthesisIndexY
);

if (closingParenthesisIndexY !== -1) {
const anythingY = str.slice(
openingParenthesisIndexY + 1,
closingParenthesisIndexY
);
result =
result.slice(0, openingParenthesisIndex) +
`underbrace(${anythingX},${anythingY})`;
i = closingParenthesisIndexY + 1;
} else {
result += str.slice(i, i + 9);
i += 9;
}
} else {
result += str.slice(i, i + 9);
i += 9;
}
} else {
result += str[i];
i++;
}
}

return result;
}
const input = '(b dot.op b dots.h.c b)_brace.b_(k_1 upright(" mal"))';
const output = replaceNestedBracePattern(input);
return output;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more