QB64 Phoenix Edition
Treebeard's String-Math - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3)
+---- Forum: Programs (https://staging.qb64phoenix.com/forumdisplay.php?fid=7)
+---- Thread: Treebeard's String-Math (/showthread.php?tid=691)

Pages: 1 2 3


RE: Treebeard's String-Math - Jack - 07-29-2022

yes Kernelpanic, the code in opening post calculates the first 115 (?) Fibonacci numbers by the reciprocal of 999999999999999999999998999999999999999999999999 to 2785 digits
the number consists of 23 9's, an 8 followed by 24 9's
you can make the number larger and do the division to higher precision to get more fibo numbers


RE: Treebeard's String-Math - Kernelpanic - 07-29-2022

(07-29-2022, 08:45 PM)Jack Wrote: you can make the number larger and do the division to higher precision to get more fibo numbers
Thanks! But . . . I don't believe.  Tongue


RE: Treebeard's String-Math - Jack - 07-29-2022

for example, construct a number like this
s=string$(100,"9")+"8"+string$(101,"9")
take the reciprocal to about 48600 digits and you get 481 fibo numbers


RE: Treebeard's String-Math - Jack - 07-29-2022

up-to fibonacci 483
Code: (Select All)
digits = 48683 'digits for division etc

'========================================================================
Dim As Double t
Dim As String n, m, r
Dim As Long i, j
t = Timer
n = "1"
m = String$(100, "9") + "8" + String$(101, "9")
bDiv n, m, r

j = InStr(r, ".")
r = Mid$(r, j + 1)
j = 1
For i = 1 To 484
    Print Mid$(r, j, 101)
    j = j + 101
Next

t = Timer - t
Print t



RE: Treebeard's String-Math - Pete - 07-29-2022

Well I did some checking, and Treebeard's string math also lacks the ability to deal with repetends.

Code: (Select All)
DIM AS STRING n, m, r
DIM AS LONG i, j
t = TIMER

INPUT "enter n ", n
IF n = "" THEN
    n = "1"
    PRINT "n = "; n
END IF
INPUT "enter m ", m
IF m = "" THEN
    m = "3"
    PRINT "m = "; m
END IF
PRINT
bDiv n, m, r
PRINT "n / m = "; r
n = r

bMul n, m, r
PRINT "r * m = "; r


So we don't get back to 1. Instead, we get 1 / 3 = .3... and * 3 = .9...

Pete


RE: Treebeard's String-Math - Jack - 07-30-2022

Pete, unless you use rational arithmetic you are going to have round/off round/up errors
my only complaint about your string-math implementation is that it's not at all clear how you would use it outside of your demo
say for example that I want to use your string-math in a Gauss-Jordan system of linear equations solver, how would you go about it?


RE: Treebeard's String-Math - Pete - 07-30-2022

(07-30-2022, 12:13 AM)Jack Wrote: Pete, unless you use rational arithmetic you are going to have round/off round/up errors
my only complaint about your string-math implementation is that it's not at all clear how you would use it outside of your demo
say for example that I want to use your string-math in a Gauss-Jordan system of linear equations solver, how would you go about it?

You'd have to code the system to process the matrix and then plug each equation into +_*? into the subroutine, much the same as with the treebeard subroutine. The same problem of not having the repetend address would, of course, produce slight variations from the accepted results made on a precision calculator. Precision calculators definitely use some sort of algorithm to handle repetends so 1 / 3 * 3 = 1 instead of .999...

Pete


RE: Treebeard's String-Math - Jack - 07-30-2022

sorry Pete but I don't see anyone using your math routines to code any math problem, TreeBeard's routines can be used anywhere you want to perform arithmetic operations.


RE: Treebeard's String-Math - Pete - 07-30-2022

What I would need to do is make it more user friendly for other applications. As is, I made it to process calculations for addition, subtraction, multiplication, and division, and express the results in as many decimals as the user required, round the results if instructed to do so, and convert back and forth from scientific notation. It also can be used for ledgers as it can show results in dollars and cents, with or without commas. Also to convert to and from scientific notation.

Pete


RE: Treebeard's String-Math - Jack - 07-30-2022

Pete, I looked at your demo and I couldn't figure out how I would use your math engine to perform any math problem, it's horrifically complex
suppose that I wanted to code a simple factorial
Code: (Select All)
input "n ";n
f=1
for i=1 to n
    f=f*i
next
print f
show me how simple it is with your math-engine
I am signing off for the weekend, see you Sunday