
(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 8 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)) (* 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 (<= x -7.8e-16) (+ x 1.0) (if (<= x 3.4e-13) (- (cos y) (* z (sin y))) (+ x (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.8e-16) {
tmp = x + 1.0;
} else if (x <= 3.4e-13) {
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 <= (-7.8d-16)) then
tmp = x + 1.0d0
else if (x <= 3.4d-13) 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 <= -7.8e-16) {
tmp = x + 1.0;
} else if (x <= 3.4e-13) {
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 <= -7.8e-16: tmp = x + 1.0 elif x <= 3.4e-13: 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 <= -7.8e-16) tmp = Float64(x + 1.0); elseif (x <= 3.4e-13) 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 <= -7.8e-16) tmp = x + 1.0; elseif (x <= 3.4e-13) tmp = cos(y) - (z * sin(y)); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.8e-16], N[(x + 1.0), $MachinePrecision], If[LessEqual[x, 3.4e-13], 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 -7.8 \cdot 10^{-16}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;x \leq 3.4 \cdot 10^{-13}:\\
\;\;\;\;\cos y - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if x < -7.79999999999999954e-16Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 83.8%
if -7.79999999999999954e-16 < x < 3.40000000000000015e-13Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
neg-mul-199.9%
unsub-neg99.9%
Simplified99.9%
if 3.40000000000000015e-13 < x Initial program 100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in z around 0 79.0%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.1e+140) (not (<= z 1.6e+212))) (* (sin y) (- z)) (+ x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e+140) || !(z <= 1.6e+212)) {
tmp = sin(y) * -z;
} 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.1d+140)) .or. (.not. (z <= 1.6d+212))) then
tmp = sin(y) * -z
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.1e+140) || !(z <= 1.6e+212)) {
tmp = Math.sin(y) * -z;
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.1e+140) or not (z <= 1.6e+212): tmp = math.sin(y) * -z else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.1e+140) || !(z <= 1.6e+212)) tmp = Float64(sin(y) * Float64(-z)); else tmp = Float64(x + cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.1e+140) || ~((z <= 1.6e+212))) tmp = sin(y) * -z; else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.1e+140], N[Not[LessEqual[z, 1.6e+212]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{+140} \lor \neg \left(z \leq 1.6 \cdot 10^{+212}\right):\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if z < -1.0999999999999999e140 or 1.5999999999999999e212 < z Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 75.4%
neg-mul-175.4%
distribute-rgt-neg-in75.4%
Simplified75.4%
if -1.0999999999999999e140 < z < 1.5999999999999999e212Initial program 100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in z around 0 87.3%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e+19) (not (<= y 50000000000.0))) (+ x (cos y)) (+ 1.0 (- x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e+19) || !(y <= 50000000000.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 <= (-5.2d+19)) .or. (.not. (y <= 50000000000.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 <= -5.2e+19) || !(y <= 50000000000.0)) {
tmp = x + Math.cos(y);
} else {
tmp = 1.0 + (x - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e+19) or not (y <= 50000000000.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 <= -5.2e+19) || !(y <= 50000000000.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 <= -5.2e+19) || ~((y <= 50000000000.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, -5.2e+19], N[Not[LessEqual[y, 50000000000.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 -5.2 \cdot 10^{+19} \lor \neg \left(y \leq 50000000000\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\end{array}
\end{array}
if y < -5.2e19 or 5e10 < y Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in z around 0 68.0%
if -5.2e19 < y < 5e10Initial program 100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 95.6%
+-commutative95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (<= y -3.9e+33) (+ x 1.0) (if (<= y 1.55e+69) (+ 1.0 (- x (* y z))) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.9e+33) {
tmp = x + 1.0;
} else if (y <= 1.55e+69) {
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 <= (-3.9d+33)) then
tmp = x + 1.0d0
else if (y <= 1.55d+69) 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 <= -3.9e+33) {
tmp = x + 1.0;
} else if (y <= 1.55e+69) {
tmp = 1.0 + (x - (y * z));
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.9e+33: tmp = x + 1.0 elif y <= 1.55e+69: tmp = 1.0 + (x - (y * z)) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.9e+33) tmp = Float64(x + 1.0); elseif (y <= 1.55e+69) 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 <= -3.9e+33) tmp = x + 1.0; elseif (y <= 1.55e+69) tmp = 1.0 + (x - (y * z)); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.9e+33], N[(x + 1.0), $MachinePrecision], If[LessEqual[y, 1.55e+69], 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 -3.9 \cdot 10^{+33}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{+69}:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < -3.9000000000000002e33 or 1.5499999999999999e69 < y Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 44.6%
if -3.9000000000000002e33 < y < 1.5499999999999999e69Initial program 100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 90.8%
+-commutative90.8%
mul-1-neg90.8%
unsub-neg90.8%
Simplified90.8%
Final simplification72.2%
(FPCore (x y z) :precision binary64 (if (<= z 2.5e+214) (+ x 1.0) (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 2.5e+214) {
tmp = x + 1.0;
} else {
tmp = 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 (z <= 2.5d+214) then
tmp = x + 1.0d0
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 2.5e+214) {
tmp = x + 1.0;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2.5e+214: tmp = x + 1.0 else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 2.5e+214) tmp = Float64(x + 1.0); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 2.5e+214) tmp = x + 1.0; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 2.5e+214], N[(x + 1.0), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.5 \cdot 10^{+214}:\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < 2.49999999999999977e214Initial program 100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 67.3%
if 2.49999999999999977e214 < z Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.7%
Simplified99.7%
Taylor expanded in z around inf 86.8%
neg-mul-186.8%
distribute-rgt-neg-in86.8%
Simplified86.8%
Taylor expanded in y around 0 43.6%
mul-1-neg43.6%
*-commutative43.6%
distribute-rgt-neg-in43.6%
Simplified43.6%
Final simplification65.8%
(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%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 63.8%
Final simplification63.8%
(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%
cancel-sign-sub-inv99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in x around inf 40.7%
Final simplification40.7%
herbie shell --seed 2023279
(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))))