Serioulsy puzzled here.

Facebook had a mathematics problem which was as thus:-

6/2(1+2) = ?

Answer is 9.

My ancient Casio FX 730P mini computer written exactly as that gives 'error' only.

Now take a look at shell versions, and a python version:-

Last login: Wed Sep 14 18:04:04 on ttys000
AMIGA:barrywalker~> echo "$(( 6/2(1+2) ))"
-bash: 6/2(1+2) : syntax error in expression (error token is "(1+2) ")
AMIGA:barrywalker~> echo "$(( 6/2*(1+2) ))"
9
AMIGA:barrywalker~> echo "6/2(1+2)" | bc
(standard_in) 1: parse error
AMIGA:barrywalker~> echo "6/2*(1+2)" | bc
9
AMIGA:barrywalker~> python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print 6/2(1+2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> print 6/2*(1+2)
9
>>> exit()
AMIGA:barrywalker~> _

Are these bugs or is it mandatory in at least these two languages here to have the multiplication operator?

Multiplication is almost never implicit in a computer language. I don't actually know any which do it implicitly, but they probably exist, maybe math-specific languages and the like.

1 Like

The overriding issue here is dependant on how the question is written and we are limited if we cannot express fractions easily.

Is it (6/2)(1+2) with answer 9 or 6/(2(1+2)) with answer 1. On a question paper, I would expect to see either this:-

 	 	 	p \{ margin-bottom: 0.1in; line-height: 120%; \}   6/2\(2\+1\)

or
p { margin-bottom: 0.1in; line-height: 120%; } 6/2(2+1)

That way we clearly know which it is. How would you know which order is expected in a line of code with an inserted multiplication sign. I suspect it would just go left to right so answer 9 but clarity is required.

Well, that didn't work well as output! Sorry about that.

What I meant to describe was that the sum is either written on paper as:-

6
---  * (1+2) =
2

or

6
---          =
2 * (1+2)

I hope I never have to try to represent fractions on the board again!

Robin

2 Likes

I thought like Robin last night, but then had a phone call so did not post and after I forgot..

you see when written like Robin its univoque but as presented in the first post (I find it ambiguous...), is it you should have used extra brackets to make it univoque otherwise, with all same weight you go from left to right?

Thanks guys...

In all the time I have written code a have assumed that hard coding the multiplication operator was the way to go. I had never even considered implicit multiplication in computer code at all but when I saw the expression in my OP I decided to try it out and true to form the results are there for all to see.

What we take for granted in our thought processes cannot be assumed in computer code.

Thanks mainly to C688 for his initial reply.

Hy,

Julia language understand implicit multiplication:

$ julia -E '6(8+4)'
72

But, many syntaxe not work (in doc) :

Regards.

1 Like