Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Can you help me rewrite this code in PHP instead of Ada, keeping it the same logically? | procedure Array_Collection is
A : array (-3 .. -1) of Integer := (1, 2, 3);
begin
A (-3) := 3;
A (-2) := 2;
A (-1) := 1;
end Array_Collection;
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Rewrite this program in PHP while keeping its functionality equivalent to the Arturo version. |
arr: ["one" 2 "three" "four"]
arr: arr ++ 5
print arr
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Port the provided AutoHotKey code into PHP while preserving the original functionality. | myCol := Object()
mycol.mykey := "my value!"
mycol["mykey"] := "new val!"
MsgBox % mycol.mykey
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Write the same algorithm in PHP as shown in this AWK implementation. | a[0]="hello"
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Maintain the same structure and functionality when rewriting this code in PHP. | DIM text$(1)
text$(0) = "Hello "
text$(1) = "world!"
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Translate this program into PHP but keep the logic exactly as in Clojure. | {1 "a", "Q" 10}
(hash-map 1 "a" "Q" 10)
(let [my-map {1 "a"}]
(assoc my-map "Q" 10))
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Translate this program into PHP but keep the logic exactly as in Common_Lisp. | CL-USER> (let ((list '())
(hash-table (make-hash-table)))
(push 1 list)
(push 2 list)
(push 3 list)
(format t "~S~%" (reverse list))
(setf (gethash 'foo hash-table) 42)
(setf (gethash 'bar hash-table) 69)
(maphash (lambda (key v... | <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Translate the given D code snippet into PHP without altering its behavior. | int[3] array;
array[0] = 5;
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Ensure the translated PHP code behaves exactly like the original Delphi snippet. |
var
intArray: TArray<Integer> = [1, 2, 3, 4, 5];
intArray2: array of Integer = [1, 2, 3, 4, 5];
intArray3: array [0..4]of Integer;
intArray4: array [10..14]of Integer;
procedure
var
intArray5: TArray<Integer>;
begin
intArray := [1,2,3];
intArray2 := [1,2,3];
intAr... | <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Translate this program into PHP but keep the logic exactly as in Elixir. | empty_list = []
list = [1,2,3,4,5]
length(list)
[0 | list]
hd(list)
tl(list)
Enum.at(list,3)
list ++ [6,7]
list -- [4,2]
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Produce a functionally identical PHP code for the snippet given in Factor. | USING: assocs deques dlists lists lists.lazy sequences sets ;
{ 1 2 "foo" 3 }
[ 1 2 3 + * ]
"Hello, world
B{ 1 2 3 }
?{ f t t }
{ 1 2 3 } 4 suffix
{ 1 2 3 } { 4 5 6 } append
{ 1 1 2 3 } { 2 5 7 8 } intersect
"Hello" { } like
{ 72 101 108 108 111 } "" like
V{ 1 2 "foo" 3 }
BV{ 1 2 2... | <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Keep all operations the same but rewrite the snippet in PHP. | include ffl/car.fs
10 car-create ar
2 0 ar car-set
3 1 ar car-set
1 0 ar car-insert
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Keep all operations the same but rewrite the snippet in PHP. | REAL A(36)
A(1) = 1
A(2) = 3*A(1) + 5
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Translate the given Groovy code snippet into PHP without altering its behavior. | def emptyList = []
assert emptyList.isEmpty() : "These are not the items you're looking for"
assert emptyList.size() == 0 : "Empty list has size 0"
assert ! emptyList : "Empty list evaluates as boolean 'false'"
def initializedList = [ 1, "b", java.awt.Color.BLUE ]
assert initializedList.size() == 3
assert initializedL... | <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Convert this Haskell block to PHP, preserving its control flow and logic. | [1, 2, 3, 4, 5]
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Write the same algorithm in PHP as shown in this Icon implementation. |
s := "abccd"
c := 'abcd'
S := set()
T := table()
L := []
record constructorname(field1,field2,fieldetc)
R := constructorname() ... | <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Produce a language-to-language conversion: from J to PHP, same semantics. | c =: 0 10 20 30 40
c, 50
0 10 20 30 40 50
_20 _10 , c
_20 _10 0 10 20 30 40
,~ c
0 10 20 30 40 0 10 20 30 40
,:~ c
0 10 20 30 40
0 10 20 30 40
30 e. c
1
30 i.~c
3
30 80 e. c
1 0
2 1 4 2 { c ... | <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Maintain the same structure and functionality when rewriting this code in PHP. | julia> collection = []
0-element Array{Any,1}
julia> push!(collection, 1,2,4,7)
4-element Array{Any,1}:
1
2
4
7
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Write a version of this Lua function in PHP with identical behavior. | collection = {0, '1'}
print(collection[1])
collection = {["foo"] = 0, ["bar"] = '1'}
print(collection["foo"])
print(collection.foo)
collection = {0, '1', ["foo"] = 0, ["bar"] = '1'}
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Convert this Mathematica snippet to PHP and keep its semantics consistent. | Lst = {3, 4, 5, 6}
->{3, 4, 5, 6}
PrependTo[ Lst, 2]
->{2, 3, 4, 5, 6}
PrependTo[ Lst, 1]
->{1, 2, 3, 4, 5, 6}
Lst
->{1, 2, 3, 4, 5, 6}
Insert[ Lst, X, 4]
->{1, 2, 3, X, 4, 5, 6}
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Maintain the same structure and functionality when rewriting this code in PHP. | >> A = {2,'TPS Report'}
A =
[2] 'TPS Report'
>> A{2} = struct('make','honda','year',2003)
A =
[2] [1x1 struct]
>> A{3} = {3,'HOVA'}
A =
[2] [1x1 struct] {1x2 cell}
>> A{2}
ans =
make: 'honda'
year: 2003
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Port the following code from Nim to PHP with equivalent syntax and logic. | var a = [1,2,3,4,5,6,7,8,9]
var b: array[128, int]
b[9] = 10
b[0..8] = a
var c: array['a'..'d', float] = [1.0, 1.1, 1.2, 1.3]
c['b'] = 10000
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Produce a functionally identical PHP code for the snippet given in OCaml. | [1; 2; 3; 4; 5]
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Convert the following code from Pascal to PHP, ensuring the logic remains intact. | var
MyArray: array[1..5] of real;
begin
MyArray[1] := 4.35;
end;
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Ensure the translated PHP code behaves exactly like the original Perl snippet. | use strict;
my @c = ();
push @c, 10, 11, 12;
push @c, 65;
print join(" ",@c) . "\n";
my %h = ();
$h{'one'} = 1;
$h{'two'} = 2;
foreach my $i ( keys %h ) {
print $i . " -> " . $h{$i} . "\n";
}
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Ensure the translated PHP code behaves exactly like the original PowerShell snippet. |
$array = "one", 2, "three", 4
$array = @("one", 2, "three", 4)
$var1, $var2, $var3, $var4 = $array
$array = 0, 1, 2, 3, 4, 5, 6, 7
$array = 0..7
[int[]] $stronglyTypedArray = 1, 2, 4, 8, 16, 32, 64, 128
$array = @()
$array = @("one")
$jaggedArray = @((11, 12, 13),
(21, 22, 23),
... | <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Ensure the translated PHP code behaves exactly like the original R snippet. | numeric(5)
1:10
c(1, 3, 6, 10, 7 + 8, sqrt(441))
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Translate this program into PHP but keep the logic exactly as in Racket. | #lang racket
(list 1 2 3 4)
(make-list 100 0)
(cons 1 (list 2 3 4))
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Change the following COBOL code into PHP without altering its purpose. | identification division.
program-id. collections.
data division.
working-storage section.
01 sample-table.
05 sample-record occurs 1 to 3 times depending on the-index.
10 sample-alpha pic x(4).
10 filler pic x value ":".
10 s... | <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Please provide an equivalent version of this REXX code in PHP. |
options replace format comments java crossref symbols nobinary
myVals = [ 'zero', 'one', 'two', 'three', 'four', 'five' ]
mySet = Set
mySet = HashSet()
loop val over myVals
mySet.add(val)
end val
loop val over mySet
say val
end val
return
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Translate the given Ruby code snippet into PHP without altering its behavior. |
a = []
a[0] = 1
a[3] = "abc"
a << 3.14
a = Array.new
a = Array.new(3)
a = Array.new(3, 0)
a = Array.new(3){|i| i*2}
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Change the programming language of this snippet from Scala to PHP without modifying what it does. | import java.util.PriorityQueue
fun main(args: Array<String>) {
val ga = arrayOf(1, 2, 3)
println(ga.joinToString(prefix = "[", postfix = "]"))
val da = doubleArrayOf(4.0, 5.0, 6.0)
println(da.joinToString(prefix = "[", postfix = "]"))
val li = listOf<Byte>(7, 8, 9)
println(li)
... | <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Convert the following code from Tcl to PHP, ensuring the logic remains intact. | set c [list] ;
lappend c 10 11 13
set c [linsert $c 2 "twelve goes here"]
foreach elem $c {puts $elem}
proc show_size {l} {
puts [llength $l]
}
show_size $c
| <?php
$a = array();
# add elements "at the end"
array_push($a, 55, 10, 20);
print_r($a);
# using an explicit key
$a['one'] = 1;
$a['two'] = 2;
print_r($a);
?>
|
Preserve the algorithm and functionality while converting the code from C to Rust. | #define cSize( a ) ( sizeof(a)/sizeof(a[0]) )
int ar[10];
ar[0] = 1;
ar[1] = 2;
int* p;
for (p=ar;
p<(ar+cSize(ar));
p++) {
printf("%d\n",*p);
}
| let a = [1u8,2,3,4,5];
let b = [0;256]
|
Port the provided C++ code into Rust while preserving the original functionality. | int a[5];
a[0] = 1;
int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
#include <string>
std::string strings[4];
| let a = [1u8,2,3,4,5];
let b = [0;256]
|
Produce a language-to-language conversion: from C# to Rust, same semantics. |
int[] intArray = new int[5] { 1, 2, 3, 4, 5 };
int[] intArray = new int[]{ 1, 2, 3, 4, 5 };
int[] intArray = { 1, 2, 3, 4, 5 };
string[] stringArr = new string[5];
stringArr[0] = "string";
| let a = [1u8,2,3,4,5];
let b = [0;256]
|
Translate this program into Rust but keep the logic exactly as in Java. | List arrayList = new ArrayList();
arrayList.add(new Integer(0));
arrayList.add(0);
List<Integer> myarrlist = new ArrayList<Integer>();
int sum;
for(int i = 0; i < 10; i++) {
myarrlist.add(i);
}
| let a = [1u8,2,3,4,5];
let b = [0;256]
|
Maintain the same structure and functionality when rewriting this code in Rust. | package main
import "fmt"
func main() {
var a []interface{}
a = append(a, 3)
a = append(a, "apples", "oranges")
fmt.Println(a)
}
| let a = [1u8,2,3,4,5];
let b = [0;256]
|
Translate this program into Python but keep the logic exactly as in Rust. | let a = [1u8,2,3,4,5];
let b = [0;256]
| collection = [0, '1']
x = collection[0]
collection.append(2)
collection.insert(0, '-1')
y = collection[0]
collection.extend([2,'3'])
collection += [2,'3']
collection[2:6]
len(coll... |
Maintain the same structure and functionality when rewriting this code in VB. | let a = [1u8,2,3,4,5];
let b = [0;256]
| Dim coll As New Collection
coll.Add "apple"
coll.Add "banana"
|
Write a version of this Ada function in C# with identical behavior. | with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Matrix is
generic
type Element is private;
Zero : Element;
One : Element;
with function "+" (A, B : Element) return Element is <>;
with function "*" (A, B : Element) return Element is <>;
with function Image (X : Element) retur... | using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Rewrite this program in C while keeping its functionality equivalent to the Ada version. | with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Matrix is
generic
type Element is private;
Zero : Element;
One : Element;
with function "+" (A, B : Element) return Element is <>;
with function "*" (A, B : Element) return Element is <>;
with function Image (X : Element) retur... | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Generate a C++ translation of this Ada snippet without changing its computational steps. | with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Matrix is
generic
type Element is private;
Zero : Element;
One : Element;
with function "+" (A, B : Element) return Element is <>;
with function "*" (A, B : Element) return Element is <>;
with function Image (X : Element) retur... | #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Transform the following Ada implementation into Go, maintaining the same output and logic. | with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Matrix is
generic
type Element is private;
Zero : Element;
One : Element;
with function "+" (A, B : Element) return Element is <>;
with function "*" (A, B : Element) return Element is <>;
with function Image (X : Element) retur... | package main
import "fmt"
type vector = []float64
type matrix []vector
func (m1 matrix) mul(m2 matrix) matrix {
rows1, cols1 := len(m1), len(m1[0])
rows2, cols2 := len(m2), len(m2[0])
if cols1 != rows2 {
panic("Matrices cannot be multiplied.")
}
result := make(matrix, rows1)
for i := ... |
Transform the following Ada implementation into Python, maintaining the same output and logic. | with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Matrix is
generic
type Element is private;
Zero : Element;
One : Element;
with function "+" (A, B : Element) return Element is <>;
with function "*" (A, B : Element) return Element is <>;
with function Image (X : Element) retur... | >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Can you help me rewrite this code in VB instead of Ada, keeping it the same logically? | with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Matrix is
generic
type Element is private;
Zero : Element;
One : Element;
with function "+" (A, B : Element) return Element is <>;
with function "*" (A, B : Element) return Element is <>;
with function Image (X : Element) retur... | Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Convert this BBC_Basic snippet to C and keep its semantics consistent. | DIM matrix(1,1), output(1,1)
matrix() = 3, 2, 2, 1
FOR power% = 0 TO 9
PROCmatrixpower(matrix(), output(), power%)
PRINT "matrix()^" ; power% " = "
FOR row% = 0 TO DIM(output(), 1)
FOR col% = 0 TO DIM(output(), 2)
PRINT output(row%,col%);
... | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Generate an equivalent C# version of this BBC_Basic code. | DIM matrix(1,1), output(1,1)
matrix() = 3, 2, 2, 1
FOR power% = 0 TO 9
PROCmatrixpower(matrix(), output(), power%)
PRINT "matrix()^" ; power% " = "
FOR row% = 0 TO DIM(output(), 1)
FOR col% = 0 TO DIM(output(), 2)
PRINT output(row%,col%);
... | using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Produce a functionally identical C++ code for the snippet given in BBC_Basic. | DIM matrix(1,1), output(1,1)
matrix() = 3, 2, 2, 1
FOR power% = 0 TO 9
PROCmatrixpower(matrix(), output(), power%)
PRINT "matrix()^" ; power% " = "
FOR row% = 0 TO DIM(output(), 1)
FOR col% = 0 TO DIM(output(), 2)
PRINT output(row%,col%);
... | #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Please provide an equivalent version of this BBC_Basic code in Python. | DIM matrix(1,1), output(1,1)
matrix() = 3, 2, 2, 1
FOR power% = 0 TO 9
PROCmatrixpower(matrix(), output(), power%)
PRINT "matrix()^" ; power% " = "
FOR row% = 0 TO DIM(output(), 1)
FOR col% = 0 TO DIM(output(), 2)
PRINT output(row%,col%);
... | >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Produce a functionally identical VB code for the snippet given in BBC_Basic. | DIM matrix(1,1), output(1,1)
matrix() = 3, 2, 2, 1
FOR power% = 0 TO 9
PROCmatrixpower(matrix(), output(), power%)
PRINT "matrix()^" ; power% " = "
FOR row% = 0 TO DIM(output(), 1)
FOR col% = 0 TO DIM(output(), 2)
PRINT output(row%,col%);
... | Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Keep all operations the same but rewrite the snippet in Go. | DIM matrix(1,1), output(1,1)
matrix() = 3, 2, 2, 1
FOR power% = 0 TO 9
PROCmatrixpower(matrix(), output(), power%)
PRINT "matrix()^" ; power% " = "
FOR row% = 0 TO DIM(output(), 1)
FOR col% = 0 TO DIM(output(), 2)
PRINT output(row%,col%);
... | package main
import "fmt"
type vector = []float64
type matrix []vector
func (m1 matrix) mul(m2 matrix) matrix {
rows1, cols1 := len(m1), len(m1[0])
rows2, cols2 := len(m2), len(m2[0])
if cols1 != rows2 {
panic("Matrices cannot be multiplied.")
}
result := make(matrix, rows1)
for i := ... |
Change the programming language of this snippet from Common_Lisp to C without modifying what it does. | (defun multiply-matrices (matrix-0 matrix-1)
"Takes two 2D arrays and returns their product, or an error if they cannot be multiplied"
(let* ((m0-dims (array-dimensions matrix-0))
(m1-dims (array-dimensions matrix-1))
(m0-dim (length m0-dims))
(m1-dim (length m1-dims)))
(if (or (/= 2 ... | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Keep all operations the same but rewrite the snippet in C#. | (defun multiply-matrices (matrix-0 matrix-1)
"Takes two 2D arrays and returns their product, or an error if they cannot be multiplied"
(let* ((m0-dims (array-dimensions matrix-0))
(m1-dims (array-dimensions matrix-1))
(m0-dim (length m0-dims))
(m1-dim (length m1-dims)))
(if (or (/= 2 ... | using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Port the following code from Common_Lisp to C++ with equivalent syntax and logic. | (defun multiply-matrices (matrix-0 matrix-1)
"Takes two 2D arrays and returns their product, or an error if they cannot be multiplied"
(let* ((m0-dims (array-dimensions matrix-0))
(m1-dims (array-dimensions matrix-1))
(m0-dim (length m0-dims))
(m1-dim (length m1-dims)))
(if (or (/= 2 ... | #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Change the programming language of this snippet from Common_Lisp to Python without modifying what it does. | (defun multiply-matrices (matrix-0 matrix-1)
"Takes two 2D arrays and returns their product, or an error if they cannot be multiplied"
(let* ((m0-dims (array-dimensions matrix-0))
(m1-dims (array-dimensions matrix-1))
(m0-dim (length m0-dims))
(m1-dim (length m1-dims)))
(if (or (/= 2 ... | >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Convert this Common_Lisp block to VB, preserving its control flow and logic. | (defun multiply-matrices (matrix-0 matrix-1)
"Takes two 2D arrays and returns their product, or an error if they cannot be multiplied"
(let* ((m0-dims (array-dimensions matrix-0))
(m1-dims (array-dimensions matrix-1))
(m0-dim (length m0-dims))
(m1-dim (length m1-dims)))
(if (or (/= 2 ... | Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Preserve the algorithm and functionality while converting the code from Common_Lisp to Go. | (defun multiply-matrices (matrix-0 matrix-1)
"Takes two 2D arrays and returns their product, or an error if they cannot be multiplied"
(let* ((m0-dims (array-dimensions matrix-0))
(m1-dims (array-dimensions matrix-1))
(m0-dim (length m0-dims))
(m1-dim (length m1-dims)))
(if (or (/= 2 ... | package main
import "fmt"
type vector = []float64
type matrix []vector
func (m1 matrix) mul(m2 matrix) matrix {
rows1, cols1 := len(m1), len(m1[0])
rows2, cols2 := len(m2), len(m2[0])
if cols1 != rows2 {
panic("Matrices cannot be multiplied.")
}
result := make(matrix, rows1)
for i := ... |
Rewrite this program in C while keeping its functionality equivalent to the D version. | import std.stdio, std.string, std.math, std.array, std.algorithm;
struct SquareMat(T = creal) {
public static string fmt = "%8.3f";
private alias TM = T[][];
private TM a;
public this(in size_t side) pure nothrow @safe
in {
assert(side > 0);
} body {
a = new TM(side, side);
... | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Translate the given D code snippet into C# without altering its behavior. | import std.stdio, std.string, std.math, std.array, std.algorithm;
struct SquareMat(T = creal) {
public static string fmt = "%8.3f";
private alias TM = T[][];
private TM a;
public this(in size_t side) pure nothrow @safe
in {
assert(side > 0);
} body {
a = new TM(side, side);
... | using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Write a version of this D function in C++ with identical behavior. | import std.stdio, std.string, std.math, std.array, std.algorithm;
struct SquareMat(T = creal) {
public static string fmt = "%8.3f";
private alias TM = T[][];
private TM a;
public this(in size_t side) pure nothrow @safe
in {
assert(side > 0);
} body {
a = new TM(side, side);
... | #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Convert this D block to Python, preserving its control flow and logic. | import std.stdio, std.string, std.math, std.array, std.algorithm;
struct SquareMat(T = creal) {
public static string fmt = "%8.3f";
private alias TM = T[][];
private TM a;
public this(in size_t side) pure nothrow @safe
in {
assert(side > 0);
} body {
a = new TM(side, side);
... | >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Generate an equivalent VB version of this D code. | import std.stdio, std.string, std.math, std.array, std.algorithm;
struct SquareMat(T = creal) {
public static string fmt = "%8.3f";
private alias TM = T[][];
private TM a;
public this(in size_t side) pure nothrow @safe
in {
assert(side > 0);
} body {
a = new TM(side, side);
... | Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Write the same algorithm in Go as shown in this D implementation. | import std.stdio, std.string, std.math, std.array, std.algorithm;
struct SquareMat(T = creal) {
public static string fmt = "%8.3f";
private alias TM = T[][];
private TM a;
public this(in size_t side) pure nothrow @safe
in {
assert(side > 0);
} body {
a = new TM(side, side);
... | package main
import "fmt"
type vector = []float64
type matrix []vector
func (m1 matrix) mul(m2 matrix) matrix {
rows1, cols1 := len(m1), len(m1[0])
rows2, cols2 := len(m2), len(m2[0])
if cols1 != rows2 {
panic("Matrices cannot be multiplied.")
}
result := make(matrix, rows1)
for i := ... |
Translate the given Delphi code snippet into C without altering its behavior. | program Matrix_exponentiation_operator;
uses
System.SysUtils;
type
TCells = array of array of double;
TMatrix = record
private
FCells: TCells;
function GetCells(r, c: Integer): Double;
procedure SetCells(r, c: Integer; const Value: Double);
class operator Implicit(a: TMatrix): string;
... | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Preserve the algorithm and functionality while converting the code from Delphi to C#. | program Matrix_exponentiation_operator;
uses
System.SysUtils;
type
TCells = array of array of double;
TMatrix = record
private
FCells: TCells;
function GetCells(r, c: Integer): Double;
procedure SetCells(r, c: Integer; const Value: Double);
class operator Implicit(a: TMatrix): string;
... | using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Transform the following Delphi implementation into C++, maintaining the same output and logic. | program Matrix_exponentiation_operator;
uses
System.SysUtils;
type
TCells = array of array of double;
TMatrix = record
private
FCells: TCells;
function GetCells(r, c: Integer): Double;
procedure SetCells(r, c: Integer; const Value: Double);
class operator Implicit(a: TMatrix): string;
... | #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Change the following Delphi code into Python without altering its purpose. | program Matrix_exponentiation_operator;
uses
System.SysUtils;
type
TCells = array of array of double;
TMatrix = record
private
FCells: TCells;
function GetCells(r, c: Integer): Double;
procedure SetCells(r, c: Integer; const Value: Double);
class operator Implicit(a: TMatrix): string;
... | >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Change the programming language of this snippet from Delphi to VB without modifying what it does. | program Matrix_exponentiation_operator;
uses
System.SysUtils;
type
TCells = array of array of double;
TMatrix = record
private
FCells: TCells;
function GetCells(r, c: Integer): Double;
procedure SetCells(r, c: Integer; const Value: Double);
class operator Implicit(a: TMatrix): string;
... | Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Translate this program into Go but keep the logic exactly as in Delphi. | program Matrix_exponentiation_operator;
uses
System.SysUtils;
type
TCells = array of array of double;
TMatrix = record
private
FCells: TCells;
function GetCells(r, c: Integer): Double;
procedure SetCells(r, c: Integer; const Value: Double);
class operator Implicit(a: TMatrix): string;
... | package main
import "fmt"
type vector = []float64
type matrix []vector
func (m1 matrix) mul(m2 matrix) matrix {
rows1, cols1 := len(m1), len(m1[0])
rows2, cols2 := len(m2), len(m2[0])
if cols1 != rows2 {
panic("Matrices cannot be multiplied.")
}
result := make(matrix, rows1)
for i := ... |
Rewrite the snippet below in C so it works the same as the original Factor code. | USING: kernel math math.matrices sequences ;
: my-m^n ( m n -- m' )
dup 0 < [ "no negative exponents" throw ] [
[ drop length identity-matrix ]
[ swap '[ _ m. ] times ] 2bi
] if ;
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Rewrite this program in C# while keeping its functionality equivalent to the Factor version. | USING: kernel math math.matrices sequences ;
: my-m^n ( m n -- m' )
dup 0 < [ "no negative exponents" throw ] [
[ drop length identity-matrix ]
[ swap '[ _ m. ] times ] 2bi
] if ;
| using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Convert this Factor block to C++, preserving its control flow and logic. | USING: kernel math math.matrices sequences ;
: my-m^n ( m n -- m' )
dup 0 < [ "no negative exponents" throw ] [
[ drop length identity-matrix ]
[ swap '[ _ m. ] times ] 2bi
] if ;
| #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Port the provided Factor code into Python while preserving the original functionality. | USING: kernel math math.matrices sequences ;
: my-m^n ( m n -- m' )
dup 0 < [ "no negative exponents" throw ] [
[ drop length identity-matrix ]
[ swap '[ _ m. ] times ] 2bi
] if ;
| >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Please provide an equivalent version of this Factor code in VB. | USING: kernel math math.matrices sequences ;
: my-m^n ( m n -- m' )
dup 0 < [ "no negative exponents" throw ] [
[ drop length identity-matrix ]
[ swap '[ _ m. ] times ] 2bi
] if ;
| Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Convert the following code from Factor to Go, ensuring the logic remains intact. | USING: kernel math math.matrices sequences ;
: my-m^n ( m n -- m' )
dup 0 < [ "no negative exponents" throw ] [
[ drop length identity-matrix ]
[ swap '[ _ m. ] times ] 2bi
] if ;
| package main
import "fmt"
type vector = []float64
type matrix []vector
func (m1 matrix) mul(m2 matrix) matrix {
rows1, cols1 := len(m1), len(m1[0])
rows2, cols2 := len(m2), len(m2[0])
if cols1 != rows2 {
panic("Matrices cannot be multiplied.")
}
result := make(matrix, rows1)
for i := ... |
Translate the given Fortran code snippet into C# without altering its behavior. | module matmod
implicit none
interface operator (.matpow.)
module procedure matrix_exp
end interface
contains
function matrix_exp(m, n) result (res)
real, intent(in) :: m(:,:)
integer, intent(in) :: n
real :: res(size(m,1),size(m,2))
integer :: i
if(n == 0) then
res = 0
do i = ... | using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Translate this program into C++ but keep the logic exactly as in Fortran. | module matmod
implicit none
interface operator (.matpow.)
module procedure matrix_exp
end interface
contains
function matrix_exp(m, n) result (res)
real, intent(in) :: m(:,:)
integer, intent(in) :: n
real :: res(size(m,1),size(m,2))
integer :: i
if(n == 0) then
res = 0
do i = ... | #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Transform the following Fortran implementation into C, maintaining the same output and logic. | module matmod
implicit none
interface operator (.matpow.)
module procedure matrix_exp
end interface
contains
function matrix_exp(m, n) result (res)
real, intent(in) :: m(:,:)
integer, intent(in) :: n
real :: res(size(m,1),size(m,2))
integer :: i
if(n == 0) then
res = 0
do i = ... | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Generate an equivalent Python version of this Fortran code. | module matmod
implicit none
interface operator (.matpow.)
module procedure matrix_exp
end interface
contains
function matrix_exp(m, n) result (res)
real, intent(in) :: m(:,:)
integer, intent(in) :: n
real :: res(size(m,1),size(m,2))
integer :: i
if(n == 0) then
res = 0
do i = ... | >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Ensure the translated VB code behaves exactly like the original Fortran snippet. | module matmod
implicit none
interface operator (.matpow.)
module procedure matrix_exp
end interface
contains
function matrix_exp(m, n) result (res)
real, intent(in) :: m(:,:)
integer, intent(in) :: n
real :: res(size(m,1),size(m,2))
integer :: i
if(n == 0) then
res = 0
do i = ... | Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Keep all operations the same but rewrite the snippet in C. | import Data.List (transpose)
(<+>)
:: Num a
=> [a] -> [a] -> [a]
(<+>) = zipWith (+)
(<*>)
:: Num a
=> [a] -> [a] -> a
(<*>) = (sum .) . zipWith (*)
newtype Mat a =
Mat [[a]]
deriving (Eq, Show)
instance Num a =>
Num (Mat a) where
negate (Mat x) = Mat $ map (map negate) x
Mat x + Mat y = Ma... | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Port the following code from Haskell to C# with equivalent syntax and logic. | import Data.List (transpose)
(<+>)
:: Num a
=> [a] -> [a] -> [a]
(<+>) = zipWith (+)
(<*>)
:: Num a
=> [a] -> [a] -> a
(<*>) = (sum .) . zipWith (*)
newtype Mat a =
Mat [[a]]
deriving (Eq, Show)
instance Num a =>
Num (Mat a) where
negate (Mat x) = Mat $ map (map negate) x
Mat x + Mat y = Ma... | using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Generate a C++ translation of this Haskell snippet without changing its computational steps. | import Data.List (transpose)
(<+>)
:: Num a
=> [a] -> [a] -> [a]
(<+>) = zipWith (+)
(<*>)
:: Num a
=> [a] -> [a] -> a
(<*>) = (sum .) . zipWith (*)
newtype Mat a =
Mat [[a]]
deriving (Eq, Show)
instance Num a =>
Num (Mat a) where
negate (Mat x) = Mat $ map (map negate) x
Mat x + Mat y = Ma... | #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Port the provided Haskell code into Python while preserving the original functionality. | import Data.List (transpose)
(<+>)
:: Num a
=> [a] -> [a] -> [a]
(<+>) = zipWith (+)
(<*>)
:: Num a
=> [a] -> [a] -> a
(<*>) = (sum .) . zipWith (*)
newtype Mat a =
Mat [[a]]
deriving (Eq, Show)
instance Num a =>
Num (Mat a) where
negate (Mat x) = Mat $ map (map negate) x
Mat x + Mat y = Ma... | >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Maintain the same structure and functionality when rewriting this code in VB. | import Data.List (transpose)
(<+>)
:: Num a
=> [a] -> [a] -> [a]
(<+>) = zipWith (+)
(<*>)
:: Num a
=> [a] -> [a] -> a
(<*>) = (sum .) . zipWith (*)
newtype Mat a =
Mat [[a]]
deriving (Eq, Show)
instance Num a =>
Num (Mat a) where
negate (Mat x) = Mat $ map (map negate) x
Mat x + Mat y = Ma... | Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Produce a functionally identical Go code for the snippet given in Haskell. | import Data.List (transpose)
(<+>)
:: Num a
=> [a] -> [a] -> [a]
(<+>) = zipWith (+)
(<*>)
:: Num a
=> [a] -> [a] -> a
(<*>) = (sum .) . zipWith (*)
newtype Mat a =
Mat [[a]]
deriving (Eq, Show)
instance Num a =>
Num (Mat a) where
negate (Mat x) = Mat $ map (map negate) x
Mat x + Mat y = Ma... | package main
import "fmt"
type vector = []float64
type matrix []vector
func (m1 matrix) mul(m2 matrix) matrix {
rows1, cols1 := len(m1), len(m1[0])
rows2, cols2 := len(m2), len(m2[0])
if cols1 != rows2 {
panic("Matrices cannot be multiplied.")
}
result := make(matrix, rows1)
for i := ... |
Change the following J code into C without altering its purpose. | mp=: +/ .*
pow=: pow0=: 4 : 'mp&x^:y =i.#x'
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Maintain the same structure and functionality when rewriting this code in C#. | mp=: +/ .*
pow=: pow0=: 4 : 'mp&x^:y =i.#x'
| using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Generate a C++ translation of this J snippet without changing its computational steps. | mp=: +/ .*
pow=: pow0=: 4 : 'mp&x^:y =i.#x'
| #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Convert the following code from J to Python, ensuring the logic remains intact. | mp=: +/ .*
pow=: pow0=: 4 : 'mp&x^:y =i.#x'
| >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Please provide an equivalent version of this J code in VB. | mp=: +/ .*
pow=: pow0=: 4 : 'mp&x^:y =i.#x'
| Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Rewrite the snippet below in Go so it works the same as the original J code. | mp=: +/ .*
pow=: pow0=: 4 : 'mp&x^:y =i.#x'
| package main
import "fmt"
type vector = []float64
type matrix []vector
func (m1 matrix) mul(m2 matrix) matrix {
rows1, cols1 := len(m1), len(m1[0])
rows2, cols2 := len(m2), len(m2[0])
if cols1 != rows2 {
panic("Matrices cannot be multiplied.")
}
result := make(matrix, rows1)
for i := ... |
Change the following Julia code into C without altering its purpose. | julia> [1 1 ; 1 0]^10
2x2 Array{Int64,2}:
89 55
55 34
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Please provide an equivalent version of this Julia code in C#. | julia> [1 1 ; 1 0]^10
2x2 Array{Int64,2}:
89 55
55 34
| using System;
using System.Collections;
using System.Collections.Generic;
using static System.Linq.Enumerable;
public static class MatrixExponentation
{
public static double[,] Identity(int size) {
double[,] matrix = new double[size, size];
for (int i = 0; i < size; i++) matrix[i, i] = 1;
r... |
Write the same algorithm in C++ as shown in this Julia implementation. | julia> [1 1 ; 1 0]^10
2x2 Array{Int64,2}:
89 55
55 34
| #include <complex>
#include <cmath>
#include <iostream>
using namespace std;
template<int MSize = 3, class T = complex<double> >
class SqMx {
typedef T Ax[MSize][MSize];
typedef SqMx<MSize, T> Mx;
private:
Ax a;
SqMx() { }
public:
SqMx(const Ax &_a) {
for (int r = 0; r < MSize; r++)
for (int c =... |
Transform the following Julia implementation into Python, maintaining the same output and logic. | julia> [1 1 ; 1 0]^10
2x2 Array{Int64,2}:
89 55
55 34
| >>> from operator import mul
>>> def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)
>>> def identity(size):
size = range(size)
return [[(i==j)*1 for i in size] for j in size]
>>> def matrixExp(m, pow):
assert pow>=0 an... |
Translate this program into VB but keep the logic exactly as in Julia. | julia> [1 1 ; 1 0]^10
2x2 Array{Int64,2}:
89 55
55 34
| Option Base 1
Private Function Identity(n As Integer) As Variant
Dim I() As Variant
ReDim I(n, n)
For j = 1 To n
For k = 1 To n
I(j, k) = 0
Next k
Next j
For j = 1 To n
I(j, j) = 1
Next j
Identity = I
End Function
Function MatrixExponentiation(ByVal x As ... |
Convert the following code from Julia to Go, ensuring the logic remains intact. | julia> [1 1 ; 1 0]^10
2x2 Array{Int64,2}:
89 55
55 34
| package main
import "fmt"
type vector = []float64
type matrix []vector
func (m1 matrix) mul(m2 matrix) matrix {
rows1, cols1 := len(m1), len(m1[0])
rows2, cols2 := len(m2), len(m2[0])
if cols1 != rows2 {
panic("Matrices cannot be multiplied.")
}
result := make(matrix, rows1)
for i := ... |
Produce a language-to-language conversion: from Lua to C, same semantics. | Matrix = {}
function Matrix.new( dim_y, dim_x )
assert( dim_y and dim_x )
local matrix = {}
local metatab = {}
setmetatable( matrix, metatab )
metatab.__add = Matrix.Add
metatab.__mul = Matrix.Mul
metatab.__pow = Matrix.Pow
matrix.dim_y = dim_y
matrix.dim_x = dim_x
m... | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct squareMtxStruct {
int dim;
double *cells;
double **m;
} *SquareMtx;
typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data);
SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data )
{
SquareMtx sm =... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.