Ask Your Question
1

simplification errors in simple expressions

asked 2011-09-22 17:53:33 +0200

Dirk Danckaert gravatar image

updated 2023-01-10 00:01:08 +0200

tmonteil gravatar image

I'm currently testing the possibilities of SAGE as a teaching aid in a high school math course (in Belgium). I stumbled upon this:

  • When evaluating x/sqrt(x^2), SAGE answers $\frac{x}{|x|}$, as it should. Appending a .simpify()-instruction to the input does not change anything.
  • However, ((1-x^2)/sqrt(1-2*x^2+x^4)).simplify_full() evaluates to $-1$, in stead of $\frac{1-x^2}{|1-x^2|}$.

As an aside, it's definitely baffling that a behemoth program like SAGE is outdone in this respect by a one-floppy-disk, antique program called DERIVE.

As another aside, I still have to find a meaningful use for the instruction simplify(). Can someone provide me an expression that is actually simplified by simplify()?

Note added: I'm not sure I'm satisfied with mr. Fateman's answer (and I definitely disagree that defining sqrt(x^2)=|x| - for real x - entails +1=-1). But what I really want to know is this: is there a SAGE object that represents (reliably) the positive square root of a positive real number x? (Surely a quantity that is not without interest.) And how do I define it in SAGE?

edit retag flag offensive close merge delete

Comments

1

The issue in the second item seems to be that `(sqrt(1-2*x^2+x^4)).simplify_radical()` returns `x^2 - 1`. I'm not sure why, but it's calling maxima to do this computation.

John Palmieri gravatar imageJohn Palmieri ( 2011-09-23 01:04:49 +0200 )edit

Maxima's radcan apparently automatically chooses a branch. See below and the link I'm about to give.

kcrisman gravatar imagekcrisman ( 2011-09-23 11:31:37 +0200 )edit

3 Answers

Sort by ยป oldest newest most voted
4

answered 2011-09-23 11:15:25 +0200

Richard Fateman gravatar image

updated 2011-09-23 11:28:35 +0200

kcrisman gravatar image

x/sqrt(x^2) is NOT x/abs(x). There are two square roots of x^2, -x and +x. Neither one of them is abs(x).

If you proceed with the belief that the correct answer is abs(x), you can easily prove (for example) that 1=-1.

Because some people over the years have preferred the incorrect answer, Macsyma and then Maxima has incorporated heuristics that depend on the setting of a flag, radcan, and also depend on domain (e.g. real or complex) and on assumptions (e.g. assume(x>0)) to control the result in this case. Since Maxima (and apparently Sage) is not programmed to deal with multi-valued expressions, you can expect that the answer to such a simplification will be unsatisfactory to some people under some settings of some flags and some options.

Sage apparently has a command called "simplify_full" which calls something in Maxima, but since that command does not exist in Maxima, it is unclear what it is going to do. There are a host of commands in Maxima that do some sort of simplification, e.g. ratsimp, fullratsimp, trigsimp, poissimp, factor, expand, ratexpand, and others. They are controlled by various flags, too.

[Edit by kcrisman - the issue here is Sage's use of radcan().]

As for the general complaint that Sage should do something that DERIVE does -- (a) DERIVE is carefully crafted to match the expectations of a certain audience, and does very well at it. As long as the problems are not "too big".
(b) Sage is a behemoth program, but the authors have only a modest understanding of what is in it, at least with respect to Maxima. If your intention is "do high school math" maybe you should directly use Maxima, esp. wxmaxima. Accessing Maxima via Sage is clumsy. Like tying your shoes while wearing mittens.

There are other computer algebra systems (much simpler than Maxima) and maybe closer to DERIVE in spirit, that might do exactly what you want (high school algebra?) and not much more.

Good luck!

edit flag offensive delete link more

Comments

I'll upvote this, as it explains the problem well, even though most Sage (and I'd guess, most Maxima) users don't really understand the difference between a symbolic expression and a function. My surprise here was that radcan() was so aggressive in choosing a branch for radicals.

kcrisman gravatar imagekcrisman ( 2011-09-23 11:31:12 +0200 )edit

Note also that before calling radcan, Sage does `maxima.eval('domain: real$')`. This presumably has some effect?

John Palmieri gravatar imageJohn Palmieri ( 2011-09-23 12:43:26 +0200 )edit

Not in this case, though perhaps in general. I didn't attach the Maxima session here, but it's in the thread referenced in my response.

kcrisman gravatar imagekcrisman ( 2011-09-23 12:45:41 +0200 )edit

I'll refrain from bickering about the 'correct' definition of sqrt(x^2). But whichever definition is used in SAGE, it should be used consistently. If sqrt(x^2) is considered to have two values, then it can't be simplified. And neither can sqrt(1-2x^2+x^4). Simplifying the expression in my post to -1 surely is nonsense. In regard to your suggestion of using Maxima directly: that is no option. There's much much more to choosing a tool for high school then the definition that is used for sqrt(x). If I fall for SAGE, it's because of the notebook interface. I'll have to weigh that pro to the con of using something 'way too big'. I still hope I can hide the intricacies of SAGE to my students, while giving them the benefit of a tremendously useful interface.

Dirk Danckaert gravatar imageDirk Danckaert ( 2011-09-23 13:18:03 +0200 )edit
1

answered 2011-09-22 22:26:59 +0200

kcrisman gravatar image

updated 2011-09-25 23:22:48 +0200

The method simplify() sends things to Maxima and back. This is useful with assumptions.

sage: var('n')
n
sage: assume(n,'integer')
sage: sin(n*pi)
sin(pi*n)
sage: sin(n*pi).simplify()
0

As for your comment, you have to "forget" assumptions about a variable to use other ones. One also has to tell Maxima that the domain is "real", not complex, for the x<0 assumption to take effect. This is somewhat troublesome, but doable.

sage: assume(x<0)
sage: maxima_calculus.eval('domain:real')
'real'
sage: sqrt(x^2).simplify()
-x

As for the error, I've sent an email to the Maxima list about this. The thread starts here. Essentially, Maxima's radcan() picks a branch and sticks with it, rather than treating sqrt() as a function per se. But Fateman's answer above gives you what you need to know (even if the news is not so good).

edit flag offensive delete link more

Comments

I see. But it seems the use of simplify() is also lacking in consistency. E.g. "assume(x>0);simplify(sqrt(x^2))" returns x, (I dare not add 'as it should') but "assume(x<0);simplify(sqrt(x^2))" doesn't return -x. Meanwhile, I'm watching the Maxima thread.

Dirk Danckaert gravatar imageDirk Danckaert ( 2011-09-23 16:16:01 +0200 )edit

Yes, the "assumptions framework" in Maxima is described as relatively weak by the Maxima doc or other comments by the devs. However, it's better than anything else we have available in Sage. See also my edit to this answer.

kcrisman gravatar imagekcrisman ( 2011-09-25 23:18:51 +0200 )edit

It's beginning to make sense. But I knew about forget(), so that was not the issue. I didn't know about the 'domain:real' thing, though. Strangely, an experiment I just did (with the code you provided, but preceded with forget()) required .simplify_full()(which I knew already to do the job) to get the (-x) result. .simplify() on its own kept returning sqrt(x^2). Then after a few re-evaluations of the same cell (with minor edits of the code), all of a sudden .simplify() returned (-x) too. And kept doing so afterwards. A little bizarre.

Dirk Danckaert gravatar imageDirk Danckaert ( 2011-09-26 09:21:33 +0200 )edit
0

answered 2013-11-06 10:47:17 +0200

kcrisman gravatar image

Update: http://trac.sagemath.org/ticket/12737 has been merged in Sage - which still doesn't give you exactly what you want, but perhaps is more to your liking:

sage: ((1-x^2)/sqrt(1-2*x^2+x^4)).simplify_full()
-(x^2 - 1)/sqrt(x^4 - 2*x^2 + 1)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2011-09-22 17:53:33 +0200

Seen: 1,797 times

Last updated: Nov 06 '13