
(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 10 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
(let* ((t_0 (+ (* z (cos y)) (+ x (sin y)))))
(if (<= t_0 -1000000.0)
(+ x z)
(if (<= t_0 -0.0001)
(sin y)
(if (<= t_0 0.0005) (+ (+ x y) z) (if (<= t_0 1.0) (sin y) (+ x z)))))))
double code(double x, double y, double z) {
double t_0 = (z * cos(y)) + (x + sin(y));
double tmp;
if (t_0 <= -1000000.0) {
tmp = x + z;
} else if (t_0 <= -0.0001) {
tmp = sin(y);
} else if (t_0 <= 0.0005) {
tmp = (x + y) + z;
} else if (t_0 <= 1.0) {
tmp = sin(y);
} 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) :: t_0
real(8) :: tmp
t_0 = (z * cos(y)) + (x + sin(y))
if (t_0 <= (-1000000.0d0)) then
tmp = x + z
else if (t_0 <= (-0.0001d0)) then
tmp = sin(y)
else if (t_0 <= 0.0005d0) then
tmp = (x + y) + z
else if (t_0 <= 1.0d0) then
tmp = sin(y)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z * Math.cos(y)) + (x + Math.sin(y));
double tmp;
if (t_0 <= -1000000.0) {
tmp = x + z;
} else if (t_0 <= -0.0001) {
tmp = Math.sin(y);
} else if (t_0 <= 0.0005) {
tmp = (x + y) + z;
} else if (t_0 <= 1.0) {
tmp = Math.sin(y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): t_0 = (z * math.cos(y)) + (x + math.sin(y)) tmp = 0 if t_0 <= -1000000.0: tmp = x + z elif t_0 <= -0.0001: tmp = math.sin(y) elif t_0 <= 0.0005: tmp = (x + y) + z elif t_0 <= 1.0: tmp = math.sin(y) else: tmp = x + z return tmp
function code(x, y, z) t_0 = Float64(Float64(z * cos(y)) + Float64(x + sin(y))) tmp = 0.0 if (t_0 <= -1000000.0) tmp = Float64(x + z); elseif (t_0 <= -0.0001) tmp = sin(y); elseif (t_0 <= 0.0005) tmp = Float64(Float64(x + y) + z); elseif (t_0 <= 1.0) tmp = sin(y); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z * cos(y)) + (x + sin(y)); tmp = 0.0; if (t_0 <= -1000000.0) tmp = x + z; elseif (t_0 <= -0.0001) tmp = sin(y); elseif (t_0 <= 0.0005) tmp = (x + y) + z; elseif (t_0 <= 1.0) tmp = sin(y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1000000.0], N[(x + z), $MachinePrecision], If[LessEqual[t$95$0, -0.0001], N[Sin[y], $MachinePrecision], If[LessEqual[t$95$0, 0.0005], N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision], If[LessEqual[t$95$0, 1.0], N[Sin[y], $MachinePrecision], N[(x + z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y + \left(x + \sin y\right)\\
\mathbf{if}\;t\_0 \leq -1000000:\\
\;\;\;\;x + z\\
\mathbf{elif}\;t\_0 \leq -0.0001:\\
\;\;\;\;\sin y\\
\mathbf{elif}\;t\_0 \leq 0.0005:\\
\;\;\;\;\left(x + y\right) + z\\
\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;\sin y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < -1e6 or 1 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6476.5
Applied rewrites76.5%
if -1e6 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < -1.00000000000000005e-4 or 5.0000000000000001e-4 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < 1Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6495.7
Applied rewrites95.7%
Taylor expanded in z around 0
Applied rewrites91.5%
if -1.00000000000000005e-4 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < 5.0000000000000001e-4Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
lower-+.f64N/A
lower-+.f6499.5
Applied rewrites99.5%
Final simplification81.3%
herbie shell --seed 2024230
(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))))