You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

2 months ago
  1. <!doctype html>
  2. <title>CodeMirror: Mathematica mode</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../../doc/docs.css">
  5. <link rel=stylesheet href=../../lib/codemirror.css>
  6. <script src=../../lib/codemirror.js></script>
  7. <script src=../../addon/edit/matchbrackets.js></script>
  8. <script src=mathematica.js></script>
  9. <style type=text/css>
  10. .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
  11. </style>
  12. <div id=nav>
  13. <a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
  14. <ul>
  15. <li><a href="../../index.html">Home</a>
  16. <li><a href="../../doc/manual.html">Manual</a>
  17. <li><a href="https://github.com/codemirror/codemirror5">Code</a>
  18. </ul>
  19. <ul>
  20. <li><a href="../index.html">Language modes</a>
  21. <li><a class=active href="#">Mathematica</a>
  22. </ul>
  23. </div>
  24. <article>
  25. <h2>Mathematica mode</h2>
  26. <textarea id="mathematicaCode">
  27. (* example Mathematica code *)
  28. (* Dualisiert wird anhand einer Polarität an einer
  29. Quadrik $x^t Q x = 0$ mit regulärer Matrix $Q$ (also
  30. mit $det(Q) \neq 0$), z.B. die Identitätsmatrix.
  31. $p$ ist eine Liste von Polynomen - ein Ideal. *)
  32. dualize::"singular" = "Q must be regular: found Det[Q]==0.";
  33. dualize[ Q_, p_ ] := Block[
  34. { m, n, xv, lv, uv, vars, polys, dual },
  35. If[Det[Q] == 0,
  36. Message[dualize::"singular"],
  37. m = Length[p];
  38. n = Length[Q] - 1;
  39. xv = Table[Subscript[x, i], {i, 0, n}];
  40. lv = Table[Subscript[l, i], {i, 1, m}];
  41. uv = Table[Subscript[u, i], {i, 0, n}];
  42. (* Konstruiere Ideal polys. *)
  43. If[m == 0,
  44. polys = Q.uv,
  45. polys = Join[p, Q.uv - Transpose[Outer[D, p, xv]].lv]
  46. ];
  47. (* Eliminiere die ersten n + 1 + m Variablen xv und lv
  48. aus dem Ideal polys. *)
  49. vars = Join[xv, lv];
  50. dual = GroebnerBasis[polys, uv, vars];
  51. (* Ersetze u mit x im Ergebnis. *)
  52. ReplaceAll[dual, Rule[u, x]]
  53. ]
  54. ]
  55. </textarea>
  56. <script>
  57. var mathematicaEditor = CodeMirror.fromTextArea(document.getElementById('mathematicaCode'), {
  58. mode: 'text/x-mathematica',
  59. lineNumbers: true,
  60. matchBrackets: true
  61. });
  62. </script>
  63. <p><strong>MIME types defined:</strong> <code>text/x-mathematica</code> (Mathematica).</p>
  64. </article>