
(FPCore (x y z t a b c) :precision binary64 (+ (- (+ (* x y) (/ (* z t) 16.0)) (/ (* a b) 4.0)) c))
double code(double x, double y, double z, double t, double a, double b, double c) {
return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
}
real(8) function code(x, y, z, t, a, b, c)
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 * y) + ((z * t) / 16.0d0)) - ((a * b) / 4.0d0)) + c
end function
public static double code(double x, double y, double z, double t, double a, double b, double c) {
return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
}
def code(x, y, z, t, a, b, c): return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c
function code(x, y, z, t, a, b, c) return Float64(Float64(Float64(Float64(x * y) + Float64(Float64(z * t) / 16.0)) - Float64(Float64(a * b) / 4.0)) + c) end
function tmp = code(x, y, z, t, a, b, c) tmp = (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c; end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] / 16.0), $MachinePrecision]), $MachinePrecision] - N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b c) :precision binary64 (+ (- (+ (* x y) (/ (* z t) 16.0)) (/ (* a b) 4.0)) c))
double code(double x, double y, double z, double t, double a, double b, double c) {
return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
}
real(8) function code(x, y, z, t, a, b, c)
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 * y) + ((z * t) / 16.0d0)) - ((a * b) / 4.0d0)) + c
end function
public static double code(double x, double y, double z, double t, double a, double b, double c) {
return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
}
def code(x, y, z, t, a, b, c): return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c
function code(x, y, z, t, a, b, c) return Float64(Float64(Float64(Float64(x * y) + Float64(Float64(z * t) / 16.0)) - Float64(Float64(a * b) / 4.0)) + c) end
function tmp = code(x, y, z, t, a, b, c) tmp = (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c; end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] / 16.0), $MachinePrecision]), $MachinePrecision] - N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c
\end{array}
(FPCore (x y z t a b c) :precision binary64 (fma y x (fma (* b -0.25) a (fma z (* t 0.0625) c))))
double code(double x, double y, double z, double t, double a, double b, double c) {
return fma(y, x, fma((b * -0.25), a, fma(z, (t * 0.0625), c)));
}
function code(x, y, z, t, a, b, c) return fma(y, x, fma(Float64(b * -0.25), a, fma(z, Float64(t * 0.0625), c))) end
code[x_, y_, z_, t_, a_, b_, c_] := N[(y * x + N[(N[(b * -0.25), $MachinePrecision] * a + N[(z * N[(t * 0.0625), $MachinePrecision] + c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(b \cdot -0.25, a, \mathsf{fma}\left(z, t \cdot 0.0625, c\right)\right)\right)
\end{array}
Initial program 97.2%
lift-+.f64N/A
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
Applied rewrites98.8%
lift-+.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f6499.2
Applied rewrites99.2%
(FPCore (x y z t a b c)
:precision binary64
(let* ((t_1 (fma y x (* 0.0625 (* z t))))
(t_2 (+ (* y x) (/ (* z t) 16.0)))
(t_3 (fma y x (* -0.25 (* b a)))))
(if (<= t_2 -5e+189)
t_1
(if (<= t_2 -2e+35)
t_3
(if (<= t_2 1e+114)
(fma -0.25 (* b a) c)
(if (<= t_2 5e+277) t_3 t_1))))))
double code(double x, double y, double z, double t, double a, double b, double c) {
double t_1 = fma(y, x, (0.0625 * (z * t)));
double t_2 = (y * x) + ((z * t) / 16.0);
double t_3 = fma(y, x, (-0.25 * (b * a)));
double tmp;
if (t_2 <= -5e+189) {
tmp = t_1;
} else if (t_2 <= -2e+35) {
tmp = t_3;
} else if (t_2 <= 1e+114) {
tmp = fma(-0.25, (b * a), c);
} else if (t_2 <= 5e+277) {
tmp = t_3;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b, c) t_1 = fma(y, x, Float64(0.0625 * Float64(z * t))) t_2 = Float64(Float64(y * x) + Float64(Float64(z * t) / 16.0)) t_3 = fma(y, x, Float64(-0.25 * Float64(b * a))) tmp = 0.0 if (t_2 <= -5e+189) tmp = t_1; elseif (t_2 <= -2e+35) tmp = t_3; elseif (t_2 <= 1e+114) tmp = fma(-0.25, Float64(b * a), c); elseif (t_2 <= 5e+277) tmp = t_3; else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(y * x + N[(0.0625 * N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * x), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] / 16.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(y * x + N[(-0.25 * N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+189], t$95$1, If[LessEqual[t$95$2, -2e+35], t$95$3, If[LessEqual[t$95$2, 1e+114], N[(-0.25 * N[(b * a), $MachinePrecision] + c), $MachinePrecision], If[LessEqual[t$95$2, 5e+277], t$95$3, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, x, 0.0625 \cdot \left(z \cdot t\right)\right)\\
t_2 := y \cdot x + \frac{z \cdot t}{16}\\
t_3 := \mathsf{fma}\left(y, x, -0.25 \cdot \left(b \cdot a\right)\right)\\
\mathbf{if}\;t\_2 \leq -5 \cdot 10^{+189}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq -2 \cdot 10^{+35}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_2 \leq 10^{+114}:\\
\;\;\;\;\mathsf{fma}\left(-0.25, b \cdot a, c\right)\\
\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{+277}:\\
\;\;\;\;t\_3\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (/.f64 (*.f64 z t) #s(literal 16 binary64))) < -5.0000000000000004e189 or 4.99999999999999982e277 < (+.f64 (*.f64 x y) (/.f64 (*.f64 z t) #s(literal 16 binary64))) Initial program 93.6%
lift-+.f64N/A
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
Applied rewrites97.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower-*.f6489.2
Applied rewrites89.2%
if -5.0000000000000004e189 < (+.f64 (*.f64 x y) (/.f64 (*.f64 z t) #s(literal 16 binary64))) < -1.9999999999999999e35 or 1e114 < (+.f64 (*.f64 x y) (/.f64 (*.f64 z t) #s(literal 16 binary64))) < 4.99999999999999982e277Initial program 99.8%
lift-+.f64N/A
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
Applied rewrites99.8%
Taylor expanded in a around inf
lower-*.f64N/A
lower-*.f6456.2
Applied rewrites56.2%
if -1.9999999999999999e35 < (+.f64 (*.f64 x y) (/.f64 (*.f64 z t) #s(literal 16 binary64))) < 1e114Initial program 99.9%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6490.5
Applied rewrites90.5%
Taylor expanded in x around 0
Applied rewrites80.2%
Final simplification76.9%
herbie shell --seed 2024223
(FPCore (x y z t a b c)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, C"
:precision binary64
(+ (- (+ (* x y) (/ (* z t) 16.0)) (/ (* a b) 4.0)) c))