Questions tagged [arithmetic]

Questions on arithmetic operations in Mathematica.

Filter by
Sorted by
Tagged with
118 votes
1 answer
2k views

Why are numeric division and subtraction not handled better in Mathematica?

There is something that has been troubling me for a while. At least through version 10.0 the performance of a / b and a - b is ...
Mr.Wizard's user avatar
  • 269k
42 votes
2 answers
1k views

Is there a difference between Divide[a,b] and a/b?

In this comment it was asserted that Divide[a,b] and a/b are different, though the documentation indicates that they are the ...
Mark Adler's user avatar
  • 4,939
36 votes
8 answers
3k views

Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$

Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), ...
xzczd's user avatar
  • 62.9k
29 votes
2 answers
681 views

Should 0 * 5ft be 0 or 0ft?

After playing with the new quantity system in Mathematica 9 for a while, I keep stumbling over this issue: 0 * Quantity[1, "Meters"] is not the same as ...
Niki Estner's user avatar
  • 35.9k
18 votes
6 answers
5k views

Puzzle with Mathematica

Hello everyone, This is a puzzle I got from someone via social media. Basically, we need to fill up the boxes with the numbers 1-9 (no repetitions) that fit the multiplication and addition operations. ...
iFikr's user avatar
  • 347
17 votes
1 answer
1k views

How to prevent reduction of a fraction into lowest terms?

I have a question about the concept of simplification. I want to explain it with an example. When I write the fraction $4/8$ in Mathematica, the output is 1/2. How ...
MATIRMAK's user avatar
  • 739
16 votes
8 answers
3k views

Product of elements of a list

Sum is for functions; Total is for a list. Product is for a function; what is the command ...
user avatar
16 votes
3 answers
1k views

How to enter a repeating decimal in Mathematica

I don't understand how to manipulate numbers with repeating decimal in Wolfram Mathematica language. For example 0.3... does not work as input and I don't see how ...
Simpleton Jack's user avatar
16 votes
1 answer
329 views

How does Plus work on machine precision Real arguments?

I thought Kahan's summation method would make a nice example for students to use to think about round-off error [W. Kahan, Pracniques: Further Remarks on Reducing Truncation Errors, Commun. ACM 8  (...
Michael E2's user avatar
  • 233k
15 votes
3 answers
11k views

Expressing a decimal as a fraction in lowest terms

How can I express a decimal such as 0.1845095405274387 as a fraction in its lowest terms?
emmett's user avatar
  • 359
13 votes
2 answers
235 views

Arithmetic operations on NumericArrays

Currently, NumericArrays are directly supported by the most important array-related functions, what makes them a very attractive data structure for implementing ...
Alexey Popkov's user avatar
11 votes
1 answer
173 views

Trace of -{1} expression

I'm trying to understand Trace. Usually it doesn't repeat but it adds {-1,-1} for his simple expression after having a correct ...
iot's user avatar
  • 619
9 votes
2 answers
856 views

Why am I seeing what looks like a violation of operator precedence?

Why is it that when I evaluate 2*2.848529281693615`+3*-0.5155083247776808` I get (* -2.93688 *) which is wrong. ...
An old man in the sea.'s user avatar
9 votes
1 answer
232 views

Arbitrary-Precision Arithmetic behaves unexpectedly

I want to understand how small numerical errors propagate through a computation and may drastically change the final result. To this end, I consider a toy world in which every number is limited to ...
user19095's user avatar
  • 389
8 votes
4 answers
1k views

How to recover Pauli matrices properties in Mathematica?

I want to do a cross or dot product involving a vector of Pauli matrices $ \vec\sigma=(\sigma^1, \sigma^2, \sigma^3) $; for example, $ \vec\sigma\times\vec\sigma=2\mathrm i\vec\sigma $ and $ \vec\...
user3654016's user avatar
8 votes
3 answers
388 views

Improving Map Function on Lists

Dealing with spectral data (2D lists) where offsets (corresponding 1D list) must be removed from each individual spectrum. Looking for feedback on improvements over my current method. ...
OpticsMan's user avatar
  • 560
8 votes
4 answers
1k views

Countdown arithmetic solver

In the numbers game in countdown, contestants are given 6 numbers with which they must reach a seventh number with basic arithmetic. The only operations allowed are addition, subtraction, ...
Feyre's user avatar
  • 8,547
7 votes
2 answers
2k views

How to do binary calculation?

For example, $a=0.10101$ in binary representation. Then how to calculate $a^2$ directly in mathematica? Is there any function turning binary into decimal? I only found its inverse...
Doris's user avatar
  • 172
7 votes
2 answers
237 views

Is there a way to show the details of a numerical computation?

I have recently started using Mathematica as a calculator while teaching (definitely overkill, but I try to use as few tools as possible). I would like my students to be able to trace simple numerical ...
A.G.'s user avatar
  • 4,312
7 votes
1 answer
177 views

Running Mathematica in 'SpouseMode'

In this previous question I looked into a deprecated capability of Mathematica from Version 2. Mathematica command that allows it to read my intentions Thanks to all for your answers. I note that ...
MikeY's user avatar
  • 7,113
5 votes
14 answers
2k views

Sum of Squares without multiplication

I want to sum the squares for a given number N from 1 without using Multiplication. Is it possible?
user2212's user avatar
5 votes
3 answers
533 views

How to find a longest word path in dictionary?

Cross post here A word path means the last character of the last word is same to the first character of the next word.And the path have no duplicated word.If I have $55$ words,I can find it with this ...
yode's user avatar
  • 26.1k
5 votes
1 answer
246 views

Does Mathematica simplify calculation when encounter zero?

e.g. when Mathematica Calculating f[x0]=A[x0] B[x0], where A[x] & B[x] could be some complicated high dimensional function. Will Mathematica outcome 0 directly ...
wannaintegrate's user avatar
5 votes
1 answer
414 views

Why can't I remove Orderless from Plus?

I am making some random algebra equations, and I want to have the ordering be random too, such that if my random equation generator makes x+1, the output stays <...
VF1's user avatar
  • 4,642
4 votes
3 answers
2k views

Permanently rounding numbers/values to a given number of significant figures

I am searching for a simple way of rounding and setting an input to a desired number of significant figures. There are a vast number of posts that discuss similar problems, but none address this issue....
George Papadopoulos's user avatar
4 votes
2 answers
379 views

Interchanging addition and multiplication

Suppose I have an expression that employs addition and multiplication, but no subtraction or division: $$ 2 a + 5 b x^3 + c \;. $$ I would like to change this to $$ (2 + a) (5 +b + x +x +x) c \;, $$ ...
Joseph O'Rourke's user avatar
4 votes
2 answers
200 views

Multiplication non-deterministic?

I have two vectors of 134 elements each ($mu$, and $gt$). $mu$ contains Integers, and $gt$ contains machine precision Reals. I execute the following simple expression multiple times without changing ...
Eric Parker's user avatar
4 votes
1 answer
401 views

multiply two vectors, component by component [closed]

Would like to take two vectors and multiply components at the same index.For example {a1, a2, a3} x {b1, b2, b3} to produce {a1 b1, a2 b2, a3 b3}. The following works, but are there some alternatives?...
user6546's user avatar
  • 1,027
4 votes
2 answers
2k views

Floating point addition not associative

Can anybody explain the following behavior? x = 0.2 + (0.3 + 0.1); y = (0.2 + 0.3) + 0.1; x == y (* -> True *) But actually the variables do not exactly ...
Ruben Garcia's user avatar
4 votes
1 answer
87 views

Simplify expressions with modulo 2 (Boolean algebra)

Suppose I have a (Boolean algebra) expression a = p1 x^2 + p2 x (x-1) + 3 p3 + 4 p4 x where p1, ..., ...
Zhengyuan Yue's user avatar
4 votes
2 answers
110 views

Raise a table of pre-existing data to the power of of one of the variables

NOTE: I have edited this question to give a table whose first elements don't count up from 0 to 5. I'm using a sample table ...
Richard Burke-Ward's user avatar
4 votes
3 answers
193 views

A sudoku-like collection puzzle

I have a puzzle. I'm given a collection of $n$ lists, all of equal (but arbitrary) length $l$. These lists are made up of 0s and a few filled in numbers, like so: { {0, 2}, {0,0}, {6, 0}, {0,0} } ...
Nico A's user avatar
  • 3,604
4 votes
1 answer
148 views

Machine Epsilon is not equal to $MachineEpsilon [duplicate]

I try to wrap my head around machine precision calculations in Mathematica (11.2, Linux). I do not understand the following behavior: ...
Robin Geyer's user avatar
4 votes
0 answers
80 views

Force computation on IEEE float/double

I'm checking two different procedures that will eventually be used with regular floating point arithmetic. I need to estimate numerical error arising from floating point arithmetic. Is there a way to ...
Radost's user avatar
  • 211
4 votes
0 answers
170 views

How can one best implement the multiplication of octonions using the Quaternions package?

I excerpt from p. 4 of the recent paper of P. J. Forrester (https://arxiv.org/pdf/1610.08081.pdf): "Let $p_1$ and $p_2$ be quaternions. The octonion algebra consists of elements of the form $p_1+p_2 ...
Paul B. Slater's user avatar
4 votes
0 answers
121 views

Simple arithmetic with Irrationals fails [closed]

While solving a simple puzzle that asked for a few calculations in plane geometry, I ended up with this expression: $-\frac{55}{2}+\frac{\sqrt{27233}}{2}+\frac{1}{2}(55-\sqrt{27233})$ Or, in ...
Felix Kasza's user avatar
3 votes
3 answers
149 views

Why does the Mathematica give different numerical results?

Why do the two inputs give different values? in:=(-y)^a /. a -> 2.99 /. y -> -2 out:=7.94474 and ...
Antimony51's user avatar
3 votes
2 answers
3k views

Doing arithmetic with binary numbers

How do I execute binary operations in Mathematica? I want to to multiply say 1010101011 (binary) to 1111101110 (binary) and getting the result 10100111101111111010? Then I want to add the result to ...
Giorgio's user avatar
  • 351
3 votes
2 answers
252 views

Applying Mod on list of list with outcomes +1, -1, other

I have a list lis = {{7, 8}, {17, 9}, {11, 10}, {12,10}} I want to apply Mod to each pair with output +1,-1 or ...
user57467's user avatar
  • 2,304
3 votes
1 answer
111 views

Why Divide does not give the same answer? [closed]

I saw a question on Facebook $8\div2 (2 + 2)=?$ Consider these inputs. Divide[8, 2 (2 + 2)] 1 $8\div2 (2 + 2)$ using esc+div+esc 16 Why the results are ...
OkkesDulgerci's user avatar
3 votes
1 answer
161 views

Solving calculation puzzle [closed]

I recently got asked how to achieve a result of 100 only using the numbers {1,7,7,7,7} (the number 1 can be used only once and ...
Arjihad's user avatar
  • 1,134
3 votes
1 answer
200 views

How can I redefine multiplication?

For instance, I want 0 Infinity = 0 I tried this: Unprotect[Times];Times[Infinity,0]=0;Times[0,Infinity]=0;Protect[Times]; But ...
Anixx's user avatar
  • 3,473
3 votes
2 answers
117 views

Can I make RandomInstance use exact arithmetic?

When using RandomInstance on a GeometricScene the answer loses precision when root objects are encountered. Is there a way to ...
user13892's user avatar
  • 9,043
3 votes
2 answers
81 views

Advice for making addition and multiplication tables for my kid

I'm working with my 6 year old on understanding and mastering addition. As a result, I want to be able to make some custom addition (and eventually multiplication) tables for her to fill out. ...
mikemtnbikes's user avatar
3 votes
1 answer
183 views

Generating prime factorizations from an integer's digits by inserting * and ^ into the digit sequence

Problem Given a positive integer, output all possible valid prime-factorization "statements" thereof created by inserting zero or more multiplication (*) symbols and zero or more power (^) symbols ...
Hans Havermann's user avatar
3 votes
1 answer
124 views

Forcing divisions to be a machine-precision floating point divisions instead of multiplication by inverse

I want to imitate machine-precision, de facto IEEE division on Mathematica. On my quick trials I find this surprisingly hard to accomplish, since Mma rewrites a / b ...
kirma's user avatar
  • 18.6k
3 votes
0 answers
73 views

Problem with Mathematica Relationship Building

When I enter the following to get Mathematica to open my pod door I get Could someone try and replicate this? Also, my name is not Dave and I throw my own error... ...
MikeY's user avatar
  • 7,113
2 votes
6 answers
287 views

Is there any function that creates an array from 1 to n, repeating each value m times?

I am trying to implement SparseArray, using the function With to give the condition for different matrix elements. I would need ...
Mencia's user avatar
  • 1,294
2 votes
3 answers
594 views

Rounding Real number

I have real numbers in array, I want to round (or truncate) these numbers to 2-digit after decimal point, then I want to write values to Excel File For example if I have ...
user81348's user avatar
2 votes
1 answer
371 views

Why is arithmetic faster for inexact arithmetic?

I have been trying to compute eigenvalues of a rather sizable matrix A, about $500 \times 500$ (but sparse). I asked Mathematica to compute ...
Jakub Konieczny's user avatar