________________________________________________________________________

This file is part of Logtalk <https://logtalk.org/>  
Copyright 1998-2021 Paulo Moura <pmoura@logtalk.org>  
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
________________________________________________________________________


% start by loading the loading the example:

| ?- logtalk_load(functions(loader)).
...


% find the roots of some functions using each one of provided methods:

| ?- bisection::find_root(f1, 1.0, 2.3, 1.0e-15, Zero).

Zero = 2.0
yes

| ?- newton::find_root(f1, 1.0, 2.3, 1.0e-15, Zero).

Zero = 2.0
yes
| ?- muller::find_root(f1, 1.0, 2.3, 1.0e-15, Zero).

Zero = 2.0
yes

| ?- bisection::find_root(f2, 1.0, 1.3, 1.0e-15, Zero).

Zero = 1.25809265664599
yes

| ?- newton::find_root(f2, 1.0, 1.3, 1.0e-15, Zero).

Zero = 1.25809265664599
yes

| ?- muller::find_root(f2, 1.0, 1.3, 1.0e-15, Zero).

Zero = 1.25809265664599
yes

| ?- bisection::find_root(humps, -1.0, 2.0, 1.0e-15, Zero).

no

| ?- muller::find_root(humps, -1.0, 2.0, 1.0e-15, Zero).

Zero = 1.29954968258
yes

| ?- newton::find_root(humps, -1.0, 2.0, 1.0e-15, Zero).
ERROR: is/2: Arithmetic: evaluation error: `float_overflow'


% find the roots of some functions running all methods at once using multi-threading:

| ?- function_root::find_root(f1, 1.0, 2.3, 1.0e-15, Zero, Method).

Zero = 2.0
Method = bisection 
yes

| ?- function_root::find_root(f2, 1.0, 1.3, 1.0e-15, Zero, Method).

Zero = 1.25809265664599
Method = newton 
yes

| ?- function_root::find_root(f3, 0.0, 3.0, 1.0e-15, Zero, Method).

Zero = 1.4142135623731
Method = newton 
yes

| ?- function_root::find_root(f4, -1.0, 2.0, 1.0e-15, Zero, Method).

Zero = -8.88178419700125e-16
Method = bisection 
yes

| ?- function_root::find_root(humps, -1.0, 2.0, 1.0e-15, Zero, Method).

Zero = 1.29954968258482
Method = muller
yes
