
(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 12 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 z (cos y) (sin y)) x))
double code(double x, double y, double z) {
return fma(z, cos(y), sin(y)) + x;
}
function code(x, y, z) return Float64(fma(z, cos(y), sin(y)) + x) end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision] + N[Sin[y], $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \cos y, \sin y\right) + x
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (* z (cos y)) (+ (sin y) x))))
(if (<= t_0 -1000000.0)
(+ z x)
(if (<= t_0 -2e-5)
(sin y)
(if (<= t_0 2e-19) (+ x (+ z y)) (if (<= t_0 1.0) (sin y) (+ z x)))))))
double code(double x, double y, double z) {
double t_0 = (z * cos(y)) + (sin(y) + x);
double tmp;
if (t_0 <= -1000000.0) {
tmp = z + x;
} else if (t_0 <= -2e-5) {
tmp = sin(y);
} else if (t_0 <= 2e-19) {
tmp = x + (z + y);
} else if (t_0 <= 1.0) {
tmp = sin(y);
} else {
tmp = z + x;
}
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)) + (sin(y) + x)
if (t_0 <= (-1000000.0d0)) then
tmp = z + x
else if (t_0 <= (-2d-5)) then
tmp = sin(y)
else if (t_0 <= 2d-19) then
tmp = x + (z + y)
else if (t_0 <= 1.0d0) then
tmp = sin(y)
else
tmp = z + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z * Math.cos(y)) + (Math.sin(y) + x);
double tmp;
if (t_0 <= -1000000.0) {
tmp = z + x;
} else if (t_0 <= -2e-5) {
tmp = Math.sin(y);
} else if (t_0 <= 2e-19) {
tmp = x + (z + y);
} else if (t_0 <= 1.0) {
tmp = Math.sin(y);
} else {
tmp = z + x;
}
return tmp;
}
def code(x, y, z): t_0 = (z * math.cos(y)) + (math.sin(y) + x) tmp = 0 if t_0 <= -1000000.0: tmp = z + x elif t_0 <= -2e-5: tmp = math.sin(y) elif t_0 <= 2e-19: tmp = x + (z + y) elif t_0 <= 1.0: tmp = math.sin(y) else: tmp = z + x return tmp
function code(x, y, z) t_0 = Float64(Float64(z * cos(y)) + Float64(sin(y) + x)) tmp = 0.0 if (t_0 <= -1000000.0) tmp = Float64(z + x); elseif (t_0 <= -2e-5) tmp = sin(y); elseif (t_0 <= 2e-19) tmp = Float64(x + Float64(z + y)); elseif (t_0 <= 1.0) tmp = sin(y); else tmp = Float64(z + x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z * cos(y)) + (sin(y) + x); tmp = 0.0; if (t_0 <= -1000000.0) tmp = z + x; elseif (t_0 <= -2e-5) tmp = sin(y); elseif (t_0 <= 2e-19) tmp = x + (z + y); elseif (t_0 <= 1.0) tmp = sin(y); else tmp = z + x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1000000.0], N[(z + x), $MachinePrecision], If[LessEqual[t$95$0, -2e-5], N[Sin[y], $MachinePrecision], If[LessEqual[t$95$0, 2e-19], N[(x + N[(z + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1.0], N[Sin[y], $MachinePrecision], N[(z + x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y + \left(\sin y + x\right)\\
\mathbf{if}\;t\_0 \leq -1000000:\\
\;\;\;\;z + x\\
\mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-5}:\\
\;\;\;\;\sin y\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-19}:\\
\;\;\;\;x + \left(z + y\right)\\
\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;\sin y\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\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
+-commutativeN/A
lower-+.f6475.9
Applied rewrites75.9%
if -1e6 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < -2.00000000000000016e-5 or 2e-19 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < 1Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6493.7
Applied rewrites93.7%
Taylor expanded in z around 0
Applied rewrites86.9%
if -2.00000000000000016e-5 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < 2e-19Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
lower-+.f6499.9
Applied rewrites99.9%
Final simplification80.2%
herbie shell --seed 2024228
(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))))