Power

From NARS2000
Revision as of 01:57, 18 December 2019 by WikiSysop (talk | contribs)
Jump to navigationJump to search
Z←{L} fg R successively applies the function f (or, if there is a Left argument, the function L∘f) to R until the expression Zn g Zn-1 returns a singleton 1. Zn and Zn-1 represent two consecutive applications of f (or L∘f) to R where Z0←R and Znf Zn-1 (or Zn←L∘f Zn-1).
Z←{L} fb R for non-negative integer scalar b, successively applies the function f (or, if there is a Left argument, the function L∘f) to R, b number of times;
for a negative integer scalar b, successively applies the inverse of the function f (or, if there is a Left argument, the inverse to the function L∘f), |b number of times
L and R are arbitrary arrays.
In the first case, Zn g Zn-1 must return a Boolean-valued singleton; otherwise a DOMAIN ERROR is signaled.
In the second case, b must be an integer scalar, otherwise a DOMAIN ERROR is signaled.


For example,

      sqrt←{{0.5×⍵+⍺÷⍵}⍣=⍨⍵} ⍝ Calculate square root using Newton's method
      sqrt 2
1.414213562373095
      fib←{⍵,+/¯2↑⍵} ⍝ Calculate a Fibonacci sequence
      fib⍣15 ⊢ 1 1
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 
      pow←{⍵=0:,1 ⋄ ⍺+⍡×⍣(⍵-1) ⍺} ⍝ Raise a polynomial to a non-negative integer power
      1 ¯1 pow 5
1 ¯5 10 ¯10 5 ¯1
      phi←1+∘÷⍣=1 ⍝ Calculate the Golden Ratio
      phi
1.618033988749894

Inverses

When the right operand to the Power Operator is a negative integer scalar, the inverse of the function left operand is applied to the right argument. At the moment, only a few inverse functions are available as follows:

Function Meaning of Inverse
L⊥⍣¯1 R (N⍴L)⊤R for N sufficiently large to display all digits of R
⊥⍣¯1 R 2⊥⍣¯1 R
L⊤⍣¯1 R L⊥R
×/⍣¯1 R πR, that is, factor R
π⍣¯1 R ×/R, that is, multiply together the factors
+\⍣¯1 R ¯2-\R
¯2-\⍣¯1 R +\R
+∘÷/⍣¯1 R Display the Continued Fraction expansion of R to at most ⎕PP terms
L+∘÷/⍣¯1 R Display the Continued Fraction expansion of R to at most L terms

For example,

      10⊥⍣¯1 1234567890
1 2 3 4 5 6 7 8 9 0
      ⊥⍣¯1 19
1 0 0 1 1
      10 10 10⊤⍣¯1 2 3 4
234
      ×/⍣¯1 130
2 5 13 
      π⍣¯1 2 5 13
130
      +\⍣¯1 ⍳4
1 1 1 1 
      ¯2-\⍣¯1 4⍴1
1 2 3 4
      +∘÷/⍣¯1 449r303
1 2 13 3 1 2
      +∘÷/+∘÷/⍣¯1 449r303
449r303
      15 +∘÷/⍣¯1 ○1x
3 7 15 1 292 1 1 1 2 1 3 1 14 2 1
      +∘÷\3 7 15 1x     ⍝ Convergents to Pi
3 22r7 333r106 355r113 
      25 +∘÷/⍣¯1 *1x
2 1 2 1 1 4 1 1 6 1 1 8 1 1 10 1 1 12 1 1 14 1 1 16 1