3 ms·
There's a fun example in the GitHub repo for calculating the square root of a number based off of a real algorithm found in a real ancient Chinese text (九章算術).
by dwohnitmok 7y ago
There's a fun example in the GitHub repo for calculating the square root of a number based off of a real algorithm found in a real ancient Chinese text (九章算術).
https://github.com/wenyan-lang/wenyan/blob/master/examples/zh_sqrt.wy https://github.com/wenyan-lang/wenyan/blob/master/examples/z...
I don't have the time to translate at the moment but I'll just leave the two here for others to see just how different they read (and for those who can read Chinese, what similarities they have).
The Wenyan language:
吾有一術。名之曰「增乘開平方」。欲行是術。必先得一數。曰「實」。乃行是術曰。
注曰。『增乘開平方法,以商數乘下法遞增求之。』。
吾有四數。名之曰「果」曰「商」曰「餘」曰「廉」。有數一。名之曰「法」。
恆為是。施「取底除」於「實」於「法」。若其之『商』小於百者乃止也。
乘「法」以百。昔之「法」者。今其是矣云云。
恆為是。若「法」不大於零者乃止也。
乘「果」以十。昔之「果」者。今其是矣。
加「廉」以「商」。乘其以十。昔之「廉」者。今其是矣。
施「取底除」於「實」於「法」。名之曰「甲」。
昔之「實」者。今「甲」之『商』是矣。
昔之「餘」者。今「甲」之『餘』是矣。
昔之「商」者。今零是矣。
恆為是。加「廉」以「商」。乘其以「商」。若其不小於「實」者乃止也。
加「商」以一。昔之「商」者。今其是矣云云。
加「廉」以「商」。乘其以「商」。若其大於「實」者。
減「商」以一。昔之「商」者。今其是矣云云。
加「廉」以「商」。昔之「廉」者。今其是矣。
加「果」以「商」。昔之「果」者。今其是矣。
乘「商」以「廉」。減「實」以其。乘其以「法」。加其以「餘」。昔之「實」者。今其是矣。
施「取底除」於「法」於百。昔之「法」者。今其之『商』是矣云云。
注曰。『商第一位。上商得數以乘下法為乘方。命上商除實。上商得數以乘下法入乘方。一退為廉,下法再退。』。
注曰。『商第二位。商得數以乘下法為隅。命上商除實訖。以上商乘下法入隅,皆名曰廉。一退,下法再退,以求第三位商。』。
注曰。『商第三位。用法如第二位求之。』。
乃得 「果」。
是謂「增乘開平方」之術也。
The original Chinese:
開方術曰:置積為實。借一算步之,超一等。議所得,以一乘所借一算為法,而以除。除已,倍法為定法。其復除。折法而下。復置借算步之如初,以復議一乘之,所得副,以加定法,以除。以所得副從定法。復除折下如前。若開之不盡者為不可開,當以面命之。若實有分者,通分內子為定實。乃開之,訖,開其母報除。若母不可開者,又以母乘定實,乃開之,訖,令如母而一。
Note the original Chinese is based off the rod calculus. https://en.m.wikipedia.org/wiki/Rod_calculus https://en.m.wikipedia.org/wiki/Rod_calculus