Serioulsy puzzled here.


 
Thread Tools Search this Thread
Top Forums Programming Serioulsy puzzled here.
# 1  
Old 09-14-2016
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:-
Code:
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?

Last edited by wisecracker; 09-14-2016 at 02:27 PM.. Reason: Added the answer.
# 2  
Old 09-14-2016
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.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 09-15-2016
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.

Last edited by rbatte1; 09-15-2016 at 05:21 AM.. Reason: Correcting appearance of fractions
# 4  
Old 09-15-2016
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:-

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

or
Code:
6
---          =
2 * (1+2)

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



Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
# 5  
Old 09-15-2016
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?
# 6  
Old 09-15-2016
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.
# 7  
Old 09-21-2016
Hy,
Quote:
Originally Posted by Corona688
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.
Julia language understand implicit multiplication:
Code:
$ julia -E '6(8+4)'
72

But, many syntaxe not work (in doc) :
Quote:
Neither juxtaposition of two parenthesized expressions, nor placing a variable before a parenthesized expression, however, can be used to imply multiplication:

julia> (x-1)(x+1)
ERROR: MethodError: objects of type Int64 are not callable
...

julia> x(x+1)
ERROR: MethodError: objects of type Int64 are not callable
...
Both expressions are interpreted as function application: any expression that is not a numeric literal, when immediately followed by a parenthetical, is interpreted as a function applied to the values in parentheses (see Functions for more about functions). Thus, in both of these cases, an error occurs since the left-hand value is not a function.
Regards.
This User Gave Thanks to disedorgue For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. OS X (Apple)

Puzzled by Find

I'm new to playing with the command line on OS X and am puzzled by the response I am getting from the find command. I have a file structure similar to the following /Volumes/ ../Drobo/ ../../Pictures/ ../../../Image 1/ ../../../../Image 1.jpg ../../../../Previews/ ../../../../../Image... (2 Replies)
Discussion started by: Denrael
2 Replies

2. Shell Programming and Scripting

Puzzled with hexdump, hd and ln

How to create a symbolic link to a command with certain argument? When I man hexdump, it is said in the man page that "-C Canonical hex+ASCII display...Calling the command hd implies this option". Actually it is. hd equals to hexdump -C. And then I examined the ln command but find it is a... (5 Replies)
Discussion started by: vistastar
5 Replies

3. Solaris

Puzzled over over the relationship between the partition and geometry of hard disk.

Not sure why solaris couldn't detect the geometry of a hard disk which has a working OS of winxp pro. Is it due to the different OS that the partition information is stored in different location? When I type '"format" it is shown as below, c3d1 < drive type unknown>... (5 Replies)
Discussion started by: just.srad
5 Replies

4. Solaris

puzzled with VxVM and iostat..

Hi all, One disk on my root disk group failed in Veritas Volume manager. I replaced it with new one, initialized it and placed it with removed one. it Synchronized plexes and everything is fine. this node was second standby node of Sun cluster. yesterday I had failure on active node with boot... (1 Reply)
Discussion started by: samar
1 Replies

5. Programming

C++ Puzzled !!

#include <iostream.h> class A { public: void f(void) { cout << "hello world \n" ; } }; void main() { A *a; a = 0 ; a->f(); // OOPs...Am I mad? What am I going to do ? } (1 Reply)
Discussion started by: RipClaw
1 Replies

6. Programming

Puzzled with user ID.

I hava been reading AUPE these days. I really am puzzled with the presentation of real user(group) ID, effective user(group) ID. How do they effect on the execution of process? What's the relationship between them? Appreciate your help. (4 Replies)
Discussion started by: lethefe
4 Replies
Login or Register to Ask a Question