
(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 10 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 (+ (+ x (cos y)) (- 1.0 (+ (* z (sin y)) 1.0))))
double code(double x, double y, double z) {
return (x + cos(y)) + (1.0 - ((z * sin(y)) + 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 + cos(y)) + (1.0d0 - ((z * sin(y)) + 1.0d0))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) + (1.0 - ((z * Math.sin(y)) + 1.0));
}
def code(x, y, z): return (x + math.cos(y)) + (1.0 - ((z * math.sin(y)) + 1.0))
function code(x, y, z) return Float64(Float64(x + cos(y)) + Float64(1.0 - Float64(Float64(z * sin(y)) + 1.0))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) + (1.0 - ((z * sin(y)) + 1.0)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) + \left(1 - \left(z \cdot \sin y + 1\right)\right)
\end{array}
Initial program 99.9%
add-cbrt-cube79.7%
pow379.7%
Applied egg-rr79.7%
rem-cbrt-cube99.9%
expm1-log1p-u81.1%
expm1-def81.1%
log1p-udef81.1%
add-exp-log99.9%
+-commutative99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))))
(if (<= x -6.2e+21)
(- x t_0)
(if (<= x 7.2e-12) (- (cos y) t_0) (fma (- z) (sin y) x)))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if (x <= -6.2e+21) {
tmp = x - t_0;
} else if (x <= 7.2e-12) {
tmp = cos(y) - t_0;
} else {
tmp = fma(-z, sin(y), x);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * sin(y)) tmp = 0.0 if (x <= -6.2e+21) tmp = Float64(x - t_0); elseif (x <= 7.2e-12) tmp = Float64(cos(y) - t_0); else tmp = fma(Float64(-z), sin(y), x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -6.2e+21], N[(x - t$95$0), $MachinePrecision], If[LessEqual[x, 7.2e-12], N[(N[Cos[y], $MachinePrecision] - t$95$0), $MachinePrecision], N[((-z) * N[Sin[y], $MachinePrecision] + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;x \leq -6.2 \cdot 10^{+21}:\\
\;\;\;\;x - t_0\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{-12}:\\
\;\;\;\;\cos y - t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, \sin y, x\right)\\
\end{array}
\end{array}
if x < -6.2e21Initial program 100.0%
add-cube-cbrt98.1%
pow398.0%
associate--l+98.0%
Applied egg-rr98.0%
Taylor expanded in z around inf 98.0%
associate-*r*98.0%
neg-mul-198.0%
*-commutative98.0%
Simplified98.0%
Taylor expanded in y around inf 100.0%
pow-base-1100.0%
*-lft-identity100.0%
neg-mul-1100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
if -6.2e21 < x < 7.2e-12Initial program 99.8%
Taylor expanded in x around 0 99.3%
if 7.2e-12 < x Initial program 100.0%
add-cube-cbrt98.0%
pow398.0%
associate--l+98.0%
Applied egg-rr98.0%
Taylor expanded in z around inf 96.7%
associate-*r*96.7%
neg-mul-196.7%
*-commutative96.7%
Simplified96.7%
Taylor expanded in y around inf 98.6%
pow-base-198.6%
*-lft-identity98.6%
associate-*r*98.6%
fma-def98.6%
neg-mul-198.6%
Simplified98.6%
Final simplification99.3%
(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 (<= z -2.6e+19) (fma (- z) (sin y) x) (if (<= z 132000000000.0) (+ x (cos y)) (- x (* z (sin y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.6e+19) {
tmp = fma(-z, sin(y), x);
} else if (z <= 132000000000.0) {
tmp = x + cos(y);
} else {
tmp = x - (z * sin(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.6e+19) tmp = fma(Float64(-z), sin(y), x); elseif (z <= 132000000000.0) tmp = Float64(x + cos(y)); else tmp = Float64(x - Float64(z * sin(y))); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.6e+19], N[((-z) * N[Sin[y], $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 132000000000.0], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(-z, \sin y, x\right)\\
\mathbf{elif}\;z \leq 132000000000:\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if z < -2.6e19Initial program 99.9%
add-cube-cbrt98.0%
pow398.0%
associate--l+98.0%
Applied egg-rr98.0%
Taylor expanded in z around inf 89.9%
associate-*r*89.9%
neg-mul-189.9%
*-commutative89.9%
Simplified89.9%
Taylor expanded in y around inf 91.6%
pow-base-191.6%
*-lft-identity91.6%
associate-*r*91.6%
fma-def91.7%
neg-mul-191.7%
Simplified91.7%
if -2.6e19 < z < 1.32e11Initial program 100.0%
Taylor expanded in z around 0 98.8%
if 1.32e11 < z Initial program 99.7%
add-cube-cbrt98.0%
pow398.0%
associate--l+98.0%
Applied egg-rr98.0%
Taylor expanded in z around inf 90.3%
associate-*r*90.3%
neg-mul-190.3%
*-commutative90.3%
Simplified90.3%
Taylor expanded in y around inf 92.0%
pow-base-192.0%
*-lft-identity92.0%
neg-mul-192.0%
+-commutative92.0%
sub-neg92.0%
Simplified92.0%
Final simplification95.5%
(FPCore (x y z) :precision binary64 (if (or (<= z 4.4e+20) (and (not (<= z 9e+56)) (<= z 9.2e+85))) (+ x (cos y)) (* z (- (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 4.4e+20) || (!(z <= 9e+56) && (z <= 9.2e+85))) {
tmp = x + cos(y);
} else {
tmp = z * -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 <= 4.4d+20) .or. (.not. (z <= 9d+56)) .and. (z <= 9.2d+85)) then
tmp = x + cos(y)
else
tmp = z * -sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= 4.4e+20) || (!(z <= 9e+56) && (z <= 9.2e+85))) {
tmp = x + Math.cos(y);
} else {
tmp = z * -Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 4.4e+20) or (not (z <= 9e+56) and (z <= 9.2e+85)): tmp = x + math.cos(y) else: tmp = z * -math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 4.4e+20) || (!(z <= 9e+56) && (z <= 9.2e+85))) tmp = Float64(x + cos(y)); else tmp = Float64(z * Float64(-sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= 4.4e+20) || (~((z <= 9e+56)) && (z <= 9.2e+85))) tmp = x + cos(y); else tmp = z * -sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 4.4e+20], And[N[Not[LessEqual[z, 9e+56]], $MachinePrecision], LessEqual[z, 9.2e+85]]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.4 \cdot 10^{+20} \lor \neg \left(z \leq 9 \cdot 10^{+56}\right) \land z \leq 9.2 \cdot 10^{+85}:\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if z < 4.4e20 or 9.0000000000000006e56 < z < 9.1999999999999996e85Initial program 99.9%
Taylor expanded in z around 0 81.3%
if 4.4e20 < z < 9.0000000000000006e56 or 9.1999999999999996e85 < z Initial program 99.6%
Taylor expanded in z around inf 73.0%
associate-*r*73.0%
neg-mul-173.0%
*-commutative73.0%
Simplified73.0%
Final simplification80.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.15e+20) (not (<= z 2550000000.0))) (- x (* z (sin y))) (+ x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e+20) || !(z <= 2550000000.0)) {
tmp = x - (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 <= (-1.15d+20)) .or. (.not. (z <= 2550000000.0d0))) then
tmp = x - (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 <= -1.15e+20) || !(z <= 2550000000.0)) {
tmp = x - (z * Math.sin(y));
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.15e+20) or not (z <= 2550000000.0): tmp = x - (z * math.sin(y)) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.15e+20) || !(z <= 2550000000.0)) tmp = Float64(x - 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 ((z <= -1.15e+20) || ~((z <= 2550000000.0))) tmp = x - (z * sin(y)); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e+20], N[Not[LessEqual[z, 2550000000.0]], $MachinePrecision]], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+20} \lor \neg \left(z \leq 2550000000\right):\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if z < -1.15e20 or 2.55e9 < z Initial program 99.8%
add-cube-cbrt98.0%
pow398.0%
associate--l+98.0%
Applied egg-rr98.0%
Taylor expanded in z around inf 90.1%
associate-*r*90.1%
neg-mul-190.1%
*-commutative90.1%
Simplified90.1%
Taylor expanded in y around inf 91.8%
pow-base-191.8%
*-lft-identity91.8%
neg-mul-191.8%
+-commutative91.8%
sub-neg91.8%
Simplified91.8%
if -1.15e20 < z < 2.55e9Initial program 100.0%
Taylor expanded in z around 0 98.8%
Final simplification95.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.42e-6) (not (<= y 15800.0))) (+ x (cos y)) (+ 1.0 (- x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.42e-6) || !(y <= 15800.0)) {
tmp = x + cos(y);
} else {
tmp = 1.0 + (x - (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 <= (-1.42d-6)) .or. (.not. (y <= 15800.0d0))) then
tmp = x + cos(y)
else
tmp = 1.0d0 + (x - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.42e-6) || !(y <= 15800.0)) {
tmp = x + Math.cos(y);
} else {
tmp = 1.0 + (x - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.42e-6) or not (y <= 15800.0): tmp = x + math.cos(y) else: tmp = 1.0 + (x - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.42e-6) || !(y <= 15800.0)) tmp = Float64(x + cos(y)); else tmp = Float64(1.0 + Float64(x - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.42e-6) || ~((y <= 15800.0))) tmp = x + cos(y); else tmp = 1.0 + (x - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.42e-6], N[Not[LessEqual[y, 15800.0]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.42 \cdot 10^{-6} \lor \neg \left(y \leq 15800\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\end{array}
\end{array}
if y < -1.42e-6 or 15800 < y Initial program 99.8%
Taylor expanded in z around 0 61.4%
if -1.42e-6 < y < 15800Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
fma-def100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 97.4%
+-commutative97.4%
mul-1-neg97.4%
unsub-neg97.4%
Simplified97.4%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (<= y -2.2e+66) (+ x 1.0) (if (<= y 68000.0) (+ 1.0 (- x (* y z))) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e+66) {
tmp = x + 1.0;
} else if (y <= 68000.0) {
tmp = 1.0 + (x - (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 <= (-2.2d+66)) then
tmp = x + 1.0d0
else if (y <= 68000.0d0) then
tmp = 1.0d0 + (x - (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 <= -2.2e+66) {
tmp = x + 1.0;
} else if (y <= 68000.0) {
tmp = 1.0 + (x - (y * z));
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.2e+66: tmp = x + 1.0 elif y <= 68000.0: tmp = 1.0 + (x - (y * z)) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.2e+66) tmp = Float64(x + 1.0); elseif (y <= 68000.0) tmp = Float64(1.0 + Float64(x - 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 <= -2.2e+66) tmp = x + 1.0; elseif (y <= 68000.0) tmp = 1.0 + (x - (y * z)); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.2e+66], N[(x + 1.0), $MachinePrecision], If[LessEqual[y, 68000.0], N[(1.0 + N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{+66}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;y \leq 68000:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < -2.1999999999999998e66 or 68000 < y Initial program 99.8%
Taylor expanded in y around 0 36.9%
+-commutative36.9%
Simplified36.9%
if -2.1999999999999998e66 < y < 68000Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
fma-def100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
Simplified91.1%
Final simplification64.7%
(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 59.6%
+-commutative59.6%
Simplified59.6%
Final simplification59.6%
(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 41.1%
Final simplification41.1%
herbie shell --seed 2023192
(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))))