Consider the following 3 lines of code:

Reduce[1. Log[3 - x] + 2. Log[1 + x] == 2.1972245773362196, x]
Reduce[1. Log[3 - x] + 2. Log[1 + x] == 2.1972245773362196 && x < 2, x]
Reduce[1. Log[3 - x] + 2. Log[1 + x] == 2.19722 && x < 2, x]

Which give the following output (and warning about exact representation which I have not included here)

Reduce[1. Log[3 - x] + 2. Log[1 + x] == 2.19722, x]

x == 1.30278 || x == 2.

x == 1.30276

Is there something I can change so that these give results that are more in line?

  • I am particularly interested in making the 2nd the the third agree (since x==2 does not satisfy x<2)

I realize this is likely an issue of precision. My difficulty is that the numbers (1.,2.,2.19722...) are coming from earlier parts of code (i.e. I am not manually entering such numbers).

Perhaps if I tell mathematica to work with a certain level of precision (somehow keep it exact, or maybe use SetPrecision?) the discrepancy will be resolved?

  • If so, is there I way I can tell mathematica to set precision locally (only for part of my notebook)?

1 Answer 1


Closer inspection shows that Reduce is correct:

Reduce[1. Log[3 - x] + 2. Log[1 + x] == 2.1972245773362196 && x < 2, x] //
 Style[#, PrintPrecision -> 17] &
Reduce[1. Log[3 - x] + 2. Log[1 + x] == 2.19722 && x < 2.1, x] // 
 Style[#, PrintPrecision -> 17] &

  x == 1.3027756377319955 || x == 1.9999999999999993
  x == 1.30275925064097   || x == 2.000013731662965

I increased the range on x in the second one, so that we can see where the root moved to. If you don't want the second solution, change the inequality to x < 1.9; if you want both, change it to x < 2.1. If you want the second solution to be 2 exactly in the first call, you might have to use exact input. (In fact, changing the left-hand side to 2.19722457733621935 results in a root that is numericized to 2. precisely and is excluded by the inequality.) You could try using arbitrary precision numbers at the beginning of your computation, and improve the accuracy that way. It's hard to say since we can't inspect the computations that led to the Reduce command.

  • $\begingroup$ Thanks. I understand that Reduce is correct. Then Is there a way I can tell mathematica to use (or display) a certain number of precision in a local environment (perhaps block or preferably module). $\endgroup$
    – user106860
    Mar 30, 2021 at 17:10
  • 2
    $\begingroup$ @user106860 Yes, aside from using arbitrary precision numbers that I alluded to, see $MinPrecision. Another requirement is to not use machine precision numbers, because they say MachinePrecision and are not controlled by $MinPrecision. The documentation I linked is a bit confusing on that point. $\endgroup$
    – Michael E2
    Mar 30, 2021 at 17:23
  • 1
    $\begingroup$ *they stay MachinePrecision... $\endgroup$
    – Michael E2
    Mar 30, 2021 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.