<!DOCTYPE html><htmllang='en'><head><title>[qty.sym.expr]</title><metacharset='UTF-8'/><linkrel='stylesheet'type='text/css'href='14882.css'/><linkrel='stylesheet'type='text/css'href='https://fonts.googleapis.com/css2?family=Noto+Serif'/><linkrel='stylesheet'type='text/css'href='https://fonts.googleapis.com/css2?family=Noto+Sans'/><linkrel='stylesheet'type='text/css'href='https://fonts.googleapis.com/css2?family=Noto+Sans+Mono'/><linkrel='icon'href='icon.png'/><linkrel='stylesheet'type='text/css'href='expanded.css'title='Normal'/><linkrel='alternate stylesheet'type='text/css'href='colored.css'title='Notes and examples colored'/><linkrel='alternate stylesheet'type='text/css'href='normative-only.css'title='Notes and examples hidden'/></head><body><divclass='wrapper'><h1><aclass='secnum'style='min-width:50pt'>5</a> Quantities and units library <aclass='abbr_ref'href='index.html#quantities'>[quantities]</a></h1><h2><aclass='secnum'style='min-width:65pt'>5.3</a> Utilities <aclass='abbr_ref'href='qty.utils.html#qty.sym.expr'>[qty.utils]</a></h2><h3><aclass='secnum'style='min-width:80pt'>5.3.4</a> Symbolic expressions <aclass='abbr_ref'>[qty.sym.expr]</a></h3><divid='general'class='section'><h4><aclass='secnum'href='#general'style='min-width:95pt'>5.3.4.1</a> General <aclass='abbr_ref'href='qty.sym.expr.general.html'>[qty.sym.expr.general]</a></h4><divclass='para'id='general-1'><divclass='marginalizedparent'><aclass='marginalized'href='#general-1'>1</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L981'>#</a></div><divclass='texpara'><divid='general-1.sentence-1'class='sentence'>Subclause [qty.<spanclass='shy'></span>sym.<spanclass='shy'></span>expr] specifies the components
used to maintain ordered, simplified, and readable
argument lists in the names of specializations<aclass='hidden_link'href='#general-1.sentence-1'>.</a></div><divid='general-example-1'class='example'><divclass='texpara'>[<i>Example <ahref='#general-example-1'>1</a></i>: <spanclass='codeblock'><spanclass='keyword'>using</span><spanclass='keyword'>namespace</span> si<spanclass='operator'>::</span>unit_symbols;
<spanclass='keyword'>int</span> x <spanclass='operator'>=</span> kg <spanclass='operator'>*</span> km <spanclass='operator'>/</span> square<spanclass='parenthesis'>(</span>h<spanclass='parenthesis'>)</span>; <spanclass='comment'>// error: cannot construct from</span>
The library ensures <spanclass='texttt'><spanclass='keyword'>decltype</span><spanclass='parenthesis'>(</span>kg <spanclass='operator'>*</span> km <spanclass='operator'>/</span> square<spanclass='parenthesis'>(</span>h<spanclass='parenthesis'>)</span><spanclass='parenthesis'>)</span></span> is styled-like as commented in diagnostics,
provided that, in the implementation-defined total order of types,
<spanclass='texttt'><spanclass='keyword'>decltype</span><spanclass='parenthesis'>(</span>kg<spanclass='parenthesis'>)</span></span> is less than <spanclass='texttt'><spanclass='keyword'>decltype</span><spanclass='parenthesis'>(</span>km<spanclass='parenthesis'>)</span></span><aclass='hidden_link'href='#general-1.sentence-2'>.</a></div> — <i>end example</i>]</div></div></div></div></div><divid='concepts'class='section'><h4><aclass='secnum'href='#concepts'style='min-width:95pt'>5.3.4.2</a> Concept <spanclass='texttt'><i>SymbolicConstant</i></span><aclass='abbr_ref'href='qty.sym.expr.concepts.html'>[qty.sym.expr.concepts]</a></h4><divclass='texpara'><divclass='itemdecl'id='concept:SymbolicConstant'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#concept:SymbolicConstant'>🔗</a></div><codeclass='itemdeclcode'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span> T<spanclass='anglebracket'>></span>
that are used in symbolic expressions<aclass='hidden_link'href='#concepts-1.sentence-1'>.</a></div></div></div></div><divid='types'class='section'><h4><aclass='secnum'href='#types'style='min-width:95pt'>5.3.4.3</a> Types <aclass='abbr_ref'href='qty.sym.expr.types.html'>[qty.sym.expr.types]</a></h4><divclass='texpara'><spanid='lib:per'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:per'>🔗</a></div><spanclass='codeblock'><spanclass='keyword'>namespace</span> mp_units <spanclass='curlybracket'>{</span>
</span></span></div><divclass='para'id='types-1'><divclass='marginalizedparent'><aclass='marginalized'href='#types-1'>1</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1023'>#</a></div><divclass='texpara'><divid='types-1.sentence-1'class='sentence'><spanclass='texttt'>per</span> is used to store arguments with negative exponents<aclass='hidden_link'href='#types-1.sentence-1'>.</a></div><divid='types-1.sentence-2'class='sentence'>A specialization of <spanclass='texttt'>per</span>
represents the product of the inverse of its template arguments<aclass='hidden_link'href='#types-1.sentence-2'>.</a></div><divid='types-1.sentence-3'class='sentence'>A program that instantiates a specialization of <spanclass='texttt'>per</span>
that is not a possible result of the library specifications
is ill-formed, no diagnostic required<aclass='hidden_link'href='#types-1.sentence-3'>.</a></div></div><divclass='texpara'><spanid='lib:power'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:power'>🔗</a></div><spanclass='codeblock'><spanclass='keyword'>namespace</span> mp_units <spanclass='curlybracket'>{</span>
</span></span></div></div><divclass='para'id='types-2'><divclass='marginalizedparent'><aclass='marginalized'href='#types-2'>2</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1045'>#</a></div><divclass='texpara'><divid='types-2.sentence-1'class='sentence'><spanclass='texttt'>power</span> represents a power (<ahref="https://www.electropedia.org/iev/iev.nsf/display?openform&ievref=102-02-08">IEC 60050, 102-02-08</a>)
of the form <spanclass="mjx-chtml"><spanclass="mjx-math"><spanclass="mjx-mrow"aria-hidden="true"><spanclass="mjx-msubsup"><spanclass="mjx-base"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.225em;">F</span></span></span></span></span><spanclass="mjx-sup"style="font-size: 70.7%; vertical-align: 0.513em; padding-left: 0px; padding-right: 0.071em;"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.298em;">Num</span></span></span></span><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mo"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.446em; padding-bottom: 0.593em;">/</span></span></span></span><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.298em;">Den</span></span></span></span></span></span></span></span></span></span></span><aclass='hidden_link'href='#types-2.sentence-1'>.</a></div><divid='types-note-1'class='note'><divclass='texpara'>[<i>Note <ahref='#types-note-1'>1</a></i>: <divid='types-2.sentence-2'class='sentence'><spanclass='texttt'>Den</span> is optional to shorten the type name when <spanclass='texttt'>Den</span> is <spanclass='texttt'><spanclass='literal'>1</span></span><aclass='hidden_link'href='#types-2.sentence-2'>.</a></div> — <i>end note</i>]</div></div><divid='types-2.sentence-3'class='sentence'>
A program that instantiates a specialization of <spanclass='texttt'>power</span>
that is not a possible result of the library specifications
is ill-formed, no diagnostic required<aclass='hidden_link'href='#types-2.sentence-3'>.</a></div></div></div><divclass='para'id='types-3'><divclass='marginalizedparent'><aclass='marginalized'href='#types-3'>3</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1055'>#</a></div><divclass='texpara'><divid='types-3.sentence-1'class='sentence'>Let <spanclass='texttt'>r</span> be <spanclass='texttt'><spanclass='texttt'><i>ratio</i></span><spanclass='curlybracket'>{</span>Num, Den<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='curlybracket'>}</span></span><aclass='hidden_link'href='#types-3.sentence-1'>.</a></div><divid='types-3.sentence-2'class='sentence'>Let <spanclass='texttt'><i>is-valid-ratio</i></span> be
<spanclass='texttt'><spanclass='literal'>true</span></span> if <spanclass='texttt'>r</span> is a valid constant expression, and
<spanclass='texttt'><spanclass='literal'>false</span></span> otherwise<aclass='hidden_link'href='#types-3.sentence-2'>.</a></div><divid='types-3.sentence-3'class='sentence'>The expression in the <spanclass='textsf'><i>requires-clause</i></span> is equivalent to:
<spanclass='texttt'>U</span> if <spanclass='texttt'>T</span> is of the form <spanclass='texttt'>power<spanclass='anglebracket'><</span>U, Ints<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span></span>, and
</code></div></div></div><divclass='para'id='algos-2'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-2'>2</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1085'>#</a></div><divclass='texpara'><divid='algos-2.sentence-1'class='sentence'><i>Returns</i>: <spanclass='texttt'><spanclass='literal'>true</span></span> if <spanclass='texttt'>T</span> is less than <spanclass='texttt'>U</span>
</span></span></div><divclass='para'id='algos-3'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-3'>3</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1100'>#</a></div><divclass='texpara'><divid='algos-3.sentence-1'class='sentence'><spanclass='texttt'><i>type-less</i></span> meets the requirements of
the <spanclass='texttt'>Pred</span> parameter of the symbolic expression algorithms below<aclass='hidden_link'href='#algos-3.sentence-1'>.</a></div></div><divclass='texpara'><spanid='lib:expr-fractions'><spanid='lib:type-list'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:type-list'>🔗</a></div><spanclass='codeblock'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span> Ts<spanclass='anglebracket'>></span>
</span></span></span></div></div><divclass='para'id='algos-4'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-4'>4</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1117'>#</a></div><divclass='texpara'><divid='algos-4.sentence-1'class='sentence'><spanclass='texttt'><i>expr-fractions</i></span> divides a symbolic expression to numerator and denominator parts<aclass='hidden_link'href='#algos-4.sentence-1'>.</a></div><divid='algos-4.sentence-2'class='sentence'>Let <spanclass='texttt'>EF</span> be a specialization of <spanclass='texttt'><i>expr-fractions</i></span><aclass='hidden_link'href='#algos-4.sentence-2'>.</a></div><ulclass='itemize'><liid='algos-4.1'><divclass='marginalizedparent'style='left:-27mm'><aclass='marginalized'href='#algos-4.1'>(4.1)</a></div><divclass='texpara'><divid='algos-4.1.sentence-1'class='sentence'>If <spanclass='texttt'>EF</span> is of the form <spanclass='texttt'><spanclass='texttt'><i>expr-fractions</i></span><spanclass='anglebracket'><</span>OneType, Ts<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span>, per<spanclass='anglebracket'><</span>Us<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span><spanclass='anglebracket'>></span></span>,
<ulclass='itemize'><liid='algos-4.1.1'><divclass='marginalizedparent'style='left:-36mm'><aclass='marginalized'href='#algos-4.1.1'>(4.1.1)</a></div><spanclass='texttt'>EF<spanclass='operator'>​::​</span><spanclass='texttt'><i>num</i></span></span> denotes <spanclass='texttt'><spanclass='texttt'><i>type-list</i></span><spanclass='anglebracket'><</span>Ts<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span></span>, and</li><liid='algos-4.1.2'><divclass='marginalizedparent'style='left:-36mm'><aclass='marginalized'href='#algos-4.1.2'>(4.1.2)</a></div><spanclass='texttt'>EF<spanclass='operator'>​::​</span><spanclass='texttt'><i>den</i></span></span> denotes <spanclass='texttt'><spanclass='texttt'><i>type-list</i></span><spanclass='anglebracket'><</span>Us<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span></span><aclass='hidden_link'href='#algos-4.1.sentence-1'>.</a></li></ul></div></div></li><liid='algos-4.2'><divclass='marginalizedparent'style='left:-27mm'><aclass='marginalized'href='#algos-4.2'>(4.2)</a></div><divclass='texpara'><divid='algos-4.2.sentence-1'class='sentence'>Otherwise, <spanclass='texttt'>EF</span> is of the form <spanclass='texttt'><spanclass='texttt'><i>expr-fractions</i></span><spanclass='anglebracket'><</span>OneType, Ts<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span></span>, and
<ulclass='itemize'><liid='algos-4.2.1'><divclass='marginalizedparent'style='left:-36mm'><aclass='marginalized'href='#algos-4.2.1'>(4.2.1)</a></div><spanclass='texttt'>EF<spanclass='operator'>​::​</span><spanclass='texttt'><i>num</i></span></span> denotes <spanclass='texttt'><spanclass='texttt'><i>type-list</i></span><spanclass='anglebracket'><</span>Ts<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span></span>, and</li><liid='algos-4.2.2'><divclass='marginalizedparent'style='left:-36mm'><aclass='marginalized'href='#algos-4.2.2'>(4.2.2)</a></div><spanclass='texttt'>EF<spanclass='operator'>​::​</span><spanclass='texttt'><i>den</i></span></span> denotes <spanclass='texttt'><spanclass='texttt'><i>type-list</i></span><spanclass='anglebracket'><</span><spanclass='anglebracket'>></span></span><aclass='hidden_link'href='#algos-4.2.sentence-1'>.</a></li></ul></div></div></li></ul></div></div><divclass='para'id='algos-5'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-5'>5</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1140'>#</a></div><divclass='texpara'><divid='algos-5.sentence-1'class='sentence'>The symbolic expression algorithms perform operations on symbolic constants<aclass='hidden_link'href='#algos-5.sentence-1'>.</a></div><divid='algos-5.sentence-2'class='sentence'>A symbolic constant is a type that is a model of <ahref='#concept:SymbolicConstant'title='5.3.4.2 Concept SymbolicConstant [qty.sym.expr.concepts]'><spanid='conceptref:SymbolicConstant_'><spanclass='texttt'><i>SymbolicConstant</i></span></span></a><aclass='hidden_link'href='#algos-5.sentence-2'>.</a></div><divid='algos-example-1'class='example'><divclass='texpara'>[<i>Example <ahref='#algos-example-1'>1</a></i>: <divid='algos-5.sentence-3'class='sentence'>The dimension <spanclass='texttt'>dim_<spanclass='shy'></span>length</span>, the quantity <spanclass='texttt'>time</span>, and the unit <spanclass='texttt'>one</span> are symbolic constants<aclass='hidden_link'href='#algos-5.sentence-3'>.</a></div> — <i>end example</i>]</div></div><divid='algos-5.sentence-4'class='sentence'>
powers with a symbolic constant base and a rational exponent,
products thereof, and
fractions thereof<aclass='hidden_link'href='#algos-5.sentence-4'>.</a></div></div></div><divclass='texpara'><divid='lib:expr-pow'><divid='lib:expr-invert'><divid='lib:expr-divide'><divid='lib:expr-multiply'><divclass='itemdecl'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:expr-multiply'>🔗</a></div><codeclass='itemdeclcode'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span><spanclass='keyword'>typename</span> To, <spanclass='keyword'>typename</span> OneType,
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span>, <spanclass='keyword'>typename</span><spanclass='anglebracket'>></span><spanclass='keyword'>typename</span> Pred <spanclass='operator'>=</span><spanclass='texttt'><i>type-less</i></span>, <spanclass='keyword'>typename</span> Lhs, <spanclass='keyword'>typename</span> Rhs<spanclass='anglebracket'>></span>
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span><spanclass='keyword'>typename</span> To, <spanclass='keyword'>typename</span> OneType,
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span>, <spanclass='keyword'>typename</span><spanclass='anglebracket'>></span><spanclass='keyword'>typename</span> Pred <spanclass='operator'>=</span><spanclass='texttt'><i>type-less</i></span>, <spanclass='keyword'>typename</span> Lhs, <spanclass='keyword'>typename</span> Rhs<spanclass='anglebracket'>></span>
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span>std<spanclass='operator'>::</span>intmax_t Num, std<spanclass='operator'>::</span>intmax_t Den, <spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span><spanclass='keyword'>typename</span> To,
<spanclass='keyword'>typename</span> OneType, <spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span>, <spanclass='keyword'>typename</span><spanclass='anglebracket'>></span><spanclass='keyword'>typename</span> Pred <spanclass='operator'>=</span><spanclass='texttt'><i>type-less</i></span>, <spanclass='keyword'>typename</span> T<spanclass='anglebracket'>></span>
</code></div></div></div></div></div></div><divclass='para'id='algos-6'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-6'>6</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1174'>#</a></div><divclass='texpara'><divid='algos-6.sentence-1'class='sentence'><i>Mandates</i>: <ulclass='itemize'><liid='algos-6.1'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-6.1'>(6.1)</a></div><spanclass='texttt'>OneType</span> is the neutral element (<ahref="https://www.electropedia.org/iev/iev.nsf/display?openform&ievref=102-01-19">IEC 60050, 102-01-19</a>) of the operation, and</li><liid='algos-6.2'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-6.2'>(6.2)</a></div><spanclass='texttt'>Pred</span> is a <i>Cpp17BinaryTypeTrait</i> (<ahref="https://wg21.link/meta.rqmts">N4971, [meta.rqmts]</a>)
with a base characteristic of <spanclass='texttt'>std<spanclass='operator'>​::​</span>bool_<spanclass='shy'></span>constant<spanclass='anglebracket'><</span>B<spanclass='anglebracket'>></span></span><aclass='hidden_link'href='#algos-6.sentence-1'>.</a><divclass='texpara'><divid='algos-6.2.sentence-2'class='sentence'><spanclass='texttt'>Pred<spanclass='anglebracket'><</span>T, U<spanclass='anglebracket'>></span></span> implements a total order for types;
<spanclass='texttt'>B</span> is <spanclass='texttt'><spanclass='literal'>true</span></span> if <spanclass='texttt'>T</span> is ordered before <spanclass='texttt'>U</span>, and <spanclass='texttt'><spanclass='literal'>false</span></span> otherwise<aclass='hidden_link'href='#algos-6.2.sentence-2'>.</a></div></div></li></ul></div></div></div></div><divclass='para'id='algos-7'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-7'>7</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1186'>#</a></div><divclass='texpara'><divid='algos-7.sentence-1'class='sentence'><i>Effects</i>: </div></div></div></div><divclass='para'id='algos-8'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-8'>8</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1188'>#</a></div><divclass='texpara'><divid='algos-8.sentence-1'class='sentence'>First, inputs to the operations are obtained from the types of the function parameters<aclass='hidden_link'href='#algos-8.sentence-1'>.</a></div><divid='algos-8.sentence-2'class='sentence'>If the type of a function parameter is:
<ulclass='itemize'><liid='algos-8.1'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-8.1'>(8.1)</a></div><divclass='texpara'><divid='algos-8.1.sentence-1'class='sentence'>A specialization of <spanclass='texttt'>To</span>,
then its input is the product of its template arguments, and
the following also apply<aclass='hidden_link'href='#algos-8.1.sentence-1'>.</a></div></div></li><liid='algos-8.2'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-8.2'>(8.2)</a></div><divclass='texpara'><divid='algos-8.2.sentence-1'class='sentence'>A specialization of <spanclass='texttt'>per</span>,
then its input is the product of the inverse of its template arguments, and
the following also apply<aclass='hidden_link'href='#algos-8.2.sentence-1'>.</a></div></div></li><liid='algos-8.3'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-8.3'>(8.3)</a></div><divclass='texpara'><divid='algos-8.3.sentence-1'class='sentence'>A specialization of the form <spanclass='texttt'>power<spanclass='anglebracket'><</span>F, Num<spanclass='anglebracket'>></span></span>,
then its input is <spanclass="mjx-chtml"><spanclass="mjx-math"><spanclass="mjx-mrow"aria-hidden="true"><spanclass="mjx-msubsup"><spanclass="mjx-base"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.225em;">F</span></span></span></span></span><spanclass="mjx-sup"style="font-size: 70.7%; vertical-align: 0.513em; padding-left: 0px; padding-right: 0.071em;"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.298em;">Num</span></span></span></span></span></span></span></span></span>, or
a specialization of the form <spanclass='texttt'>power<spanclass='anglebracket'><</span>F, Num, Den<spanclass='anglebracket'>></span></span>,
then its input is <spanclass="mjx-chtml"><spanclass="mjx-math"><spanclass="mjx-mrow"aria-hidden="true"><spanclass="mjx-msubsup"><spanclass="mjx-base"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.225em;">F</span></span></span></span></span><spanclass="mjx-sup"style="font-size: 70.7%; vertical-align: 0.513em; padding-left: 0px; padding-right: 0.071em;"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.298em;">Num</span></span></span></span><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mo"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.446em; padding-bottom: 0.593em;">/</span></span></span></span><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.298em;">Den</span></span></span></span></span></span></span></span></span></span></span>, and
the following also applies<aclass='hidden_link'href='#algos-8.3.sentence-1'>.</a></div></div></li><liid='algos-8.4'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-8.4'>(8.4)</a></div><divclass='texpara'><divid='algos-8.4.sentence-1'class='sentence'>Otherwise, the input is the symbolic constant itself<aclass='hidden_link'href='#algos-8.4.sentence-1'>.</a></div></div></li></ul></div><divid='algos-example-2'class='example'><divclass='texpara'>[<i>Example <ahref='#algos-example-2'>2</a></i>: <divid='algos-8.sentence-3'class='sentence'>Item by item, this algorithm step goes from the C++ parameter type
in the mathematical domain<aclass='hidden_link'href='#algos-8.sentence-3'>.</a></li></ul></div> — <i>end example</i>]</div></div></div></div></div><divclass='para'id='algos-9'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-9'>9</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1227'>#</a></div><divclass='texpara'><divid='algos-9.sentence-1'class='sentence'>Then, the operation takes place:
<ulclass='itemize'><liid='algos-9.1'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-9.1'>(9.1)</a></div><spanclass='texttt'><i>expr-multiply</i></span> multiplies its inputs,</li><liid='algos-9.2'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-9.2'>(9.2)</a></div><spanclass='texttt'><i>expr-divide</i></span> divides the input of its first parameter by the input of its second parameter,</li><liid='algos-9.3'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-9.3'>(9.3)</a></div><spanclass='texttt'><i>expr-invert</i></span> divides <spanclass='math'>1</span> by its input, and</li><liid='algos-9.4'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-9.4'>(9.4)</a></div><spanclass='texttt'><i>expr-pow</i></span> raises its input to the <spanclass="mjx-chtml"><spanclass="mjx-math"><spanclass="mjx-mrow"aria-hidden="true"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.298em;">Num</span></span></span></span><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mo"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.446em; padding-bottom: 0.593em;">/</span></span></span></span><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mtext"><spanclass="mjx-char MJXc-TeX-type-R"style="padding-top: 0.372em; padding-bottom: 0.298em;">Den</span></span></span></span></span></span></span><aclass='hidden_link'href='#algos-9.sentence-1'>.</a></li></ul></div></div></div></div><divclass='para'id='algos-10'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-10'>10</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1240'>#</a></div><divclass='texpara'><divid='algos-10.sentence-1'class='sentence'>Finally, let <spanclass='math'><spanclass='mathalpha'>r</span></span> be the result of the operation simplified as follows:
<ulclass='itemize'><liid='algos-10.1'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-10.1'>(10.1)</a></div><divclass='texpara'><divid='algos-10.1.sentence-1'class='sentence'>All terms are part of the same fraction (if any)<aclass='hidden_link'href='#algos-10.1.sentence-1'>.</a></div></div></li><liid='algos-10.2'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-10.2'>(10.2)</a></div><divclass='texpara'><divid='algos-10.2.sentence-1'class='sentence'>There is at most a single term with a given symbolic constant<aclass='hidden_link'href='#algos-10.2.sentence-1'>.</a></div></div></li><liid='algos-10.3'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-10.3'>(10.3)</a></div><divclass='texpara'><divid='algos-10.3.sentence-1'class='sentence'>There are no negative exponents<aclass='hidden_link'href='#algos-10.3.sentence-1'>.</a></div></div></li><liid='algos-10.4'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-10.4'>(10.4)</a></div><divclass='texpara'><divid='algos-10.4.sentence-1'class='sentence'><spanclass='math'>1</span> is only present as <spanclass='math'><spanclass='mathalpha'>r</span></span> and as a numerator with a denominator not equal to <spanclass='math'>1</span><aclass='hidden_link'href='#algos-10.4.sentence-1'>.</a></div></div></li></ul></div><divid='algos-example-3'class='example'><divclass='texpara'>[<i>Example <ahref='#algos-example-3'>3</a></i>: <divid='algos-10.sentence-2'class='sentence'>Item by item: <br/></div><spanclass="mjx-chtml"><spanclass="mjx-math"><spanclass="mjx-mrow"aria-hidden="true"><spanclass="mjx-mi"><spanclass="mjx-char MJXc-TeX-math-I"style="padding-top: 0.225em; padding-bottom: 0.298em;">x</span></span><spanclass="mjx-mo MJXc-space2"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.225em; padding-bottom: 0.298em;">×</span></span><spanclass="mjx-texatom MJXc-space2"><spanclass="mjx-mrow"></span></span><spanclass="mjx-mn"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.372em; padding-bottom: 0.372em;">1</span></span><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mo"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.446em; padding-bottom: 0.593em;">/</span></span></span></span><spanclass="mjx-mi"><spanclass="mjx-char MJXc-TeX-math-I"style="padding-top: 0.225em; padding-bottom: 0.519em; padding-right: 0.006em;">y</span></span><spanclass="mjx-mo MJXc-space2"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.225em; padding-bottom: 0.298em;">×</span></span><spanclass="mjx-texatom MJXc-space2"><spanclass="mjx-mrow"></span></span><spanclass="mjx-mn"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.372em; padding-bottom: 0.372em;">1</span></span><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mo"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.446em; padding-bottom: 0.593em;">/</span></span></span></span><spanclass="mjx-msubsup"><spanclass="mjx-base"><spanclass="mjx-mi"><spanclass="mjx-char MJXc-TeX-math-I"style="padding-top: 0.225em; padding-bottom: 0.298em;">x</span></span></span><spanclass="mjx-sup"style="font-size: 70.7%; vertical-align: 0.513em; padding-left: 0px; padding-right: 0.071em;"><spanclass="mjx-mn"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.372em; padding-bottom: 0.372em;">2</span></span></span></span></span></span></span><br/><divid='algos-10.sentence-3'class='sentence'><spanclass="mjx-chtml"><spanclass="mjx-math"><spanclass="mjx-mrow"aria-hidden="true"><spanclass="mjx-mo"><spanclass="mjx-char MJXc-TeX-main-R"style="padding-top: 0.077em; padding-bottom: 0.298em;">=</span></span><spanclass="mjx-mi MJXc-space3"><spanclass="mjx-char MJXc-TeX-math-I"style="padding-top: 0.225em; padding-bottom: 0.298em;">x</span></span><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mo"><spanclass="mjx-char MJXc-TeX-main-
<spanclass="mjx-chtml"><spanclass="mjx-math"><spanclass="mjx-mrow"aria-hidden="true"><spanclass="mjx-msubsup"><spanclass="mjx-base"><spanclass="mjx-mi"><spanclass="mjx-char MJXc-TeX-math-I"style="padding-top: 0.225em; padding-bottom: 0.298em;">x</span></span></span><spanclass="mjx-sup"style="font-size: 70.7%; vertical-align: 0.513em; padding-left: 0px; padding-right: 0.071em;"><spanclass="mjx-texatom"><spanclass="mjx-mrow"><spanclass="mjx-mi"><spanclass="mjx-char MJXc-TeX-math-I"style="padding-top: 0.225em; padding-bottom: 0.298em;">n</span></span></span></span></span></span></span></span></span> is mapped to <spanclass='texttt'>power<spanclass='anglebracket'><</span><spanclass='math'><spanclass='mathalpha'>x</span></span>, <spanclass='math'><spanclass='mathalpha'>n</span></span><spanclass='anglebracket'>></span></span>, and</li><liid='algos-11.3.2'><divclass='marginalizedparent'style='left:-48mm'><aclass='marginalized'href='#algos-11.3.2'>(11.3.2)</a></div><spanclass='math'>1</span> is mapped to <spanclass='texttt'>OneType<spanclass='curlybracket'>{</span><spanclass='curlybracket'>}</span></span><aclass='hidden_link'href='#algos-11.3.sentence-1'>.</a></li></ul></div></div></li><liid='algos-11.4'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-11.4'>(11.4)</a></div><divclass='texpara'><divid='algos-11.4.sentence-1'class='sentence'>Then, a denominator <spanclass='math'><spanclass='mathalpha'>x</span></span> of <spanclass='math'><spanclass='mathalpha'>r</span></span> (if any) is mapped to <spanclass='texttt'>per<spanclass='anglebracket'><</span><spanclass='math'><spanclass='mathalpha'>x</span></span><spanclass='anglebracket'>></span></span><aclass='hidden_link'href='#algos-11.4.sentence-1'>.</a></div></div></li><liid='algos-11.5'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-11.5'>(11.5)</a></div><divclass='texpara'><divid='algos-11.5.sentence-1'class='sentence'>Then, sorts <spanclass='math'><spanclass='mathalpha'>r</span></span> without <spanclass='texttt'>per</span> (if any) and
the template arguments of <spanclass='texttt'>per</span> (if any)
according to <spanclass='texttt'>Pred</span><aclass='hidden_link'href='#algos-11.5.sentence-1'>.</a></div></div></li><liid='algos-11.6'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-11.6'>(11.6)</a></div><divclass='texpara'><divid='algos-11.6.sentence-1'class='sentence'>Finally, returns <spanclass='texttt'>To<spanclass='anglebracket'><</span><spanclass='math'><spanclass='mathalpha'>r</span></span><spanclass='anglebracket'>></span><spanclass='curlybracket'>{</span><spanclass='curlybracket'>}</span></span>, where <spanclass='texttt'>per</span> (if any) is the last argument<aclass='hidden_link'href='#algos-11.6.sentence-1'>.</a></div></div></li></ul></div></div></div></div><divclass='para'id='algos-12'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-12'>12</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1288'>#</a></div><divclass='texpara'><divid='algos-12.sentence-1'class='sentence'><i>Remarks</i>: A valid template argument list for <spanclass='texttt'>To</span> and <spanclass='texttt'>per</span>
is formed by interspersing commas between each mapped term<aclass='hidden_link'href='#algos-12.sentence-1'>.</a></div><divid='algos-12.sentence-2'class='sentence'>If a mapping to <spanclass='texttt'>std<spanclass='operator'>​::​</span>intmax_<spanclass='shy'></span>t</span> is not representable,
the program is ill-formed<aclass='hidden_link'href='#algos-12.sentence-2'>.</a></div></div></div></div><divclass='para'id='algos-13'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-13'>13</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1296'>#</a></div><divclass='texpara'><divid='algos-13.sentence-1'class='sentence'><spanclass='texttt'><i>expr-map</i></span> maps the contents of one symbolic expression to another resulting in a different type list<aclass='hidden_link'href='#algos-13.sentence-1'>.</a></div></div></div><divclass='texpara'><divid='lib:expr-map'><divclass='itemdecl'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:expr-map'>🔗</a></div><codeclass='itemdeclcode'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span><spanclass='anglebracket'>></span><spanclass='keyword'>typename</span> Proj, <spanclass='keyword'>template</span><spanclass='anglebracket'><</span><spanclass='keyword'>typename</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span><spanclass='keyword'>typename</span> To, <spanclass='keyword'>typename</span> OneType,
<ulclass='itemize'><liid='algos-14.1'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-14.1'>(14.1)</a></div><spanclass='texttt'><spanclass='texttt'><i>expr-type-map</i></span><spanclass='anglebracket'><</span>U<spanclass='anglebracket'>></span></span> be
<spanclass='texttt'>power<spanclass='anglebracket'><</span>Proj<spanclass='anglebracket'><</span>F<spanclass='anglebracket'>></span>, Ints<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span></span> if <spanclass='texttt'>U</span> is of the form <spanclass='texttt'>power<spanclass='anglebracket'><</span>F, Ints<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span></span>, and
<spanclass='texttt'>Proj<spanclass='anglebracket'><</span>U<spanclass='anglebracket'>></span></span> otherwise,</li><liid='algos-14.2'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-14.2'>(14.2)</a></div><spanclass='texttt'><spanclass='texttt'><i>map-power</i></span><spanclass='parenthesis'>(</span>u<spanclass='parenthesis'>)</span></span> be
<spanclass='texttt'>pow<spanclass='anglebracket'><</span>Ints<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span><spanclass='parenthesis'>(</span>F<spanclass='curlybracket'>{</span><spanclass='curlybracket'>}</span><spanclass='parenthesis'>)</span></span> if <spanclass='texttt'><spanclass='keyword'>decltype</span><spanclass='parenthesis'>(</span>u<spanclass='parenthesis'>)</span></span> is of the form <spanclass='texttt'>power<spanclass='anglebracket'><</span>F, Ints<spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='anglebracket'>></span></span>, and
<spanclass='texttt'>u</span> otherwise, and</li><liid='algos-14.3'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#algos-14.3'>(14.3)</a></div><spanclass='texttt'>Nums</span> and <spanclass='texttt'>Dens</span>
<spanclass='texttt'>T<spanclass='operator'>​::​</span><spanclass='texttt'><i>nums</i></span></span> and <spanclass='texttt'>T<spanclass='operator'>​::​</span><spanclass='texttt'><i>dens</i></span></span>, respectively<aclass='hidden_link'href='#algos-14.sentence-1'>.</a></li></ul></div></div></div></div><divclass='para'id='algos-15'><divclass='marginalizedparent'><aclass='marginalized'href='#algos-15'>15</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L1324'>#</a></div><divclass='texpara'><divid='algos-15.sentence-1'class='sentence'><i>Returns</i>: <spanclass='codeblock'><spanclass='parenthesis'>(</span>OneType<spanclass='curlybracket'>{</span><spanclass='curlybracket'>}</span><spanclass='operator'>*</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>.</span><spanclass='operator'>*</span><i>map-power</i><spanclass='parenthesis'>(</span><i>expr-type-map</i><spanclass='anglebracket'><</span>Nums<spanclass='anglebracket'>></span><spanclass='curlybracket'>{</span><spanclass='curlybracket'>}</span><spanclass='parenthesis'>)</span><spanclass='parenthesis'>)</span><spanclass='operator'>/</span>