Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,85 @@
|
|||
-- for I/O
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
|
||||
|
||||
-- for estimating the maximum width of a column
|
||||
with Ada.Numerics.Generic_Elementary_Functions;
|
||||
|
||||
procedure PascalMatrix is
|
||||
|
||||
type Matrix is array (Positive range <>, Positive range <>) of Natural;
|
||||
|
||||
-- instantiate Generic_Elementary_Functions for Float type
|
||||
package Math is new Ada.Numerics.Generic_Elementary_Functions(Float_Type => Float);
|
||||
use Math;
|
||||
|
||||
procedure Print(m: in Matrix) is
|
||||
-- determine the maximum width of a column
|
||||
w: Float := Log(Float(m'Length(1)**(m'Length(1)/2)), 10.0);
|
||||
width: Positive := Natural(Float'Ceiling(w)) + 1;
|
||||
begin
|
||||
for i in m'First(1)..m'Last(1) loop
|
||||
Put("( ");
|
||||
for j in m'First(2)..m'Last(2) loop
|
||||
Put(m(i,j), width);
|
||||
end loop;
|
||||
Put(" )"); New_Line(1);
|
||||
end loop;
|
||||
end Print;
|
||||
|
||||
function Upper_Triangular(n: in Positive) return Matrix is
|
||||
result: Matrix(1..n, 1..n) := (
|
||||
1 => ( others => 1 ),
|
||||
others => ( others => 0 )
|
||||
);
|
||||
begin
|
||||
for i in 2..n loop
|
||||
result(i,i) := 1;
|
||||
for j in i+1..n loop
|
||||
result(i,j) := result(i,j-1) + result(i-1,j-1);
|
||||
end loop;
|
||||
end loop;
|
||||
return result;
|
||||
end Upper_Triangular;
|
||||
|
||||
function Lower_Triangular(n: in Positive) return Matrix is
|
||||
result: Matrix(1..n, 1..n) := (
|
||||
others => ( 1 => 1, others => 0 )
|
||||
);
|
||||
begin
|
||||
for i in 2..n loop
|
||||
result(i,i) := 1;
|
||||
for j in i+1..n loop
|
||||
result(j,i) := result(j-1,i) + result(j-1,i-1);
|
||||
end loop;
|
||||
end loop;
|
||||
return result;
|
||||
end Lower_Triangular;
|
||||
|
||||
function Symmetric(n: in Positive) return Matrix is
|
||||
result: Matrix(1..n, 1..n) := (
|
||||
1 => ( others => 1 ),
|
||||
others => ( 1 => 1, others => 0 )
|
||||
);
|
||||
begin
|
||||
for i in 2..n loop
|
||||
for j in 2..n loop
|
||||
result(i,j) := result(i,j-1) + result(i-1,j);
|
||||
end loop;
|
||||
end loop;
|
||||
return result;
|
||||
end Symmetric;
|
||||
|
||||
n: Positive;
|
||||
|
||||
begin
|
||||
Put("What dimension Pascal matrix would you like? ");
|
||||
Get(n);
|
||||
Put("Upper triangular:"); New_Line(1);
|
||||
Print(Upper_Triangular(n));
|
||||
Put("Lower triangular:"); New_Line(1);
|
||||
Print(Lower_Triangular(n));
|
||||
Put("Symmetric:"); New_Line(1);
|
||||
Print(Symmetric(n));
|
||||
end PascalMatrix;
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
require "matrix"
|
||||
local int = require "int"
|
||||
|
||||
local function pascal_upper_triangular(n)
|
||||
local m = {}
|
||||
for i = 1, n do
|
||||
m[i] = {}
|
||||
for j = 1, n do m[i][j] = (j >= i) ? int.binomial(j - 1, i - 1) : 0 end
|
||||
end
|
||||
return matrix.from(m)
|
||||
end
|
||||
|
||||
local function pascal_symmetric(n)
|
||||
local m = {}
|
||||
for i = 1, n do
|
||||
m[i] = {}
|
||||
for j = 1, n do m[i][j] = int.binomial(i + j - 2, i - 1) end
|
||||
end
|
||||
return matrix.from(m)
|
||||
end
|
||||
|
||||
local function pascal_lower_triangular(n)
|
||||
return pascal_symmetric(n):cholesky()
|
||||
end
|
||||
|
||||
local n = 5
|
||||
print("Pascal upper-triangular matrix:")
|
||||
print(pascal_upper_triangular(n))
|
||||
print("\nPascal lower-triangular matrix:")
|
||||
print(pascal_lower_triangular(n):format("%d"))
|
||||
print("\nPascal symmetric matrix:")
|
||||
print(pascal_symmetric(n))
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# Pascal's approach.
|
||||
G! ← ⍥(˜⊂^0⊸⊣)-1⧻⊸⊢
|
||||
⍉G!(↘¯1⬚0⧈+)⬚0˜↯[1]⊂1 5
|
||||
G!(↘¯1⬚0⧈+)⬚0˜↯[1]⊂1 5
|
||||
G!(\+)˜↯1⊂1 5
|
||||
|
||||
# Combinatorial approach.
|
||||
T ← ⧅>
|
||||
˙⊞T⇡5
|
||||
⍉˙⊞T⇡5
|
||||
≡≡T⍉↯[⟜∘]⟜⇡ ⟜(˙⊞+⇡)5
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
Function pascal_upper(i,j)
|
||||
WScript.StdOut.Write "Pascal Upper"
|
||||
WScript.StdOut.WriteLine
|
||||
For l = i To j
|
||||
For m = i To j
|
||||
If l <= m Then
|
||||
WScript.StdOut.Write binomial(m,l) & vbTab
|
||||
Else
|
||||
WScript.StdOut.Write 0 & vbTab
|
||||
End If
|
||||
Next
|
||||
WScript.StdOut.WriteLine
|
||||
Next
|
||||
WScript.StdOut.WriteLine
|
||||
End Function
|
||||
|
||||
Function pascal_lower(i,j)
|
||||
WScript.StdOut.Write "Pascal Lower"
|
||||
WScript.StdOut.WriteLine
|
||||
For l = i To j
|
||||
For m = i To j
|
||||
If l >= m Then
|
||||
WScript.StdOut.Write binomial(l,m) & vbTab
|
||||
Else
|
||||
WScript.StdOut.Write 0 & vbTab
|
||||
End If
|
||||
Next
|
||||
WScript.StdOut.WriteLine
|
||||
Next
|
||||
WScript.StdOut.WriteLine
|
||||
End Function
|
||||
|
||||
Function pascal_symmetric(i,j)
|
||||
WScript.StdOut.Write "Pascal Symmetric"
|
||||
WScript.StdOut.WriteLine
|
||||
For l = i To j
|
||||
For m = i To j
|
||||
WScript.StdOut.Write binomial(l+m,m) & vbTab
|
||||
Next
|
||||
WScript.StdOut.WriteLine
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function binomial(n,k)
|
||||
binomial = factorial(n)/(factorial(n-k)*factorial(k))
|
||||
End Function
|
||||
|
||||
Function factorial(n)
|
||||
If n = 0 Then
|
||||
factorial = 1
|
||||
Else
|
||||
For i = n To 1 Step -1
|
||||
If i = n Then
|
||||
factorial = n
|
||||
Else
|
||||
factorial = factorial * i
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End Function
|
||||
|
||||
'Test driving
|
||||
Call pascal_upper(0,4)
|
||||
Call pascal_lower(0,4)
|
||||
Call pascal_symmetric(0,4)
|
||||
Loading…
Add table
Add a link
Reference in a new issue