<?php

/*
   ###########################################################################
   RELATIVISTIC SPACECRAFT MOTION TYPE 1 NUMERICAL WORKSHEET

   AUTHOR   : Jay Tanner - 2025
   LANGUAGE : PHP v8.2.12
   LICENSE  : Public Domain

   This program computes the basic relativistic linear motion statistics for an
   intestellar or intergalactic space voyage, taking into account the effects
   of relativistic time dilation.  Computations are carried out to 50 decimals.

   However, it can also be used for travel computations within the solar system
   as well.

   The ultra-high precision is to make it easier to numerically compare Newton-
   ian physics to relativistic physics when working with ordinary or smaller
   distances.
   ###########################################################################
*/

   
ob_start(); // Initialize output buffer.

   
$cYear date('Y');

// ---------------------------------------------------------------
// Define the program cookie name and set it to expire in 30 days.

   
$CookieName 'Relativistic-Spacecraft-Motion-Type-1-Worksheet';
   
$ExpiresIn30Days time() + 30*86400;


// ---------------------------------
// Define PHP program and HTML info.

   
$_AUTHOR_           "Jay Tanner - $cYear";
   
$_PROGRAM_VERSION_  'v1.00 - '$at "&#97;&#116;&#32;&#76;&#111;&#99;&#97;&#108;&#32;&#84;&#105;&#109;&#101;&#32;"$LTC "&#85;&#84;&#67;";
   
$_SCRIPT_FILE_PATH_ Filter_Input(INPUT_SERVER'SCRIPT_FILENAME');
   
$_REVISION_DATE_    $_PROGRAM_VERSION_ .'Revised: 'date("Y-F-d-l $at h:i:s A   ($LTC"FileMTime($_SCRIPT_FILE_PATH_))."&minus;05:00)";
   
$_BROWSER_TAB_TEXT_ "Relativistic Spacecraft Motion Type 1";
   
$_INTERFACE_TITLE_  "<span style='font-size:14pt;'>Relativistic Spacecraft Motion Type-1 Worksheet</span><br><br><span style='font-size:11pt;'>PHP Program by Jay Tanner of Waterloo, NY, USA</span>";


/* -------------------------------------
   Define main TextArea text and background
   colors and HTML table row span. If an
   error is reported, then these colors
   will change internally to red/white.
*/
   
$TxColor 'black';
   
$BgColor 'white';


// ---------------------------------------------
// Do this only if [SUBMIT] button was clicked.

   
$w Filter_Input(INPUT_POST'SubmitButton');

   if (!IsSet(
$w))
  {

/* ----------------------------------------------------------------------
   If this program is being called externally, rather than being executed
   by clicking the [SUBMIT] button, and an active cookie also exists,
   then restore the previously saved interface settings from it. If
   the user leaves and comes back later, all the interface settings
   will be remembered and restored if the cookie was not deleted.
*/
   
$w Filter_Input(INPUT_COOKIE$CookieName);

   if (IsSet(
$w))
      {
       
$CookieDataString Filter_Input(INPUT_COOKIE$CookieName);
       list(
$a,$D,$TimeUnitsSymbol) = Preg_Split("[\|]"$CookieDataString);
      }

   else

/* -----------------------------------------------------------
   If there is no previous cookie with the interface settings,
   then set the initial default interface startup values and
   store them in a new cookie.
*/
 
{
  
$a '9.80665';         // Acceleration Rate (m/s²)
  
$D '1';               // Distance in Light Years
  
$TimeUnitsSymbol 'Y'// Time Units Symbol


// -------------------------------------------
// Store current interface settings in cookie.

   
$CookieDataString "$a|$D|$TimeUnitsSymbol";
   
SetCookie ($CookieName$CookieDataString$ExpiresIn30Days);
  } 
// End of  else {...}

  
// End of  if (!isset(_POST['SubmitButton']))


/* ------------------------------------------
   Read values of all interface arguments and
   set any empty arguments to default values.
*/
   
$w Filter_Input(INPUT_POST'SubmitButton');

   if (isset(
$w))
{
   
$a trim(Filter_Input(INPUT_POST'a'));
   
$a Str_Replace('-'''$a);

   
$D trim(Filter_Input(INPUT_POST'D'));
   
$D Str_Replace(' '''$D);
   
$D Str_Replace('-'''$D);
   
$D = (StrPos($D'.') === FALSE)? "$D.0" $D;
   
$D RTrim(RTrim(Str_Replace(','''$D), '0'), '.');

   
$TimeUnitsSymbol trim(Filter_Input(INPUT_POST'TimeUnitsSymbol'));
   
$TimeUnitsSymbol StrToUpper(substr($TimeUnitsSymbol,0,1));

// -------------------
// Set default values.

   
if ($a == '') {$a '9.80665';}
   if (
$D == '') {$D '1.0';}
   if (
$TimeUnitsSymbol == '') {$TimeUnitsSymbol 'Y';}

// -------------------------------------
// Store interface argument in a cookie.

   
$CookieDataString "$a|$D|$TimeUnitsSymbol";
   
SetCookie ($CookieName$CookieDataString$ExpiresIn30Days);
}


/* ---------------------------------------------
   Optionally check ($a) value for validity.
   If error, set error flag and message values.
*/
   
$ErrFlag FALSE;
   
$ErrMssg '';


// -------------------------------------------------
   
if (StrPos('SMHDWY'$TimeUnitsSymbol) === FALSE)
      {
       
$ErrFlag TRUE;
       
$ErrMssg =
"Bad time units symbol:
$TimeUnitsSymbol

The time units symbols are:
S   Seconds
M   Minutes
H   Hours
D   Days
W   Weeks
Y   Years

The symbols are NOT case-sensitive."
;
      }


// --------------------
   
if (!Is_Numeric($D))
      {
       
$ErrFlag TRUE;
       
$ErrMssg "Bad distance value:\n$D\n\nThe distance value must be a plain positive number.";
      }

// --------------------
   
if (!Is_Numeric($a))
      {
       
$ErrFlag TRUE;
       
$ErrMssg "Bad acceleration value:\n$a\n\nThe acceleration value must be a plain number greater than zero.";
      }



/* -----------------------------
   Set initial uniform width for
   tables alignment in pixels.
*/
   
$TableWidth '780';


// ******************************************
// ******************************************
// If error was reported (TRUE), then display
// the error message on a red background.

   
if ($ErrFlag === TRUE)
  {
   
$TxColor 'white';
   
$BgColor '#CC0000';
   
$TextArea2Text '';

   
$TextArea1Text =
"=== ERROR ===

$ErrMssg";
  }

else


  {
// *********************************************************
// BEGIN MAIN COMPUTATIONS HERE IF NO ERRORS DETECTED ABOVE.
// *********************************************************




// ----------------------------------
// Computation or function call code.


   
$statistics Relativity_101 ($a$D$TimeUnitsSymbol);




// *******************************************
// DROP THROUGH HERE AFTER COMPUTATIONS ABOVE
// TO PRINT OUT THE RESULTS OF THE OPERATIONS.
// *******************************************

   
$TextArea1Text =
"
$statistics
"
;
  }


// ****************************
// Define TextArea2 text block.

   
$TextArea2Text =
"******************************************************************************
                             SOME GENERAL INFORMATION

This program computes the basic relativistic linear motion statistics for an
interstellar or intergalactic space voyage,  taking into account the effects
of relativistic time dilation out to millions of light years.   Computations
are carried out to 50 decimals.  However, it can also be used for space voy-
age computations within the solar system as well as for target distances of
hundreds or millions of light years.

The initial  default values are set  to compute the statistics for a voyage at
1G acceleration to a target 1 light year away.  This is a common problem often
encountered in studying the basics of relativistic space voyages.

The program allows the user to experiment with various acceleration, distance
and time units and compute the effects of relativistic time dilation on both
parties during and at each end of the voyage.

The ultra-high precision is to make it easier to numerically compare Newton-
ian physics to relativistic physics when working with ordinary or smaller
distances.   When working with only double precision, such numerical com-
parisons are hard to make very accurately.

In reality, at this point in time, we cannot yet make the kind of engines we
require to make the kind of voyages so easily simulated on paper.    But we
can at the least compute the fantasy while we await the required technology
to arise, if ever.

The time dilation problem makes manned voyages to any extremely remote places
very impractical.  It could take hundreds or even thousands of Earth years to
make a round trip voyage even to nearby stars, whether manned or robotic.

Also see this ref:
https://math.ucr.edu/home/baez/physics/Relativity/SR/Rocket/rocket.html

CAVEAT:
In considering the grievous logistics involved with such voyages, our civili-
zation will probably be  annihilated by a cosmic  or anthropological calamity
before we develop such space travel technology, but one can dream - ad astra.
******************************************************************************
"
;



// **************************************************************************
// Determine number of text columns and rows to use in the output text areas.
// These values vary randomly according to the text block width and length.
// The idea is to eliminate the need for scroll-bars within the text areas
// or worry as much about the variable dimensions of a text display area.

// ------------
// Text Area 1.

   
$Text1Cols Max(Array_Map('StrLen'PReg_Split("[\n]"trim($TextArea1Text))));
   if (
$Text1Cols <= 78) {$Text1Cols 78;} // Default
   
$Text1Rows Substr_Count($TextArea1Text"\n");

// ------------
// Text Area 2.

   
$Text2Cols Max(Array_Map('StrLen'PReg_Split("[\n]"trim($TextArea2Text))));
   if (
$Text2Cols 80) {$Text2Cols 80;} // Default
   
$Text2Rows Substr_Count($TextArea2Text"\n");



// ******************************************
// GENERATE CLIENT WEB PAGE TO DISPLAY OUTPUT

   
print <<< HTML_WEB_PAGE

<!DOCTYPE HTML>
<HTML>

<head>
<title>
$_BROWSER_TAB_TEXT_</title>

<meta name='viewport' content='width=device-width, initial-scale=0.8'>

<meta http-equiv='content-type' content='text/html; charset=UTF-8'>
<meta http-equiv='pragma'       content='no-cache'>
<meta http-equiv='expires'      content='-1'>
<meta name='description'        content='Numerical relativistic spacecraft motion type 1 statistics worksheet'>
<meta name='keywords'           content='NeoProgrammics/PHPScienceLabs'>
<meta name='author'             content='Jay Tanner - https://www.NeoProgrammics.com'>
<meta name='robots'             content='index,follow'>
<meta name='googlebot'          content='index,follow'>

<style>

 BODY {color:white; background:black; font-family:Verdana; font-size:12pt; line-height:125%;}

 TABLE
{font-size:13pt; border: 1px solid black;}


 TD
{
 color:black; background:white; line-height:150%; font-size:10pt;
 padding:6px; text-align:center;
}


 UL
{font-family:Verdana; font-size:12pt; line-height:150%; text-align:justify;}


 PRE
{
 background:white; color:black; font-family:monospace; font-size:12.5pt;
 font-weight:bold; text-align:left; line-height:125%; padding:6px;
 border:2px solid black; border-radius:8px;
 page-break-before:page;
}


 DIV
{
 background:white; color:black; font-family:Verdana; font-size:11pt;
 font-weight:normal; line-height:125%; padding:6px;
}


 TEXTAREA
{
 background:white; color:black; font-family:monospace; font-size:11.5pt;
 font-weight:bold; padding:4pt; white-space:pre; border-radius:8px;
 line-height:125%;
}


 INPUT[type='text']::-ms-clear {width:0; height:0;}

 INPUT[type='text']
{
 font-family:monospace; color:black; background:white; font-size:13pt;
 font-weight:bold; text-align:center; box-shadow:2px 2px 3px #666666;
 border:1px solid black; border-radius:4px;
}
 INPUT[type='text']:focus
{
 font-family:monospace; background:white; box-shadow:2px 2px 3px #666666;
 font-size:13pt; border:2px solid blue; text-align:center; font-weight:bold;
 border-radius:2px;
}



 INPUT[type='submit']
{
 background:black; color:cyan; font-family:Verdana; font-size:10pt;
 font-weight:bold; border-radius:4px; border:4px solid #777777;
 padding:3pt;
}
 INPUT[type='submit']:hover
{
 background:black; color:white; font-family:Verdana; font-size:10pt;
 font-weight:bold; border-radius:4px; border:4px solid red;
 padding:3pt;
}





// Link states MUST be set in the following order:
// :link, :visited, :hover, :active

 A:link
{
 font-size:10pt; background:transparent; color:#8080FF; border-radius:4px;
 font-family:Verdana; font-weight:bold; text-decoration:none;
 line-height:175%; padding:3px; border:1px solid transparent;
}
 A:visited
{
 font-size:10pt; background:transparent; color:DarkCyan; border-radius:4px;
}
 A:hover
{
 font-size:10pt; background:yellow; color:black; border:1px solid black;
 box-shadow:1px 1px 3px #222222; border-radius:4px;
}
 A:active
{
 font-size:10pt; background:yellow; color:black; border-radius:4px;
}


 HR {background:red; height:4px; border:0px;}


[title-text]:hover:after
{
 opacity:1.0;
 transition:all 1.0s ease 1.0s;
 text-align:left;
 visibility:visible;
}

[title-text]:after
{
 opacity:1.0;
 content:attr(title-text);
 text-align:left;
 left:50%;
 background-color:yellow;
 color:black;
 font-size:10pt;
 position:absolute;
 padding:1px 5px 2px 5px;
 white-space:pre;
 border:1px solid red;
 z-index:1;
 visibility:hidden;
}

[title-text] {position: relative;}


::selection{background-color:yellow !important; color:black !important;}
::-moz-selection{background-color:yellow !important; color:black !important;}
</style>

</head>

<body>

<!-- Define container form --->
<form name="form1" method="post" action="">

<!-- Define main page title/header. --->
<table width="
$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">


<tr><td colspan="99" style="color:white; background-color:#000066; border:2px solid white; border-radius:8px 8px 0px 0px;">
$_INTERFACE_TITLE_</td></tr>
</table>


<!-- Define input (a) text box  --->
<table width="
$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr><td style="line-height:175%; border-radius:0px 0px 0px 8px;" width='33%'>Acceleration Rate (m/s&#178;)</b><br><input name="a"  type="text" value="
$a"  size="24" maxlength="32"></td>
<td style="line-height:175%;" width='33%'>Distance Value in Light Time Units<br><input name="D"  type="text" value="
$D"  size="32" maxlength="81"></td>
<td style="line-height:175%; border-radius:0px 0px 8px 0px;" width='33%' title=' TIME UNITS SYMBOLS \n\n S\tSeconds \n M\tMinutes \n H\tHours \n D\tDays \n W\tWeeks \n Y\tYears (365.25 days) \n\n NOT CASE-SENSITIVE '>Time Units Symbol<br><input name="TimeUnitsSymbol"  type="text" value="
$TimeUnitsSymbol"  size="2" maxlength="1"></td></tr>
</table>


<!-- Define [SUBMIT] button --->
<table width="
$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr><td colspan="99" style="background-color:black;"><input type="submit" name="SubmitButton" value=" C O M P U T E "></td></tr>
<!-- Yellow source code view link. --->
<tr>
<td colspan='3' style='background:transparent; color:black; font-size:10pt;
                       text-align:center;'>
<a href='View-Source-Code.php' target='_blank'
   style='font-family:Verdana; color:black; background:yellow;
         text-decoration:none; border:1px solid black; padding:4px;
         font-size:10pt; border-radius:4px;'>
         &nbsp;<span style='font-weight:normal;'>View/Copy PHP Source Code</span>&nbsp;</a>
</td>
</tr>
</table>




<!-- Define TextArea1 --->
<table width="
$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="99" style="text-align:center; color:GreenYellow; background-color:black;">Double-Click Within Text Area to Select ALL Text<br>
<textarea ID="TextArea1" name="TextArea1" style="color:
$TxColor; background:$BgColor; padding:6px; border:2px solid white;" cols="$Text1Cols" rows="$Text1Rows" ReadOnly OnDblClick="this.select();" OnMouseUp="return true;">
$TextArea1Text
</textarea>
</td>
</tr>
</table>


<!-- Define TextArea2 --->
<table width="
$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="99" style="text-align:center; color:GreenYellow; background:black;">Double-Click Within Text Area to Select ALL Text<br>
<textarea ID="TextArea2" name="TextArea2" style="color:black; background:white; padding:6px;" cols="
$Text2Cols" rows="$Text2Rows" ReadOnly OnDblClick="this.select();" OnMouseUp="return true;">
$TextArea2Text
</textarea>
</tr>
</table>


<!-- Define page footer --->
<table width="
$TableWidth" align="center" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="99" style="color:GreenYellow; background:black;">PHP Program by 
$_AUTHOR_<br><span style="color:silver; background:black;">$_REVISION_DATE_</span></td>
</tr>
</table>

</form>
<!-- End of container form --->


<!-- Extra bottom scroll space --->
<br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>

</body>
</HTML>



HTML_WEB_PAGE;



/*
  ############################################################################
  This function computes the arbitrary-precision natural logarithm for any
  positive (x) argument to up to 100 decimals.

  SPECIAL CASE:
  If (x) is a decimal value (0 < x < 1), then Ln(x) = -Ln(1/x)

  ERRORS:
  Returns error message if non-numeric or if (x <= 0).

  NO DEPENDENCIES
  ############################################################################
*/


   
function BC_Ln ($xArgStr$Decimals=16)
{
   
$x trim($xArgStr);
   if (
StrPos($x'-') !== FALSE or $x <= or !Is_Numeric($x))
  {return 
"ERROR: BC_Ln()\n\nArgument must be numeric and > 0";}

   
$q trim($Decimals);
   
$Q 100;
   if (
$q  $Q) {$q $Q;}
   if (
$q <=  0) {$q =  1;}

// -------------------------------------------------------
// Handle case of fractional (x) values where (0 < x < 1).

   
$sign ''; if ($x and $x 1) {$sign '-'$x bcDiv('1'$x$Q);}

// -------------------------------------------------------------------------------
// Natural logarithm of 10 to 110 decimals (used as internal conversion constant).

   
$LN_10 '2.30258509299404568401799145468436420760110148862877297603332790096757260967735248023599720508959829834196778403';

/* ------------------------------------------
   Determine power of 10 in positive (x) and
   where to place the decimal in the result.
*/
   
$dpos 1;
   if(
$x >= 10)
     {
      
$dpos floor(log10($x) + 1);
      
$x Str_Replace('.'''$x);
      
$x substr($x,0,1).'.'.substr($x,1StrLen($x));
     }

   
$PrecisionLimit '0.'.Str_Repeat('0'$q).'1';
   
$n $term 1;
   
$sum 0;
   
$k bcDiv(bcSub($x'1'$Q), $x$Q);

   while (
abs($term) > $PrecisionLimit)
  {
   
$numer bcpow($k$n$Q);
   
$denom $n;
   
$term  bcDiv($numer$denom$Q);
   
$sum   bcAdd($sum$term$Q);
   
$n++;
  }
   
$sum bcAdd($sumbcMul($dpos-1$LN_10$Q), $Q);

// -------------------------------------------------------
// Return the sum rounded to the given number of decimals.

   
return $sign.bcAdd($sumStr_Replace('1','5'$PrecisionLimit), $q);

// End of  BC_Ln(...)




















   
function Encomma ($BCNumStr)
{
   
$N trim($BCNumStr);

   
$i StrPos($N'.');  if ($i === FALSE) {$N .= '.0';}
   if (
substr($N,0,1) == '.') {$N "0$N";}

   
$DecimalPart StrRChr($N'.');
   
$i StrPos($N'.');

   
$IntegerPart Number_Format(substr($N,0,$i));

   return 
"$IntegerPart$DecimalPart";
}






   function 
Dist_Accelerated ($AccelRate$ProperTimeInterval$Decimals=16)
{
   
$a trim($AccelRate);
   
$t trim($ProperTimeInterval);

   
$c '299792458';
   
$Q 50;
   
$q trim($Decimals);

   
$at_c bcDiv(bcMul($a$t$Q), $c$Q);
   
$c2_a bcDiv(bcMul($c$c$Q), $a$Q);

   
$X bcDiv(bcMul($c$c$Q), $a$Q);
   
$Y bcAdd('1'bcMul($at_c$at_c$Q),$Q);
   
$D bcMul($c2_abcSub(bcSqRt($Y$Q), '1'$Q),$Q);

   return 
$D;

}






/*
   ###########################################################################
   This functions returns the formal name of a large numeric value string.
   ONLY the integer part is used.  Any decimal part is ignored.

   EXAMPLE:
   Given a signed numerical string argument like:
   BigNumStr = '7,805,769,880,904,240,738,817,015,808'
   or
   BigNumStr = '78057691843657209880904240738817015808'

   If there is any decimal part of BigNum, it will be
   removed. Only the integer part counts here.

   The function returns the formal designation:
   '7.81 octillion'

   ###########################################################################
*/
   
function BC_Big_Num_Name ($BigNumStr$Decimals=2)
{

/* -------------------------------------------------------------
   Filter out any commas or negative sign and use absolute value
   of big number by removing any preceding numerical +/- sign.
*/
   
$BigNum Str_Replace(','''Str_Replace(' ' ,''trim($BigNumStr)));

// -------------------------------
// Preserve any numerical +/- sign
// to reattach to output.

   
$NumSign '';
   if (
substr($BigNum,0,1) == '-') {$NumSign '-';}
   if (
substr($BigNum,0,1) == '+') {$NumSign '+';}
   
$BigNum Str_Replace('+'''Str_Replace('-'''$BigNum));

/* ---------------------------------
   Count number number of raw digits
   in the filtered numeric string.
*/
   
$DigitsCount StrLen($BigNum);

// ------------------------------------
// Error if big integer is non-numeric.

   
if (!Is_Numeric($BigNum)) {return 'ERROR: Cannot resolve as a valid number value.';}

/* --------------------------------------------------
   Cut off any decimal part of the big number string.
   Only the big integer part counts here.
*/
   
$i StrPos($BigNum'.');   if ($i === FALSE) {$BigNum "$BigNum.0";}
   
$i StrPos($BigNum'.');   $BigNum substr($BigNum0$i);

// -----------------------------------------------
// Set number of decimals to use in output string.
// This usually just 1 to 3 decimals.

   
$decimals abs(IntVal(trim($Decimals)));

   if (
$decimals == 0) {$decimals 1;}

/* ----------------------------------------
   Define an array of formal integer names.

   https://en.wikipedia.org/wiki/Names_of_large_numbers
*/
   
$DigitGroupsStr '';

   
$BigNum StrRev($BigNum);

// ***************
// ***************

   
$groups[1]  = '';
   
$groups[2]  = 'thousand';
   
$groups[3]  = 'million';
   
$groups[4]  = 'billion';
   
$groups[5]  = 'trillion';
   
$groups[6]  = 'quadrillion';
   
$groups[7]  = 'quintillion';
   
$groups[8]  = 'sextillion';
   
$groups[9]  = 'septillion';
   
$groups[10] = 'octillion';
   
$groups[11] = 'nonillion';
   
$groups[12] = 'decillion';
   
$groups[13] = 'undecillion';
   
$groups[14] = 'duodecillion';
   
$groups[15] = 'tredecillion';
   
$groups[16] = 'quattuordecillion';
   
$groups[17] = 'quindecillion';
   
$groups[18] = 'sexdecillion';
   
$groups[19] = 'septendecillion';
   
$groups[20] = 'octodecillion';
   
$groups[21] = 'novemdecillion';
   
$groups[22] = 'vigintillion';
   
$groups[23] = 'unvigintillion';
   
$groups[24] = 'duovigintillion';
   
$groups[25] = 'trevigintillion';
   
$groups[26] = 'quattuorvigintillion';
   
$groups[27] = 'quinvigintillion';
   
$groups[28] = 'sexvigintillion';
   
$groups[29] = 'septenvigintillion';
   
$groups[30] = 'octovigintillion';
   
$groups[31] = 'novemvigintillion';
   
$groups[32] = 'trigintillion';
   
$groups[33] = 'untrigintillion';
   
$groups[34] = 'duotrigintillion';

// ----------------------------------------
// Break up big integer into spaced 3-digit
// groups and count the number of groups.

   
for($i=0;   $i $DigitsCount;   $i++)
  {
   
$DigitGroupsStr .= substr($BigNum,$i,1);

   if ((
$i+1) % == 0) {$DigitGroupsStr .= ' ';}
  }
   
$DigitGroupsStr trim(StrRev($DigitGroupsStr));

   
$DigitGroupsCount Substr_Count($DigitGroupsStr' ');

// -------------------
// Get top group name.

   
$TopNameStr $groups[$DigitGroupsCount];

// ------------------------------------
// Make number into decimal value (x).

   
$w StrRev($DigitGroupsStr);
   
$n StrRev(StrRChr($w' '));
   
$L StrLen($n);
   
$w StrRev($w);
   
$w trim($n).'.'.substr(Str_Replace(' ','',$w), $L-1StrLen($w));
   
$w SPrintF("%1.$decimals"f"$w);

   unset(
$groups);

// Done.
   
return "$NumSign$w $TopNameStr";

// End of  BC_Big_Num_Name (...)




/*
   This function computes the relativistic linear motion statistics Type 1
   in the form of a plain text table.

   Distance are in natural light time units.
   If time units = years, then distances = Light Years (LY).
   If time units = days, then distances = Light Days (LD).
   etc.


   DEPENDENCY: BC_Ln()

   ERRORS:
   No special error checking is done.
*/

   
function Relativity_101 ($AccelRateStr='9.80665'$DistStr='1'$TimeUnitStr='Y')
{
   
$Q  60// Internal working decimals.
   
$q 50;

   
$c  '299792458';
   
$a  trim($AccelRateStr);
   
$TU substr(StrToUpper(trim($TimeUnitStr)),0,1);
   
$D  Str_Replace(',' ,''trim($DistStr));

/* ---------------------------------------------------
   Determine which time constant and distance units to
   use according to the given (TimeUnitsStr).
   NOT case-sensitive.

  TIME UNITS and SYMBOLS    DISTANCE UNITS and SYMBOLS
  ----------------------    --------------------------
  Seconds           S       Light Seconds         LS
  Minutes           M       Light Minutes         LM
  Hours             H       Light Hours           LH
  Days              D       Light Days            LD
  Weeks             W       Light Weeks           LW
  Years             Y       Light Years           LY
  -------------- --------   ------------------ -------
*/
   
switch ($TU)
  {
   case 
'S'$K '1';        $TU 'Second';  $DU 'LS'; break;
   case 
'M'$K '60';       $TU 'Minute';  $DU 'LM'; break;
   case 
'H'$K '3600';     $TU 'Hour';    $DU 'LH'; break;
   case 
'D'$K '86400';    $TU 'Day';     $DU 'LD'; break;
   case 
'W'$K '604800';   $TU 'Week';    $DU 'LW'; break;
   case 
'Y'$K '31557600'$TU 'Year';    $DU 'LY'; break;
   default : 
$K '31557600'$TU 'Year';    $DU 'LY'; break;
  }

// ----------------------------------------------
// Compute relativistic linear motion statistics.

   
$G      RTrim(RTrim(bcDiv($a'9.80665'$Q), '0'), '.');
   
$A      bcDiv(bcMul($a,$K$Q),$c$Q);
   
$RecipA bcDiv('1',$A$Q);
   
$X      bcAdd($D,$RecipA$Q);
   
$X2     bcMul($X,$X$Q);
   
$T      bcSqRt(bcSub($X2,bcMul($RecipA,$RecipA$Q),$Q),$Q);
   
$beta   bcDiv($T,$X$Q);
   
$v      bcMul($beta,$c$Q);
   
$t      bcDiv(BC_Ln(bcMul($A,bcAdd($X,$T$Q),$Q)),$A$Q);

   
$TwoT   bcMul('2'$T$Q);
   
$Twot   bcMul('2'$t$Q);


// ------------------------------------------------------
// Do some extra formatting and speed units computations.

   
$afps bcDiv($a'0.3048'$q);
   
$A  bcAdd($A,  '0'$q);
   
$T  bcAdd($T,  '0'$q);
   
$t  bcAdd($t,  '0'$q);
   
$TwoT bcAdd($TwoT'0'$q);
   
$Twot bcAdd($Twot'0'$q);

   
$vkph   bcDiv(bcMul($v'3600'$Q), '1000'$q);
   
$vmph   bcDiv($vkph'1.609344'$q);
   
$v      bcAdd($v'0'$q);

   
$Ds     = (trim($DistStr) <> 1)? 's':'';
   
$Ts     = (trim($T) <> 1)? 's':'';
   
$ts     = (trim($t) <> 1)? 's':'';

   
$v      encomma($v);
   
$vkph   encomma($vkph);
   
$vmph   encomma($vmph);

   
$beta bcAdd($beta'0'$q);

// ---------------------------------------------------------------------------
// Construct output table in plain, monospace text.

   
$w =
"       ****************************************************************
           NUMERICAL RELATIVISTIC SPACECRAFT MOTION TYPE 1 WORKSHEET


#############################################################################
APPLIED DATA AND DEFINITIONS:

 Time Units     = 
$TU&#115;
 Distance Units = Light 
$TU&#115;

 c = Speed of Light.
    = 299,792,458 m/s

 a = Acceleration experienced on spacecraft (m/s&#178;).

 g = Standard gravitational acceleration on Earth.
   = 9.80665 m/s&#178;

 G = Accelerative G-Factor corresponding to (a).
     Earth G = 1.0
   = a / 9.80665

 The value of (K) used below  depends on the time units we choose to apply
 to the computations. Its value equates to the number of seconds in the
 chosen time unit.

 Distances are reckoned in the chosen light time units.  In other words,
 if the chosen time unit is years, then distances are reckoned in Light
 Years.  If the chosen time units are days, then distances are reckoned
 in Light Days, etc..
#############################################################################


 ==========================================================
   Time Units     K = Seconds in Time Unit   Distance Units
 ==============   ========================   ==============
 Seconds          1                          Light Seconds
 Minutes          60                         Light Minutes
 Hours            3600                       Light Hours
 Days             86400                      Light Days
 Weeks            604800                     Light Weeks
 Standard Years   31557600   (365.25 days)   Light Years
 ==============   ========================   ==============

 In this case, we are using 
$TU&#115; as the time units, so
 the value of K = 
$K = Seconds per $TU.


 *****************************************************************************
 THE BASIC SCENARIO and RELATED NUMERICAL COMPUTATIONS


 Acceleration rate experienced on the spacecraft.

 a = 
$a m/s&#178;
   = 
$G G
   = 
$afps ft/s&#178;

---------------------------------------------------
 Distance to the target destination in light units.

 D = 
$D Light $TU$Ds

-----------------------------------------------------------
 Relativistic Acceleration Potential.  This is the relativ-
 istic speed we would reach by accelerating at rate (a) for
 (K) seconds - IF - there was no speed-of-light limit (c).

 A = a * K / c
   = 
$A

---------------------------------------------------
 Earth time it takes to accelerate to distance (D).

 T = SqRt(D&#178; + 2*D/A)
   = 
$T $TU$Ts

2T = 
$TwoT

-----------------------------------------------------------------
 Proper (spacecraft) time it takes to accelerate to distance (D).

 t = Ln(A*((D + 1/A) + SqRt(D&#178; + 2*D/A))) / A
   = 
$t $TU$ts

2t = 
$Twot

---------------------------------------------
 Relativistic speed achieved at distance (D).
 This value will always be less than 1.

 &beta; = SqRt(D&#178; + 2*D/A) / (D + 1/A)
   = v/c
   = 
$beta

-----------------------------------------------------------------
 Speed achieved at distance (D).   This value will always be less
 than the speed of light (299,792,458 m/s).

 v = &beta; * c
   = 
$v m/s
   = 
$vkph km/h
   = 
$vmph mi/h
 *****************************************************************************
"
;

   return 
RTrim($w);

// End of  Relativity_101 (...)













// END OF PROGRAM





?>