
(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 9 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) (+ x (sin y))))
double code(double x, double y, double z) {
return fma(z, cos(y), (x + sin(y)));
}
function code(x, y, z) return fma(z, cos(y), Float64(x + sin(y))) end
code[x_, y_, z_] := N[(z * N[Cos[y], $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \cos y, x + \sin y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.3e-7) (not (<= y 0.058))) (+ x (* z (cos y))) (+ y (+ z x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.3e-7) || !(y <= 0.058)) {
tmp = x + (z * cos(y));
} else {
tmp = y + (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) :: tmp
if ((y <= (-1.3d-7)) .or. (.not. (y <= 0.058d0))) then
tmp = x + (z * cos(y))
else
tmp = y + (z + x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.3e-7) || !(y <= 0.058)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = y + (z + x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.3e-7) or not (y <= 0.058): tmp = x + (z * math.cos(y)) else: tmp = y + (z + x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.3e-7) || !(y <= 0.058)) tmp = Float64(x + Float64(z * cos(y))); else tmp = Float64(y + Float64(z + x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.3e-7) || ~((y <= 0.058))) tmp = x + (z * cos(y)); else tmp = y + (z + x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.3e-7], N[Not[LessEqual[y, 0.058]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(z + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{-7} \lor \neg \left(y \leq 0.058\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;y + \left(z + x\right)\\
\end{array}
\end{array}
if y < -1.29999999999999999e-7 or 0.0580000000000000029 < y Initial program 99.9%
Taylor expanded in x around inf 73.5%
if -1.29999999999999999e-7 < y < 0.0580000000000000029Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 99.4%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -3e+36) (not (<= z 620.0))) (+ x (* z (cos y))) (+ z (+ x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3e+36) || !(z <= 620.0)) {
tmp = x + (z * cos(y));
} else {
tmp = z + (x + sin(y));
}
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 ((z <= (-3d+36)) .or. (.not. (z <= 620.0d0))) then
tmp = x + (z * cos(y))
else
tmp = z + (x + sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3e+36) || !(z <= 620.0)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = z + (x + Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3e+36) or not (z <= 620.0): tmp = x + (z * math.cos(y)) else: tmp = z + (x + math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3e+36) || !(z <= 620.0)) tmp = Float64(x + Float64(z * cos(y))); else tmp = Float64(z + Float64(x + sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3e+36) || ~((z <= 620.0))) tmp = x + (z * cos(y)); else tmp = z + (x + sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3e+36], N[Not[LessEqual[z, 620.0]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{+36} \lor \neg \left(z \leq 620\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + \left(x + \sin y\right)\\
\end{array}
\end{array}
if z < -3e36 or 620 < z Initial program 99.9%
Taylor expanded in x around inf 99.5%
if -3e36 < z < 620Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= x -11.5) (+ z x) (if (<= x 4.5e-225) (+ y (+ z x)) (if (<= x 9.2e-33) (sin y) (+ z x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -11.5) {
tmp = z + x;
} else if (x <= 4.5e-225) {
tmp = y + (z + x);
} else if (x <= 9.2e-33) {
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) :: tmp
if (x <= (-11.5d0)) then
tmp = z + x
else if (x <= 4.5d-225) then
tmp = y + (z + x)
else if (x <= 9.2d-33) 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 tmp;
if (x <= -11.5) {
tmp = z + x;
} else if (x <= 4.5e-225) {
tmp = y + (z + x);
} else if (x <= 9.2e-33) {
tmp = Math.sin(y);
} else {
tmp = z + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -11.5: tmp = z + x elif x <= 4.5e-225: tmp = y + (z + x) elif x <= 9.2e-33: tmp = math.sin(y) else: tmp = z + x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -11.5) tmp = Float64(z + x); elseif (x <= 4.5e-225) tmp = Float64(y + Float64(z + x)); elseif (x <= 9.2e-33) tmp = sin(y); else tmp = Float64(z + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -11.5) tmp = z + x; elseif (x <= 4.5e-225) tmp = y + (z + x); elseif (x <= 9.2e-33) tmp = sin(y); else tmp = z + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -11.5], N[(z + x), $MachinePrecision], If[LessEqual[x, 4.5e-225], N[(y + N[(z + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9.2e-33], N[Sin[y], $MachinePrecision], N[(z + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -11.5:\\
\;\;\;\;z + x\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-225}:\\
\;\;\;\;y + \left(z + x\right)\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{-33}:\\
\;\;\;\;\sin y\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if x < -11.5 or 9.19999999999999942e-33 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 88.8%
if -11.5 < x < 4.5e-225Initial program 99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 56.1%
if 4.5e-225 < x < 9.19999999999999942e-33Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 95.5%
Taylor expanded in z around 0 58.3%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (<= x -2.4e-57) (+ z x) (if (<= x 4.8e-123) (* z (cos y)) (if (<= x 9.2e-33) (sin y) (+ z x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e-57) {
tmp = z + x;
} else if (x <= 4.8e-123) {
tmp = z * cos(y);
} else if (x <= 9.2e-33) {
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) :: tmp
if (x <= (-2.4d-57)) then
tmp = z + x
else if (x <= 4.8d-123) then
tmp = z * cos(y)
else if (x <= 9.2d-33) 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 tmp;
if (x <= -2.4e-57) {
tmp = z + x;
} else if (x <= 4.8e-123) {
tmp = z * Math.cos(y);
} else if (x <= 9.2e-33) {
tmp = Math.sin(y);
} else {
tmp = z + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.4e-57: tmp = z + x elif x <= 4.8e-123: tmp = z * math.cos(y) elif x <= 9.2e-33: tmp = math.sin(y) else: tmp = z + x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.4e-57) tmp = Float64(z + x); elseif (x <= 4.8e-123) tmp = Float64(z * cos(y)); elseif (x <= 9.2e-33) tmp = sin(y); else tmp = Float64(z + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.4e-57) tmp = z + x; elseif (x <= 4.8e-123) tmp = z * cos(y); elseif (x <= 9.2e-33) tmp = sin(y); else tmp = z + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.4e-57], N[(z + x), $MachinePrecision], If[LessEqual[x, 4.8e-123], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9.2e-33], N[Sin[y], $MachinePrecision], N[(z + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-57}:\\
\;\;\;\;z + x\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{-123}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{-33}:\\
\;\;\;\;\sin y\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if x < -2.40000000000000006e-57 or 9.19999999999999942e-33 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 86.2%
if -2.40000000000000006e-57 < x < 4.8e-123Initial program 99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in z around inf 65.8%
if 4.8e-123 < x < 9.19999999999999942e-33Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 90.1%
Taylor expanded in z around 0 69.6%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (<= x -11.5) (+ z x) (if (<= x 1e-32) (+ y (+ z x)) (+ z x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -11.5) {
tmp = z + x;
} else if (x <= 1e-32) {
tmp = y + (z + x);
} 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) :: tmp
if (x <= (-11.5d0)) then
tmp = z + x
else if (x <= 1d-32) then
tmp = y + (z + x)
else
tmp = z + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -11.5) {
tmp = z + x;
} else if (x <= 1e-32) {
tmp = y + (z + x);
} else {
tmp = z + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -11.5: tmp = z + x elif x <= 1e-32: tmp = y + (z + x) else: tmp = z + x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -11.5) tmp = Float64(z + x); elseif (x <= 1e-32) tmp = Float64(y + Float64(z + x)); else tmp = Float64(z + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -11.5) tmp = z + x; elseif (x <= 1e-32) tmp = y + (z + x); else tmp = z + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -11.5], N[(z + x), $MachinePrecision], If[LessEqual[x, 1e-32], N[(y + N[(z + x), $MachinePrecision]), $MachinePrecision], N[(z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -11.5:\\
\;\;\;\;z + x\\
\mathbf{elif}\;x \leq 10^{-32}:\\
\;\;\;\;y + \left(z + x\right)\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if x < -11.5 or 1.00000000000000006e-32 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 88.8%
if -11.5 < x < 1.00000000000000006e-32Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 49.9%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (+ z x))
double code(double x, double y, double z) {
return z + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + x
end function
public static double code(double x, double y, double z) {
return z + x;
}
def code(x, y, z): return z + x
function code(x, y, z) return Float64(z + x) end
function tmp = code(x, y, z) tmp = z + x; end
code[x_, y_, z_] := N[(z + x), $MachinePrecision]
\begin{array}{l}
\\
z + x
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 68.1%
Final simplification68.1%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in x around 0 57.9%
Taylor expanded in z around inf 40.2%
*-commutative40.2%
rem-cube-cbrt39.6%
Applied egg-rr39.6%
Taylor expanded in y around 0 27.1%
pow-base-127.1%
*-lft-identity27.1%
Simplified27.1%
Final simplification27.1%
herbie shell --seed 2023230
(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))))