Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7078579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:33:55+00:00 2026-05-28T06:33:55+00:00

I want to write a function, and I want to learn about clarify and

  • 0

I want to write a function, and I want to learn about clarify and describe by words (analysis) the code before I am going to write it.

So here is a function I want to write: compare two equivalence classes using boolean matrix

I have a boolean matrix, 2 equivalence classes are an input they are a list of int. The output is the compare of two equivalence classes.

The conditions to compare 2 list equivalence classes:

1) boolean matrix is an transitive closure

2) check every element of each class, if these elements are comparable (has path connected them), compare them. An element can connect to 0 or n element in another class. Throw an exception when they don’t have a connection between them.

for example: i connected to j and h; k and u are in an same equivalence class ; j connected to k

 i -> j -> k <-> u
 |
 v
 h 

3) if two elements are in the same equivalence class they are equal (0); if they have a path from i to j then i < j (-1), otherwise i > j (1).

4) each equivalence class only appears once and each equivalence class contains at least one element.

Here is a function:

let cmp_classes m c c' =
  match c, c' with
   | i :: is, j :: js ->
     (* when i and j has path *)
        if m.(i).(j) = true then compare i j else
     (* when i and j don't have path*) 
        if m.(i).(j) = false then
      (* find k in js *)
      ...
      (* check if i and k has path or not, if yes: compare i k; if no: find h in is*)
      ....  
      (* find h in is*)
      ....
      (* check if h has path to j or not, if yes: compare h j; if no: check h and k *)
       .....
      (* check h and k has path or not, if yes: compare h k; if no: there is no path*)
      .....
   | _ -> assert false

I want you to help me, because I want to be able to write more function trustworthy from the beginning by having a good and clear description. Thank you so much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:33:55+00:00Added an answer on May 28, 2026 at 6:33 am

    I’m not sure I understand your question but I can try to answer anyway.

    • To reprensent your equivalence classes, you don’t need a list of ints. You can either pick a unique representant (the smaller int of the class for instance) or you can pick any (as you don’t really care, as you have the transitive closure of the relation available anyway);

    • If your boolean matrix represents the transitive closure of your relation, then to compare two elements, you just have to check the booleans …

      let compare m i j = match m.(i).(j), m.(j).(i) with
        (* same class: there is a path between i and j, and between j and i *)
        | true, true  -> 0
      
        (* there is a path between i and j *) 
        | true, false -> -1
      
        (* there is a path between j and i *) 
        | false, true -> 1
      
        (* i and j are not comparable *)
        | false, false -> raise Not_found
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a function that accepts two objects as parameters and compare
I just want to learn something new here about my code. I have the
I want to write a function in Python that returns different fixed values based
I want to write a function that takes an array of letters as an
I want to write a function that returns the nearest next power of 2
I want to write a function that accepts a parameter which can be either
I want to write a function like equalp, which gives #t for (equalp Xy
I want to write a function which can validate a given value (passed as
i want to write a function that prints multi-dimensional objects which are text (or
I want to write 'twice' function that takes a function and an argument and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.