
(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 (fmax (- (hypot (* z 30.0) (* y 30.0)) 25.0) (- (fabs (fma 30.0 x (sin (* z 30.0)))) 0.2)))
double code(double x, double y, double z) {
return fmax((hypot((z * 30.0), (y * 30.0)) - 25.0), (fabs(fma(30.0, x, sin((z * 30.0)))) - 0.2));
}
function code(x, y, z) return fmax(Float64(hypot(Float64(z * 30.0), Float64(y * 30.0)) - 25.0), Float64(abs(fma(30.0, x, sin(Float64(z * 30.0)))) - 0.2)) end
code[x_, y_, z_] := N[Max[N[(N[Sqrt[N[(z * 30.0), $MachinePrecision] ^ 2 + N[(y * 30.0), $MachinePrecision] ^ 2], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(30.0 * x + N[Sin[N[(z * 30.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(\mathsf{hypot}\left(z \cdot 30, y \cdot 30\right) - 25, \left|\mathsf{fma}\left(30, x, \sin \left(z \cdot 30\right)\right)\right| - 0.2\right)
\end{array}
Initial program 45.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
metadata-evalN/A
unpow-prod-downN/A
unpow2N/A
*-commutativeN/A
metadata-evalN/A
unpow-prod-downN/A
unpow2N/A
lower-hypot.f64N/A
lift-*.f64N/A
lift-*.f6475.3
Applied rewrites75.3%
Taylor expanded in y around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites75.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-sin.f64N/A
lift-*.f6498.8
Applied rewrites98.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.15e+158) (not (<= y 5.1e+73))) (fmax (* -30.0 x) (- (fabs (fma y 30.0 (sin (* 30.0 x)))) 0.2)) (fmax (- (sqrt (* (* x x) 900.0)) 25.0) (- (fabs (* z 30.0)) 0.2))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e+158) || !(y <= 5.1e+73)) {
tmp = fmax((-30.0 * x), (fabs(fma(y, 30.0, sin((30.0 * x)))) - 0.2));
} else {
tmp = fmax((sqrt(((x * x) * 900.0)) - 25.0), (fabs((z * 30.0)) - 0.2));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -1.15e+158) || !(y <= 5.1e+73)) tmp = fmax(Float64(-30.0 * x), Float64(abs(fma(y, 30.0, sin(Float64(30.0 * x)))) - 0.2)); else tmp = fmax(Float64(sqrt(Float64(Float64(x * x) * 900.0)) - 25.0), Float64(abs(Float64(z * 30.0)) - 0.2)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.15e+158], N[Not[LessEqual[y, 5.1e+73]], $MachinePrecision]], N[Max[N[(-30.0 * x), $MachinePrecision], N[(N[Abs[N[(y * 30.0 + N[Sin[N[(30.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], N[Max[N[(N[Sqrt[N[(N[(x * x), $MachinePrecision] * 900.0), $MachinePrecision]], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(z * 30.0), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{+158} \lor \neg \left(y \leq 5.1 \cdot 10^{+73}\right):\\
\;\;\;\;\mathsf{max}\left(-30 \cdot x, \left|\mathsf{fma}\left(y, 30, \sin \left(30 \cdot x\right)\right)\right| - 0.2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(\sqrt{\left(x \cdot x\right) \cdot 900} - 25, \left|z \cdot 30\right| - 0.2\right)\\
\end{array}
\end{array}
if y < -1.14999999999999993e158 or 5.10000000000000024e73 < y Initial program 18.7%
Taylor expanded in x around -inf
lower-*.f647.7
Applied rewrites7.7%
Taylor expanded in z around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites7.6%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-sin.f64N/A
lift-*.f6476.9
Applied rewrites76.9%
if -1.14999999999999993e158 < y < 5.10000000000000024e73Initial program 56.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6438.0
Applied rewrites38.0%
Taylor expanded in y around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites37.3%
Taylor expanded in x around 0
*-commutativeN/A
lift-sin.f64N/A
lift-*.f6435.9
Applied rewrites35.9%
Taylor expanded in z around 0
*-commutativeN/A
lift-*.f6469.9
Applied rewrites69.9%
Final simplification71.9%
(FPCore (x y z)
:precision binary64
(if (<= x -5.5e-77)
(fmax (* -30.0 x) (- (fabs (fma y 30.0 (sin (* 30.0 x)))) 0.2))
(if (<= x 4.5e+152)
(fmax (- (sqrt (* (* x x) 900.0)) 25.0) (- (fabs (* z 30.0)) 0.2))
(fmax (* z 30.0) (- (fabs (fma 30.0 x (sin (* z 30.0)))) 0.2)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e-77) {
tmp = fmax((-30.0 * x), (fabs(fma(y, 30.0, sin((30.0 * x)))) - 0.2));
} else if (x <= 4.5e+152) {
tmp = fmax((sqrt(((x * x) * 900.0)) - 25.0), (fabs((z * 30.0)) - 0.2));
} else {
tmp = fmax((z * 30.0), (fabs(fma(30.0, x, sin((z * 30.0)))) - 0.2));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -5.5e-77) tmp = fmax(Float64(-30.0 * x), Float64(abs(fma(y, 30.0, sin(Float64(30.0 * x)))) - 0.2)); elseif (x <= 4.5e+152) tmp = fmax(Float64(sqrt(Float64(Float64(x * x) * 900.0)) - 25.0), Float64(abs(Float64(z * 30.0)) - 0.2)); else tmp = fmax(Float64(z * 30.0), Float64(abs(fma(30.0, x, sin(Float64(z * 30.0)))) - 0.2)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -5.5e-77], N[Max[N[(-30.0 * x), $MachinePrecision], N[(N[Abs[N[(y * 30.0 + N[Sin[N[(30.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 4.5e+152], N[Max[N[(N[Sqrt[N[(N[(x * x), $MachinePrecision] * 900.0), $MachinePrecision]], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(z * 30.0), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], N[Max[N[(z * 30.0), $MachinePrecision], N[(N[Abs[N[(30.0 * x + N[Sin[N[(z * 30.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-77}:\\
\;\;\;\;\mathsf{max}\left(-30 \cdot x, \left|\mathsf{fma}\left(y, 30, \sin \left(30 \cdot x\right)\right)\right| - 0.2\right)\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{max}\left(\sqrt{\left(x \cdot x\right) \cdot 900} - 25, \left|z \cdot 30\right| - 0.2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(z \cdot 30, \left|\mathsf{fma}\left(30, x, \sin \left(z \cdot 30\right)\right)\right| - 0.2\right)\\
\end{array}
\end{array}
if x < -5.49999999999999998e-77Initial program 33.2%
Taylor expanded in x around -inf
lower-*.f6446.6
Applied rewrites46.6%
Taylor expanded in z around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites46.6%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-sin.f64N/A
lift-*.f6473.4
Applied rewrites73.4%
if -5.49999999999999998e-77 < x < 4.5000000000000001e152Initial program 57.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6433.9
Applied rewrites33.9%
Taylor expanded in y around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites32.9%
Taylor expanded in x around 0
*-commutativeN/A
lift-sin.f64N/A
lift-*.f6431.5
Applied rewrites31.5%
Taylor expanded in z around 0
*-commutativeN/A
lift-*.f6471.3
Applied rewrites71.3%
if 4.5000000000000001e152 < x Initial program 7.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
metadata-evalN/A
unpow-prod-downN/A
unpow2N/A
*-commutativeN/A
metadata-evalN/A
unpow-prod-downN/A
unpow2N/A
lower-hypot.f64N/A
lift-*.f64N/A
lift-*.f6443.3
Applied rewrites43.3%
Taylor expanded in y around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.3%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-sin.f64N/A
lift-*.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
*-commutativeN/A
lift-*.f6493.1
Applied rewrites93.1%
(FPCore (x y z) :precision binary64 (fmax (- (hypot (* z 30.0) (* y 30.0)) 25.0) (- (fabs (* 30.0 x)) 0.2)))
double code(double x, double y, double z) {
return fmax((hypot((z * 30.0), (y * 30.0)) - 25.0), (fabs((30.0 * x)) - 0.2));
}
public static double code(double x, double y, double z) {
return fmax((Math.hypot((z * 30.0), (y * 30.0)) - 25.0), (Math.abs((30.0 * x)) - 0.2));
}
def code(x, y, z): return fmax((math.hypot((z * 30.0), (y * 30.0)) - 25.0), (math.fabs((30.0 * x)) - 0.2))
function code(x, y, z) return fmax(Float64(hypot(Float64(z * 30.0), Float64(y * 30.0)) - 25.0), Float64(abs(Float64(30.0 * x)) - 0.2)) end
function tmp = code(x, y, z) tmp = max((hypot((z * 30.0), (y * 30.0)) - 25.0), (abs((30.0 * x)) - 0.2)); end
code[x_, y_, z_] := N[Max[N[(N[Sqrt[N[(z * 30.0), $MachinePrecision] ^ 2 + N[(y * 30.0), $MachinePrecision] ^ 2], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(30.0 * x), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(\mathsf{hypot}\left(z \cdot 30, y \cdot 30\right) - 25, \left|30 \cdot x\right| - 0.2\right)
\end{array}
Initial program 45.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
metadata-evalN/A
unpow-prod-downN/A
unpow2N/A
*-commutativeN/A
metadata-evalN/A
unpow-prod-downN/A
unpow2N/A
lower-hypot.f64N/A
lift-*.f64N/A
lift-*.f6475.3
Applied rewrites75.3%
Taylor expanded in y around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites75.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-sin.f64N/A
lift-*.f6498.8
Applied rewrites98.8%
Taylor expanded in x around inf
lift-*.f6497.9
Applied rewrites97.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.7e+156) (not (<= x 5.8e+187))) (fmax (* -30.0 x) (- (fabs (* 30.0 x)) 0.2)) (fmax (- (sqrt (* (* x x) 900.0)) 25.0) (- (fabs (* z 30.0)) 0.2))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e+156) || !(x <= 5.8e+187)) {
tmp = fmax((-30.0 * x), (fabs((30.0 * x)) - 0.2));
} else {
tmp = fmax((sqrt(((x * x) * 900.0)) - 25.0), (fabs((z * 30.0)) - 0.2));
}
return tmp;
}
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
real(8) :: tmp
if ((x <= (-1.7d+156)) .or. (.not. (x <= 5.8d+187))) then
tmp = fmax(((-30.0d0) * x), (abs((30.0d0 * x)) - 0.2d0))
else
tmp = fmax((sqrt(((x * x) * 900.0d0)) - 25.0d0), (abs((z * 30.0d0)) - 0.2d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e+156) || !(x <= 5.8e+187)) {
tmp = fmax((-30.0 * x), (Math.abs((30.0 * x)) - 0.2));
} else {
tmp = fmax((Math.sqrt(((x * x) * 900.0)) - 25.0), (Math.abs((z * 30.0)) - 0.2));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.7e+156) or not (x <= 5.8e+187): tmp = fmax((-30.0 * x), (math.fabs((30.0 * x)) - 0.2)) else: tmp = fmax((math.sqrt(((x * x) * 900.0)) - 25.0), (math.fabs((z * 30.0)) - 0.2)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.7e+156) || !(x <= 5.8e+187)) tmp = fmax(Float64(-30.0 * x), Float64(abs(Float64(30.0 * x)) - 0.2)); else tmp = fmax(Float64(sqrt(Float64(Float64(x * x) * 900.0)) - 25.0), Float64(abs(Float64(z * 30.0)) - 0.2)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.7e+156) || ~((x <= 5.8e+187))) tmp = max((-30.0 * x), (abs((30.0 * x)) - 0.2)); else tmp = max((sqrt(((x * x) * 900.0)) - 25.0), (abs((z * 30.0)) - 0.2)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.7e+156], N[Not[LessEqual[x, 5.8e+187]], $MachinePrecision]], N[Max[N[(-30.0 * x), $MachinePrecision], N[(N[Abs[N[(30.0 * x), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision], N[Max[N[(N[Sqrt[N[(N[(x * x), $MachinePrecision] * 900.0), $MachinePrecision]], $MachinePrecision] - 25.0), $MachinePrecision], N[(N[Abs[N[(z * 30.0), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{+156} \lor \neg \left(x \leq 5.8 \cdot 10^{+187}\right):\\
\;\;\;\;\mathsf{max}\left(-30 \cdot x, \left|30 \cdot x\right| - 0.2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(\sqrt{\left(x \cdot x\right) \cdot 900} - 25, \left|z \cdot 30\right| - 0.2\right)\\
\end{array}
\end{array}
if x < -1.7e156 or 5.8000000000000002e187 < x Initial program 7.5%
Taylor expanded in x around -inf
lower-*.f6444.6
Applied rewrites44.6%
Taylor expanded in z around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites44.6%
Taylor expanded in y around 0
lift-sin.f64N/A
lift-*.f6444.6
Applied rewrites44.6%
Taylor expanded in x around 0
lift-*.f6477.8
Applied rewrites77.8%
if -1.7e156 < x < 5.8000000000000002e187Initial program 54.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6433.2
Applied rewrites33.2%
Taylor expanded in y around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites32.3%
Taylor expanded in x around 0
*-commutativeN/A
lift-sin.f64N/A
lift-*.f6431.0
Applied rewrites31.0%
Taylor expanded in z around 0
*-commutativeN/A
lift-*.f6465.4
Applied rewrites65.4%
Final simplification67.7%
(FPCore (x y z) :precision binary64 (fmax (* -30.0 x) (- (fabs (* 30.0 x)) 0.2)))
double code(double x, double y, double z) {
return fmax((-30.0 * x), (fabs((30.0 * x)) - 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(((-30.0d0) * x), (abs((30.0d0 * x)) - 0.2d0))
end function
public static double code(double x, double y, double z) {
return fmax((-30.0 * x), (Math.abs((30.0 * x)) - 0.2));
}
def code(x, y, z): return fmax((-30.0 * x), (math.fabs((30.0 * x)) - 0.2))
function code(x, y, z) return fmax(Float64(-30.0 * x), Float64(abs(Float64(30.0 * x)) - 0.2)) end
function tmp = code(x, y, z) tmp = max((-30.0 * x), (abs((30.0 * x)) - 0.2)); end
code[x_, y_, z_] := N[Max[N[(-30.0 * x), $MachinePrecision], N[(N[Abs[N[(30.0 * x), $MachinePrecision]], $MachinePrecision] - 0.2), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{max}\left(-30 \cdot x, \left|30 \cdot x\right| - 0.2\right)
\end{array}
Initial program 45.5%
Taylor expanded in x around -inf
lower-*.f6416.4
Applied rewrites16.4%
Taylor expanded in z around 0
*-commutativeN/A
sin-+PI/2-revN/A
sin-mult-revN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites16.1%
Taylor expanded in y around 0
lift-sin.f64N/A
lift-*.f6415.3
Applied rewrites15.3%
Taylor expanded in x around 0
lift-*.f6428.7
Applied rewrites28.7%
herbie shell --seed 2025085
(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)))