Posts: 424
Threads: 27
Joined: Apr 2022
Reputation:
26
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
Posts: 996
Threads: 50
Joined: May 2022
Reputation:
27
(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.
Posts: 424
Threads: 27
Joined: Apr 2022
Reputation:
26
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
Posts: 424
Threads: 27
Joined: Apr 2022
Reputation:
26
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
Posts: 2,123
Threads: 217
Joined: Apr 2022
Reputation:
100
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
Posts: 424
Threads: 27
Joined: Apr 2022
Reputation:
26
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?
Posts: 2,123
Threads: 217
Joined: Apr 2022
Reputation:
100
(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
Posts: 424
Threads: 27
Joined: Apr 2022
Reputation:
26
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.
Posts: 2,123
Threads: 217
Joined: Apr 2022
Reputation:
100
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
Posts: 424
Threads: 27
Joined: Apr 2022
Reputation:
26
07-30-2022, 01:05 AM
(This post was last modified: 07-30-2022, 01:07 AM by Jack.)
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
|