numqubits=6
numTgates=6
-numruns=20
+threshold=0.005 # absolute value threshold difference between computed and exact value
+
+numruns=100
echo "Starting test of $numruns random $numqubits-Pauli expectation values..."
for i in $(seq 1 $numruns)
are=$(echo "$a" | cut -f 1 -d " " | cut -c 1-5);
aim=$(echo "$a" | cut -f 3 -d " " | cut -c 1-5); aimsign=$(echo $a | cut -f 2 -d " "); bimsign=$(echo $b | cut -f 2 -d " ");
bre=$(echo "$b" | cut -f 1 -d " " | cut -c 1-5);
-bim=$(echo "$b" | cut -f 3 -d " " | cut -c 1-5); echo "$i: $are $aimsign $aim and $bre $bimsign $bim"
-if [ "$are" == "$bre" ] && [ "$aim" == "$bim" ] && [ "$aimsign" == "$bimsign" ]
+bim=$(echo "$b" | cut -f 3 -d " " | cut -c 1-5);
+c=$( printf 'scale=5; (%.5f)^2 + (%.5f)^2\n' "$are" "$aim" | bc -l )
+echo "$i: $are $aimsign $aim and $bre $bimsign $bim"
+rediff=$( printf 'sqrt((%f - %f)^2)\n' "$are" "$bre" | bc -l )
+imdiff=$( printf 'sqrt((%f - %f)^2)\n' "$aim" "$bim" | bc -l )
+if (( $(echo "$rediff < $threshold" |bc -l) )) && (( $(echo "$imdiff < $threshold" |bc -l) ))
then
-continue
-else
-echo "NOT EQUAL!"
-exit
+ if (( $(echo "$bim < $threshold" |bc -l) )) || [ "$aimsign" == "$bimsign" ]
+ then
+ continue
+ else
+ echo "NOT EQUAL!"
+ exit
+ fi
+ else
+ echo "NOT EQUAL!"
+ exit
fi
done
echo "Test passed!"