From 9ef77d9ba7316f975e0385d6817e5b1b3e7f4257 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 23 Apr 2023 11:33:56 -0500 Subject: [PATCH] Expand on variables in formulas --- docs/guide/important-concepts/formulas.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/guide/important-concepts/formulas.md b/docs/guide/important-concepts/formulas.md index 16d5452f..9ed06b06 100644 --- a/docs/guide/important-concepts/formulas.md +++ b/docs/guide/important-concepts/formulas.md @@ -20,6 +20,10 @@ const myRepeatable = createRepeatable(() => ({ For inverting and integrating, formulas should have a single variable, which serves as the input. Although other parts of the formula can be computed values, they must not be dependent on the input variable for inverting or integrating purposes. Formulas work correctly as long as changing other parts of the formula doesn't affect the input variable. +The variable is defined by wrapping the input to the formula in `Formula.variable`. In the cost requirement example above, the repeatable's `amount` is the input to the variable. That means inverting the function would calculate the amount based on the cost, and integrating would be finding the area under the curve where the repeatable's `amount` is the x axis and the output of the formula is the y axis. + +If the cost formula had not marked a variable, e.g. `Formula.pow(myRepeatable.amount, 1.05).times(100)` then the formula would not be invertible or integrable, and would throw an error if either operation was tried. While `evaluate()` will work as expected, passing a value to `evaluate()` will not, as it will not know what value to override. + ### Invertibility and Integrability Certain operations may not support inverting or integrating. Functions such as rounding or clamping are non-invertible, while others like super-log are non-integrable. You may only use a single complex operation in addition to add, sub, mult, and div operations. For formulas with two complex operations, a [custom formula](#custom-formulas) is required.