Do we simplify sqrt(x^2) equal to |x| or x?

Given the request to simplify nth roots of products of x^m, I’m working on a solution.

However, I’m uncertain how precisely we need to verify assumptions for simplifying manipulations. For example, do we play it loosey-goosey and simplify sqrt(x^6) to x^3 even though that is invalid unless x >= 0? Or do we simplify it to |x|^3? (I assume we’re OK with assuming x is real.)

The math-expressions library underlying Doenet’s math does have an assumptions system, where one can add an assumption like x >= 0. However, I have not exposed that to Doenet, as I didn’t want to introduce that complexity to users. We could potentially hook into that, but such an endeavor would not be quick (nor high on the priority list).

The places where I have seen this question asked usually add that assumption in the problem statement, ~ assume all variables are positive real numbers.

Maybe I do have to add an assumptions attribute to <math> which will be pumped into the simplify function.

Like
<math simplify assumptions="x > 0">sqrt(x^2)</math>
will simplify to x. But
<math simplify>sqrt(x^2)</math>
will simplify to abs(x).

If I do that, expect to it work quite imperfectly at first…

We’d have to keep a running list of how it needs to be improved, with the idea that it might take awhile to get through the list.

Writing sqrt(x^2) = x is a common algebra error that we have to fight all the time – I literally had students make this error earlier today, in a multivariable calculus course, and it meant they got the problem wrong. I’d be… unhappy… with any online system that made this mistake be the default behavior.

But I’d also be happy to have a way to add the assumption that x >= 0. The potential behavior you described seems reasonable!

For what it’s worth, adding those conditions would be consistent with Mathematica:

In[11]:= Simplify[Sqrt[x^2]]
         Simplify[Sqrt[x^2], x \[Element] Reals]
         Simplify[Sqrt[x^2], x > 0]

Out[11]= Sqrt[x^2]

Out[12]= Abs[x]

Out[13]= x

(As long as I’m mentioning Mathematica: it uses Assumptions-> and also Assuming. I’m sure there’s a clear logical difference between them, but because I don’t use them every day, I always guess and get it wrong, and have to go look up which one I want. So I’ve vote for avoiding multiple similarly named attributes like that. :slight_smile: )

Now, my working model is that we don’t even assume that the variables are real. I hope that isn’t too much of a pain.

<math simplify>sqrt(x^2)</math> leaves the results as sqrt(x^2).

<math simplify assumptions="x>=0">sqrt(x^2)</math> gives x.

<math simplify assumptions="x ∈ R">sqrt(x^2)</math> gives abs(x).

I went ahead and released a dev version of this so folks can play around with simplifications of roots.

On beta.doenet.org, when editing a document, you can click on Settings and change the DoenetML version to 0.7dev. Then, the assumptions attribute should be available on <math> and it should simplify roots of powers if you give it the right assumptions.

I’m curious to hear if this is working the way you’d expect.

I agree with Jon and believe strongly that it should not simplify to x. I think being able to add assumptions is a nice feature, though I’m less sure about needing to specify that we are working with real numbers, as I would tend to assume that’s the case in most courses.

Yeah, I’m not sure about the complex/real assumption part either.

I left it with the more “conservative” assumption on assumptions for now, but I’m happy to revisit it.