
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / 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) * t) / t)
end function
public static double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
def code(x, y, z, t): return x * (((y / z) * t) / t)
function code(x, y, z, t) return Float64(x * Float64(Float64(Float64(y / z) * t) / t)) end
function tmp = code(x, y, z, t) tmp = x * (((y / z) * t) / t); end
code[x_, y_, z_, t_] := N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\end{array}
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / 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) * t) / t)
end function
public static double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
def code(x, y, z, t): return x * (((y / z) * t) / t)
function code(x, y, z, t) return Float64(x * Float64(Float64(Float64(y / z) * t) / t)) end
function tmp = code(x, y, z, t) tmp = x * (((y / z) * t) / t); end
code[x_, y_, z_, t_] := N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\end{array}
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
NOTE: x_m, y_m, z_m, and t should be sorted in increasing order before calling this function.
(FPCore (z_s y_s x_s x_m y_m z_m t)
:precision binary64
(*
z_s
(*
y_s
(*
x_s
(if (<= (* x_m (/ (* (/ y_m z_m) t) t)) 1e+28)
(* (/ y_m z_m) x_m)
(* (/ x_m z_m) y_m))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
assert(x_m < y_m && y_m < z_m && z_m < t);
double code(double z_s, double y_s, double x_s, double x_m, double y_m, double z_m, double t) {
double tmp;
if ((x_m * (((y_m / z_m) * t) / t)) <= 1e+28) {
tmp = (y_m / z_m) * x_m;
} else {
tmp = (x_m / z_m) * y_m;
}
return z_s * (y_s * (x_s * tmp));
}
x\_m = private
x\_s = private
y\_m = private
y\_s = private
z\_m = private
z\_s = private
NOTE: x_m, y_m, z_m, and t 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(z_s, y_s, x_s, x_m, y_m, z_m, t)
use fmin_fmax_functions
real(8), intent (in) :: z_s
real(8), intent (in) :: y_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8), intent (in) :: t
real(8) :: tmp
if ((x_m * (((y_m / z_m) * t) / t)) <= 1d+28) then
tmp = (y_m / z_m) * x_m
else
tmp = (x_m / z_m) * y_m
end if
code = z_s * (y_s * (x_s * tmp))
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
assert x_m < y_m && y_m < z_m && z_m < t;
public static double code(double z_s, double y_s, double x_s, double x_m, double y_m, double z_m, double t) {
double tmp;
if ((x_m * (((y_m / z_m) * t) / t)) <= 1e+28) {
tmp = (y_m / z_m) * x_m;
} else {
tmp = (x_m / z_m) * y_m;
}
return z_s * (y_s * (x_s * tmp));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) [x_m, y_m, z_m, t] = sort([x_m, y_m, z_m, t]) def code(z_s, y_s, x_s, x_m, y_m, z_m, t): tmp = 0 if (x_m * (((y_m / z_m) * t) / t)) <= 1e+28: tmp = (y_m / z_m) * x_m else: tmp = (x_m / z_m) * y_m return z_s * (y_s * (x_s * tmp))
x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) z\_m = abs(z) z\_s = copysign(1.0, z) x_m, y_m, z_m, t = sort([x_m, y_m, z_m, t]) function code(z_s, y_s, x_s, x_m, y_m, z_m, t) tmp = 0.0 if (Float64(x_m * Float64(Float64(Float64(y_m / z_m) * t) / t)) <= 1e+28) tmp = Float64(Float64(y_m / z_m) * x_m); else tmp = Float64(Float64(x_m / z_m) * y_m); end return Float64(z_s * Float64(y_s * Float64(x_s * tmp))) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
z\_m = abs(z);
z\_s = sign(z) * abs(1.0);
x_m, y_m, z_m, t = num2cell(sort([x_m, y_m, z_m, t])){:}
function tmp_2 = code(z_s, y_s, x_s, x_m, y_m, z_m, t)
tmp = 0.0;
if ((x_m * (((y_m / z_m) * t) / t)) <= 1e+28)
tmp = (y_m / z_m) * x_m;
else
tmp = (x_m / z_m) * y_m;
end
tmp_2 = z_s * (y_s * (x_s * tmp));
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, z_m, and t should be sorted in increasing order before calling this function.
code[z$95$s_, y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_, t_] := N[(z$95$s * N[(y$95$s * N[(x$95$s * If[LessEqual[N[(x$95$m * N[(N[(N[(y$95$m / z$95$m), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], 1e+28], N[(N[(y$95$m / z$95$m), $MachinePrecision] * x$95$m), $MachinePrecision], N[(N[(x$95$m / z$95$m), $MachinePrecision] * y$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
[x_m, y_m, z_m, t] = \mathsf{sort}([x_m, y_m, z_m, t])\\
\\
z\_s \cdot \left(y\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \cdot \frac{\frac{y\_m}{z\_m} \cdot t}{t} \leq 10^{+28}:\\
\;\;\;\;\frac{y\_m}{z\_m} \cdot x\_m\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{z\_m} \cdot y\_m\\
\end{array}\right)\right)
\end{array}
if (*.f64 x (/.f64 (*.f64 (/.f64 y z) t) t)) < 9.99999999999999958e27Initial program 96.1%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6499.7
Applied rewrites99.7%
if 9.99999999999999958e27 < (*.f64 x (/.f64 (*.f64 (/.f64 y z) t) t)) Initial program 66.1%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
associate-*r*N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6498.8
Applied rewrites98.8%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) z\_m = (fabs.f64 z) z\_s = (copysign.f64 #s(literal 1 binary64) z) NOTE: x_m, y_m, z_m, and t should be sorted in increasing order before calling this function. (FPCore (z_s y_s x_s x_m y_m z_m t) :precision binary64 (* z_s (* y_s (* x_s (* (/ x_m z_m) y_m)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
assert(x_m < y_m && y_m < z_m && z_m < t);
double code(double z_s, double y_s, double x_s, double x_m, double y_m, double z_m, double t) {
return z_s * (y_s * (x_s * ((x_m / z_m) * y_m)));
}
x\_m = private
x\_s = private
y\_m = private
y\_s = private
z\_m = private
z\_s = private
NOTE: x_m, y_m, z_m, and t 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(z_s, y_s, x_s, x_m, y_m, z_m, t)
use fmin_fmax_functions
real(8), intent (in) :: z_s
real(8), intent (in) :: y_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8), intent (in) :: t
code = z_s * (y_s * (x_s * ((x_m / z_m) * y_m)))
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
assert x_m < y_m && y_m < z_m && z_m < t;
public static double code(double z_s, double y_s, double x_s, double x_m, double y_m, double z_m, double t) {
return z_s * (y_s * (x_s * ((x_m / z_m) * y_m)));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) [x_m, y_m, z_m, t] = sort([x_m, y_m, z_m, t]) def code(z_s, y_s, x_s, x_m, y_m, z_m, t): return z_s * (y_s * (x_s * ((x_m / z_m) * y_m)))
x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) z\_m = abs(z) z\_s = copysign(1.0, z) x_m, y_m, z_m, t = sort([x_m, y_m, z_m, t]) function code(z_s, y_s, x_s, x_m, y_m, z_m, t) return Float64(z_s * Float64(y_s * Float64(x_s * Float64(Float64(x_m / z_m) * y_m)))) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
z\_m = abs(z);
z\_s = sign(z) * abs(1.0);
x_m, y_m, z_m, t = num2cell(sort([x_m, y_m, z_m, t])){:}
function tmp = code(z_s, y_s, x_s, x_m, y_m, z_m, t)
tmp = z_s * (y_s * (x_s * ((x_m / z_m) * y_m)));
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, z_m, and t should be sorted in increasing order before calling this function.
code[z$95$s_, y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_, t_] := N[(z$95$s * N[(y$95$s * N[(x$95$s * N[(N[(x$95$m / z$95$m), $MachinePrecision] * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
[x_m, y_m, z_m, t] = \mathsf{sort}([x_m, y_m, z_m, t])\\
\\
z\_s \cdot \left(y\_s \cdot \left(x\_s \cdot \left(\frac{x\_m}{z\_m} \cdot y\_m\right)\right)\right)
\end{array}
Initial program 81.1%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
associate-*r*N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6492.2
Applied rewrites92.2%
herbie shell --seed 2025101
(FPCore (x y z t)
:name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, B"
:precision binary64
(* x (/ (* (/ y z) t) t)))