The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: What's in an expression?
Replies: 8   Last Post: Mar 15, 2014 3:54 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bob Hanlon

Posts: 906
Registered: 10/29/11
Re: What's in an expression?
Posted: Mar 11, 2014 3:16 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Assuming that answers are entered as strings; to exclude derivatives but
allow other alternative forms:

verifySolution[proposed_, actual_, cond_: {}] :=
StringFreeQ[proposed, {"Derivative", "'", "D["}] &&
Simplify[ToExpression[proposed] == actual, cond]

answers = {"Sin'[x]", "Derivative[1][Sin][x]",
"D[Sin[x],x]", "Cos[x]", "Sin[x]/Tan[x]"};

ToExpression /@ answers // Union


verifySolution[#, Cos[x]] & /@ answers

{False, False, False, True, True}

If the answer must be literally the same as the intended answer:

verifySolution2[proposed_, actual_] :=
SameQ @@ (StringTrim /@ {proposed, actual})

verifySolution2[#, "Cos[x]"] & /@ answers

{False, False, False, True, False}

Bob Hanlon

On Mon, Mar 10, 2014 at 4:38 AM, <> wrote:

> Hi all,
> I'm building a little Mathematica system that checks answers entered by
> students. Suppose the question is "what is Sin'[x]?" ad the student
> responds: Sin'[x] which is "correct", but not the intended answer (Cos[x]).
> I'm wondering if there is a general way to approach this sort of problem.
> In particular, is there a way to find out whether a given expression
> includes certain elements (like Derivative)?
> Thank you in advance,
> Sam

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.