
(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 9 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 (let* ((t_0 (+ x (cos y)))) (if (or (<= y -3200000000.0) (not (<= y 1.8e+42))) t_0 (- t_0 (* y z)))))
double code(double x, double y, double z) {
double t_0 = x + cos(y);
double tmp;
if ((y <= -3200000000.0) || !(y <= 1.8e+42)) {
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 <= (-3200000000.0d0)) .or. (.not. (y <= 1.8d+42))) 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 <= -3200000000.0) || !(y <= 1.8e+42)) {
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 <= -3200000000.0) or not (y <= 1.8e+42): 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 <= -3200000000.0) || !(y <= 1.8e+42)) 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 <= -3200000000.0) || ~((y <= 1.8e+42))) 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, -3200000000.0], N[Not[LessEqual[y, 1.8e+42]], $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 -3200000000 \lor \neg \left(y \leq 1.8 \cdot 10^{+42}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_0 - y \cdot z\\
\end{array}
\end{array}
if y < -3.2e9 or 1.8e42 < y Initial program 99.9%
Taylor expanded in y around 0 43.1%
Taylor expanded in z around 0 72.0%
if -3.2e9 < y < 1.8e42Initial program 100.0%
Taylor expanded in y around 0 98.0%
Final simplification85.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -125000000.0) (not (<= y 7.5e-11))) (+ x (cos y)) (+ 1.0 (- x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -125000000.0) || !(y <= 7.5e-11)) {
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 <= (-125000000.0d0)) .or. (.not. (y <= 7.5d-11))) 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 <= -125000000.0) || !(y <= 7.5e-11)) {
tmp = x + Math.cos(y);
} else {
tmp = 1.0 + (x - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -125000000.0) or not (y <= 7.5e-11): tmp = x + math.cos(y) else: tmp = 1.0 + (x - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -125000000.0) || !(y <= 7.5e-11)) 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 <= -125000000.0) || ~((y <= 7.5e-11))) tmp = x + cos(y); else tmp = 1.0 + (x - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -125000000.0], N[Not[LessEqual[y, 7.5e-11]], $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 -125000000 \lor \neg \left(y \leq 7.5 \cdot 10^{-11}\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\end{array}
\end{array}
if y < -1.25e8 or 7.5e-11 < y Initial program 99.9%
Taylor expanded in y around 0 44.2%
Taylor expanded in z around 0 71.3%
if -1.25e8 < y < 7.5e-11Initial program 100.0%
Taylor expanded in y around 0 99.9%
Taylor expanded in y around 0 99.9%
mul-1-neg99.9%
distribute-rgt-neg-out99.9%
+-commutative99.9%
associate-+r+99.9%
distribute-rgt-neg-out99.9%
sub-neg99.9%
associate-+r-99.9%
Simplified99.9%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.5e+22) (+ x 1.0) (if (<= y 6.2e+29) (+ 1.0 (+ x (* y (- (* y -0.5) z)))) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.5e+22) {
tmp = x + 1.0;
} else if (y <= 6.2e+29) {
tmp = 1.0 + (x + (y * ((y * -0.5) - 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 <= (-1.5d+22)) then
tmp = x + 1.0d0
else if (y <= 6.2d+29) then
tmp = 1.0d0 + (x + (y * ((y * (-0.5d0)) - 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 <= -1.5e+22) {
tmp = x + 1.0;
} else if (y <= 6.2e+29) {
tmp = 1.0 + (x + (y * ((y * -0.5) - z)));
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.5e+22: tmp = x + 1.0 elif y <= 6.2e+29: tmp = 1.0 + (x + (y * ((y * -0.5) - z))) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.5e+22) tmp = Float64(x + 1.0); elseif (y <= 6.2e+29) tmp = Float64(1.0 + Float64(x + Float64(y * Float64(Float64(y * -0.5) - z)))); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.5e+22) tmp = x + 1.0; elseif (y <= 6.2e+29) tmp = 1.0 + (x + (y * ((y * -0.5) - z))); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.5e+22], N[(x + 1.0), $MachinePrecision], If[LessEqual[y, 6.2e+29], N[(1.0 + N[(x + N[(y * N[(N[(y * -0.5), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+22}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+29}:\\
\;\;\;\;1 + \left(x + y \cdot \left(y \cdot -0.5 - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < -1.5e22 or 6.1999999999999998e29 < y Initial program 99.9%
Taylor expanded in y around 0 42.0%
Taylor expanded in y around 0 46.2%
+-commutative46.2%
Simplified46.2%
if -1.5e22 < y < 6.1999999999999998e29Initial program 100.0%
Taylor expanded in y around 0 97.3%
Taylor expanded in y around 0 95.6%
mul-1-neg95.6%
distribute-rgt-neg-out95.6%
+-commutative95.6%
distribute-rgt-neg-out95.6%
unsub-neg95.6%
fma-def95.6%
unpow295.6%
Simplified95.6%
Taylor expanded in y around 0 95.6%
associate-+r+95.6%
+-commutative95.6%
+-commutative95.6%
mul-1-neg95.6%
sub-neg95.6%
unpow295.6%
associate-*r*95.6%
*-commutative95.6%
distribute-rgt-out--95.6%
*-commutative95.6%
Simplified95.6%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (<= y -4100000000.0) (+ x 1.0) (if (<= y 2.7e+58) (+ 1.0 (- x (* y z))) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4100000000.0) {
tmp = x + 1.0;
} else if (y <= 2.7e+58) {
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 <= (-4100000000.0d0)) then
tmp = x + 1.0d0
else if (y <= 2.7d+58) 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 <= -4100000000.0) {
tmp = x + 1.0;
} else if (y <= 2.7e+58) {
tmp = 1.0 + (x - (y * z));
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4100000000.0: tmp = x + 1.0 elif y <= 2.7e+58: tmp = 1.0 + (x - (y * z)) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4100000000.0) tmp = Float64(x + 1.0); elseif (y <= 2.7e+58) 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 <= -4100000000.0) tmp = x + 1.0; elseif (y <= 2.7e+58) tmp = 1.0 + (x - (y * z)); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4100000000.0], N[(x + 1.0), $MachinePrecision], If[LessEqual[y, 2.7e+58], 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 -4100000000:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{+58}:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < -4.1e9 or 2.7000000000000001e58 < y Initial program 99.9%
Taylor expanded in y around 0 43.1%
Taylor expanded in y around 0 46.4%
+-commutative46.4%
Simplified46.4%
if -4.1e9 < y < 2.7000000000000001e58Initial program 100.0%
Taylor expanded in y around 0 98.0%
Taylor expanded in y around 0 96.7%
mul-1-neg96.7%
distribute-rgt-neg-out96.7%
+-commutative96.7%
associate-+r+96.7%
distribute-rgt-neg-out96.7%
sub-neg96.7%
associate-+r-96.7%
Simplified96.7%
Final simplification71.7%
(FPCore (x y z) :precision binary64 (if (<= x -2.8e-11) (+ x 1.0) (if (<= x 8e-19) (- 1.0 (* y z)) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e-11) {
tmp = x + 1.0;
} else if (x <= 8e-19) {
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 <= (-2.8d-11)) then
tmp = x + 1.0d0
else if (x <= 8d-19) 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 <= -2.8e-11) {
tmp = x + 1.0;
} else if (x <= 8e-19) {
tmp = 1.0 - (y * z);
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.8e-11: tmp = x + 1.0 elif x <= 8e-19: tmp = 1.0 - (y * z) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.8e-11) tmp = Float64(x + 1.0); elseif (x <= 8e-19) 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 <= -2.8e-11) tmp = x + 1.0; elseif (x <= 8e-19) tmp = 1.0 - (y * z); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.8e-11], N[(x + 1.0), $MachinePrecision], If[LessEqual[x, 8e-19], N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-11}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;x \leq 8 \cdot 10^{-19}:\\
\;\;\;\;1 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if x < -2.8e-11 or 7.9999999999999998e-19 < x Initial program 100.0%
Taylor expanded in y around 0 77.9%
Taylor expanded in y around 0 84.4%
+-commutative84.4%
Simplified84.4%
if -2.8e-11 < x < 7.9999999999999998e-19Initial program 99.9%
Taylor expanded in y around 0 61.8%
Taylor expanded in y around 0 48.5%
mul-1-neg48.5%
distribute-rgt-neg-out48.5%
+-commutative48.5%
distribute-rgt-neg-out48.5%
unsub-neg48.5%
fma-def48.5%
unpow248.5%
Simplified48.5%
Taylor expanded in z around inf 49.9%
associate-*r*49.9%
neg-mul-149.9%
*-commutative49.9%
Simplified49.9%
Final simplification69.2%
(FPCore (x y z) :precision binary64 (if (<= z 1.95e+217) (+ x 1.0) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.95e+217) {
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 <= 1.95d+217) 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 <= 1.95e+217) {
tmp = x + 1.0;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.95e+217: tmp = x + 1.0 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.95e+217) 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 <= 1.95e+217) tmp = x + 1.0; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.95e+217], N[(x + 1.0), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.95 \cdot 10^{+217}:\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 1.94999999999999997e217Initial program 100.0%
Taylor expanded in y around 0 71.7%
Taylor expanded in y around 0 68.0%
+-commutative68.0%
Simplified68.0%
if 1.94999999999999997e217 < z Initial program 99.8%
Taylor expanded in y around 0 60.4%
Taylor expanded in y around inf 42.1%
mul-1-neg42.1%
distribute-rgt-neg-out42.1%
Simplified42.1%
Final simplification65.9%
(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 70.8%
Taylor expanded in y around 0 64.1%
+-commutative64.1%
Simplified64.1%
Final simplification64.1%
(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 y around 0 70.8%
Taylor expanded in x around inf 45.6%
Final simplification45.6%
herbie shell --seed 2023230
(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))))