
(FPCore (x y z t a b c) :precision binary64 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))
double code(double x, double y, double z, double t, double a, double b, double c) {
return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
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, a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((((x * 9.0d0) * y) - (((z * 4.0d0) * t) * a)) + b) / (z * c)
end function
public static double code(double x, double y, double z, double t, double a, double b, double c) {
return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
def code(x, y, z, t, a, b, c): return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c)
function code(x, y, z, t, a, b, c) return Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c)) end
function tmp = code(x, y, z, t, a, b, c) tmp = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c); end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] - N[(N[(N[(z * 4.0), $MachinePrecision] * t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b c) :precision binary64 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))
double code(double x, double y, double z, double t, double a, double b, double c) {
return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
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, a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((((x * 9.0d0) * y) - (((z * 4.0d0) * t) * a)) + b) / (z * c)
end function
public static double code(double x, double y, double z, double t, double a, double b, double c) {
return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
def code(x, y, z, t, a, b, c): return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c)
function code(x, y, z, t, a, b, c) return Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c)) end
function tmp = code(x, y, z, t, a, b, c) tmp = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c); end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] - N[(N[(N[(z * 4.0), $MachinePrecision] * t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\end{array}
c\_m = (fabs.f64 c)
c\_s = (copysign.f64 #s(literal 1 binary64) c)
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
(FPCore (c_s x y z t a b c_m)
:precision binary64
(let* ((t_1 (fma (* y x) 9.0 b)))
(*
c_s
(if (<= c_m 2.8e-99)
(/ (+ (- (* (* x 9.0) y) (* (* 4.0 z) (* a t))) b) (* z c_m))
(if (<= c_m 2.05e+141)
(* (fma (/ a c_m) -4.0 (/ t_1 (* (* t z) c_m))) t)
(if (<= c_m 1.22e+225)
(+
(/ b (* c_m z))
(fma (* (/ x c_m) 9.0) (/ y z) (* (/ (* a t) c_m) -4.0)))
(* (fma (/ t c_m) 4.0 (/ (/ (/ t_1 c_m) z) (- a))) (- a))))))))c\_m = fabs(c);
c\_s = copysign(1.0, c);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
double code(double c_s, double x, double y, double z, double t, double a, double b, double c_m) {
double t_1 = fma((y * x), 9.0, b);
double tmp;
if (c_m <= 2.8e-99) {
tmp = ((((x * 9.0) * y) - ((4.0 * z) * (a * t))) + b) / (z * c_m);
} else if (c_m <= 2.05e+141) {
tmp = fma((a / c_m), -4.0, (t_1 / ((t * z) * c_m))) * t;
} else if (c_m <= 1.22e+225) {
tmp = (b / (c_m * z)) + fma(((x / c_m) * 9.0), (y / z), (((a * t) / c_m) * -4.0));
} else {
tmp = fma((t / c_m), 4.0, (((t_1 / c_m) / z) / -a)) * -a;
}
return c_s * tmp;
}
c\_m = abs(c) c\_s = copysign(1.0, c) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) function code(c_s, x, y, z, t, a, b, c_m) t_1 = fma(Float64(y * x), 9.0, b) tmp = 0.0 if (c_m <= 2.8e-99) tmp = Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(4.0 * z) * Float64(a * t))) + b) / Float64(z * c_m)); elseif (c_m <= 2.05e+141) tmp = Float64(fma(Float64(a / c_m), -4.0, Float64(t_1 / Float64(Float64(t * z) * c_m))) * t); elseif (c_m <= 1.22e+225) tmp = Float64(Float64(b / Float64(c_m * z)) + fma(Float64(Float64(x / c_m) * 9.0), Float64(y / z), Float64(Float64(Float64(a * t) / c_m) * -4.0))); else tmp = Float64(fma(Float64(t / c_m), 4.0, Float64(Float64(Float64(t_1 / c_m) / z) / Float64(-a))) * Float64(-a)); end return Float64(c_s * tmp) end
c\_m = N[Abs[c], $MachinePrecision]
c\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
code[c$95$s_, x_, y_, z_, t_, a_, b_, c$95$m_] := Block[{t$95$1 = N[(N[(y * x), $MachinePrecision] * 9.0 + b), $MachinePrecision]}, N[(c$95$s * If[LessEqual[c$95$m, 2.8e-99], N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] - N[(N[(4.0 * z), $MachinePrecision] * N[(a * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c$95$m), $MachinePrecision]), $MachinePrecision], If[LessEqual[c$95$m, 2.05e+141], N[(N[(N[(a / c$95$m), $MachinePrecision] * -4.0 + N[(t$95$1 / N[(N[(t * z), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[c$95$m, 1.22e+225], N[(N[(b / N[(c$95$m * z), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(x / c$95$m), $MachinePrecision] * 9.0), $MachinePrecision] * N[(y / z), $MachinePrecision] + N[(N[(N[(a * t), $MachinePrecision] / c$95$m), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t / c$95$m), $MachinePrecision] * 4.0 + N[(N[(N[(t$95$1 / c$95$m), $MachinePrecision] / z), $MachinePrecision] / (-a)), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]]]]), $MachinePrecision]]
\begin{array}{l}
c\_m = \left|c\right|
\\
c\_s = \mathsf{copysign}\left(1, c\right)
\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y \cdot x, 9, b\right)\\
c\_s \cdot \begin{array}{l}
\mathbf{if}\;c\_m \leq 2.8 \cdot 10^{-99}:\\
\;\;\;\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(4 \cdot z\right) \cdot \left(a \cdot t\right)\right) + b}{z \cdot c\_m}\\
\mathbf{elif}\;c\_m \leq 2.05 \cdot 10^{+141}:\\
\;\;\;\;\mathsf{fma}\left(\frac{a}{c\_m}, -4, \frac{t\_1}{\left(t \cdot z\right) \cdot c\_m}\right) \cdot t\\
\mathbf{elif}\;c\_m \leq 1.22 \cdot 10^{+225}:\\
\;\;\;\;\frac{b}{c\_m \cdot z} + \mathsf{fma}\left(\frac{x}{c\_m} \cdot 9, \frac{y}{z}, \frac{a \cdot t}{c\_m} \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{c\_m}, 4, \frac{\frac{\frac{t\_1}{c\_m}}{z}}{-a}\right) \cdot \left(-a\right)\\
\end{array}
\end{array}
\end{array}
if c < 2.8000000000000001e-99Initial program 82.2%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6485.0
Applied rewrites85.0%
if 2.8000000000000001e-99 < c < 2.05000000000000011e141Initial program 76.9%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.8%
if 2.05000000000000011e141 < c < 1.22e225Initial program 65.0%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites79.6%
Taylor expanded in b around 0
lower--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
frac-timesN/A
lower-neg.f64N/A
associate-*r/N/A
Applied rewrites92.7%
if 1.22e225 < c Initial program 52.7%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites75.4%
Final simplification83.5%
c\_m = (fabs.f64 c)
c\_s = (copysign.f64 #s(literal 1 binary64) c)
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
(FPCore (c_s x y z t a b c_m)
:precision binary64
(let* ((t_1 (fma (* y x) 9.0 b)))
(*
c_s
(if (<= a -2.2e-149)
(* (fma (/ a c_m) -4.0 (/ t_1 (* (* t z) c_m))) t)
(if (<= a 4.6e-7)
(+
(/ b (* c_m z))
(fma (* (/ x c_m) 9.0) (/ y z) (* (/ (* a t) c_m) -4.0)))
(* (fma (/ t c_m) 4.0 (/ (/ (/ t_1 c_m) z) (- a))) (- a)))))))c\_m = fabs(c);
c\_s = copysign(1.0, c);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
double code(double c_s, double x, double y, double z, double t, double a, double b, double c_m) {
double t_1 = fma((y * x), 9.0, b);
double tmp;
if (a <= -2.2e-149) {
tmp = fma((a / c_m), -4.0, (t_1 / ((t * z) * c_m))) * t;
} else if (a <= 4.6e-7) {
tmp = (b / (c_m * z)) + fma(((x / c_m) * 9.0), (y / z), (((a * t) / c_m) * -4.0));
} else {
tmp = fma((t / c_m), 4.0, (((t_1 / c_m) / z) / -a)) * -a;
}
return c_s * tmp;
}
c\_m = abs(c) c\_s = copysign(1.0, c) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) function code(c_s, x, y, z, t, a, b, c_m) t_1 = fma(Float64(y * x), 9.0, b) tmp = 0.0 if (a <= -2.2e-149) tmp = Float64(fma(Float64(a / c_m), -4.0, Float64(t_1 / Float64(Float64(t * z) * c_m))) * t); elseif (a <= 4.6e-7) tmp = Float64(Float64(b / Float64(c_m * z)) + fma(Float64(Float64(x / c_m) * 9.0), Float64(y / z), Float64(Float64(Float64(a * t) / c_m) * -4.0))); else tmp = Float64(fma(Float64(t / c_m), 4.0, Float64(Float64(Float64(t_1 / c_m) / z) / Float64(-a))) * Float64(-a)); end return Float64(c_s * tmp) end
c\_m = N[Abs[c], $MachinePrecision]
c\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
code[c$95$s_, x_, y_, z_, t_, a_, b_, c$95$m_] := Block[{t$95$1 = N[(N[(y * x), $MachinePrecision] * 9.0 + b), $MachinePrecision]}, N[(c$95$s * If[LessEqual[a, -2.2e-149], N[(N[(N[(a / c$95$m), $MachinePrecision] * -4.0 + N[(t$95$1 / N[(N[(t * z), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[a, 4.6e-7], N[(N[(b / N[(c$95$m * z), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(x / c$95$m), $MachinePrecision] * 9.0), $MachinePrecision] * N[(y / z), $MachinePrecision] + N[(N[(N[(a * t), $MachinePrecision] / c$95$m), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t / c$95$m), $MachinePrecision] * 4.0 + N[(N[(N[(t$95$1 / c$95$m), $MachinePrecision] / z), $MachinePrecision] / (-a)), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
c\_m = \left|c\right|
\\
c\_s = \mathsf{copysign}\left(1, c\right)
\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y \cdot x, 9, b\right)\\
c\_s \cdot \begin{array}{l}
\mathbf{if}\;a \leq -2.2 \cdot 10^{-149}:\\
\;\;\;\;\mathsf{fma}\left(\frac{a}{c\_m}, -4, \frac{t\_1}{\left(t \cdot z\right) \cdot c\_m}\right) \cdot t\\
\mathbf{elif}\;a \leq 4.6 \cdot 10^{-7}:\\
\;\;\;\;\frac{b}{c\_m \cdot z} + \mathsf{fma}\left(\frac{x}{c\_m} \cdot 9, \frac{y}{z}, \frac{a \cdot t}{c\_m} \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{c\_m}, 4, \frac{\frac{\frac{t\_1}{c\_m}}{z}}{-a}\right) \cdot \left(-a\right)\\
\end{array}
\end{array}
\end{array}
if a < -2.1999999999999998e-149Initial program 79.7%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites83.2%
if -2.1999999999999998e-149 < a < 4.5999999999999999e-7Initial program 80.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.7%
Taylor expanded in b around 0
lower--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
frac-timesN/A
lower-neg.f64N/A
associate-*r/N/A
Applied rewrites90.5%
if 4.5999999999999999e-7 < a Initial program 71.3%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.6%
Final simplification86.2%
c\_m = (fabs.f64 c)
c\_s = (copysign.f64 #s(literal 1 binary64) c)
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
(FPCore (c_s x y z t a b c_m)
:precision binary64
(*
c_s
(if (<= c_m 1.6e-86)
(*
(/
(fma (/ (* a t) b) -4.0 (fma (/ (/ (* y x) b) z) 9.0 (pow z -1.0)))
(- c_m))
(- b))
(if (<= c_m 1.22e+225)
(+
(/ b (* c_m z))
(fma (* (/ x c_m) 9.0) (/ y z) (* (/ (* a t) c_m) -4.0)))
(*
(fma (/ t c_m) 4.0 (/ (/ (/ (fma (* y x) 9.0 b) c_m) z) (- a)))
(- a))))))c\_m = fabs(c);
c\_s = copysign(1.0, c);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
double code(double c_s, double x, double y, double z, double t, double a, double b, double c_m) {
double tmp;
if (c_m <= 1.6e-86) {
tmp = (fma(((a * t) / b), -4.0, fma((((y * x) / b) / z), 9.0, pow(z, -1.0))) / -c_m) * -b;
} else if (c_m <= 1.22e+225) {
tmp = (b / (c_m * z)) + fma(((x / c_m) * 9.0), (y / z), (((a * t) / c_m) * -4.0));
} else {
tmp = fma((t / c_m), 4.0, (((fma((y * x), 9.0, b) / c_m) / z) / -a)) * -a;
}
return c_s * tmp;
}
c\_m = abs(c) c\_s = copysign(1.0, c) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) function code(c_s, x, y, z, t, a, b, c_m) tmp = 0.0 if (c_m <= 1.6e-86) tmp = Float64(Float64(fma(Float64(Float64(a * t) / b), -4.0, fma(Float64(Float64(Float64(y * x) / b) / z), 9.0, (z ^ -1.0))) / Float64(-c_m)) * Float64(-b)); elseif (c_m <= 1.22e+225) tmp = Float64(Float64(b / Float64(c_m * z)) + fma(Float64(Float64(x / c_m) * 9.0), Float64(y / z), Float64(Float64(Float64(a * t) / c_m) * -4.0))); else tmp = Float64(fma(Float64(t / c_m), 4.0, Float64(Float64(Float64(fma(Float64(y * x), 9.0, b) / c_m) / z) / Float64(-a))) * Float64(-a)); end return Float64(c_s * tmp) end
c\_m = N[Abs[c], $MachinePrecision]
c\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
code[c$95$s_, x_, y_, z_, t_, a_, b_, c$95$m_] := N[(c$95$s * If[LessEqual[c$95$m, 1.6e-86], N[(N[(N[(N[(N[(a * t), $MachinePrecision] / b), $MachinePrecision] * -4.0 + N[(N[(N[(N[(y * x), $MachinePrecision] / b), $MachinePrecision] / z), $MachinePrecision] * 9.0 + N[Power[z, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-c$95$m)), $MachinePrecision] * (-b)), $MachinePrecision], If[LessEqual[c$95$m, 1.22e+225], N[(N[(b / N[(c$95$m * z), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(x / c$95$m), $MachinePrecision] * 9.0), $MachinePrecision] * N[(y / z), $MachinePrecision] + N[(N[(N[(a * t), $MachinePrecision] / c$95$m), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t / c$95$m), $MachinePrecision] * 4.0 + N[(N[(N[(N[(N[(y * x), $MachinePrecision] * 9.0 + b), $MachinePrecision] / c$95$m), $MachinePrecision] / z), $MachinePrecision] / (-a)), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
c\_m = \left|c\right|
\\
c\_s = \mathsf{copysign}\left(1, c\right)
\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\
\\
c\_s \cdot \begin{array}{l}
\mathbf{if}\;c\_m \leq 1.6 \cdot 10^{-86}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a \cdot t}{b}, -4, \mathsf{fma}\left(\frac{\frac{y \cdot x}{b}}{z}, 9, {z}^{-1}\right)\right)}{-c\_m} \cdot \left(-b\right)\\
\mathbf{elif}\;c\_m \leq 1.22 \cdot 10^{+225}:\\
\;\;\;\;\frac{b}{c\_m \cdot z} + \mathsf{fma}\left(\frac{x}{c\_m} \cdot 9, \frac{y}{z}, \frac{a \cdot t}{c\_m} \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{c\_m}, 4, \frac{\frac{\frac{\mathsf{fma}\left(y \cdot x, 9, b\right)}{c\_m}}{z}}{-a}\right) \cdot \left(-a\right)\\
\end{array}
\end{array}
if c < 1.60000000000000003e-86Initial program 81.9%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites77.0%
Taylor expanded in c around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
Applied rewrites82.2%
if 1.60000000000000003e-86 < c < 1.22e225Initial program 74.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.1%
Taylor expanded in b around 0
lower--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
frac-timesN/A
lower-neg.f64N/A
associate-*r/N/A
Applied rewrites89.9%
if 1.22e225 < c Initial program 52.7%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites75.4%
Final simplification83.3%
c\_m = (fabs.f64 c)
c\_s = (copysign.f64 #s(literal 1 binary64) c)
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
(FPCore (c_s x y z t a b c_m)
:precision binary64
(*
c_s
(if (<= c_m 1.6e-86)
(*
(/
(fma (/ (* a t) b) -4.0 (fma (/ (/ (* y x) b) z) 9.0 (pow z -1.0)))
(- c_m))
(- b))
(+
(/ b (* c_m z))
(fma (* (/ x c_m) 9.0) (/ y z) (* (/ (* a t) c_m) -4.0))))))c\_m = fabs(c);
c\_s = copysign(1.0, c);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
double code(double c_s, double x, double y, double z, double t, double a, double b, double c_m) {
double tmp;
if (c_m <= 1.6e-86) {
tmp = (fma(((a * t) / b), -4.0, fma((((y * x) / b) / z), 9.0, pow(z, -1.0))) / -c_m) * -b;
} else {
tmp = (b / (c_m * z)) + fma(((x / c_m) * 9.0), (y / z), (((a * t) / c_m) * -4.0));
}
return c_s * tmp;
}
c\_m = abs(c) c\_s = copysign(1.0, c) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) function code(c_s, x, y, z, t, a, b, c_m) tmp = 0.0 if (c_m <= 1.6e-86) tmp = Float64(Float64(fma(Float64(Float64(a * t) / b), -4.0, fma(Float64(Float64(Float64(y * x) / b) / z), 9.0, (z ^ -1.0))) / Float64(-c_m)) * Float64(-b)); else tmp = Float64(Float64(b / Float64(c_m * z)) + fma(Float64(Float64(x / c_m) * 9.0), Float64(y / z), Float64(Float64(Float64(a * t) / c_m) * -4.0))); end return Float64(c_s * tmp) end
c\_m = N[Abs[c], $MachinePrecision]
c\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
code[c$95$s_, x_, y_, z_, t_, a_, b_, c$95$m_] := N[(c$95$s * If[LessEqual[c$95$m, 1.6e-86], N[(N[(N[(N[(N[(a * t), $MachinePrecision] / b), $MachinePrecision] * -4.0 + N[(N[(N[(N[(y * x), $MachinePrecision] / b), $MachinePrecision] / z), $MachinePrecision] * 9.0 + N[Power[z, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-c$95$m)), $MachinePrecision] * (-b)), $MachinePrecision], N[(N[(b / N[(c$95$m * z), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(x / c$95$m), $MachinePrecision] * 9.0), $MachinePrecision] * N[(y / z), $MachinePrecision] + N[(N[(N[(a * t), $MachinePrecision] / c$95$m), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
c\_m = \left|c\right|
\\
c\_s = \mathsf{copysign}\left(1, c\right)
\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\
\\
c\_s \cdot \begin{array}{l}
\mathbf{if}\;c\_m \leq 1.6 \cdot 10^{-86}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a \cdot t}{b}, -4, \mathsf{fma}\left(\frac{\frac{y \cdot x}{b}}{z}, 9, {z}^{-1}\right)\right)}{-c\_m} \cdot \left(-b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c\_m \cdot z} + \mathsf{fma}\left(\frac{x}{c\_m} \cdot 9, \frac{y}{z}, \frac{a \cdot t}{c\_m} \cdot -4\right)\\
\end{array}
\end{array}
if c < 1.60000000000000003e-86Initial program 81.9%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites77.0%
Taylor expanded in c around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
Applied rewrites82.2%
if 1.60000000000000003e-86 < c Initial program 68.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.7%
Taylor expanded in b around 0
lower--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
frac-timesN/A
lower-neg.f64N/A
associate-*r/N/A
Applied rewrites84.6%
Final simplification82.9%
c\_m = (fabs.f64 c)
c\_s = (copysign.f64 #s(literal 1 binary64) c)
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
(FPCore (c_s x y z t a b c_m)
:precision binary64
(let* ((t_1 (/ (* a t) c_m)))
(*
c_s
(if (<= z -9e-122)
(+ (/ b (* c_m z)) (fma (* (/ x c_m) 9.0) (/ y z) (* t_1 -4.0)))
(-
(fma
t_1
4.0
(* b (/ (- (/ (* -9.0 (* y x)) (* c_m b)) (pow c_m -1.0)) z))))))))c\_m = fabs(c);
c\_s = copysign(1.0, c);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
double code(double c_s, double x, double y, double z, double t, double a, double b, double c_m) {
double t_1 = (a * t) / c_m;
double tmp;
if (z <= -9e-122) {
tmp = (b / (c_m * z)) + fma(((x / c_m) * 9.0), (y / z), (t_1 * -4.0));
} else {
tmp = -fma(t_1, 4.0, (b * ((((-9.0 * (y * x)) / (c_m * b)) - pow(c_m, -1.0)) / z)));
}
return c_s * tmp;
}
c\_m = abs(c) c\_s = copysign(1.0, c) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) function code(c_s, x, y, z, t, a, b, c_m) t_1 = Float64(Float64(a * t) / c_m) tmp = 0.0 if (z <= -9e-122) tmp = Float64(Float64(b / Float64(c_m * z)) + fma(Float64(Float64(x / c_m) * 9.0), Float64(y / z), Float64(t_1 * -4.0))); else tmp = Float64(-fma(t_1, 4.0, Float64(b * Float64(Float64(Float64(Float64(-9.0 * Float64(y * x)) / Float64(c_m * b)) - (c_m ^ -1.0)) / z)))); end return Float64(c_s * tmp) end
c\_m = N[Abs[c], $MachinePrecision]
c\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
code[c$95$s_, x_, y_, z_, t_, a_, b_, c$95$m_] := Block[{t$95$1 = N[(N[(a * t), $MachinePrecision] / c$95$m), $MachinePrecision]}, N[(c$95$s * If[LessEqual[z, -9e-122], N[(N[(b / N[(c$95$m * z), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(x / c$95$m), $MachinePrecision] * 9.0), $MachinePrecision] * N[(y / z), $MachinePrecision] + N[(t$95$1 * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[(t$95$1 * 4.0 + N[(b * N[(N[(N[(N[(-9.0 * N[(y * x), $MachinePrecision]), $MachinePrecision] / N[(c$95$m * b), $MachinePrecision]), $MachinePrecision] - N[Power[c$95$m, -1.0], $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])]), $MachinePrecision]]
\begin{array}{l}
c\_m = \left|c\right|
\\
c\_s = \mathsf{copysign}\left(1, c\right)
\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\
\\
\begin{array}{l}
t_1 := \frac{a \cdot t}{c\_m}\\
c\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-122}:\\
\;\;\;\;\frac{b}{c\_m \cdot z} + \mathsf{fma}\left(\frac{x}{c\_m} \cdot 9, \frac{y}{z}, t\_1 \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;-\mathsf{fma}\left(t\_1, 4, b \cdot \frac{\frac{-9 \cdot \left(y \cdot x\right)}{c\_m \cdot b} - {c\_m}^{-1}}{z}\right)\\
\end{array}
\end{array}
\end{array}
if z < -8.99999999999999959e-122Initial program 71.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.4%
Taylor expanded in b around 0
lower--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
frac-timesN/A
lower-neg.f64N/A
associate-*r/N/A
Applied rewrites85.2%
if -8.99999999999999959e-122 < z Initial program 81.8%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.4%
Taylor expanded in z around -inf
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites86.8%
Final simplification86.2%
c\_m = (fabs.f64 c) c\_s = (copysign.f64 #s(literal 1 binary64) c) NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function. NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function. (FPCore (c_s x y z t a b c_m) :precision binary64 (* c_s (+ (/ b (* c_m z)) (fma (* (/ x c_m) 9.0) (/ y z) (* (/ (* a t) c_m) -4.0)))))
c\_m = fabs(c);
c\_s = copysign(1.0, c);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
assert(x < y && y < z && z < t && t < a && a < b && b < c_m);
double code(double c_s, double x, double y, double z, double t, double a, double b, double c_m) {
return c_s * ((b / (c_m * z)) + fma(((x / c_m) * 9.0), (y / z), (((a * t) / c_m) * -4.0)));
}
c\_m = abs(c) c\_s = copysign(1.0, c) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) x, y, z, t, a, b, c_m = sort([x, y, z, t, a, b, c_m]) function code(c_s, x, y, z, t, a, b, c_m) return Float64(c_s * Float64(Float64(b / Float64(c_m * z)) + fma(Float64(Float64(x / c_m) * 9.0), Float64(y / z), Float64(Float64(Float64(a * t) / c_m) * -4.0)))) end
c\_m = N[Abs[c], $MachinePrecision]
c\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, b, and c_m should be sorted in increasing order before calling this function.
code[c$95$s_, x_, y_, z_, t_, a_, b_, c$95$m_] := N[(c$95$s * N[(N[(b / N[(c$95$m * z), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(x / c$95$m), $MachinePrecision] * 9.0), $MachinePrecision] * N[(y / z), $MachinePrecision] + N[(N[(N[(a * t), $MachinePrecision] / c$95$m), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c\_m = \left|c\right|
\\
c\_s = \mathsf{copysign}\left(1, c\right)
\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\\\
[x, y, z, t, a, b, c_m] = \mathsf{sort}([x, y, z, t, a, b, c_m])\\
\\
c\_s \cdot \left(\frac{b}{c\_m \cdot z} + \mathsf{fma}\left(\frac{x}{c\_m} \cdot 9, \frac{y}{z}, \frac{a \cdot t}{c\_m} \cdot -4\right)\right)
\end{array}
Initial program 77.9%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites75.7%
Taylor expanded in b around 0
lower--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
mul-1-negN/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
frac-timesN/A
lower-neg.f64N/A
associate-*r/N/A
Applied rewrites79.9%
Final simplification79.9%
herbie shell --seed 2025057
(FPCore (x y z t a b c)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, J"
:precision binary64
:alt
(! :herbie-platform default (if (< (/ (+ (- (* (* x 9) y) (* (* (* z 4) t) a)) b) (* z c)) -220031348160821/200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ (+ (- (* (* x 9) y) (* (* z 4) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9) y) (* (* (* z 4) t) a)) b) (* z c)) 0) (/ (/ (+ (- (* (* x 9) y) (* (* (* z 4) t) a)) b) z) c) (if (< (/ (+ (- (* (* x 9) y) (* (* (* z 4) t) a)) b) (* z c)) 365902434742109/31250000000000000000000000000000000000000000000000000000000000000000) (/ (+ (- (* (* x 9) y) (* (* z 4) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9) y) (* (* (* z 4) t) a)) b) (* z c)) 28768236795461370000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (+ (* (* 9 (/ y c)) (/ x z)) (/ b (* c z))) (* 4 (/ (* a t) c))) (if (< (/ (+ (- (* (* x 9) y) (* (* (* z 4) t) a)) b) (* z c)) 138385150424563190000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ (+ (- (* (* x 9) y) (* (* z 4) (* t a))) b) (* z c)) (- (+ (* 9 (* (/ y (* c z)) x)) (/ b (* c z))) (* 4 (/ (* a t) c)))))))))
(/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))