1
$\begingroup$

I am trying to extract the mantissas of a list of numbers using the ScientificForm and then do some operation on them. However, it seems that the output does not act like a number and is not computable (this is also noted in the documentation). I was wondering if there is a workaround for this?

Here is an example:

list = ScientificForm[#, NumberFormat -> (#1 &)] & /@ {12.34,23.45,345.6}

Then Total@list returns 1.234 + 2.345 + 3.456 without computing the sum.

$\endgroup$
5
  • $\begingroup$ @Nasser Could you elaborate? How would you get the mantissas? $\endgroup$
    – SaMaSo
    Commented Feb 28, 2023 at 13:11
  • 2
    $\begingroup$ MantissaExponent /@ {12.34, 23.45, 345.6} ? $\endgroup$
    – Syed
    Commented Feb 28, 2023 at 13:16
  • $\begingroup$ @Syed Thanks, I didn't know about this function. However, it seems that this gives a mantissa different than that in scientific notation (where it should lie between 1 and 10). Am I right? $\endgroup$
    – SaMaSo
    Commented Feb 28, 2023 at 13:30
  • $\begingroup$ I think that you have asked two questions and yes you are right. The MantissaExponent will give a mantissa between 0 and 1. For addition, this is not useful since all exponents need to be the same before you add the mantissas; which brings us back to square one. $\endgroup$
    – Syed
    Commented Feb 28, 2023 at 13:46
  • $\begingroup$ @Syed yes it's a different question, but I only asked because it was proposed as a solution with a slightly different answer. Thanks for your help, BTW. $\endgroup$
    – SaMaSo
    Commented Feb 28, 2023 at 16:18

2 Answers 2

3
$\begingroup$

What I meant is since you have the original list, why not do the operation on it? Like this (see also comment by Syed above on MantissaExponent)

list1 = {12.34, 23.45, 345.6};
m = Last /@ MantissaExponent /@ list1 
list1/10^(m - 1)

Mathematica graphics

Total[%]

Mathematica graphics

Instead of doing

list = ScientificForm[#, NumberFormat -> (#1 &)] & /@ list1

Mathematica graphics

And then trying to do Total on the above, which will not work since it has wrappers around them.

$\endgroup$
3
  • $\begingroup$ Thanks, this would do the job. It is just a bit cumbersome, especially sinceManitssaExponent works slightly differently than the common scientific notation. $\endgroup$
    – SaMaSo
    Commented Feb 28, 2023 at 13:35
  • $\begingroup$ @Nasser the Total you have calculated is not going to be correct unless all exponents are the same. Then you add the mantissas and multiply. $\endgroup$
    – Syed
    Commented Feb 28, 2023 at 13:48
  • $\begingroup$ @Syed Seems this actually works even for numbers with different exponents. $\endgroup$
    – SaMaSo
    Commented Feb 28, 2023 at 16:21
3
$\begingroup$

The general idea is to do computations and display the result using the Form wrapper of choice. Compare the following for instance.

blist = ScientificForm /@ {12.34, 23.45, 345.6}
Total[blist]
Total[blist[[All, 1]]]

so I would say extract the first part.

list = ScientificForm[#, NumberFormat -> (#1 &)][[1]] & /@ {12.34, 
   23.45, 345.6}

or

list = First@ScientificForm[#, NumberFormat -> (#1 &)] & /@ {12.34, 
   23.45, 345.6}

If you look at the TreeForm output for individual numbers, it is clear that you need the first part.

enter image description here


2 list

{24.68, 46.9, 691.2}

$\endgroup$
2
  • $\begingroup$ This is returning the numbers in the original list themselves. As mentioned in the question, I want to extract the mantissa. Can this be modified to do that? $\endgroup$
    – SaMaSo
    Commented Feb 28, 2023 at 13:09
  • $\begingroup$ The Total [ blist [[All,1]] ] is still returning the sum of the original numbers, not just the mantissas. $\endgroup$
    – SaMaSo
    Commented Feb 28, 2023 at 16:17

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.