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.

  • @chocolate ごめんなさい括弧の対応とか逆ポーランド記法的読み方への対応が要ると思うので reopen しました – naruto Mar 1 '18 at 3:50
  • カッコは「、」で表す方式にする、って言うから別に要らないと思ったの。。 – Chocolate Mar 1 '18 at 3:56
  • @Chocolate Thank you for considering the comma for parentheses in my concept... I was concerned that it may not read well... If there is a better suggestion whereby I would include terms in parentheses, please let me know. – Eliseo d'Annunzio Mar 1 '18 at 4:08

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 (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.

  • Oops, maybe you're writing a calculator where there are no brackets nor a stack, and *// and +/- have the same priority? Then you can just use the simple left-to-right reading. – naruto Mar 1 '18 at 5:45
  • 1
    I think left-to-right reading may be the way to go... Thank you... – Eliseo d'Annunzio Mar 1 '18 at 6:45
  • 3
    @naruto It may be pointless to the OP, but I very much enjoyed learning about it :) – user3856370 Mar 1 '18 at 16:30
  • 1
    Wait a second, @user3856370... I never said it was pointless... While I know RPN uses a similar structure to the SOV grammar structure in Japanese, I required a simpler approach that I can later employ in a much larger system... I may yet consider using the RPN method in my next iteration of the project... – Eliseo d'Annunzio Mar 1 '18 at 22:34
  • 1
    As a programmer, I love how you explained the connection between Japanese verbs and reverse Polish notation! – Nayuki Mar 1 '18 at 23:43

Japan uses 「足す」(tasu:plus)「引く」(hiku:minus)「掛ける」(kakeru:multiplied by)「割る」(waru:divided by). For example, 2+2 in words is "ni tasu ni", 2-2 is "ni hiku ni", 2x2 is "ni kakeru ni", 2/2 is "ni waru ni".

If it is assumed that the person using the calculator program is a native Japanese speaker, I think they will be more comfortable using those four terms rather than "purasu""mainasu".

  • Thanks for the preferred usage... I wanted something as native as possible... "purasu" and "mainasu" seemed so generic and well... too Western for my liking... – Eliseo d'Annunzio Mar 1 '18 at 3:56
  • @Eliseo of course, your code could handle both forms :) – Pedro A Mar 1 '18 at 21:14
  • @Hamsterrific, all in due time! I'm using this initial program to work out the methodology for extrapolating this to a full language compiler... So once I have the initial version worked out, I may consider going further with katakana forms where required and maybe enforce the SOV grammar/RPN format for number manipulation... – Eliseo d'Annunzio Mar 1 '18 at 23:48

(3 + 1 - 2) * 6 / 2

How about...

SAN tasu ICHI hiku NI, kakeru ROKU waru NI

(or SAN purasu ICHI mainasu NI, kakeru ROKU waru NI)

We usually read the parentheses (in maths) as "kakko ... kakko tojiru", as in:

(3 + 1 - 2) * 6 / 2

kakko SAN tasu ICHI hiku NI kakko tojiru kekeru ROKU waru NI

though it might look a bit wordy...

  • Happy to use tasu, hiku, kakeru and waru... That's fantastic... Thank you. – Eliseo d'Annunzio Mar 1 '18 at 3:55
  • よく見たら100円ショップの電卓的な計算手法ぽいので、この回答とdupeになってたやつで十分でした…深く考えすぎました…すみません – naruto Mar 1 '18 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.