Printing a complex matrix Fortran - matrix

The complex matrix is declared this way:
complex(8) :: matrix(:,:)
How can I print this matrix with each element as: (a, b) or a+ib, and in a nxn format? (by that I mean as a square matrix, with a row per line, so there will be n rows and n columns)
This is the way I would print a real matrix with the format I want:
do i=1,n
do j=1,n
write(*, fmt="(f0.2, tr2)", advance="no") matrix(i,j)
end do
write(*, fmt="(a)") " "
end do
But I'm not sure how to translate this to a complex matrix

How can I print this matrix with each element as: (a, b)
Supposing you already know that (a b) is the default printing fotmat for complex type, Why isn't this just enough?
do j=1,n
write(*, *) matrix(:,j)
end do
The output would be something like:
(10.000000000000000,-20.000000000000000) (10.000000000000000,-20.000000000000000) (10.000000000000000,-20.000000000000000)
(10.000000000000000, 20.000000000000000) (10.000000000000000, 20.000000000000000) (10.000000000000000, 20.000000000000000)
If you want something more customized, you could try something like this (adjusting the field width and precision):
do j=1,n
write(*, "(*('('sf6.2xspf6.2x'i)':x))") matrix(:,j)
end do
That produces something like this:
( 10.00 -20.00 i) ( 10.00 -20.00 i) ( 10.00 -20.00 i)
( 10.00 +20.00 i) ( 10.00 +20.00 i) ( 10.00 +20.00 i)

So far this is what has worked for me. Taking into account Clinton's advice:
character(19) fmt
fmt = '(F7.2,"+",F7.2,"i")'
do i=1,n
do j=1,n
fmt(8:8) = MERGE('+',' ',imag(a(i,j)).gt.0)
write(*,fmt, advance="no") a(i,j)
end do
write(*, fmt="(a)") " "
end do
And the output is:
-0.26 -0.00i -0.00 -0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i
0.00+ 0.00i -0.25 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i
0.00 0.00i 0.00 0.00i -0.05 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i
0.00 0.00i 0.00 0.00i 0.00 0.00i -0.05 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i
0.00+ 0.00i -0.46 -0.00i -0.00+ 0.00i -0.00+ 0.00i -0.50 0.00i 0.00 -0.00i 0.00 0.00i -0.00 0.00i
0.32+ 0.00i -0.00+ 0.00i 0.00 -0.00i -0.00 -0.00i 0.00+ 0.00i -0.27 0.00i 0.00 0.00i 0.00 0.00i
-0.00+ 0.00i 0.00 -0.00i -0.00 -0.00i 0.24+ 0.00i 0.00 0.00i 0.00 0.00i -0.18 0.00i 0.00 0.00i
0.00 0.00i -0.00 -0.00i 0.24+ 0.00i 0.00 -0.00i 0.00 0.00i 0.00 0.00i 0.00 0.00i -0.18 0.00i
If someone has a better suggestion I'll be glad to hear it :)

Here is something that has worked in the past, it could be fine tuned quite a bit
!! compile and link with gfortran -I/usr/include -o PrintComplex PrintComplex.f90
Program PrintComplex
use, intrinsic :: iso_c_binding
implicit none
integer, parameter :: N=16
integer :: k
real (kind=c_double) :: val(N)
complex (kind=c_double_complex) :: in(N)
character(19) fmt
fmt = '(F7.2,"+",F7.2,"i")'
val=(/(sin(3.14159d0*float(k)/3.d0),k=1,N)/)
in=cmplx(val,-val/2)
print *,"in"
do k=1,N
fmt(8:8) = MERGE('+',' ',imag(in(k)).gt.0)
write(*,fmt)in(k)
end do
End Program PrintComplex
The output is:
in
0.87 -0.43i
0.87 -0.43i
0.00 -0.00i
-0.87+ 0.43i
-0.87+ 0.43i
-0.00+ 0.00i
0.87 -0.43i
0.87 -0.43i
0.00 -0.00i
-0.87+ 0.43i
-0.87+ 0.43i
-0.00+ 0.00i
0.87 -0.43i
0.87 -0.43i
0.00 -0.00i
-0.87+ 0.43i

Related

Definition of Reflexive Transitive Closure

Many predicates essentially use some form of transitive closure, only to discover that termination has to be addressed too. Why not solve this once and forever with closure0/3:
:- meta_predicate closure0(2,?,?).
:- meta_predicate closure(2,?,?).
:- meta_predicate closure0(2,?,?,+). % internal
closure0(R_2, X0,X) :-
closure0(R_2, X0,X, [X0]).
closure(R_2, X0,X) :-
call(R_2, X0,X1),
closure0(R_2, X1,X, [X1,X0]).
closure0(_R_2, X,X, _).
closure0(R_2, X0,X, Xs) :-
call(R_2, X0,X1),
non_member(X1, Xs),
closure0(R_2, X1,X, [X1|Xs]).
non_member(_E, []).
non_member(E, [X|Xs]) :-
dif(E,X),
non_member(E, Xs).
Are there cases where this definition cannot be used for implementing transitive closure?
Why dif/2?
To answer #WouterBeek's comment in detail: dif/2 or dif_si/2 are ideal, because they are able to show or signal potential problems. However, in current implementations the top-level loop often hides the actual issues. Consider the goal closure0(\_^_^true,a,b) which certainly is quite problematic in itself. When using the following systems the actual problem is directly not visible.
| ?- closure0(\_^_^true,a,b). % SICStus
yes
?- closure0(\_^_^true,a,b). % SWI
true ;
true ;
true ...
Both top-level loops do not show what we actually want to see: the dangling constraints. In SICStus we need a pseudo variable to produce some substitution, in SWI, the query has to be wrapped with call_residue_vars/2. In this manner all variables that have constraints attached are now shown.
| ?- closure0(\_^_^true,a,b), Alt=t. % SICStus
Alt = t ? ;
Alt = t,
prolog:dif(_A,a),
prolog:dif(b,_A) ? ;
Alt = t,
prolog:dif(_A,a),
prolog:dif(_B,_A),
prolog:dif(_B,a),
prolog:dif(b,_B),
prolog:dif(b,_A) ...
?- call_residue_vars(closure0(\_^_^true,a,b),Vs). % SWI
Vs = [] ;
Vs = [_G1744, _G1747, _G1750],
dif(_G1744, a),
dif(b, _G1744) ;
Vs = [_G1915, _G1918, _G1921, _G1924, _G1927, _G1930, _G1933],
dif(_G1915, a),
dif(b, _G1915),
dif(_G1921, _G1915),
dif(_G1921, a),
dif(b, _G1921) ...
It's useful, but in my opinion not yet ideal because I cannot cut duplicate paths at the point of their creation.
Consider, with the complete graph K_n:
n_complete(N, Es) :-
numlist(1, N, Ns),
phrase(pairs(Ns), Es).
adjacent(Edges, X, Y) :- member(edge(X, Y), Edges).
pairs([]) --> [].
pairs([N|Ns]) --> edges(Ns, N), pairs(Ns).
edges([], _) --> [].
edges([N|Ns], X) --> [edge(X,N),edge(N,X)], edges(Ns, X).
The following query now has super-exponential runtime, although the closure can actually be found in polynomial time:
?- length(_, N), n_complete(N, Es), portray_clause(N),
time(findall(Y, closure0(adjacent(Es), 1, Y), Ys)),
false.
1.
16 inferences, 0.000 CPU in 0.000 seconds (97% CPU, 1982161 Lips)
2.
54 inferences, 0.000 CPU in 0.000 seconds (98% CPU, 4548901 Lips)
3.
259 inferences, 0.000 CPU in 0.000 seconds (97% CPU, 14499244 Lips)
4.
1,479 inferences, 0.000 CPU in 0.000 seconds (100% CPU, 16219595 Lips)
5.
9,599 inferences, 0.000 CPU in 0.000 seconds (100% CPU, 27691393 Lips)
6.
70,465 inferences, 0.002 CPU in 0.002 seconds (100% CPU, 28911161 Lips)
7.
581,283 inferences, 0.020 CPU in 0.020 seconds (100% CPU, 29397339 Lips)
8.
5,343,059 inferences, 0.181 CPU in 0.181 seconds (100% CPU, 29488001 Lips)
9.
54,252,559 inferences, 1.809 CPU in 1.808 seconds (100% CPU, 29994536 Lips)
10.
603,682,989 inferences, 19.870 CPU in 19.865 seconds (100% CPU, 30381451 Lips)
It would be great if a more efficient way to determine the closure could also be expressed with this meta-predicate.
For example, one would normally simply use Warshall's algorithm to compute the closure in cubic time, with code similar to:
node_edges_closure(Node, Edges, Closure) :-
warshall_fixpoint(Edges, [Node], Closure).
warshall_fixpoint(Edges, Nodes0, Closure) :-
findall(Y, (member(X, Nodes0), adjacent(Edges, X, Y)), Nodes1, Nodes0),
sort(Nodes1, Nodes),
( Nodes == Nodes0 -> Closure = Nodes0
; warshall_fixpoint(Edges, Nodes, Closure)
).
Yielding (with all drawbacks in comparison to the nicely declarative closure0/3):
?- length(_, N), n_complete(N, Es), portray_clause(N),
time(node_edges_closure(1, Es, Ys)),
false.
1.
% 16 inferences, 0.000 CPU in 0.000 seconds (75% CPU, 533333 Lips)
2.
% 43 inferences, 0.000 CPU in 0.000 seconds (85% CPU, 1228571 Lips)
3.
% 69 inferences, 0.000 CPU in 0.000 seconds (85% CPU, 1769231 Lips)
4.
% 115 inferences, 0.000 CPU in 0.000 seconds (89% CPU, 2346939 Lips)
5.
% 187 inferences, 0.000 CPU in 0.000 seconds (91% CPU, 2968254 Lips)
6.
% 291 inferences, 0.000 CPU in 0.000 seconds (92% CPU, 3548780 Lips)
7.
% 433 inferences, 0.000 CPU in 0.000 seconds (95% CPU, 3866071 Lips)
8.
% 619 inferences, 0.000 CPU in 0.000 seconds (96% CPU, 4268966 Lips)
9.
% 855 inferences, 0.000 CPU in 0.000 seconds (97% CPU, 4500000 Lips)
10.
% 1,147 inferences, 0.000 CPU in 0.000 seconds (98% CPU, 4720165 Lips)
etc.

IR Hex to Raw IR code conversion

How do I get this Hex IR Code
0000 006d 0022 0003 00a9 00a8 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 0702 00a9 00a8 0015 0015 0015 0e6e
Into a Raw IR Code like this
int[] irdata = {4600,4350,700,1550,650,1550,650,1600,650,450,650,450,650,450,650,450,700,400,700,1550,650,1550,650,1600,650,450,650,450,650,450,700,450,650,450,650,450,650,1550,700,450,650,450,650,450,650,450,650,450,700,400,650,1600,650,450,650,1550,650,1600,650,1550,650,1550,700,1550,650,1550,650};
mIR.sendIRPattern(37470, irdata);
The first four numbers there have special meaning:
1 - 0000 indicates raw IR data (you can ignore this value)
2 - frequency
3 - length of the first burst pair sequence
4 - length of the second burst pair sequence
The frequency will be particularly important. LG wants the frequency in Hz, as you might expect, but your Hex code is in terms of the Pronto internal clock. The conversion will be:
carrierfrequency = 1000000/(HexFreq * .241246)
To the rest of the code, after that four digit preamble, LG wants those in μs, where the hex code has them in terms of the frequency. You'll need to convert each of them:
pulselength = 1000000*(HexPulse/carrierfrequency)
I'm not sure whether you want to just send the whole thing, or only the first or second burst sequence. The second is a repeat sequence, used for long button presses and the like. But keep in mind, these are in terms of pairs, not individual numbers. 00a9 00a8 is one burst pair (on time, off time). In this case:
first sequence: 00a9 00a8 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 0702
second sequence: 00a9 00a8 0015 0015 0015 0e6e
Sidenote: The distinct pair up front, and very large value at the end are very typical. Makes it easy to eyeball without having to count.
So, to lay out the steps:
array numbers = Split hexcode on space
(ignore numbers[0])
carrierFrequency = 1000000/(numbers[1] * .241246)
codeLength = numbers[2]
repeatCodeLength = numbers[3]
for (number in numbers[4 to end]) {
convertedToMicrosec = 1000000*(number/carrierFrequency)
fullSequenceConverted.add(convertedToMicrosec)
}
sequence1EndPoint = 2 * codeLength
sequence2EndPoint = sequence1EndPoint + 2 * repeatCodeLength
firstSequence = fullSequenceConverted from index 0 to sequence1EndPoint
secondSequence = fullSequenceConverted from sequence1EndPoint to sequence2EndPoint
mIR.sendIRPattern(carrierFrequency, firstSequence)

Syntax error during associative array expansion in Bash 4.2

all
I got two 2D-array files to read with bash
these two files contain different rows x columns such as:
file1.txt (nx6)
DIFFUSION X 0.054 0.072 Y E2
DEEP_N_WELL X 1.8 2.25 N D
PW_CORE X 0.306 0.306 Y U1
PW_IO X 0.306 0.306 Y T1
NW_CORE X 0.306 0.306 Y U1
NW_IO X 0.306 0.306 Y T1
TG X 0.306 0.306 N S1
N+_POLY_IMP X 0.162 0.162 Y T1
POLY1 X 0.036 0.09 Y F2
LV_NLDD X 0.162 0.162 Y T1
LV_PLDD X 0.162 0.162 Y T1
LPL_NLDD X 0.162 0.162 Y T1
LPL_PLDD X 0.162 0.162 Y T1
CELL_NLDD X 0.216 0.216 N U1
CELL_PLDD X 0.216 0.216 N U1
HV_NLDD X 0.162 0.162 Y T1
HV_PLDD X 0.162 0.162 Y T1
N+ X 0.162 0.162 Y T1
P+ X 0.162 0.162 Y T1
SMT X 0.162 0.162 Y T1
PESD X 0.486 0.486 N A
SAB X 0.324 0.324 N S1
CONTACT X 0.054 0.072/0.090 Y F1
METAL1 1x 0.063 0.063 Y E2
MVIA1 1x 0.063 0.063/0.081 Y E1
METAL2 1x 0.063 0.063 Y E2
MVIA2 1x 0.063 0.063/0.081 Y E1
METAL3 1x 0.063 0.063 Y E2
MVIA3 1x 0.063 0.063/0.081 Y E1
METAL4 1x 0.063 0.063 Y E2
MVIA4 1x 0.063 0.063/0.081 Y E1
METAL5 1x 0.063 0.063 Y E2
MVIA5 1x 0.063 0.063/0.081 Y E1
METAL6 1x 0.063 0.063 Y E2
MVIA6 6x 0.31 0.320/0.320 N S1
METAL7 6x 0.32 0.4 N S1
TMV_RDL X 1.8 1.8 N B
AL_RDL X 1.8 1.8 N B
PASV_RDL X 5.4 5.4 N B
N_WELL X 0.306 0.306 NULL U1
HP_CELL_NLDD X 0.216 0.216 N U1
HP_CELL_PLDD X 0.216 0.216 N U1
LVH_NLDD X 0.162 0.162 Y T1
LVH_PLDD X 0.162 0.162 Y T1
LVUL_NLDD X 0.162 0.162 Y T1
LVUL_PLDD X 0.162 0.162 Y T1
CG X 0.306 0.306 N S1
AW X 1.5 1.5 N B
file2.txt (mx3)
DIFFUSION 0.054 0.072
POLY1 0.036 0.090
SMT 0.162 0.162
VTNH 0.162 0.162
VTPH 0.162 0.162
N+_POLY_IMP 0.162 0.162
P+_POLY_IMP 0.162 0.162
LV_NLDD 0.162 0.162
LV_PLDD 0.162 0.162
HV_NLDD 0.162 0.162
HV_PLDD 0.162 0.162
LVL_NLDD 0.162 0.162
LVL_PLDD 0.162 0.162
LVH_NLDD 0.162 0.162
LVH_PLDD 0.162 0.162
LPL_NLDD 0.162 0.162
LPL_PLDD 0.162 0.162
HVL_NLDD 0.162 0.162
N+ 0.162 0.162
P+ 0.162 0.162
SG 0.162 0.162
VTP_WLDR 0.162 0.162
VTN_WLDR 0.162 0.162
HS_CELL_PLDD 0.216 0.216
HS_CELL_NLDD 0.216 0.216
NW_CORE 0.306 0.306
PW_CORE 0.306 0.306
PW_IO 0.306 0.306
NW_IO 0.306 0.306
DT 0.090 0.118
CONTACT 0.054 0.072/0.091
METAL1 0.063 0.063
MVIA1 0.063 0.063/0.081
METAL2 0.063 0.063
MVIA2 0.063 0.063/0.081
METAL3 0.063 0.063
MVIA3 0.063 0.063/0.081
METAL4 0.063 0.063
MVIA4 0.063 0.063/0.081
METAL5 0.063 0.063
MVIA5 0.063 0.063/0.081
METAL6 0.063 0.063
MVIA6 0.063 0.063/0.081
METAL7 0.063 0.063
MVIA7 0.126 0.126
METAL8 0.126 0.126
MVIA8 0.126 0.126
METAL9 0.126 0.126
what I wanna do is to extract the elements inside both files then do some comparisons as following picture:
http://imgur.com/3Zd0TKD.jpg
"DESC1==DESC2" or "DESC1!=DESC2" in green label is a obstructer for me
I really wanna do is to take one element in $DESC1 and compare with whole elements in ${DESC2[#]}, if it does/dosen't find a element in ${DESC2[#]} then feedback true/false
Here is my work:
#!/bin/bash
clear
##===================================================================##
##===================================================================##
##========== read information from file1.txt and file2.txt ==========##
##===================================================================##
##===================================================================##
idx1=0
while read -a file1array$idx1; do
let idx1++
done < file1.txt
idx2=0
while read -a file2array$idx2; do
let idx2++
done < file2.txt
##===================================================================##
##===================================================================##
##================ start to compare these two files =================##
##===================================================================##
##===================================================================##
for ((i=0; i<idx1; i++)); do
for ((j=0; j<idx2; j++)); do
DESC1="file1array$i[0]"
DM1="file1array$i[1]"
W1="file1array$i[2]"
S1="file1array$i[3]"
CRITICAL1="file1array$i[4]"
GRADE1="file1array$i[5]"
DESC2="file2array$j[0]"
W2="file2array$j[1]"
S2="file2array$j[2]"
if [[ "${!GRADE1}" == [E-GT-Z][1-9] && "${!DESC1}" == "${!DESC2}" ]]; then
W1_Judge=`expr "scale=3; ${!W1} - ${!W2}" | bc`
S1_Judge=`expr "scale=3; ${!S1} - ${!S2}" | bc`
[ $W1_Judge != 0 -o $S1_Judge != 0 ] && declare -A jgWS=( ["${!DESC1}"]="WSNG" )
elif [[ "${!GRADE1}" == [E-GT-Z][1-9] && "${!DESC1}" != "${!DESC2}" ]]; then
[ "${!CRITICAL1}" != "NULL" ] && declare -A jgLOSS=( ["${!DESC1}"]="LOSSNG" )
elif [[ "${!GRADE1}" != [E-GT-Z][1-9] && "${!DESC1}" == "${!DESC2}" ]]; then
[[ "$DM1" == [1-2]x || "$DM1" == "X" ]] && declare -A jgEXTRA=( ["${!DESC1}"]="EXTRANG" )
else
declare -A jgBYPASS=( ["${!DESC1}"]="OK" )
fi
done
if [ "${jgWS[${!DESC1}]}" == "WSNG" ]; then
echo "${!DESC1} : W or S NG"
elif [ "${jgLOSS[${!DESC1}]}" == "LOSSNG" ]; then
echo "${!DESC1} : LOSS NG"
elif [ "${jgEXTRA[${!DESC1}]}" == "EXTRANG" ]; then
echo "${!DESC1} : EXTRA NG"
else
echo "${!DESC1} : OK"
fi
done
How can I solve the part of green label or is there any easier way to achieve the goal? I feel that I'm very close but turns out I'm just stuck with for-loop and test
The error message is "N+: syntax error: operand expected (error token is "+")"
Actually I can simply define "declare -A jgEXTRA=( ["N+"]="EXTRANG" )" and "echo {jgEXTRA[N+]}"
so I don't know what's going on? Is there any way to solve it?
For the first question:
The complexity of your script is high. It would be an issue if file1 and file2 are big. You should sort them to reduce the complexity (from N^2 to log N).
Do you consider to use 'comm' command? I think this does a big part of the job and could let you simplify your script a lot
For the second question:
It seems you do not initialize jgWS in some condition. When it happens, ${jgWS[a]} return empty string, but ${jgWS[a+]} prints your error message. I am not sure to understand why, but it is what I observed.
Other remarks
You read loops, at the begining, will miss the last lines of file1 and file2 if they are not terminated by a Linux Line Feed (because read returns false when it doesn't finish on LF).

How do I design and load my Prolog source files so I don't have to manually use_module?

I have a source file, openpage.pl, where I call use_module/1 to "import" SWI-Prolog's http_open/3:
use_module(library(http/http_open)).
request(URL, In) :- http_open(URL, In, []),
copy_stream_data(In, user_output),
close(In).
It loads without complaint. However, try as I might, I can't run it the rules in it.
?- [openpage].
% openpage compiled 0.00 sec, 1,828 bytes
true.
?- request('http://www.google.com', In).
ERROR: request/2: Undefined procedure: http_open/3
?- use_module(library(http/http_open)).
true.
?- request('http://www.google.com', In).
ERROR: request/2: Undefined procedure: http_open/3
?- make.
% Scanning references for 1 possibly undefined predicates
Warning: The predicates below are not defined. If these are defined
Warning: at runtime using assert/1, use :- dynamic Name/Arity.
Warning:
Warning: http_open/3, which is referenced by
Warning: status/2 at /home/dale/sesame_test/prolog/openpage.pl:16
Warning: request/2 at /home/dale/sesame_test/prolog/openpage.pl:3
Warning: modified/2 at /home/dale/sesame_test/prolog/openpage.pl:7
true.
?- [openpage].
% openpage compiled 0.00 sec, 616 bytes
true.
?- request('http://www.google.com', In).
ERROR: request/2: Undefined procedure: http_open/3
?-
[forced] Action (h for help) ? exit
So in my next session, I invoke use_module/1 before loading my source file, and all is fine:
?- use_module(library(http/http_open)).
% library(uri) compiled into uri 0.00 sec, 199,772 bytes
% library(readutil) compiled into read_util 0.00 sec, 10,312 bytes
% library(socket) compiled into socket 0.00 sec, 6,376 bytes
% library(option) compiled into swi_option 0.00 sec, 7,748 bytes
% library(base64) compiled into base64 0.00 sec, 9,776 bytes
% library(debug) compiled into prolog_debug 0.01 sec, 12,056 bytes
% library(http/http_open) compiled into http_open 0.01 sec, 282,844 bytes
true.
?- [openpage].
% openpage compiled 0.00 sec, 1,380 bytes
true.
?- request('http://www.google.com/', In).
<!doctype html><html itemscope itemtype="http://schema.org/WebPage">
...
In = <stream>(0x9366508).
How can I set up and execute my files so that I don't need this manual step of loading modules before loading my own code?
Try:
:- use_module(library(http/http_open)).
in your source file.

Swi-Prolog: Undefined procedure: random_permutation/2

Why this predicate random_permutation doesn't work?
http://www.swi-prolog.org/pldoc/doc_for?object=random_permutation/2
?- use_module(library(random)).
% library(pairs) compiled into pairs 0.00 sec, 8,880 bytes
% library(random) compiled into random 0.04 sec, 333,032 bytes
true.
?- L=[1,2,3,4,5], random_permutation(L,P).
ERROR: toplevel: Undefined procedure: random_permutation/2 (DWIM could not correct goal)
How can I make it work?
Please double check the version you are using. I am using 5.10.5 and the sizes of the libraries do not seem to match.
3 ?- use_module(library(random)).
% library(pairs) compiled into pairs 0.00 sec, 4,568 bytes
% library(random) compiled into random 0.03 sec, 46,624 bytes
true.
4 ?- L=[1,2,3,4,5], random_permutation(L,K).
L = [1, 2, 3, 4, 5],
K = [1, 3, 2, 4, 5].

Resources