
(FPCore (x y z t) :precision binary64 (+ (* x (+ (+ (+ (+ y z) z) y) t)) (* y 5.0)))
double code(double x, double y, double z, double t) {
return (x * ((((y + z) + z) + y) + t)) + (y * 5.0);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * ((((y + z) + z) + y) + t)) + (y * 5.0d0)
end function
public static double code(double x, double y, double z, double t) {
return (x * ((((y + z) + z) + y) + t)) + (y * 5.0);
}
def code(x, y, z, t): return (x * ((((y + z) + z) + y) + t)) + (y * 5.0)
function code(x, y, z, t) return Float64(Float64(x * Float64(Float64(Float64(Float64(y + z) + z) + y) + t)) + Float64(y * 5.0)) end
function tmp = code(x, y, z, t) tmp = (x * ((((y + z) + z) + y) + t)) + (y * 5.0); end
code[x_, y_, z_, t_] := N[(N[(x * N[(N[(N[(N[(y + z), $MachinePrecision] + z), $MachinePrecision] + y), $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision] + N[(y * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right) + y \cdot 5
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (* x (+ (+ (+ (+ y z) z) y) t)) (* y 5.0)))
double code(double x, double y, double z, double t) {
return (x * ((((y + z) + z) + y) + t)) + (y * 5.0);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * ((((y + z) + z) + y) + t)) + (y * 5.0d0)
end function
public static double code(double x, double y, double z, double t) {
return (x * ((((y + z) + z) + y) + t)) + (y * 5.0);
}
def code(x, y, z, t): return (x * ((((y + z) + z) + y) + t)) + (y * 5.0)
function code(x, y, z, t) return Float64(Float64(x * Float64(Float64(Float64(Float64(y + z) + z) + y) + t)) + Float64(y * 5.0)) end
function tmp = code(x, y, z, t) tmp = (x * ((((y + z) + z) + y) + t)) + (y * 5.0); end
code[x_, y_, z_, t_] := N[(N[(x * N[(N[(N[(N[(y + z), $MachinePrecision] + z), $MachinePrecision] + y), $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision] + N[(y * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\left(\left(\left(y + z\right) + z\right) + y\right) + t\right) + y \cdot 5
\end{array}
(FPCore (x y z t) :precision binary64 (fma y 5.0 (* (fma (+ z y) 2.0 t) x)))
double code(double x, double y, double z, double t) {
return fma(y, 5.0, (fma((z + y), 2.0, t) * x));
}
function code(x, y, z, t) return fma(y, 5.0, Float64(fma(Float64(z + y), 2.0, t) * x)) end
code[x_, y_, z_, t_] := N[(y * 5.0 + N[(N[(N[(z + y), $MachinePrecision] * 2.0 + t), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 5, \mathsf{fma}\left(z + y, 2, t\right) \cdot x\right)
\end{array}
Initial program 100.0%
Taylor expanded in t around inf
+-commutativeN/A
associate-+l+N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
distribute-lft-inN/A
associate-*r/N/A
associate-*l/N/A
*-inversesN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
Applied rewrites89.8%
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (* 2.0 y) x)))
(if (<= x -3.1e+116)
t_1
(if (<= x -1.6e-47)
(* t x)
(if (<= x 1.28e-20) (* 5.0 y) (if (<= x 3e+194) (* t x) t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = (2.0 * y) * x;
double tmp;
if (x <= -3.1e+116) {
tmp = t_1;
} else if (x <= -1.6e-47) {
tmp = t * x;
} else if (x <= 1.28e-20) {
tmp = 5.0 * y;
} else if (x <= 3e+194) {
tmp = t * x;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = (2.0d0 * y) * x
if (x <= (-3.1d+116)) then
tmp = t_1
else if (x <= (-1.6d-47)) then
tmp = t * x
else if (x <= 1.28d-20) then
tmp = 5.0d0 * y
else if (x <= 3d+194) then
tmp = t * x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (2.0 * y) * x;
double tmp;
if (x <= -3.1e+116) {
tmp = t_1;
} else if (x <= -1.6e-47) {
tmp = t * x;
} else if (x <= 1.28e-20) {
tmp = 5.0 * y;
} else if (x <= 3e+194) {
tmp = t * x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (2.0 * y) * x tmp = 0 if x <= -3.1e+116: tmp = t_1 elif x <= -1.6e-47: tmp = t * x elif x <= 1.28e-20: tmp = 5.0 * y elif x <= 3e+194: tmp = t * x else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(2.0 * y) * x) tmp = 0.0 if (x <= -3.1e+116) tmp = t_1; elseif (x <= -1.6e-47) tmp = Float64(t * x); elseif (x <= 1.28e-20) tmp = Float64(5.0 * y); elseif (x <= 3e+194) tmp = Float64(t * x); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (2.0 * y) * x; tmp = 0.0; if (x <= -3.1e+116) tmp = t_1; elseif (x <= -1.6e-47) tmp = t * x; elseif (x <= 1.28e-20) tmp = 5.0 * y; elseif (x <= 3e+194) tmp = t * x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(2.0 * y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -3.1e+116], t$95$1, If[LessEqual[x, -1.6e-47], N[(t * x), $MachinePrecision], If[LessEqual[x, 1.28e-20], N[(5.0 * y), $MachinePrecision], If[LessEqual[x, 3e+194], N[(t * x), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(2 \cdot y\right) \cdot x\\
\mathbf{if}\;x \leq -3.1 \cdot 10^{+116}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -1.6 \cdot 10^{-47}:\\
\;\;\;\;t \cdot x\\
\mathbf{elif}\;x \leq 1.28 \cdot 10^{-20}:\\
\;\;\;\;5 \cdot y\\
\mathbf{elif}\;x \leq 3 \cdot 10^{+194}:\\
\;\;\;\;t \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -3.09999999999999996e116 or 3.0000000000000003e194 < x Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites39.3%
if -3.09999999999999996e116 < x < -1.6e-47 or 1.2800000000000001e-20 < x < 3.0000000000000003e194Initial program 99.9%
Taylor expanded in t around inf
lower-*.f6434.5
Applied rewrites34.5%
if -1.6e-47 < x < 1.2800000000000001e-20Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6460.5
Applied rewrites60.5%
Final simplification47.0%
herbie shell --seed 2024230
(FPCore (x y z t)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, B"
:precision binary64
(+ (* x (+ (+ (+ (+ y z) z) y) t)) (* y 5.0)))