Skip to main content

Questions tagged [arithmetic]

Questions on arithmetic operations in Mathematica.

Filter by
Sorted by
Tagged with
120 votes
1 answer
3k 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
  • 272k
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,959
37 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
  • 67.1k
29 votes
2 answers
686 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
  • 36.2k
18 votes
6 answers
6k 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
18 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
  • 749
17 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
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
1 answer
331 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
  • 239k
15 votes
3 answers
12k 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
305 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
176 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
857 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
236 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
392 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
  • 576
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,617
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
240 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,372
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,183
6 votes
1 answer
429 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,742
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
547 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.9k
5 votes
1 answer
249 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
4 votes
5 answers
496 views

How to check if multiplication requires carries?

For some purposes I need to know if there are there any carries in the multiplication of two numbers, especially in base-2. How can we do this in Mathematica? Thanks to all, very interesting answers! ...
lesobrod's user avatar
  • 1,846
4 votes
4 answers
219 views

Lines of intersections in a parabola

To test the parabolic sieve, my intention was for the graph to show the coordinates of two points on the parabola and the value of the intersection on the y-axis. A table with this information would ...
Rubens Vilhena Fonseca's user avatar
4 votes
3 answers
3k 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
397 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
207 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
475 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,069
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
143 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
127 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
203 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,644
4 votes
1 answer
154 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
84 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
178 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
124 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
161 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
  • 341
3 votes
2 answers
676 views

Recycle buying soda problem

there is a question: " If a bottle of soda costs \$1 and you can exchange two empty bottles for one soda, how many sodas can you drink with \$20 " ...
我心永恒's user avatar
  • 1,572
3 votes
2 answers
280 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,788
3 votes
1 answer
115 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
166 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 ...
Arji's user avatar
  • 1,134
3 votes
1 answer
213 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,630
3 votes
2 answers
122 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,523
3 votes
2 answers
88 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
187 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
145 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
  • 19.1k
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,183