Test.check failing for property "Euclidian distance between any two normalized vectors are bounded to [0-2]

Im trying to experiment with test.check and Clojure, however im not an expert in either, or math. However it is my understanding that the following code and test should always succeed. Can someone help to clarify if it is my math understanding or my impl that is wrong.

(defn minmax-norm
  (let [min (apply min xs)
        max (apply max xs)]
    (map (fn [x] (/ (- x min) (+ (- max min) (math/pow 10 -100)))) xs)))

(defn euclidean-distance
  [fr fc]
  (->> (minmax-norm fc)
       (map - (minmax-norm fr))
       (map #(math/pow % 2))
       (reduce +)

(defspec preference-fn
  (prop/for-all [[xs ys] (gen/bind (gen/such-that pos? gen/nat) (fn [x]
                                        (gen/not-empty (gen/vector gen/large-integer x))
                                        (gen/not-empty (gen/vector gen/large-integer x)))))]
                (let [s (sut/euclidean-distance xs ys)]
                  (t/testing "For any two non-empty vectors of equal length s is bounded between 0-2"
                    (and (<= 0 s) (>= 2 s))))))

1 Like
user> (euclidean-distance [0 0 0] [1 0 0])
user> (euclidean-distance [0 0 0] [-1 0 0])


Is it that I misunderstand how I should normalize the two vectors? I normalize them independently…

After switching the normalization function to

(defn norm
  (let [magnitude (->> xs
                       (map #(math/pow % 2))
                       (reduce +)
    (->> xs (map #(/ % magnitude)))))

The test are passing, might be that the property does not hold true for min-max normalization?

However its not the case that (= (euclidean-distance [10 1]) (euclidean-distance [1 10])) however since the formula involve subtraction I dont think that commutativity is a property of euclidean-distance?