
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (+ x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x + sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x + sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x + \sin y\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.4e+148) (fma (cos y) z (sin y)) (if (<= z 6.5e+106) (fma 1.0 z (+ x (sin y))) (fma (cos y) z (+ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+148) {
tmp = fma(cos(y), z, sin(y));
} else if (z <= 6.5e+106) {
tmp = fma(1.0, z, (x + sin(y)));
} else {
tmp = fma(cos(y), z, (x + y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.4e+148) tmp = fma(cos(y), z, sin(y)); elseif (z <= 6.5e+106) tmp = fma(1.0, z, Float64(x + sin(y))); else tmp = fma(cos(y), z, Float64(x + y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.4e+148], N[(N[Cos[y], $MachinePrecision] * z + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.5e+106], N[(1.0 * z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z + N[(x + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+148}:\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, \sin y\right)\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{+106}:\\
\;\;\;\;\mathsf{fma}\left(1, z, x + \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, x + y\right)\\
\end{array}
\end{array}
if z < -1.3999999999999999e148Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6489.4
Applied rewrites89.4%
if -1.3999999999999999e148 < z < 6.5000000000000003e106Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites96.2%
if 6.5000000000000003e106 < z Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
lower-+.f6486.0
Applied rewrites86.0%
Final simplification93.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fma (cos y) z (+ x y))))
(if (<= z -7.5e+147)
t_0
(if (<= z 6.5e+106) (fma 1.0 z (+ x (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(cos(y), z, (x + y));
double tmp;
if (z <= -7.5e+147) {
tmp = t_0;
} else if (z <= 6.5e+106) {
tmp = fma(1.0, z, (x + sin(y)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(cos(y), z, Float64(x + y)) tmp = 0.0 if (z <= -7.5e+147) tmp = t_0; elseif (z <= 6.5e+106) tmp = fma(1.0, z, Float64(x + sin(y))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z + N[(x + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.5e+147], t$95$0, If[LessEqual[z, 6.5e+106], N[(1.0 * z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\cos y, z, x + y\right)\\
\mathbf{if}\;z \leq -7.5 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{+106}:\\
\;\;\;\;\mathsf{fma}\left(1, z, x + \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.50000000000000037e147 or 6.5000000000000003e106 < z Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
lower-+.f6486.0
Applied rewrites86.0%
if -7.50000000000000037e147 < z < 6.5000000000000003e106Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites96.2%
Final simplification93.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (sin y))))
(if (<= y -2.5e+23)
t_0
(if (<= y 8.5e-10) (fma (fma (* z y) -0.5 1.0) y (+ x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x + sin(y);
double tmp;
if (y <= -2.5e+23) {
tmp = t_0;
} else if (y <= 8.5e-10) {
tmp = fma(fma((z * y), -0.5, 1.0), y, (x + z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x + sin(y)) tmp = 0.0 if (y <= -2.5e+23) tmp = t_0; elseif (y <= 8.5e-10) tmp = fma(fma(Float64(z * y), -0.5, 1.0), y, Float64(x + z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.5e+23], t$95$0, If[LessEqual[y, 8.5e-10], N[(N[(N[(z * y), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * y + N[(x + z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \sin y\\
\mathbf{if}\;y \leq -2.5 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(z \cdot y, -0.5, 1\right), y, x + z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.5e23 or 8.4999999999999996e-10 < y Initial program 99.9%
Taylor expanded in y around 0
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6425.6
Applied rewrites25.6%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f64N/A
lower-sin.f6469.4
Applied rewrites69.4%
if -2.5e23 < y < 8.4999999999999996e-10Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.3
Applied rewrites99.3%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (fma 1.0 z (+ x (sin y))))
double code(double x, double y, double z) {
return fma(1.0, z, (x + sin(y)));
}
function code(x, y, z) return fma(1.0, z, Float64(x + sin(y))) end
code[x_, y_, z_] := N[(1.0 * z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1, z, x + \sin y\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites85.9%
Final simplification85.9%
(FPCore (x y z)
:precision binary64
(if (<= y -2.5e+23)
(+ x z)
(if (<= y 1e+18)
(fma (fma (fma -0.16666666666666666 y (* -0.5 z)) y 1.0) y (+ x z))
(+ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+23) {
tmp = x + z;
} else if (y <= 1e+18) {
tmp = fma(fma(fma(-0.16666666666666666, y, (-0.5 * z)), y, 1.0), y, (x + z));
} else {
tmp = x + z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2.5e+23) tmp = Float64(x + z); elseif (y <= 1e+18) tmp = fma(fma(fma(-0.16666666666666666, y, Float64(-0.5 * z)), y, 1.0), y, Float64(x + z)); else tmp = Float64(x + z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2.5e+23], N[(x + z), $MachinePrecision], If[LessEqual[y, 1e+18], N[(N[(N[(-0.16666666666666666 * y + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + 1.0), $MachinePrecision] * y + N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+23}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 10^{+18}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y, -0.5 \cdot z\right), y, 1\right), y, x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if y < -2.5e23 or 1e18 < y Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6441.8
Applied rewrites41.8%
if -2.5e23 < y < 1e18Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6496.0
Applied rewrites96.0%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.26e+33) (+ x z) (if (<= y 1e+18) (fma (fma (* z y) -0.5 1.0) y (+ x z)) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.26e+33) {
tmp = x + z;
} else if (y <= 1e+18) {
tmp = fma(fma((z * y), -0.5, 1.0), y, (x + z));
} else {
tmp = x + z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.26e+33) tmp = Float64(x + z); elseif (y <= 1e+18) tmp = fma(fma(Float64(z * y), -0.5, 1.0), y, Float64(x + z)); else tmp = Float64(x + z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.26e+33], N[(x + z), $MachinePrecision], If[LessEqual[y, 1e+18], N[(N[(N[(z * y), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * y + N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.26 \cdot 10^{+33}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 10^{+18}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(z \cdot y, -0.5, 1\right), y, x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if y < -1.26e33 or 1e18 < y Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6442.9
Applied rewrites42.9%
if -1.26e33 < y < 1e18Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6494.1
Applied rewrites94.1%
Final simplification71.9%
(FPCore (x y z)
:precision binary64
(if (<= y -2.6e+23)
(+ x z)
(if (<= y 3.05e+37)
(fma (fma (* -0.16666666666666666 y) y 1.0) y (+ x z))
(+ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.6e+23) {
tmp = x + z;
} else if (y <= 3.05e+37) {
tmp = fma(fma((-0.16666666666666666 * y), y, 1.0), y, (x + z));
} else {
tmp = x + z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2.6e+23) tmp = Float64(x + z); elseif (y <= 3.05e+37) tmp = fma(fma(Float64(-0.16666666666666666 * y), y, 1.0), y, Float64(x + z)); else tmp = Float64(x + z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2.6e+23], N[(x + z), $MachinePrecision], If[LessEqual[y, 3.05e+37], N[(N[(N[(-0.16666666666666666 * y), $MachinePrecision] * y + 1.0), $MachinePrecision] * y + N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+23}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 3.05 \cdot 10^{+37}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666 \cdot y, y, 1\right), y, x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if y < -2.59999999999999992e23 or 3.05e37 < y Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6441.1
Applied rewrites41.1%
if -2.59999999999999992e23 < y < 3.05e37Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6494.8
Applied rewrites94.8%
Taylor expanded in y around inf
Applied rewrites95.3%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (if (<= y -5.8e+35) (+ x z) (if (<= y 1.9e+15) (+ (+ x y) z) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.8e+35) {
tmp = x + z;
} else if (y <= 1.9e+15) {
tmp = (x + y) + z;
} else {
tmp = x + z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-5.8d+35)) then
tmp = x + z
else if (y <= 1.9d+15) then
tmp = (x + y) + z
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.8e+35) {
tmp = x + z;
} else if (y <= 1.9e+15) {
tmp = (x + y) + z;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.8e+35: tmp = x + z elif y <= 1.9e+15: tmp = (x + y) + z else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.8e+35) tmp = Float64(x + z); elseif (y <= 1.9e+15) tmp = Float64(Float64(x + y) + z); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.8e+35) tmp = x + z; elseif (y <= 1.9e+15) tmp = (x + y) + z; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.8e+35], N[(x + z), $MachinePrecision], If[LessEqual[y, 1.9e+15], N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{+35}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+15}:\\
\;\;\;\;\left(x + y\right) + z\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if y < -5.79999999999999989e35 or 1.9e15 < y Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6442.7
Applied rewrites42.7%
if -5.79999999999999989e35 < y < 1.9e15Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6494.0
Applied rewrites94.0%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6466.5
Applied rewrites66.5%
Final simplification66.5%
(FPCore (x y z) :precision binary64 (+ z y))
double code(double x, double y, double z) {
return z + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + y
end function
public static double code(double x, double y, double z) {
return z + y;
}
def code(x, y, z): return z + y
function code(x, y, z) return Float64(z + y) end
function tmp = code(x, y, z) tmp = z + y; end
code[x_, y_, z_] := N[(z + y), $MachinePrecision]
\begin{array}{l}
\\
z + y
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6463.8
Applied rewrites63.8%
Taylor expanded in x around 0
Applied rewrites29.8%
herbie shell --seed 2024298
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))