MathGroup Archive 2014

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: What's in an expression?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132417] Re: What's in an expression?
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Tue, 11 Mar 2014 03:36:08 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20140310083813.8DCCA6A2A@smc.vnet.net>

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


{Cos[x]}


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, <sam.takoy at yahoo.com> 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
>
>




  • Prev by Date: Re: What's in an expression?
  • Next by Date: Re: What's in an expression?
  • Previous by thread: What's in an expression?
  • Next by thread: Re: What's in an expression?