
(FPCore (x y z)
:precision binary64
(fmax
(-
(sqrt
(+ (+ (pow (* x 30.0) 2.0) (pow (* y 30.0) 2.0)) (pow (* z 30.0) 2.0)))
25.0)
(-
(fabs
(+
(+
(* (sin (* x 30.0)) (cos (* y 30.0)))
(* (sin (* y 30.0)) (cos (* z 30.0))))
(* (sin (* z 30.0)) (cos (* x 30.0)))))
0.2)))
double code(double x, double y, double z) {
return fmax((sqrt(((pow((x * 30.0), 2.0) + pow((y * 30.0), 2.0)) + pow((z * 30.0), 2.0))) - 25.0), (fabs((((sin((x * 30.0)) * cos((y * 30.0))) + (sin((y * 30.0)) * cos((z * 30.0)))) + (sin((z * 30.0)) * cos((x * 30.0))))) - 0.2));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = fmax((sqrt(((((x * 30.0d0) ** 2.0d0) + ((y * 30.0d0) ** 2.0d0)) + ((z * 30.0d0) ** 2.0d0))) - 25.0d0), (abs((((sin((x * 30.0d0)) * cos((y * 30.0d0))) + (sin((y * 30.0d0)) * cos((z * 30.0d0)))) + (sin((z * 30.0d0)) * cos((x * 30.0d0))))) - 0.2d0))
end function
public static double code(double x, double y, double z) {
return fmax((Math.sqrt(((Math.pow((x * 30.0), 2.0) + Math.pow((y * 30.0), 2.0)) + Math.pow((z * 30.0), 2.0))) - 25.0), (Math.abs((((Math.sin((x * 30.0)) * Math.cos((y * 30.0))) + (Math.sin((y * 30.0)) * Math.cos((z * 30.0)))) + (Math.sin((z * 30.0)) * Math.cos((x * 30.0))))) - 0.2));
}
def code(x, y, z): return fmax((math.sqrt(((math.pow((x * 30.0), 2.0) + math.pow((y * 30.0), 2.0)) + math.pow((z * 30.0), 2.0))) - 25.0), (math.fabs((((math.sin((x * 30.0)) * math.cos((y * 30.0))) + (math.sin((y * 30.0)) * math.cos((z * 30.0)))) + (math.sin((z * 30.0)) * math.cos((x * 30.0))))) - 0.2))
function code(x, y, z) return fmax(Float64(sqrt(Float64(Float64((Float64(x * 30.0) ^ 2.0) + (Float64(y * 30.0) ^ 2.0)) + (Float64(z * 30.0) ^ 2.0))) - 25.0), Float64(abs(Float64(Float64(Float64(sin(Float64(x * 30.0)) * cos(Float64(y * 30.0))) + Float64(sin(Float64(y * 30.0)) * cos(Float64(z * 30.0)))) + Float64(sin(Float64(z * 30.0)) * cos(Float64(x * 30.0))))) - 0.2)) end
function tmp = code(x, y, z) tmp = max((sqrt(((((x * 30.0) ^ 2.0) + ((y * 30.0) ^ 2.0)) + ((z * 30.0) ^ 2.0))) - 25.0), (abs((((sin((x * 30.0)) * cos((y * 30.0))) + (sin((y * 30.0)) * cos((z * 30.0)))) + (sin((z * 30.0)) * cos((x * 30.0))))) - 0.2)); end
code[x_, y_, z_] := N[Max[N[(N[Sqrt[N[(N[(N[Power[N[(x * 30.0), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(y * 30.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[Power[N[(z * 30.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(N[(N[(N[Sin[N[(x * 30.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(y * 30.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[N[(y * 30.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(z * 30.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[N[(z * 30.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(x * 30.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(\sqrt{\left({\left(x \cdot 30\right)}^{2} + {\left(y \cdot 30\right)}^{2}\right) + {\left(z \cdot 30\right)}^{2}} - 25, \left|\left(\sin \left(x \cdot 30\right) \cdot \cos \left(y \cdot 30\right) + \sin \left(y \cdot 30\right) \cdot \cos \left(z \cdot 30\right)\right) + \sin \left(z \cdot 30\right) \cdot \cos \left(x \cdot 30\right)\right| - 0.2\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z)
:precision binary64
(fmax
(-
(sqrt
(+ (+ (pow (* x 30.0) 2.0) (pow (* y 30.0) 2.0)) (pow (* z 30.0) 2.0)))
25.0)
(-
(fabs
(+
(+
(* (sin (* x 30.0)) (cos (* y 30.0)))
(* (sin (* y 30.0)) (cos (* z 30.0))))
(* (sin (* z 30.0)) (cos (* x 30.0)))))
0.2)))
double code(double x, double y, double z) {
return fmax((sqrt(((pow((x * 30.0), 2.0) + pow((y * 30.0), 2.0)) + pow((z * 30.0), 2.0))) - 25.0), (fabs((((sin((x * 30.0)) * cos((y * 30.0))) + (sin((y * 30.0)) * cos((z * 30.0)))) + (sin((z * 30.0)) * cos((x * 30.0))))) - 0.2));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = fmax((sqrt(((((x * 30.0d0) ** 2.0d0) + ((y * 30.0d0) ** 2.0d0)) + ((z * 30.0d0) ** 2.0d0))) - 25.0d0), (abs((((sin((x * 30.0d0)) * cos((y * 30.0d0))) + (sin((y * 30.0d0)) * cos((z * 30.0d0)))) + (sin((z * 30.0d0)) * cos((x * 30.0d0))))) - 0.2d0))
end function
public static double code(double x, double y, double z) {
return fmax((Math.sqrt(((Math.pow((x * 30.0), 2.0) + Math.pow((y * 30.0), 2.0)) + Math.pow((z * 30.0), 2.0))) - 25.0), (Math.abs((((Math.sin((x * 30.0)) * Math.cos((y * 30.0))) + (Math.sin((y * 30.0)) * Math.cos((z * 30.0)))) + (Math.sin((z * 30.0)) * Math.cos((x * 30.0))))) - 0.2));
}
def code(x, y, z): return fmax((math.sqrt(((math.pow((x * 30.0), 2.0) + math.pow((y * 30.0), 2.0)) + math.pow((z * 30.0), 2.0))) - 25.0), (math.fabs((((math.sin((x * 30.0)) * math.cos((y * 30.0))) + (math.sin((y * 30.0)) * math.cos((z * 30.0)))) + (math.sin((z * 30.0)) * math.cos((x * 30.0))))) - 0.2))
function code(x, y, z) return fmax(Float64(sqrt(Float64(Float64((Float64(x * 30.0) ^ 2.0) + (Float64(y * 30.0) ^ 2.0)) + (Float64(z * 30.0) ^ 2.0))) - 25.0), Float64(abs(Float64(Float64(Float64(sin(Float64(x * 30.0)) * cos(Float64(y * 30.0))) + Float64(sin(Float64(y * 30.0)) * cos(Float64(z * 30.0)))) + Float64(sin(Float64(z * 30.0)) * cos(Float64(x * 30.0))))) - 0.2)) end
function tmp = code(x, y, z) tmp = max((sqrt(((((x * 30.0) ^ 2.0) + ((y * 30.0) ^ 2.0)) + ((z * 30.0) ^ 2.0))) - 25.0), (abs((((sin((x * 30.0)) * cos((y * 30.0))) + (sin((y * 30.0)) * cos((z * 30.0)))) + (sin((z * 30.0)) * cos((x * 30.0))))) - 0.2)); end
code[x_, y_, z_] := N[Max[N[(N[Sqrt[N[(N[(N[Power[N[(x * 30.0), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(y * 30.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[Power[N[(z * 30.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(N[(N[(N[Sin[N[(x * 30.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(y * 30.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[N[(y * 30.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(z * 30.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[N[(z * 30.0), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(x * 30.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(\sqrt{\left({\left(x \cdot 30\right)}^{2} + {\left(y \cdot 30\right)}^{2}\right) + {\left(z \cdot 30\right)}^{2}} - 25, \left|\left(\sin \left(x \cdot 30\right) \cdot \cos \left(y \cdot 30\right) + \sin \left(y \cdot 30\right) \cdot \cos \left(z \cdot 30\right)\right) + \sin \left(z \cdot 30\right) \cdot \cos \left(x \cdot 30\right)\right| - 0.2\right)
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (sin (* 30.0 y))))
(if (or (<= z -5.5e+75) (not (<= z 115000000.0)))
(fmax
(- (hypot (* -30.0 z) (* -30.0 y)) 25.0)
(- (fabs (fma t_0 1.0 (* z 30.0))) 0.2))
(fmax
(- (hypot (* -30.0 y) (* -30.0 x)) 25.0)
(- (fabs (fma t_0 1.0 (sin (* 30.0 z)))) 0.2)))))
double code(double x, double y, double z) {
double t_0 = sin((30.0 * y));
double tmp;
if ((z <= -5.5e+75) || !(z <= 115000000.0)) {
tmp = fmax((hypot((-30.0 * z), (-30.0 * y)) - 25.0), (fabs(fma(t_0, 1.0, (z * 30.0))) - 0.2));
} else {
tmp = fmax((hypot((-30.0 * y), (-30.0 * x)) - 25.0), (fabs(fma(t_0, 1.0, sin((30.0 * z)))) - 0.2));
}
return tmp;
}
function code(x, y, z) t_0 = sin(Float64(30.0 * y)) tmp = 0.0 if ((z <= -5.5e+75) || !(z <= 115000000.0)) tmp = fmax(Float64(hypot(Float64(-30.0 * z), Float64(-30.0 * y)) - 25.0), Float64(abs(fma(t_0, 1.0, Float64(z * 30.0))) - 0.2)); else tmp = fmax(Float64(hypot(Float64(-30.0 * y), Float64(-30.0 * x)) - 25.0), Float64(abs(fma(t_0, 1.0, sin(Float64(30.0 * z)))) - 0.2)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[Sin[N[(30.0 * y), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[z, -5.5e+75], N[Not[LessEqual[z, 115000000.0]], $MachinePrecision]], N[Max[N[(N[Sqrt[N[(-30.0 * z), $MachinePrecision] ^ 2 + N[(-30.0 * y), $MachinePrecision] ^ 2], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(t$95$0 * 1.0 + N[(z * 30.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], N[Max[N[(N[Sqrt[N[(-30.0 * y), $MachinePrecision] ^ 2 + N[(-30.0 * x), $MachinePrecision] ^ 2], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(t$95$0 * 1.0 + N[Sin[N[(30.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(30 \cdot y\right)\\
\mathbf{if}\;z \leq -5.5 \cdot 10^{+75} \lor \neg \left(z \leq 115000000\right):\\
\;\;\;\;\mathsf{max}\left(\mathsf{hypot}\left(-30 \cdot z, -30 \cdot y\right) - 25, \left|\mathsf{fma}\left(t\_0, 1, z \cdot 30\right)\right| - 0.2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(\mathsf{hypot}\left(-30 \cdot y, -30 \cdot x\right) - 25, \left|\mathsf{fma}\left(t\_0, 1, \sin \left(30 \cdot z\right)\right)\right| - 0.2\right)\\
\end{array}
\end{array}
if z < -5.5000000000000001e75 or 1.15e8 < z Initial program 39.2%
Taylor expanded in x around 0
Applied rewrites39.2%
Taylor expanded in x around 0
Applied rewrites87.3%
Taylor expanded in z around 0
Applied rewrites87.3%
Taylor expanded in z around 0
Applied rewrites87.3%
if -5.5000000000000001e75 < z < 1.15e8Initial program 59.2%
Taylor expanded in x around 0
Applied rewrites59.2%
Taylor expanded in z around 0
Applied rewrites97.1%
Taylor expanded in z around 0
Applied rewrites97.1%
Final simplification92.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (sin (* 30.0 y))))
(if (or (<= y -6.2e+117) (not (<= y 2.6e-19)))
(fmax
(- (hypot (* -30.0 z) (* -30.0 y)) 25.0)
(- (fabs (fma t_0 1.0 (* z 30.0))) 0.2))
(fmax
(- (hypot (* -30.0 x) (* z 30.0)) 25.0)
(- (fabs (fma t_0 1.0 (sin (* 30.0 z)))) 0.2)))))
double code(double x, double y, double z) {
double t_0 = sin((30.0 * y));
double tmp;
if ((y <= -6.2e+117) || !(y <= 2.6e-19)) {
tmp = fmax((hypot((-30.0 * z), (-30.0 * y)) - 25.0), (fabs(fma(t_0, 1.0, (z * 30.0))) - 0.2));
} else {
tmp = fmax((hypot((-30.0 * x), (z * 30.0)) - 25.0), (fabs(fma(t_0, 1.0, sin((30.0 * z)))) - 0.2));
}
return tmp;
}
function code(x, y, z) t_0 = sin(Float64(30.0 * y)) tmp = 0.0 if ((y <= -6.2e+117) || !(y <= 2.6e-19)) tmp = fmax(Float64(hypot(Float64(-30.0 * z), Float64(-30.0 * y)) - 25.0), Float64(abs(fma(t_0, 1.0, Float64(z * 30.0))) - 0.2)); else tmp = fmax(Float64(hypot(Float64(-30.0 * x), Float64(z * 30.0)) - 25.0), Float64(abs(fma(t_0, 1.0, sin(Float64(30.0 * z)))) - 0.2)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[Sin[N[(30.0 * y), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[y, -6.2e+117], N[Not[LessEqual[y, 2.6e-19]], $MachinePrecision]], N[Max[N[(N[Sqrt[N[(-30.0 * z), $MachinePrecision] ^ 2 + N[(-30.0 * y), $MachinePrecision] ^ 2], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(t$95$0 * 1.0 + N[(z * 30.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], N[Max[N[(N[Sqrt[N[(-30.0 * x), $MachinePrecision] ^ 2 + N[(z * 30.0), $MachinePrecision] ^ 2], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(t$95$0 * 1.0 + N[Sin[N[(30.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(30 \cdot y\right)\\
\mathbf{if}\;y \leq -6.2 \cdot 10^{+117} \lor \neg \left(y \leq 2.6 \cdot 10^{-19}\right):\\
\;\;\;\;\mathsf{max}\left(\mathsf{hypot}\left(-30 \cdot z, -30 \cdot y\right) - 25, \left|\mathsf{fma}\left(t\_0, 1, z \cdot 30\right)\right| - 0.2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(\mathsf{hypot}\left(-30 \cdot x, z \cdot 30\right) - 25, \left|\mathsf{fma}\left(t\_0, 1, \sin \left(30 \cdot z\right)\right)\right| - 0.2\right)\\
\end{array}
\end{array}
if y < -6.1999999999999995e117 or 2.60000000000000013e-19 < y Initial program 31.6%
Taylor expanded in x around 0
Applied rewrites31.6%
Taylor expanded in x around 0
Applied rewrites84.8%
Taylor expanded in z around 0
Applied rewrites84.8%
Taylor expanded in z around 0
Applied rewrites84.8%
if -6.1999999999999995e117 < y < 2.60000000000000013e-19Initial program 63.4%
Taylor expanded in x around 0
Applied rewrites63.4%
Taylor expanded in x around 0
Applied rewrites63.0%
Taylor expanded in z around 0
Applied rewrites63.0%
Taylor expanded in y around 0
Applied rewrites96.1%
Final simplification91.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (sin (* 30.0 y))) (t_1 (sin (* 30.0 z))))
(if (<= x -1.35e+38)
(fmax (- (* -30.0 x) 25.0) (- (fabs (fma (* y 30.0) 1.0 t_1)) 0.2))
(if (<= x 8.5e+164)
(fmax
(- (hypot (* -30.0 z) (* -30.0 y)) 25.0)
(- (fabs (fma t_0 1.0 (* z 30.0))) 0.2))
(fmax (* 30.0 x) (- (fabs (fma t_0 1.0 t_1)) 0.2))))))
double code(double x, double y, double z) {
double t_0 = sin((30.0 * y));
double t_1 = sin((30.0 * z));
double tmp;
if (x <= -1.35e+38) {
tmp = fmax(((-30.0 * x) - 25.0), (fabs(fma((y * 30.0), 1.0, t_1)) - 0.2));
} else if (x <= 8.5e+164) {
tmp = fmax((hypot((-30.0 * z), (-30.0 * y)) - 25.0), (fabs(fma(t_0, 1.0, (z * 30.0))) - 0.2));
} else {
tmp = fmax((30.0 * x), (fabs(fma(t_0, 1.0, t_1)) - 0.2));
}
return tmp;
}
function code(x, y, z) t_0 = sin(Float64(30.0 * y)) t_1 = sin(Float64(30.0 * z)) tmp = 0.0 if (x <= -1.35e+38) tmp = fmax(Float64(Float64(-30.0 * x) - 25.0), Float64(abs(fma(Float64(y * 30.0), 1.0, t_1)) - 0.2)); elseif (x <= 8.5e+164) tmp = fmax(Float64(hypot(Float64(-30.0 * z), Float64(-30.0 * y)) - 25.0), Float64(abs(fma(t_0, 1.0, Float64(z * 30.0))) - 0.2)); else tmp = fmax(Float64(30.0 * x), Float64(abs(fma(t_0, 1.0, t_1)) - 0.2)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[Sin[N[(30.0 * y), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(30.0 * z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -1.35e+38], N[Max[N[(N[(-30.0 * x), $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(N[(y * 30.0), $MachinePrecision] * 1.0 + t$95$1), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 8.5e+164], N[Max[N[(N[Sqrt[N[(-30.0 * z), $MachinePrecision] ^ 2 + N[(-30.0 * y), $MachinePrecision] ^ 2], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(t$95$0 * 1.0 + N[(z * 30.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], N[Max[N[(30.0 * x), $MachinePrecision], N[(N[Abs[N[(t$95$0 * 1.0 + t$95$1), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(30 \cdot y\right)\\
t_1 := \sin \left(30 \cdot z\right)\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{max}\left(-30 \cdot x - 25, \left|\mathsf{fma}\left(y \cdot 30, 1, t\_1\right)\right| - 0.2\right)\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{+164}:\\
\;\;\;\;\mathsf{max}\left(\mathsf{hypot}\left(-30 \cdot z, -30 \cdot y\right) - 25, \left|\mathsf{fma}\left(t\_0, 1, z \cdot 30\right)\right| - 0.2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(30 \cdot x, \left|\mathsf{fma}\left(t\_0, 1, t\_1\right)\right| - 0.2\right)\\
\end{array}
\end{array}
if x < -1.34999999999999998e38Initial program 36.1%
Taylor expanded in x around 0
Applied rewrites36.1%
Taylor expanded in x around -inf
Applied rewrites63.3%
Taylor expanded in z around 0
Applied rewrites63.3%
Taylor expanded in y around 0
Applied rewrites84.1%
if -1.34999999999999998e38 < x < 8.50000000000000027e164Initial program 59.9%
Taylor expanded in x around 0
Applied rewrites59.9%
Taylor expanded in x around 0
Applied rewrites90.7%
Taylor expanded in z around 0
Applied rewrites90.7%
Taylor expanded in z around 0
Applied rewrites90.0%
if 8.50000000000000027e164 < x Initial program 6.9%
Taylor expanded in x around 0
Applied rewrites6.9%
Taylor expanded in x around 0
Applied rewrites20.6%
Taylor expanded in z around 0
Applied rewrites20.6%
Taylor expanded in x around inf
Applied rewrites82.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* -30.0 x) 25.0)) (t_1 (sin (* 30.0 y))))
(if (<= y -9.2e+137)
(fmax t_0 (- (fabs (fma (* y 30.0) 1.0 (sin (* 30.0 z)))) 0.2))
(if (<= y 2.6e-19)
(fmax t_0 (- (fabs (fma t_1 1.0 (* z 30.0))) 0.2))
(fmax
(- (* 30.0 y) 25.0)
(- (fabs (fma t_1 (cos (* -30.0 z)) (* z 30.0))) 0.2))))))
double code(double x, double y, double z) {
double t_0 = (-30.0 * x) - 25.0;
double t_1 = sin((30.0 * y));
double tmp;
if (y <= -9.2e+137) {
tmp = fmax(t_0, (fabs(fma((y * 30.0), 1.0, sin((30.0 * z)))) - 0.2));
} else if (y <= 2.6e-19) {
tmp = fmax(t_0, (fabs(fma(t_1, 1.0, (z * 30.0))) - 0.2));
} else {
tmp = fmax(((30.0 * y) - 25.0), (fabs(fma(t_1, cos((-30.0 * z)), (z * 30.0))) - 0.2));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(-30.0 * x) - 25.0) t_1 = sin(Float64(30.0 * y)) tmp = 0.0 if (y <= -9.2e+137) tmp = fmax(t_0, Float64(abs(fma(Float64(y * 30.0), 1.0, sin(Float64(30.0 * z)))) - 0.2)); elseif (y <= 2.6e-19) tmp = fmax(t_0, Float64(abs(fma(t_1, 1.0, Float64(z * 30.0))) - 0.2)); else tmp = fmax(Float64(Float64(30.0 * y) - 25.0), Float64(abs(fma(t_1, cos(Float64(-30.0 * z)), Float64(z * 30.0))) - 0.2)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-30.0 * x), $MachinePrecision] - 25.0), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(30.0 * y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[y, -9.2e+137], N[Max[t$95$0, N[(N[Abs[N[(N[(y * 30.0), $MachinePrecision] * 1.0 + N[Sin[N[(30.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], If[LessEqual[y, 2.6e-19], N[Max[t$95$0, N[(N[Abs[N[(t$95$1 * 1.0 + N[(z * 30.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], N[Max[N[(N[(30.0 * y), $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(t$95$1 * N[Cos[N[(-30.0 * z), $MachinePrecision]], $MachinePrecision] + N[(z * 30.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -30 \cdot x - 25\\
t_1 := \sin \left(30 \cdot y\right)\\
\mathbf{if}\;y \leq -9.2 \cdot 10^{+137}:\\
\;\;\;\;\mathsf{max}\left(t\_0, \left|\mathsf{fma}\left(y \cdot 30, 1, \sin \left(30 \cdot z\right)\right)\right| - 0.2\right)\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{max}\left(t\_0, \left|\mathsf{fma}\left(t\_1, 1, z \cdot 30\right)\right| - 0.2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(30 \cdot y - 25, \left|\mathsf{fma}\left(t\_1, \cos \left(-30 \cdot z\right), z \cdot 30\right)\right| - 0.2\right)\\
\end{array}
\end{array}
if y < -9.19999999999999997e137Initial program 21.8%
Taylor expanded in x around 0
Applied rewrites21.8%
Taylor expanded in x around -inf
Applied rewrites6.7%
Taylor expanded in z around 0
Applied rewrites6.4%
Taylor expanded in y around 0
Applied rewrites71.6%
if -9.19999999999999997e137 < y < 2.60000000000000013e-19Initial program 63.5%
Taylor expanded in x around 0
Applied rewrites63.5%
Taylor expanded in x around -inf
Applied rewrites37.4%
Taylor expanded in z around 0
Applied rewrites37.4%
Taylor expanded in z around 0
Applied rewrites78.1%
if 2.60000000000000013e-19 < y Initial program 35.3%
Taylor expanded in x around 0
Applied rewrites35.3%
Taylor expanded in y around inf
Applied rewrites64.7%
Taylor expanded in z around 0
Applied rewrites84.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* -30.0 x) 25.0)))
(if (or (<= z -1.25e+20) (not (<= z 1.32e+16)))
(fmax t_0 (- (fabs (fma (sin (* 30.0 y)) 1.0 (* z 30.0))) 0.2))
(fmax t_0 (- (fabs (fma (* y 30.0) 1.0 (sin (* 30.0 z)))) 0.2)))))
double code(double x, double y, double z) {
double t_0 = (-30.0 * x) - 25.0;
double tmp;
if ((z <= -1.25e+20) || !(z <= 1.32e+16)) {
tmp = fmax(t_0, (fabs(fma(sin((30.0 * y)), 1.0, (z * 30.0))) - 0.2));
} else {
tmp = fmax(t_0, (fabs(fma((y * 30.0), 1.0, sin((30.0 * z)))) - 0.2));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(-30.0 * x) - 25.0) tmp = 0.0 if ((z <= -1.25e+20) || !(z <= 1.32e+16)) tmp = fmax(t_0, Float64(abs(fma(sin(Float64(30.0 * y)), 1.0, Float64(z * 30.0))) - 0.2)); else tmp = fmax(t_0, Float64(abs(fma(Float64(y * 30.0), 1.0, sin(Float64(30.0 * z)))) - 0.2)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-30.0 * x), $MachinePrecision] - 25.0), $MachinePrecision]}, If[Or[LessEqual[z, -1.25e+20], N[Not[LessEqual[z, 1.32e+16]], $MachinePrecision]], N[Max[t$95$0, N[(N[Abs[N[(N[Sin[N[(30.0 * y), $MachinePrecision]], $MachinePrecision] * 1.0 + N[(z * 30.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], N[Max[t$95$0, N[(N[Abs[N[(N[(y * 30.0), $MachinePrecision] * 1.0 + N[Sin[N[(30.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -30 \cdot x - 25\\
\mathbf{if}\;z \leq -1.25 \cdot 10^{+20} \lor \neg \left(z \leq 1.32 \cdot 10^{+16}\right):\\
\;\;\;\;\mathsf{max}\left(t\_0, \left|\mathsf{fma}\left(\sin \left(30 \cdot y\right), 1, z \cdot 30\right)\right| - 0.2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(t\_0, \left|\mathsf{fma}\left(y \cdot 30, 1, \sin \left(30 \cdot z\right)\right)\right| - 0.2\right)\\
\end{array}
\end{array}
if z < -1.25e20 or 1.32e16 < z Initial program 40.0%
Taylor expanded in x around 0
Applied rewrites40.0%
Taylor expanded in x around -inf
Applied rewrites12.6%
Taylor expanded in z around 0
Applied rewrites12.4%
Taylor expanded in z around 0
Applied rewrites74.9%
if -1.25e20 < z < 1.32e16Initial program 59.7%
Taylor expanded in x around 0
Applied rewrites59.7%
Taylor expanded in x around -inf
Applied rewrites41.2%
Taylor expanded in z around 0
Applied rewrites41.1%
Taylor expanded in y around 0
Applied rewrites77.7%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (fmax (- (* -30.0 x) 25.0) (- (fabs (fma (* y 30.0) 1.0 (sin (* 30.0 z)))) 0.2)))
double code(double x, double y, double z) {
return fmax(((-30.0 * x) - 25.0), (fabs(fma((y * 30.0), 1.0, sin((30.0 * z)))) - 0.2));
}
function code(x, y, z) return fmax(Float64(Float64(-30.0 * x) - 25.0), Float64(abs(fma(Float64(y * 30.0), 1.0, sin(Float64(30.0 * z)))) - 0.2)) end
code[x_, y_, z_] := N[Max[N[(N[(-30.0 * x), $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(N[(y * 30.0), $MachinePrecision] * 1.0 + N[Sin[N[(30.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(-30 \cdot x - 25, \left|\mathsf{fma}\left(y \cdot 30, 1, \sin \left(30 \cdot z\right)\right)\right| - 0.2\right)
\end{array}
Initial program 49.6%
Taylor expanded in x around 0
Applied rewrites49.6%
Taylor expanded in x around -inf
Applied rewrites26.5%
Taylor expanded in z around 0
Applied rewrites26.4%
Taylor expanded in y around 0
Applied rewrites53.8%
herbie shell --seed 2025019
(FPCore (x y z)
:name "Gyroid sphere"
:precision binary64
(fmax (- (sqrt (+ (+ (pow (* x 30.0) 2.0) (pow (* y 30.0) 2.0)) (pow (* z 30.0) 2.0))) 25.0) (- (fabs (+ (+ (* (sin (* x 30.0)) (cos (* y 30.0))) (* (sin (* y 30.0)) (cos (* z 30.0)))) (* (sin (* z 30.0)) (cos (* x 30.0))))) 0.2)))