Kahan p13 Example 2

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_1 := 2 - \frac{\frac{2}{t}}{1 + \frac{1}{t}}\\ t_2 := t\_1 \cdot t\_1\\ \frac{1 + t\_2}{2 + t\_2} \end{array} \end{array} \]
(FPCore (t)
 :precision binary64
 (let* ((t_1 (- 2.0 (/ (/ 2.0 t) (+ 1.0 (/ 1.0 t))))) (t_2 (* t_1 t_1)))
   (/ (+ 1.0 t_2) (+ 2.0 t_2))))
double code(double t) {
	double t_1 = 2.0 - ((2.0 / t) / (1.0 + (1.0 / t)));
	double t_2 = t_1 * t_1;
	return (1.0 + t_2) / (2.0 + t_2);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(t)
use fmin_fmax_functions
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: t_2
    t_1 = 2.0d0 - ((2.0d0 / t) / (1.0d0 + (1.0d0 / t)))
    t_2 = t_1 * t_1
    code = (1.0d0 + t_2) / (2.0d0 + t_2)
end function
public static double code(double t) {
	double t_1 = 2.0 - ((2.0 / t) / (1.0 + (1.0 / t)));
	double t_2 = t_1 * t_1;
	return (1.0 + t_2) / (2.0 + t_2);
}
def code(t):
	t_1 = 2.0 - ((2.0 / t) / (1.0 + (1.0 / t)))
	t_2 = t_1 * t_1
	return (1.0 + t_2) / (2.0 + t_2)
function code(t)
	t_1 = Float64(2.0 - Float64(Float64(2.0 / t) / Float64(1.0 + Float64(1.0 / t))))
	t_2 = Float64(t_1 * t_1)
	return Float64(Float64(1.0 + t_2) / Float64(2.0 + t_2))
end
function tmp = code(t)
	t_1 = 2.0 - ((2.0 / t) / (1.0 + (1.0 / t)));
	t_2 = t_1 * t_1;
	tmp = (1.0 + t_2) / (2.0 + t_2);
end
code[t_] := Block[{t$95$1 = N[(2.0 - N[(N[(2.0 / t), $MachinePrecision] / N[(1.0 + N[(1.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, N[(N[(1.0 + t$95$2), $MachinePrecision] / N[(2.0 + t$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := 2 - \frac{\frac{2}{t}}{1 + \frac{1}{t}}\\
t_2 := t\_1 \cdot t\_1\\
\frac{1 + t\_2}{2 + t\_2}
\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2025093 
(FPCore (t)
  :name "Kahan p13 Example 2"
  :precision binary64
  (/ (+ 1.0 (* (- 2.0 (/ (/ 2.0 t) (+ 1.0 (/ 1.0 t)))) (- 2.0 (/ (/ 2.0 t) (+ 1.0 (/ 1.0 t)))))) (+ 2.0 (* (- 2.0 (/ (/ 2.0 t) (+ 1.0 (/ 1.0 t)))) (- 2.0 (/ (/ 2.0 t) (+ 1.0 (/ 1.0 t))))))))

Please file a bug report with this information.

Backtrace

result arity mismatch; expected number of values not received expected: 2 received: 1 in: local-binding form arguments...: '((0.6666666620862377 14630026972.36943) . #f)LC
batch-prepare-points/home/nightlies/herbie/random-cleanup/src/core/sampling.rkt1230
prepend-argument/home/nightlies/herbie/random-cleanup/src/core/bsearch.rkt970
hash-ref!/usr/share/racket/collects/racket/private/more-scheme.rkt3772
pred/home/nightlies/herbie/random-cleanup/src/core/bsearch.rkt1404
binary-search-floats/home/nightlies/herbie/random-cleanup/src/core/bsearch.rkt690
sindices->spoints/home/nightlies/herbie/random-cleanup/src/core/bsearch.rkt1210
(unnamed)/usr/share/racket/collects/racket/contract/private/arrow-higher-order.rkt37933
f11.../match/compiler.rkt55940
make-regime!/home/nightlies/herbie/random-cleanup/src/core/mainloop.rkt2620
extract!/home/nightlies/herbie/random-cleanup/src/core/mainloop.rkt610
run-improve!/home/nightlies/herbie/random-cleanup/src/core/mainloop.rkt370
get-alternatives/home/nightlies/herbie/random-cleanup/src/api/sandbox.rkt610
(unnamed)/home/nightlies/herbie/random-cleanup/src/api/sandbox.rkt1936
(unnamed)/usr/share/racket/pkgs/profile-lib/main.rkt4010
profile-thunk/usr/share/racket/pkgs/profile-lib/main.rkt90
in-engine/home/nightlies/herbie/random-cleanup/src/api/sandbox.rkt2092
(unnamed)/usr/share/racket/collects/racket/engine.rkt4224