<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Optimierung von Exprssion-template-ausdrücken]]></title><description><![CDATA[<p>Hi Leute!</p>
<p>Zuerstmal das Problem an einem einfachen Beispiel Illustriert.</p>
<p>Bei Matrix-Vektor Operationen kann man viel gewinnen, wenn man Ausdrücke passend umordnet. Ein Bispiel ist der Matrix-Ausdruck</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>C</mi><mo>=</mo><mi>I</mi><mo>+</mo><mi>A</mi><msup><mi>A</mi><mi>T</mi></msup></mrow><annotation encoding="application/x-tex">C=I+AA^T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8413309999999999em;"></span><span class="strut bottom" style="height:0.924661em;vertical-align:-0.08333em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mrel">=</span><span class="mord mathit" style="margin-right:0.07847em;">I</span><span class="mbin">+</span><span class="mord mathit">A</span><span class="mord"><span class="mord mathit">A</span><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathit" style="margin-right:0.13889em;">T</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span></span></span></span><br />
wobei I die Identität und A eine große Matrix ist. Dieser Ausdruck lässt sich straightforward berechnen:</p>
<pre><code>C=I
C+=AA^T
</code></pre>
<p>nun schaue ich mir aber den folgenden Ausdruck an:</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>y</mi><mo>=</mo><mo>(</mo><mi>I</mi><mo>+</mo><mi>A</mi><msup><mi>A</mi><mi>T</mi></msup><mo>)</mo><mi>x</mi></mrow><annotation encoding="application/x-tex">y=(I+AA^T)x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8413309999999999em;"></span><span class="strut bottom" style="height:1.0913309999999998em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.03588em;">y</span><span class="mrel">=</span><span class="mopen">(</span><span class="mord mathit" style="margin-right:0.07847em;">I</span><span class="mbin">+</span><span class="mord mathit">A</span><span class="mord"><span class="mord mathit">A</span><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathit" style="margin-right:0.13889em;">T</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span><span class="mclose">)</span><span class="mord mathit">x</span></span></span></span><br />
wobei y nun ein Vektor ist. Auf einmal ändert sich die optimale Berechnung zu:</p>
<pre><code>t = A^Ty
y = At
y+=x
</code></pre>
<p>Dies ist extrem viel schneller, weil ich ein matrix-matrix produkt gegen ein Matrix-Vektor produkt tausche. ausserdem wird weniger Speicher gebraucht, weil ich C nicht explizit berechnen muss.</p>
<p>Nun würde ich das gerne meiner linearen Algebra beibringen, weil es Fälle gibt, bei denen ein Ausdruck nicht transformiert werden kann. Ein Beispiel wäre, wenn ich den Ausdruck für C einer Funktion übergebe, die dann mit der Matrix ein Matrix-Vektor Produkt berechnet.</p>
<p>Der Ausdruck für C wird bei mir (vereinfacht) über expression-templates durch den folgenden Typ dargestellt:</p>
<pre><code>matrix_plus&lt;
  Identity,
  matrix_product&lt;Matrix,transpose&lt;Matrix&gt; &gt; 
&gt;
</code></pre>
<p>und der Vektor Ausdruck naiv als</p>
<pre><code>matrix_vector_prod&lt;
    matrix_plus&lt;
        Identity,
        matrix_product&lt;Matrix,transpose&lt;Matrix&gt; &gt; 
    &gt;,
    Vector
&gt;
</code></pre>
<p>und der optimale Ausdruck hat die Form</p>
<pre><code>vector_plus&lt;
    Vector, 
    matrix_vector_prod&lt;
        Matrix, 
        matrix_vector_prod&lt; transpose&lt;Matrix&gt;, Vector &gt; 
    &gt; 
&gt;
</code></pre>
<p>nur wie kann ich jetzt a) sinnvolle Regeln definieren, die den Ausdruck vereinfachen und b) wie kann ich die Transformation dann implementieren?</p>
<p>Irgendwelche Ideen seitens der Cracks? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Ich tendiegere gerade zu Substitutionsregeln, aber die schiere Anzahl möglicher Fälle erschreckt mich dann doch sehr. Ein Algorithmischer Ansatz der ohne konkretes Wissen der Typen auskommt wäre mir lieber.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/319706/optimierung-von-exprssion-template-ausdrücken</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Jul 2026 03:40:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/319706.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Aug 2013 18:18:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Optimierung von Exprssion-template-ausdrücken on Thu, 29 Aug 2013 18:18:57 GMT]]></title><description><![CDATA[<p>Hi Leute!</p>
<p>Zuerstmal das Problem an einem einfachen Beispiel Illustriert.</p>
<p>Bei Matrix-Vektor Operationen kann man viel gewinnen, wenn man Ausdrücke passend umordnet. Ein Bispiel ist der Matrix-Ausdruck</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>C</mi><mo>=</mo><mi>I</mi><mo>+</mo><mi>A</mi><msup><mi>A</mi><mi>T</mi></msup></mrow><annotation encoding="application/x-tex">C=I+AA^T</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8413309999999999em;"></span><span class="strut bottom" style="height:0.924661em;vertical-align:-0.08333em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mrel">=</span><span class="mord mathit" style="margin-right:0.07847em;">I</span><span class="mbin">+</span><span class="mord mathit">A</span><span class="mord"><span class="mord mathit">A</span><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathit" style="margin-right:0.13889em;">T</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span></span></span></span><br />
wobei I die Identität und A eine große Matrix ist. Dieser Ausdruck lässt sich straightforward berechnen:</p>
<pre><code>C=I
C+=AA^T
</code></pre>
<p>nun schaue ich mir aber den folgenden Ausdruck an:</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>y</mi><mo>=</mo><mo>(</mo><mi>I</mi><mo>+</mo><mi>A</mi><msup><mi>A</mi><mi>T</mi></msup><mo>)</mo><mi>x</mi></mrow><annotation encoding="application/x-tex">y=(I+AA^T)x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8413309999999999em;"></span><span class="strut bottom" style="height:1.0913309999999998em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.03588em;">y</span><span class="mrel">=</span><span class="mopen">(</span><span class="mord mathit" style="margin-right:0.07847em;">I</span><span class="mbin">+</span><span class="mord mathit">A</span><span class="mord"><span class="mord mathit">A</span><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathit" style="margin-right:0.13889em;">T</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span><span class="mclose">)</span><span class="mord mathit">x</span></span></span></span><br />
wobei y nun ein Vektor ist. Auf einmal ändert sich die optimale Berechnung zu:</p>
<pre><code>t = A^Ty
y = At
y+=x
</code></pre>
<p>Dies ist extrem viel schneller, weil ich ein matrix-matrix produkt gegen ein Matrix-Vektor produkt tausche. ausserdem wird weniger Speicher gebraucht, weil ich C nicht explizit berechnen muss.</p>
<p>Nun würde ich das gerne meiner linearen Algebra beibringen, weil es Fälle gibt, bei denen ein Ausdruck nicht transformiert werden kann. Ein Beispiel wäre, wenn ich den Ausdruck für C einer Funktion übergebe, die dann mit der Matrix ein Matrix-Vektor Produkt berechnet.</p>
<p>Der Ausdruck für C wird bei mir (vereinfacht) über expression-templates durch den folgenden Typ dargestellt:</p>
<pre><code>matrix_plus&lt;
  Identity,
  matrix_product&lt;Matrix,transpose&lt;Matrix&gt; &gt; 
&gt;
</code></pre>
<p>und der Vektor Ausdruck naiv als</p>
<pre><code>matrix_vector_prod&lt;
    matrix_plus&lt;
        Identity,
        matrix_product&lt;Matrix,transpose&lt;Matrix&gt; &gt; 
    &gt;,
    Vector
&gt;
</code></pre>
<p>und der optimale Ausdruck hat die Form</p>
<pre><code>vector_plus&lt;
    Vector, 
    matrix_vector_prod&lt;
        Matrix, 
        matrix_vector_prod&lt; transpose&lt;Matrix&gt;, Vector &gt; 
    &gt; 
&gt;
</code></pre>
<p>nur wie kann ich jetzt a) sinnvolle Regeln definieren, die den Ausdruck vereinfachen und b) wie kann ich die Transformation dann implementieren?</p>
<p>Irgendwelche Ideen seitens der Cracks? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Ich tendiegere gerade zu Substitutionsregeln, aber die schiere Anzahl möglicher Fälle erschreckt mich dann doch sehr. Ein Algorithmischer Ansatz der ohne konkretes Wissen der Typen auskommt wäre mir lieber.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349254</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349254</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Thu, 29 Aug 2013 18:18:57 GMT</pubDate></item><item><title><![CDATA[Reply to Optimierung von Exprssion-template-ausdrücken on Thu, 29 Aug 2013 19:28:27 GMT]]></title><description><![CDATA[<p>Die Substitutionsregeln wären vermutlich das einfachste umzusetzen, und compilezeitmässig am schnellsten. In TMP-Pseudocode:</p>
<pre><code>deep_simplify&lt;T&gt; =
  while !is_same&lt;T, simplify&lt;T&gt; &gt;
    T = simplify&lt;T&gt;
  foreach U in T::operands:
    U = deep_simplify&lt;U&gt;

// Substitutionsregeln
simplify&lt;T&gt; = identity

simplify&lt;matrix_vector_prod&lt;...&gt; &gt; = vector_plus&lt;...&gt;
</code></pre>
<p>Damit wird der Ausdruck schön linear vereinfacht.</p>
<p>Ein algorithmischer Ansatz würde in Richtung Fallunterscheidungen laufen.</p>
<pre><code>cost&lt;T&gt; = // Anzahl nötige Multiplikationen für T (angenommen, die Grösse steht fest)

better&lt;T1, T2&gt; = std::conditional&lt;(cost&lt;T1&gt; &lt; cost&lt;T2&gt;), T1, T2&gt;

simplify&lt;T&gt; = identity

simplify&lt;matrix_vector_prod&lt;Identity,T&gt; &gt; = T;
simplify&lt;matrix_vector_prod&lt;T,Identity&gt; &gt; = T;

simplify&lt;matrix_vector_prod&lt;matrix_plus&lt;A,B&gt;,C&gt;&gt; = better&lt;
  simplify&lt;matrix_plus&lt;matrix_vector_prod&lt;A,C&gt;,matrix_vector_prod&lt;B,C&gt; &gt;,
  matrix_vector_prod&lt;simplify&lt;matrix_plus&lt;A,B&gt;&gt;,simplify&lt;C&gt;&gt;
&gt;
</code></pre>
<p>Machen würde ich das erst ab C++11. Dann kannst du das Expressiontemplate durchgehen und jede Variable mit einem eindeutigen Index versehen.<br />
( <code>matrix_id&lt;1&gt;</code> , <code>matrix_id&lt;2&gt;</code> , ...). Dann simplifizieren und nachher wieder zurückeinsetzen (</p>
<pre><code class="language-cpp">tuple all_arguments = ...; // Liste
  // zwei Listen lassen sich mit tuple_cat zusammenführen
tuple_get&lt;matrix_id::id&gt;(all_arguments) // Id durch Parameter ersetzen
</code></pre>
<p>)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349275</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349275</guid><dc:creator><![CDATA[xprssn]]></dc:creator><pubDate>Thu, 29 Aug 2013 19:28:27 GMT</pubDate></item><item><title><![CDATA[Reply to Optimierung von Exprssion-template-ausdrücken on Fri, 30 Aug 2013 06:36:13 GMT]]></title><description><![CDATA[<p>otze schrieb:</p>
<blockquote>
<p>wobei y nun ein Vektor ist. Auf einmal ändert sich die optimale Berechnung zu:</p>
<pre><code>t = A^Ty
y = At
y+=x
</code></pre>
</blockquote>
<p>Du meinst wohl</p>
<pre><code>t = A'x
</code></pre>
<blockquote>
<p>Auf einmal ändert sich die optimale Berechnung zu</p>
</blockquote>
<p>Wie auf einmal? Du rechnest ja was komplett anderes aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349333</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349333</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Fri, 30 Aug 2013 06:36:13 GMT</pubDate></item><item><title><![CDATA[Reply to Optimierung von Exprssion-template-ausdrücken on Fri, 30 Aug 2013 08:17:03 GMT]]></title><description><![CDATA[<p>@xprssn Ja, an so etwas habe ich auch gedacht, auch wenn ich C++11 nicht verwenden kann. Aber ich vermute, dass die Regeln nicht so einfach umsetzbar sind. Das Problem ist, das die Genauen Kosten nicht bekannt sind, sondern nur die asymptotischen Kosten.</p>
<p>Das Problem, das ich mit einfachen Regelbasierten Ansätzen habe ist, das sie nicht skalieren, einfach weil es zu viele möglichkeiten gibt.</p>
<p>Wenn ich mir einen komplexeren Ausdruck betrachte:</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>y</mi><mo>=</mo><mo>(</mo><mi>A</mi><msup><mi>A</mi><mi>T</mi></msup><mo>+</mo><mi>B</mi><mo>+</mo><mi>C</mi><msup><mo>)</mo><mi>T</mi></msup><mi>x</mi></mrow><annotation encoding="application/x-tex">y=(AA^T+B+C)^T x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8413309999999999em;"></span><span class="strut bottom" style="height:1.0913309999999998em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.03588em;">y</span><span class="mrel">=</span><span class="mopen">(</span><span class="mord mathit">A</span><span class="mord"><span class="mord mathit">A</span><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathit" style="margin-right:0.13889em;">T</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span><span class="mbin">+</span><span class="mord mathit" style="margin-right:0.05017em;">B</span><span class="mbin">+</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mclose"><span class="mclose">)</span><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathit" style="margin-right:0.13889em;">T</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span><span class="mord mathit">x</span></span></span></span></p>
<p>Dann kann es sein, das AA^T so tief im Templateausdruck versteckt ist, das ich kein Substitutionsregel mit der nötigen Tiefe haben kann.</p>
<p>Das einzige was dann ginge sind Brute-Force Methoden wie:</p>
<pre><code>simplify&lt;matrix_vector_prod&lt;matrix_add&lt;A,B&gt;, x&gt; = 
    simplify &lt; vector_add&lt;
         simplify &lt;matrix_vector_prod&lt;A,x&gt; &gt;,
         simplify &lt;matrix_vector_prod&lt;B,x&gt; &gt;
    &gt; //(1)

simplify&lt;vector_matrix_prod&lt;x, matrix_add&lt;A,B&gt; &gt; = 
    simplify &lt; vector_add&lt;
         simplify &lt;vector_matrix_prod&lt;x,A&gt; &gt;,
         simplify &lt;vector_matrix_prod&lt;x,B&gt; &gt;
    &gt;//(2)

simplify&lt;matrix_vector_prod&lt;transpose&lt;A&gt;, x&gt; = 
    simplify&lt;vector_matrix_prod&lt;x,A&gt; &gt; //(3)

simplify&lt;vector_matrix_prod&lt;x,transpose&lt;A&gt;&gt; = 
    simplify&lt;matrix_vector_prod&lt;A,x&gt; &gt; //(4)

simplify&lt;matrix_vector_prod&lt;matrix_matrix_prod&lt;A,B&gt;, x&gt;=
    simplify&lt;matrix_vector_prod&lt;
        simplify &lt;A&gt;,
        simplify &lt;matrix_vector_prod&lt;B,x&gt;
    &gt; //(5)
simplify&lt;vector_matrix_prod&lt;x,matrix_matrix_prod&lt;A,B&gt; &gt;=
    simplify&lt;vector_matrix_prod&lt;
        simplify &lt;vector_matrix_prod&lt;x,A&gt;
        simplify &lt;B&gt;,
    &gt; //(6)
</code></pre>
<p>Und die Auswrtung des Ausdrucks wäre dann (Für den Vektor x lass ich das transponiertzeichen ^T weg, weil vektoren in den regeln oben keine orientierung haben):</p>
(AA^T+B+C)^T x \xrightarrow{(3)} x(AA^T+B+C) \xrightarrow{(2)} xAA^T+x(B+C)  
\xrightarrow{(2)} xAA^T+xB+xC \xrightarrow{(5)} (xA)A^T+xB+xC  
\xrightarrow{(4)} A(xA)+xB+xC
<p>Und dann wäre die optimale Berechnung:</p>
<pre><code>t=xA
y=At 
y+=xB
y+=xC
</code></pre>
<p>Und das ist noch ein recht einfaches Beispiel, meine lineare Algebra kann leider noch ein wenig mehr. Die Anzahl der Regeln sollte exponentiell mit der Anzahl der Operationen wachsen. Und dann stellen sich auf einmal Fragen wie: &quot;gibt es zyklen in den Regeln?&quot; &quot;ist der entstehend Ausdruck optimal?&quot; &quot;ist das Resultat eindeutig?&quot; usw.</p>
<p>Ein weiteres ungelöstes Problem ist noch, wie ich die Ausdrücke dann überhaupt transformiere. Selbst wenn ich den Typ des Ausdrucks optimiere, muss ich ihn hinterher noch zusammenbauen.</p>
<p>Angenommen das Standardinterface für einen unären Ausdruck (zum Beispiel transpose&lt;A&gt;) sieht so aus:</p>
<pre><code>template&lt;class A&gt;
struct Transpose{
    Transpose(A):m_expression(A){}

    A const&amp; expression()const{
         return m_expression;
    }
private:
    A m_expression;
};
</code></pre>
<p>und für einen binären ausdruck dann equiavalent mit jeweils 2 Ausdrücken. Wie würdet ihr dann aus dem ursprünglichen Ausdruck den neuen Ausdruck konstruieren? Es gäbe da zwei Möglichkeiten: entweder auf dem selben Weg wie jetzt die Regeln angewandt werden, das heißt der Ausdruck wird für jede Regelanwendung einmal neu konstruiert. Dies würde die Konstruktion des Ausdrucks vereinfachen, man müsste aber darauf hoffen, das der Compiler das optimiert kriegt. Oder die einzelnen Blätter werden enumeriert und über die transformationen gespeichert, welche Blätter am Ende wo gebraucht werden.</p>
<p>Im ersten Fall hätte man dann zum Beispiel noch eine Funktion wie:</p>
<pre><code>//implementation von (1)
//constructs new tree simplify((A+B)x)-&gt; simplify(simplify(Ax)+simplify(Bx)) 
template&lt;class A,class B, class x&gt;
typename simplify&lt;matrix_vector_prod&lt;matrix_add&lt;A,B&gt;, x &gt; &gt;::type
construct_simplified(matrix_vector_prod&lt;matrix_add&lt;A,B&gt;, x &gt; e){
    typedef typename simplify&lt;matrix_vector_prod&lt;A,x&gt; &gt;::type LeftExpression;
    typedef typename simplify&lt;matrix_vector_prod&lt;B,x&gt; &gt;::type RightExpression;
    //apply inner rule for the left expression
    //simplify&lt;matrix_vector_prod&lt;A,x&gt; &gt;
    matrix_vector_prod&lt;A,x&gt; unsimplified_left(
        e.expression1().expression1(),//A
        e.expression2()//x
    );
    LeftExpression left = construct_simplified(unsimplified_left);
    //apply inner rule for the right expression
    //simplify&lt;matrix_vector_prod&lt;B,x&gt; &gt;
    matrix_vector_prod&lt;B,x&gt; unsimplified_left(
        e.expression1().expression2(),//B
        e.expression2()//x
    );
    RightExpression right = construct_simplified(unsimplified_right);

    //construct resulting whole expression and simplify it again
    vector_add&lt;LeftExpression,RightExpression&gt; simplified_expression(left,right);
    return construct_simplified(simplified_expression);
}
</code></pre>
<p>Sieht mir nach echt viel Arbeit aus...</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21632">@knivil</a> ich verstehe dein Problem nicht, halte dich aber für zu intelligent als das ich das unter Trollen abstempeln will. Ich geh erstmal von Morgenmüdigkeit vor dem ersten Kaffee aus. Bei einer ungenannten Sprache über Syntax zu streiten ist aber genauso sinnvoll, wie im nächsten Absatz einen Nebenkriegsschauplatz über Semantik zu eröffnen. Abr wenn du willst, substitutiere ^T durch '. Ich machs nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349341</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349341</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Fri, 30 Aug 2013 08:17:03 GMT</pubDate></item><item><title><![CDATA[Reply to Optimierung von Exprssion-template-ausdrücken on Fri, 30 Aug 2013 09:24:19 GMT]]></title><description><![CDATA[<p>Wie sehen in der Regel dein Matrizen aus? Schwachbesetzt? Band? Obere-/Unterere-Δ-matrix?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349346</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349346</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 30 Aug 2013 09:24:19 GMT</pubDate></item><item><title><![CDATA[Reply to Optimierung von Exprssion-template-ausdrücken on Fri, 30 Aug 2013 09:53:23 GMT]]></title><description><![CDATA[<p>Ich habe Matlab-Syntax verwendet weil fuer ^T zu faul war und ich bezog mich auf das y in der Gleichung t = A'y das eigentlich t = A'x heissen sollte.</p>
<p>Hauptproblem wird wohl sein, dass mehrere Wege zum Ziel fuehren. Beispiel:<br />
ABx -&gt; ((Bx)'A')' -&gt; t = Bx; u = tA' y = u'<br />
ABx -&gt; (A(Bx)) -&gt; t = Bx; y = At</p>
<p>in beiden Varianten kommen nur noch dein gewuenschten Basisoperationen vor. Wie entscheidest du, welcher Pfad als erstes ausprobiert wird? Wie sieht die Verallgemeinerung beispielsweise fuer Tensoren aus?</p>
<blockquote>
<p>vektoren in den regeln oben keine orientierung haben</p>
</blockquote>
<p>Viele Physiker wuerden jetzt vielleicht aufschreien, co- und kontravariant.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349354</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349354</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Fri, 30 Aug 2013 09:53:23 GMT</pubDate></item><item><title><![CDATA[Reply to Optimierung von Exprssion-template-ausdrücken on Fri, 30 Aug 2013 10:11:38 GMT]]></title><description><![CDATA[<p>Unterschiedlich.</p>
<p>Meistens dicht, manchmal gibt es dichte und spärliche Teile (unstrukturiert). obere/untere dreiecksmatrizeen kommen so gut wie nie ausserhalb der üblichen Solver vor, banded matrizen werden gar nicht unterstützt.</p>
<p>Ich besitze für jeden Matrixtyp bereits eigene operationen die dann im letzten Schritt bei der Transformation Ausdruck-&gt;Auswertereihenfolge gewählt werden.</p>
<p>Mir geht es gerade um den grundsätzlichen Aufbau von so einer Ausdrucksoptimierung. Natürlich kann ich noch beliebig Metainformationen der einzelnen Argumente mit einfließen lassen.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21632">@Knivil</a> ahh okay :). Sorry.</p>
<p>Die Bibliothek richtet sich nicht an Physiker, sondern Maschinenlerner. Ich geb dir Recht, das es in der Formelschreibweise einen Unterschied macht und das ziehe ich normalerweise auch durch. Hier hätte ich aber bei der Ausformulierung Probleme gehabt, weil eine Regel dann zu einer ziemlich &quot;komischen&quot; Vereinfachung geführt hätte - eine ziemlich große Menge an transponiertzeichen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Ansonsten:<br />
Ja es kann mehrere Wege geben. Für mich wäre dein Beispiel nicht anwendbar, weil ich mein vektoren nicht transponieren kann und weil meine Regeln Ausdrücke mit wenig transponierten bevorzugen:</p>
<p>((Bx)'A')' -&gt; A(Bx) -&gt; t=Bx; y=At</p>
<p>Im Allgemeinen stimme ich dir aber zu. Wenn im jetzigen Ansatz 2 Regeln gleich gut matchen ist der Aufruf von simplify mehrdeutig. Wäre sicher spannend zu sehen, ob man das beweisen kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Die Verallgemeinerung auf Tensoren hingegen hat untergeordnete Relevanz, weil ich die nicht einmal unterstütze ;). Wenn ich mal Tensoren haben sollte, kann ich mir dafür ja was überlegen, aber dafür müsste ich mich darin erst einmal einlesen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349355</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349355</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Fri, 30 Aug 2013 10:11:38 GMT</pubDate></item><item><title><![CDATA[Reply to Optimierung von Exprssion-template-ausdrücken on Fri, 30 Aug 2013 10:15:17 GMT]]></title><description><![CDATA[<p>Vielleicht gibt es hier Anregungen: <a href="http://cpp-next.com/archive/2011/01/expressive-c-expression-optimization/" rel="nofollow">http://cpp-next.com/archive/2011/01/expressive-c-expression-optimization/</a> und dann gibt es ja noch blitz++.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349361</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349361</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Fri, 30 Aug 2013 10:15:17 GMT</pubDate></item><item><title><![CDATA[Reply to Optimierung von Exprssion-template-ausdrücken on Fri, 30 Aug 2013 20:12:41 GMT]]></title><description><![CDATA[<p>danke für den Link.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349466</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349466</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Fri, 30 Aug 2013 20:12:41 GMT</pubDate></item></channel></rss>