The Novels

Economics 101, a Novel (Rough Draft) -- My first sustained attempt at a novel, two-thirds finished in rough draft, and heading a little too far south.
What would you do if you and your study partner, with whom you had been seriously discussing marriage, suddenly found yourselves all alone together on a desert island? Study economics?
Sociology 500, a Romance (Second Draft) -- The first book in the Economics 101 Trilogy.(On hold.)
Karel and Dan, former American football teammates and now graduate students, meet fellow graduate students Kristie and Bobbie, and the four form a steady study group.

Featured Post

Sociology 500, a Romance, ch 1 pt 1 -- Introducing Bobbie

TOC Well, let's meet Roberta Whitmer. Bobbie entered the anthropology department office and looked around. Near the receptionis...

Tuesday, April 11, 2017

Backup: Sociology 500, a Romance, ch 3 pt 10 -- Computers

[JMR201704121825: metadata edits -- Title/name.]

Sociology 500, a {replace}Novel{with}Romance{replace.}, ch 3 pt 10 -- Computers

[JMR201704121825: end metadata edit.]


[JMR201704121022: edits -- cleanup.]

"{replace}It's{with}Of course it's{replace.} just like the first year from the computer generated chart, but a little more readable."

---------------

(You'll notice that some of the names of their months parallel ours and some don't. Winter solstice was usually the first day of Time-division, so {replace}it{with}that month{replace.} started earlier than January starts for us.)

---------------

"Shouldn't be a problem. It's just {replace}another function{with}a few more functions{replace.}."

---------------

But I have the same bad habit. Come to think of it, so did Mr. Mon, whom we have heard a little about, {replace}but{with}'though{replace.} not yet by name.

---------------

Dan continued, "Anyway, sorry, Mark, but Ted can't even say he can't talk about that. And, theoretically, I was not supposed to say what I just said." Dan's expression changed from irritation to amusement. "And I can't believe I just actually used the word, 'theoretically'. And I can't believe I'm going to ask everyone to forget you heard any of this."{add} Chuckling, he shook his head.{add.}

---------------

Bess said, {add}excitedly, {add.}"Yes, he does. He says according to his calculations, they could eventually be cheap enough and small enough for ordinary people to own."

---------------

{replace}The{with}Many of the{replace.} students began to talk excitedly about the possibility of having a computer{replace} and{with}, and about{replace.} what they might do with one.

---------------

Then Professor Billings {add}noticed the clock {add.}and said, "Oh. Look at the time. {replace}Class dismissed{with}We're done for today{replace.}."

---------------

"The more time passes, the more I {replace}think Karel was right{with}agree with Karel{replace.}. Maybe I should have just let the computer go to junk instead of signing the NDA so I could bid on it."

---------------

"I'd have gone to {replace}give the judge a piece of my mind{with}have a little talk with that judge{replace.}, but Dad told me to forget it."

---------------

So, while they go to meet Bobbie and Karel, should we take a look at Ted's {replace}programs{with]work{replace.}?

[JMR201704121022: end-edits.]

[JMR201704120928: backup of http://joel-rees-economics.blogspot.com/2017/04/soc500-03-10-computers.html.]
Previous




"Thank you, Karen and Georgia, for volunteering to do the typing." Professor Billings turned back to Ted. "It looks like you've got your chart ready."

"It's just like the first year from the computer generated chart, but a little more readable."
      Month   Length Sum    End 
Time-division:  30    30   29.39
Deep-winter:    29    59   58.78
War-time:       30    89   88.18
Thaw-time:      29   118  117.57
Rebirth:        29   147  146.96
Brides-month:   30   177  176.35
Imperious:      29   206  205.75
Glorious:       30   236  235.14
False-summer:   29   265  264.53
Harvest:        29   294  293.92
Gratitude:      30   324  323.31
Winter-month:   29   353  352.71

(You'll notice that some of the names of their months parallel ours and some don't. Winter solstice was usually the first day of Time-division, so it started earlier than January starts for us.)

"I think I would show this chart to young students instead of the computer generated charts, or at least show it first. And I think it'd work best to have the students help me put the chart up -- ask about each month, add things up, and so forth."

"Sounds good," Professor Billings agreed.

Merill asked, "Is there a reason you didn't have the computer put the names of the months in the computer chart?"

"I was focusing on the math. Eventually, as Professor Billings suggested, I want to use double integers in the sums so I can print out a listing up to the present and beyond. But I haven't written all the double length integer routines yet."

"Can your computer do that?" asked the professor.

"Shouldn't be a problem. It's just another function."

Ultimately, it wasn't a problem for him, and it's only a problem for us if we try to run the code below on an old eight or sixteen bit processor.

"So how much of a problem would it be to have the computer print the names of the months, too?"

Ted laughed. "Not too much. But there are several ways to do it, and I have a bad habit of trying to make the program too general, which means I tend to do things the hard way." Ted did not elaborate. I might explain later.

But I have the same bad habit. Come to think of it, so did Mr. Mon, whom we have heard a little about, but not yet by name.

"Nice chart," the professor complimented him.

"Yeah. But I want to write a program to print out a regular calendar for any month of any year, too."

Carl was the one to ask, "You can do that?"

"It should be possible, just a matter of the time to write the program. I should be able to show the phases of the moons, as well."

Georgia asked, with just a little acid in her tone, "So, you just happened to bring this printout today?"

Ted laughed a little shyly, "Not really. I read in the syllabus that we would be studying skip years, and started working on this program Saturday night."

The professor frowned in concern. "Please don't let this put a crimp in your social life."

Ted shrugged.

Mark asked, "So is there a way we could bring this whiz-bang computer into a classroom for students to, I don't know, interact with?"

Ted opened his mouth as if to say, "Sure!", but then he closed it without saying anything. He looked at Dan, as if looking for help.

Dan raised his hands in a hands-off gesture. "Don't look at me."

Ted mumbled, "Maybe, ... maybe not ..."

Dan face showed a bit of consternation. He said, "I'm trying to do what the judge said, too, although you know I don't think he had any authority to put a gag on me."

The classroom was suddenly dead quiet. All ears listened.

Dan continued, "Anyway, sorry, Mark, but Ted can't even say he can't talk about that. And, theoretically, I was not supposed to say what I just said." Dan's expression changed from irritation to amusement. "And I can't believe I just actually used the word, 'theoretically'. And I can't believe I'm going to ask everyone to forget you heard any of this."

There was scattered nervous laughter.

Kristie felt indignant that her friends would be so imposed upon. But, not knowing about the non-disclosure agreement, she didn't know what to think. In fact, this was the first indication she had that Ted and Dan knew each other very well.

Bess spoke up. "My dad is actually working on a device to let computers print things to a television screen. That would be really useful in a classroom. He thinks they will one day be cheap enough to have in regular elementary school classrooms, too."

Dan rolled his eyes, and Ted showed his surprise.

But Dan bit his tongue. Instead of commenting on the futility of non-disclosure agreements, he said, "Really? That's way cool. Does he think the prices of computers themselves will drop, too?"

Now Ted was indignant, but he also held his tongue.

Bess said, "Yes, he does. He says according to his calculations, they could eventually be cheap enough and small enough for ordinary people to own."

The students began to talk excitedly about the possibility of having a computer and what they might do with one.

Then Professor Billings said, "Oh. Look at the time. Class dismissed."

As the students left, a number of them gathered around Bess and Professor Billings to talk about the possibility of schools being able to afford a computer.

Merill left quietly.

Ted and Dan stayed away from the group and talked in low voices.

"Karel is right," Dan said. "Your old boss ought to be sharing his stuff, not trying to keep it secret so he can patent it all and have a monopoly."

"The more time passes, the more I think Karel was right. Maybe I should have just let the computer go to junk instead of signing the NDA so I could bid on it."

Kristie listened quietly.

"Would it have made any difference about the court order not to talk?"

"I don't know. Karel thought my signature gave weight to Mr. Mon's arguments."

"It puts you and Karel and Merill in a tough spot. Me too, even though I only heard a few things about it from Karel before the gag order was set."

"Sorry about that."

"I'd have gone to give the judge a piece of my mind, but Dad told me to forget it."

"I couldn't just let the computer go to scrap. All the work we put into it. And the programming system would have just been lost."

"I was wondering about that."

"No, Mr. Mon said we could let people see the high-level code, just not the parts that would be needed to build the system. I think he thought rumors would be good advertising."

"If we were allowed to talk, there'd be even better advertising."

The professor joined them, and asked, "Will what happened now cause trouble for you guys?"

"I don't think so," Ted replied. "I said nothing, and Dan can claim best effort."

Kristie spoke up. "We were going to meet Karel and Bobbie for lunch."

"Ah. Gotta go."

"Me, too."

And they gathered their books and said goodbye to the professor and left.



So, while they go to meet Bobbie and Karel, should we take a look at Ted's programs?



( Forth code for calculating idealized lengths of months )
( relative to skip years in the world of )
( Bobbie, Karel, Dan, and Kristi, Sociology 500, a Novel. )

( by Ted Turpin, of the Union of Independent States, Xhilr )
( Earth Copyright 2017, Joel Matthew Rees )

( Permission granted to use for personal entertainment only. )

( -- If you need it for other purposes, rewriting it yourself is not that hard, )
( and the result will be guaranteed to satisfy your needs much more effectively. )



( You can save it as something like "econmonths.fs". )
( In gforth and most modern or emulated environments, )
( just paste it into the terminal of a running Forth session. )

( Run it with

 7 SHOWIDEALMONTHS

  for seven years, etc. )


( Uses integer math throughout. )
( Forth expression syntax is mostly postfix. )
( Only the definition syntax is prefix or infix. )
( I've added some comments with equivalent infix expressions )
( to help those unfamiliar with Forth. )


( Using baroque identifiers for ancient Forths. )
( fig-Forth used first three character + length significance in symbol tables. )


( UM*, FM/MOD, and S>D are already there in most modern Forths. )
( These definitions are only for ancient Forths, )
( especially pre-1983 fig and bif-c. )
( Un-comment them if you see errors like )
( UM* ? err # 0 )
( from PRMONTH or thereabouts. )

( : UM* U* ; ) ( modern name for unsigned mixed multiply )

( This is a cheat! Behavior is not well defined for negative numbers, )
( but we don't do negatives here. )
( So this is just sloppy renaming in a sloppy fashion: )
( : FM/MOD M/MOD DROP ; ) ( unsigned division with modulo remainder )

( : S>D S->D ; ) ( Modern name for single-to-double. )

( Showing the above in infix won't help. )

SP@ SP@ - ABS CONSTANT CELLWIDTH
( Infix won't help here, either, but I can try to explain: )
( CELLWIDTH = absolute-value-of difference-between SP-without-pointer and SP-with-pointer.  )

( Semi-simulate local variables with the ability to fetch and store relative to top of stack. )

( Infix will be confusing here, too. )
: LC@ ( index -- sp[ix] ) ( 0 is top. PICK is available on many modern Forths. )
  1 + CELLWIDTH *  ( Skip over the stack address on stack. )
  SP@ + @  ( Assumes push-down stack. Will fail on push-up. )
;

( Infix will be confusing here, too. )
: LC! ( n index -- ) ( 0 is top. Just store. This is not ROLL. )
  2 + CELLWIDTH *  ( Index and stack address are extra on stack during calculation. )
  SP@ +  ( Assumes push-down stack. )
  ! ( *** Will fail in MISERABLE ways on push-up stacks! *** )
;

( Make things easier to read. )
( Infix will be confusing here, too. )

: PRCH EMIT ;

: COMMA 44 PRCH ;
: COLON 58 PRCH ;
: POINT 46 PRCH ;
: LPAREN 40 PRCH ;
: RPAREN 41 PRCH ;

( No trailing space. )
: PSNUM ( number -- )
 0 .R ;


( Do it in integers! )

( Watch limits on 16 bit processors! )

7 CONSTANT SCYCLE ( years in short cycle )
( SCYCLE = 7 )

7 2 * CONSTANT SPMCYC ( short cycles in medium cycle )
( SPMCYC = 7 × 2 )

SCYCLE SPMCYC * CONSTANT MCYCLE ( years in medium cycle, should be 98 )
( MCYCLE = SCYCLE × SPMCYC )

7 7 * CONSTANT SPLCYC ( short cycles in single long cycle )
( SPLCYC = 7 × 7 )

SCYCLE SPLCYC * CONSTANT LCYCLE ( years in single long cycle, should be 343 )
( LCYCLE = SCYCLE × SPLCYC )

7 CONSTANT MP2LCYC ( medium cycles in double long cycle )
( MP2LCYC = 7 )
( MPLCYC would not be an integer: 3 1/2 )

MCYCLE MP2LCYC * CONSTANT 2LCYCLE ( years in double long cycle, should be 686 )
( 2LCYCLE = MCYCLE × MP2LCYC )

352 CONSTANT DPSKIPYEAR ( floor of days per year  )


5 CONSTANT RDSCYCLE ( remainder days in short cycle )

DPSKIPYEAR SCYCLE * RDSCYCLE + CONSTANT DPSCYCLE ( whole days per 7 year cycle )
( DPSCYCLE = DPSKIPYEAR × SCYCLE + RDSCYCLE )
( DPSCYCLE SPMCYC * CONSTANT DPMCYCLE )
( DPMCYCLE = DPSCYCLE × SPMCYC )
( DPMCYCLE MP2LCYC * CONSTANT DP2LCYCLE )
( DP2LCYCLE = DPMCYCLE × MP2LCYC )
( DPMCYCLE and DP2LCYCLE would overflow on 16 bit math CPUs. )
( No particular problem on 32 bit CPUs.

RDSCYCLE SPMCYC * 1 - CONSTANT RDMCYCLE ( remainder days in medium cycle )
( RDMCYCLE = RDSCYCLE × SPMCYC - 1 )

RDMCYCLE MP2LCYC * 2 + CONSTANT RD2LCYCLE ( remainder days in double long cycle -- odd number )
( RD2LCYCLE = RDMCYCLE × MP2LCYC + 2 )
( RD2LCYCLE / 2LCYCLE is fractional part of year. )
( Ergo, length of year is DPSKIPYEAR + RD2LCYCLE / 2LCYCLE, )
( or 352 485/686 days. )

12 CONSTANT MPYEAR ( months per year )

DPSKIPYEAR MPYEAR /MOD CONSTANT FDMONTH ( floor of days per month )
( FDMONTH = DPSKIPYEAR / MPYEAR )
CONSTANT FRMONTH ( floored minimum remainder days per month )
( FRMONTH = DPSKIPYEAR MOD MPYEAR )

2LCYCLE MPYEAR * CONSTANT MDENOMINATOR ( denominator of month fractional part )
( MDENOMINATOR = 2LCYCLE × MPYEAR  )

FRMONTH 2LCYCLE * RD2LCYCLE + CONSTANT MNUMERATOR ( numerator of month fractional part )
( MNUMERATOR  = FRMONTH × 2LCYCLE + RD2LCYCLE )
( Ergo, length of month is FDMONTH + MNUMERATOR / MDENOMINATOR, )
( or 29 3229/8232 days. )

MDENOMINATOR 2 / CONSTANT MROUNDFUDGE

( Infix will be confusing below here, as well. )
( Hopefully, the comments and explanations will provide enough clues. )

( Sum up the days of the months in a year. )
: SU1MONTH ( startfractional startdays -- endfractional enddays )
  FDMONTH + ( Add the whole part. )
  SWAP ( Make the fractional part available to work on. )
  MNUMERATOR + ( Add the fractional part. )
  DUP MDENOMINATOR < ( Have we got a whole day yet? )
  IF
    SWAP ( No, restore stack order for next pass. )
  ELSE
    MDENOMINATOR - ( Take one whole day from the fractional part. )
    SWAP 1+ ( Restore stack and add the day carried in. )
  ENDIF
;

: PRMONTH ( fractional days -- fractional days )
  SPACE DUP PSNUM POINT ( whole days )
  OVER 1000 UM* ( Fake three digits of decimal precision. )
  MROUNDFUDGE 0 D+ ( Round the bottom digit. )
  MDENOMINATOR FM/MOD ( Divide, or evaluate the fraction. )
  S>D <# # # # #> ( Formatting puts most significant digits in buffer first. )
  TYPE ( Fake decimal output. )
  DROP SPACE
;

: SH1IDEALYEAR ( year daysmemory fractional days -- year daysmemory fractional days )
  CR
  12 0 DO
    3 LC@ PSNUM SPACE ( year )
    I PSNUM COLON SPACE
    SU1MONTH
    DUP 3 LC@ - ( difference in days )
    2 LC@ ( ceiling ) IF 1+ ENDIF
    DUP PSNUM SPACE ( show theoretical days in month )
    3 LC@ + ( sum of days )
    LPAREN DUP PSNUM COMMA SPACE
    2 LC! ( update )
    PRMONTH RPAREN CR
  LOOP
;

: SHOWIDEALMONTHS ( years -- )
  >R
  0 0 0 0 ( year, daysmemory, fractional, days )
  R> 0 DO
    CR
    SH1IDEALYEAR
    3 LC@ 1+ 3 LC!
  LOOP
  DROP DROP DROP DROP
;

  0 CONSTANT SKMONTH
  1 CONSTANT SK1SHORTCYC
  4 CONSTANT SK2SHORTCYC
 48 CONSTANT SKMEDIUMCYC
186 CONSTANT LPLONGCYC  ( Must be short1 or short2 within the seven year cycle. )

( Since skipyears are the exception, )
( we test for skipyears instead of leapyears. )
( Calendar system starts with year 0, not year 1. )
( Would need to check and adjust if the calendar started with year )
: ISKIPYEAR ( year -- flag )
  DUP MCYCLE MOD SKMEDIUMCYC =
  IF DROP -1  ( One specified extra skip year in medium cycle. )
  ELSE
    DUP SCYCLE MOD DUP
    SK1SHORTCYC =
    SWAP SK2SHORTCYC = OR  ( Two specified skip years in short cycle, but ... )
    SWAP LCYCLE MOD LPLONGCYC = 0= AND ( not the specified exception in the long cycle. )
  ENDIF
;


( At this point, I hit a condundrum. )
( Modern "standard" Forths want uninitialized variables, )
( but ancient, especially fig-Forths want initialized variables. )
( The lower-level <BUILDS DOES> for fig is only partially part of the modern standard. )
( And CREATE is initialized as a CONSTANT in the fig-Forth, )
( but has no initial characteristic code or value in modern standards. )
( So. )
( On ancient Forths, VARIABLE wants an initial value. We give it a zero. )
( The zero stays around forever on modern Forths, or until you drop it. )
0 VARIABLE DIMARRAY  ( Days In Months array )
   30 DIMARRAY !  ( 1st month )
   29 ,
   30 ,
   29 ,
   29 ,
   30 ,
   29 ,
   30 ,
   29 ,
   29 ,
   30 ,
   29 ,
   0 ,

: DIMONTH ( year month -- days )
  DUP 0 < 0=
  OVER MPYEAR < AND 0=
  IF
    DROP DROP 0  ( Out of range. No days. )
  ELSE
    DUP CELLWIDTH * DIMARRAY + @  ( Get the basic days. )
    SWAP SKMONTH =  ( true if skip month )
    ROT ISKIPYEAR AND  ( true if skip month of skip year )
    1 AND - ( Subtrahend is 1 only if skip month of skip year. )
  ENDIF
;
   
: SH1YEAR ( year daysmemory fractional days -- year daysmemory fractional days )
  CR
  12 0 DO
    3 LC@ PSNUM SPACE ( year )
    I PSNUM COLON SPACE
    SU1MONTH  ( ideal month )
    3 LC@ I DIMONTH  ( real month )
    DUP PSNUM SPACE ( show days in month )
    3 LC@ + ( sum of days )
    LPAREN DUP PSNUM COMMA SPACE
    2 LC! ( update )
    PRMONTH RPAREN CR
  LOOP
;

: SHOWMONTHS ( years -- )
  >R
  0 0 0 0 ( year, daysmemory, fractional, days )
  R> 0 DO
    CR
    SH1YEAR
    3 LC@ 1+ 3 LC!
  LOOP
  DROP DROP DROP DROP
;



Copying and pasting from here doesn't work very well. You can download the source code from
https://osdn.net/users/reiisi/pastebin/4990
You can save the file as something like "econmonths.fs".

In most modern Forths, you can just paste it into a running Forth session, and run it with
7 SHOWIDEALMONTHS
to show the ideal months that Ted talks about here, or
7 SHOWMONTHS
to show the months by the skip years, according to their calendar. You can compare the two, to see how their skip years keep the slippage minimal, restoring to no slippage at all after six hundred eight-six years.

If you need a Forth to run it on, you can find gforth at
<https://www.gnu.org/software/gforth/>.
You can also find it in the packages of most modern OS distributions and in many application stores. (It is Android's store, but not in iOS's, at least, not at the time I wrote this.) For MSWindows, you can download Cygwin at <https://www.cygwin.com/> and get gforth through the Cygwin packages.

If you like to compile things like this yourself, I guess I won't need to tell you how.

HTML documentation can be found on the web at <http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/>, which includes a tutorial for experienced programmers. An easier tutorial can be found in the book, Starting Forth, which can be found here: <https://www.forth.com/starting-forth/>.

Gforth is not the only Forth which will work, I think most modern Forths will run the code without modification.

The newsgroup comp.lang.forth, which can be accessed through newsreaders and various web interfaces is a good source of amusing and sometimes informative conversation about Forth.

If you like compiling things to play with, I have my own Forth, written in C, which you can find here: <http://bif-c.sourceforge.net/>. You'll want to look at the wiki, too: <https://sourceforge.net/p/bif-c/wiki/Home/>.

If Forth's postfix syntax is uncomfortable, I wrote similar programs in the Basic Calulator utility, bc, which is generally part of most modern operating system distributions without having to get it from packages. (You can get it as a package through Cygwin if you are running one of Microsoft's OSses.)

Just run "bc" from the command line and paste in the bc code, which you can get here: <https://osdn.net/users/reiisi/pastebin/4988>.

And, as I suggest in the code comments, you might modify the code to see how well your own leap year system works for your world. (Pretty well, really.)



You may have noticed, their calendar includes zeros. Years, months, days, all start with the zeroeth. That's a little different from us, isn't it?

And you're probably wondering about hours and minutes at this point. Similar to the way it happened in our world, the 12 constellations that represented the months also represented the hours of the night. Day and night were divided into four watches, and the night had three constellations per watch, so the day did, too.

Then some bright soul recognized that day and night varied in length, and instead of tying the hours to dawn or sunset, tied them to noon. And the royalty of his country liked it and it stuck for the more progressive parts of the world.

Sixty minute hours were derived from twelves, to give sixty minute hours and sixty second minutes. And that's convenient for us, because we could get confused if they used hundreds or forty-nines or base two.

(I really would have liked to show Ted's original programs. But I would have to write the emulator for the hardware he used, write the assembler and use it to bootstrap the language interpreter, write tools for converting -- meaningfully -- from their character set to ours, and so on. And I'd want to construct a font for their characters, too. That's a lot of work. Maybe if I ever write a best seller and make a million dollars off of it, I'll be able to break loose the time and hire the employees to do such a thing. ;-)

Previous TOC Next



[Backup and edit history will eventually be here: http://joel-rees-economics.blogspot.com/2017/04/backup-soc500-03-10-computers.html.]




[Chapter 3 part 10 is original to the second draft, and is not found in the first draft. Chronologically, it would be placed in chapter five of the first draft: http://free-is-not-free.blogspot.com/2016/05/economics-101-novel-ch05-first-semester.html.]

[JMR201704120928: end-backup.]

No comments:

Post a Comment

Keep it on topic, and be patient with the moderator. I have other things to do, too, you know.