admin管理员组文章数量:1391925
I'm working on a Circom circuit to calculate the BMI (Body Mass Index) and check if a person is healthy based on their height and weight. However, I'm currently using a custom div
function for division and implementing a BMI check that isn't fully optimized. Below is the code I've written so far:
pragma circom 2.0.0;
function div(a, b) {
var r = a;
var q = 0;
while (r >= b) {
r = r - b;
q = q + 1;
}
return q;
}
template BMIChecker() {
// Declaration of signals.
signal input height; // in cm(centimeters)
signal input weight; // in kg(kilograms) * 10000000(10^7)
signal output isHealthy; // 1 if healthy, 0 if not healthy
var max = 25000;
var min = 18499;
signal height_squared <== height * height;
var bmi = div(weight, height_squared);
signal output inv <-- bmi > min && bmi < max ? 1 : 0;
log("isHealthy: ", inv);
isHealthy <== inv;
isHealthy === 1;
}
component main = BMIChecker();
Questions:
Optimization: The custom
div
function I've written performs repeated subtraction, but it seems inefficient for larger inputs. Is there a more efficient or optimized way to handle division in Circom?BMI Calculation: The BMI is calculated as
weight / (height^2)
. In my code, I manually calculate height squared and use a custom division function. Are there better ways to handle this within Circom, such as using specific circuits or built-in functions?Bounds Checking: In the current implementation, I am using a conditional expression to check if the BMI is between a defined range. Would this approach be the most efficient in Circom, or is there a better way to implement the check for a healthy BMI?
Any help with optimizing this BMI circuit for better performance or more efficient computation would be greatly appreciated!
本文标签: What is the best way to implement a custom div function and BMI check in CircomStack Overflow
版权声明:本文标题:What is the best way to implement a custom `div` function and BMI check in Circom? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744703029a2620673.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论