• Forth for a balanced ternary machine

    From Matthias Koch@m.cook@gmx.net to comp.lang.forth on Mon May 25 14:58:44 2026
    From Newsgroup: comp.lang.forth


    A few days ago, I released an experiment on how Forth might adapt to a balanced ternary architecture, with an instruction set emulator and a native FPGA implementation included. In balanced ternary, all numbers are signed with low-level arithmetic being quite elegant, and there are new logic operators to explore. If you like to dive in: https://codeberg.org/Mecrisp/mecrisp-ternary

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Mon May 25 18:10:36 2026
    From Newsgroup: comp.lang.forth

    Matthias Koch <m.cook@gmx.net> writes:
    [reformatted to follow line length conventions:]
    A few days ago, I released an experiment on how Forth might adapt to
    a balanced ternary architecture, with an instruction set emulator and
    a native FPGA implementation included. In balanced ternary, all
    numbers are signed with low-level arithmetic being quite elegant, and
    there are new logic operators to explore. If you like to dive in: >https://codeberg.org/Mecrisp/mecrisp-ternary

    Quite interesting.

    A note on:

    |In balanced ternary, a right shift is exactly the same as symmetric
    |division by powers of three, unlike binary in which right-shifting
    |negative two-complement numbers to divide by powers of two gives
    |rounding artifacts.

    Floored division is not any more a rounding artifact than symmetric
    division is. Whether to use floored or symmetric division depends on
    the application. That's why we have FM/MOD and SM/REM in the
    standard. The Forth-83 committee was so strongly in favour of floored
    that they broke compatibility with Forth-79 because of that.

    Gforth since 0.7 implements / and other division words where Forth-94
    allows the system to choose as floored division words. This means
    that in Gforth, "2 /" is equivalent to 2/ (which is defined as a shift
    right by 1 bit):

    -3 2 / . \ prints -2
    -3 2/ . \ prints -2

    - anton
    --
    M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
    comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
    New standard: https://forth-standard.org/
    EuroForth 2025 proceedings: http://www.euroforth.org/ef25/papers/
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Tue May 26 15:53:12 2026
    From Newsgroup: comp.lang.forth

    On 26/05/2026 4:10 am, Anton Ertl wrote:
    Matthias Koch <m.cook@gmx.net> writes:
    ...
    |In balanced ternary, a right shift is exactly the same as symmetric |division by powers of three, unlike binary in which right-shifting
    |negative two-complement numbers to divide by powers of two gives
    |rounding artifacts.

    Floored division is not any more a rounding artifact than symmetric
    division is. Whether to use floored or symmetric division depends on
    the application. That's why we have FM/MOD and SM/REM in the
    standard. The Forth-83 committee was so strongly in favour of floored
    that they broke compatibility with Forth-79 because of that.

    Gforth since 0.7 implements / and other division words where Forth-94
    allows the system to choose as floored division words. This means
    that in Gforth, "2 /" is equivalent to 2/ (which is defined as a shift
    right by 1 bit):

    -3 2 / . \ prints -2
    -3 2/ . \ prints -2

    Which is all very nice until beginners ask how that makes any sense ;-)

    ANS at least tells you 2* 2/ are bit-shifters with historic, albeit misleading, names.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Tue May 26 07:46:33 2026
    From Newsgroup: comp.lang.forth

    dxf <dxforth@gmail.com> writes:
    On 26/05/2026 4:10 am, Anton Ertl wrote:
    Gforth since 0.7 implements / and other division words where Forth-94
    allows the system to choose as floored division words. This means
    that in Gforth, "2 /" is equivalent to 2/ (which is defined as a shift
    right by 1 bit):

    -3 2 / . \ prints -2
    -3 2/ . \ prints -2

    Which is all very nice until beginners ask how that makes any sense ;-)

    They don't (I know because I have been teaching Forth beginners for
    three decades). That's because negative dividends are rare, and
    negative divisors are even rarer. But in those cases where negative
    dividends occur, floored division usually makes sense, and users
    encountering it don't ask.

    ANS at least tells you 2* 2/ are bit-shifters with historic, albeit misleading,
    names.

    The name of 2* is not misleading on architectures with 2s-complement arithmetic. I.e., every architecture designed in the last
    half-century (the IBM S/360 is actually 62 years old), and everything
    that any existing standard system (for any Forth standard) runs on.

    And the name 2/ is not misleading on Forth systems where / is floored,
    such as Gforth.

    Here's what the Forth-94 rationale says:

    |A.6.1.0320 2*
    |
    |Historically, 2* has been implemented on two's-complement machines as
    |a logical left-shift instruction. Multiplication by two is an
    |efficient side-effect on these machines. However, shifting implies a |knowledge of the significance and position of bits in a cell. While
    |the name implies multiplication, most implementors have used a
    |hardware left shift to implement 2*.
    |
    |A.6.1.0330 2/
    |
    |This word has the same common usage and misnaming implications as
    |2*. It is often implemented on two's-complement machines with a
    |hardware right shift that propagates the sign bit.

    These sections may mislead the reader into believing that 2* and 2/
    actually mean something different than

    |6.1.0320 2* two-star CORE
    | ( x1 -- x2 )
    |
    |x2 is the result of shifting x1 one bit toward the most-significant
    |bit, filling the vacated least-significant bit with zero.
    |
    |6.1.0330 2/ two-slash CORE
    | ( x1 -- x2 )
    |
    |x2 is the result of shifting x1 one bit toward the least-significant
    |bit, leaving the most-significant bit unchanged.

    The rationale sections above were deleted in an editorial change in
    2012, but I don't know why. Anyway, given the obvious difference
    between the name and the specification of the behaviour, does it need
    a rationale to explain that there may be a difference?

    However, with the acceptance of the 2s-complement proposal, there no
    longer is a difference for 2*, and one might specify it as multiplying
    by 2.

    - anton
    --
    M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
    comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
    New standard: https://forth-standard.org/
    EuroForth 2025 proceedings: http://www.euroforth.org/ef25/papers/
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Wed May 27 00:52:04 2026
    From Newsgroup: comp.lang.forth

    On 26/05/2026 5:46 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 26/05/2026 4:10 am, Anton Ertl wrote:
    Gforth since 0.7 implements / and other division words where Forth-94
    allows the system to choose as floored division words. This means
    that in Gforth, "2 /" is equivalent to 2/ (which is defined as a shift
    right by 1 bit):

    -3 2 / . \ prints -2
    -3 2/ . \ prints -2

    Which is all very nice until beginners ask how that makes any sense ;-)

    They don't (I know because I have been teaching Forth beginners for
    three decades). That's because negative dividends are rare, and
    negative divisors are even rarer. But in those cases where negative dividends occur, floored division usually makes sense, and users
    encountering it don't ask.

    In a teaching scenario I wouldn't necessarily expect questions either. Importantly it didn't make sense to forth vendors to make breaking
    changes for something that was occasionally useful.

    ANS at least tells you 2* 2/ are bit-shifters with historic, albeit misleading,
    names.

    The name of 2* is not misleading on architectures with 2s-complement arithmetic. I.e., every architecture designed in the last
    half-century (the IBM S/360 is actually 62 years old), and everything
    that any existing standard system (for any Forth standard) runs on.

    And it's on such machines that one finds symmetric hardware division co-existing with arithmetic right shift instructions and coders not
    getting freaked out by it.

    ...

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Buzz McCool@buzz_mccool@yahoo.com to comp.lang.forth on Tue May 26 08:52:02 2026
    From Newsgroup: comp.lang.forth

    On 5/26/2026 12:46 AM, Anton Ertl wrote:
    ... I have been teaching Forth beginners for three decades. ...

    Does your university offer a class on Forth?

    https://dl.acm.org/doi/pdf/10.1145/165628.165632 https://www.cs.uaf.edu/~chappell/class/2023_spr/cs331/read/forth_quick.html

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Thu May 28 21:03:40 2026
    From Newsgroup: comp.lang.forth

    On 27/05/2026 1:52 am, Buzz McCool wrote:
    On 5/26/2026 12:46 AM, Anton Ertl wrote:
    ... I have been teaching Forth beginners for three decades. ...

    Does your university offer a class on Forth?

    https://dl.acm.org/doi/pdf/10.1145/165628.165632 https://www.cs.uaf.edu/~chappell/class/2023_spr/cs331/read/forth_quick.html


    Forth is like 60's music. You had to be there.

    --- Synchronet 3.22a-Linux NewsLink 1.2