Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Preserve the algorithm and functionality while converting the code from Ada to PHP.
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"); C...
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Translate this program into PHP but keep the logic exactly as in Arturo.
output: "output.txt" docs: "docs" write output "" write.directory docs ø write join.path ["/" output] "" write.directory join.path ["/" docs] ø
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Can you help me rewrite this code in PHP instead of AutoHotKey, keeping it the same logically?
FileAppend,,output.txt FileCreateDir, docs FileAppend,,c:\output.txt FileCreateDir, c:\docs
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Maintain the same structure and functionality when rewriting this code in PHP.
BEGIN { printf "" > "output.txt" close("output.txt") printf "" > "/output.txt" close("/output.txt") system("mkdir docs") system("mkdir /docs") }
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Can you help me rewrite this code in PHP instead of BBC_Basic, keeping it the same logically?
CLOSE #OPENOUT("output.txt") CLOSE #OPENOUT("\output.txt") *MKDIR docs *MKDIR \docs
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Write the same code in PHP as shown below in Common_Lisp.
(import '(java.io File)) (.createNewFile (new File "output.txt")) (.mkdir (new File "docs")) (.createNewFile (File. (str (File/separator) "output.txt"))) (.mkdir (File. (str (File/separator) "docs")))
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Write a version of this D function in PHP with identical behavior.
module fileio ; import std.stdio ; import std.path ; import std.file ; import std.stream ; string[] genName(string name){ string cwd = curdir ~ sep ; string root = sep ; name = std.path.getBaseName(name) ; return [cwd ~ name, root ~ name] ; } void Remove(string target){ if(exists(target)){ ...
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Rewrite the snippet below in PHP so it works the same as the original Delphi code.
program createFile; uses Classes, SysUtils; const filename = 'output.txt'; var cwdPath, fsPath: string; function CreateEmptyFile1: Boolean; var f: textfile; begin cwdPath := ExtractFilePath(ParamStr(0)) + '1_'+filename; AssignFile(f,cwdPath); Rewrite(f); Result := IOResult = 0; ...
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Can you help me rewrite this code in PHP instead of Elixir, keeping it the same logically?
File.open("output.txt", [:write]) File.open("/output.txt", [:write]) File.mkdir!("docs") File.mkdir!("/docs")
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Maintain the same structure and functionality when rewriting this code in PHP.
-module(new_file). -export([main/0]). main() -> ok = file:write_file( "output.txt", <<>> ), ok = file:make_dir( "docs" ), ok = file:write_file( filename:join(["/", "output.txt"]), <<>> ), ok = file:make_dir( filename:join(["/", "docs"]) ).
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Write a version of this F# function in PHP with identical behavior.
open System.IO [<EntryPoint>] let main argv = let fileName = "output.txt" let dirName = "docs" for path in ["."; "/"] do ignore (File.Create(Path.Combine(path, fileName))) ignore (Directory.CreateDirectory(Path.Combine(path, dirName))) 0
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Port the provided Factor code into PHP while preserving the original functionality.
USE: io.directories "output.txt" "/output.txt" [ touch-file ] bi@ "docs" "/docs" [ make-directory ] bi@
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Convert this Forth block to PHP, preserving its control flow and logic.
s" output.txt" w/o create-file throw drop s" /output.txt" w/o create-file throw drop
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Generate a PHP translation of this Fortran snippet without changing its computational steps.
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
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Produce a functionally identical PHP code for the snippet given in Groovy.
new File("output.txt").createNewFile() new File(File.separator + "output.txt").createNewFile() new File("docs").mkdir() new File(File.separator + "docs").mkdir()
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Can you help me rewrite this code in PHP instead of Haskell, keeping it the same logically?
import System.Directory createFile name = writeFile name "" main = do createFile "output.txt" createDirectory "docs" createFile "/output.txt" createDirectory "/docs"
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Transform the following J implementation into PHP, maintaining the same output and logic.
'' 1!:2 <'/output.txt' 1!:5 <'/docs'
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Rewrite the snippet below in PHP so it works the same as the original Julia code.
touch("output.txt") mkdir("docs") try touch("/output.txt") mkdir("/docs") catch e warn(e) end
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Ensure the translated PHP code behaves exactly like the original Lua snippet.
io.open("output.txt", "w"):close() io.open("\\output.txt", "w"):close()
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Keep all operations the same but rewrite the snippet in PHP.
SetDirectory@NotebookDirectory[]; t = OpenWrite["output.txt"] Close[t] s = OpenWrite[First@FileNameSplit[$InstallationDirectory] <> "\\output.txt"] Close[s] CreateDirectory["\\docs"] CreateDirectory[Directory[]<>"\\docs"]
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Write a version of this MATLAB function in PHP with identical behavior.
fid = fopen('output.txt','w'); fclose(fid); fid = fopen('/output.txt','w'); fclose(fid); mkdir('docs'); mkdir('/docs');
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Transform the following Nim implementation into PHP, maintaining the same output and logic.
import os open("output.txt", fmWrite).close() createDir("docs") open(DirSep & "output.txt", fmWrite).close() createDir(DirSep & "docs")
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Write the same code in PHP as shown below in OCaml.
# let oc = open_out "output.txt" in close_out oc;; - : unit = () # Unix.mkdir "docs" 0o750 ;; - : unit = ()
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Ensure the translated PHP code behaves exactly like the original Perl snippet.
use File::Spec::Functions qw(catfile rootdir); { open my $fh, '>', 'output.txt'; mkdir 'docs'; }; { open my $fh, '>', catfile rootdir, 'output.txt'; mkdir catfile rootdir, 'docs'; };
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Write a version of this PowerShell function in PHP with identical behavior.
New-Item output.txt -ItemType File New-Item \output.txt -ItemType File New-Item docs -ItemType Directory New-Item \docs -ItemType Directory
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Rewrite this program in PHP while keeping its functionality equivalent to the R version.
f <- file("output.txt", "w") close(f) f <- file("/output.txt", "w") close(f) success <- dir.create("docs") success <- dir.create("/docs")
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Generate an equivalent PHP version of this Racket code.
#lang racket (display-to-file "" "output.txt") (make-directory "docs") (display-to-file "" "/output.txt") (make-directory "/docs")
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Transform the following COBOL implementation into PHP, maintaining the same output and logic.
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. ...
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Rewrite this program in PHP while keeping its functionality equivalent to the REXX version.
options replace format comments java crossref symbols nobinary fName = ''; fName[0] = 2; fName[1] = '.' || File.separator || 'output.txt'; fName[2] = File.separator || 'output.txt' dName = ''; dName[0] = 2; dName[1] = '.' || File.separator || 'docs'; dName[2] = File.separator || 'docs' do loop i_ = 1 to fNam...
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Convert this Ruby block to PHP, preserving its control flow and logic.
File.write "output.txt", "" Dir.mkdir "docs" File.write "/output.txt", "" Dir.mkdir "/docs"
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Port the provided Scala code into PHP while preserving the original functionality.
import java.io.File fun main(args: Array<String>) { val filePaths = arrayOf("output.txt", "c:\\output.txt") val dirPaths = arrayOf("docs", "c:\\docs") var f: File for (path in filePaths) { f = File(path) if (f.createNewFile()) println("$path successfully created") ...
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Keep all operations the same but rewrite the snippet in PHP.
close [open output.txt w] close [open [file nativename /output.txt] w] file mkdir docs file mkdir [file nativename /docs]
<?php touch('output.txt'); mkdir('docs'); touch('/output.txt'); mkdir('/docs'); ?>
Convert this C++ block to Rust, preserving its control flow and logic.
#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; }
use std::io::{self, Write}; use std::fs::{DirBuilder, File}; use std::path::Path; use std::{process,fmt}; const FILE_NAME: &'static str = "output.txt"; const DIR_NAME : &'static str = "docs"; fn main() { create(".").and(create("/")) .unwrap_or_else(|e| error_handler(e,1)); } fn create<P>(root: P)...
Change the following Java code into Rust without altering its purpose.
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.pr...
use std::io::{self, Write}; use std::fs::{DirBuilder, File}; use std::path::Path; use std::{process,fmt}; const FILE_NAME: &'static str = "output.txt"; const DIR_NAME : &'static str = "docs"; fn main() { create(".").and(create("/")) .unwrap_or_else(|e| error_handler(e,1)); } fn create<P>(root: P)...
Write a version of this Go function in Rust with identical behavior.
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.Print...
use std::io::{self, Write}; use std::fs::{DirBuilder, File}; use std::path::Path; use std::{process,fmt}; const FILE_NAME: &'static str = "output.txt"; const DIR_NAME : &'static str = "docs"; fn main() { create(".").and(create("/")) .unwrap_or_else(|e| error_handler(e,1)); } fn create<P>(root: P)...
Write a version of this Rust function in Python with identical behavior.
use std::io::{self, Write}; use std::fs::{DirBuilder, File}; use std::path::Path; use std::{process,fmt}; const FILE_NAME: &'static str = "output.txt"; const DIR_NAME : &'static str = "docs"; fn main() { create(".").and(create("/")) .unwrap_or_else(|e| error_handler(e,1)); } fn create<P>(root: P)...
import os for directory in ['/', './']: open(directory + 'output.txt', 'w').close() os.mkdir(directory + 'docs')
Produce a functionally identical VB code for the snippet given in Rust.
use std::io::{self, Write}; use std::fs::{DirBuilder, File}; use std::path::Path; use std::{process,fmt}; const FILE_NAME: &'static str = "output.txt"; const DIR_NAME : &'static str = "docs"; fn main() { create(".").and(create("/")) .unwrap_or_else(|e| error_handler(e,1)); } fn create<P>(root: P)...
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
Change the programming language of this snippet from C# to Rust without modifying what it does.
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"); } }
use std::io::{self, Write}; use std::fs::{DirBuilder, File}; use std::path::Path; use std::{process,fmt}; const FILE_NAME: &'static str = "output.txt"; const DIR_NAME : &'static str = "docs"; fn main() { create(".").and(create("/")) .unwrap_or_else(|e| error_handler(e,1)); } fn create<P>(root: P)...
Rewrite this program in Rust while keeping its functionality equivalent to the C version.
#include <stdio.h> int main() { FILE *fh = fopen("output.txt", "w"); fclose(fh); return 0; }
use std::io::{self, Write}; use std::fs::{DirBuilder, File}; use std::path::Path; use std::{process,fmt}; const FILE_NAME: &'static str = "output.txt"; const DIR_NAME : &'static str = "docs"; fn main() { create(".").and(create("/")) .unwrap_or_else(|e| error_handler(e,1)); } fn create<P>(root: P)...
Rewrite this program in C# while keeping its functionality equivalent to the Ada version.
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;
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}, ...
Maintain the same structure and functionality when rewriting this code in C.
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;
#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 ...
Keep all operations the same but rewrite the snippet in C++.
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;
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} matrix(size_t rows, size_t columns, scalar_type value) ...
Generate a Go translation of this Ada snippet without changing its computational steps.
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;
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) i...
Write a version of this Ada function in Java with identical behavior.
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;
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...
Translate the given Ada code snippet into Python without altering its behavior.
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;
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 ==...
Translate the given Ada code snippet into VB without altering its behavior.
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;
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 ...
Rewrite the snippet below in C so it works the same as the original AutoHotKey code.
Cholesky_Decomposition(A){ L := [], n := A.Count() L[1,1] := Sqrt(A[1,1]) loop % n { k := A_Index loop % n-1 { i := A_Index+1 Sigma := 0, j := 0 while (++j <= k-1) Sigma += L[i, j] * L[k, j] L[i, k] := (A[i, k] - Si...
#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 ...
Write the same code in C# as shown below in AutoHotKey.
Cholesky_Decomposition(A){ L := [], n := A.Count() L[1,1] := Sqrt(A[1,1]) loop % n { k := A_Index loop % n-1 { i := A_Index+1 Sigma := 0, j := 0 while (++j <= k-1) Sigma += L[i, j] * L[k, j] L[i, k] := (A[i, k] - Si...
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}, ...
Maintain the same structure and functionality when rewriting this code in C++.
Cholesky_Decomposition(A){ L := [], n := A.Count() L[1,1] := Sqrt(A[1,1]) loop % n { k := A_Index loop % n-1 { i := A_Index+1 Sigma := 0, j := 0 while (++j <= k-1) Sigma += L[i, j] * L[k, j] L[i, k] := (A[i, k] - Si...
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} matrix(size_t rows, size_t columns, scalar_type value) ...
Convert the following code from AutoHotKey to Java, ensuring the logic remains intact.
Cholesky_Decomposition(A){ L := [], n := A.Count() L[1,1] := Sqrt(A[1,1]) loop % n { k := A_Index loop % n-1 { i := A_Index+1 Sigma := 0, j := 0 while (++j <= k-1) Sigma += L[i, j] * L[k, j] L[i, k] := (A[i, k] - Si...
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...
Ensure the translated Python code behaves exactly like the original AutoHotKey snippet.
Cholesky_Decomposition(A){ L := [], n := A.Count() L[1,1] := Sqrt(A[1,1]) loop % n { k := A_Index loop % n-1 { i := A_Index+1 Sigma := 0, j := 0 while (++j <= k-1) Sigma += L[i, j] * L[k, j] L[i, k] := (A[i, k] - Si...
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 ==...
Preserve the algorithm and functionality while converting the code from AutoHotKey to VB.
Cholesky_Decomposition(A){ L := [], n := A.Count() L[1,1] := Sqrt(A[1,1]) loop % n { k := A_Index loop % n-1 { i := A_Index+1 Sigma := 0, j := 0 while (++j <= k-1) Sigma += L[i, j] * L[k, j] L[i, k] := (A[i, k] - Si...
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 ...
Write a version of this AutoHotKey function in Go with identical behavior.
Cholesky_Decomposition(A){ L := [], n := A.Count() L[1,1] := Sqrt(A[1,1]) loop % n { k := A_Index loop % n-1 { i := A_Index+1 Sigma := 0, j := 0 while (++j <= k-1) Sigma += L[i, j] * L[k, j] L[i, k] := (A[i, k] - Si...
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) i...
Generate a C translation of this BBC_Basic snippet without changing its computational steps.
DIM m1(2,2) m1() = 25, 15, -5, \ \ 15, 18, 0, \ \ -5, 0, 11 PROCcholesky(m1()) PROCprint(m1()) PRINT @% = &2050A DIM m2(3,3) m2() = 18, 22, 54, 42, \ \ 22, 70, 86, 62, \ \ 54, 86, 174, 134, \ \ 42, 62, 13...
#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 ...
Transform the following BBC_Basic implementation into C#, maintaining the same output and logic.
DIM m1(2,2) m1() = 25, 15, -5, \ \ 15, 18, 0, \ \ -5, 0, 11 PROCcholesky(m1()) PROCprint(m1()) PRINT @% = &2050A DIM m2(3,3) m2() = 18, 22, 54, 42, \ \ 22, 70, 86, 62, \ \ 54, 86, 174, 134, \ \ 42, 62, 13...
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}, ...
Keep all operations the same but rewrite the snippet in C++.
DIM m1(2,2) m1() = 25, 15, -5, \ \ 15, 18, 0, \ \ -5, 0, 11 PROCcholesky(m1()) PROCprint(m1()) PRINT @% = &2050A DIM m2(3,3) m2() = 18, 22, 54, 42, \ \ 22, 70, 86, 62, \ \ 54, 86, 174, 134, \ \ 42, 62, 13...
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} matrix(size_t rows, size_t columns, scalar_type value) ...
Convert this BBC_Basic snippet to Java and keep its semantics consistent.
DIM m1(2,2) m1() = 25, 15, -5, \ \ 15, 18, 0, \ \ -5, 0, 11 PROCcholesky(m1()) PROCprint(m1()) PRINT @% = &2050A DIM m2(3,3) m2() = 18, 22, 54, 42, \ \ 22, 70, 86, 62, \ \ 54, 86, 174, 134, \ \ 42, 62, 13...
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...
Write the same algorithm in Python as shown in this BBC_Basic implementation.
DIM m1(2,2) m1() = 25, 15, -5, \ \ 15, 18, 0, \ \ -5, 0, 11 PROCcholesky(m1()) PROCprint(m1()) PRINT @% = &2050A DIM m2(3,3) m2() = 18, 22, 54, 42, \ \ 22, 70, 86, 62, \ \ 54, 86, 174, 134, \ \ 42, 62, 13...
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 ==...
Transform the following BBC_Basic implementation into VB, maintaining the same output and logic.
DIM m1(2,2) m1() = 25, 15, -5, \ \ 15, 18, 0, \ \ -5, 0, 11 PROCcholesky(m1()) PROCprint(m1()) PRINT @% = &2050A DIM m2(3,3) m2() = 18, 22, 54, 42, \ \ 22, 70, 86, 62, \ \ 54, 86, 174, 134, \ \ 42, 62, 13...
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 ...
Maintain the same structure and functionality when rewriting this code in Go.
DIM m1(2,2) m1() = 25, 15, -5, \ \ 15, 18, 0, \ \ -5, 0, 11 PROCcholesky(m1()) PROCprint(m1()) PRINT @% = &2050A DIM m2(3,3) m2() = 18, 22, 54, 42, \ \ 22, 70, 86, 62, \ \ 54, 86, 174, 134, \ \ 42, 62, 13...
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) i...
Produce a language-to-language conversion: from Clojure to C, same semantics.
(defn cholesky [matrix] (let [n (count matrix) A (to-array-2d matrix) L (make-array Double/TYPE n n)] (doseq [i (range n) j (range (inc i))] (let [s (reduce + (for [k (range j)] (* (aget L i k) (aget L j k))))] (aset L i j (if (= i j) (Math/sqrt (- (aget A i i...
#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 ...
Convert the following code from Clojure to C#, ensuring the logic remains intact.
(defn cholesky [matrix] (let [n (count matrix) A (to-array-2d matrix) L (make-array Double/TYPE n n)] (doseq [i (range n) j (range (inc i))] (let [s (reduce + (for [k (range j)] (* (aget L i k) (aget L j k))))] (aset L i j (if (= i j) (Math/sqrt (- (aget A i i...
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}, ...
Produce a language-to-language conversion: from Clojure to C++, same semantics.
(defn cholesky [matrix] (let [n (count matrix) A (to-array-2d matrix) L (make-array Double/TYPE n n)] (doseq [i (range n) j (range (inc i))] (let [s (reduce + (for [k (range j)] (* (aget L i k) (aget L j k))))] (aset L i j (if (= i j) (Math/sqrt (- (aget A i i...
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} matrix(size_t rows, size_t columns, scalar_type value) ...
Maintain the same structure and functionality when rewriting this code in Java.
(defn cholesky [matrix] (let [n (count matrix) A (to-array-2d matrix) L (make-array Double/TYPE n n)] (doseq [i (range n) j (range (inc i))] (let [s (reduce + (for [k (range j)] (* (aget L i k) (aget L j k))))] (aset L i j (if (= i j) (Math/sqrt (- (aget A i i...
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...
Port the following code from Clojure to Python with equivalent syntax and logic.
(defn cholesky [matrix] (let [n (count matrix) A (to-array-2d matrix) L (make-array Double/TYPE n n)] (doseq [i (range n) j (range (inc i))] (let [s (reduce + (for [k (range j)] (* (aget L i k) (aget L j k))))] (aset L i j (if (= i j) (Math/sqrt (- (aget A i i...
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 ==...
Maintain the same structure and functionality when rewriting this code in VB.
(defn cholesky [matrix] (let [n (count matrix) A (to-array-2d matrix) L (make-array Double/TYPE n n)] (doseq [i (range n) j (range (inc i))] (let [s (reduce + (for [k (range j)] (* (aget L i k) (aget L j k))))] (aset L i j (if (= i j) (Math/sqrt (- (aget A i i...
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 ...
Port the provided Clojure code into Go while preserving the original functionality.
(defn cholesky [matrix] (let [n (count matrix) A (to-array-2d matrix) L (make-array Double/TYPE n n)] (doseq [i (range n) j (range (inc i))] (let [s (reduce + (for [k (range j)] (* (aget L i k) (aget L j k))))] (aset L i j (if (= i j) (Math/sqrt (- (aget A i i...
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) i...
Transform the following Common_Lisp implementation into C, maintaining the same output and logic.
(defun chol (A) (let* ((n (car (array-dimensions A))) (L (make-array `(,n ,n) :initial-element 0))) (do ((k 0 (incf k))) ((> k (- n 1)) nil) (setf (aref L k k) (sqrt (- (aref A k k) (do* ((j 0 (incf j)) (sum (expt (aref...
#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 ...
Port the provided Common_Lisp code into C# while preserving the original functionality.
(defun chol (A) (let* ((n (car (array-dimensions A))) (L (make-array `(,n ,n) :initial-element 0))) (do ((k 0 (incf k))) ((> k (- n 1)) nil) (setf (aref L k k) (sqrt (- (aref A k k) (do* ((j 0 (incf j)) (sum (expt (aref...
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}, ...
Convert this Common_Lisp block to C++, preserving its control flow and logic.
(defun chol (A) (let* ((n (car (array-dimensions A))) (L (make-array `(,n ,n) :initial-element 0))) (do ((k 0 (incf k))) ((> k (- n 1)) nil) (setf (aref L k k) (sqrt (- (aref A k k) (do* ((j 0 (incf j)) (sum (expt (aref...
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} matrix(size_t rows, size_t columns, scalar_type value) ...
Convert this Common_Lisp block to Java, preserving its control flow and logic.
(defun chol (A) (let* ((n (car (array-dimensions A))) (L (make-array `(,n ,n) :initial-element 0))) (do ((k 0 (incf k))) ((> k (- n 1)) nil) (setf (aref L k k) (sqrt (- (aref A k k) (do* ((j 0 (incf j)) (sum (expt (aref...
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...
Translate this program into Python but keep the logic exactly as in Common_Lisp.
(defun chol (A) (let* ((n (car (array-dimensions A))) (L (make-array `(,n ,n) :initial-element 0))) (do ((k 0 (incf k))) ((> k (- n 1)) nil) (setf (aref L k k) (sqrt (- (aref A k k) (do* ((j 0 (incf j)) (sum (expt (aref...
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 ==...
Convert the following code from Common_Lisp to VB, ensuring the logic remains intact.
(defun chol (A) (let* ((n (car (array-dimensions A))) (L (make-array `(,n ,n) :initial-element 0))) (do ((k 0 (incf k))) ((> k (- n 1)) nil) (setf (aref L k k) (sqrt (- (aref A k k) (do* ((j 0 (incf j)) (sum (expt (aref...
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 ...
Convert this Common_Lisp block to Go, preserving its control flow and logic.
(defun chol (A) (let* ((n (car (array-dimensions A))) (L (make-array `(,n ,n) :initial-element 0))) (do ((k 0 (incf k))) ((> k (- n 1)) nil) (setf (aref L k k) (sqrt (- (aref A k k) (do* ((j 0 (incf j)) (sum (expt (aref...
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) i...
Maintain the same structure and functionality when rewriting this code in C.
import std.stdio, std.math, std.numeric; T[][] cholesky(T)(in T[][] A) pure nothrow { auto L = new T[][](A.length, A.length); foreach (immutable r, row; L) row[r + 1 .. $] = 0; foreach (immutable i; 0 .. A.length) foreach (immutable j; 0 .. i + 1) { auto t = dotProduct(L[i][0 ....
#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 ...
Generate a C# translation of this D snippet without changing its computational steps.
import std.stdio, std.math, std.numeric; T[][] cholesky(T)(in T[][] A) pure nothrow { auto L = new T[][](A.length, A.length); foreach (immutable r, row; L) row[r + 1 .. $] = 0; foreach (immutable i; 0 .. A.length) foreach (immutable j; 0 .. i + 1) { auto t = dotProduct(L[i][0 ....
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}, ...
Port the following code from D to C++ with equivalent syntax and logic.
import std.stdio, std.math, std.numeric; T[][] cholesky(T)(in T[][] A) pure nothrow { auto L = new T[][](A.length, A.length); foreach (immutable r, row; L) row[r + 1 .. $] = 0; foreach (immutable i; 0 .. A.length) foreach (immutable j; 0 .. i + 1) { auto t = dotProduct(L[i][0 ....
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} matrix(size_t rows, size_t columns, scalar_type value) ...
Write a version of this D function in Java with identical behavior.
import std.stdio, std.math, std.numeric; T[][] cholesky(T)(in T[][] A) pure nothrow { auto L = new T[][](A.length, A.length); foreach (immutable r, row; L) row[r + 1 .. $] = 0; foreach (immutable i; 0 .. A.length) foreach (immutable j; 0 .. i + 1) { auto t = dotProduct(L[i][0 ....
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...
Write the same code in Python as shown below in D.
import std.stdio, std.math, std.numeric; T[][] cholesky(T)(in T[][] A) pure nothrow { auto L = new T[][](A.length, A.length); foreach (immutable r, row; L) row[r + 1 .. $] = 0; foreach (immutable i; 0 .. A.length) foreach (immutable j; 0 .. i + 1) { auto t = dotProduct(L[i][0 ....
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 ==...
Rewrite the snippet below in VB so it works the same as the original D code.
import std.stdio, std.math, std.numeric; T[][] cholesky(T)(in T[][] A) pure nothrow { auto L = new T[][](A.length, A.length); foreach (immutable r, row; L) row[r + 1 .. $] = 0; foreach (immutable i; 0 .. A.length) foreach (immutable j; 0 .. i + 1) { auto t = dotProduct(L[i][0 ....
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 ...
Convert this D snippet to Go and keep its semantics consistent.
import std.stdio, std.math, std.numeric; T[][] cholesky(T)(in T[][] A) pure nothrow { auto L = new T[][](A.length, A.length); foreach (immutable r, row; L) row[r + 1 .. $] = 0; foreach (immutable i; 0 .. A.length) foreach (immutable j; 0 .. i + 1) { auto t = dotProduct(L[i][0 ....
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) i...
Rewrite this program in C while keeping its functionality equivalent to the Delphi version.
function Cholesky(a : array of Float) : array of Float; var i, j, k, n : Integer; s : Float; begin n:=Round(Sqrt(a.Length)); Result:=new Float[n*n]; for i:=0 to n-1 do begin for j:=0 to i do begin s:=0 ; for k:=0 to j-1 do s+=Result[i*n+k] * Result[j*n+k]; if ...
#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 ...
Port the following code from Delphi to C# with equivalent syntax and logic.
function Cholesky(a : array of Float) : array of Float; var i, j, k, n : Integer; s : Float; begin n:=Round(Sqrt(a.Length)); Result:=new Float[n*n]; for i:=0 to n-1 do begin for j:=0 to i do begin s:=0 ; for k:=0 to j-1 do s+=Result[i*n+k] * Result[j*n+k]; if ...
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}, ...
Translate this program into C++ but keep the logic exactly as in Delphi.
function Cholesky(a : array of Float) : array of Float; var i, j, k, n : Integer; s : Float; begin n:=Round(Sqrt(a.Length)); Result:=new Float[n*n]; for i:=0 to n-1 do begin for j:=0 to i do begin s:=0 ; for k:=0 to j-1 do s+=Result[i*n+k] * Result[j*n+k]; if ...
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} matrix(size_t rows, size_t columns, scalar_type value) ...
Keep all operations the same but rewrite the snippet in Java.
function Cholesky(a : array of Float) : array of Float; var i, j, k, n : Integer; s : Float; begin n:=Round(Sqrt(a.Length)); Result:=new Float[n*n]; for i:=0 to n-1 do begin for j:=0 to i do begin s:=0 ; for k:=0 to j-1 do s+=Result[i*n+k] * Result[j*n+k]; if ...
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...
Rewrite the snippet below in Python so it works the same as the original Delphi code.
function Cholesky(a : array of Float) : array of Float; var i, j, k, n : Integer; s : Float; begin n:=Round(Sqrt(a.Length)); Result:=new Float[n*n]; for i:=0 to n-1 do begin for j:=0 to i do begin s:=0 ; for k:=0 to j-1 do s+=Result[i*n+k] * Result[j*n+k]; if ...
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 ==...
Maintain the same structure and functionality when rewriting this code in VB.
function Cholesky(a : array of Float) : array of Float; var i, j, k, n : Integer; s : Float; begin n:=Round(Sqrt(a.Length)); Result:=new Float[n*n]; for i:=0 to n-1 do begin for j:=0 to i do begin s:=0 ; for k:=0 to j-1 do s+=Result[i*n+k] * Result[j*n+k]; if ...
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 ...
Write a version of this Delphi function in Go with identical behavior.
function Cholesky(a : array of Float) : array of Float; var i, j, k, n : Integer; s : Float; begin n:=Round(Sqrt(a.Length)); Result:=new Float[n*n]; for i:=0 to n-1 do begin for j:=0 to i do begin s:=0 ; for k:=0 to j-1 do s+=Result[i*n+k] * Result[j*n+k]; if ...
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) i...
Change the programming language of this snippet from F# to C without modifying what it does.
open Microsoft.FSharp.Collections let cholesky a = let calc (a: float[,]) (l: float[,]) i j = let c1 j = let sum = List.sumBy (fun k -> l.[j, k] ** 2.0) [0..j - 1] sqrt (a.[j, j] - sum) let c2 i j = let sum = List.sumBy (fun k -> l.[i, k] * l.[j, k]) [0..j - 1] ...
#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 ...
Produce a language-to-language conversion: from F# to C#, same semantics.
open Microsoft.FSharp.Collections let cholesky a = let calc (a: float[,]) (l: float[,]) i j = let c1 j = let sum = List.sumBy (fun k -> l.[j, k] ** 2.0) [0..j - 1] sqrt (a.[j, j] - sum) let c2 i j = let sum = List.sumBy (fun k -> l.[i, k] * l.[j, k]) [0..j - 1] ...
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}, ...
Generate an equivalent C++ version of this F# code.
open Microsoft.FSharp.Collections let cholesky a = let calc (a: float[,]) (l: float[,]) i j = let c1 j = let sum = List.sumBy (fun k -> l.[j, k] ** 2.0) [0..j - 1] sqrt (a.[j, j] - sum) let c2 i j = let sum = List.sumBy (fun k -> l.[i, k] * l.[j, k]) [0..j - 1] ...
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} matrix(size_t rows, size_t columns, scalar_type value) ...
Transform the following F# implementation into Java, maintaining the same output and logic.
open Microsoft.FSharp.Collections let cholesky a = let calc (a: float[,]) (l: float[,]) i j = let c1 j = let sum = List.sumBy (fun k -> l.[j, k] ** 2.0) [0..j - 1] sqrt (a.[j, j] - sum) let c2 i j = let sum = List.sumBy (fun k -> l.[i, k] * l.[j, k]) [0..j - 1] ...
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...
Port the following code from F# to Python with equivalent syntax and logic.
open Microsoft.FSharp.Collections let cholesky a = let calc (a: float[,]) (l: float[,]) i j = let c1 j = let sum = List.sumBy (fun k -> l.[j, k] ** 2.0) [0..j - 1] sqrt (a.[j, j] - sum) let c2 i j = let sum = List.sumBy (fun k -> l.[i, k] * l.[j, k]) [0..j - 1] ...
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 ==...
Transform the following F# implementation into VB, maintaining the same output and logic.
open Microsoft.FSharp.Collections let cholesky a = let calc (a: float[,]) (l: float[,]) i j = let c1 j = let sum = List.sumBy (fun k -> l.[j, k] ** 2.0) [0..j - 1] sqrt (a.[j, j] - sum) let c2 i j = let sum = List.sumBy (fun k -> l.[i, k] * l.[j, k]) [0..j - 1] ...
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 ...
Write the same algorithm in Go as shown in this F# implementation.
open Microsoft.FSharp.Collections let cholesky a = let calc (a: float[,]) (l: float[,]) i j = let c1 j = let sum = List.sumBy (fun k -> l.[j, k] ** 2.0) [0..j - 1] sqrt (a.[j, j] - sum) let c2 i j = let sum = List.sumBy (fun k -> l.[i, k] * l.[j, k]) [0..j - 1] ...
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) i...
Generate a C# translation of this Fortran snippet without changing its computational steps.
Program Cholesky_decomp implicit none INTEGER, PARAMETER :: m=3 INTEGER, PARAMETER :: n=3 COMPLEX, DIMENSION(m,n) :: A REAL, DIMENSION(m,n) :: L REAL :: sum1, sum2 INTEGER i,j,k A(1,:)=(/ 25, 15, -5 /) A(2,:)=(/ 15, 18, 0 /) A(3,:)=(/ -5, 0, 11 /) L(1,1)=real(sqrt(A(1,1))) L(2,1)=...
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}, ...
Convert this Fortran block to C++, preserving its control flow and logic.
Program Cholesky_decomp implicit none INTEGER, PARAMETER :: m=3 INTEGER, PARAMETER :: n=3 COMPLEX, DIMENSION(m,n) :: A REAL, DIMENSION(m,n) :: L REAL :: sum1, sum2 INTEGER i,j,k A(1,:)=(/ 25, 15, -5 /) A(2,:)=(/ 15, 18, 0 /) A(3,:)=(/ -5, 0, 11 /) L(1,1)=real(sqrt(A(1,1))) L(2,1)=...
#include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <vector> template <typename scalar_type> class matrix { public: matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns), elements_(rows * columns) {} matrix(size_t rows, size_t columns, scalar_type value) ...
Write the same algorithm in C as shown in this Fortran implementation.
Program Cholesky_decomp implicit none INTEGER, PARAMETER :: m=3 INTEGER, PARAMETER :: n=3 COMPLEX, DIMENSION(m,n) :: A REAL, DIMENSION(m,n) :: L REAL :: sum1, sum2 INTEGER i,j,k A(1,:)=(/ 25, 15, -5 /) A(2,:)=(/ 15, 18, 0 /) A(3,:)=(/ -5, 0, 11 /) L(1,1)=real(sqrt(A(1,1))) L(2,1)=...
#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 ...
Ensure the translated Java code behaves exactly like the original Fortran snippet.
Program Cholesky_decomp implicit none INTEGER, PARAMETER :: m=3 INTEGER, PARAMETER :: n=3 COMPLEX, DIMENSION(m,n) :: A REAL, DIMENSION(m,n) :: L REAL :: sum1, sum2 INTEGER i,j,k A(1,:)=(/ 25, 15, -5 /) A(2,:)=(/ 15, 18, 0 /) A(3,:)=(/ -5, 0, 11 /) L(1,1)=real(sqrt(A(1,1))) L(2,1)=...
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...
Convert this Fortran block to Python, preserving its control flow and logic.
Program Cholesky_decomp implicit none INTEGER, PARAMETER :: m=3 INTEGER, PARAMETER :: n=3 COMPLEX, DIMENSION(m,n) :: A REAL, DIMENSION(m,n) :: L REAL :: sum1, sum2 INTEGER i,j,k A(1,:)=(/ 25, 15, -5 /) A(2,:)=(/ 15, 18, 0 /) A(3,:)=(/ -5, 0, 11 /) L(1,1)=real(sqrt(A(1,1))) L(2,1)=...
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 ==...