Skip to main content
added 488 characters in body
Source Link
WillG
  • 1.1k
  • 6
  • 15

Consider the function

f[a_] := NIntegrate[Sqrt[a + Log[x]], {x, 1, 10}, WorkingPrecision -> 30].

With this definition, I cannot call f[0.1] (for example) without Mathematica throwing an error, since "0.1" is interpreted automatically as a machine number with MachinePrecision (about 16), whereas the integration requires 30 digits of precision.

But when I enter 0.1, of course I really mean 1/10. One solution is to enter f[1/10], but this is very inconvenient to do every time, especially because my real functions involve many parameters with long strings of decimal numbers. What's the best way around this issue? Ideally, I'd like Mathematica to interpret 0.1 as 1/10 automatically, as mentioned in the title.

EDIT

To clarify, I would like any decimal number input be treated as the exact mathematical number with the same name. For example, 0.### should become ###/1000. As pointed out in the comments, Rationalize converts 0.33333333 to 1/3, which I would consider a problem for my case. I would like Mathematica to treat decimal number input as exact numbers without rounding to any finite precision, nor assuming that I intended a "close" but different rational number.


Another option would be to change the function definition:

f[a_] := NIntegrate[Sqrt[Rationalize[a] + Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

or

f[a_] := NIntegrate[Sqrt[SetPrecision[a, \[Infinity]] + Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

But this too would be quite inconvenient to do for every function I use. I also worry about the fact that SetPrecision[0.1, \[Infinity]] does not give 1/10. So all this makes me wonder what the "right" method is.

Consider the function

f[a_] := NIntegrate[Sqrt[a + Log[x]], {x, 1, 10}, WorkingPrecision -> 30].

With this definition, I cannot call f[0.1] (for example) without Mathematica throwing an error, since "0.1" is interpreted automatically as a machine number with MachinePrecision (about 16), whereas the integration requires 30 digits of precision.

But when I enter 0.1, of course I really mean 1/10. One solution is to enter f[1/10], but this is very inconvenient to do every time, especially because my real functions involve many parameters with long strings of decimal numbers. What's the best way around this issue? Ideally, I'd like Mathematica to interpret 0.1 as 1/10 automatically, as mentioned in the title.


Another option would be to change the function definition:

f[a_] := NIntegrate[Sqrt[Rationalize[a] + Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

or

f[a_] := NIntegrate[Sqrt[SetPrecision[a, \[Infinity]] + Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

But this too would be quite inconvenient to do for every function I use. I also worry about the fact that SetPrecision[0.1, \[Infinity]] does not give 1/10. So all this makes me wonder what the "right" method is.

Consider the function

f[a_] := NIntegrate[Sqrt[a + Log[x]], {x, 1, 10}, WorkingPrecision -> 30].

With this definition, I cannot call f[0.1] (for example) without Mathematica throwing an error, since "0.1" is interpreted automatically as a machine number with MachinePrecision (about 16), whereas the integration requires 30 digits of precision.

But when I enter 0.1, of course I really mean 1/10. One solution is to enter f[1/10], but this is very inconvenient to do every time, especially because my real functions involve many parameters with long strings of decimal numbers. What's the best way around this issue? Ideally, I'd like Mathematica to interpret 0.1 as 1/10 automatically, as mentioned in the title.

EDIT

To clarify, I would like any decimal number input be treated as the exact mathematical number with the same name. For example, 0.### should become ###/1000. As pointed out in the comments, Rationalize converts 0.33333333 to 1/3, which I would consider a problem for my case. I would like Mathematica to treat decimal number input as exact numbers without rounding to any finite precision, nor assuming that I intended a "close" but different rational number.


Another option would be to change the function definition:

f[a_] := NIntegrate[Sqrt[Rationalize[a] + Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

or

f[a_] := NIntegrate[Sqrt[SetPrecision[a, \[Infinity]] + Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

But this too would be quite inconvenient to do for every function I use. I also worry about the fact that SetPrecision[0.1, \[Infinity]] does not give 1/10. So all this makes me wonder what the "right" method is.

edited body
Source Link
WillG
  • 1.1k
  • 6
  • 15

Consider the function

f[a_] := NIntegrate[aNIntegrate[Sqrt[a + Sqrt[Log[x]]Log[x]], {x, 1, 10}, WorkingPrecision -> 30].

With this definition, I cannot call f[0.1] (for example) without Mathematica throwing an error, since "0.1" is interpreted automatically as a machine number with MachinePrecision (about 16), whereas the integration requires 30 digits of precision.

But when I enter 0.1, of course I really mean 1/10. One solution is to enter f[1/10], but this is very inconvenient to do every time, especially because my real functions involve many parameters with long strings of decimal numbers. What's the best way around this issue? Ideally, I'd like Mathematica to interpret 0.1 as 1/10 automatically, as mentioned in the title.


Another option would be to change the function definition:

f[a_] := NIntegrate[Rationalize[a]NIntegrate[Sqrt[Rationalize[a] + Sqrt[Log[x]]Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

or

f[a_] := NIntegrate[SetPrecision[aNIntegrate[Sqrt[SetPrecision[a, \[Infinity]] + Sqrt[Log[x]]Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

But this too would be quite inconvenient to do for every function I use. I also worry about the fact that SetPrecision[0.1, \[Infinity]] does not give 1/10. So all this makes me wonder what the "right" method is.

Consider the function

f[a_] := NIntegrate[a + Sqrt[Log[x]], {x, 1, 10}, WorkingPrecision -> 30].

With this definition, I cannot call f[0.1] (for example) without Mathematica throwing an error, since "0.1" is interpreted automatically as a machine number with MachinePrecision (about 16), whereas the integration requires 30 digits of precision.

But when I enter 0.1, of course I really mean 1/10. One solution is to enter f[1/10], but this is very inconvenient to do every time, especially because my real functions involve many parameters with long strings of decimal numbers. What's the best way around this issue? Ideally, I'd like Mathematica to interpret 0.1 as 1/10 automatically, as mentioned in the title.


Another option would be to change the function definition:

f[a_] := NIntegrate[Rationalize[a] + Sqrt[Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

or

f[a_] := NIntegrate[SetPrecision[a, \[Infinity]] + Sqrt[Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

But this too would be quite inconvenient to do for every function I use. I also worry about the fact that SetPrecision[0.1, \[Infinity]] does not give 1/10. So all this makes me wonder what the "right" method is.

Consider the function

f[a_] := NIntegrate[Sqrt[a + Log[x]], {x, 1, 10}, WorkingPrecision -> 30].

With this definition, I cannot call f[0.1] (for example) without Mathematica throwing an error, since "0.1" is interpreted automatically as a machine number with MachinePrecision (about 16), whereas the integration requires 30 digits of precision.

But when I enter 0.1, of course I really mean 1/10. One solution is to enter f[1/10], but this is very inconvenient to do every time, especially because my real functions involve many parameters with long strings of decimal numbers. What's the best way around this issue? Ideally, I'd like Mathematica to interpret 0.1 as 1/10 automatically, as mentioned in the title.


Another option would be to change the function definition:

f[a_] := NIntegrate[Sqrt[Rationalize[a] + Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

or

f[a_] := NIntegrate[Sqrt[SetPrecision[a, \[Infinity]] + Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

But this too would be quite inconvenient to do for every function I use. I also worry about the fact that SetPrecision[0.1, \[Infinity]] does not give 1/10. So all this makes me wonder what the "right" method is.

Source Link
WillG
  • 1.1k
  • 6
  • 15

Can I change the default behavior so that "0.1" is interpreted as "1/10" automatically?

Consider the function

f[a_] := NIntegrate[a + Sqrt[Log[x]], {x, 1, 10}, WorkingPrecision -> 30].

With this definition, I cannot call f[0.1] (for example) without Mathematica throwing an error, since "0.1" is interpreted automatically as a machine number with MachinePrecision (about 16), whereas the integration requires 30 digits of precision.

But when I enter 0.1, of course I really mean 1/10. One solution is to enter f[1/10], but this is very inconvenient to do every time, especially because my real functions involve many parameters with long strings of decimal numbers. What's the best way around this issue? Ideally, I'd like Mathematica to interpret 0.1 as 1/10 automatically, as mentioned in the title.


Another option would be to change the function definition:

f[a_] := NIntegrate[Rationalize[a] + Sqrt[Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

or

f[a_] := NIntegrate[SetPrecision[a, \[Infinity]] + Sqrt[Log[x]], {x, 1, 10}, WorkingPrecision -> 30]

But this too would be quite inconvenient to do for every function I use. I also worry about the fact that SetPrecision[0.1, \[Infinity]] does not give 1/10. So all this makes me wonder what the "right" method is.