mlton

Horner's rule for two-variable polynomial

狂风中的少年 提交于 2020-01-21 11:26:07
问题 Horner's rule is used to simplify the process of evaluating a polynomial at specific variable values. https://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation#Standard_ML I've easily applied the method using SML, to a one variable polynomial, represented as an int list: fun horner coeffList x = foldr (fn (a, b) => a + b * x) (0.0) coeffList This works fine. We can then call it using: - val test = horner [1.0, 2.0, 3.0] 2.0; > val test = 17.0 : real Where [1.0, 2.0, 3.0] is the

Horner's rule for two-variable polynomial

末鹿安然 提交于 2019-12-01 18:01:36
Horner's rule is used to simplify the process of evaluating a polynomial at specific variable values. https://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation#Standard_ML I've easily applied the method using SML, to a one variable polynomial, represented as an int list: fun horner coeffList x = foldr (fn (a, b) => a + b * x) (0.0) coeffList This works fine. We can then call it using: - val test = horner [1.0, 2.0, 3.0] 2.0; > val test = 17.0 : real Where [1.0, 2.0, 3.0] is the list representing the polynomial coefficients, 2.0 is the value of the variable x, and 17.0 is the