Comments (4)
Well, one way to look at it is that the complex square root is multiple valued, and both of these are square roots of -4 so both are valid. But that doesn't tell you why the computations produce different ones in the two cases. Here the reason:
In the Complex context, all computations are performed using complex numbers, even if they started out as reals, so (-2)^2
is really (-2+0i)^(-2+0i)
. The complex power z^w
is computed using exp(w * log(z))
, with log(z)
as log(mod(z)) + arg(z)*i
, and arg(a + bi)
being atan2(b,a)
(arctangent of b/a, where the signs of a and b are taken into account to get an angle between -pi and pi). That means the branch cut for log(z)
is along the negative real axis, which is right where -4 lies, and so the computation is sensitive to slight changes in the complex part of the value.
Now getting back to (2+0i)*(-2+0i)
, this turns out to be a + bi
where a = -4 and b = -9.79717439317883e-16 a number very close, but not quite equal to, zero. But most important, it is negative, so that means (-2)^2 - 8
is across the branch cut from -4
, and arg((-2)^2)
is -pi (or very close to it) while arg(-4)
is pi. That means log((-2)^2 - 8) = log(4) - pi*i
while log(-4) = log(4) + pi * i
, which leads to sqrt(-4) = 2i
while sqrt((-2)^2 - 8) = -2i
.
Such issues are inherent in the fact the sqrt()
, log()
, arg()
and so on are multiple-valued. One could perhaps improve things by using different branch cuts for arg()
(say the positive x-axis when a + bi
has a < 0
, but this would still be problematic when everything is close to 0). It might be worth giving that a try.
from pg.
Even though (-2i)^2 = (2i)^2 = -4
, the usual convention with a square root is that the square root of a real number returns the positive result. So if a student enters the answer sqrt((-2)^2-8)
or sqrt(-4)
, it is rather unexpected to have the system tell them that first is incorrect and the second is not when 2i is the correct answer, and simplification is not expected.
from pg.
The problem is that the computed (-2)^2
isn't a real number (it is slightly off), so that doesn't happen. To fix that aspect of it, the Complex context would have to be made more sophisticated (in having it not promote all values to complex numbers before doing the computations). That is possible, but would take considerable reworking of the internals of the Complex context.
I was only trying to indicate why the result is what it is, not that it is ideal.
Also, my suggestion about changing arg()
for negative real parts is useless, as that just changes the branch cut to along the imaginary axis. D'oh!
from pg.
I suppose one possible approach would be to convert -9.79717439317883e-16 to actually being 0 (using the zeroLevelTol
and zeroLevel
values, so they can be configured by the problem author).
from pg.
Related Issues (20)
- Bug when a matrix Math Object is reused as an answer HOT 10
- PGML.pl has lines that should have been removed. HOT 1
- checkboxlist within a RadioMultiAnswer HOT 4
- Using upToConstant with complex numbers HOT 4
- keyboard issue with GraphTool HOT 7
- inconsistency in multiple choice macros HOT 3
- run-perltidy deletes .bak files
- Error answers now are escaped when they shouldn't be. HOT 1
- Cropping from pgfplots is not always working for final SVG output HOT 13
- variables declared with `my` lead to errors HOT 1
- student answers get spaces normalized
- iframeResizer, feedback popover, and mqeditor HOT 15
- Updating AnswerFormatHelp.pl HOT 5
- Viewing all correct answers at the same time HOT 4
- PTX "image" tag getting changed to "img" HOT 5
- error with brace and x HOT 9
- PG editor not decoding as expecting HOT 1
- macros/graph/PGnauGraphics.pl doesn't use unique name, which can break tests. HOT 1
- securtiy issues with braces HOT 2
- MathQuill toolbar placement in a relatively positioned parent - bug when in an RTL course. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pg.