Public
Edited
May 13, 2023
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;
}
a = a.replace(/\.simpli/g, ".simplify()");
a = a.replace(/\.getg\(\)/g, ".g");
a = replaceExpressionPol(a);
a = a.replace(/\.getd\(\)/g, ".d");
a = a.replace(/\.getn\(\)/g, ".data.length");
a = a.replace(/_infinit/g, "NegInfinity");
a = a.replace(/infinit/g, "Infinity");
a = a.replace(/\bs1\b/g, "self");
a = foldFn(a, "oplus");
a = replaceSubstringsFun2Method(a, "oplus");
a = foldFn(a, "otimes");
a = replaceSubstringsFun2Method(a, "otimes");
a = removeOuterParenthesis(a, "if");
a = removeOuterParenthesis(a, "while");
a = wrapInIsZero(a);
a = replaceInit(a);
return md`\`\`\`rust
${a}
\`\`\``;
}
Insert cell
import { ace } from "@jobleonard/ace"
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