Standard mathematical operations, expressed in Japanese


First-time poster on this channel, so please forgive me if I screw anything
up...

I'm currently writing a "Japanese Calculator" program as part of a personal
project I'm working on which takes rōmaji input and converts the phrase,
determines the mathematical expression and spits out the answer in decimal
format... Numbers will be written in upper case for example:

`ICHI purasu GO mainasu YON purasu ROKU`

1 + 5 - 4 + 6, in this case, which will spit out `8` as a final answer...

In my program, if I use a comma after a specific operation and value, the
intention is that it will store the value in an interim memory and then the
next operation will be acted upon the next value... For example:

`ICHI purasu GO, mainasu SAN` which could be interpreted as (1 + 5) - 3.

My focus in this question is in the legibility and grammatical correctness in
whatever input I give it... I'd like consistency as well as ease of grammar...

Now I've been happy to use プラス and マイナス in their rōmaji forms... but I've been
stuck on how to get some sort of suitable legibility with things like
multiplication and division... I want to use the equivalents of "multiplied
by" and "divided by" but have found that:

With multiplication, for example, "x multiplied by y", I get: `x ni y o
jōjita`

And with division, for example, "x divided by y", I get: `x o y de watta`

Would these be considered suitable equivalents?

For example, if I wanted to do (3 + 1 - 2) * 6 / 2, and using these two other
phrases, and the comma concept I mentioned above, and still make it legibly
correct Japanese, would the following be considered a sufficient and legible
translation?

`SAN purasu ICHI mainasu NI, ni ROKU o joujita o NI de watta`

If not, I would appreciate any way of improving this kind of input, so I can
implement these into my code and still retain some legibility.

Thanks, or rather... arigatou.




First of all, let me assume:

  1. You're only interested in the simple four operations (`+`, `-`, `*`, `/`) and brackets `(` `)`
  2. Multiplication and division have higher priority, e.g., `1 + 2 * 3` is `7`, not `9`
  3. Of course you want to make the reading unambiguous, taking brackets into consideration

So we want to read something like `1 + 3 * (4 - 1)` (=10) but nothing more
complicated than this. Actually, there are two programmatic approaches I can
think of:

### Simple left-to-right approach

The most straightforward way is to simply read each number and symbol from
left to right, just as you read "two, times, bracket, one, plus, three, close-
bracket". This is what is done every day in math classes at middle school.

  * `+`: たす _tasu_ or プラス _purasu_
  * `-`: ひく _hiku_ or マイナス _mainasu_
  * `*`: かける _kakeru_
  * `/`: わる _waru_
  * `(`: かっこ _kakko_
  * `)`: とじかっこ _toji-kakko_ or かっことじ _kakko-toji_

So `1 + 3 * (4 - 1)` would be:

> いち プラス さん かける **かっこ** よん マイナス いち **かっことじ**  
>  ICHI purasu SAN kakeru kakko YON mainasu ICHI kakko-toji

Although uninteresting, this should be very easy to understand, and actually
the natural one, IMO.

### "(Un)natural" approach

What if you want a more "natural" and grammatical Japanese sentence? If you
know [reverse Polish
notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation) (RPN), it is
known that the Japanese language can read math expressions just like RPN. And
the merit of this approach is that you don't have to pronounce brackets at
all.

For example, `1 + 3` is "the sum of one and three" in "natural" English. In
"natural" Japanese, this can be read as:

> いち **と** さん **の** **わ**  
>  ICHI to SAN no **wa**

...just like its reverse-Polish representation, `1 3 +`, except that you need
to insert と _to_ ("and") between the numbers and の _no_ ("-'s") before the
operator. You can use these four words:

  * 和 わ _wa_ "sum" `+`
  * 差 さ _sa_ "difference" `-`
  * 積 せき _seki_ "product" `*`
  * 商 しょう _sho_ "quotient" `/`

For a little more complicated example, `2 * (1 + 3)`, which is `2 1 3 + *` in
RPN, would be:

> に と いち と さん の わ の せき  
>  に と、 (いち と さん の わ) の せき  
>  NI to, ICHI to SAN no wa no seki

(Brackets and commas are technically redundant and optional, but they
definitely help humans.)

`1 + 3 * (4 - 1)`, or `1 3 4 1 - * +` in RPN, would be:

> いち と さん と よん と いち の さ の せき の わ  
>  いち と (さん と (よん と いち の さ) の せき) の わ

It seems that you're using a kind of stack memory in your calculator, so I
think this approach should express the internal representation of your
calculator, too. (`と` pushes onto the stack, `の` pops from the stack.)
Technically, now you can construct the reading of math expressions of
arbitrary depth. However, without brackets, note that the last example is very
confusing even to native speakers. It's not possible to convert very
complicated math expressions into natural sentences anyway. Not possible in
English, either. You may want to stick to the left-to-right reading, although
uninteresting.




First of all, let me assume:

  1. You're only interested in the simple four operations (`+`, `-`, `*`, `/`) and brackets `(` `)`
  2. Multiplication and division have higher priority, e.g., `1 + 2 * 3` is `7`, not `9`
  3. Of course you want to make the reading unambiguous, taking brackets into consideration

So we want to read something like `1 + 3 * (4 - 1)` (=10) but nothing more
complicated than this. Actually, there are two programmatic approaches I can
think of:

### Simple left-to-right approach

The most straightforward way is to simply read each number and symbol from
left to right, just as you read "two, times, bracket, one, plus, three, close-
bracket". This is what is done every day in math classes at middle school.

  * `+`: たす _tasu_ or プラス _purasu_
  * `-`: ひく _hiku_ or マイナス _mainasu_
  * `*`: かける _kakeru_
  * `/`: わる _waru_
  * `(`: かっこ _kakko_
  * `)`: とじかっこ _toji-kakko_ or かっことじ _kakko-toji_

So `1 + 3 * (4 - 1)` would be:

> いち プラス さん かける **かっこ** よん マイナス いち **かっことじ**  
>  ICHI purasu SAN kakeru kakko YON mainasu ICHI kakko-toji

Although uninteresting, this should be very easy to understand, and actually
the natural one, IMO.

### "(Un)natural" approach

What if you want a more "natural" and grammatical Japanese sentence? If you
know [reverse Polish
notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation) (RPN), it is
known that the Japanese language can read math expressions just like RPN. And
the merit of this approach is that you don't have to pronounce brackets at
all.

For example, `1 + 3` is "the sum of one and three" in "natural" English. In
"natural" Japanese, this can be read as:

> いち **と** さん **の** **わ**  
>  ICHI to SAN no **wa**

...just like its reverse-Polish representation, `1 3 +`, except that you need
to insert と _to_ ("and") between the numbers and の _no_ ("-'s") before the
operator. You can use these four words:

  * 和 わ _wa_ "sum" `+`
  * 差 さ _sa_ "difference" `-`
  * 積 せき _seki_ "product" `*`
  * 商 しょう _sho_ "quotient" `/`

For a little more complicated example, `2 * (1 + 3)`, which is `2 1 3 + *` in
RPN, would be:

> に と いち と さん の わ の せき  
>  に と、 (いち と さん の わ) の せき  
>  NI to, ICHI to SAN no wa no seki

(Brackets and commas are technically redundant and optional, but they
definitely help humans.)

`1 + 3 * (4 - 1)`, or `1 3 4 1 - * +` in RPN, would be:

> いち と さん と よん と いち の さ の せき の わ  
>  いち と (さん と (よん と いち の さ) の せき) の わ

It seems that you're using a kind of stack memory in your calculator, so I
think this approach should express the internal representation of your
calculator, too. (`と` pushes onto the stack, `の` pops from the stack.)
Technically, now you can construct the reading of math expressions of
arbitrary depth. However, without brackets, note that the last example is very
confusing even to native speakers. It's not possible to convert very
complicated math expressions into natural sentences anyway. Not possible in
English, either. You may want to stick to the left-to-right reading, although
uninteresting.

