ambuda-org / vidyut

Infrastructure for Sanskrit software. For Python bindings, see `vidyut-py`.
48 stars 21 forks source link

[prakriya] Prakriya doesn't show all rules involved in the process? #44

Closed vipranarayan14 closed 8 months ago

vipranarayan14 commented 1 year ago

In the derivation of बुध्यात् (बुधँ अवगमने 01.0994):

Without the presence of atleast the क्ङिति च, it is difficult to understand why there is no guNa in the form.

image

Dr Dhaval's Prakriyāpradarśinī shows क्ङिति च:

image

If this is intended, I understand.

akprasad commented 1 year ago

Thanks for filing this! I think we should add क्ङिति च here. The current logic, in pseudocode, is something like:

if is_knit {
  return
}
if sarvadhatuka_ardhadhatukayoh {
  do_guna()
  mark("7.3.84")
} else if puganta_laghupadhasya {
  do_guna()
  mark("7.3.86")
}

It should instead be:

if sarvadhatuka_ardhadhatukayoh {
  if is_knit {
   mark("1.1.5")
  } else {
    do_guna()
    mark("7.3.84")
  }
} else if puganta_laghupadhasya {
  if is_knit {
   mark("1.1.5")
  } else {
    do_guna()
    mark("7.3.86")
  }
}

Do you want to try making the code change?

vipranarayan14 commented 1 year ago

Yes! It will allow me to understand the inner workings of vidyut.

vipranarayan14 commented 1 year ago

The current logic, in pseudocode, is something like:

if is_knit {
  return
}
if sarvadhatuka_ardhadhatukayoh {
  do_guna()
  mark("7.3.84")
} else if puganta_laghupadhasya {
  do_guna()
  mark("7.3.86")
}

The actual code used for applying guna is different from what you have described here. It seems it is more like:

if laghu_upadha && can_use_guna {
    do_guna()
    mark("7.3.86")
} else if ik_anta && can_use_guna {
    do_guna()
    mark("7.3.84")
}

can_use_guna checks if the next term is kit or Nit and a few other criteria.

Due to can_use_guna, if the next term is not kit or Nit, the entire block won't run in both the cases.

akprasad commented 1 year ago

Thanks for checking -- I was speaking loosely to keep the description simple, but I'll be more precise in the future.

In this case, the control flow is quite complex, but I think we can try pushing it in:

if laghu_upadha {
  if can_use_guna {
    mark("7.3.86")
  } else {
    mark("1.1.5");
  } 
}

Feel free to heavily modify this function, too -- I dislike the control flow here, and if you can find a cleaner approach, I'm all for it.

vipranarayan14 commented 1 year ago

Thanks for checking -- I was speaking loosely to keep the description simple, but I'll be more precise in the future.

In this case, the control flow is quite complex, but I think we can try pushing it in:

if laghu_upadha {
  if can_use_guna {
    mark("7.3.86")
  } else {
    mark("1.1.5");
  } 
}

I did the same thing. But I couldn't make it pass all the tests. After that, I couldn't find time to work on it. I'll try it again sometime tomorrow and let you know.

Feel free to heavily modify this function, too -- I dislike the control flow here, and if you can find a cleaner approach, I'm all for it.

Thanks for the permission 🙂. Some people don't like others disturbing their codebase. However, I'll modify them in small steps so that I don't break anything accidentally. (Your extensive suite of tests wouldn't allow me to break anything anyway.)

akprasad commented 8 months ago

The lack of rule logging here is making some other debugging difficult, so I'll take a look at the refactor.

akprasad commented 8 months ago

I've implemented a fix for this locally and will push it out in the next round of cleanup. As illustration, here's the case you mentioned above:

image
akprasad commented 8 months ago

Pushed.