# HP Forums

Full Version: (50g) Earthquake Magnitudes: How Much Stronger?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In honor of the two large earthquakes here in Southern California in the past two consecutive days, here's a little User RPL program called 'QUAKE' which answers the question, "How much bigger in one earthquake than another earthquake?"

"Earthquake magnitude" has many different meanings. This program uses the definition used by the USGS, since that's what the US news services quote.

INPUT: Two earthquake magnitudes (order doesn't matter).
OUTPUT: How much "BIGGER" the larger quake is, and how much "STRONGER" (energy expended) the larger quake is. Both outputs are tagged.

Example: Yesterday's quake was M7.1 and the quake the day before that was M6.4. How much worse was yesterday's quake?

7.1 ENTER 6.4 QUAKE -->
STRONGER: 11.2
BIGGER: 5

So yesterday's quake was 5 times bigger and 11.2 times stronger than the quake the day before that.

'QUAKE'
<< I->R - ABS ALOG LASTARG 2. / ALOG OVER * 1. RND
"STRONGER" ->TAG SWAP 1. RND "BIGGER" ->TAG >>

BYTES: 76.5 #EECDh

The math is simple. If the two magnitudes are A and B:
BIGGER = 10^ABS(A-B)
STRONGER = 10^(ABS(A-B)/2)*BIGGER
Simplifying the program is left as a micro-challenge.

Hi, Joe:

Sorry for the quakes, we had a respectable one last week or so in Costa Rica, no damage.

(07-06-2019 01:21 PM)Joe Horn Wrote: [ -> ]Example: Yesterday's quake was M7.1 and the quake the day before that was M6.4. How much worse was yesterday's quake?

7.1 ENTER 6.4 QUAKE -->
STRONGER: 11.2
BIGGER: 5
[...]

'QUAKE'
<< I->R - ABS ALOG LASTARG 2. / ALOG OVER * 1. RND
"STRONGER" ->TAG SWAP 1. RND "BIGGER" ->TAG >>

BYTES: 76.5 #EECDh

HP-71B:

INPUT A,B @ T=ABS(A-B) @ "Bigger:";10^T;", Stronger:";10^(1.5*T)

Trivial but shorter and way less cryptic, as usual. If you want results rounded to just 1 decimal place, place a FIX 1 anywhere before the output.

Have a nice weekend.

V.
(07-06-2019 01:21 PM)Joe Horn Wrote: [ -> ]'QUAKE'
<< I->R - ABS ALOG LASTARG 2. / ALOG OVER * 1. RND
"STRONGER" ->TAG SWAP 1. RND "BIGGER" ->TAG >>

BYTES: 76.5 #EECDh

Interesting. I make that 86 bytes but with the same checksum as you.

There's this option too (leaving the rounding to the user's display settings):

Code:
```<<   - ->NUM ABS ALOG DUP 1.5 ^   "STRONGER" ->TAG SWAP "BIGGER" ->TAG >>```

76.5 bytes, #3C12h
And for RPN fans here is a 42S version

Code:
```00 { 47-Byte Prgm } 01▸LBL "QUAKE" 02 - 03 ABS 04 10↑X 05 1.5 06 RCL× ST L 07 10↑X 08 "Bigger: " 09 ARCL ST Y 10 ├"[LF]Stronger: " 11 ARCL ST X 12 AVIEW 13 END```
(07-06-2019 05:06 PM)grsbanks Wrote: [ -> ]
(07-06-2019 01:21 PM)Joe Horn Wrote: [ -> ]'QUAKE'
<< I->R - ABS ALOG LASTARG 2. / ALOG OVER * 1. RND
"STRONGER" ->TAG SWAP 1. RND "BIGGER" ->TAG >>

BYTES: 76.5 #EECDh

Interesting. I make that 86 bytes but with the same checksum as you.

Yes, it's 86 bytes if you execute BYTES on the name, but 76.5 bytes if you execute BYTES on the program itself, which I prefer to do, to allow for renaming.
(07-06-2019 04:20 PM)Valentin Albillo Wrote: [ -> ]
HP-71B:

INPUT A,B @ T=ABS(A-B) @ "Bigger:";10^T;", Stronger:";10^(1.5*T)

Trivial but shorter and way less cryptic, as usual.

Thanks for sharing that! The human-readable clarity of HP-71 BASIC always warms my heart.
(07-06-2019 05:07 PM)Didier Lachieze Wrote: [ -> ]And for RPN fans here is a 42S version

Code:
```00 { 47-Byte Prgm } 01▸LBL "QUAKE" 02 - 03 ABS 04 10↑X 05 1.5 06 RCL× ST L 07 10↑X 08 "Bigger: " 09 ARCL ST Y 10 ├"[LF]Stronger: " 11 ARCL ST X 12 AVIEW 13 END```

Oh, does this mean I can play 'Quake' on my DM42?
(07-06-2019 09:52 PM)Joe Horn Wrote: [ -> ]Yes, it's 86 bytes if you execute BYTES on the name, but 76.5 bytes if you execute BYTES on the program itself, which I prefer to do, to allow for renaming.

Interesting. I'll have to read up on this and find out why.

Feeding my version of the program to BYTES makes it 67 bytes in length.
On the HP Prime, I have implemented some additional earthquake functions that may be of interest.