
(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 (sin y) (- z) (+ x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x + cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x + cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x + \cos y\right)
\end{array}
Initial program 99.9%
sub-neg99.9%
+-commutative99.9%
*-commutative99.9%
distribute-rgt-neg-in99.9%
fma-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x -4.6e+18) x (if (<= x 1.95e+52) (- (cos y) (* (sin y) z)) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.6e+18) {
tmp = x;
} else if (x <= 1.95e+52) {
tmp = cos(y) - (sin(y) * z);
} else {
tmp = x + 1.0;
}
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 <= (-4.6d+18)) then
tmp = x
else if (x <= 1.95d+52) then
tmp = cos(y) - (sin(y) * z)
else
tmp = x + 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.6e+18) {
tmp = x;
} else if (x <= 1.95e+52) {
tmp = Math.cos(y) - (Math.sin(y) * z);
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.6e+18: tmp = x elif x <= 1.95e+52: tmp = math.cos(y) - (math.sin(y) * z) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.6e+18) tmp = x; elseif (x <= 1.95e+52) tmp = Float64(cos(y) - Float64(sin(y) * z)); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.6e+18) tmp = x; elseif (x <= 1.95e+52) tmp = cos(y) - (sin(y) * z); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.6e+18], x, If[LessEqual[x, 1.95e+52], N[(N[Cos[y], $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{+18}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.95 \cdot 10^{+52}:\\
\;\;\;\;\cos y - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if x < -4.6e18Initial program 99.9%
Taylor expanded in x around inf 88.1%
if -4.6e18 < x < 1.95e52Initial program 99.8%
Taylor expanded in x around 0 96.1%
if 1.95e52 < x Initial program 100.0%
Taylor expanded in y around 0 89.8%
+-commutative89.8%
Simplified89.8%
Final simplification92.7%
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x + cos(y)) - (sin(y) * 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 + cos(y)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x + math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - \sin y \cdot z
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (cos y)))) (if (or (<= y -3.2e+36) (not (<= y 105000.0))) t_0 (- t_0 (* y z)))))
double code(double x, double y, double z) {
double t_0 = x + cos(y);
double tmp;
if ((y <= -3.2e+36) || !(y <= 105000.0)) {
tmp = t_0;
} else {
tmp = t_0 - (y * 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 = x + cos(y)
if ((y <= (-3.2d+36)) .or. (.not. (y <= 105000.0d0))) then
tmp = t_0
else
tmp = t_0 - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + Math.cos(y);
double tmp;
if ((y <= -3.2e+36) || !(y <= 105000.0)) {
tmp = t_0;
} else {
tmp = t_0 - (y * z);
}
return tmp;
}
def code(x, y, z): t_0 = x + math.cos(y) tmp = 0 if (y <= -3.2e+36) or not (y <= 105000.0): tmp = t_0 else: tmp = t_0 - (y * z) return tmp
function code(x, y, z) t_0 = Float64(x + cos(y)) tmp = 0.0 if ((y <= -3.2e+36) || !(y <= 105000.0)) tmp = t_0; else tmp = Float64(t_0 - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + cos(y); tmp = 0.0; if ((y <= -3.2e+36) || ~((y <= 105000.0))) tmp = t_0; else tmp = t_0 - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[y, -3.2e+36], N[Not[LessEqual[y, 105000.0]], $MachinePrecision]], t$95$0, N[(t$95$0 - N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \cos y\\
\mathbf{if}\;y \leq -3.2 \cdot 10^{+36} \lor \neg \left(y \leq 105000\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_0 - y \cdot z\\
\end{array}
\end{array}
if y < -3.1999999999999999e36 or 105000 < y Initial program 99.8%
Taylor expanded in z around 0 65.1%
if -3.1999999999999999e36 < y < 105000Initial program 100.0%
Taylor expanded in y around 0 96.7%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.024) (not (<= y 13000.0))) (+ x (cos y)) (+ 1.0 (fma (- y) z x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.024) || !(y <= 13000.0)) {
tmp = x + cos(y);
} else {
tmp = 1.0 + fma(-y, z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.024) || !(y <= 13000.0)) tmp = Float64(x + cos(y)); else tmp = Float64(1.0 + fma(Float64(-y), z, x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.024], N[Not[LessEqual[y, 13000.0]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[((-y) * z + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.024 \lor \neg \left(y \leq 13000\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;1 + \mathsf{fma}\left(-y, z, x\right)\\
\end{array}
\end{array}
if y < -0.024 or 13000 < y Initial program 99.8%
Taylor expanded in z around 0 65.5%
if -0.024 < y < 13000Initial program 100.0%
add-cube-cbrt99.7%
pow399.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 98.4%
associate-*r*98.4%
fma-def98.4%
mul-1-neg98.4%
Simplified98.4%
Final simplification82.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.04) (not (<= y 13000.0))) (+ x (cos y)) (+ x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.04) || !(y <= 13000.0)) {
tmp = x + cos(y);
} else {
tmp = x + (1.0 - (y * 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 <= (-0.04d0)) .or. (.not. (y <= 13000.0d0))) then
tmp = x + cos(y)
else
tmp = x + (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.04) || !(y <= 13000.0)) {
tmp = x + Math.cos(y);
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.04) or not (y <= 13000.0): tmp = x + math.cos(y) else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.04) || !(y <= 13000.0)) tmp = Float64(x + cos(y)); else tmp = Float64(x + Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.04) || ~((y <= 13000.0))) tmp = x + cos(y); else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.04], N[Not[LessEqual[y, 13000.0]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.04 \lor \neg \left(y \leq 13000\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -0.0400000000000000008 or 13000 < y Initial program 99.8%
Taylor expanded in z around 0 65.5%
if -0.0400000000000000008 < y < 13000Initial program 100.0%
Taylor expanded in y around 0 98.4%
associate-+r+98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
Simplified98.4%
Final simplification82.5%
(FPCore (x y z) :precision binary64 (if (<= y -3.2e+36) (+ x 1.0) (if (<= y 1220000000.0) (+ x (- 1.0 (* y z))) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e+36) {
tmp = x + 1.0;
} else if (y <= 1220000000.0) {
tmp = x + (1.0 - (y * z));
} else {
tmp = x + 1.0;
}
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.2d+36)) then
tmp = x + 1.0d0
else if (y <= 1220000000.0d0) then
tmp = x + (1.0d0 - (y * z))
else
tmp = x + 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e+36) {
tmp = x + 1.0;
} else if (y <= 1220000000.0) {
tmp = x + (1.0 - (y * z));
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.2e+36: tmp = x + 1.0 elif y <= 1220000000.0: tmp = x + (1.0 - (y * z)) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.2e+36) tmp = Float64(x + 1.0); elseif (y <= 1220000000.0) tmp = Float64(x + Float64(1.0 - Float64(y * z))); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.2e+36) tmp = x + 1.0; elseif (y <= 1220000000.0) tmp = x + (1.0 - (y * z)); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.2e+36], N[(x + 1.0), $MachinePrecision], If[LessEqual[y, 1220000000.0], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{+36}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;y \leq 1220000000:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < -3.1999999999999999e36 or 1.22e9 < y Initial program 99.8%
Taylor expanded in y around 0 44.3%
+-commutative44.3%
Simplified44.3%
if -3.1999999999999999e36 < y < 1.22e9Initial program 100.0%
Taylor expanded in y around 0 93.2%
associate-+r+93.2%
+-commutative93.2%
mul-1-neg93.2%
unsub-neg93.2%
Simplified93.2%
Final simplification71.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.3e-40) (+ x 1.0) (if (<= x 4.8e+31) (- 1.0 (* y z)) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e-40) {
tmp = x + 1.0;
} else if (x <= 4.8e+31) {
tmp = 1.0 - (y * z);
} else {
tmp = x + 1.0;
}
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 <= (-1.3d-40)) then
tmp = x + 1.0d0
else if (x <= 4.8d+31) then
tmp = 1.0d0 - (y * z)
else
tmp = x + 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e-40) {
tmp = x + 1.0;
} else if (x <= 4.8e+31) {
tmp = 1.0 - (y * z);
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e-40: tmp = x + 1.0 elif x <= 4.8e+31: tmp = 1.0 - (y * z) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e-40) tmp = Float64(x + 1.0); elseif (x <= 4.8e+31) tmp = Float64(1.0 - Float64(y * z)); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.3e-40) tmp = x + 1.0; elseif (x <= 4.8e+31) tmp = 1.0 - (y * z); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e-40], N[(x + 1.0), $MachinePrecision], If[LessEqual[x, 4.8e+31], N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-40}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{+31}:\\
\;\;\;\;1 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if x < -1.3000000000000001e-40 or 4.79999999999999965e31 < x Initial program 99.9%
Taylor expanded in y around 0 82.1%
+-commutative82.1%
Simplified82.1%
if -1.3000000000000001e-40 < x < 4.79999999999999965e31Initial program 99.9%
Taylor expanded in y around 0 55.0%
associate-+r+55.0%
+-commutative55.0%
mul-1-neg55.0%
unsub-neg55.0%
Simplified55.0%
Taylor expanded in x around 0 54.2%
Final simplification69.1%
(FPCore (x y z) :precision binary64 (if (<= z 3.2e+250) (+ x 1.0) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 3.2e+250) {
tmp = x + 1.0;
} else {
tmp = y * -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 (z <= 3.2d+250) then
tmp = x + 1.0d0
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 3.2e+250) {
tmp = x + 1.0;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3.2e+250: tmp = x + 1.0 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3.2e+250) tmp = Float64(x + 1.0); else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 3.2e+250) tmp = x + 1.0; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3.2e+250], N[(x + 1.0), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.2 \cdot 10^{+250}:\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 3.1999999999999997e250Initial program 99.9%
Taylor expanded in y around 0 66.8%
+-commutative66.8%
Simplified66.8%
if 3.1999999999999997e250 < z Initial program 99.8%
Taylor expanded in y around 0 58.7%
Taylor expanded in y around inf 58.7%
associate-*r*58.7%
neg-mul-158.7%
Simplified58.7%
Final simplification66.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 64.5%
+-commutative64.5%
Simplified64.5%
Final simplification64.5%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf 44.7%
Final simplification44.7%
herbie shell --seed 2023240
(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))))