
(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]
x \cdot \frac{\frac{y}{z} \cdot t}{t}
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]
x \cdot \frac{\frac{y}{z} \cdot t}{t}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (fmin (fabs x) (fabs y))) (t_2 (fmax (fabs x) (fabs y))))
(*
(copysign 1 x)
(*
(copysign 1 y)
(*
(copysign 1 z)
(if (<= (fabs z) 2000000000000)
(* (/ t_1 (fabs z)) t_2)
(* (/ t_2 (fabs z)) t_1)))))))double code(double x, double y, double z, double t) {
double t_1 = fmin(fabs(x), fabs(y));
double t_2 = fmax(fabs(x), fabs(y));
double tmp;
if (fabs(z) <= 2000000000000.0) {
tmp = (t_1 / fabs(z)) * t_2;
} else {
tmp = (t_2 / fabs(z)) * t_1;
}
return copysign(1.0, x) * (copysign(1.0, y) * (copysign(1.0, z) * tmp));
}
public static double code(double x, double y, double z, double t) {
double t_1 = fmin(Math.abs(x), Math.abs(y));
double t_2 = fmax(Math.abs(x), Math.abs(y));
double tmp;
if (Math.abs(z) <= 2000000000000.0) {
tmp = (t_1 / Math.abs(z)) * t_2;
} else {
tmp = (t_2 / Math.abs(z)) * t_1;
}
return Math.copySign(1.0, x) * (Math.copySign(1.0, y) * (Math.copySign(1.0, z) * tmp));
}
def code(x, y, z, t): t_1 = fmin(math.fabs(x), math.fabs(y)) t_2 = fmax(math.fabs(x), math.fabs(y)) tmp = 0 if math.fabs(z) <= 2000000000000.0: tmp = (t_1 / math.fabs(z)) * t_2 else: tmp = (t_2 / math.fabs(z)) * t_1 return math.copysign(1.0, x) * (math.copysign(1.0, y) * (math.copysign(1.0, z) * tmp))
function code(x, y, z, t) t_1 = fmin(abs(x), abs(y)) t_2 = fmax(abs(x), abs(y)) tmp = 0.0 if (abs(z) <= 2000000000000.0) tmp = Float64(Float64(t_1 / abs(z)) * t_2); else tmp = Float64(Float64(t_2 / abs(z)) * t_1); end return Float64(copysign(1.0, x) * Float64(copysign(1.0, y) * Float64(copysign(1.0, z) * tmp))) end
function tmp_2 = code(x, y, z, t) t_1 = min(abs(x), abs(y)); t_2 = max(abs(x), abs(y)); tmp = 0.0; if (abs(z) <= 2000000000000.0) tmp = (t_1 / abs(z)) * t_2; else tmp = (t_2 / abs(z)) * t_1; end tmp_2 = (sign(x) * abs(1.0)) * ((sign(y) * abs(1.0)) * ((sign(z) * abs(1.0)) * tmp)); end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Min[N[Abs[x], $MachinePrecision], N[Abs[y], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Max[N[Abs[x], $MachinePrecision], N[Abs[y], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[z], $MachinePrecision], 2000000000000], N[(N[(t$95$1 / N[Abs[z], $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision], N[(N[(t$95$2 / N[Abs[z], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_1 := \mathsf{min}\left(\left|x\right|, \left|y\right|\right)\\
t_2 := \mathsf{max}\left(\left|x\right|, \left|y\right|\right)\\
\mathsf{copysign}\left(1, x\right) \cdot \left(\mathsf{copysign}\left(1, y\right) \cdot \left(\mathsf{copysign}\left(1, z\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|z\right| \leq 2000000000000:\\
\;\;\;\;\frac{t\_1}{\left|z\right|} \cdot t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_2}{\left|z\right|} \cdot t\_1\\
\end{array}\right)\right)
\end{array}
if z < 2e12Initial program 81.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-inversesN/A
associate-*l/N/A
associate-*r/N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
mult-flip-revN/A
lower-/.f6492.0%
Applied rewrites92.0%
if 2e12 < z Initial program 81.1%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identity92.2%
lower-*.f64N/A
*-commutativeN/A
lower-*.f6492.2%
Applied rewrites92.2%
(FPCore (x y z t) :precision binary64 (* (copysign 1 x) (* (copysign 1 y) (* (/ (fmin (fabs x) (fabs y)) z) (fmax (fabs x) (fabs y))))))
double code(double x, double y, double z, double t) {
return copysign(1.0, x) * (copysign(1.0, y) * ((fmin(fabs(x), fabs(y)) / z) * fmax(fabs(x), fabs(y))));
}
public static double code(double x, double y, double z, double t) {
return Math.copySign(1.0, x) * (Math.copySign(1.0, y) * ((fmin(Math.abs(x), Math.abs(y)) / z) * fmax(Math.abs(x), Math.abs(y))));
}
def code(x, y, z, t): return math.copysign(1.0, x) * (math.copysign(1.0, y) * ((fmin(math.fabs(x), math.fabs(y)) / z) * fmax(math.fabs(x), math.fabs(y))))
function code(x, y, z, t) return Float64(copysign(1.0, x) * Float64(copysign(1.0, y) * Float64(Float64(fmin(abs(x), abs(y)) / z) * fmax(abs(x), abs(y))))) end
function tmp = code(x, y, z, t) tmp = (sign(x) * abs(1.0)) * ((sign(y) * abs(1.0)) * ((min(abs(x), abs(y)) / z) * max(abs(x), abs(y)))); end
code[x_, y_, z_, t_] := N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[(N[Min[N[Abs[x], $MachinePrecision], N[Abs[y], $MachinePrecision]], $MachinePrecision] / z), $MachinePrecision] * N[Max[N[Abs[x], $MachinePrecision], N[Abs[y], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \left(\mathsf{copysign}\left(1, y\right) \cdot \left(\frac{\mathsf{min}\left(\left|x\right|, \left|y\right|\right)}{z} \cdot \mathsf{max}\left(\left|x\right|, \left|y\right|\right)\right)\right)
Initial program 81.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-inversesN/A
associate-*l/N/A
associate-*r/N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
mult-flip-revN/A
lower-/.f6492.0%
Applied rewrites92.0%
herbie shell --seed 2025271 -o generate:evaluate
(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)))