Talk:Trigonometric functions: Difference between revisions

m (→‎Notes on precise sin implemented in Rexx: removed still more pronouns. -- ~~~~)
 
(15 intermediate revisions by 2 users not shown)
Line 60:
: Also, I long ago discovered that most trig and hyperbolic functions of this type usually require at least four extra (decimal) digits to be used (but only for some values that are near asymptotic points and others near multiples or fractions of pi. So I added one more digits to be on the safe side. Since then, I made the addition to an even five for a few hyperbolic functions and then did the same to the trig functions, but used ten here (on Rosetta Code) for safety's sake. -- [[User:Gerard Schildberger|Gerard Schildberger]] 20:55, 22 June 2012 (UTC)
 
I discussed this topic 10 years ago on Vladimir ZabrovskyKhabarovsk's Album of (Rexx) algorithms which contains a wealth of code.
 
: Did you change the REXX variable SHOWDIGS to 30? If so, I don't receive the same results you post. I assume you've must have cut and pasted from your own copy of the REXX program as the output format is much different. I would like to know what your results are for the REXX example as shown in Rosetta Code.
Line 88:
.
.</lang>
 
This isn't probably the best forum to discuss these types of code (result) minutia when code is taken out of context or the modified code or driver code isn't shown to verify your results. I can be contacted via E-mail to iron out these details before large amounts of chatter are posted. -- [[User:Gerard Schildberger|Gerard Schildberger]] 20:55, 22 June 2012 (UTC)
<br>
 
----
 
It IS! I wanted to point out a problem and its solution.
I don't think people want to understand the huge driver and its details (SHOWDIGS)
but rather want to use the functions offered for their task.
 
<br>
---
 
-----
 
<br>I couldn't disagree more about people not wanting to understand the details. That is why there are a good number
<br>of comments in the section code and the aforemented REXX code. These details are important to understand before
<br>source code is ripped from a working example. This is the main reason the number of shown digits was increased from
<br>6 to 30. People should plainly see that the example as coded works perfectly. If another constructed version doesn't
<br>give the expected results, it might be time to re-read the prologue. Or better yet, use the prologue REXX code.
<br><br>It's important to note that '''numeric digits nnn''' is not what precision you ''want'', but what precision the
<br>REXX code ''uses''. One should always specify more than what is liked. Programmers most often forget that negative
<br>numbers consume an "extra" digit, and it's always better to be safe than sorry. If one wants 30 digit accuracy, then
<br>be prepared to over-specify the numeric digits (or just use the technique shown in the REXX example on the main page).
: <br><br>The huge driver is mainly two statements with eight more to invoke the functions:
 
: The huge driver is mainly two statements with eight more to invoke the functions
:
<lang rexx>showdigs=30 /*show only 30 digits of number. */
numeric digits showdigs+10</lang>
In my other "trig/hyperbolic/math" subroutine (not included here), it has 175 different functions, and
<br>adding the REXX statements to bump the precision and re-nonormalizenormalize the result for each of the those
<br>functions would be to burdensome and bulky. In most likehoodlikelihood, the re-normaliztionnormalization would be a waste of time
<br>if the invocation program is performing a series of SIN calls, as indeed, the Rosetta Code example is.
<br>The small REXX program (here on Rosetta Code) only has 18 internal functions, and even that small number
<br>would add a significant amount of code. But that's what Rosetta Code is for. Anyone can add more versions,
<br>and it would nice to see such a version.
<br>This type of REXX code (bumping the precision, re-normalizing) can't be consoliatedconsolidated because of the
<br>manner in which REXX honors '''numeric digits''' between subroutine calls, so it's impossible to use a REXX
<br>subroutine to avoid the repetitious code. Making 175 unique subroutines is one way of solving that problem,
Line 112 ⟶ 128:
<br>elsewhere) trig/hyperbolic/math package has, but clearly, one can see the problem with adding that large a
<br>number of external functions.
<br>There is another problem with function name collision, which is another topic for another time. and worthy
<br>of a detailed discussion elsewhere.
<br>So instead, I did what was suggested in the (prologue) commentary, that is: to increase the precision
<br>higher than one needs, and just use what precision is needed from that time on. More whitespace was added
<br>around that part of the section comments so it can more easily be seen what was written. If one want to use the SIN
<br>the SIN function and ignore the prologue (as far as intent), then they'll get what they programmed for.
<br>ThisExtending the precision is basic REXX programming and is a common practice that is soon adapted by most.
<br>The code acknowledges that more precision is needed than what is wanted, so the proglogue for the
<br>REXX example (on the main page) does that with the '''showdigs''' variable, as the section and REXX code comments clearly
<br>clearly state. -- [[User:Gerard Schildberger|Gerard Schildberger]] 21:23, 23 June 2012 (UTC)
<br><br>
 
-----
 
I did not modify anything!
Line 147 ⟶ 166:
</pre>
What I want is that the first call gives me the 30 correct digits.
This can be done by internally (in sin) raise the precision and return theresultthe result rounded to the desired precision.
 
Note that external funtionsfunctions don't inherit the caller's precision,
so having an extra (optional) argument p is an option.
Also the possiblitypossibility of x in sin(x) is radians or degrees is a useful extension implemented in the ooRexx function package.
--[[User:Walterpachl|Walterpachl]] 07:13, 23 June 2012 (UTC)
 
----
 
To not only ask for solutions, here is my version of sin according to my specs:
SIN: procedure
Line 204 ⟶ 224:
'028410270193852110555964462294895493038196'
--[[User:Walterpachl|Walterpachl]] 18:08, 23 June 2012 (UTC)
 
-----
 
The REXX program example on the main page was modeled after the PL/I and Fortran languages in that the (trig) function this is called is named by want the argument is specified as, that is, degrees or radians; radians being the default or "simple" or "pure" name, the degree version usually has a '''D''' appended to the function name. Once you make the programmer specify the type of argument for the none-default, there's more documentation involved and error checking.
<br>The REXX philosophy would be to take (in the above case) the 2nd argument and just use the first character as being significant (as the '''strip''', '''arg''', '''date''', '''time''', '''datatype''', '''verify''', '''trace''', and other BIFs do).
<br>So one could code: ''y=sin(z,'degrees')'' for instance.
<br>Also, the aforementioned BIFs also accept the option in lower and mixed case, not just uppercase.
<br>The nice thing about allowing the programmer to specify the units is that other units can be added besides degrees, '''grads''' (and it variant spellings) and '''mils'''. -- [[User:Gerard Schildberger|Gerard Schildberger]] 22:18, 23 June 2012 (UTC)
<br><br>For those that are interested:
<br>
<br>A '''grad''' is 16 '''mils'''.
<br>A '''grad''' is about 1/51.5 '''radians'''.
<br>A '''grad''' is 9/10 of a '''degree'''.
<br>A '''degree''' is 9/10 of a '''mil'''.
<br>
<br>There are 2pi radians in a circle.
<br>There are 360 degrees in a circle.
<br>There are 400 grads in a circle.
<br>There are 6,400 mils in a circle.
<br><br> -- [[User:Gerard Schildberger|Gerard Schildberger]] 23:50, 23 June 2012 (UTC)
<br>
----
While my 'precise sin' function above was triggered by the task 'Trigonometric Functions'
it has no further relationship to the cited task.
What I wanted was that this little program shows 30 correct digits
(the value to be tested for being the 'real' value of sin(0.1) rounded to 30 digits)
/* REXX */
Numeric Digits 30
Say sin(0.1) /* if 'my' sin is included an internal procedure */
Say sin(0.1,,30) /* if it is used as external procedure */
 
--[[User:Walterpachl|Walterpachl]] 07:51, 24 June 2012 (UTC)
 
: I don't understand, if you're discussing something that has no further relationship to the cited task, then why complain out the REXX example in the cited task? It isn't fair nor appropriate to use a subroutine taken out of context (i.e., not use the proglogue). Please re-read the REXX section (especially the boxed comments). -- [[User:Gerard Schildberger|Gerard Schildberger]] 19:49, 24 June 2012 (UTC)
 
: I went back and put the appropriate REXX header section comments in a box so it could be more easily read ''and'' catch one's attention. I don't know how to make it any more plainer or clearer than that. If one follows ''either'' of the two suggested techniques to accommodate the wanting of more accuracy, then all of the REXX example subroutines on the main page perform perfectly well with ''either'' technique and return precise results. To reiterate, if you want 30 "precise" digits, then specify '''numeric digits 40'''. -- [[User:Gerard Schildberger|Gerard Schildberger]] 19:49, 24 June 2012 (UTC)
 
 
== another thought on SIN ==
 
Thanks to Paul K.: &nbsp; &nbsp; "Mathematical puns are the first sine of madness.”
 
-- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 08:53, 13 May 2020 (UTC)
 
== Padé Approximants. ==
 
Please see the commentary at [[Trigonometric functions#Quackery]].
 
You are invited to offer your expertise and thoughts on the use and applicability of Padé Approximants to this and other tasks.
 
--[[User:GordonCharlton|GordonCharlton]] ([[User talk:GordonCharlton|talk]]) 22:19, 14 July 2021 (UTC)
1,462

edits