Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3

Percentage Accurate: 52.7% → 52.9%
Time: 4.1s
Alternatives: 4
Speedup: 1.3×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot y - z \cdot y\right) \cdot t \end{array} \]
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
double code(double x, double y, double z, double t) {
	return ((x * y) - (z * y)) * t;
}
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(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = ((x * y) - (z * y)) * t
end function
public static double code(double x, double y, double z, double t) {
	return ((x * y) - (z * y)) * t;
}
def code(x, y, z, t):
	return ((x * y) - (z * y)) * t
function code(x, y, z, t)
	return Float64(Float64(Float64(x * y) - Float64(z * y)) * t)
end
function tmp = code(x, y, z, t)
	tmp = ((x * y) - (z * y)) * t;
end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot y - z \cdot y\right) \cdot t
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 4 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 52.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot y - z \cdot y\right) \cdot t \end{array} \]
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
double code(double x, double y, double z, double t) {
	return ((x * y) - (z * y)) * t;
}
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(x, y, z, t)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = ((x * y) - (z * y)) * t
end function
public static double code(double x, double y, double z, double t) {
	return ((x * y) - (z * y)) * t;
}
def code(x, y, z, t):
	return ((x * y) - (z * y)) * t
function code(x, y, z, t)
	return Float64(Float64(Float64(x * y) - Float64(z * y)) * t)
end
function tmp = code(x, y, z, t)
	tmp = ((x * y) - (z * y)) * t;
end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot y - z \cdot y\right) \cdot t
\end{array}

Alternative 1: 52.9% accurate, 0.4× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ t_m = \left|t\right| \\ [x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\ \\ \begin{array}{l} \mathbf{if}\;x \cdot y\_m - z \cdot y\_m \leq -4 \cdot 10^{+272}:\\ \;\;\;\;\left(\left(\left(z + x\right) \cdot \left(x - z\right)\right) \cdot \frac{t\_m}{z}\right) \cdot y\_m\\ \mathbf{else}:\\ \;\;\;\;\left(\left(x - z\right) \cdot y\_m\right) \cdot t\_m\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
t_m = (fabs.f64 t)
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
(FPCore (x y_m z t_m)
 :precision binary64
 (if (<= (- (* x y_m) (* z y_m)) -4e+272)
   (* (* (* (+ z x) (- x z)) (/ t_m z)) y_m)
   (* (* (- x z) y_m) t_m)))
y_m = fabs(y);
t_m = fabs(t);
assert(x < y_m && y_m < z && z < t_m);
double code(double x, double y_m, double z, double t_m) {
	double tmp;
	if (((x * y_m) - (z * y_m)) <= -4e+272) {
		tmp = (((z + x) * (x - z)) * (t_m / z)) * y_m;
	} else {
		tmp = ((x - z) * y_m) * t_m;
	}
	return tmp;
}
y_m =     private
t_m =     private
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
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(x, y_m, z, t_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8), intent (in) :: t_m
    real(8) :: tmp
    if (((x * y_m) - (z * y_m)) <= (-4d+272)) then
        tmp = (((z + x) * (x - z)) * (t_m / z)) * y_m
    else
        tmp = ((x - z) * y_m) * t_m
    end if
    code = tmp
end function
y_m = Math.abs(y);
t_m = Math.abs(t);
assert x < y_m && y_m < z && z < t_m;
public static double code(double x, double y_m, double z, double t_m) {
	double tmp;
	if (((x * y_m) - (z * y_m)) <= -4e+272) {
		tmp = (((z + x) * (x - z)) * (t_m / z)) * y_m;
	} else {
		tmp = ((x - z) * y_m) * t_m;
	}
	return tmp;
}
y_m = math.fabs(y)
t_m = math.fabs(t)
[x, y_m, z, t_m] = sort([x, y_m, z, t_m])
def code(x, y_m, z, t_m):
	tmp = 0
	if ((x * y_m) - (z * y_m)) <= -4e+272:
		tmp = (((z + x) * (x - z)) * (t_m / z)) * y_m
	else:
		tmp = ((x - z) * y_m) * t_m
	return tmp
y_m = abs(y)
t_m = abs(t)
x, y_m, z, t_m = sort([x, y_m, z, t_m])
function code(x, y_m, z, t_m)
	tmp = 0.0
	if (Float64(Float64(x * y_m) - Float64(z * y_m)) <= -4e+272)
		tmp = Float64(Float64(Float64(Float64(z + x) * Float64(x - z)) * Float64(t_m / z)) * y_m);
	else
		tmp = Float64(Float64(Float64(x - z) * y_m) * t_m);
	end
	return tmp
end
y_m = abs(y);
t_m = abs(t);
x, y_m, z, t_m = num2cell(sort([x, y_m, z, t_m])){:}
function tmp_2 = code(x, y_m, z, t_m)
	tmp = 0.0;
	if (((x * y_m) - (z * y_m)) <= -4e+272)
		tmp = (((z + x) * (x - z)) * (t_m / z)) * y_m;
	else
		tmp = ((x - z) * y_m) * t_m;
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
t_m = N[Abs[t], $MachinePrecision]
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
code[x_, y$95$m_, z_, t$95$m_] := If[LessEqual[N[(N[(x * y$95$m), $MachinePrecision] - N[(z * y$95$m), $MachinePrecision]), $MachinePrecision], -4e+272], N[(N[(N[(N[(z + x), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision] * N[(t$95$m / z), $MachinePrecision]), $MachinePrecision] * y$95$m), $MachinePrecision], N[(N[(N[(x - z), $MachinePrecision] * y$95$m), $MachinePrecision] * t$95$m), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
t_m = \left|t\right|
\\
[x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y\_m - z \cdot y\_m \leq -4 \cdot 10^{+272}:\\
\;\;\;\;\left(\left(\left(z + x\right) \cdot \left(x - z\right)\right) \cdot \frac{t\_m}{z}\right) \cdot y\_m\\

\mathbf{else}:\\
\;\;\;\;\left(\left(x - z\right) \cdot y\_m\right) \cdot t\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z y)) < -4.0000000000000003e272

    1. Initial program 52.7%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Applied rewrites47.6%

      \[\leadsto \color{blue}{\left(\left(x - z\right) \cdot t\right) \cdot y} \]
    3. Applied rewrites36.0%

      \[\leadsto \color{blue}{\left(\left(\left(z + x\right) \cdot \left(x - z\right)\right) \cdot \frac{t}{z + x}\right)} \cdot y \]
    4. Taylor expanded in x around 0

      \[\leadsto \left(\left(\left(z + x\right) \cdot \left(x - z\right)\right) \cdot \color{blue}{\frac{t}{z}}\right) \cdot y \]
    5. Applied rewrites26.6%

      \[\leadsto \left(\left(\left(z + x\right) \cdot \left(x - z\right)\right) \cdot \color{blue}{\frac{t}{z}}\right) \cdot y \]

    if -4.0000000000000003e272 < (-.f64 (*.f64 x y) (*.f64 z y))

    1. Initial program 52.7%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Applied rewrites52.9%

      \[\leadsto \color{blue}{\left(\left(x - z\right) \cdot y\right) \cdot t} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 52.7% accurate, 1.3× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ t_m = \left|t\right| \\ [x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\ \\ \left(\left(x - z\right) \cdot y\_m\right) \cdot t\_m \end{array} \]
y_m = (fabs.f64 y)
t_m = (fabs.f64 t)
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
(FPCore (x y_m z t_m) :precision binary64 (* (* (- x z) y_m) t_m))
y_m = fabs(y);
t_m = fabs(t);
assert(x < y_m && y_m < z && z < t_m);
double code(double x, double y_m, double z, double t_m) {
	return ((x - z) * y_m) * t_m;
}
y_m =     private
t_m =     private
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
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(x, y_m, z, t_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8), intent (in) :: t_m
    code = ((x - z) * y_m) * t_m
end function
y_m = Math.abs(y);
t_m = Math.abs(t);
assert x < y_m && y_m < z && z < t_m;
public static double code(double x, double y_m, double z, double t_m) {
	return ((x - z) * y_m) * t_m;
}
y_m = math.fabs(y)
t_m = math.fabs(t)
[x, y_m, z, t_m] = sort([x, y_m, z, t_m])
def code(x, y_m, z, t_m):
	return ((x - z) * y_m) * t_m
y_m = abs(y)
t_m = abs(t)
x, y_m, z, t_m = sort([x, y_m, z, t_m])
function code(x, y_m, z, t_m)
	return Float64(Float64(Float64(x - z) * y_m) * t_m)
end
y_m = abs(y);
t_m = abs(t);
x, y_m, z, t_m = num2cell(sort([x, y_m, z, t_m])){:}
function tmp = code(x, y_m, z, t_m)
	tmp = ((x - z) * y_m) * t_m;
end
y_m = N[Abs[y], $MachinePrecision]
t_m = N[Abs[t], $MachinePrecision]
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
code[x_, y$95$m_, z_, t$95$m_] := N[(N[(N[(x - z), $MachinePrecision] * y$95$m), $MachinePrecision] * t$95$m), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
t_m = \left|t\right|
\\
[x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\
\\
\left(\left(x - z\right) \cdot y\_m\right) \cdot t\_m
\end{array}
Derivation
  1. Initial program 52.7%

    \[\left(x \cdot y - z \cdot y\right) \cdot t \]
  2. Applied rewrites52.9%

    \[\leadsto \color{blue}{\left(\left(x - z\right) \cdot y\right) \cdot t} \]
  3. Add Preprocessing

Alternative 3: 48.4% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ t_m = \left|t\right| \\ [x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1.26 \cdot 10^{+116}:\\ \;\;\;\;t\_m \cdot \left(x \cdot y\_m\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(x - z\right) \cdot t\_m\right) \cdot y\_m\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
t_m = (fabs.f64 t)
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
(FPCore (x y_m z t_m)
 :precision binary64
 (if (<= x -1.26e+116) (* t_m (* x y_m)) (* (* (- x z) t_m) y_m)))
y_m = fabs(y);
t_m = fabs(t);
assert(x < y_m && y_m < z && z < t_m);
double code(double x, double y_m, double z, double t_m) {
	double tmp;
	if (x <= -1.26e+116) {
		tmp = t_m * (x * y_m);
	} else {
		tmp = ((x - z) * t_m) * y_m;
	}
	return tmp;
}
y_m =     private
t_m =     private
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
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(x, y_m, z, t_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8), intent (in) :: t_m
    real(8) :: tmp
    if (x <= (-1.26d+116)) then
        tmp = t_m * (x * y_m)
    else
        tmp = ((x - z) * t_m) * y_m
    end if
    code = tmp
end function
y_m = Math.abs(y);
t_m = Math.abs(t);
assert x < y_m && y_m < z && z < t_m;
public static double code(double x, double y_m, double z, double t_m) {
	double tmp;
	if (x <= -1.26e+116) {
		tmp = t_m * (x * y_m);
	} else {
		tmp = ((x - z) * t_m) * y_m;
	}
	return tmp;
}
y_m = math.fabs(y)
t_m = math.fabs(t)
[x, y_m, z, t_m] = sort([x, y_m, z, t_m])
def code(x, y_m, z, t_m):
	tmp = 0
	if x <= -1.26e+116:
		tmp = t_m * (x * y_m)
	else:
		tmp = ((x - z) * t_m) * y_m
	return tmp
y_m = abs(y)
t_m = abs(t)
x, y_m, z, t_m = sort([x, y_m, z, t_m])
function code(x, y_m, z, t_m)
	tmp = 0.0
	if (x <= -1.26e+116)
		tmp = Float64(t_m * Float64(x * y_m));
	else
		tmp = Float64(Float64(Float64(x - z) * t_m) * y_m);
	end
	return tmp
end
y_m = abs(y);
t_m = abs(t);
x, y_m, z, t_m = num2cell(sort([x, y_m, z, t_m])){:}
function tmp_2 = code(x, y_m, z, t_m)
	tmp = 0.0;
	if (x <= -1.26e+116)
		tmp = t_m * (x * y_m);
	else
		tmp = ((x - z) * t_m) * y_m;
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
t_m = N[Abs[t], $MachinePrecision]
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
code[x_, y$95$m_, z_, t$95$m_] := If[LessEqual[x, -1.26e+116], N[(t$95$m * N[(x * y$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - z), $MachinePrecision] * t$95$m), $MachinePrecision] * y$95$m), $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|
\\
t_m = \left|t\right|
\\
[x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.26 \cdot 10^{+116}:\\
\;\;\;\;t\_m \cdot \left(x \cdot y\_m\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left(x - z\right) \cdot t\_m\right) \cdot y\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.2599999999999999e116

    1. Initial program 52.7%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{t \cdot \left(x \cdot y\right)} \]
    3. Applied rewrites34.2%

      \[\leadsto \color{blue}{t \cdot \left(x \cdot y\right)} \]

    if -1.2599999999999999e116 < x

    1. Initial program 52.7%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Applied rewrites47.6%

      \[\leadsto \color{blue}{\left(\left(x - z\right) \cdot t\right) \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 34.2% accurate, 1.8× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ t_m = \left|t\right| \\ [x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\ \\ t\_m \cdot \left(x \cdot y\_m\right) \end{array} \]
y_m = (fabs.f64 y)
t_m = (fabs.f64 t)
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
(FPCore (x y_m z t_m) :precision binary64 (* t_m (* x y_m)))
y_m = fabs(y);
t_m = fabs(t);
assert(x < y_m && y_m < z && z < t_m);
double code(double x, double y_m, double z, double t_m) {
	return t_m * (x * y_m);
}
y_m =     private
t_m =     private
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
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(x, y_m, z, t_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8), intent (in) :: t_m
    code = t_m * (x * y_m)
end function
y_m = Math.abs(y);
t_m = Math.abs(t);
assert x < y_m && y_m < z && z < t_m;
public static double code(double x, double y_m, double z, double t_m) {
	return t_m * (x * y_m);
}
y_m = math.fabs(y)
t_m = math.fabs(t)
[x, y_m, z, t_m] = sort([x, y_m, z, t_m])
def code(x, y_m, z, t_m):
	return t_m * (x * y_m)
y_m = abs(y)
t_m = abs(t)
x, y_m, z, t_m = sort([x, y_m, z, t_m])
function code(x, y_m, z, t_m)
	return Float64(t_m * Float64(x * y_m))
end
y_m = abs(y);
t_m = abs(t);
x, y_m, z, t_m = num2cell(sort([x, y_m, z, t_m])){:}
function tmp = code(x, y_m, z, t_m)
	tmp = t_m * (x * y_m);
end
y_m = N[Abs[y], $MachinePrecision]
t_m = N[Abs[t], $MachinePrecision]
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
code[x_, y$95$m_, z_, t$95$m_] := N[(t$95$m * N[(x * y$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y_m = \left|y\right|
\\
t_m = \left|t\right|
\\
[x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\
\\
t\_m \cdot \left(x \cdot y\_m\right)
\end{array}
Derivation
  1. Initial program 52.7%

    \[\left(x \cdot y - z \cdot y\right) \cdot t \]
  2. Taylor expanded in x around inf

    \[\leadsto \color{blue}{t \cdot \left(x \cdot y\right)} \]
  3. Applied rewrites34.2%

    \[\leadsto \color{blue}{t \cdot \left(x \cdot y\right)} \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025159 
(FPCore (x y z t)
  :name "Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3"
  :precision binary64
  (* (- (* x y) (* z y)) t))