WeixiangYan/CodeTransOcean huggingface dataset:
Task: Create a file

C: #include <stdio.h>

int main() {
  FILE *fh = fopen("output.txt", "w");
  fclose(fh);

  return 0;
}










Fortran: PROGRAM CREATION
OPEN (UNIT=5, FILE="output.txt", STATUS="NEW")   
CLOSE (UNIT=5)
OPEN (UNIT=5, FILE="/output.txt", STATUS="NEW")  
CLOSE (UNIT=5)



call system("mkdir docs/")
call system("mkdir ~/docs/")

END PROGRAM
Task: Create a file





Java: import java.io.*;
public class CreateFileTest {
	public static void main(String args[]) {
		try {
			new File("output.txt").createNewFile();
			new File(File.separator + "output.txt").createNewFile();
			new File("docs").mkdir();
			new File(File.separator + "docs").mkdir();
		} catch (IOException e) {
			System.err.println(e.getMessage());
		}
	}
}






Fortran: PROGRAM CREATION
OPEN (UNIT=5, FILE="output.txt", STATUS="NEW")   
CLOSE (UNIT=5)
OPEN (UNIT=5, FILE="/output.txt", STATUS="NEW")  
CLOSE (UNIT=5)



call system("mkdir docs/")
call system("mkdir ~/docs/")

END PROGRAM
Task: Create a file







Python: import os
for directory in ['/', './']:
  open(directory + 'output.txt', 'w').close()  
  os.mkdir(directory + 'docs')                 




Fortran: PROGRAM CREATION
OPEN (UNIT=5, FILE="output.txt", STATUS="NEW")   
CLOSE (UNIT=5)
OPEN (UNIT=5, FILE="/output.txt", STATUS="NEW")  
CLOSE (UNIT=5)



call system("mkdir docs/")
call system("mkdir ~/docs/")

END PROGRAM
Task: Create a file








VB: Public Sub create_file()
    Dim FileNumber As Integer
    FileNumber = FreeFile
    MkDir "docs"
    Open "docs\output.txt" For Output As #FreeFile
    Close #FreeFile
    MkDir "C:\docs"
    Open "C:\docs\output.txt" For Output As #FreeFile
    Close #FreeFile
End Sub



Fortran: PROGRAM CREATION
OPEN (UNIT=5, FILE="output.txt", STATUS="NEW")   
CLOSE (UNIT=5)
OPEN (UNIT=5, FILE="/output.txt", STATUS="NEW")  
CLOSE (UNIT=5)



call system("mkdir docs/")
call system("mkdir ~/docs/")

END PROGRAM
Task: Create a file






PHP: <?php
touch('output.txt');
mkdir('docs');
touch('/output.txt');
mkdir('/docs');
?>





Fortran: PROGRAM CREATION
OPEN (UNIT=5, FILE="output.txt", STATUS="NEW")   
CLOSE (UNIT=5)
OPEN (UNIT=5, FILE="/output.txt", STATUS="NEW")  
CLOSE (UNIT=5)



call system("mkdir docs/")
call system("mkdir ~/docs/")

END PROGRAM
Task: Create a file

C: #include <stdio.h>

int main() {
  FILE *fh = fopen("output.txt", "w");
  fclose(fh);

  return 0;
}









COBOL:        identification division.
       program-id. create-a-file.

       data division.
       working-storage section.
       01 skip                 pic 9 value 2.
       01 file-name.
          05 value "/output.txt".
       01 dir-name.
          05 value "/docs".
       01 file-handle          usage binary-long.

       procedure division.
       files-main.

      
       perform create-file-and-dir

      
       move 1 to skip
       perform create-file-and-dir

       goback.

       create-file-and-dir.
      
       call "CBL_CREATE_FILE" using file-name(skip:) 3 0 0 file-handle
       if return-code not equal 0 then
           display "error: CBL_CREATE_FILE " file-name(skip:) ": "
                   file-handle ", " return-code upon syserr
       end-if

      
       call "CBL_CREATE_DIR" using dir-name(skip:)
       if return-code not equal 0 then
           display "error: CBL_CREATE_DIR " dir-name(skip:) ": "
                   return-code upon syserr
       end-if
       .

       end program create-a-file.
Task: Create a file



C#: using System;
using System.IO;

class Program {
    static void Main(string[] args) {
        File.Create("output.txt");
        File.Create(@"\output.txt");

        Directory.CreateDirectory("docs");
        Directory.CreateDirectory(@"\docs");
    }
}







COBOL:        identification division.
       program-id. create-a-file.

       data division.
       working-storage section.
       01 skip                 pic 9 value 2.
       01 file-name.
          05 value "/output.txt".
       01 dir-name.
          05 value "/docs".
       01 file-handle          usage binary-long.

       procedure division.
       files-main.

      
       perform create-file-and-dir

      
       move 1 to skip
       perform create-file-and-dir

       goback.

       create-file-and-dir.
      
       call "CBL_CREATE_FILE" using file-name(skip:) 3 0 0 file-handle
       if return-code not equal 0 then
           display "error: CBL_CREATE_FILE " file-name(skip:) ": "
                   file-handle ", " return-code upon syserr
       end-if

      
       call "CBL_CREATE_DIR" using dir-name(skip:)
       if return-code not equal 0 then
           display "error: CBL_CREATE_DIR " dir-name(skip:) ": "
                   return-code upon syserr
       end-if
       .

       end program create-a-file.
Task: Create a file


C++: #include <direct.h>
#include <fstream>

int main() {
    std::fstream f("output.txt", std::ios::out);
    f.close();
    f.open("/output.txt", std::ios::out);
    f.close();

    _mkdir("docs");
    _mkdir("/docs");

    return 0;
}








COBOL:        identification division.
       program-id. create-a-file.

       data division.
       working-storage section.
       01 skip                 pic 9 value 2.
       01 file-name.
          05 value "/output.txt".
       01 dir-name.
          05 value "/docs".
       01 file-handle          usage binary-long.

       procedure division.
       files-main.

      
       perform create-file-and-dir

      
       move 1 to skip
       perform create-file-and-dir

       goback.

       create-file-and-dir.
      
       call "CBL_CREATE_FILE" using file-name(skip:) 3 0 0 file-handle
       if return-code not equal 0 then
           display "error: CBL_CREATE_FILE " file-name(skip:) ": "
                   file-handle ", " return-code upon syserr
       end-if

      
       call "CBL_CREATE_DIR" using dir-name(skip:)
       if return-code not equal 0 then
           display "error: CBL_CREATE_DIR " dir-name(skip:) ": "
                   return-code upon syserr
       end-if
       .

       end program create-a-file.
Task: Create a file





Java: import java.io.*;
public class CreateFileTest {
	public static void main(String args[]) {
		try {
			new File("output.txt").createNewFile();
			new File(File.separator + "output.txt").createNewFile();
			new File("docs").mkdir();
			new File(File.separator + "docs").mkdir();
		} catch (IOException e) {
			System.err.println(e.getMessage());
		}
	}
}





COBOL:        identification division.
       program-id. create-a-file.

       data division.
       working-storage section.
       01 skip                 pic 9 value 2.
       01 file-name.
          05 value "/output.txt".
       01 dir-name.
          05 value "/docs".
       01 file-handle          usage binary-long.

       procedure division.
       files-main.

      
       perform create-file-and-dir

      
       move 1 to skip
       perform create-file-and-dir

       goback.

       create-file-and-dir.
      
       call "CBL_CREATE_FILE" using file-name(skip:) 3 0 0 file-handle
       if return-code not equal 0 then
           display "error: CBL_CREATE_FILE " file-name(skip:) ": "
                   file-handle ", " return-code upon syserr
       end-if

      
       call "CBL_CREATE_DIR" using dir-name(skip:)
       if return-code not equal 0 then
           display "error: CBL_CREATE_DIR " dir-name(skip:) ": "
                   return-code upon syserr
       end-if
       .

       end program create-a-file.
Task: Create a file







Python: import os
for directory in ['/', './']:
  open(directory + 'output.txt', 'w').close()  
  os.mkdir(directory + 'docs')                 



COBOL:        identification division.
       program-id. create-a-file.

       data division.
       working-storage section.
       01 skip                 pic 9 value 2.
       01 file-name.
          05 value "/output.txt".
       01 dir-name.
          05 value "/docs".
       01 file-handle          usage binary-long.

       procedure division.
       files-main.

      
       perform create-file-and-dir

      
       move 1 to skip
       perform create-file-and-dir

       goback.

       create-file-and-dir.
      
       call "CBL_CREATE_FILE" using file-name(skip:) 3 0 0 file-handle
       if return-code not equal 0 then
           display "error: CBL_CREATE_FILE " file-name(skip:) ": "
                   file-handle ", " return-code upon syserr
       end-if

      
       call "CBL_CREATE_DIR" using dir-name(skip:)
       if return-code not equal 0 then
           display "error: CBL_CREATE_DIR " dir-name(skip:) ": "
                   return-code upon syserr
       end-if
       .

       end program create-a-file.
Task: Create a file








VB: Public Sub create_file()
    Dim FileNumber As Integer
    FileNumber = FreeFile
    MkDir "docs"
    Open "docs\output.txt" For Output As #FreeFile
    Close #FreeFile
    MkDir "C:\docs"
    Open "C:\docs\output.txt" For Output As #FreeFile
    Close #FreeFile
End Sub


COBOL:        identification division.
       program-id. create-a-file.

       data division.
       working-storage section.
       01 skip                 pic 9 value 2.
       01 file-name.
          05 value "/output.txt".
       01 dir-name.
          05 value "/docs".
       01 file-handle          usage binary-long.

       procedure division.
       files-main.

      
       perform create-file-and-dir

      
       move 1 to skip
       perform create-file-and-dir

       goback.

       create-file-and-dir.
      
       call "CBL_CREATE_FILE" using file-name(skip:) 3 0 0 file-handle
       if return-code not equal 0 then
           display "error: CBL_CREATE_FILE " file-name(skip:) ": "
                   file-handle ", " return-code upon syserr
       end-if

      
       call "CBL_CREATE_DIR" using dir-name(skip:)
       if return-code not equal 0 then
           display "error: CBL_CREATE_DIR " dir-name(skip:) ": "
                   return-code upon syserr
       end-if
       .

       end program create-a-file.
Task: Create a file




Go: package main

import (
    "fmt"
    "os"
)

func createFile(fn string) {
    f, err := os.Create(fn)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("file", fn, "created!")
    f.Close()
}

func createDir(dn string) {
    err := os.Mkdir(dn, 0666)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("directory", dn, "created!")
}

func main() {
    createFile("input.txt")
    createFile("/input.txt")
    createDir("docs")
    createDir("/docs")
}






COBOL:        identification division.
       program-id. create-a-file.

       data division.
       working-storage section.
       01 skip                 pic 9 value 2.
       01 file-name.
          05 value "/output.txt".
       01 dir-name.
          05 value "/docs".
       01 file-handle          usage binary-long.

       procedure division.
       files-main.

      
       perform create-file-and-dir

      
       move 1 to skip
       perform create-file-and-dir

       goback.

       create-file-and-dir.
      
       call "CBL_CREATE_FILE" using file-name(skip:) 3 0 0 file-handle
       if return-code not equal 0 then
           display "error: CBL_CREATE_FILE " file-name(skip:) ": "
                   file-handle ", " return-code upon syserr
       end-if

      
       call "CBL_CREATE_DIR" using dir-name(skip:)
       if return-code not equal 0 then
           display "error: CBL_CREATE_DIR " dir-name(skip:) ": "
                   return-code upon syserr
       end-if
       .

       end program create-a-file.
Task: Create a file






PHP: <?php
touch('output.txt');
mkdir('docs');
touch('/output.txt');
mkdir('/docs');
?>
Task: Create a file






PHP: <?php
touch('output.txt');
mkdir('docs');
touch('/output.txt');
mkdir('/docs');
?>






Ada: with Ada.Streams.Stream_IO, Ada.Directories;
use  Ada.Streams.Stream_IO, Ada.Directories;

procedure File_Creation is
   
   File_Handle : File_Type;
   
begin
   
   Create (File_Handle, Out_File, "output.txt");
   Close (File_Handle);
   Create_Directory("docs");
   Create (File_Handle, Out_File, "/output.txt");
   Close (File_Handle);
   Create_Directory("/docs");
   
end File_Creation;
Task: Create a file






PHP: <?php
touch('output.txt');
mkdir('docs');
touch('/output.txt');
mkdir('/docs');
?>




COBOL:        identification division.
       program-id. create-a-file.

       data division.
       working-storage section.
       01 skip                 pic 9 value 2.
       01 file-name.
          05 value "/output.txt".
       01 dir-name.
          05 value "/docs".
       01 file-handle          usage binary-long.

       procedure division.
       files-main.

      
       perform create-file-and-dir

      
       move 1 to skip
       perform create-file-and-dir

       goback.

       create-file-and-dir.
      
       call "CBL_CREATE_FILE" using file-name(skip:) 3 0 0 file-handle
       if return-code not equal 0 then
           display "error: CBL_CREATE_FILE " file-name(skip:) ": "
                   file-handle ", " return-code upon syserr
       end-if

      
       call "CBL_CREATE_DIR" using dir-name(skip:)
       if return-code not equal 0 then
           display "error: CBL_CREATE_DIR " dir-name(skip:) ": "
                   return-code upon syserr
       end-if
       .

       end program create-a-file.
Task: Cholesky decomposition



C#: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cholesky
{
    class Program
    {
        
        
        
        
        static void Main(string[] args)
        {
            double[,] test1 = new double[,]
            {
                {25, 15, -5},
                {15, 18, 0},
                {-5, 0, 11},
            };

            double[,] test2 = new double[,]
            {
                {18, 22, 54, 42},
                {22, 70, 86, 62},
                {54, 86, 174, 134},
                {42, 62, 134, 106},
            };

            double[,] chol1 = Cholesky(test1);
            double[,] chol2 = Cholesky(test2);

            Console.WriteLine("Test 1: ");
            Print(test1);
            Console.WriteLine("");
            Console.WriteLine("Lower Cholesky 1: ");
            Print(chol1);
            Console.WriteLine("");
            Console.WriteLine("Test 2: ");
            Print(test2);
            Console.WriteLine("");
            Console.WriteLine("Lower Cholesky 2: ");
            Print(chol2);

        }

        public static void Print(double[,] a)
        {
            int n = (int)Math.Sqrt(a.Length);

            StringBuilder sb = new StringBuilder();
            for (int r = 0; r < n; r++)
            {
                string s = "";
                for (int c = 0; c < n; c++)
                {
                    s += a[r, c].ToString("f5").PadLeft(9) + ",";
                }
                sb.AppendLine(s);
            }

            Console.WriteLine(sb.ToString());
        }

        
        
        
        
        
        
        
        
        public static double[,] Cholesky(double[,] a)
        {
            int n = (int)Math.Sqrt(a.Length);

            double[,] ret = new double[n, n];
            for (int r = 0; r < n; r++)
                for (int c = 0; c <= r; c++)
                {
                    if (c == r)
                    {
                        double sum = 0;
                        for (int j = 0; j < c; j++)
                        {
                            sum += ret[c, j] * ret[c, j];
                        }
                        ret[c, c] = Math.Sqrt(a[c, c] - sum);
                    }
                    else
                    {
                        double sum = 0;
                        for (int j = 0; j < c; j++)
                            sum += ret[r, j] * ret[c, j];
                        ret[r, c] = 1.0 / ret[c, c] * (a[r, c] - sum);
                    }
                }

            return ret;
        }
    }
}









Ada: with Ada.Numerics.Generic_Real_Arrays;
generic
   with package Matrix is new Ada.Numerics.Generic_Real_Arrays (<>);
package Decomposition is

   
   procedure Decompose (A : Matrix.Real_Matrix; L : out Matrix.Real_Matrix);

end Decomposition;
Task: Cholesky decomposition

C: #include <stdio.h>
#include <stdlib.h>
#include <math.h>

double *cholesky(double *A, int n) {
    double *L = (double*)calloc(n * n, sizeof(double));
    if (L == NULL)
        exit(EXIT_FAILURE);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < (i+1); j++) {
            double s = 0;
            for (int k = 0; k < j; k++)
                s += L[i * n + k] * L[j * n + k];
            L[i * n + j] = (i == j) ?
                           sqrt(A[i * n + i] - s) :
                           (1.0 / L[j * n + j] * (A[i * n + j] - s));
        }

    return L;
}

void show_matrix(double *A, int n) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            printf("%2.5f ", A[i * n + j]);
        printf("\n");
    }
}

int main() {
    int n = 3;
    double m1[] = {25, 15, -5,
                   15, 18,  0,
                   -5,  0, 11};
    double *c1 = cholesky(m1, n);
    show_matrix(c1, n);
    printf("\n");
    free(c1);

    n = 4;
    double m2[] = {18, 22,  54,  42,
                   22, 70,  86,  62,
                   54, 86, 174, 134,
                   42, 62, 134, 106};
    double *c2 = cholesky(m2, n);
    show_matrix(c2, n);
    free(c2);

    return 0;
}











Ada: with Ada.Numerics.Generic_Real_Arrays;
generic
   with package Matrix is new Ada.Numerics.Generic_Real_Arrays (<>);
package Decomposition is

   
   procedure Decompose (A : Matrix.Real_Matrix; L : out Matrix.Real_Matrix);

end Decomposition;
Task: Cholesky decomposition




Go: package main

import (
    "fmt"
    "math"
)




type symmetric struct {
    order int
    ele   []float64
}

type lower struct {
    order int
    ele   []float64
}



func (s *symmetric) print() {
    const eleFmt = "%10.5f "
    row, diag := 1, 0
    for i, e := range s.ele {
        fmt.Printf(eleFmt, e)
        if i == diag {
            for j, col := diag+row, row; col < s.order; j += col {
                fmt.Printf(eleFmt, s.ele[j])
                col++
            }
            fmt.Println()
            row++
            diag += row
        }
    }
}



func (l *lower) print() {
    const eleFmt = "%10.5f "
    row, diag := 1, 0
    for i, e := range l.ele {
        fmt.Printf(eleFmt, e)
        if i == diag {
            for j := row; j < l.order; j++ {
                fmt.Printf(eleFmt, 0.)
            }
            fmt.Println()
            row++
            diag += row
        }
    }
}



func (a *symmetric) choleskyLower() *lower {
    l := &lower{a.order, make([]float64, len(a.ele))}
    row, col := 1, 1
    dr := 0 
    dc := 0 
    for i, e := range a.ele {
        if i < dr {
            d := (e - l.ele[i]) / l.ele[dc]
            l.ele[i] = d
            ci, cx := col, dc
            for j := i + 1; j <= dr; j++ {
                cx += ci
                ci++
                l.ele[j] += d * l.ele[cx]
            }
            col++
            dc += col
        } else {
            l.ele[i] = math.Sqrt(e - l.ele[i])
            row++
            dr += row
            col = 1
            dc = 0
        }
    }
    return l
}

func main() {
    demo(&symmetric{3, []float64{
        25,
        15, 18,
        -5, 0, 11}})
    demo(&symmetric{4, []float64{
        18,
        22, 70,
        54, 86, 174,
        42, 62, 134, 106}})
}

func demo(a *symmetric) {
    fmt.Println("A:")
    a.print()
    fmt.Println("L:")
    a.choleskyLower().print()
}








Ada: with Ada.Numerics.Generic_Real_Arrays;
generic
   with package Matrix is new Ada.Numerics.Generic_Real_Arrays (<>);
package Decomposition is

   
   procedure Decompose (A : Matrix.Real_Matrix; L : out Matrix.Real_Matrix);

end Decomposition;
Task: Cholesky decomposition





Java: import java.util.Arrays;

public class Cholesky {
	public static double[][] chol(double[][] a){
		int m = a.length;
		double[][] l = new double[m][m]; 
		for(int i = 0; i< m;i++){
			for(int k = 0; k < (i+1); k++){
				double sum = 0;
				for(int j = 0; j < k; j++){
					sum += l[i][j] * l[k][j];
				}
				l[i][k] = (i == k) ? Math.sqrt(a[i][i] - sum) :
					(1.0 / l[k][k] * (a[i][k] - sum));
			}
		}
		return l;
	}
	
	public static void main(String[] args){
		double[][] test1 = {{25, 15, -5},
							{15, 18, 0},
							{-5, 0, 11}};
		System.out.println(Arrays.deepToString(chol(test1)));
		double[][] test2 = {{18, 22, 54, 42},
							{22, 70, 86, 62},
							{54, 86, 174, 134},
							{42, 62, 134, 106}};
		System.out.println(Arrays.deepToString(chol(test2)));
	}
}







Ada: with Ada.Numerics.Generic_Real_Arrays;
generic
   with package Matrix is new Ada.Numerics.Generic_Real_Arrays (<>);
package Decomposition is

   
   procedure Decompose (A : Matrix.Real_Matrix; L : out Matrix.Real_Matrix);

end Decomposition;
Task: Cholesky decomposition







Python: from __future__ import print_function

from pprint import pprint
from math import sqrt


def cholesky(A):
    L = [[0.0] * len(A) for _ in xrange(len(A))]
    for i in xrange(len(A)):
        for j in xrange(i+1):
            s = sum(L[i][k] * L[j][k] for k in xrange(j))
            L[i][j] = sqrt(A[i][i] - s) if (i == j) else \
                      (1.0 / L[j][j] * (A[i][j] - s))
    return L

if __name__ == "__main__":
    m1 = [[25, 15, -5],
          [15, 18,  0],
          [-5,  0, 11]]
    pprint(cholesky(m1))
    print()
    
    m2 = [[18, 22,  54,  42],
          [22, 70,  86,  62],
          [54, 86, 174, 134],
          [42, 62, 134, 106]]
    pprint(cholesky(m2), width=120)





Ada: with Ada.Numerics.Generic_Real_Arrays;
generic
   with package Matrix is new Ada.Numerics.Generic_Real_Arrays (<>);
package Decomposition is

   
   procedure Decompose (A : Matrix.Real_Matrix; L : out Matrix.Real_Matrix);

end Decomposition;
Task: Cholesky decomposition








VB: Function Cholesky(Mat As Range) As Variant

Dim A() As Double, L() As Double, sum As Double, sum2 As Double
Dim m As Byte, i As Byte, j As Byte, k As Byte


    If Mat.Rows.Count <> Mat.Columns.Count Then
        MsgBox ("Correlation matrix is not square")
        Exit Function
    End If
    
    m = Mat.Rows.Count


    ReDim A(0 To m - 1, 0 To m - 1)
    ReDim L(0 To m - 1, 0 To m - 1)
    For i = 0 To m - 1
        For j = 0 To m - 1
            A(i, j) = Mat(i + 1, j + 1).Value2
            L(i, j) = 0
        Next j
    Next i


    Select Case m
        Case Is = 1
            L(0, 0) = Sqr(A(0, 0))
        
        Case Is = 2
            L(0, 0) = Sqr(A(0, 0))
            L(1, 0) = A(1, 0) / L(0, 0)
            L(1, 1) = Sqr(A(1, 1) - L(1, 0) * L(1, 0))
        
        Case Else
            L(0, 0) = Sqr(A(0, 0))
            L(1, 0) = A(1, 0) / L(0, 0)
            L(1, 1) = Sqr(A(1, 1) - L(1, 0) * L(1, 0))
            For i = 2 To m - 1
                sum2 = 0
                For k = 0 To i - 1
                    sum = 0
                    For j = 0 To k
                        sum = sum + L(i, j) * L(k, j)
                    Next j
                    L(i, k) = (A(i, k) - sum) / L(k, k)
                    sum2 = sum2 + L(i, k) * L(i, k)
                Next k
                L(i, i) = Sqr(A(i, i) - sum2)
            Next i
    End Select
    Cholesky = L
End Function




Ada: with Ada.Numerics.Generic_Real_Arrays;
generic
   with package Matrix is new Ada.Numerics.Generic_Real_Arrays (<>);
package Decomposition is

   
   procedure Decompose (A : Matrix.Real_Matrix; L : out Matrix.Real_Matrix);

end Decomposition;