
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(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 + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(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 + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma z (- (sin y)) (+ x (cos y))))
double code(double x, double y, double z) {
return fma(z, -sin(y), (x + cos(y)));
}
function code(x, y, z) return fma(z, Float64(-sin(y)), Float64(x + cos(y))) end
code[x_, y_, z_] := N[(z * (-N[Sin[y], $MachinePrecision]) + N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, -\sin y, x + \cos y\right)
\end{array}
Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
sin-neg99.9%
fma-def100.0%
sin-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -0.006) (+ x 1.0) (if (<= x 0.105) (- (cos y) (* z (sin y))) (+ x (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.006) {
tmp = x + 1.0;
} else if (x <= 0.105) {
tmp = cos(y) - (z * sin(y));
} else {
tmp = x + cos(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 (x <= (-0.006d0)) then
tmp = x + 1.0d0
else if (x <= 0.105d0) then
tmp = cos(y) - (z * sin(y))
else
tmp = x + cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.006) {
tmp = x + 1.0;
} else if (x <= 0.105) {
tmp = Math.cos(y) - (z * Math.sin(y));
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.006: tmp = x + 1.0 elif x <= 0.105: tmp = math.cos(y) - (z * math.sin(y)) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.006) tmp = Float64(x + 1.0); elseif (x <= 0.105) tmp = Float64(cos(y) - Float64(z * sin(y))); else tmp = Float64(x + cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.006) tmp = x + 1.0; elseif (x <= 0.105) tmp = cos(y) - (z * sin(y)); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.006], N[(x + 1.0), $MachinePrecision], If[LessEqual[x, 0.105], N[(N[Cos[y], $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.006:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;x \leq 0.105:\\
\;\;\;\;\cos y - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if x < -0.0060000000000000001Initial program 99.9%
Taylor expanded in y around 0 83.1%
+-commutative83.1%
Simplified83.1%
if -0.0060000000000000001 < x < 0.104999999999999996Initial program 99.9%
Taylor expanded in x around 0 99.5%
if 0.104999999999999996 < x Initial program 99.9%
Taylor expanded in z around 0 88.0%
+-commutative88.0%
Simplified88.0%
Final simplification92.6%
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(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 + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.2e+183) (not (<= z 5.8e+105))) (* z (- (sin y))) (+ x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e+183) || !(z <= 5.8e+105)) {
tmp = z * -sin(y);
} else {
tmp = x + cos(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 <= (-4.2d+183)) .or. (.not. (z <= 5.8d+105))) then
tmp = z * -sin(y)
else
tmp = x + cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e+183) || !(z <= 5.8e+105)) {
tmp = z * -Math.sin(y);
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.2e+183) or not (z <= 5.8e+105): tmp = z * -math.sin(y) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.2e+183) || !(z <= 5.8e+105)) tmp = Float64(z * Float64(-sin(y))); else tmp = Float64(x + cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.2e+183) || ~((z <= 5.8e+105))) tmp = z * -sin(y); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.2e+183], N[Not[LessEqual[z, 5.8e+105]], $MachinePrecision]], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+183} \lor \neg \left(z \leq 5.8 \cdot 10^{+105}\right):\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if z < -4.2e183 or 5.8000000000000002e105 < z Initial program 99.8%
Taylor expanded in z around inf 74.7%
neg-mul-174.7%
*-commutative74.7%
distribute-rgt-neg-in74.7%
Simplified74.7%
if -4.2e183 < z < 5.8000000000000002e105Initial program 100.0%
Taylor expanded in z around 0 89.0%
+-commutative89.0%
Simplified89.0%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.027) (not (<= y 1.2e-8))) (+ x (cos y)) (+ 1.0 (- x (* z y)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.027) || !(y <= 1.2e-8)) {
tmp = x + cos(y);
} else {
tmp = 1.0 + (x - (z * 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 ((y <= (-0.027d0)) .or. (.not. (y <= 1.2d-8))) then
tmp = x + cos(y)
else
tmp = 1.0d0 + (x - (z * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.027) || !(y <= 1.2e-8)) {
tmp = x + Math.cos(y);
} else {
tmp = 1.0 + (x - (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.027) or not (y <= 1.2e-8): tmp = x + math.cos(y) else: tmp = 1.0 + (x - (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.027) || !(y <= 1.2e-8)) tmp = Float64(x + cos(y)); else tmp = Float64(1.0 + Float64(x - Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.027) || ~((y <= 1.2e-8))) tmp = x + cos(y); else tmp = 1.0 + (x - (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.027], N[Not[LessEqual[y, 1.2e-8]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.027 \lor \neg \left(y \leq 1.2 \cdot 10^{-8}\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x - z \cdot y\right)\\
\end{array}
\end{array}
if y < -0.0269999999999999997 or 1.19999999999999999e-8 < y Initial program 99.9%
Taylor expanded in z around 0 65.5%
+-commutative65.5%
Simplified65.5%
if -0.0269999999999999997 < y < 1.19999999999999999e-8Initial program 100.0%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0002) (not (<= x 2.35e-30))) (+ x 1.0) (cos y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0002) || !(x <= 2.35e-30)) {
tmp = x + 1.0;
} else {
tmp = cos(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 ((x <= (-0.0002d0)) .or. (.not. (x <= 2.35d-30))) then
tmp = x + 1.0d0
else
tmp = cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0002) || !(x <= 2.35e-30)) {
tmp = x + 1.0;
} else {
tmp = Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0002) or not (x <= 2.35e-30): tmp = x + 1.0 else: tmp = math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0002) || !(x <= 2.35e-30)) tmp = Float64(x + 1.0); else tmp = cos(y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.0002) || ~((x <= 2.35e-30))) tmp = x + 1.0; else tmp = cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0002], N[Not[LessEqual[x, 2.35e-30]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[Cos[y], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0002 \lor \neg \left(x \leq 2.35 \cdot 10^{-30}\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;\cos y\\
\end{array}
\end{array}
if x < -2.0000000000000001e-4 or 2.34999999999999985e-30 < x Initial program 99.9%
Taylor expanded in y around 0 82.4%
+-commutative82.4%
Simplified82.4%
if -2.0000000000000001e-4 < x < 2.34999999999999985e-30Initial program 99.9%
Taylor expanded in z around 0 65.5%
+-commutative65.5%
Simplified65.5%
Taylor expanded in x around 0 65.0%
Final simplification73.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.1) (not (<= y 1.2e-8))) (+ x 1.0) (+ 1.0 (- x (* z y)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.1) || !(y <= 1.2e-8)) {
tmp = x + 1.0;
} else {
tmp = 1.0 + (x - (z * 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 ((y <= (-3.1d0)) .or. (.not. (y <= 1.2d-8))) then
tmp = x + 1.0d0
else
tmp = 1.0d0 + (x - (z * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.1) || !(y <= 1.2e-8)) {
tmp = x + 1.0;
} else {
tmp = 1.0 + (x - (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.1) or not (y <= 1.2e-8): tmp = x + 1.0 else: tmp = 1.0 + (x - (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.1) || !(y <= 1.2e-8)) tmp = Float64(x + 1.0); else tmp = Float64(1.0 + Float64(x - Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.1) || ~((y <= 1.2e-8))) tmp = x + 1.0; else tmp = 1.0 + (x - (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.1], N[Not[LessEqual[y, 1.2e-8]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[(1.0 + N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \lor \neg \left(y \leq 1.2 \cdot 10^{-8}\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x - z \cdot y\right)\\
\end{array}
\end{array}
if y < -3.10000000000000009 or 1.19999999999999999e-8 < y Initial program 99.9%
Taylor expanded in y around 0 43.7%
+-commutative43.7%
Simplified43.7%
if -3.10000000000000009 < y < 1.19999999999999999e-8Initial program 100.0%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification70.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e-28) (not (<= x 0.017))) (+ x 1.0) (- 1.0 (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-28) || !(x <= 0.017)) {
tmp = x + 1.0;
} else {
tmp = 1.0 - (z * 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 ((x <= (-6d-28)) .or. (.not. (x <= 0.017d0))) then
tmp = x + 1.0d0
else
tmp = 1.0d0 - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-28) || !(x <= 0.017)) {
tmp = x + 1.0;
} else {
tmp = 1.0 - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-28) or not (x <= 0.017): tmp = x + 1.0 else: tmp = 1.0 - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-28) || !(x <= 0.017)) tmp = Float64(x + 1.0); else tmp = Float64(1.0 - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6e-28) || ~((x <= 0.017))) tmp = x + 1.0; else tmp = 1.0 - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-28], N[Not[LessEqual[x, 0.017]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-28} \lor \neg \left(x \leq 0.017\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;1 - z \cdot y\\
\end{array}
\end{array}
if x < -6.00000000000000005e-28 or 0.017000000000000001 < x Initial program 99.9%
Taylor expanded in y around 0 81.3%
+-commutative81.3%
Simplified81.3%
if -6.00000000000000005e-28 < x < 0.017000000000000001Initial program 99.9%
Taylor expanded in y around 0 52.3%
mul-1-neg52.3%
unsub-neg52.3%
Simplified52.3%
Taylor expanded in x around 0 52.3%
associate-*r*52.3%
neg-mul-152.3%
Simplified52.3%
Final simplification67.4%
(FPCore (x y z) :precision binary64 (if (<= x -0.88) x (if (<= x 1.32e-21) 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.88) {
tmp = x;
} else if (x <= 1.32e-21) {
tmp = 1.0;
} else {
tmp = 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 <= (-0.88d0)) then
tmp = x
else if (x <= 1.32d-21) then
tmp = 1.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.88) {
tmp = x;
} else if (x <= 1.32e-21) {
tmp = 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.88: tmp = x elif x <= 1.32e-21: tmp = 1.0 else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.88) tmp = x; elseif (x <= 1.32e-21) tmp = 1.0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.88) tmp = x; elseif (x <= 1.32e-21) tmp = 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.88], x, If[LessEqual[x, 1.32e-21], 1.0, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.88:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.32 \cdot 10^{-21}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -0.880000000000000004 or 1.32e-21 < x Initial program 99.9%
Taylor expanded in x around inf 83.5%
if -0.880000000000000004 < x < 1.32e-21Initial program 99.9%
Taylor expanded in x around 0 99.5%
Taylor expanded in y around 0 41.5%
Final simplification62.5%
(FPCore (x y z) :precision binary64 (+ x 1.0))
double code(double x, double y, double z) {
return x + 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + 1.0d0
end function
public static double code(double x, double y, double z) {
return x + 1.0;
}
def code(x, y, z): return x + 1.0
function code(x, y, z) return Float64(x + 1.0) end
function tmp = code(x, y, z) tmp = x + 1.0; end
code[x_, y_, z_] := N[(x + 1.0), $MachinePrecision]
\begin{array}{l}
\\
x + 1
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 62.8%
+-commutative62.8%
Simplified62.8%
Final simplification62.8%
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 57.9%
Taylor expanded in y around 0 22.3%
Final simplification22.3%
herbie shell --seed 2023321
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, B"
:precision binary64
(- (+ x (cos y)) (* z (sin y))))