Skip to content

Instantly share code, notes, and snippets.

@davidmerwin
Last active September 22, 2023 07:33
Show Gist options
  • Save davidmerwin/4c384d6fadf978241d0e58a59a8134fc to your computer and use it in GitHub Desktop.
Save davidmerwin/4c384d6fadf978241d0e58a59a8134fc to your computer and use it in GitHub Desktop.
This code snippet creates a mathematical matrix with two columns: A, B, and MJX. It also includes text classes for the mjx-alternate attribute in an HTML document that can be used to generate MathML data

MathML Code Snippet

Preview:
<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mo>=</mo>
  <mrow data-mjx-texclass="INNER">
    <mo data-mjx-texclass="OPEN">{</mo>
    <mrow data-mjx-texclass="INNER">
      <mo data-mjx-texclass="OPEN">(</mo>
      <msup>
        <mrow></mrow>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <msup>
        <mi>A</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo>,</mo>
      <msup>
        <mrow></mrow>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <msup>
        <mi>B</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo data-mjx-texclass="CLOSE">)</mo>
    </mrow>
    <mo>,</mo>
    <mrow data-mjx-texclass="INNER">
      <mo data-mjx-texclass="OPEN">(</mo>
      <msup>
        <mrow></mrow>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <msup>
        <mi>A</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo>,</mo>
      <msup>
        <mrow></mrow>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <msup>
        <mi>C</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo data-mjx-texclass="CLOSE">)</mo>
    </mrow>
    <mo>,</mo>
    <mrow data-mjx-texclass="INNER">
      <mo data-mjx-texclass="OPEN">(</mo>
      <msup>
        <mrow></mrow>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <msup>
        <mi>B</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo>,</mo>
      <msup>
        <mi>C</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo data-mjx-texclass="CLOSE">)</mo>
    </mrow>
    <mo>,</mo>
    <mrow data-mjx-texclass="INNER">
      <mo data-mjx-texclass="OPEN">(</mo>
      <msup>
        <mrow></mrow>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <msup>
        <mi>B</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo>,</mo>
      <msup>
        <mrow></mrow>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <msup>
        <mi>D</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo data-mjx-texclass="CLOSE">)</mo>
    </mrow>
    <mo>,</mo>
    <mrow data-mjx-texclass="INNER">
      <mo data-mjx-texclass="OPEN">(</mo>
      <msup>
        <mrow></mrow>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <msup>
        <mi>C</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo>,</mo>
      <msup>
        <mi>D</mi>
        <mrow>
          <mi data-mjx-alternate="1" mathvariant="normal"></mi>
        </mrow>
      </msup>
      <mo data-mjx-texclass="CLOSE">)</mo>
    </mrow>
    <mo data-mjx-texclass="CLOSE">}</mo>
  </mrow>
</math>
Associated Context
Type Code Snippet ( .html )
Associated Tags Framework: MathML `MMX: A/B
💡 Smart Description This code snippet creates a mathematical matrix with two columns: A, B, and MJX. It also includes text classes for the mjx-alternate attribute in an HTML document that can be used to generate MathML data
This code snippet represents a mathematical equation using MathML markup language. It defines a set of equations involving variables A, B, C, and D, each raised to a power of a prime symbol.
🔎 Suggested Searches math element with mrow data-mjx-texclass
mathelement with text class and mo attributes
mathelement with multiple lines in MJX grid
mathelement with multi line elements to a row
MathML code for equation with variables A, B, C, and D
MathML code for equation with prime notation
MathML code for equation with nested parentheses
MathML code for equation with superscripts
MathML code for equation with curly braces
Related Links https://www.html.am/html-codes/forms/html-select-tag.cfm
http://www.w3.org/1998/Math/MathML">
https://www.mathjax.org/
Related People David Merwin
Sensitive Information No Sensitive Information Detected
Shareable Link https://davidmerwin.pieces.cloud/?p=bd7347a0d3
@davidmerwin
Copy link
Author

import dimod
# Define the graph and binary variables
graph $=\left{\left({ }^{\prime} A^{\prime},{ }^{\prime} B^{\prime}\right),\left({ }^{\prime} A^{\prime},{ }^{\prime} C^{\prime}\right),\left({ }^{\prime} B^{\prime}, C^{\prime}\right),\left({ }^{\prime} B^{\prime},{ }^{\prime} D^{\prime}\right),\left({ }^{\prime} C^{\prime}, D^{\prime}\right)\right}$
binary_variables $=\left{{ }^{\prime} A ',{ }^{\prime} B^{\prime},{ }^{\prime} C^{\prime},{ }^{\prime} D^{\prime}\right}$
# Create a binary quadratic model (BQM)
bqm = dimod.BinaryQuadraticModel.empty(dimod.BINARY)
# Add the objective function
for $\mathbf{U}, \mathbf{v}$ in graph:
bqm.add_interaction( $(\mathbf{v}, \mathbf{v}, 1)$ # Cost of edge connection
print (bqm)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment