[LON-CAPA-users] math rendering engine

Justin Gray lon-capa-users@mail.lon-capa.org
Tue, 19 Jan 2010 15:05:06 -0800


--001517576db65e1fef047d8c8184
Content-Type: text/plain; charset=ISO-8859-1

Thanks, Stefan! This works great and is much cleaner using arrays.

I have left in a separate array @displayfunctions in this problem. Indeed,
this is unnecessary but it allows me to display the equations nicely, and so
I have one array @functions with the functions expressed in Maxima syntax
and another array @displayfunctions with the functions expressed in LaTeX.
The <algebra> tag is versatile but seems to be incompatible with some of the
more cosmetic LaTeX commands that I use to display equations.

Many thanks for identifying my parsing problems.

Best,
Justin

Justin Gray | Senior Lecturer
Department of Mathematics | Simon Fraser University
8888 University Drive, Burnaby | V5A 1S6 | Canada
Tel: +1 778.782.4237




On Tue, Jan 19, 2010 at 2:47 AM, Stefan Bisitz <st.bisitz@ostfalia.de>wrote:

> Hi Justin and other math authors,
>
> Once again another optimization:
> You might want to put your functions into an array and the answer examples,
> too. Then dynamically choose from these lists by using
> $n = &random(1,$#functions,1);
> $function = $functions[$n];
> $example = $examples[$n];
>
> This way, you can easily add (or remove) functions by just adding them to
> the functions array and add an example to the examples array. No other code
> adjustments are needed.
>
> The following problem source code respects all of this and the other
> optimizations discussed before. It's not fully tested, but should work.
>
> Hope this helps,
> Stefan Bisitz
>
> ----------------------------------------------------------------
>
> <problem>
> <script type="loncapa/perl">
> @functions = (
>  "(x^2 - 1)^2",
>  "sqrt(x^2 - 1)",
>  "3/(2 + x^2)",
>  "2/(3 + sqrt(1 + x))",
> );
> @examples = (
>  &xmlparse('Many answers are possible. One example would be <m>$ f(x) =
> x^2, \quad g(x) = x^2 - 1 $</m>'),
>  &xmlparse('Many answers are possible. One example would be <m>$ f(x) =
> \sqrt{x}, \quad g(x) = x^2 - 1 $</m>'),
>  &xmlparse('Many answers are possible. One example would be <m>$ f(x) =
> 3/x, \quad g(x) = 2 + x^2 $</m>'),
>
>  &xmlparse('Many answers are possible. One example would be <m>$ f(x) =
> 2/(3 + x), \quad g(x) = \sqrt{1 + x} $</m>'),
> );
> $n = &random(1,$#functions,1);
> $function = $functions[$n];
> $example = $examples[$n];
> </script>
>
> <startouttext />
> <p>Give an example of two nontrivial functions <m>$ f $</m> and <m>$ g
> $</m> such that <m eval="on">$ (f \circ g)(x) = $</m>
> <algebra>$function</algebra>.</p>Enter your answer in the form
> <p><b>expression1,expression2</b></p> where <m>$ f(x) =  $</m>
> <b>expression1</b> and <m>$ g(x) =  $</m> <b>expression2</b>.<p></p>
>
> <endouttext />
>
> <mathresponse answerdisplay="$example" cas="maxima" args="$function"
> id="11">
>    <answer>f(x) := RESPONSE[1];
> g(x) := RESPONSE[2];
> h(x) := LONCAPALIST[1];
> composition:is(trigsimp(f(g(x)) - h(x)) = 0);
> fnottrivial:is(not(f(x) = x));
> gnottrivial:is(not(g(x) = x));
> composition and fnottrivial and gnottrivial;</answer>
>    <textline readonly="no" size="20" />
>    <hintgroup showoncorrect="no">
>        <mathhint name="composition not equal" cas="maxima" args="$function"
> id="12">
>            <answer>f(x) := RESPONSE[1];
> g(x) := RESPONSE[2];
> h(x) := LONCAPALIST[1];
> is(not(f(g(x)) = h(x)));</answer>
>        </mathhint>
> <hintpart on="composition not equal">
>    <startouttext /><p>Your example does not satisfy <m eval="on">$ (f \circ
> g)(x) = f(g(x)) = $</m> <algebra>$function</algebra>.</p><endouttext />
>
> </hintpart>
>    </hintgroup>
>    <hintgroup showoncorrect="no">
>        <mathhint name="f trivial" cas="maxima" id="13">
>            <answer>f(x) := RESPONSE[1];
> is(f(x) = x);</answer>
>        </mathhint>
> <hintpart on="f trivial">
>    <startouttext /><p>The question asks for nontrivial functions, and so
> you cannot use <m>$ f(x) = x $</m>.</p><endouttext />
> </hintpart>
>    </hintgroup>
>    <hintgroup showoncorrect="no">
>        <mathhint name="g trivial" cas="maxima" id="14">
>            <answer>g(x) := RESPONSE[2];
> is(g(x) = x);</answer>
>        </mathhint>
> <hintpart on="g trivial">
>    <startouttext /><p>The question asks for nontrivial functions, and so
> you cannot use <m>$ g(x) = x $</m>.</p><endouttext />
> </hintpart>
>    </hintgroup>
> </mathresponse>
> </problem>
> ----------------------------------------------------------------
>
>
>
> On 19.01.2010 11:13, Stefan Bisitz wrote:
>
>> And again... ;-)
>>
>> Much better (the best?):
>>
>> Don't use two variables, one for calculations and one for display. It's
>> simpler, shorter and less error-prone to have only one variable:
>>
>> <script type="loncapa/perl">
>> $function1 = "(x^2 - 1)^2";
>> $function2 = "sqrt(x^2 - 1)";
>> $function3 = "3/(2 + x^2)";
>> $function4 = "2/(3 + sqrt(1 + x))";
>> $example1=[...]
>> </script>
>>
>> <startouttext />
>> <p>Give an example of two nontrivial functions <m>$ f $</m> and <m>$ g
>> $</m> such that <m eval="on">$ (f \circ g)(x) = $</m>
>> <algebra>$displayfunction</algebra>.</p>
>> [...]
>> <endouttext />
>>
>>
>> In general, store or calculate your formula in one variable using the
>> 1-dimensional "pocket calculator" notation. Reuse the same variable to
>> display it by using the <algebra> tag (without any "$") which automatically
>> renders in the preferred method.
>>
>> Stefan Bisitz
>>
>>
>> On 19.01.2010 11:04, Stefan Bisitz wrote:
>>
>>> Hi again,
>>>
>>> Why "pre-parse" anyway?
>>>
>>> Even better:
>>>
>>> 1)
>>> <script type="loncapa/perl">
>>> [...]
>>> $displayfunction1 = '(x^2 - 1)^2';
>>> [...]
>>>
>>> and 2)
>>> [...]
>>> such that <m eval="on">$ (f \circ g)(x) = $displayfunction $</m>.
>>> [...]
>>>
>>>
>>> Stefan Bisitz
>>>
>>>
>>> On 19.01.2010 10:32, Stefan Bisitz wrote:
>>>
>>>> Hi Justin,
>>>>
>>>> It's quite simple to solve your display issues. You parse the formula
>>>> twice:
>>>> 1) $displayfunction1 = &xmlparse('<m>$(x^2 - 1)^2$</m>');
>>>> [...]
>>>>
>>>> 2) <m eval="on">$(f \circ g)(x) = $displayfunction $</m>
>>>>
>>>> Just change to
>>>> <m>$ (f \circ g)(x) = $</m> $displayfunction
>>>>
>>>> $displayfunction is already parsed and must not be included again in the
>>>> <m> tag.
>>>>
>>>> tth as well as mimetex works now (tested on bleeding edge machine).
>>>>
>>>> And yes, please avoid to use jsmath hardcoded in the problem. Let the
>>>> CCs or students decide.
>>>>
>>>> Stefan Bisitz
>>>>
>>>>
>>>>
>>>> On 19.01.2010 09:59, Justin Gray wrote:
>>>>
>>>>> When displaying equations, setting the display attribute within the <m>
>>>>> tag to "jsMath" is generally discouraged as it requires users to have
>>>>> installed jsmath software on their computer and will override their
>>>>> preferences on how math equations are displayed.
>>>>>
>>>>> I have tried viewing the problem below on several computers and jsMath
>>>>> seems to be the only math rendering engine that lets me view the equations
>>>>> properly. (With tth the equations do not show up at all and with mimetex the
>>>>> equations are incomprehensible.) I am reluctant to force users to jsMath for
>>>>> this problem. Perhaps there is another way to remedy this problem?
>>>>>
>>>>> Any suggestions are appreciated.
>>>>>
>>>>> Thanks,
>>>>> Justin
>>>>>
>>>>> Justin Gray | Senior Lecturer
>>>>> Department of Mathematics | Simon Fraser University
>>>>> 8888 University Drive, Burnaby | V5A 1S6 | Canada
>>>>> Tel: +1 778.782.4237
>>>>>
>>>>> <problem>
>>>>> <script type="loncapa/perl">
>>>>> $function1 = "(x^2 - 1)^2";
>>>>> $function2 = "sqrt(x^2 - 1)";
>>>>> $function3 = "3/(2 + x^2)";
>>>>> $function4 = "2/(3 + sqrt(1 + x))";
>>>>> $displayfunction1 = &xmlparse('<m>$(x^2 - 1)^2$</m>');
>>>>> $displayfunction2 = &xmlparse('<m>$\sqrt{x^2 - 1}$</m>');
>>>>> $displayfunction3 = &xmlparse('<m>$\displaystyle \frac{3}{2 +
>>>>> x^2}$</m>');
>>>>> $displayfunction4 = &xmlparse('<m>$\displaystyle \frac{2}{3 + \sqrt{1 +
>>>>> x}}$</m>');
>>>>> $example1=&xmlparse('Many answers are possible. One example would be
>>>>> <m>$f(x) = x^2, \quad g(x) = x^2 - 1$</m>');
>>>>> $example2=&xmlparse('Many answers are possible. One example would be
>>>>> <m>$f(x) = \sqrt{x}, \quad g(x) = x^2 - 1$</m>');
>>>>> $example3=&xmlparse('Many answers are possible. One example would be
>>>>> <m>$f(x) = 3/x, \quad g(x) = 2 + x^2$</m>');
>>>>> $example4=&xmlparse('Many answers are possible. One example would be
>>>>> <m>$f(x) = 2/(3 + x), \quad g(x) = \sqrt{1 + x}$</m>');
>>>>> $n = &random(1,4,1);
>>>>> $function =
>>>>> &choose($n,"$function1","$function2","$function3","$function4");
>>>>> $displayfunction =
>>>>> &choose($n,"$displayfunction1","$displayfunction2","$displayfunction3","$displayfunction4");
>>>>>
>>>>> $example = &choose($n,"$example1","$example2","$example3","$example4");
>>>>> </script>
>>>>>
>>>>> <startouttext /><p>Give an example of two nontrivial functions
>>>>> <m>$f$</m> and <m>$g$</m> such that <m eval="on">$(f \circ g)(x) =
>>>>> $displayfunction $</m>.</p>Enter your answer in the form
>>>>> <p><b>expression1,expression2</b></p> where <m>$f(x) = $</m>
>>>>> <b>expression1</b> and <m>$g(x) = $</m>
>>>>> <b>expression2</b>.<p></p><endouttext />
>>>>>
>>>>> <mathresponse answerdisplay="$example" cas="maxima" args="$function"
>>>>> id="11">
>>>>>    <answer>f(x) := RESPONSE[1];
>>>>> g(x) := RESPONSE[2];
>>>>> h(x) := LONCAPALIST[1];
>>>>> composition:is(trigsimp(f(g(x)) - h(x)) = 0);
>>>>> fnottrivial:is(not(f(x) = x));
>>>>> gnottrivial:is(not(g(x) = x));
>>>>> composition and fnottrivial and gnottrivial;</answer>
>>>>>    <textline readonly="no" size="20" />
>>>>>    <hintgroup showoncorrect="no">
>>>>>        <mathhint name="composition not equal" cas="maxima"
>>>>> args="$function" id="12">
>>>>>            <answer>f(x) := RESPONSE[1];
>>>>> g(x) := RESPONSE[2];
>>>>> h(x) := LONCAPALIST[1];
>>>>> is(not(f(g(x)) = h(x)));</answer>
>>>>>        </mathhint>
>>>>> <hintpart on="composition not equal">
>>>>>    <startouttext /><p>Your example does not satisfy <m eval="on">$(f
>>>>> \circ g)(x) = f(g(x)) = $displayfunction $</m>.</p><endouttext />
>>>>> </hintpart>
>>>>>    </hintgroup>
>>>>>    <hintgroup showoncorrect="no">
>>>>>        <mathhint name="f trivial" cas="maxima" id="13">
>>>>>            <answer>f(x) := RESPONSE[1];
>>>>> is(f(x) = x);</answer>
>>>>>        </mathhint>
>>>>> <hintpart on="f trivial">
>>>>>    <startouttext /><p>The question asks for nontrivial functions, and
>>>>> so you cannot use <m>$f(x) = x$</m>.</p><endouttext />
>>>>> </hintpart>
>>>>>    </hintgroup>
>>>>>    <hintgroup showoncorrect="no">
>>>>>        <mathhint name="g trivial" cas="maxima" id="14">
>>>>>            <answer>g(x) := RESPONSE[2];
>>>>> is(g(x) = x);</answer>
>>>>>        </mathhint>
>>>>> <hintpart on="g trivial">
>>>>>    <startouttext /><p>The question asks for nontrivial functions, and
>>>>> so you cannot use <m>$g(x) = x$</m>.</p><endouttext />
>>>>> </hintpart>
>>>>>    </hintgroup>
>>>>> </mathresponse>
>>>>> </problem>
>>>>>
>>>>>
>>>>>
>>>>>
>>>> _______________________________________________
>>>> LON-CAPA-users mailing list
>>>> LON-CAPA-users@mail.lon-capa.org
>>>> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
>>>>
>>>
>>>
>>>
>> _______________________________________________
>> LON-CAPA-users mailing list
>> LON-CAPA-users@mail.lon-capa.org
>> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
>>
>
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users@mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
>

--001517576db65e1fef047d8c8184
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Thanks, Stefan! This works great and is much cleaner using arrays. <br><br>=
I have left in a separate array @displayfunctions in this problem. Indeed, =
this is unnecessary but it allows me to display the equations nicely, and s=
o I have one array @functions with the functions expressed in Maxima syntax=
 and another array @displayfunctions with the functions expressed in LaTeX.=
 The &lt;algebra&gt; tag is versatile but seems to be incompatible with som=
e of the more cosmetic LaTeX commands that I use to display equations. <br>

<br>Many thanks for identifying my parsing problems.<br><br>Best,<br>Justin=
<br><br clear=3D"all">Justin Gray | Senior Lecturer<br>Department of Mathem=
atics | Simon Fraser University<br>8888 University Drive, Burnaby | V5A 1S6=
 | Canada<br>

Tel: +1 778.782.4237<br><br><br>
<br><br><div class=3D"gmail_quote">On Tue, Jan 19, 2010 at 2:47 AM, Stefan =
Bisitz <span dir=3D"ltr">&lt;<a href=3D"mailto:st.bisitz@ostfalia.de">st.bi=
sitz@ostfalia.de</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote"=
 style=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.=
8ex; padding-left: 1ex;">

Hi Justin and other math authors,<br>
<br>
Once again another optimization:<br>
You might want to put your functions into an array and the answer examples,=
 too. Then dynamically choose from these lists by using<br>
$n =3D &amp;random(1,$#functions,1);<br>
$function =3D $functions[$n];<br>
$example =3D $examples[$n];<br>
<br>
This way, you can easily add (or remove) functions by just adding them to t=
he functions array and add an example to the examples array. No other code =
adjustments are needed.<br>
<br>
The following problem source code respects all of this and the other optimi=
zations discussed before. It&#39;s not fully tested, but should work.<br>
<br>
Hope this helps,<br>
Stefan Bisitz<br>
<br>
----------------------------------------------------------------<div class=
=3D"im"><br>
&lt;problem&gt;<br>
&lt;script type=3D&quot;loncapa/perl&quot;&gt;<br></div>
@functions =3D (<br>
 =A0&quot;(x^2 - 1)^2&quot;,<br>
 =A0&quot;sqrt(x^2 - 1)&quot;,<br>
 =A0&quot;3/(2 + x^2)&quot;,<br>
 =A0&quot;2/(3 + sqrt(1 + x))&quot;,<br>
);<br>
@examples =3D (<br>
 =A0&amp;xmlparse(&#39;Many answers are possible. One example would be &lt;=
m&gt;$ f(x) =3D x^2, \quad g(x) =3D x^2 - 1 $&lt;/m&gt;&#39;),<br>
 =A0&amp;xmlparse(&#39;Many answers are possible. One example would be &lt;=
m&gt;$ f(x) =3D \sqrt{x}, \quad g(x) =3D x^2 - 1 $&lt;/m&gt;&#39;),<br>
 =A0&amp;xmlparse(&#39;Many answers are possible. One example would be &lt;=
m&gt;$ f(x) =3D 3/x, \quad g(x) =3D 2 + x^2 $&lt;/m&gt;&#39;),<div class=3D=
"im"><br>
 =A0&amp;xmlparse(&#39;Many answers are possible. One example would be &lt;=
m&gt;$ f(x) =3D 2/(3 + x), \quad g(x) =3D \sqrt{1 + x} $&lt;/m&gt;&#39;),<b=
r>
);<br></div>
$n =3D &amp;random(1,$#functions,1);<br>
$function =3D $functions[$n];<br>
$example =3D $examples[$n];<br>
&lt;/script&gt;<br>
<br>
&lt;startouttext /&gt;<br>
&lt;p&gt;Give an example of two nontrivial functions &lt;m&gt;$ f $&lt;/m&g=
t; and &lt;m&gt;$ g $&lt;/m&gt; such that &lt;m eval=3D&quot;on&quot;&gt;$ =
(f \circ g)(x) =3D $&lt;/m&gt; &lt;algebra&gt;$function&lt;/algebra&gt;.&lt=
;/p&gt;Enter your answer in the form &lt;p&gt;&lt;b&gt;expression1,expressi=
on2&lt;/b&gt;&lt;/p&gt; where &lt;m&gt;$ f(x) =3D =A0$&lt;/m&gt; &lt;b&gt;e=
xpression1&lt;/b&gt; and &lt;m&gt;$ g(x) =3D =A0$&lt;/m&gt; &lt;b&gt;expres=
sion2&lt;/b&gt;.&lt;p&gt;&lt;/p&gt;<div class=3D"im">

<br>
&lt;endouttext /&gt;<br>
<br>
&lt;mathresponse answerdisplay=3D&quot;$example&quot; cas=3D&quot;maxima&qu=
ot; args=3D&quot;$function&quot; id=3D&quot;11&quot;&gt;<br>
 =A0 =A0&lt;answer&gt;f(x) :=3D RESPONSE[1];<br>
g(x) :=3D RESPONSE[2];<br>
h(x) :=3D LONCAPALIST[1];<br>
composition:is(trigsimp(f(g(x)) - h(x)) =3D 0);<br>
fnottrivial:is(not(f(x) =3D x));<br>
gnottrivial:is(not(g(x) =3D x));<br>
composition and fnottrivial and gnottrivial;&lt;/answer&gt;<br>
 =A0 =A0&lt;textline readonly=3D&quot;no&quot; size=3D&quot;20&quot; /&gt;<=
br>
 =A0 =A0&lt;hintgroup showoncorrect=3D&quot;no&quot;&gt;<br>
 =A0 =A0 =A0 =A0&lt;mathhint name=3D&quot;composition not equal&quot; cas=
=3D&quot;maxima&quot; args=3D&quot;$function&quot; id=3D&quot;12&quot;&gt;<=
br>
 =A0 =A0 =A0 =A0 =A0 =A0&lt;answer&gt;f(x) :=3D RESPONSE[1];<br>
g(x) :=3D RESPONSE[2];<br>
h(x) :=3D LONCAPALIST[1];<br>
is(not(f(g(x)) =3D h(x)));&lt;/answer&gt;<br>
 =A0 =A0 =A0 =A0&lt;/mathhint&gt;<br>
&lt;hintpart on=3D&quot;composition not equal&quot;&gt;<br></div>
 =A0 =A0&lt;startouttext /&gt;&lt;p&gt;Your example does not satisfy &lt;m =
eval=3D&quot;on&quot;&gt;$ (f \circ g)(x) =3D f(g(x)) =3D $&lt;/m&gt; &lt;a=
lgebra&gt;$function&lt;/algebra&gt;.&lt;/p&gt;&lt;endouttext /&gt;<div clas=
s=3D"im">

<br>
&lt;/hintpart&gt;<br>
 =A0 =A0&lt;/hintgroup&gt;<br>
 =A0 =A0&lt;hintgroup showoncorrect=3D&quot;no&quot;&gt;<br>
 =A0 =A0 =A0 =A0&lt;mathhint name=3D&quot;f trivial&quot; cas=3D&quot;maxim=
a&quot; id=3D&quot;13&quot;&gt;<br>
 =A0 =A0 =A0 =A0 =A0 =A0&lt;answer&gt;f(x) :=3D RESPONSE[1];<br>
is(f(x) =3D x);&lt;/answer&gt;<br>
 =A0 =A0 =A0 =A0&lt;/mathhint&gt;<br>
&lt;hintpart on=3D&quot;f trivial&quot;&gt;<br>
 =A0 =A0&lt;startouttext /&gt;&lt;p&gt;The question asks for nontrivial fun=
ctions, and so you cannot use &lt;m&gt;$ f(x) =3D x $&lt;/m&gt;.&lt;/p&gt;&=
lt;endouttext /&gt;<br>
&lt;/hintpart&gt;<br>
 =A0 =A0&lt;/hintgroup&gt;<br>
 =A0 =A0&lt;hintgroup showoncorrect=3D&quot;no&quot;&gt;<br>
 =A0 =A0 =A0 =A0&lt;mathhint name=3D&quot;g trivial&quot; cas=3D&quot;maxim=
a&quot; id=3D&quot;14&quot;&gt;<br>
 =A0 =A0 =A0 =A0 =A0 =A0&lt;answer&gt;g(x) :=3D RESPONSE[2];<br>
is(g(x) =3D x);&lt;/answer&gt;<br>
 =A0 =A0 =A0 =A0&lt;/mathhint&gt;<br>
&lt;hintpart on=3D&quot;g trivial&quot;&gt;<br>
 =A0 =A0&lt;startouttext /&gt;&lt;p&gt;The question asks for nontrivial fun=
ctions, and so you cannot use &lt;m&gt;$ g(x) =3D x $&lt;/m&gt;.&lt;/p&gt;&=
lt;endouttext /&gt;<br>
&lt;/hintpart&gt;<br>
 =A0 =A0&lt;/hintgroup&gt;<br>
&lt;/mathresponse&gt;<br>
&lt;/problem&gt;<br></div>
----------------------------------------------------------------<div><div><=
/div><div class=3D"h5"><br>
<br>
<br>
On 19.01.2010 11:13, Stefan Bisitz wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
And again... ;-)<br>
<br>
Much better (the best?):<br>
<br>
Don&#39;t use two variables, one for calculations and one for display. It&#=
39;s simpler, shorter and less error-prone to have only one variable:<br>
<br>
&lt;script type=3D&quot;loncapa/perl&quot;&gt;<br>
$function1 =3D &quot;(x^2 - 1)^2&quot;;<br>
$function2 =3D &quot;sqrt(x^2 - 1)&quot;;<br>
$function3 =3D &quot;3/(2 + x^2)&quot;;<br>
$function4 =3D &quot;2/(3 + sqrt(1 + x))&quot;;<br>
$example1=3D[...]<br>
&lt;/script&gt;<br>
<br>
&lt;startouttext /&gt;<br>
&lt;p&gt;Give an example of two nontrivial functions &lt;m&gt;$ f $&lt;/m&g=
t; and &lt;m&gt;$ g $&lt;/m&gt; such that &lt;m eval=3D&quot;on&quot;&gt;$ =
(f \circ g)(x) =3D $&lt;/m&gt; &lt;algebra&gt;$displayfunction&lt;/algebra&=
gt;.&lt;/p&gt;<br>


[...]<br>
&lt;endouttext /&gt;<br>
<br>
<br>
In general, store or calculate your formula in one variable using the 1-dim=
ensional &quot;pocket calculator&quot; notation. Reuse the same variable to=
 display it by using the &lt;algebra&gt; tag (without any &quot;$&quot;) wh=
ich automatically renders in the preferred method.<br>


<br>
Stefan Bisitz<br>
<br>
<br>
On 19.01.2010 11:04, Stefan Bisitz wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi again,<br>
<br>
Why &quot;pre-parse&quot; anyway?<br>
<br>
Even better:<br>
<br>
1)<br>
&lt;script type=3D&quot;loncapa/perl&quot;&gt;<br>
[...]<br>
$displayfunction1 =3D &#39;(x^2 - 1)^2&#39;;<br>
[...]<br>
<br>
and 2)<br>
[...]<br>
such that &lt;m eval=3D&quot;on&quot;&gt;$ (f \circ g)(x) =3D $displayfunct=
ion $&lt;/m&gt;.<br>
[...]<br>
<br>
<br>
Stefan Bisitz<br>
<br>
<br>
On 19.01.2010 10:32, Stefan Bisitz wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Justin,<br>
<br>
It&#39;s quite simple to solve your display issues. You parse the formula t=
wice:<br>
1) $displayfunction1 =3D &amp;xmlparse(&#39;&lt;m&gt;$(x^2 - 1)^2$&lt;/m&gt=
;&#39;);<br>
[...]<br>
<br>
2) &lt;m eval=3D&quot;on&quot;&gt;$(f \circ g)(x) =3D $displayfunction $&lt=
;/m&gt;<br>
<br>
Just change to<br>
&lt;m&gt;$ (f \circ g)(x) =3D $&lt;/m&gt; $displayfunction<br>
<br>
$displayfunction is already parsed and must not be included again in the &l=
t;m&gt; tag.<br>
<br>
tth as well as mimetex works now (tested on bleeding edge machine).<br>
<br>
And yes, please avoid to use jsmath hardcoded in the problem. Let the CCs o=
r students decide.<br>
<br>
Stefan Bisitz<br>
<br>
<br>
<br>
On 19.01.2010 09:59, Justin Gray wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
When displaying equations, setting the display attribute within the &lt;m&g=
t; tag to &quot;jsMath&quot; is generally discouraged as it requires users =
to have<br>
installed jsmath software on their computer and will override their prefere=
nces on how math equations are displayed.<br>
<br>
I have tried viewing the problem below on several computers and jsMath seem=
s to be the only math rendering engine that lets me view the equations prop=
erly. (With tth the equations do not show up at all and with mimetex the eq=
uations are incomprehensible.) I am reluctant to force users to jsMath for =
this problem. Perhaps there is another way to remedy this problem?<br>


<br>
Any suggestions are appreciated.<br>
<br>
Thanks,<br>
Justin<br>
<br>
Justin Gray | Senior Lecturer<br>
Department of Mathematics | Simon Fraser University<br>
8888 University Drive, Burnaby | V5A 1S6 | Canada<br>
Tel: +1 778.782.4237<br>
<br>
&lt;problem&gt;<br>
&lt;script type=3D&quot;loncapa/perl&quot;&gt;<br>
$function1 =3D &quot;(x^2 - 1)^2&quot;;<br>
$function2 =3D &quot;sqrt(x^2 - 1)&quot;;<br>
$function3 =3D &quot;3/(2 + x^2)&quot;;<br>
$function4 =3D &quot;2/(3 + sqrt(1 + x))&quot;;<br>
$displayfunction1 =3D &amp;xmlparse(&#39;&lt;m&gt;$(x^2 - 1)^2$&lt;/m&gt;&#=
39;);<br>
$displayfunction2 =3D &amp;xmlparse(&#39;&lt;m&gt;$\sqrt{x^2 - 1}$&lt;/m&gt=
;&#39;);<br>
$displayfunction3 =3D &amp;xmlparse(&#39;&lt;m&gt;$\displaystyle \frac{3}{2=
 + x^2}$&lt;/m&gt;&#39;);<br>
$displayfunction4 =3D &amp;xmlparse(&#39;&lt;m&gt;$\displaystyle \frac{2}{3=
 + \sqrt{1 + x}}$&lt;/m&gt;&#39;);<br>
$example1=3D&amp;xmlparse(&#39;Many answers are possible. One example would=
 be &lt;m&gt;$f(x) =3D x^2, \quad g(x) =3D x^2 - 1$&lt;/m&gt;&#39;);<br>
$example2=3D&amp;xmlparse(&#39;Many answers are possible. One example would=
 be &lt;m&gt;$f(x) =3D \sqrt{x}, \quad g(x) =3D x^2 - 1$&lt;/m&gt;&#39;);<b=
r>
$example3=3D&amp;xmlparse(&#39;Many answers are possible. One example would=
 be &lt;m&gt;$f(x) =3D 3/x, \quad g(x) =3D 2 + x^2$&lt;/m&gt;&#39;);<br>
$example4=3D&amp;xmlparse(&#39;Many answers are possible. One example would=
 be &lt;m&gt;$f(x) =3D 2/(3 + x), \quad g(x) =3D \sqrt{1 + x}$&lt;/m&gt;&#3=
9;);<br>
$n =3D &amp;random(1,4,1);<br>
$function =3D &amp;choose($n,&quot;$function1&quot;,&quot;$function2&quot;,=
&quot;$function3&quot;,&quot;$function4&quot;);<br>
$displayfunction =3D &amp;choose($n,&quot;$displayfunction1&quot;,&quot;$di=
splayfunction2&quot;,&quot;$displayfunction3&quot;,&quot;$displayfunction4&=
quot;); <br>
$example =3D &amp;choose($n,&quot;$example1&quot;,&quot;$example2&quot;,&qu=
ot;$example3&quot;,&quot;$example4&quot;);<br>
&lt;/script&gt;<br>
<br>
&lt;startouttext /&gt;&lt;p&gt;Give an example of two nontrivial functions =
&lt;m&gt;$f$&lt;/m&gt; and &lt;m&gt;$g$&lt;/m&gt; such that &lt;m eval=3D&q=
uot;on&quot;&gt;$(f \circ g)(x) =3D $displayfunction $&lt;/m&gt;.&lt;/p&gt;=
Enter your answer in the form &lt;p&gt;&lt;b&gt;expression1,expression2&lt;=
/b&gt;&lt;/p&gt; where &lt;m&gt;$f(x) =3D $&lt;/m&gt; &lt;b&gt;expression1&=
lt;/b&gt; and &lt;m&gt;$g(x) =3D $&lt;/m&gt; &lt;b&gt;expression2&lt;/b&gt;=
.&lt;p&gt;&lt;/p&gt;&lt;endouttext /&gt;<br>


<br>
&lt;mathresponse answerdisplay=3D&quot;$example&quot; cas=3D&quot;maxima&qu=
ot; args=3D&quot;$function&quot; id=3D&quot;11&quot;&gt;<br>
 =A0 =A0&lt;answer&gt;f(x) :=3D RESPONSE[1];<br>
g(x) :=3D RESPONSE[2];<br>
h(x) :=3D LONCAPALIST[1];<br>
composition:is(trigsimp(f(g(x)) - h(x)) =3D 0);<br>
fnottrivial:is(not(f(x) =3D x));<br>
gnottrivial:is(not(g(x) =3D x));<br>
composition and fnottrivial and gnottrivial;&lt;/answer&gt;<br>
 =A0 =A0&lt;textline readonly=3D&quot;no&quot; size=3D&quot;20&quot; /&gt;<=
br>
 =A0 =A0&lt;hintgroup showoncorrect=3D&quot;no&quot;&gt;<br>
 =A0 =A0 =A0 =A0&lt;mathhint name=3D&quot;composition not equal&quot; cas=
=3D&quot;maxima&quot; args=3D&quot;$function&quot; id=3D&quot;12&quot;&gt;<=
br>
 =A0 =A0 =A0 =A0 =A0 =A0&lt;answer&gt;f(x) :=3D RESPONSE[1];<br>
g(x) :=3D RESPONSE[2];<br>
h(x) :=3D LONCAPALIST[1];<br>
is(not(f(g(x)) =3D h(x)));&lt;/answer&gt;<br>
 =A0 =A0 =A0 =A0&lt;/mathhint&gt;<br>
&lt;hintpart on=3D&quot;composition not equal&quot;&gt;<br>
 =A0 =A0&lt;startouttext /&gt;&lt;p&gt;Your example does not satisfy &lt;m =
eval=3D&quot;on&quot;&gt;$(f \circ g)(x) =3D f(g(x)) =3D $displayfunction $=
&lt;/m&gt;.&lt;/p&gt;&lt;endouttext /&gt;<br>
&lt;/hintpart&gt;<br>
 =A0 =A0&lt;/hintgroup&gt;<br>
 =A0 =A0&lt;hintgroup showoncorrect=3D&quot;no&quot;&gt;<br>
 =A0 =A0 =A0 =A0&lt;mathhint name=3D&quot;f trivial&quot; cas=3D&quot;maxim=
a&quot; id=3D&quot;13&quot;&gt;<br>
 =A0 =A0 =A0 =A0 =A0 =A0&lt;answer&gt;f(x) :=3D RESPONSE[1];<br>
is(f(x) =3D x);&lt;/answer&gt;<br>
 =A0 =A0 =A0 =A0&lt;/mathhint&gt;<br>
&lt;hintpart on=3D&quot;f trivial&quot;&gt;<br>
 =A0 =A0&lt;startouttext /&gt;&lt;p&gt;The question asks for nontrivial fun=
ctions, and so you cannot use &lt;m&gt;$f(x) =3D x$&lt;/m&gt;.&lt;/p&gt;&lt=
;endouttext /&gt;<br>
&lt;/hintpart&gt;<br>
 =A0 =A0&lt;/hintgroup&gt;<br>
 =A0 =A0&lt;hintgroup showoncorrect=3D&quot;no&quot;&gt;<br>
 =A0 =A0 =A0 =A0&lt;mathhint name=3D&quot;g trivial&quot; cas=3D&quot;maxim=
a&quot; id=3D&quot;14&quot;&gt;<br>
 =A0 =A0 =A0 =A0 =A0 =A0&lt;answer&gt;g(x) :=3D RESPONSE[2];<br>
is(g(x) =3D x);&lt;/answer&gt;<br>
 =A0 =A0 =A0 =A0&lt;/mathhint&gt;<br>
&lt;hintpart on=3D&quot;g trivial&quot;&gt;<br>
 =A0 =A0&lt;startouttext /&gt;&lt;p&gt;The question asks for nontrivial fun=
ctions, and so you cannot use &lt;m&gt;$g(x) =3D x$&lt;/m&gt;.&lt;/p&gt;&lt=
;endouttext /&gt;<br>
&lt;/hintpart&gt;<br>
 =A0 =A0&lt;/hintgroup&gt;<br>
&lt;/mathresponse&gt;<br>
&lt;/problem&gt;<br>
<br>
<br>
<br>
</blockquote>
<br>
_______________________________________________<br>
LON-CAPA-users mailing list<br>
<a href=3D"mailto:LON-CAPA-users@mail.lon-capa.org" target=3D"_blank">LON-C=
APA-users@mail.lon-capa.org</a><br>
<a href=3D"http://mail.lon-capa.org/mailman/listinfo/lon-capa-users" target=
=3D"_blank">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</a><br=
>
</blockquote>
<br>
<br>
</blockquote>
<br>
_______________________________________________<br>
LON-CAPA-users mailing list<br>
<a href=3D"mailto:LON-CAPA-users@mail.lon-capa.org" target=3D"_blank">LON-C=
APA-users@mail.lon-capa.org</a><br>
<a href=3D"http://mail.lon-capa.org/mailman/listinfo/lon-capa-users" target=
=3D"_blank">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</a><br=
>
</blockquote>
<br>
_______________________________________________<br>
LON-CAPA-users mailing list<br>
<a href=3D"mailto:LON-CAPA-users@mail.lon-capa.org" target=3D"_blank">LON-C=
APA-users@mail.lon-capa.org</a><br>
<a href=3D"http://mail.lon-capa.org/mailman/listinfo/lon-capa-users" target=
=3D"_blank">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</a><br=
>
</div></div></blockquote></div><br>

--001517576db65e1fef047d8c8184--