
(FPCore (x y z) :precision binary64 :pre TRUE (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
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 = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * (y + z)) / z END code
\frac{x \cdot \left(y + z\right)}{z}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
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 = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * (y + z)) / z END code
\frac{x \cdot \left(y + z\right)}{z}
(FPCore (x y z) :precision binary64 :pre TRUE (* (copysign 1.0 x) (if (<= (fabs x) 2.604772325003076e-139) (fma (* y (fabs x)) (/ 1.0 z) (fabs x)) (fma (fabs x) (/ y z) (fabs x)))))
double code(double x, double y, double z) {
double tmp;
if (fabs(x) <= 2.604772325003076e-139) {
tmp = fma((y * fabs(x)), (1.0 / z), fabs(x));
} else {
tmp = fma(fabs(x), (y / z), fabs(x));
}
return copysign(1.0, x) * tmp;
}
function code(x, y, z) tmp = 0.0 if (abs(x) <= 2.604772325003076e-139) tmp = fma(Float64(y * abs(x)), Float64(1.0 / z), abs(x)); else tmp = fma(abs(x), Float64(y / z), abs(x)); end return Float64(copysign(1.0, x) * tmp) end
code[x_, y_, z_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 2.604772325003076e-139], N[(N[(y * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[(1.0 / z), $MachinePrecision] + N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(N[Abs[x], $MachinePrecision] * N[(y / z), $MachinePrecision] + N[Abs[x], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 2.604772325003076 \cdot 10^{-139}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot \left|x\right|, \frac{1}{z}, \left|x\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|x\right|, \frac{y}{z}, \left|x\right|\right)\\
\end{array}
if x < 2.6047723250030761e-139Initial program 84.8%
Applied rewrites94.0%
if 2.6047723250030761e-139 < x Initial program 84.8%
Applied rewrites95.5%
(FPCore (x y z) :precision binary64 :pre TRUE (fma x (/ y z) x))
double code(double x, double y, double z) {
return fma(x, (y / z), x);
}
function code(x, y, z) return fma(x, Float64(y / z), x) end
code[x_, y_, z_] := N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * (y / z)) + x END code
\mathsf{fma}\left(x, \frac{y}{z}, x\right)
Initial program 84.8%
Applied rewrites95.5%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (/ (* x y) z)))
(if (<= y -4.4496981415615434e-17)
t_0
(if (<= y 3.727054120548146e+47) (* x 1.0) t_0))))double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (y <= -4.4496981415615434e-17) {
tmp = t_0;
} else if (y <= 3.727054120548146e+47) {
tmp = x * 1.0;
} else {
tmp = t_0;
}
return tmp;
}
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) :: t_0
real(8) :: tmp
t_0 = (x * y) / z
if (y <= (-4.4496981415615434d-17)) then
tmp = t_0
else if (y <= 3.727054120548146d+47) then
tmp = x * 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (y <= -4.4496981415615434e-17) {
tmp = t_0;
} else if (y <= 3.727054120548146e+47) {
tmp = x * 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) / z tmp = 0 if y <= -4.4496981415615434e-17: tmp = t_0 elif y <= 3.727054120548146e+47: tmp = x * 1.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * y) / z) tmp = 0.0 if (y <= -4.4496981415615434e-17) tmp = t_0; elseif (y <= 3.727054120548146e+47) tmp = Float64(x * 1.0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * y) / z; tmp = 0.0; if (y <= -4.4496981415615434e-17) tmp = t_0; elseif (y <= 3.727054120548146e+47) tmp = x * 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[y, -4.4496981415615434e-17], t$95$0, If[LessEqual[y, 3.727054120548146e+47], N[(x * 1.0), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = ((x * y) / z) IN LET tmp_1 = IF (y <= (372705412054814616519807377301979582364609675264)) THEN (x * (1)) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-4449698141561543378010010345383822612506954265860180386393807339118211530148983001708984375e-107)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \frac{x \cdot y}{z}\\
\mathbf{if}\;y \leq -4.4496981415615434 \cdot 10^{-17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.727054120548146 \cdot 10^{+47}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -4.4496981415615434e-17 or 3.7270541205481462e47 < y Initial program 84.8%
Taylor expanded in y around inf
Applied rewrites46.9%
if -4.4496981415615434e-17 < y < 3.7270541205481462e47Initial program 84.8%
Taylor expanded in y around 0
Applied rewrites40.7%
Applied rewrites51.4%
Taylor expanded in y around 0
Applied rewrites51.4%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* x (/ y z))))
(if (<= y -4.4496981415615434e-17)
t_0
(if (<= y 3.727054120548146e+47) (* x 1.0) t_0))))double code(double x, double y, double z) {
double t_0 = x * (y / z);
double tmp;
if (y <= -4.4496981415615434e-17) {
tmp = t_0;
} else if (y <= 3.727054120548146e+47) {
tmp = x * 1.0;
} else {
tmp = t_0;
}
return tmp;
}
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) :: t_0
real(8) :: tmp
t_0 = x * (y / z)
if (y <= (-4.4496981415615434d-17)) then
tmp = t_0
else if (y <= 3.727054120548146d+47) then
tmp = x * 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y / z);
double tmp;
if (y <= -4.4496981415615434e-17) {
tmp = t_0;
} else if (y <= 3.727054120548146e+47) {
tmp = x * 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y / z) tmp = 0 if y <= -4.4496981415615434e-17: tmp = t_0 elif y <= 3.727054120548146e+47: tmp = x * 1.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y / z)) tmp = 0.0 if (y <= -4.4496981415615434e-17) tmp = t_0; elseif (y <= 3.727054120548146e+47) tmp = Float64(x * 1.0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y / z); tmp = 0.0; if (y <= -4.4496981415615434e-17) tmp = t_0; elseif (y <= 3.727054120548146e+47) tmp = x * 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.4496981415615434e-17], t$95$0, If[LessEqual[y, 3.727054120548146e+47], N[(x * 1.0), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (x * (y / z)) IN LET tmp_1 = IF (y <= (372705412054814616519807377301979582364609675264)) THEN (x * (1)) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-4449698141561543378010010345383822612506954265860180386393807339118211530148983001708984375e-107)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := x \cdot \frac{y}{z}\\
\mathbf{if}\;y \leq -4.4496981415615434 \cdot 10^{-17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.727054120548146 \cdot 10^{+47}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -4.4496981415615434e-17 or 3.7270541205481462e47 < y Initial program 84.8%
Taylor expanded in y around 0
Applied rewrites40.7%
Applied rewrites51.4%
Taylor expanded in y around 0
Applied rewrites51.4%
Taylor expanded in y around inf
Applied rewrites46.0%
if -4.4496981415615434e-17 < y < 3.7270541205481462e47Initial program 84.8%
Taylor expanded in y around 0
Applied rewrites40.7%
Applied rewrites51.4%
Taylor expanded in y around 0
Applied rewrites51.4%
(FPCore (x y z) :precision binary64 :pre TRUE (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
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 = 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]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x * (1) END code
x \cdot 1
Initial program 84.8%
Taylor expanded in y around 0
Applied rewrites40.7%
Applied rewrites51.4%
Taylor expanded in y around 0
Applied rewrites51.4%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
(/ (* x (+ y z)) z))